Properties from aspects not set in CMIS 1.1

462 Views Asked by At

We have a problem with a Folder object and custom aspects:

...
properties.put(PropertyIds.OBJECT_TYPE_ID, "F:sd:folderDocument,P:sd:info");
properties.put("sd:cause", "asdfg");
Folder stDocument = folder.createFolder(properties);
...

Conten of sd:cause is "nothing" in CMIS 1.1 but in CMIS 1.0 work fine.

NOT WORK!

params.put(SessionParameter.ATOMPUB_URL, "http://localhost:8084/alfresco/api/-default-/public/cmis/versions/1.1/atom");

WORK!

params.put(SessionParameter.ATOMPUB_URL, "http://localhost:8084/alfresco/api/-default-/public/cmis/versions/1.0/atom");

We need work in version 1.1

2

There are 2 best solutions below

2
Jeff Potts On BEST ANSWER

In CMIS 1.1 you add an aspect by adding the aspect type ID to the cmis:secondaryObjectTypeIds property. Here is an example: https://gist.github.com/jpotts/7242070

Make sure you are NOT using the alfresco object factory from the CMIS extensions project when using CMIS 1.1.

1
Fernando González On

The unit test with cmis:secondaryObjectTypeIds is:

    @Test
    public void createStDocumentWithCMIS11() {
        String folderId = "workspace://SpacesStore/03de40f1-e80d-4e0d-8b67-67e93f6e30a1";

        // Connection and session to CMIS 1.1
        HashMap<String, String> params = new HashMap<>();
        params.put(SessionParameter.ATOMPUB_URL, "http://localhost:8084/alfresco/api/-default-/cmis/versions/1.1/atom");
        params.put(SessionParameter.USER, "admin");
        params.put(SessionParameter.PASSWORD, "admin");
        params.put(SessionParameter.BINDING_TYPE, BindingType.ATOMPUB.value());
        params.put(SessionParameter.OBJECT_FACTORY_CLASS, "org.alfresco.cmis.client.impl.AlfrescoObjectFactoryImpl");

        SessionFactory factory = SessionFactoryImpl.newInstance();
        Session session = factory.getRepositories(params).get(0).createSession();

        // Find root folder
        Folder folder = (Folder) session.getObject(folderId);
        assertNotNull(folder);

        // Properties for type
        Map<String, Object> properties = new HashMap<>();
        properties.put(PropertyIds.NAME, "Test CMIS folder type stDocument");
        properties.put(PropertyIds.OBJECT_TYPE_ID, "F:sd:structDocument");
        properties.put("sd:situation", "situation");

        // Create folder
        Folder stDocument = folder.createFolder(properties);
        assertNotNull(stDocument);

        // Add secondary objects (Aspects)
        List<Object> aspects = stDocument.getProperty("cmis:secondaryObjectTypeIds").getValues();
        aspects.add("P:sd:additionalInfo");
        HashMap<String, Object> props = new HashMap<>();
        props.put("cmis:secondaryObjectTypeIds", aspects);
        stDocument.updateProperties(props);

        // Add aspect's property
        HashMap<String, Object> propsAspects = new HashMap<>();
        propsAspects.put("sd:cause", "test");
        stDocument.updateProperties(propsAspects);

        assertEquals("test", stDocument.getProperty("sd:cause").getValueAsString());
    }

But not work... :(

Error in JUnit

Field is empty