Search in sources :

Example 11 with CMISNodeInfo

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

the class AlfrescoCmisServiceImpl method appendContentStream.

@Override
public void appendContentStream(String repositoryId, Holder<String> objectId, Holder<String> changeToken, ContentStream contentStream, boolean isLastChunk, ExtensionsData extension) {
    if ((contentStream == null) || (contentStream.getStream() == null)) {
        throw new CmisInvalidArgumentException("No content!");
    }
    checkRepositoryId(repositoryId);
    CMISNodeInfo info = getOrCreateNodeInfo(objectId.getValue(), "Object");
    NodeRef nodeRef = info.getNodeRef();
    if (((DocumentTypeDefinition) info.getType().getTypeDefinition(false)).getContentStreamAllowed() == ContentStreamAllowed.NOTALLOWED) {
        throw new CmisStreamNotSupportedException("Document type doesn't allow content!");
    }
    // ALF-21852 - Separated appendContent and objectId.setValue in two different transactions because
    // after executing appendContent, the new objectId is not visible.
    RetryingTransactionHelper helper = connector.getRetryingTransactionHelper();
    helper.doInTransaction(new RetryingTransactionCallback<Void>() {

        public Void execute() throws Throwable {
            try {
                connector.appendContent(info, contentStream, isLastChunk);
            } catch (IOException e) {
                throw new ContentIOException("", e);
            }
            return null;
        }
    }, false, true);
    String objId = helper.doInTransaction(new RetryingTransactionCallback<String>() {

        public String execute() throws Throwable {
            return connector.createObjectId(nodeRef);
        }
    }, true, true);
    objectId.setValue(objId);
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) CmisStreamNotSupportedException(org.apache.chemistry.opencmis.commons.exceptions.CmisStreamNotSupportedException) RetryingTransactionHelper(org.alfresco.repo.transaction.RetryingTransactionHelper) CmisInvalidArgumentException(org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException) CMISNodeInfo(org.alfresco.opencmis.dictionary.CMISNodeInfo) IOException(java.io.IOException) ContentIOException(org.alfresco.service.cmr.repository.ContentIOException) ContentIOException(org.alfresco.service.cmr.repository.ContentIOException)

Example 12 with CMISNodeInfo

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

the class AlfrescoCmisServiceImpl method getDescendantsTree.

private void getDescendantsTree(String repositoryId, NodeRef folderNodeRef, int depth, String filter, Boolean includeAllowableActions, IncludeRelationships includeRelationships, String renditionFilter, Boolean includePathSegment, boolean foldersOnly, List<ObjectInFolderContainer> list) {
    // get the children references
    List<ChildAssociationRef> childrenList = connector.getNodeService().getChildAssocs(folderNodeRef);
    for (ChildAssociationRef child : childrenList) {
        try {
            TypeDefinitionWrapper type = connector.getType(child.getChildRef());
            if (type == null) {
                continue;
            }
            boolean isFolder = (type instanceof FolderTypeDefintionWrapper);
            if (foldersOnly && !isFolder) {
                continue;
            }
            if (isFolder && type.getAlfrescoClass().equals(ContentModel.TYPE_SYSTEM_FOLDER)) {
                continue;
            }
            if (connector.isHidden(child.getChildRef())) {
                continue;
            }
            if (connector.filter(child.getChildRef())) {
                continue;
            }
            boolean isObjectInfoRequired = getContext().isObjectInfoRequired();
            // create a child CMIS object
            ObjectInFolderDataImpl object = new ObjectInFolderDataImpl();
            // note: checkExists=false (don't need to check again)
            CMISNodeInfo ni = createNodeInfo(child.getChildRef(), null, false);
            object.setObject(connector.createCMISObject(ni, filter, includeAllowableActions, includeRelationships, renditionFilter, false, false));
            if (isObjectInfoRequired) {
                getObjectInfo(repositoryId, ni.getObjectId(), includeRelationships);
            }
            if (includePathSegment) {
                object.setPathSegment(connector.getName(child.getChildRef()));
            }
            // create the container
            ObjectInFolderContainerImpl container = new ObjectInFolderContainerImpl();
            container.setObject(object);
            if ((depth != 1) && isFolder) {
                container.setChildren(new ArrayList<ObjectInFolderContainer>());
                getDescendantsTree(repositoryId, child.getChildRef(), depth - 1, filter, includeAllowableActions, includeRelationships, renditionFilter, includePathSegment, foldersOnly, container.getChildren());
            }
            // add it
            list.add(container);
        } catch (InvalidNodeRefException e) {
        // ignore invalid children
        } catch (CmisObjectNotFoundException e) {
        // ignore objects that have not been found (perhaps because their type is unknown to CMIS)
        }
    }
}
Also used : ObjectInFolderDataImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.ObjectInFolderDataImpl) CmisObjectNotFoundException(org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException) ObjectInFolderContainerImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.ObjectInFolderContainerImpl) TypeDefinitionWrapper(org.alfresco.opencmis.dictionary.TypeDefinitionWrapper) InvalidNodeRefException(org.alfresco.service.cmr.repository.InvalidNodeRefException) CMISNodeInfo(org.alfresco.opencmis.dictionary.CMISNodeInfo) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) FolderTypeDefintionWrapper(org.alfresco.opencmis.dictionary.FolderTypeDefintionWrapper) ObjectInFolderContainer(org.apache.chemistry.opencmis.commons.data.ObjectInFolderContainer)

