Search in sources :

Example 36 with CmisInvalidArgumentException

use of org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException 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 37 with CmisInvalidArgumentException

use of org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException in project alfresco-repository by Alfresco.

the class AlfrescoCmisServiceImpl method create.

// --- object service ---
@Override
public String create(String repositoryId, Properties properties, String folderId, ContentStream contentStream, VersioningState versioningState, List<String> policies, ExtensionsData extension) {
    checkRepositoryId(repositoryId);
    // check properties
    if (properties == null || properties.getProperties() == null) {
        throw new CmisInvalidArgumentException("Properties must be set!");
    }
    // get the type
    String objectTypeId = connector.getObjectTypeIdProperty(properties);
    // find the type
    TypeDefinitionWrapper type = connector.getOpenCMISDictionaryService().findType(objectTypeId);
    if (type == null) {
        throw new CmisInvalidArgumentException("Type '" + objectTypeId + "' is unknown!");
    }
    // create object
    String newId = null;
    switch(type.getBaseTypeId()) {
        case CMIS_DOCUMENT:
            versioningState = getDocumentDefaultVersioningState(versioningState, type);
            newId = createDocument(repositoryId, properties, folderId, contentStream, versioningState, policies, null, null, extension);
            break;
        case CMIS_FOLDER:
            newId = createFolder(repositoryId, properties, folderId, policies, null, null, extension);
            break;
        case CMIS_POLICY:
            newId = createPolicy(repositoryId, properties, folderId, policies, null, null, extension);
            break;
        case CMIS_ITEM:
            newId = createItem(repositoryId, properties, folderId, policies, null, null, extension);
            break;
        default:
            break;
    }
    // check new object id
    if (newId == null) {
        throw new CmisRuntimeException("Creation failed!");
    }
    boolean isObjectInfoRequired = getContext().isObjectInfoRequired();
    if (isObjectInfoRequired) {
        try {
            getObjectInfo(repositoryId, newId, "*", IncludeRelationships.NONE);
        } catch (InvalidNodeRefException e) {
            throw new CmisRuntimeException("Creation failed! New object not found!");
        }
    }
    // return the new object id
    return newId;
}
Also used : CmisRuntimeException(org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException) TypeDefinitionWrapper(org.alfresco.opencmis.dictionary.TypeDefinitionWrapper) CmisInvalidArgumentException(org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException) InvalidNodeRefException(org.alfresco.service.cmr.repository.InvalidNodeRefException)

Example 38 with CmisInvalidArgumentException

use of org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException in project alfresco-repository by Alfresco.

the class AlfrescoCmisServiceImpl method deleteTree.

@Override
public FailedToDeleteData deleteTree(String repositoryId, String folderId, Boolean allVersions, UnfileObject unfileObjects, final Boolean continueOnFailure, ExtensionsData extension) {
    checkRepositoryId(repositoryId);
    if (!allVersions) {
        throw new CmisInvalidArgumentException("Only allVersions=true supported!");
    }
    if (unfileObjects == UnfileObject.UNFILE) {
        throw new CmisInvalidArgumentException("Unfiling not supported!");
    }
    final NodeRef folderNodeRef = getOrCreateFolderInfo(folderId, "Folder").getNodeRef();
    final FailedToDeleteDataImpl result = new FailedToDeleteDataImpl();
    try {
        connector.deleteNode(folderNodeRef, true);
    } catch (Exception e) {
        List<String> ids = new ArrayList<String>();
        ids.add(folderId);
        result.setIds(ids);
    }
    return result;
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) CmisInvalidArgumentException(org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException) FailedToDeleteDataImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.FailedToDeleteDataImpl) ObjectInFolderList(org.apache.chemistry.opencmis.commons.data.ObjectInFolderList) ArrayList(java.util.ArrayList) TypeDefinitionList(org.apache.chemistry.opencmis.commons.definitions.TypeDefinitionList) ObjectList(org.apache.chemistry.opencmis.commons.data.ObjectList) List(java.util.List) CmisContentAlreadyExistsException(org.apache.chemistry.opencmis.commons.exceptions.CmisContentAlreadyExistsException) CmisConstraintException(org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException) CmisPermissionDeniedException(org.apache.chemistry.opencmis.commons.exceptions.CmisPermissionDeniedException) CmisRuntimeException(org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException) IOException(java.io.IOException) CmisVersioningException(org.apache.chemistry.opencmis.commons.exceptions.CmisVersioningException) CmisInvalidArgumentException(org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException) FileNotFoundException(org.alfresco.service.cmr.model.FileNotFoundException) CmisObjectNotFoundException(org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException) CmisStorageException(org.apache.chemistry.opencmis.commons.exceptions.CmisStorageException) CmisStreamNotSupportedException(org.apache.chemistry.opencmis.commons.exceptions.CmisStreamNotSupportedException) InvalidNodeRefException(org.alfresco.service.cmr.repository.InvalidNodeRefException) ContentIOException(org.alfresco.service.cmr.repository.ContentIOException)

