boolean cmis11 = context.getCmisVersion() != CmisVersion.CMIS_1_0;
validateProperties(repositoryId, so, properties, false, cmis11);
if (changeToken != null && changeToken.getValue() != null
&& Long.valueOf(so.getChangeToken()) > Long.valueOf(changeToken.getValue())) {
throw new CmisUpdateConflictException("updateProperties failed: changeToken does not match");
}
// update properties
boolean hasUpdatedProp = false;
// Find secondary type definitions to consider for update
List<String> existingSecondaryTypeIds = so.getSecondaryTypeIds();
@SuppressWarnings("unchecked")
PropertyData<String> pdSec = (PropertyData<String>) properties.getProperties().get(PropertyIds.SECONDARY_OBJECT_TYPE_IDS);
List<String> newSecondaryTypeIds = pdSec == null ? null : pdSec.getValues();
Set<String> secondaryTypeIds = new HashSet<String>();
if (null != existingSecondaryTypeIds)
secondaryTypeIds.addAll(existingSecondaryTypeIds);
if (null != newSecondaryTypeIds)
secondaryTypeIds.addAll(newSecondaryTypeIds);
// Find secondary type definitions to delete (null means not set --> do not change, empty --> remove all secondary types)
if (null != newSecondaryTypeIds) {
List<String> propertiesIdToDelete = getListOfPropertiesToDeleteFromRemovedSecondaryTypes(repositoryId, so, newSecondaryTypeIds);
for (String propIdToRemove : propertiesIdToDelete) {
so.getProperties().remove(propIdToRemove);
}
}
// update properties:
if(properties != null) {
for (String key : properties.getProperties().keySet()) {
if (key.equals(PropertyIds.NAME)) {
continue; // ignore here
}
PropertyData<?> value = properties.getProperties().get(key);
PropertyDefinition<?> propDef = typeDef.getPropertyDefinitions().get(key);
if (null == propDef && cmis11) {
TypeDefinition typeDefSecondary= getSecondaryTypeDefinition(repositoryId, secondaryTypeIds, key);
if (null == typeDefSecondary)
throw new CmisInvalidArgumentException("Cannot update property " + key + ": not contained in type");
propDef = typeDefSecondary.getPropertyDefinitions().get(key);
}
if (value.getValues() == null || value.getFirstValue() == null) {
// delete property
// check if a required a property
if (propDef.isRequired()) {
throw new CmisConstraintException(
"updateProperties failed, following property can't be deleted, because it is required: "
+ key);
}
oldProperties.remove(key);
hasUpdatedProp = true;
} else {
if (propDef.getUpdatability().equals(Updatability.WHENCHECKEDOUT)) {
if (!isCheckedOut)
throw new CmisUpdateConflictException(
"updateProperties failed, following property can't be updated, because it is not checked-out: "
+ key);
} else if (!propDef.getUpdatability().equals(Updatability.READWRITE)) {
throw new CmisConstraintException(
"updateProperties failed, following property can't be updated, because it is not writable: "