Search in sources :

Example 31 with CMISNodeInfo

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

the class AlfrescoCmisServiceImpl method createItem.

@Override
public String createItem(String repositoryId, Properties properties, String folderId, List<String> policies, Acl addAces, 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_ITEM);
    connector.checkChildObjectType(parentInfo, type.getTypeId());
    /**
     * The above code specifies a folder - so the contents of a folder (as defined by the alfresco model) are
     * ASSOC cm:contains to a TYPE sys:base
     */
    QName assocQName = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, QName.createValidLocalName(name));
    Map<QName, Serializable> props = new HashMap<QName, Serializable>(11);
    props.put(ContentModel.PROP_NAME, (Serializable) assocQName.getLocalName());
    ChildAssociationRef newRef = connector.getNodeService().createNode(parentInfo.getNodeRef(), ContentModel.ASSOC_CONTAINS, assocQName, type.getAlfrescoClass(), props);
    NodeRef nodeRef = newRef.getChildRef();
    connector.setProperties(nodeRef, type, properties, new String[] { PropertyIds.NAME, PropertyIds.OBJECT_TYPE_ID });
    connector.getNodeService().setProperty(nodeRef, ContentModel.PROP_NAME, assocQName.getLocalName());
    connector.applyPolicies(nodeRef, type, policies);
    connector.applyACL(nodeRef, type, addAces, removeAces);
    String objectId = connector.createObjectId(nodeRef);
    return objectId;
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) Serializable(java.io.Serializable) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) TypeDefinitionWrapper(org.alfresco.opencmis.dictionary.TypeDefinitionWrapper) QName(org.alfresco.service.namespace.QName) CMISNodeInfo(org.alfresco.opencmis.dictionary.CMISNodeInfo) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef)

Example 32 with CMISNodeInfo

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

the class CMISConnector method getContentStream.

/**
 * Gets the content from the repository.
 */
