Question

Is there any way to programmatically understand what properties there are for a custom model in Alfresco?

For example, data dictionary in oracle helps you to find what tables are defined by which column names and column data types.

My goal is a sample code in java which extracts all custom defined content models, their attributes, their attributes data types, etc. For example my sample code should return to me that there is a custom content Model which has an integer attribute with name 'No' and a string attribute with name 'Description'. I know this is possible with DictionaryComponent, But I don't know how should I use it.

Was it helpful?

Solution 2

thanks a lot of alfresian responses, My code sample is something like below: I found the sample code from : this URL

    public void GetAllAvailableDataTypes() throws IOException
{
    Session session = getSession(); 
    boolean includePropertyDefintions = true;
      for (Tree t : session.getTypeDescendants(
            null, // start at the top of the tree
            -1, // infinite depth recursion
            includePropertyDefintions // include prop defs
            )) {
         printTypes(t, "");
      }
}


public void printTypes(Tree tree, String tab) {          
      ObjectType objType = (ObjectType) tree.getItem();
      String type =  objType.getId();
      if(true)//type.endsWith("hstcase"))
      {
          System.out.println(tab + "TYPE:" + objType.getDisplayName() +
            " (" + objType.getDescription() + ")");
          //Print some of the common attributes for this type
          System.out.print(tab + " Id:" + "-----"+ objType.getId() + "-----");                          
          System.out.print(" Fileable:" + objType.isFileable());
          System.out.print(" Queryable:" + objType.isQueryable());

          if (objType instanceof DocumentType) {                        
              System.out.print(" [DOC Attrs->] Versionable:" +
                      ((DocumentType)objType).isVersionable());
              System.out.println(" Content:" +
                      ((DocumentType)objType).getContentStreamAllowed());
        Map<String, org.apache.chemistry.opencmis.commons.definitions.PropertyDefinition<?>> props = objType.getPropertyDefinitions();
        Set<String> keys = props.keySet();
        Collection<org.apache.chemistry.opencmis.commons.definitions.PropertyDefinition<?>> porpsAsCollection = props.values();
        for(org.apache.chemistry.opencmis.commons.definitions.PropertyDefinition<?> p: porpsAsCollection)
        {
            //System.out.println(p.getDescription());
            PropertyType pt = p.getPropertyType();
            System.out.println("Display Name: "+ p.getDisplayName());
            System.out.println("Local Name: "+ p.getLocalName());
            System.out.println("Attribute Type: "+ pt.value());      
        }           
      }
      System.out.println(""); // end the line
      }
      List<Tree> childs = tree.getChildren();
      for (Tree t : childs) {
         // there are more - call self for next level
         printTypes(t, tab + " ");
      }

}

OTHER TIPS

Take a look at org.alfresco.service.cmr.dictionary.DictionaryService.

will your Java-code running in-context with alfresco (as part of the /alfresco webapp) or outside?

If your running in-context, then Alfreso Java Foundation API is your choice where DictionaryService is part of. just inject the bean into your java code.

If your code is running outside of alfresco, then Alfresco REST API or CMIS is your choice.

If you're still lost, then train yourself first. Jeff wrote some good articles http://ecmarchitect.com/alfresco-developer-series & also a book.

Also a good starting point - Alfresco Developer Docs: http://docs.alfresco.com/4.2/topic/com.alfresco.enterprise.doc/concepts/dev-for-developers.html

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top