Search in sources :

Example 26 with CMISNodeInfo

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

the class AlfrescoCmisServiceImpl method getObjectRelationships.

// --- relationship service ---
@Override
public ObjectList getObjectRelationships(String repositoryId, String objectId, Boolean includeSubRelationshipTypes, RelationshipDirection relationshipDirection, String typeId, String filter, Boolean includeAllowableActions, BigInteger maxItems, BigInteger skipCount, ExtensionsData extension) {
    checkRepositoryId(repositoryId);
    // what kind of object is it?
    CMISNodeInfo info = getOrCreateNodeInfo(objectId, "Object");
    if (info.isVariant(CMISObjectVariant.ASSOC)) {
        throw new CmisInvalidArgumentException("Object is a relationship!");
    }
    if (info.isVariant(CMISObjectVariant.VERSION)) {
        throw new CmisInvalidArgumentException("Object is a document version!");
    }
    // check if the relationship base type is requested
    if (BaseTypeId.CMIS_RELATIONSHIP.value().equals(typeId)) {
        boolean isrt = (includeSubRelationshipTypes == null ? false : includeSubRelationshipTypes.booleanValue());
        if (isrt) {
            // all relationships are a direct subtype of the base type in
            // Alfresco -> remove filter
            typeId = null;
        } else {
            // there are no relationships of the base type in Alfresco ->
            // return empty list
            ObjectListImpl result = new ObjectListImpl();
            result.setHasMoreItems(false);
            result.setNumItems(BigInteger.ZERO);
            result.setObjects(new ArrayList<ObjectData>());
            return result;
        }
    }
    return connector.getObjectRelationships(info.getNodeRef(), relationshipDirection, typeId, filter, includeAllowableActions, maxItems, skipCount);
}
Also used : CmisInvalidArgumentException(org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException) ObjectData(org.apache.chemistry.opencmis.commons.data.ObjectData) CMISNodeInfo(org.alfresco.opencmis.dictionary.CMISNodeInfo) ObjectListImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.ObjectListImpl)

Example 27 with CMISNodeInfo

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

the class AlfrescoCmisServiceImpl method updateProperties.

@Override
public void updateProperties(String repositoryId, Holder<String> objectId, Holder<String> changeToken, final Properties properties, ExtensionsData extension) {
    checkRepositoryId(repositoryId);
    final CMISNodeInfo info = getOrCreateNodeInfo(objectId.getValue(), "Object");
    if (info.isVariant(CMISObjectVariant.ASSOC)) {
        throw new CmisInvalidArgumentException("Relationship properties cannot be updated!");
    } else {
        if (info.isVariant(CMISObjectVariant.VERSION)) {
            throw new CmisInvalidArgumentException("Document is not the latest version!");
        }
        final NodeRef nodeRef = info.getNodeRef();
        connector.setProperties(nodeRef, info.getType(), properties, new String[0]);
        objectId.setValue(connector.createObjectId(nodeRef));
        boolean isObjectInfoRequired = getContext().isObjectInfoRequired();
        if (isObjectInfoRequired) {
            getObjectInfo(repositoryId, objectId.getValue(), "*", IncludeRelationships.NONE);
        }
        connector.getActivityPoster().postFileFolderUpdated(info.isFolder(), nodeRef);
    }
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) CmisInvalidArgumentException(org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException) CMISNodeInfo(org.alfresco.opencmis.dictionary.CMISNodeInfo)

Example 28 with CMISNodeInfo

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

the class AlfrescoCmisServiceImpl method getContentStream.

@Override
public ContentStream getContentStream(String repositoryId, String objectId, String streamId, BigInteger offset, BigInteger length, ExtensionsData extension) {
    checkRepositoryId(repositoryId);
    // what kind of object is it?
    CMISNodeInfo info = getOrCreateNodeInfo(objectId, "Object");
    // relationships cannot have content
    if (info.isVariant(CMISObjectVariant.ASSOC)) {
        throw new CmisInvalidArgumentException("Object is a relationship and cannot have content!");
    }
    // now get it
    return connector.getContentStream(info, streamId, offset, length);
}
Also used : CmisInvalidArgumentException(org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException) CMISNodeInfo(org.alfresco.opencmis.dictionary.CMISNodeInfo)

Example 29 with CMISNodeInfo

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

the class AlfrescoCmisServiceImpl method createDocument.

