Wednesday, November 30, 2016

CMIS - adding new aspect removed existing aspects problem

I had a problem where there were existing custom aspects/attributes already applied to an existing object with a createObject api.

A post process needed to apply additional aspects (for migration purposes) to set the legacy object id information.  It ended up blowing away the existing aspect and properties!

Environment:
OSX El Capitan 10.11.6
java version "1.8.0_101"
Alfresco 5.1.0/ CMIS 1.1
Apache chemistry chemistry-opencmis-client-impl 0.14.0

Problem:
Existing post processing code was attempting to add the new migrated aspect to the properties map.  You can see it setting the “PropertyIds.SECONDARY_OBJECT_TYPE_IDS” property with the new type.  This is going to replace any “PropertyIds.SECONDARY_OBJECT_TYPE_IDS” that may have previously existed!

List<String> secondaryTypeProps = new ArrayList<String>();
secondaryTypeProps.add(CmisConstants.CST_ASPECT_MIGRATED_EVENT);

Map<String, Object> properties = new HashMap<String, Object>();
properties.put(PropertyIds.SECONDARY_OBJECT_TYPE_IDS, secondaryTypeProps);
… add new custom properties

Solution:
Since you are completely replacing the "PropertyIds.SECONDARY_OBJECT_TYPE_IDS" property, you need to retrieve the existing value(s) first, and then add any new aspect(s) to it.

// Retrieve existing aspects
List<Object> aspects = obj.getProperty(PropertyIds.SECONDARY_OBJECT_TYPE_IDS).getValues();
aspects.add(CmisConstants.CST_ASPECT_MIGRATED_EVENT);

// Following adds the new aspect for migrate event aspect
Map<String, Object> properties = new HashMap<String, Object>();
properties.put(PropertyIds.SECONDARY_OBJECT_TYPE_IDS, aspects);
… add new custom properties

No comments:

Post a Comment

I appreciate your time in leaving a comment!