mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-31 17:39:05 +00:00
Fix/mnt 16641 cmis applying aspects including protected properties (REPO-1065) (#20)
* REPO-1065 : Service Pack: MNT-16641 CMIS API: Applying aspects including protected properties results in CmisInvalidArgumentException: Property is read-only! Remove code from CMISConnector.processSecondaryTypes, that for each aspect added, it will search all of his properties in repository and add them with a null value(if not included in the propsToAdd). Add an extra check to CMISTest.testUpdatePropertiesSetDeleteContentVersioning now adding the P:cm:lockable aspect to a document (before this fix failing). Added CMISConnector.isUpdatable returns true/false if a property is updatable
This commit is contained in:
committed by
GitHub
parent
344952540b
commit
366a0e773e
@@ -3097,13 +3097,14 @@ public class CMISConnector implements ApplicationContextAware, ApplicationListen
|
|||||||
throw new CmisInvalidArgumentException("Property " + property.getId() + " is unknown!");
|
throw new CmisInvalidArgumentException("Property " + property.getId() + " is unknown!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Boolean isOnWorkingCopy = checkOutCheckInService.isWorkingCopy(nodeRef);
|
||||||
|
Updatability updatability = propDef.getPropertyDefinition().getUpdatability();
|
||||||
|
if (!isUpdatable(updatability, isOnWorkingCopy))
|
||||||
|
{
|
||||||
|
throw new CmisInvalidArgumentException("Property " + propertyId + " is read-only!");
|
||||||
|
}
|
||||||
|
|
||||||
Updatability updatability = propDef.getPropertyDefinition().getUpdatability();
|
|
||||||
if ((updatability == Updatability.READONLY)
|
|
||||||
|| (updatability == Updatability.WHENCHECKEDOUT && !checkOutCheckInService.isWorkingCopy(nodeRef)))
|
|
||||||
{
|
|
||||||
throw new CmisInvalidArgumentException("Property " + property.getId() + " is read-only!");
|
|
||||||
}
|
|
||||||
TypeDefinitionWrapper propType = propDef.getOwningType();
|
TypeDefinitionWrapper propType = propDef.getOwningType();
|
||||||
Serializable value = getValue(property, propDef.getPropertyDefinition().getCardinality() == Cardinality.MULTI);
|
Serializable value = getValue(property, propDef.getPropertyDefinition().getCardinality() == Cardinality.MULTI);
|
||||||
Pair<TypeDefinitionWrapper, Serializable> pair = new Pair<TypeDefinitionWrapper, Serializable>(propType, value);
|
Pair<TypeDefinitionWrapper, Serializable> pair = new Pair<TypeDefinitionWrapper, Serializable>(propType, value);
|
||||||
@@ -3127,21 +3128,21 @@ public class CMISConnector implements ApplicationContextAware, ApplicationListen
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (String propertyId : propsMap.keySet())
|
for (String propertyId : propsMap.keySet())
|
||||||
{
|
{
|
||||||
if(propertyId.equals(PropertyIds.SECONDARY_OBJECT_TYPE_IDS))
|
if (propertyId.equals(PropertyIds.SECONDARY_OBJECT_TYPE_IDS))
|
||||||
{
|
{
|
||||||
// already handled above
|
// already handled above
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
pair = propsMap.get(propertyId);
|
pair = propsMap.get(propertyId);
|
||||||
TypeDefinitionWrapper propType = pair.getFirst();
|
TypeDefinitionWrapper propType = pair.getFirst();
|
||||||
Serializable value = pair.getSecond();
|
Serializable value = pair.getSecond();
|
||||||
if (Arrays.binarySearch(exclude, propertyId) < 0)
|
if (Arrays.binarySearch(exclude, propertyId) < 0)
|
||||||
{
|
{
|
||||||
setProperty(nodeRef, propType, propertyId, value);
|
setProperty(nodeRef, propType, propertyId, value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
List<CmisExtensionElement> extensions = properties.getExtensions();
|
List<CmisExtensionElement> extensions = properties.getExtensions();
|
||||||
@@ -3226,26 +3227,6 @@ public class CMISConnector implements ApplicationContextAware, ApplicationListen
|
|||||||
for(QName aspectQName : toAdd)
|
for(QName aspectQName : toAdd)
|
||||||
{
|
{
|
||||||
nodeService.addAspect(nodeRef, aspectQName, null);
|
nodeService.addAspect(nodeRef, aspectQName, null);
|
||||||
|
|
||||||
// get aspect properties
|
|
||||||
AspectDefinition aspectDef = dictionaryService.getAspect(aspectQName);
|
|
||||||
Map<QName, org.alfresco.service.cmr.dictionary.PropertyDefinition> 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<TypeDefinitionWrapper, Serializable> pair = new Pair<TypeDefinitionWrapper, Serializable>(propType, null);
|
|
||||||
propsToAdd.put(propertyId, pair);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3579,13 +3560,13 @@ public class CMISConnector implements ApplicationContextAware, ApplicationListen
|
|||||||
{
|
{
|
||||||
throw new CmisInvalidArgumentException("Property " + propertyId + " is unknown!");
|
throw new CmisInvalidArgumentException("Property " + propertyId + " is unknown!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Boolean isOnWorkingCopy = checkOutCheckInService.isWorkingCopy(nodeRef);
|
||||||
Updatability updatability = propDef.getPropertyDefinition().getUpdatability();
|
Updatability updatability = propDef.getPropertyDefinition().getUpdatability();
|
||||||
if ((updatability == Updatability.READONLY)
|
if (!isUpdatable(updatability, isOnWorkingCopy))
|
||||||
|| (updatability == Updatability.WHENCHECKEDOUT && !checkOutCheckInService.isWorkingCopy(nodeRef)))
|
{
|
||||||
{
|
throw new CmisInvalidArgumentException("Property " + propertyId + " is read-only!");
|
||||||
throw new CmisInvalidArgumentException("Property " + propertyId + " is read-only!");
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if(propDef.getPropertyId().equals(PropertyIds.SECONDARY_OBJECT_TYPE_IDS))
|
if(propDef.getPropertyId().equals(PropertyIds.SECONDARY_OBJECT_TYPE_IDS))
|
||||||
{
|
{
|
||||||
@@ -3610,7 +3591,7 @@ public class CMISConnector implements ApplicationContextAware, ApplicationListen
|
|||||||
{
|
{
|
||||||
String newName = value.toString();
|
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 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);
|
String wcLabel = (String)this.nodeService.getProperty(nodeRef, ContentModel.PROP_WORKING_COPY_LABEL);
|
||||||
if (wcLabel == null)
|
if (wcLabel == null)
|
||||||
@@ -4109,5 +4090,24 @@ public class CMISConnector implements ApplicationContextAware, ApplicationListen
|
|||||||
singletonCache.put(KEY_CMIS_RENDITION_MAPPING_NODEREF, renditionMapping);
|
singletonCache.put(KEY_CMIS_RENDITION_MAPPING_NODEREF, renditionMapping);
|
||||||
}
|
}
|
||||||
return renditionMapping;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -3352,7 +3352,19 @@ public class CMISTest
|
|||||||
|
|
||||||
cmisService.updateProperties(repositoryId, new Holder<String>(fileInfo.getNodeRef().toString()), null, properties, null);
|
cmisService.updateProperties(repositoryId, new Holder<String>(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<QName> existingAspects = nodeService.getAspects(docs.get(0).getNodeRef());
|
||||||
|
cmisService.updateProperties(repositoryId,new Holder<String>(docs.get(0).getNodeRef().toString()), null, properties, null);
|
||||||
|
Set<QName> updatedAspects = nodeService.getAspects(docs.get(0).getNodeRef());
|
||||||
|
updatedAspects.removeAll(existingAspects);
|
||||||
|
|
||||||
|
assertEquals(ContentModel.ASPECT_LOCKABLE, updatedAspects.iterator().next());
|
||||||
|
|
||||||
|
}
|
||||||
return repositoryId;
|
return repositoryId;
|
||||||
}
|
}
|
||||||
}, CmisVersion.CMIS_1_1);
|
}, CmisVersion.CMIS_1_1);
|
||||||
|
Reference in New Issue
Block a user