Example 39 with CmisInvalidArgumentException

use of org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException in project alfresco-repository by Alfresco.

the class AlfrescoCmisServiceImpl method createRelationship.

@Override
public String createRelationship(String repositoryId, Properties properties, List<String> policies, Acl addAces, Acl removeAces, ExtensionsData extension) {
    checkRepositoryId(repositoryId);
    // get type
    String objectTypeId = connector.getObjectTypeIdProperty(properties);
    final TypeDefinitionWrapper type = connector.getTypeForCreate(objectTypeId, BaseTypeId.CMIS_RELATIONSHIP);
    // get source object
    String sourceId = connector.getSourceIdProperty(properties);
    CMISNodeInfo sourceInfo = getOrCreateNodeInfo(sourceId, "Source");
    if (!sourceInfo.isVariant(CMISObjectVariant.CURRENT_VERSION) && !sourceInfo.isVariant(CMISObjectVariant.FOLDER) && !sourceInfo.isVariant(CMISObjectVariant.ITEM)) {
        throw new CmisInvalidArgumentException("Source is not the latest version of a document, a folder or an item object!");
    }
    final NodeRef sourceNodeRef = sourceInfo.getNodeRef();
    // get target object
    String targetId = connector.getTargetIdProperty(properties);
    CMISNodeInfo targetInfo = getOrCreateNodeInfo(targetId, "Target");
    if (!targetInfo.isVariant(CMISObjectVariant.CURRENT_VERSION) && !targetInfo.isVariant(CMISObjectVariant.FOLDER) && !targetInfo.isVariant(CMISObjectVariant.ITEM)) {
        throw new CmisInvalidArgumentException("Target is not the latest version of a document, a folder or an item object!!");
    }
    final NodeRef targetNodeRef = targetInfo.getNodeRef();
    // check policies and ACLs
    if ((policies != null) && (!policies.isEmpty())) {
        throw new CmisConstraintException("Relationships are not policy controllable!");
    }
    if ((addAces != null) && (addAces.getAces() != null) && (!addAces.getAces().isEmpty())) {
        throw new CmisConstraintException("Relationships are not ACL controllable!");
    }
    if ((removeAces != null) && (removeAces.getAces() != null) && (!removeAces.getAces().isEmpty())) {
        throw new CmisConstraintException("Relationships are not ACL controllable!");
    }
    // create relationship
    // ALF-10085 : disable auditing behaviour for this use case
    // Lasts for txn
    boolean wasEnabled = connector.disableBehaviour(ContentModel.ASPECT_AUDITABLE, sourceNodeRef);
    try {
        AssociationRef assocRef = connector.getNodeService().createAssociation(sourceNodeRef, targetNodeRef, type.getAlfrescoClass());
        return CMISConnector.ASSOC_ID_PREFIX + assocRef.getId();
    } finally {
        if (wasEnabled) {
            connector.enableBehaviour(ContentModel.ASPECT_AUDITABLE, sourceNodeRef);
        }
    }
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) TypeDefinitionWrapper(org.alfresco.opencmis.dictionary.TypeDefinitionWrapper) CmisConstraintException(org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException) CmisInvalidArgumentException(org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException) CMISNodeInfo(org.alfresco.opencmis.dictionary.CMISNodeInfo) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) AssociationRef(org.alfresco.service.cmr.repository.AssociationRef)