public ContentStream getContentStream(CMISNodeInfo info, String streamId, BigInteger offset, BigInteger length) {
    // get the type and check if the object can have content
    TypeDefinitionWrapper type = info.getType();
    checkDocumentTypeForContent(type);
    // looks like a document, now get the content
    ContentStreamImpl result = new ContentStreamImpl();
    result.setFileName(info.getName());
    // if streamId is set, fetch other content
    NodeRef streamNodeRef = info.getNodeRef();
    if ((streamId != null) && (streamId.length() > 0)) {
        CMISNodeInfo streamInfo = createNodeInfo(streamId);
        if (!streamInfo.isVariant(CMISObjectVariant.CURRENT_VERSION)) {
            throw new CmisInvalidArgumentException("Stream id is invalid: " + streamId + ", expected variant " + CMISObjectVariant.CURRENT_VERSION + ", got variant " + streamInfo.getObjectVariant());
        }
        streamNodeRef = streamInfo.getNodeRef();
        type = streamInfo.getType();
        checkDocumentTypeForContent(type);
    }
    // get the stream now
    try {
        ContentReader contentReader = contentService.getReader(streamNodeRef, ContentModel.PROP_CONTENT);
        if (contentReader == null) {
            throw new CmisConstraintException("Document has no content!");
        }
        result.setMimeType(contentReader.getMimetype());
        long contentSize = contentReader.getSize();
        if ((offset == null) && (length == null)) {
            result.setStream(contentReader.getContentInputStream());
            result.setLength(BigInteger.valueOf(contentSize));
            publishReadEvent(streamNodeRef, info.getName(), result.getMimeType(), contentSize, contentReader.getEncoding(), null);
        } else {
            long off = (offset == null ? 0 : offset.longValue());
            long len = (length == null ? contentSize : length.longValue());
            if (off + len > contentSize) {
                len = contentReader.getSize() - off;
            }
            result.setStream(new RangeInputStream(contentReader.getContentInputStream(), off, len));
            result.setLength(BigInteger.valueOf(len));
            publishReadEvent(streamNodeRef, info.getName(), result.getMimeType(), contentSize, contentReader.getEncoding(), off + " - " + len);
        }
    } catch (Exception e) {
        if (e instanceof CmisBaseException) {
            throw (CmisBaseException) e;
        } else {
            StringBuilder msg = new StringBuilder("Failed to retrieve content: " + e.getMessage());
            Throwable cause = e.getCause();
            if (cause != null) {
                // add the cause to the CMIS exception
                msg.append(", ");
                msg.append(cause.getMessage());
            }
            throw new CmisRuntimeException(msg.toString(), e);
        }
    }
    return result;
}
Also used : ContentStreamImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.ContentStreamImpl) CmisRuntimeException(org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException) ItemTypeDefinitionWrapper(org.alfresco.opencmis.dictionary.ItemTypeDefinitionWrapper) TypeDefinitionWrapper(org.alfresco.opencmis.dictionary.TypeDefinitionWrapper) DocumentTypeDefinitionWrapper(org.alfresco.opencmis.dictionary.DocumentTypeDefinitionWrapper) CmisConstraintException(org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException) ContentReader(org.alfresco.service.cmr.repository.ContentReader) CMISNodeInfo(org.alfresco.opencmis.dictionary.CMISNodeInfo) CmisContentAlreadyExistsException(org.apache.chemistry.opencmis.commons.exceptions.CmisContentAlreadyExistsException) FileExistsException(org.alfresco.service.cmr.model.FileExistsException) InvalidAspectException(org.alfresco.service.cmr.dictionary.InvalidAspectException) AccessDeniedException(org.alfresco.repo.security.permissions.AccessDeniedException) CmisConstraintException(org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException) CmisBaseException(org.apache.chemistry.opencmis.commons.exceptions.CmisBaseException) IOException(java.io.IOException) BeansException(org.springframework.beans.BeansException) CmisInvalidArgumentException(org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException) CmisObjectNotFoundException(org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException) CmisStreamNotSupportedException(org.apache.chemistry.opencmis.commons.exceptions.CmisStreamNotSupportedException) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) DatatypeConfigurationException(javax.xml.datatype.DatatypeConfigurationException) CmisRuntimeException(org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException) FileNotFoundException(org.alfresco.service.cmr.model.FileNotFoundException) InvalidNodeRefException(org.alfresco.service.cmr.repository.InvalidNodeRefException) NodeRef(org.alfresco.service.cmr.repository.NodeRef) CmisBaseException(org.apache.chemistry.opencmis.commons.exceptions.CmisBaseException) CmisInvalidArgumentException(org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException)

Example 33 with CMISNodeInfo

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

the class AlfrescoCmisServiceImpl method cancelCheckOut.

@Override
public void cancelCheckOut(String repositoryId, String objectId, ExtensionsData extension) {
    checkRepositoryId(repositoryId);
    CMISNodeInfo info = getOrCreateNodeInfo(objectId, "Object");
    // only accept a PWC
    if (!info.isVariant(CMISObjectVariant.PWC)) {
        NodeRef nodeRef = info.getNodeRef();
        NodeRef workingCopyNodeRef = connector.getCheckOutCheckInService().getWorkingCopy(nodeRef);
        info = getOrCreateNodeInfo(workingCopyNodeRef.getId());
        if (!info.isVariant(CMISObjectVariant.PWC)) {
            throw new CmisVersioningException("Object is not a PWC!");
        }
    }
    // get object
    final NodeRef nodeRef = info.getNodeRef();
    // cancel check out
    connector.getCheckOutCheckInService().cancelCheckout(nodeRef);
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) CmisVersioningException(org.apache.chemistry.opencmis.commons.exceptions.CmisVersioningException) CMISNodeInfo(org.alfresco.opencmis.dictionary.CMISNodeInfo)

