use of org.alfresco.opencmis.dictionary.PropertyDefinitionWrapper in project alfresco-repository by Alfresco.
the class CMISConnector method setProperty.
/**
* Sets a property value.
*/
public void setProperty(NodeRef nodeRef, TypeDefinitionWrapper type, String propertyId, Serializable value) {
if (propertyId == null) {
throw new CmisInvalidArgumentException("Cannot process not null property!");
}
PropertyDefinitionWrapper propDef = type.getPropertyById(propertyId);
if (propDef == null) {
throw new CmisInvalidArgumentException("Property " + propertyId + " is unknown!");
}
Boolean isOnWorkingCopy = checkOutCheckInService.isWorkingCopy(nodeRef);
Updatability updatability = propDef.getPropertyDefinition().getUpdatability();
if (!isUpdatable(updatability, isOnWorkingCopy)) {
throw new CmisInvalidArgumentException("Property " + propertyId + " is read-only!");
}
if (propDef.getPropertyId().equals(PropertyIds.SECONDARY_OBJECT_TYPE_IDS)) {
throw new IllegalArgumentException("Cannot process " + PropertyIds.SECONDARY_OBJECT_TYPE_IDS + " in setProperty");
} else {
QName propertyQName = propDef.getPropertyAccessor().getMappedProperty();
if (propertyQName == null) {
throw new CmisConstraintException("Unable to set property " + propertyId + "!");
}
if (propertyId.equals(PropertyIds.NAME)) {
if (!(value instanceof String)) {
throw new CmisInvalidArgumentException("Object name must be a string!");
}
try {
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 (isOnWorkingCopy) {
String wcLabel = (String) this.nodeService.getProperty(nodeRef, ContentModel.PROP_WORKING_COPY_LABEL);
if (wcLabel == null) {
wcLabel = CheckOutCheckInServiceImpl.getWorkingCopyLabel();
}
if (!newName.contains(wcLabel)) {
newName = CheckOutCheckInServiceImpl.createWorkingCopyName(newName, wcLabel);
}
}
fileFolderService.rename(nodeRef, newName);
} catch (FileExistsException e) {
throw new CmisContentAlreadyExistsException("An object with this name already exists!", e);
} catch (FileNotFoundException e) {
throw new CmisInvalidArgumentException("Object with id " + nodeRef.getId() + " not found!");
}
} else {
// overflow check
if (propDef.getPropertyDefinition().getPropertyType() == PropertyType.INTEGER && value instanceof BigInteger) {
org.alfresco.service.cmr.dictionary.PropertyDefinition def = dictionaryService.getProperty(propertyQName);
QName dataDef = def.getDataType().getName();
BigInteger bigValue = (BigInteger) value;
if ((bigValue.compareTo(maxInt) > 0 || bigValue.compareTo(minInt) < 0) && dataDef.equals(DataTypeDefinition.INT)) {
throw new CmisConstraintException("Value is out of range for property " + propertyQName.getLocalName());
}
if ((bigValue.compareTo(maxLong) > 0 || bigValue.compareTo(minLong) < 0) && dataDef.equals(DataTypeDefinition.LONG)) {
throw new CmisConstraintException("Value is out of range for property " + propertyQName.getLocalName());
}
}
nodeService.setProperty(nodeRef, propertyQName, value);
}
}
}
use of org.alfresco.opencmis.dictionary.PropertyDefinitionWrapper in project alfresco-repository by Alfresco.
the class CMISConnector method getSortProperty.
// --------------------------------------------------------------
// Alfresco methods
// --------------------------------------------------------------
/*
* For the given cmis property name get the corresponding Alfresco property name.
*
* Certain CMIS properties (e.g. cmis:creationDate and cmis:lastModifiedBy) don't
* have direct mappings to Alfresco properties through the CMIS dictionary, because
* these mappings should not be exposed outside the repository through CMIS. For these,
* however, this method provides the mapping so that the sort works.
*
*/
public Pair<QName, Boolean> getSortProperty(String cmisPropertyName, String direction) {
QName sortPropName = null;
Pair<QName, Boolean> sortProp = null;
PropertyDefinitionWrapper propDef = getOpenCMISDictionaryService().findPropertyByQueryName(cmisPropertyName);
if (propDef != null) {
if (propDef.getPropertyId().equals(PropertyIds.BASE_TYPE_ID)) {
// special-case (see also ALF-13968) - for getChildren, using "cmis:baseTypeId" allows sorting of folders first and vice-versa (cmis:folder <-> cmis:document)
sortPropName = GetChildrenCannedQuery.SORT_QNAME_NODE_IS_FOLDER;
} else {
sortPropName = propDef.getPropertyAccessor().getMappedProperty();
}
if (sortPropName == null) {
// ok to map these properties because we are always getting current versions of nodes
sortPropName = SORT_PROPERTY_MAPPINGS.get(cmisPropertyName);
}
}
if (sortPropName != null) {
boolean sortAsc = (direction == null ? true : direction.equalsIgnoreCase("asc"));
sortProp = new Pair<QName, Boolean>(sortPropName, sortAsc);
} else {
if (logger.isDebugEnabled()) {
logger.debug("Ignore sort property '" + cmisPropertyName + " - mapping not found");
}
}
return sortProp;
}
Aggregations