AnsweredAssumed Answered

Cannot set Title, Location on DataListItem using java opencmis

Question asked by devg107 on Aug 21, 2015
Latest reply on Aug 24, 2015 by devg107
Hi,

We want to write properties into a datalist but are having difficulty populating the fields using a java program.

We're trying to add DataList items into a Event List (built-in type of data list) that we created manually on the Alfresco site. we are able to set the value for property 'Description' on the item being added to my list using the Java code below, but not able to set 'Title' or 'Location' properties on it. Have tried retrieving the newly created item and updating the properties, but that does not work either. Could someone please suggest how to work this out. Please note that my list is not a custom data list.

Thanks
Dev




public class Test
{
    public static void main(String[] args)
    {
       Map<String, String> parameter = new HashMap<String, String>();
       AlfrescoItemType itemType = null;
       // Set the user credentials
       parameter.put(SessionParameter.USER, "admin");
       parameter.put(SessionParameter.PASSWORD, "root");

       // Specify the connection settings
       parameter.put(SessionParameter.ATOMPUB_URL, "http://localhost:8181/alfresco/api/-default-/public/cmis/versions/1.1/atom");
       parameter.put(SessionParameter.BINDING_TYPE, BindingType.ATOMPUB.value());

       // Set the alfresco object factory
       parameter.put(SessionParameter.OBJECT_FACTORY_CLASS, "org.alfresco.cmis.client.impl.AlfrescoObjectFactoryImpl");

       // Create a session
       SessionFactory factory = SessionFactoryImpl.newInstance();
       Session session = factory.getRepositories(parameter).get(0).createSession();
AlfrescoFolder dataLists = (AlfrescoFolder) session.getObjectByPath("/Sites/alerts/dataLists/262abf17-b519-48b2-91d8-1eadb919dae7");
       System.out.println(" dataList object—"+dataLists.getName());

       Map<String, Object> properties = new HashMap<String, Object>();
//   properties.put(PropertyIds.OBJECT_TYPE_ID, "D:dl:dataListItem");
       properties.put(PropertyIds.OBJECT_TYPE_ID, "D:dl:event");
       
   String var_name_extension = "9";
   properties.put(PropertyIds.NAME, "some name"+var_name_extension);
       properties.put(PropertyIds.DESCRIPTION, "some description"+var_name_extension);
//       properties.put("cm:title", "some title3");
       
//    IF BELOW 4 LINES ARE USED, IT CREATES AN ITEM IN THE LIST BUT WITHOUT DESCRIPTION, I see an empty row IN THE LIST
       
//       properties.put(PropertyIds.OBJECT_TYPE_ID, "cmis:document,P:cm:titled");
//      properties.put(PropertyIds.NAME, "some name"+var_name_extension);
//       properties.put("cm:title", "some title");
//       properties.put("cm:description", "some description");
       
   ObjectId newItemId = session.createItem(properties, dataLists);
   System.out.println("newItemId===="+newItemId);
      
   AlfrescoDocument dLItem = (AlfrescoDocument) session.getObjectByPath("/Sites/alerts/dataLists/262abf17-b519-48b2-91d8-1eadb919dae7/some name"+var_name_extension);
//   dLItem.addAspect("D:dl:dataListItem,P:cm:titled", "HELLO");
   Map<String, Object> newProps = new HashMap<String, Object>();
   newProps.put("cm:title", "HELLO");
   dLItem.updateProperties(newProps,true);
             
    }
}


Outcomes