Search in sources :

Example 21 with CMISNodeInfo

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

the class AlfrescoCmisServiceImpl method getObject.

@Override
public ObjectData getObject(String repositoryId, String objectId, String filter, Boolean includeAllowableActions, IncludeRelationships includeRelationships, String renditionFilter, Boolean includePolicyIds, Boolean includeAcl, ExtensionsData extension) {
    long start = System.currentTimeMillis();
    checkRepositoryId(repositoryId);
    // what kind of object is it?
    CMISNodeInfo info = getOrCreateNodeInfo(objectId, "Object");
    // create a CMIS object
    ObjectData object = connector.createCMISObject(info, filter, includeAllowableActions, includeRelationships, renditionFilter, includePolicyIds, includeAcl);
    boolean isObjectInfoRequired = getContext().isObjectInfoRequired();
    if (isObjectInfoRequired) {
        getObjectInfo(repositoryId, info.getObjectId(), includeRelationships);
    }
    logGetObjectCall("getObject", start, objectId, filter, includeAllowableActions, includeRelationships, renditionFilter, includePolicyIds, includeAcl, isObjectInfoRequired, extension);
    return object;
}
Also used : ObjectData(org.apache.chemistry.opencmis.commons.data.ObjectData) CMISNodeInfo(org.alfresco.opencmis.dictionary.CMISNodeInfo)

Example 22 with CMISNodeInfo

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

the class AlfrescoCmisServiceImpl method getRenditions.

@Override
public List<RenditionData> getRenditions(String repositoryId, String objectId, String renditionFilter, BigInteger maxItems, BigInteger skipCount, ExtensionsData extension) {
    checkRepositoryId(repositoryId);
    // what kind of object is it?
    CMISNodeInfo info = getOrCreateNodeInfo(objectId, "Object");
    if (info.isVariant(CMISObjectVariant.ASSOC)) {
        return Collections.emptyList();
    } else {
        return connector.getRenditions(info.getNodeRef(), renditionFilter, maxItems, skipCount);
    }
}
Also used : CMISNodeInfo(org.alfresco.opencmis.dictionary.CMISNodeInfo)

Example 23 with CMISNodeInfo

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

the class CMISNodeInfoImpl method getParents.

@Override
public List<CMISNodeInfo> getParents() {
    if ((objecVariant == CMISObjectVariant.INVALID_ID) || (objecVariant == CMISObjectVariant.NOT_A_CMIS_OBJECT) || (objecVariant == CMISObjectVariant.NOT_EXISTING) || (objecVariant == CMISObjectVariant.PERMISSION_DENIED)) {
        return Collections.<CMISNodeInfo>emptyList();
    }
    if (parents == null) {
        parents = new ArrayList<CMISNodeInfo>();
        NodeRef nodeRefForParent = (isCurrentVersion() ? getCurrentNodeNodeRef() : nodeRef);
        List<ChildAssociationRef> nodeParents = connector.getNodeService().getParentAssocs(nodeRefForParent, ContentModel.ASSOC_CONTAINS, RegexQNamePattern.MATCH_ALL);
        if (nodeParents != null) {
            for (ChildAssociationRef parent : nodeParents) {
                if (connector.getType(parent.getParentRef()) instanceof FolderTypeDefintionWrapper) {
                    parents.add(new CMISNodeInfoImpl(connector, parent.getParentRef()));
                }
            }
        }
    }
    return parents;
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) CMISNodeInfo(org.alfresco.opencmis.dictionary.CMISNodeInfo) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) FolderTypeDefintionWrapper(org.alfresco.opencmis.dictionary.FolderTypeDefintionWrapper)

Example 24 with CMISNodeInfo

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

the class AlfrescoCmisServiceImpl method getPropertiesOfLatestVersion.

@Override
public Properties getPropertiesOfLatestVersion(String repositoryId, String objectId, String versionSeriesId, Boolean major, String filter, ExtensionsData extension) {
    checkRepositoryId(repositoryId);
    if (objectId != null) {
        // it's an AtomPub call
        versionSeriesId = connector.getCurrentVersionId(objectId);
    }
    // what kind of object is it?
    CMISNodeInfo info = getOrCreateNodeInfo(versionSeriesId, "Version Series");
    if (info.isVariant(CMISObjectVariant.ASSOC)) {
        return connector.getAssocProperties(info, filter);
    } else {
        CMISNodeInfo versionInfo = createNodeInfo(((CMISNodeInfoImpl) info).getLatestVersionNodeRef(major));
        addNodeInfo(versionInfo);
        return connector.getNodeProperties(versionInfo, filter);
    }
}
Also used : CMISNodeInfo(org.alfresco.opencmis.dictionary.CMISNodeInfo)

