Downtime Announcement: Please note the SAP Community Wiki will be unavailable due to a system upgrade on Thursday, September 24th between 6 and 7 AM CEST
Skip to end of metadata
Go to start of metadata

Table of Contents

Prerequisites and Relevant Knowledge Management APIs
Scenario
Coding in Detail
Configuration
Sample Metadata Extension

Applies To:

Knowledge Management SAP NetWeaver 04 SPS11 and higher.

Summary

Modeling properties and assigning default values or value lists in KMC is a very useful feature delivered in the standard installation. You often need to provide metadata values for KMC properties that are delivered by external sources, e.g. backend systems or remote applications. Therefore, you can implement a Metadata Extension that provides dynamic value access and a validation check.

Prerequisites and Relevant Knowledge Management APIs

A prerequisite for developers using the Metadata Extensions is to have an understanding of the concepts described in Repository Framework Concepts (RCO) and advanced knowledge of flexible UI component development and deployment. Due to the amount of configuration, it is also recommended that you have an understanding of the Global Service "Property Metadata."

This tutorial describes the implementation of the dynamic value provider as a Metadata Extension. The following Knowledge Management API package is used in the sample implementation:

com.sapportals.wcm.service.propertyconfig.*: Contains all classes for implementing a Metadata Extension

Scenario

During the document upload process you can maintain properties assigned to the new resource object. By default you get a list of KMC standard properties and additional properties that are modeled in the Global Service "Property Metadata." The values assigned to the properties can either be specified in a free text field or as a fixed list of pre-configured values.

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
To offer a more flexible list of values, the dynamic value providers can be implemented for a custom- specific value list. These values can be retrieved from a remote system or backend system depending on the modeled property and meta- context information.

Each value provided in the dynamic value provider can be localized either by a resource bundle or an 'own translation' mechanism. Depending on the property definition in the Global Service "Property Metadata," you can assign single or multiple values to the property.

Beside the pre-filled list of selectable property values, it is also required to do a value validation of the user input, e.g. in a string-based property.

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
Therefore, a validation class can be implemented that validates user input and returns error messages in case of invalid values. The error messages are displayed on the standard UI either in the details iView or in the upload dialog.

Coding in Detail

This example shows the implementation of the IDynamicValues and of the IValidation interface that are used as Metadata Extension for KMC properties.

Implementing the IDynamicValues Interface

