Skip to Content
author's profile photo Former Member
Former Member

Code for setting KM Folder properties(standard & custom)

Hi,

How do I programatically set the KM Folder properties(standard as well as custom defined) ?

Also, how do I programatically set KM Document properties(standard & custom) and its Permissions ?

(I have NWDS setup to do the development)

Any API references or code samples or documentation would be of great help

thanks

Ashish

Add a comment
10|10000 characters needed characters exceeded

Related questions

3 Answers

  • Posted on Aug 08, 2006 at 12:04 AM
    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Aug 08, 2006 at 05:34 AM

    Hi

    you can use com.sap.netweaver.bc.rf.common.property.SystemPropertyFactory.create....(.....) methods or constructors of some of property classes.

    for. e.g.

    com.sap.netweaver.bc.rf.common.property.stringtype.StringSingleValueProperty...

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Sep 19, 2006 at 06:52 PM

    You could do something like this...

    path is the location of the resource in KM.

    namespace is the namespace of the property you would like to set.

    name is the id of the property you would like to set.

    value is what you want to set it to.

    public static boolean setPropertyValueOfResource(String path, String namespace, String name, String value)
    {
            try
    	{
    		RID file = RID.getRID(path);
    		IUser user = WPUMFactory.getServiceUserFactory().getServiceUser("cmadmin_service");
    		IResourceContext rContext = new ResourceContext(user);
    		IResource fileResource = ResourceFactory.getInstance().getResource(file, rContext);
    		IPropertyName pName = new PropertyName(namespace, name);
    		IProperty prop = new Property(pName, value);
    		fileResource.setProperty(prop);
    		return true;
    	}
    	catch(NullPointerException E)
    	{
    		...
    	} 
    	catch(UserManagementException e)
    	{
    		...
    	} 
    	catch(ResourceException e)
    	{
    		...
    	}
    }
    

    You can also get the property value of a resource.

    public static String getPropertyValueOfResource(String path, String namespace, String name)
    {
    	try
    	{
    		RID file = RID.getRID(path);
    		IUser user = WPUMFactory.getServiceUserFactory().getServiceUser("cmadmin_service");
    		IResourceContext rContext = new ResourceContext(user);
    		IResource fileResource = ResourceFactory.getInstance().getResource(file, rContext);
    		IPropertyName pName = new PropertyName(namespace, name);
    		IProperty property = fileResource.getProperty(pName);
    				
    		return property.getValueAsString();
    	}
    	catch(NullPointerException E)
    	{
    		...
    	} 
    	catch(UserManagementException e)
    	{
    		...
    	} 
    	catch(ResourceException e)
    	{
    		...
    	}
    }
    

    You can also get the available values for the property

    public static String[] getAllowedPropertyValues(String propertyId, String namespace)
    {
    	try
    	{
    		IPropertyConfigurationService propConfigService =(IPropertyConfigurationService)ResourceFactory.getInstance().getServiceFactory().getService("PropertyConfigurationService");
     
    		IMetaModel metaModel = propConfigService.getMetaModel();
    		IPropertyName propertyName = new PropertyName(namespace, propertyId);
    		IMetaName metaName = metaModel.searchByPropertyName(propertyName);
    		IMetaValueListIterator iterator = metaName.allowedValueIterator();
    
    		String values = "";
    				
    		while(iterator.hasNext()) 
    		{
    			IMetaValue m = iterator.next();
    			values += m.getValue() + ";";
    		}
    				
    		return values.split(";");
    	}
    	catch (ResourceException e) 
    	{
    		...
    	}
    	catch (PropertyConfigurationServiceException e)
    	{
    		...
    	}
    }
    

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member

      Hi Eric,

      I used the code suggested by you, but i m getting NullPointerException in the following statement:

      IUser user = WPUMFactory.getServiceUserFactory().getServiceUser("cmadmin_service");

      Please help me out.

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.