Search in sources :

Example 11 with PropertyDefinitionWrapper

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);
        }
    }
}
Also used : QName(org.alfresco.service.namespace.QName) CmisConstraintException(org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException) FileNotFoundException(org.alfresco.service.cmr.model.FileNotFoundException) PropertyString(org.apache.chemistry.opencmis.commons.data.PropertyString) Updatability(org.apache.chemistry.opencmis.commons.enums.Updatability) PropertyDefinitionWrapper(org.alfresco.opencmis.dictionary.PropertyDefinitionWrapper) CmisInvalidArgumentException(org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException) CmisContentAlreadyExistsException(org.apache.chemistry.opencmis.commons.exceptions.CmisContentAlreadyExistsException) BigInteger(java.math.BigInteger) FileExistsException(org.alfresco.service.cmr.model.FileExistsException)

Example 12 with PropertyDefinitionWrapper

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;
}
Also used : PropertyDefinitionWrapper(org.alfresco.opencmis.dictionary.PropertyDefinitionWrapper) QName(org.alfresco.service.namespace.QName)

Aggregations

PropertyDefinitionWrapper (org.alfresco.opencmis.dictionary.PropertyDefinitionWrapper)12 PropertyString (org.apache.chemistry.opencmis.commons.data.PropertyString)8 TypeDefinitionWrapper (org.alfresco.opencmis.dictionary.TypeDefinitionWrapper)7 Serializable (java.io.Serializable)6 ArrayList (java.util.ArrayList)6 QName (org.alfresco.service.namespace.QName)6 DocumentTypeDefinitionWrapper (org.alfresco.opencmis.dictionary.DocumentTypeDefinitionWrapper)5 ItemTypeDefinitionWrapper (org.alfresco.opencmis.dictionary.ItemTypeDefinitionWrapper)5 List (java.util.List)4 ObjectList (org.apache.chemistry.opencmis.commons.data.ObjectList)4 Collections.singletonList (java.util.Collections.singletonList)3 CmisExtensionElement (org.apache.chemistry.opencmis.commons.data.CmisExtensionElement)3 CmisConstraintException (org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException)3 CmisInvalidArgumentException (org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException)3 BigInteger (java.math.BigInteger)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 FileExistsException (org.alfresco.service.cmr.model.FileExistsException)2 FileNotFoundException (org.alfresco.service.cmr.model.FileNotFoundException)2 InvalidNodeRefException (org.alfresco.service.cmr.repository.InvalidNodeRefException)2