Search in sources :

Example 1 with RenditionData

use of org.apache.chemistry.opencmis.commons.data.RenditionData in project copper-cms by PogeyanOSS.

the class ObjectActor method getRenditions.

private JSONArray getRenditions(QueryGetRequest t) throws CmisInvalidArgumentException, CmisRuntimeException {
    String permission = t.getUserObject().getPermission();
    if (!Helpers.checkingUserPremission(permission, "get")) {
        throw new CmisRuntimeException(t.getUserName() + " is not authorized to applyAcl.");
    }
    String objectId = t.getObjectId();
    String renditionFilter = t.getParameter(QueryGetRequest.PARAM_RENDITION_FILTER);
    BigInteger maxItems = t.getBigIntegerParameter(QueryGetRequest.PARAM_MAX_ITEMS);
    BigInteger skipCount = t.getBigIntegerParameter(QueryGetRequest.PARAM_SKIP_COUNT);
    List<RenditionData> renditions = CmisObjectService.Impl.getRenditions(t.getRepositoryId(), objectId, renditionFilter, maxItems, skipCount, null);
    JSONArray resultRenditions = new JSONArray();
    if (renditions != null) {
        for (RenditionData rendition : renditions) {
            resultRenditions.add(JSONConverter.convert(rendition));
        }
    }
    return resultRenditions;
}
Also used : CmisRuntimeException(org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException) JSONArray(org.apache.chemistry.opencmis.commons.impl.json.JSONArray) BigInteger(java.math.BigInteger) RenditionData(org.apache.chemistry.opencmis.commons.data.RenditionData)

Example 2 with RenditionData

use of org.apache.chemistry.opencmis.commons.data.RenditionData in project alfresco-repository by Alfresco.

the class CMISConnector method createCMISObjectImpl.

@SuppressWarnings("unchecked")
private ObjectData createCMISObjectImpl(final CMISNodeInfo info, Properties nodeProps, String filter, boolean includeAllowableActions, IncludeRelationships includeRelationships, String renditionFilter, boolean includePolicyIds, boolean includeAcl) {
    final ObjectDataImpl result = new ObjectDataImpl();
    // set allowable actions
    if (includeAllowableActions) {
        result.setAllowableActions(getAllowableActions(info));
    }
    // set policy ids
    if (includePolicyIds) {
        result.setPolicyIds(new PolicyIdListImpl());
    }
    if (info.isRelationship()) {
        // set properties
        result.setProperties(getAssocProperties(info, filter));
        // set ACL
        if (includeAcl) {
            // association have no ACL - return an empty list of ACEs
            result.setAcl(new AccessControlListImpl((List<Ace>) Collections.EMPTY_LIST));
            result.setIsExactAcl(Boolean.FALSE);
        }
    } else {
        // set properties
        result.setProperties(nodeProps);
        // set relationships
        if (includeRelationships != IncludeRelationships.NONE) {
            result.setRelationships(getRelationships(info.getNodeRef(), includeRelationships));
        }
        // set renditions
        if (!RENDITION_NONE.equals(renditionFilter)) {
            List<RenditionData> renditions = getRenditions(info.getNodeRef(), renditionFilter, null, null);
            if ((renditions != null) && (!renditions.isEmpty())) {
                result.setRenditions(renditions);
            } else {
                result.setRenditions(Collections.EMPTY_LIST);
            }
        }
        // set ACL
        if (includeAcl) {
            AuthenticationUtil.runAsSystem(new RunAsWork<Void>() {

                @Override
                public Void doWork() throws Exception {
                    Acl acl = getACL(info.getCurrentNodeNodeRef(), false);
                    if (acl != null) {
                        result.setAcl(acl);
                        result.setIsExactAcl(acl.isExact());
                    }
                    return null;
                }
            });
        }
        // add aspects
        List<CmisExtensionElement> extensions = getAspectExtensions(info, filter, result.getProperties().getProperties().keySet());
        if (!extensions.isEmpty()) {
            result.getProperties().setExtensions(Collections.singletonList((CmisExtensionElement) new CmisExtensionElementImpl(ALFRESCO_EXTENSION_NAMESPACE, ASPECTS, null, extensions)));
        }
    }
    return result;
}
Also used : PolicyIdListImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.PolicyIdListImpl) CapabilityAcl(org.apache.chemistry.opencmis.commons.enums.CapabilityAcl) Acl(org.apache.chemistry.opencmis.commons.data.Acl) ObjectDataImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.ObjectDataImpl) CmisExtensionElementImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.CmisExtensionElementImpl) 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) CmisExtensionElement(org.apache.chemistry.opencmis.commons.data.CmisExtensionElement) AccessControlListImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.AccessControlListImpl) Collections.singletonList(java.util.Collections.singletonList) ObjectList(org.apache.chemistry.opencmis.commons.data.ObjectList) ArrayList(java.util.ArrayList) List(java.util.List) RenditionData(org.apache.chemistry.opencmis.commons.data.RenditionData)

Example 3 with RenditionData

use of org.apache.chemistry.opencmis.commons.data.RenditionData 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)

Example 4 with RenditionData