@Override
public String createDocument(String repositoryId, final Properties properties, String folderId, final ContentStream contentStream, VersioningState versioningState, final List<String> policies, final Acl addAces, final Acl removeAces, ExtensionsData extension) {
    checkRepositoryId(repositoryId);
    // get the parent folder node ref
    final CMISNodeInfo parentInfo = getOrCreateFolderInfo(folderId, "Parent folder");
    // get name and type
    final String name = connector.getNameProperty(properties, null);
    final String objectTypeId = connector.getObjectTypeIdProperty(properties);
    final TypeDefinitionWrapper type = connector.getTypeForCreate(objectTypeId, BaseTypeId.CMIS_DOCUMENT);
    connector.checkChildObjectType(parentInfo, type.getTypeId());
    DocumentTypeDefinition docType = (DocumentTypeDefinition) type.getTypeDefinition(false);
    if ((docType.getContentStreamAllowed() == ContentStreamAllowed.NOTALLOWED) && (contentStream != null)) {
        throw new CmisConstraintException("This document type does not support content!");
    }
    if ((docType.getContentStreamAllowed() == ContentStreamAllowed.REQUIRED) && (contentStream == null)) {
        throw new CmisConstraintException("This document type does requires content!");
    }
    if (!docType.isVersionable() && (versioningState != VersioningState.NONE)) {
        throw new CmisConstraintException("This document type is not versionable!");
    }
    versioningState = getDocumentDefaultVersioningState(versioningState, type);
    FileInfo fileInfo = connector.getFileFolderService().create(parentInfo.getNodeRef(), name, type.getAlfrescoClass());
    NodeRef nodeRef = fileInfo.getNodeRef();
    connector.setProperties(nodeRef, type, properties, new String[] { PropertyIds.NAME, PropertyIds.OBJECT_TYPE_ID });
    connector.applyPolicies(nodeRef, type, policies);
    connector.applyACL(nodeRef, type, addAces, removeAces);
    // handle content
    if (contentStream != null) {
        // write content
        String mimeType = parseMimeType(contentStream);
        String encoding = getEncoding(contentStream.getStream(), mimeType);
        ContentWriter writer = connector.getFileFolderService().getWriter(nodeRef);
        writer.setMimetype(mimeType);
        writer.setEncoding(encoding);
        writer.putContent(contentStream.getStream());
    }
    connector.extractMetadata(nodeRef);
    // generate "doclib" thumbnail asynchronously
    connector.createThumbnails(nodeRef, Collections.singleton("doclib"));
    connector.applyVersioningState(nodeRef, versioningState);
    String objectId = connector.createObjectId(nodeRef);
    connector.getActivityPoster().postFileFolderAdded(nodeRef);
    return objectId;
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) DocumentTypeDefinition(org.apache.chemistry.opencmis.commons.definitions.DocumentTypeDefinition) ContentWriter(org.alfresco.service.cmr.repository.ContentWriter) FileInfo(org.alfresco.service.cmr.model.FileInfo) TypeDefinitionWrapper(org.alfresco.opencmis.dictionary.TypeDefinitionWrapper) CmisConstraintException(org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException) CMISNodeInfo(org.alfresco.opencmis.dictionary.CMISNodeInfo)

Example 30 with CMISNodeInfo

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

the class AlfrescoCmisServiceImpl method getObjectByPath.

@Override
public ObjectData getObjectByPath(String repositoryId, String path, String filter, Boolean includeAllowableActions, IncludeRelationships includeRelationships, String renditionFilter, Boolean includePolicyIds, Boolean includeAcl, ExtensionsData extension) {
    long start = System.currentTimeMillis();
    boolean isObjectInfoRequired = false;
    checkRepositoryId(repositoryId);
    // start at the root node
    NodeRef rootNodeRef = connector.getRootNodeRef();
    ObjectData object;
    if (path.equals("/")) {
        object = connector.createCMISObject(createNodeInfo(rootNodeRef), filter, includeAllowableActions, includeRelationships, renditionFilter, includePolicyIds, includeAcl);
    } else {
        try {
            // resolve path and get the node ref
            FileInfo fileInfo = connector.getFileFolderService().resolveNamePath(rootNodeRef, Arrays.asList(path.substring(1).split("/")));
            if (connector.filter(fileInfo.getNodeRef())) {
                throw new CmisObjectNotFoundException("Object not found: " + path);
            }
            CMISNodeInfo info = createNodeInfo(fileInfo.getNodeRef(), fileInfo.getType(), fileInfo.getProperties(), null, false);
            object = connector.createCMISObject(info, filter, includeAllowableActions, includeRelationships, renditionFilter, includePolicyIds, includeAcl);
            isObjectInfoRequired = getContext().isObjectInfoRequired();
            if (isObjectInfoRequired) {
                getObjectInfo(repositoryId, info.getObjectId(), includeRelationships);
            }
        } catch (FileNotFoundException e) {
            throw new CmisObjectNotFoundException("Object not found: " + path);
        }
    }
    logGetObjectCall("getObjectByPath", start, path, filter, includeAllowableActions, includeRelationships, renditionFilter, includePolicyIds, includeAcl, isObjectInfoRequired, extension);
    return object;
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) FileInfo(org.alfresco.service.cmr.model.FileInfo) CmisObjectNotFoundException(org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException) ObjectData(org.apache.chemistry.opencmis.commons.data.ObjectData) FileNotFoundException(org.alfresco.service.cmr.model.FileNotFoundException) 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