The important method to be implemented is getAllowedValues(). This method must return a list of values (IMetaValueList) that contain at least the technical keys for the values later rendered in the property dialog.

 public IMetaValueList getAllowedValues(IMetaName metaName, IMetaContext metaContext)     throws PropertyConfigurationServiceException {

 In this example, a simple list is generated by a "for" loop and filled with technical keys:

IMetaValueList valueList =         this.model.createEmptyMetaValueList();            String value = null;    for (int i = 0; i < 10; i++) {        value = metaName.getName()+".techKey."+i;        valueList.add(            model.createMetaValue(model, metaName, this, value)        );    }    return valueList;

 The list can also be filled by calling a remote application that delivers the values in an appropriate format.

The meta- context object provides information on the property configuration e.g. for which mime types, resource type, or resource path the Metadata Extension is valid and the property is defined for. Information on the resource and the user is also provided implicitly through the metaContext.getResource() method call. So the values can also be retrieved in a context dependent mode from a remote application.

The list must be filled with IMetaValue objects that can be generated by factory methods of the model. The IMetaValue objects must therefore refer to the model, the meta-name, its provider, and of course to a value. The value is represented as technical keys and will appear as a localized text string in the property renderer later on.

The values themselves are localized by the getValueLabel() method, which should return a valid localization string for every property value that occurs in the IMetaValueList.

public String getValueLabel(IMetaValue metaValue, Locale locale)      throws PropertyConfigurationServiceException {        return ResourceBundle.getBundle(this.getClass().getName(),             locale).getString("value.lbl."+ metaValue.getValue());    } 

 You can also provide default values that are taken by the UI later on to pre-fill the property renderers

public IMetaValue getDefaultValue(IMetaName metaName) {      return this.model.createMetaValue(this.model, metaName, this, "");    }

  The property that is rendered on the UI is set with a certain label and a description that can also be localized by the IDynamicValues implementation.

public String getPropertyLabel(IMetaName metaName, Locale locale)      throws PropertyConfigurationServiceException {        return ResourceBundle.getBundle(this.getClass().getName(),             locale).getString("property.lbl."+ metaName.getName()    }				public String getPropertyDescription(IMetaName mName, Locale locale)      throws PropertyConfigurationServiceException {        return ResourceBundle.getBundle(this.getClass().getName(),             locale).getString("property.desc."+mName.getName());}

 For the localization texts a new resource bundle has to be created. In this sample the resource bundle is located in the same package structure as the implementation is. The resource bundle must be defined at least in the default bundle <BundleName>.properties. Additional bundles for different languages can of course be added.

 The resource bundle file should then look like this:

value.lbl.SampleProperty.techKey.0=(default value)value.lbl.SampleProperty.techKey.1=Value 1value.lbl.SampleProperty.techKey.2=Value 2value.lbl.SampleProperty.techKey.3=Value 3value.lbl.SampleProperty.techKey.4=Value 4value.lbl.SampleProperty.techKey.5=Value 5value.lbl.SampleProperty.techKey.6=Value 6value.lbl.SampleProperty.techKey.7=Value 7value.lbl.SampleProperty.techKey.8=Value 8value.lbl.SampleProperty.techKey.9=Value 9property.lbl.SampleProperty=Sample Propertyproperty.desc.SampleProperty=This is a sample property ...

 Both the Java code and the resource bundle should be deployed together later on.

 Methods to be implemented:


Method


Purpose


getAllowedValues()


Return a list with all possible values for the corresponding meta name and meta context.


getValueLabel()


Returns a localized string representation for the corresponding IMetaValue.


getDefaultValue()


Returns a default value for the corresponding IMetaName.


getPropertyLabel()


Returns a localized string label representation for the IMetaName.


getPropertyDescription()


Returns a localized description for the IMetaName.

Implementing the IValidation Interface:

The interface defines certain methods to be implemented. The validate() method takes care of the validation of the property's value. Therefore it is mandatory to implement it.

 public IValidationErrorList validate(IMetaName metaName,         IProperty property, IMetaContext metaContext) throws             PropertyConfigurationServiceException {				        IValidationErrorList errors =      this.model.createEmptyValidationErrorList();

If the check is not passed, you have to create an IValidationError object that can be added to the error list. The object must be created with references to the model, the meta-name it belongs to, the validation class, and an error ID that is used for a localized error message later on.

IValidationError error = this.model.createValidationError(        this.model,        metaName,        this,        ERROR_ID_INVALID_LENGTH    );

 The method either returns a list of errors (IValidationErrorList) or null if the validation is passed. In case a list is generated, IValidationError objects have to be placed into the list.

  return (errors.isEmpty() ? null : errors);

The error messages are returned in a localized string from the getErrorMessage() method.

public String getErrorMessage(String errorID,         IMetaNameList metaNames, Locale locale, Map additionalInformation)             throws PropertyConfigurationServiceException {        return ResourceBundle.getBundle(this.getClass().getName(),     }

Methods to be implemented:


Method


Purpose


getErrorMessage()


Returns a localized string of the error message.


validate()


Validates the value of the property and returns an list of errors or null if the validation checks are passed.

Configuration:

After deployment of the Java part, some configuration steps have to be done in the standard configuration UI for KMC.

Mapping for Metadata Extensions:

The newly created dynamic value provider has to be registered as a Metadata Extension in the Global Service "Property Metadata." Create a new Metadata Extension, specifying the "Dynamic Value Class" and the "Bundle File" properties.


 
 
 
 
 
 
 
 
 
 
 
 
After committing the new Metadata Extension it should be immediately available in the configuration. For the validation class, a new Metadata Extension configuration can be generated. Assign the Validation class implementation and the Bundle File to the newly created configuration.

 
 
 
  
 

Alternatively you can combine both Dynamic value class and Validation class in one configuration object.

Create a New Property:

To make the new Metadata Extension work in the Upload and Details iView, you have to model a new property in the Global Service "Property Metadata."
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
Define all required attributes for the property and assign the previously created Metadata Extension to the property.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
After saving the property definition, the property now should appear in the Upload and Details iView under the tab "Miscellaneous," unless you have assigned it to another group.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
Sample Metadata Extension

The following archive contains a valid and deployable SAP NetWeaver Developer Studio project based on KM API of NW04 SPS 11, which shows the steps described above in a whole example.

For an example, download the file com.sap.netweaver.kmc.metaextension.zip 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

3 Comments

  1. Former Member

    Is this code located anywhere?

    Without it, it's impossible to understand what the "model" variable type is, or how to instantiate it.  If the code isn't available, could more of this be created here?  I know it's an old article, but still relevant in NW 7.4 today.

  2. Former Member

    So - the answer is - your class should implement IValidation, IDynamicValues or both as stated above, then simply add a private member variable called "model" of type "IMetaModel" and this should be all you need.

    For anyone else reading this and missing the final piece.