Example 13 with CMISNodeInfo

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

the class AlfrescoCmisServiceImpl method createDocumentFromSource.

@Override
public String createDocumentFromSource(String repositoryId, String sourceId, final Properties properties, String folderId, 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 source
    CMISNodeInfo info = getOrCreateNodeInfo(sourceId, "Source");
    // check source
    if (info.isVariant(CMISObjectVariant.ASSOC)) {
        throw new CmisConstraintException("Source object is not a document!");
    }
    final NodeRef sourceNodeRef = info.getNodeRef();
    if (!info.isDocument()) {
        throw new CmisConstraintException("Source object is not a document!");
    }
    // get name and type
    final String name = connector.getNameProperty(properties, info.getName());
    final TypeDefinitionWrapper type = info.getType();
    connector.checkChildObjectType(parentInfo, type.getTypeId());
    versioningState = getDocumentDefaultVersioningState(versioningState, type);
    try {
        FileInfo fileInfo = connector.getFileFolderService().copy(sourceNodeRef, parentInfo.getNodeRef(), name);
        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);
        connector.extractMetadata(nodeRef);
        connector.createThumbnails(nodeRef, Collections.singleton("doclib"));
        connector.applyVersioningState(nodeRef, versioningState);
        connector.getActivityPoster().postFileFolderAdded(nodeRef);
        return connector.createObjectId(nodeRef);
    } catch (FileNotFoundException e) {
        throw new CmisContentAlreadyExistsException("An object with this name already exists!", e);
    }
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) FileInfo(org.alfresco.service.cmr.model.FileInfo) CmisConstraintException(org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException) TypeDefinitionWrapper(org.alfresco.opencmis.dictionary.TypeDefinitionWrapper) FileNotFoundException(org.alfresco.service.cmr.model.FileNotFoundException) CmisContentAlreadyExistsException(org.apache.chemistry.opencmis.commons.exceptions.CmisContentAlreadyExistsException) CMISNodeInfo(org.alfresco.opencmis.dictionary.CMISNodeInfo)

Example 14 with CMISNodeInfo

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

the class AlfrescoCmisServiceImpl method setContentStream.

@Override
public void setContentStream(String repositoryId, Holder<String> objectId, Boolean overwriteFlag, Holder<String> changeToken, final ContentStream contentStream, ExtensionsData extension) {
    checkRepositoryId(repositoryId);
    CMISNodeInfo info = getOrCreateNodeInfo(objectId.getValue(), "Object");
    if (!info.isVariant(CMISObjectVariant.CURRENT_VERSION) && !info.isVariant(CMISObjectVariant.PWC)) {
        throw new CmisStreamNotSupportedException("Content can only be set on private working copies or current versions.");
    }
    final NodeRef nodeRef = info.getNodeRef();
    if (((DocumentTypeDefinition) info.getType().getTypeDefinition(false)).getContentStreamAllowed() == ContentStreamAllowed.NOTALLOWED) {
        throw new CmisStreamNotSupportedException("Document type doesn't allow content!");
    }
    boolean existed = connector.getContentService().getReader(nodeRef, ContentModel.PROP_CONTENT) != null;
    if (existed && !overwriteFlag) {
        throw new CmisContentAlreadyExistsException("Content already exists!");
    }
    if ((contentStream == null) || (contentStream.getStream() == null)) {
        throw new CmisInvalidArgumentException("No content!");
    }
    // ALF-21852 - Separated setContent and objectId.setValue in two different transactions because
    // after executing setContent, the new objectId is not visible.
    RetryingTransactionHelper helper = connector.getRetryingTransactionHelper();
    helper.doInTransaction(new RetryingTransactionCallback<Void>() {

        public Void execute() throws Throwable {
            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.getActivityPoster().postFileFolderUpdated(info.isFolder(), nodeRef);
            return null;
        }
    }, false, true);
    String objId = helper.doInTransaction(new RetryingTransactionCallback<String>() {

        public String execute() throws Throwable {
            return connector.createObjectId(nodeRef);
        }
    }, true, true);
    objectId.setValue(objId);
}
Also used : CmisStreamNotSupportedException(org.apache.chemistry.opencmis.commons.exceptions.CmisStreamNotSupportedException) RetryingTransactionHelper(org.alfresco.repo.transaction.RetryingTransactionHelper) CMISNodeInfo(org.alfresco.opencmis.dictionary.CMISNodeInfo) NodeRef(org.alfresco.service.cmr.repository.NodeRef) ContentWriter(org.alfresco.service.cmr.repository.ContentWriter) CmisContentAlreadyExistsException(org.apache.chemistry.opencmis.commons.exceptions.CmisContentAlreadyExistsException) CmisInvalidArgumentException(org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException)

Example 15 with CMISNodeInfo

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

the class AlfrescoCmisServiceImpl method createFolder.

@Override
public String createFolder(String repositoryId, final Properties properties, String folderId, 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, "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_FOLDER);
    connector.checkChildObjectType(parentInfo, type.getTypeId());
    // run transaction
    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);
    connector.getActivityPoster().postFileFolderAdded(nodeRef);
    String objectId = connector.createObjectId(nodeRef);
    return objectId;
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) FileInfo(org.alfresco.service.cmr.model.FileInfo) TypeDefinitionWrapper(org.alfresco.opencmis.dictionary.TypeDefinitionWrapper) 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