Example 34 with CMISNodeInfo

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

the class AlfrescoCmisServiceImpl method removePolicy.

@Override
public void removePolicy(String repositoryId, String policyId, String objectId, ExtensionsData extension) {
    checkRepositoryId(repositoryId);
    // what kind of object is it?
    CMISNodeInfo info = getOrCreateNodeInfo(objectId, "Object");
    TypeDefinitionWrapper type = info.getType();
    if (type == null) {
        throw new CmisObjectNotFoundException("No corresponding type found! Not a CMIS object?");
    }
    throw new CmisConstraintException("Object is not policy controllable!");
}
Also used : CmisObjectNotFoundException(org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException) TypeDefinitionWrapper(org.alfresco.opencmis.dictionary.TypeDefinitionWrapper) CmisConstraintException(org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException) CMISNodeInfo(org.alfresco.opencmis.dictionary.CMISNodeInfo)

Example 35 with CMISNodeInfo

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

the class AlfrescoCmisServiceImpl method getObjectInfoIntern.

/**
 * Collects the {@link ObjectInfo} about an object.
 *
 * (Provided by OpenCMIS, but optimized for Alfresco.)
 */
@SuppressWarnings("unchecked")
@Override
protected ObjectInfo getObjectInfoIntern(String repositoryId, ObjectData object) {
    // if the object has no properties, stop here
    if (object.getProperties() == null || object.getProperties().getProperties() == null) {
        throw new CmisRuntimeException("No properties!");
    }
    String objectId = object.getId();
    CMISNodeInfo ni = getOrCreateNodeInfo(objectId);
    ObjectInfoImpl info = new ObjectInfoImpl();
    // general properties
    info.setObject(object);
    info.setId(objectId);
    info.setName(getStringProperty(object, PropertyIds.NAME));
    info.setCreatedBy(getStringProperty(object, PropertyIds.CREATED_BY));
    info.setCreationDate(getDateTimeProperty(object, PropertyIds.CREATION_DATE));
    info.setLastModificationDate(getDateTimeProperty(object, PropertyIds.LAST_MODIFICATION_DATE));
    info.setTypeId(getIdProperty(object, PropertyIds.OBJECT_TYPE_ID));
    info.setBaseType(object.getBaseTypeId());
    if (ni.isRelationship()) {
        // versioning
        info.setWorkingCopyId(null);
        info.setWorkingCopyOriginalId(null);
        info.setVersionSeriesId(null);
        info.setIsCurrentVersion(true);
        info.setWorkingCopyId(null);
        info.setWorkingCopyOriginalId(null);
        // content
        info.setHasContent(false);
        info.setContentType(null);
        info.setFileName(null);
        // parent
        info.setHasParent(false);
        // policies and relationships
        info.setSupportsRelationships(false);
        info.setSupportsPolicies(false);
        // renditions
        info.setRenditionInfos(null);
        // relationships
        info.setRelationshipSourceIds(null);
        info.setRelationshipTargetIds(null);
        // global settings
        info.setHasAcl(false);
        info.setSupportsDescendants(false);
        info.setSupportsFolderTree(false);
    } else if (ni.isFolder()) {
        // versioning
        info.setWorkingCopyId(null);
        info.setWorkingCopyOriginalId(null);
        info.setVersionSeriesId(null);
        info.setIsCurrentVersion(true);
        info.setWorkingCopyId(null);
        info.setWorkingCopyOriginalId(null);
        // content
        info.setHasContent(false);
        info.setContentType(null);
        info.setFileName(null);
        // parent
        info.setHasParent(!ni.isRootFolder());
        // policies and relationships
        info.setSupportsRelationships(true);
        info.setSupportsPolicies(true);
        // renditions
        info.setRenditionInfos(null);
        // relationships
        setRelaionshipsToObjectInfo(object, info);
        // global settings
        info.setHasAcl(true);
        info.setSupportsDescendants(true);
        info.setSupportsFolderTree(true);
    } else if (ni.isDocument()) {
        // versioning
        info.setWorkingCopyId(null);
        info.setWorkingCopyOriginalId(null);
        info.setVersionSeriesId(ni.getCurrentNodeId());
        if (ni.isPWC()) {
            info.setIsCurrentVersion(false);
            info.setWorkingCopyId(ni.getObjectId());
            info.setWorkingCopyOriginalId(ni.getCurrentObjectId());
        } else {
            info.setIsCurrentVersion(ni.isCurrentVersion());
            if (ni.hasPWC()) {
                info.setWorkingCopyId(ni.getCurrentNodeId() + CMISConnector.ID_SEPERATOR + CMISConnector.PWC_VERSION_LABEL);
                info.setWorkingCopyOriginalId(ni.getCurrentObjectId());
            } else {
                info.setWorkingCopyId(null);
                info.setWorkingCopyOriginalId(null);
            }
        }
        // content
        String fileName = getStringProperty(object, PropertyIds.CONTENT_STREAM_FILE_NAME);
        String mimeType = getStringProperty(object, PropertyIds.CONTENT_STREAM_MIME_TYPE);
        String streamId = getIdProperty(object, PropertyIds.CONTENT_STREAM_ID);
        BigInteger length = getIntegerProperty(object, PropertyIds.CONTENT_STREAM_LENGTH);
        boolean hasContent = fileName != null || mimeType != null || streamId != null || length != null;
        if (hasContent) {
            info.setHasContent(hasContent);
            info.setContentType(mimeType);
            info.setFileName(fileName);
        } else {
            info.setHasContent(false);
            info.setContentType(null);
            info.setFileName(null);
        }
        // parent
        info.setHasParent(ni.isCurrentVersion() || ni.isPWC());
        // policies and relationships
        info.setSupportsRelationships(true);
        info.setSupportsPolicies(true);
        // renditions
        String renditionFilter = getRequestParameterRenditionFilter();
        List<RenditionInfo> renditionInfos = new ArrayList<>();
        CMISNodeInfo nodeInfo = getOrCreateNodeInfo(objectId);
        NodeRef nodeRef = nodeInfo.getNodeRef();
        if (nodeRef != null) {
            List<RenditionData> renditions = connector.getRenditions(nodeRef, renditionFilter, null, null);
            for (RenditionData rendition : renditions) {
                RenditionInfoImpl renditionInfo = new RenditionInfoImpl();
                renditionInfo.setId(rendition.getStreamId());
                renditionInfo.setKind(rendition.getKind());
                renditionInfo.setContentType(rendition.getMimeType());
                renditionInfo.setTitle(rendition.getTitle());
                renditionInfo.setLength(rendition.getBigLength());
                renditionInfos.add(renditionInfo);
            }
        }
        info.setRenditionInfos(renditionInfos);
        // relationships
        setRelaionshipsToObjectInfo(object, info);
        // global settings
        info.setHasAcl(true);
        info.setSupportsDescendants(true);
        info.setSupportsFolderTree(true);
    } else if (ni.isItem()) {
        info.setHasAcl(true);
        info.setHasContent(false);
    }
    return info;
}
Also used : CmisRuntimeException(org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException) RenditionInfo(org.apache.chemistry.opencmis.commons.server.RenditionInfo) ArrayList(java.util.ArrayList) CMISNodeInfo(org.alfresco.opencmis.dictionary.CMISNodeInfo) ObjectInfoImpl(org.apache.chemistry.opencmis.commons.impl.server.ObjectInfoImpl) NodeRef(org.alfresco.service.cmr.repository.NodeRef) RenditionInfoImpl(org.apache.chemistry.opencmis.commons.impl.server.RenditionInfoImpl) BigInteger(java.math.BigInteger) RenditionData(org.apache.chemistry.opencmis.commons.data.RenditionData)

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