use of org.apache.chemistry.opencmis.commons.data.RenditionData in project alfresco-repository by Alfresco.

the class CMISConnector method query.

@SuppressWarnings("unchecked")
public ObjectList query(String statement, Boolean includeAllowableActions, IncludeRelationships includeRelationships, String renditionFilter, BigInteger maxItems, BigInteger skipCount) /*, CmisVersion cmisVersion*/
{
    // prepare results
    ObjectListImpl result = new ObjectListImpl();
    result.setObjects(new ArrayList<ObjectData>());
    // prepare query
    CMISQueryOptions options = new CMISQueryOptions(statement, getRootStoreRef());
    CmisVersion cmisVersion = getRequestCmisVersion();
    options.setCmisVersion(cmisVersion);
    options.setQueryMode(CMISQueryMode.CMS_WITH_ALFRESCO_EXTENSIONS);
    int skip = 0;
    if ((skipCount != null) && (skipCount.intValue() >= 0)) {
        skip = skipCount.intValue();
        options.setSkipCount(skip);
    }
    if ((maxItems != null) && (maxItems.intValue() >= 0)) {
        options.setMaxItems(maxItems.intValue());
    }
    boolean fetchObject = includeAllowableActions || (includeRelationships != IncludeRelationships.NONE) || (!RENDITION_NONE.equals(renditionFilter));
    // query
    CMISResultSet rs = getOpenCMISQueryService().query(options);
    try {
        CMISResultSetColumn[] columns = rs.getMetaData().getColumns();
        for (CMISResultSetRow row : rs) {
            NodeRef nodeRef = row.getNodeRef();
            if (!nodeService.exists(nodeRef) || filter(nodeRef)) {
                continue;
            }
            TypeDefinitionWrapper type = getType(nodeRef);
            if (type == null) {
                continue;
            }
            ObjectDataImpl hit = new ObjectDataImpl();
            PropertiesImpl properties = new PropertiesImpl();
            hit.setProperties(properties);
            Map<String, Serializable> values = row.getValues();
            for (CMISResultSetColumn column : columns) {
                AbstractPropertyData<?> property = getProperty(column.getCMISDataType(), column.getCMISPropertyDefinition(), values.get(column.getName()));
                property.setQueryName(column.getName());
                properties.addProperty(property);
            }
            if (fetchObject) {
                // set allowable actions
                if (includeAllowableActions) {
                    CMISNodeInfoImpl nodeInfo = createNodeInfo(nodeRef);
                    if (!nodeInfo.getObjectVariant().equals(CMISObjectVariant.NOT_EXISTING)) {
                        hit.setAllowableActions(getAllowableActions(nodeInfo));
                    }
                }
                // set relationships
                if (includeRelationships != IncludeRelationships.NONE) {
                    hit.setRelationships(getRelationships(nodeRef, includeRelationships));
                }
                // set renditions
                if (!RENDITION_NONE.equals(renditionFilter)) {
                    List<RenditionData> renditions = getRenditions(nodeRef, renditionFilter, null, null);
                    if ((renditions != null) && (!renditions.isEmpty())) {
                        hit.setRenditions(renditions);
                    } else {
                        hit.setRenditions(Collections.EMPTY_LIST);
                    }
                }
            }
            result.getObjects().add(hit);
        }
        long numberFound = rs.getNumberFound();
        if (numberFound != -1) {
            result.setNumItems(BigInteger.valueOf(numberFound));
        }
        result.setHasMoreItems(rs.hasMore());
    } finally {
        rs.close();
    }
    return result;
}
Also used : CmisVersion(org.apache.chemistry.opencmis.commons.enums.CmisVersion) Serializable(java.io.Serializable) PropertiesImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertiesImpl) ItemTypeDefinitionWrapper(org.alfresco.opencmis.dictionary.ItemTypeDefinitionWrapper) TypeDefinitionWrapper(org.alfresco.opencmis.dictionary.TypeDefinitionWrapper) DocumentTypeDefinitionWrapper(org.alfresco.opencmis.dictionary.DocumentTypeDefinitionWrapper) ObjectData(org.apache.chemistry.opencmis.commons.data.ObjectData) ObjectListImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.ObjectListImpl) CMISQueryOptions(org.alfresco.opencmis.search.CMISQueryOptions) PropertyString(org.apache.chemistry.opencmis.commons.data.PropertyString) CMISResultSet(org.alfresco.opencmis.search.CMISResultSet) CMISResultSetRow(org.alfresco.opencmis.search.CMISResultSetRow) ObjectDataImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.ObjectDataImpl) CMISResultSetColumn(org.alfresco.opencmis.search.CMISResultSetColumn) NodeRef(org.alfresco.service.cmr.repository.NodeRef) RenditionData(org.apache.chemistry.opencmis.commons.data.RenditionData)

Example 5 with RenditionData

use of org.apache.chemistry.opencmis.commons.data.RenditionData in project alfresco-repository by Alfresco.

the class CMISRenditionMapping method getRenditions.

