Search in sources :

Example 1 with ObjectInfoImpl

use of org.apache.chemistry.opencmis.commons.impl.server.ObjectInfoImpl 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

BigInteger (java.math.BigInteger)1 ArrayList (java.util.ArrayList)1 CMISNodeInfo (org.alfresco.opencmis.dictionary.CMISNodeInfo)1 NodeRef (org.alfresco.service.cmr.repository.NodeRef)1 RenditionData (org.apache.chemistry.opencmis.commons.data.RenditionData)1 CmisRuntimeException (org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException)1 ObjectInfoImpl (org.apache.chemistry.opencmis.commons.impl.server.ObjectInfoImpl)1 RenditionInfoImpl (org.apache.chemistry.opencmis.commons.impl.server.RenditionInfoImpl)1 RenditionInfo (org.apache.chemistry.opencmis.commons.server.RenditionInfo)1