2

In FileNet P8, I need to get the datatype of the property of a custom class using JAVA API. Is there any way to do the same?

2 Answers 2

6

This should give you an idea of what you need to do:

    //SymbolicName of the property we will search for.
    String strSearchName = PropertyNames.DATE_LAST_MODIFIED;
    //Document (or other object) that we will use to get classDescription.
    Document document = (Document) arg0; 

    PropertyDescription objPropDesc = null;
    PropertyDescriptionList pdl = document.get_ClassDescription().get_PropertyDescriptions();
    Iterator<?> iter = pdl.iterator();
    while (iter.hasNext())
    {                                               
        objPropDesc = (PropertyDescription) iter.next();                      

       // Get SymbolicName property from the property cache
       String strPropDescSymbolicName = objPropDesc.get_SymbolicName();

       if (strPropDescSymbolicName.equalsIgnoreCase(strSearchName))
       {
          // PropertyDescription object found
          System.out.println("Property description selected: " + strPropDescSymbolicName);
          System.out.println(objPropDesc);

          TypeID type = objPropDesc.get_DataType();
          System.out.println(type.toString());
          break;
       }
    }

The idea is to:

  1. Take an object (Document in this case).
  2. Get its Class Description.
  3. Get the list of Property Descriptions from the Class Description.
  4. Loop through the Property Descritpions until you locate the Description you are trying to find.
  5. Get the TypeId from the Property Description.
  6. The TypeId contains the information you need to know what the Type is of the Property.

I borrowed code from here : Working with Properties

You should also familiarize yourself with this : Properties

Edit to add a different method:

In the case of creating documents, we need to be able to obtain the Class Description object. This means we will need to perform additional round trips.

// Get the ClassDescription
String strSymbolicName = "myClassName";
ClassDescription objClassDesc = Factory.ClassDescription.fetchInstance(myObjStore, strSymbolicName, null);

// find the PropertyDescription     
PropertyDescription pds = null;
PropertyDescriptionList pdl = objClassDesc.get_PropertyDescriptions()‌​;
Iterator<?> itr = pdl.iterator();
while(itr.hasNext()){ 
    pds = (PropertyDescription) itr.next();
    System.out.println("Symbolic Name is "+pds.get_SymbolicName()+" DataType is "+pds.get_DataType().toString()); 
}

// You can now use it in a loop of several documents if you wish.
...

Take a look here as well : Working With Classes

8
  • I don't think this will work for me. In my case, I need to add the new document to the FileNet. The properties are passed as key value pairs.
    – Arjun
    Oct 17, 2016 at 10:38
  • Document myDocument = Factory.Document.fetchInstance(myObjStore, aDocument.getDocumentClassName(), null); PropertyDescription pds = null; PropertyDescriptionList pdl = myDocument.get_ClassDescription().get_PropertyDescriptions(); Iterator<?> itr = pdl.iterator(); while(itr.hasNext()){ pds = (PropertyDescription) itr.next(); System.out.println("Symbolic Name is "+pds.get_SymbolicName()+" DataType is "+pds.get_DataType().toString()); }
    – Arjun
    Oct 17, 2016 at 10:41
  • What exception are you getting? You may need to fetch the Properties of your pds object first. Your document's class would already be defined, so the Property is already defined. I'm assuming that you want to know the datatype to ensure you are placing the right datatype into the filenet Property value. Oct 18, 2016 at 13:41
  • Document myDocument =Factory.Document.createInstance(myObjStore, aDocument.getDocumentClassName()); PropertyDescription pds = null; PropertyDescriptionList pdl = myDocument.get_ClassDescription().get_PropertyDescriptions(); Iterator<?> itr = pdl.iterator(); while(itr.hasNext()){ pds = (PropertyDescription) itr.next(); System.out.println("Symbolic Name is "+pds.get_SymbolicName()+" DataType is "+pds.get_DataType().toString()); }
    – Arjun
    Oct 19, 2016 at 5:42
  • With the above code I am getting the error as API_PROPERTY_NOT_IN_CACHE ClassDescription property not in property collection.
    – Arjun
    Oct 19, 2016 at 5:44
0

Christopher Powell's answer is correct, there is one thing it does not cover, though (depending on the definition of the custom class in question). Consider this as a "best practice" or just an extension of the code borrowed from the URL that Christopher mentioned.

The FileNet P8 class hierarchy allows for inheritance of property definitions. Simple example: one can search through the 'Document' class - which is the root class of the class hierarchy - of an object store, and use some property of a subclass in the search sql. Imagine Subclass1 as an immediate subclass of Document. Subclass1 has a property Property1. Even if Document does not have this property in its class description, a search in Document with Property1='somevalue' will return objects of Subclass1 (if there is a match with 'somevalue').

However,

objClassDesc.get_PropertyDescriptions()‌​;

won't return property descriptions of subclasses, thus you might end up with API_PROPERTY_NOT_IN_CACHE errors. To give you a good starting point if you are facing this case, look at below code:

PropertyDescriptionList ownProps = objClassDesc.get_PropertyDescriptions();
PropertyDescriptionList subclassProps = null;
if (objClassDesc.get_HasProperSubclassProperties()) {
    logger.debug("Document class '"+documentClassname+"' supports 'include descendant properties' queries, including descendant properties.");
    subclassProps = objClassDesc.get_ProperSubclassPropertyDescriptions();
}

List<PropertyDescription> result = mergePropertyDescriptionLists(ownProps, subclassProps);

If you need to merge those two lists, you are better off using a List of PropertyDescription objects instead of PropertyDescriptionList: the ones returned by the server are read-only.

@SuppressWarnings("unchecked")
protected List<PropertyDescription> mergePropertyDescriptionLists(PropertyDescriptionList list1, PropertyDescriptionList list2) throws Exception {  
    try {
        @SuppressWarnings("unchecked")
        List<PropertyDescription> mergedList = new ArrayList<PropertyDescription>();
        if (list1 != null && (list1.size() > 0)) {
            mergedList.addAll(list1);
        }
        if (list2 != null && (list2.size() > 0)) {
            mergedList.addAll(list2);
        }
        return mergedList;
    } catch (Throwable t) {
        throw new Exception("Failed to merge property description lists.", t);
    }
    
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.