Search in sources :

Example 36 with CMISNodeInfo

use of org.alfresco.opencmis.dictionary.CMISNodeInfo 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 37 with CMISNodeInfo

use of org.alfresco.opencmis.dictionary.CMISNodeInfo 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)

Example 38 with CMISNodeInfo

use of org.alfresco.opencmis.dictionary.CMISNodeInfo in project alfresco-repository by Alfresco.

the class AlfrescoCmisServiceImpl method addObjectToFolder.

// --- multifiling service ---
@Override
public void addObjectToFolder(String repositoryId, String objectId, String folderId, Boolean allVersions, ExtensionsData extension) {
    checkRepositoryId(repositoryId);
    if (!allVersions) {
        throw new CmisInvalidArgumentException("Only allVersions=true supported!");
    }
    // get node ref
    CMISNodeInfo info = getOrCreateNodeInfo(objectId, "Object");
    if (!info.isDocument()) {
        throw new CmisInvalidArgumentException("Object is not a document!");
    }
    final NodeRef nodeRef = info.getNodeRef();
    // get the folder node ref
    final CMISNodeInfo folderInfo = getOrCreateFolderInfo(folderId, "Folder");
    connector.checkChildObjectType(folderInfo, info.getType().getTypeId());
    final QName name = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, QName.createValidLocalName((String) connector.getNodeService().getProperty(nodeRef, ContentModel.PROP_NAME)));
    connector.getNodeService().addChild(folderInfo.getNodeRef(), nodeRef, ContentModel.ASSOC_CONTAINS, name);
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) QName(org.alfresco.service.namespace.QName) CmisInvalidArgumentException(org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException) CMISNodeInfo(org.alfresco.opencmis.dictionary.CMISNodeInfo)

Example 39 with CMISNodeInfo

use of org.alfresco.opencmis.dictionary.CMISNodeInfo in project alfresco-repository by Alfresco.

the class AlfrescoCmisServiceImpl method getOrCreateNodeInfo.

protected CMISNodeInfo getOrCreateNodeInfo(String objectId) {
    CMISNodeInfo result = nodeInfoMap.get(objectId);
    if (result == null) {
        result = connector.createNodeInfo(objectId);
        nodeInfoMap.put(objectId, result);
    }
    return result;
}
Also used : CMISNodeInfo(org.alfresco.opencmis.dictionary.CMISNodeInfo)

Example 40 with CMISNodeInfo

use of org.alfresco.opencmis.dictionary.CMISNodeInfo in project alfresco-repository by Alfresco.

the class AlfrescoCmisServiceImpl method getFolderParent.

@Override
public ObjectData getFolderParent(String repositoryId, String folderId, String filter, ExtensionsData extension) {
    checkRepositoryId(repositoryId);
    // get the node ref
    CMISNodeInfo info = getOrCreateFolderInfo(folderId, "Folder");
    // the root folder has no parent
    if (info.isRootFolder()) {
        throw new CmisInvalidArgumentException("Root folder has no parent!");
    }
    // get the parent
    List<CMISNodeInfo> parentInfos = info.getParents();
    if (parentInfos.isEmpty()) {
        throw new CmisRuntimeException("Folder has no parent and is not the root folder?!");
    }
    CMISNodeInfo parentInfo = addNodeInfo(parentInfos.get(0));
    ObjectData result = connector.createCMISObject(parentInfo, filter, false, IncludeRelationships.NONE, CMISConnector.RENDITION_NONE, false, false);
    boolean isObjectInfoRequired = getContext().isObjectInfoRequired();
    if (isObjectInfoRequired) {
        getObjectInfo(repositoryId, parentInfo.getObjectId(), IncludeRelationships.NONE);
    }
    return result;
}
Also used : CmisRuntimeException(org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException) CmisInvalidArgumentException(org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException) ObjectData(org.apache.chemistry.opencmis.commons.data.ObjectData) CMISNodeInfo(org.alfresco.opencmis.dictionary.CMISNodeInfo)

Aggregations

CMISNodeInfo (org.alfresco.opencmis.dictionary.CMISNodeInfo)42 NodeRef (org.alfresco.service.cmr.repository.NodeRef)26 CmisInvalidArgumentException (org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException)15 TypeDefinitionWrapper (org.alfresco.opencmis.dictionary.TypeDefinitionWrapper)13 CmisConstraintException (org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException)13 ObjectData (org.apache.chemistry.opencmis.commons.data.ObjectData)10 CmisObjectNotFoundException (org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException)8 ArrayList (java.util.ArrayList)6 ChildAssociationRef (org.alfresco.service.cmr.repository.ChildAssociationRef)6 FileInfo (org.alfresco.service.cmr.model.FileInfo)5 InvalidNodeRefException (org.alfresco.service.cmr.repository.InvalidNodeRefException)5 CmisStreamNotSupportedException (org.apache.chemistry.opencmis.commons.exceptions.CmisStreamNotSupportedException)5 RetryingTransactionHelper (org.alfresco.repo.transaction.RetryingTransactionHelper)4 FileNotFoundException (org.alfresco.service.cmr.model.FileNotFoundException)4 QName (org.alfresco.service.namespace.QName)4 CmisContentAlreadyExistsException (org.apache.chemistry.opencmis.commons.exceptions.CmisContentAlreadyExistsException)4 IOException (java.io.IOException)3 ContentWriter (org.alfresco.service.cmr.repository.ContentWriter)3 CmisRuntimeException (org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException)3 Serializable (java.io.Serializable)2