cancel
Showing results for 
Search instead for 
Did you mean: 

Cannot set Title, Location on DataListItem using java opencmis

devg107
Champ in-the-making
Champ in-the-making
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);
             
    }
}


1 REPLY 1

devg107
Champ in-the-making
Champ in-the-making
Hi, I've managed to update most properties except the 'Title' using code below. I could not find any relevant property for 'Title' in the data model xml file for title. can someone please suggest. Thanks.

<java>
                properties.put(PropertyIds.OBJECT_TYPE_ID, "D:dl:event,P:cm:attachable,P:cm:titled");
           properties.put("dl:eventLocation","test-Location-"+var_name_extension);
           properties.put("dl:eventStartDate",new Date());
           properties.put("dl:eventEndDate",new Date());
           properties.put("dl:eventRegistrations","team developers");
           properties.put("dl:eventNote","starts at 9 am");
</java>