public List<RenditionData> getRenditions(NodeRef nodeRef, String renditionFilter, BigInteger maxItems, BigInteger skipCount) {
    List<RenditionData> result = new ArrayList<RenditionData>();
    // split the filter
    Set<String> filterSet = splitRenditionFilter(renditionFilter);
    if ((filterSet != null) && (filterSet.contains(CMISConnector.RENDITION_NONE))) {
        // "cmis:none" found -> no renditions
        return result;
    }
    // convert BigIntegers to int
    int max = (maxItems == null ? Integer.MAX_VALUE : maxItems.intValue());
    int skip = (skipCount == null || skipCount.intValue() < 0 ? 0 : skipCount.intValue());
    if (max > 0) {
        // find all renditions and filter them
        List<ChildAssociationRef> renditionList = renditionService.getRenditions(nodeRef);
        int lastIndex = (max + skip > renditionList.size() ? renditionList.size() : max + skip) - 1;
        for (int i = skip; i <= lastIndex; i++) {
            ChildAssociationRef rendition = renditionList.get(i);
            NodeRef rendNodeRef = rendition.getChildRef();
            String rendName = rendition.getQName().getLocalName();
            // get and check content
            QName contentProperty = ContentModel.PROP_CONTENT;
            Serializable contentPropertyName = nodeService.getProperty(rendNodeRef, ContentModel.PROP_CONTENT_PROPERTY_NAME);
            if (contentPropertyName != null) {
                contentProperty = (QName) contentPropertyName;
            }
            ContentReader reader = contentService.getReader(rendNodeRef, contentProperty);
            if ((reader == null) || (!reader.exists())) {
                // no content -> no rendition
                continue;
            }
            // get and clean MIME type
            String mimeType = reader.getMimetype();
            if (mimeType.indexOf(';') > 3) {
                mimeType = mimeType.substring(0, mimeType.indexOf(';')).trim();
            }
            // if a filter is set, check it
            if (filterSet != null) {
                boolean include = false;
                for (String f : filterSet) {
                    if (f.indexOf('/') == -1) {
                        // found a kind, not a MIME type
                        List<String> renditionNames = kindToRenditionNames.get(f);
                        if (renditionNames != null && renditionNames.contains(rendName)) {
                            include = true;
                            break;
                        }
                    } else if (f.endsWith("*")) {
                        // found MIME type with wildcard
                        if (mimeType.startsWith(f.substring(0, f.length() - 2))) {
                            include = true;
                            break;
                        }
                    } else {
                        // found complete MIME type
                        if (mimeType.equals(f)) {
                            include = true;
                            break;
                        }
                    }
                }
                // if no filter matches, skip this rendition
                if (!include) {
                    continue;
                }
            }
            // gather rendition data
            String title = rendName;
            String kind = (renditionNamesToKind.containsKey(rendName) ? renditionNamesToKind.get(rendName) : rendName);
            BigInteger length = BigInteger.valueOf(reader.getSize());
            BigInteger width = null;
            BigInteger height = null;
            if (renditionNameToSize.containsKey(rendName)) {
                BigInteger[] size = renditionNameToSize.get(rendName);
                width = size[0];
                height = size[1];
            }
            // finally add this rendition
            result.add(createRenditionData(rendNodeRef, mimeType, title, kind, length, width, height));
        }
    }
    return result;
}
Also used : Serializable(java.io.Serializable) QName(org.alfresco.service.namespace.QName) ContentReader(org.alfresco.service.cmr.repository.ContentReader) ArrayList(java.util.ArrayList) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) NodeRef(org.alfresco.service.cmr.repository.NodeRef) BigInteger(java.math.BigInteger) RenditionData(org.apache.chemistry.opencmis.commons.data.RenditionData)

Aggregations

RenditionData (org.apache.chemistry.opencmis.commons.data.RenditionData)5 BigInteger (java.math.BigInteger)3 ArrayList (java.util.ArrayList)3 NodeRef (org.alfresco.service.cmr.repository.NodeRef)3 CmisRuntimeException (org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException)3 Serializable (java.io.Serializable)2 ObjectDataImpl (org.apache.chemistry.opencmis.commons.impl.dataobjects.ObjectDataImpl)2 IOException (java.io.IOException)1 Collections.singletonList (java.util.Collections.singletonList)1 List (java.util.List)1 DatatypeConfigurationException (javax.xml.datatype.DatatypeConfigurationException)1 AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)1 CMISNodeInfo (org.alfresco.opencmis.dictionary.CMISNodeInfo)1 DocumentTypeDefinitionWrapper (org.alfresco.opencmis.dictionary.DocumentTypeDefinitionWrapper)1 ItemTypeDefinitionWrapper (org.alfresco.opencmis.dictionary.ItemTypeDefinitionWrapper)1 TypeDefinitionWrapper (org.alfresco.opencmis.dictionary.TypeDefinitionWrapper)1 CMISQueryOptions (org.alfresco.opencmis.search.CMISQueryOptions)1 CMISResultSet (org.alfresco.opencmis.search.CMISResultSet)1 CMISResultSetColumn (org.alfresco.opencmis.search.CMISResultSetColumn)1 CMISResultSetRow (org.alfresco.opencmis.search.CMISResultSetRow)1