Example 25 with CMISNodeInfo

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

the class AlfrescoCmisServiceImpl method deleteObjectOrCancelCheckOut.

@Override
public void deleteObjectOrCancelCheckOut(String repositoryId, final String objectId, final Boolean allVersions, ExtensionsData extension) {
    checkRepositoryId(repositoryId);
    // what kind of object is it?
    final CMISNodeInfo info = getOrCreateNodeInfo(objectId, "Object");
    do {
        // handle relationships
        if (info.isVariant(CMISObjectVariant.ASSOC)) {
            AssociationRef assocRef = info.getAssociationRef();
            connector.getNodeService().removeAssociation(assocRef.getSourceRef(), assocRef.getTargetRef(), assocRef.getTypeQName());
            // Reason for do-while
            break;
        }
        NodeRef nodeRef = info.getNodeRef();
        // handle PWC
        if (info.isVariant(CMISObjectVariant.PWC)) {
            connector.getCheckOutCheckInService().cancelCheckout(nodeRef);
            // Reason for do-while
            break;
        }
        // handle folders
        if (info.isFolder()) {
            // Check if there is at least one child
            if (connector.getNodeService().getChildAssocs(nodeRef, ContentModel.ASSOC_CONTAINS, RegexQNamePattern.MATCH_ALL, 1, false).size() > 0) {
                throw new CmisConstraintException("Could not delete folder with at least one child!");
            }
            connector.deleteNode(nodeRef, true);
            // Reason for do-while
            break;
        }
        if (info.hasPWC()) {
            // checkout, not allowed.
            throw new CmisConstraintException("Could not delete/cancel checkout on the original checked out document");
        }
        // handle versions
        if (info.isVariant(CMISObjectVariant.VERSION)) {
            nodeRef = info.getCurrentNodeNodeRef();
        }
        if (allVersions) {
            NodeRef workingCopy = connector.getCheckOutCheckInService().getWorkingCopy(nodeRef);
            if (workingCopy != null) {
                connector.getCheckOutCheckInService().cancelCheckout(workingCopy);
            }
        } else if (info.isVariant(CMISObjectVariant.VERSION)) {
            // Check the DELETE permission since the version service has no restrictions.
            AccessStatus perm = connector.getServiceRegistry().getPermissionService().hasPermission(nodeRef, PermissionService.DELETE);
            if (AccessStatus.ALLOWED != perm) {
                throw new CmisPermissionDeniedException("Cannot delete the node version.");
            }
            Version version = ((CMISNodeInfoImpl) info).getVersion();
            connector.getVersionService().deleteVersion(nodeRef, version);
            // Reason for do-while
            break;
        }
        // attempt to delete the node
        if (allVersions) {
            connector.deleteNode(nodeRef, true);
        } else {
            CMISNodeInfoImpl infoImpl = (CMISNodeInfoImpl) info;
            Version version = infoImpl.getVersion();
            if (infoImpl.getVersionHistory().getPredecessor(version) == null) {
                connector.deleteNode(nodeRef, true);
            } else {
                AccessStatus perm = connector.getServiceRegistry().getPermissionService().hasPermission(nodeRef, PermissionService.DELETE);
                if (AccessStatus.ALLOWED != perm) {
                    throw new CmisPermissionDeniedException("Cannot delete the node version.");
                }
                connector.getVersionService().deleteVersion(nodeRef, version);
                // MNT-10032 revert node version to predecessor
                connector.getVersionService().revert(nodeRef);
            }
        }
    } while (// Dodgey, but avoided having to play with too much code during refactor
    false);
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) Version(org.alfresco.service.cmr.version.Version) CmisVersion(org.apache.chemistry.opencmis.commons.enums.CmisVersion) CmisConstraintException(org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException) CmisPermissionDeniedException(org.apache.chemistry.opencmis.commons.exceptions.CmisPermissionDeniedException) CMISNodeInfo(org.alfresco.opencmis.dictionary.CMISNodeInfo) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) AssociationRef(org.alfresco.service.cmr.repository.AssociationRef) AccessStatus(org.alfresco.service.cmr.security.AccessStatus)

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