diff --git a/src/main/java/org/alfresco/opencmis/CMISConnector.java b/src/main/java/org/alfresco/opencmis/CMISConnector.java index c5f6d47b90..e2a0e12263 100644 --- a/src/main/java/org/alfresco/opencmis/CMISConnector.java +++ b/src/main/java/org/alfresco/opencmis/CMISConnector.java @@ -3098,12 +3098,13 @@ public class CMISConnector implements ApplicationContextAware, ApplicationListen } } + Boolean isOnWorkingCopy = checkOutCheckInService.isWorkingCopy(nodeRef); Updatability updatability = propDef.getPropertyDefinition().getUpdatability(); - if ((updatability == Updatability.READONLY) - || (updatability == Updatability.WHENCHECKEDOUT && !checkOutCheckInService.isWorkingCopy(nodeRef))) + if (!isUpdatable(updatability, isOnWorkingCopy)) { - throw new CmisInvalidArgumentException("Property " + property.getId() + " is read-only!"); + throw new CmisInvalidArgumentException("Property " + propertyId + " is read-only!"); } + TypeDefinitionWrapper propType = propDef.getOwningType(); Serializable value = getValue(property, propDef.getPropertyDefinition().getCardinality() == Cardinality.MULTI); Pair pair = new Pair(propType, value); @@ -3129,7 +3130,7 @@ public class CMISConnector implements ApplicationContextAware, ApplicationListen for (String propertyId : propsMap.keySet()) { - if(propertyId.equals(PropertyIds.SECONDARY_OBJECT_TYPE_IDS)) + if (propertyId.equals(PropertyIds.SECONDARY_OBJECT_TYPE_IDS)) { // already handled above continue; @@ -3219,26 +3220,6 @@ public class CMISConnector implements ApplicationContextAware, ApplicationListen for(QName aspectQName : toAdd) { nodeService.addAspect(nodeRef, aspectQName, null); - - // get aspect properties - AspectDefinition aspectDef = dictionaryService.getAspect(aspectQName); - Map aspectPropDefs = aspectDef.getProperties(); - TypeDefinitionWrapper w = getOpenCMISDictionaryService().findNodeType(aspectQName); - // for each aspect property... - for(QName propQName : aspectPropDefs.keySet()) - { - // find CMIS property id - PropertyDefinitionWrapper property = w.getPropertyByQName(propQName); - String propertyId = property.getPropertyId(); - if(!propsToAdd.containsKey(propertyId)) - { - TypeDefinitionWrapper propType = property.getOwningType(); - // CMIS 1.1 secondary types specification requires that all secondary type properties are set - // property not included in propsToAdd, add it with null value - Pair pair = new Pair(propType, null); - propsToAdd.put(propertyId, pair); - } - } } } @@ -3573,9 +3554,9 @@ public class CMISConnector implements ApplicationContextAware, ApplicationListen throw new CmisInvalidArgumentException("Property " + propertyId + " is unknown!"); } + Boolean isOnWorkingCopy = checkOutCheckInService.isWorkingCopy(nodeRef); Updatability updatability = propDef.getPropertyDefinition().getUpdatability(); - if ((updatability == Updatability.READONLY) - || (updatability == Updatability.WHENCHECKEDOUT && !checkOutCheckInService.isWorkingCopy(nodeRef))) + if (!isUpdatable(updatability, isOnWorkingCopy)) { throw new CmisInvalidArgumentException("Property " + propertyId + " is read-only!"); } @@ -3603,7 +3584,7 @@ public class CMISConnector implements ApplicationContextAware, ApplicationListen { String newName = value.toString(); // If the node is checked out and the name property is set on the working copy, make sure the new name has the working copy format - if (checkOutCheckInService.isWorkingCopy(nodeRef)) + if (isOnWorkingCopy) { String wcLabel = (String)this.nodeService.getProperty(nodeRef, ContentModel.PROP_WORKING_COPY_LABEL); if (wcLabel == null) @@ -4103,4 +4084,23 @@ public class CMISConnector implements ApplicationContextAware, ApplicationListen } return renditionMapping; } + + /** + * Verify if a property is updatable. + * @param updatability + * @param isOnWorkingCopy + * @return + */ + private boolean isUpdatable(Updatability updatability, Boolean isOnWorkingCopy) + { + if ((updatability == Updatability.READONLY) + || (updatability == Updatability.WHENCHECKEDOUT && !isOnWorkingCopy)) + { + return false; + } + else + { + return true; + } + } } diff --git a/src/test/java/org/alfresco/opencmis/CMISTest.java b/src/test/java/org/alfresco/opencmis/CMISTest.java index 3518b87e76..76fc8451f0 100644 --- a/src/test/java/org/alfresco/opencmis/CMISTest.java +++ b/src/test/java/org/alfresco/opencmis/CMISTest.java @@ -3362,7 +3362,19 @@ public class CMISTest cmisService.updateProperties(repositoryId, new Holder(fileInfo.getNodeRef().toString()), null, properties, null); } - + //This extra check was added due to MNT-16641. + { + PropertiesImpl properties = new PropertiesImpl(); + properties.addProperty(new PropertyStringImpl(PropertyIds.SECONDARY_OBJECT_TYPE_IDS, "P:cm:lockable")); + + Set existingAspects = nodeService.getAspects(docs.get(0).getNodeRef()); + cmisService.updateProperties(repositoryId,new Holder(docs.get(0).getNodeRef().toString()), null, properties, null); + Set updatedAspects = nodeService.getAspects(docs.get(0).getNodeRef()); + updatedAspects.removeAll(existingAspects); + + assertEquals(ContentModel.ASPECT_LOCKABLE, updatedAspects.iterator().next()); + + } return repositoryId; } }, CmisVersion.CMIS_1_1);