Example 40 with CmisInvalidArgumentException

use of org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException in project alfresco-repository by Alfresco.

the class AlfrescoCmisServiceImpl method moveObject.

@Override
public void moveObject(String repositoryId, Holder<String> objectId, String targetFolderId, String sourceFolderId, ExtensionsData extension) {
    checkRepositoryId(repositoryId);
    // get object and source and target parent
    CMISNodeInfo info = getOrCreateNodeInfo(objectId.getValue(), "Object");
    final NodeRef nodeRef = info.getCurrentNodeNodeRef();
    final CMISNodeInfo sourceInfo = getOrCreateFolderInfo(sourceFolderId, "Source Folder");
    final CMISNodeInfo targetInfo = getOrCreateFolderInfo(targetFolderId, "Target Folder");
    connector.checkChildObjectType(targetInfo, info.getType().getTypeId());
    ChildAssociationRef primaryParentRef = connector.getNodeService().getPrimaryParent(nodeRef);
    // if this is a primary child node, move it
    if (primaryParentRef.getParentRef().equals(sourceInfo.getNodeRef())) {
        connector.getNodeService().moveNode(nodeRef, targetInfo.getNodeRef(), primaryParentRef.getTypeQName(), primaryParentRef.getQName());
    } else {
        boolean found = false;
        // otherwise, reparent it
        for (ChildAssociationRef parent : connector.getNodeService().getParentAssocs(nodeRef, ContentModel.ASSOC_CONTAINS, RegexQNamePattern.MATCH_ALL)) {
            if (parent.getParentRef().equals(sourceInfo.getNodeRef())) {
                connector.getNodeService().removeChildAssociation(parent);
                connector.getNodeService().addChild(targetInfo.getNodeRef(), nodeRef, ContentModel.ASSOC_CONTAINS, parent.getQName());
                found = true;
            }
        }
        if (!found) {
            throw new IllegalArgumentException(new CmisInvalidArgumentException("Document is not a child of the source folder that was specified!"));
        }
    }
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) CmisInvalidArgumentException(org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException) CMISNodeInfo(org.alfresco.opencmis.dictionary.CMISNodeInfo) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef)

Aggregations

CmisInvalidArgumentException (org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException)42 CMISNodeInfo (org.alfresco.opencmis.dictionary.CMISNodeInfo)14 NodeRef (org.alfresco.service.cmr.repository.NodeRef)13 CmisConstraintException (org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException)12 ArrayList (java.util.ArrayList)11 CmisRuntimeException (org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException)10 TypeDefinitionWrapper (org.alfresco.opencmis.dictionary.TypeDefinitionWrapper)9 CmisObjectNotFoundException (org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException)8 PropertyString (org.apache.chemistry.opencmis.commons.data.PropertyString)7 HashMap (java.util.HashMap)6 Map (java.util.Map)6 DocumentTypeDefinitionWrapper (org.alfresco.opencmis.dictionary.DocumentTypeDefinitionWrapper)6 ItemTypeDefinitionWrapper (org.alfresco.opencmis.dictionary.ItemTypeDefinitionWrapper)6 CmisStreamNotSupportedException (org.apache.chemistry.opencmis.commons.exceptions.CmisStreamNotSupportedException)6 List (java.util.List)5 ObjectData (org.apache.chemistry.opencmis.commons.data.ObjectData)5 CmisContentAlreadyExistsException (org.apache.chemistry.opencmis.commons.exceptions.CmisContentAlreadyExistsException)5 IOException (java.io.IOException)4 QName (org.alfresco.service.namespace.QName)4 CmisTestResult (org.apache.chemistry.opencmis.tck.CmisTestResult)4