public void updateProperties(CallContext context, String repositoryId, Holder<String> objectId,
Holder<String> changeToken, Properties properties, Acl acl, ExtensionsData extension,
ObjectInfoHandler objectInfos) {
LOG.debug("start updateProperties()");
StoredObject so = validator.updateProperties(context, repositoryId, objectId, extension);
String user = context.getUsername();
// Validation
TypeDefinition typeDef = getTypeDefinition(repositoryId, so);
boolean isCheckedOut = false;
// if the object is a versionable object it must be checked-out
if (so instanceof VersionedDocument || so instanceof DocumentVersion) {
// VersionedDocument verDoc =
// testIsNotCheckedOutBySomeoneElse(so, user);
testHasProperCheckedOutStatus(so, user);
isCheckedOut = true;
}
Map<String, PropertyData<?>> oldProperties = so.getProperties();
// check properties for validity
TypeValidator.validateProperties(typeDef, properties, false);
if (changeToken != null && changeToken.getValue() != null
&& Long.valueOf(so.getChangeToken()) > Long.valueOf(changeToken.getValue())) {
throw new CmisUpdateConflictException(" updateProperties failed: outdated changeToken");
}
// update properties
boolean hasUpdatedName = false;
boolean hasUpdatedOtherProps = false;
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 (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);
hasUpdatedOtherProps = true;
} else {
if (propDef.getUpdatability().equals(Updatability.WHENCHECKEDOUT) && !isCheckedOut) {
throw new CmisConstraintException(
"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: "
+ key);
}
oldProperties.put(key, value);
hasUpdatedOtherProps = true;
}
}
// get name from properties and perform special rename to check if
// path already exists
PropertyData<?> pd = properties.getProperties().get(PropertyIds.NAME);
if (pd != null && so instanceof Filing) {
String newName = (String) pd.getFirstValue();
List<Folder> parents = ((Filing) so).getParents(user);
if (so instanceof Folder && parents.isEmpty()) {
throw new CmisConstraintException("updateProperties failed, you cannot rename the root folder");
}
if (newName == null || newName.equals("")) {
throw new CmisConstraintException("updateProperties failed, name must not be empty.");
}
so.rename((String) pd.getFirstValue()); // note: this does persist
hasUpdatedName = true;
}
if (hasUpdatedOtherProps) {
// set user, creation date, etc.
if (user == null) {
user = "unknown";
}
so.updateSystemBasePropertiesWhenModified(properties.getProperties(), user);
// set changeToken
so.persist();
}
if (hasUpdatedName || hasUpdatedOtherProps) {
objectId.setValue(so.getId()); // might have a new id
if (null != changeToken) {
String changeTokenVal = so.getChangeToken();
LOG.debug("updateProperties(), new change token is: " + changeTokenVal);
changeToken.setValue(changeTokenVal);
}
}
if (null != acl) {
LOG.warn("Setting ACLs is currently not supported by this implementation, acl is ignored");
// if implemented add this call:
// fAclService.appyAcl(context, repositoryId, acl, null,
// AclPropagation.OBJECTONLY,
// extension);
}
TypeDefinition td = fStoreManager.getTypeById(repositoryId, so.getTypeId()).getTypeDefinition();
ObjectData od = PropertyCreationHelper.getObjectData(td, so, null, user, false,
IncludeRelationships.NONE, null, false, false, extension);
// To be able to provide all Atom links in the response we need
// additional information: