Search in sources :

Example 1 with ContentInfo

use of org.alfresco.rest.api.model.ContentInfo in project alfresco-remote-api by Alfresco.

the class RenditionsImpl method toApiRendition.

protected Rendition toApiRendition(NodeRef renditionNodeRef) {
    Rendition apiRendition = new Rendition();
    String renditionName = (String) nodeService.getProperty(renditionNodeRef, ContentModel.PROP_NAME);
    apiRendition.setId(renditionName);
    ContentData contentData = getContentData(renditionNodeRef, false);
    ContentInfo contentInfo = null;
    if (contentData != null) {
        contentInfo = new ContentInfo(contentData.getMimetype(), getMimeTypeDisplayName(contentData.getMimetype()), contentData.getSize(), contentData.getEncoding());
    }
    apiRendition.setContent(contentInfo);
    apiRendition.setStatus(RenditionStatus.CREATED);
    return apiRendition;
}
Also used : ContentData(org.alfresco.service.cmr.repository.ContentData) ContentInfo(org.alfresco.rest.api.model.ContentInfo) Rendition(org.alfresco.rest.api.model.Rendition)

Example 2 with ContentInfo

use of org.alfresco.rest.api.model.ContentInfo in project alfresco-remote-api by Alfresco.

the class QuickShareLinksImpl method getQuickShareInfo.

private QuickShareLink getQuickShareInfo(NodeRef nodeRef, Map<String, Object> map, boolean noAuth, List<String> includeParam) {
    String sharedId = (String) map.get("sharedId");
    try {
        Map<QName, Serializable> nodeProps = nodeService.getProperties(nodeRef);
        ContentData cd = (ContentData) nodeProps.get(ContentModel.PROP_CONTENT);
        String mimeType = cd.getMimetype();
        String mimeTypeName = mimeTypeService.getDisplaysByMimetype().get(mimeType);
        ContentInfo contentInfo = new ContentInfo(mimeType, mimeTypeName, cd.getSize(), cd.getEncoding());
        Map<String, UserInfo> mapUserInfo = new HashMap<>(2);
        // note: if noAuth mode then don't return userids (to limit disclosure and be consistent with v0 internal)
        boolean displayNameOnly = noAuth;
        UserInfo modifiedByUser = Node.lookupUserInfo((String) nodeProps.get(ContentModel.PROP_MODIFIER), mapUserInfo, personService, displayNameOnly);
        // TODO review - should we return sharedByUser for authenticated users only ?? (not exposed by V0 but needed for "find")
        String sharedByUserId = (String) nodeProps.get(QuickShareModel.PROP_QSHARE_SHAREDBY);
        UserInfo sharedByUser = Node.lookupUserInfo(sharedByUserId, mapUserInfo, personService, displayNameOnly);
        QuickShareLink qs = new QuickShareLink(sharedId, nodeRef.getId());
        qs.setName((String) map.get("name"));
        qs.setTitle((String) map.get("title"));
        qs.setDescription((String) map.get("description"));
        qs.setContent(contentInfo);
        qs.setModifiedAt((Date) map.get("modified"));
        qs.setModifiedByUser(modifiedByUser);
        qs.setSharedByUser(sharedByUser);
        qs.setExpiresAt((Date) map.get("expiryDate"));
        // note: if noAuth mode then do not return allowable operations (eg. but can be optionally returned when finding shared links)
        if (!noAuth) {
            if (includeParam.contains(PARAM_INCLUDE_ALLOWABLEOPERATIONS)) {
                if (quickShareService.canDeleteSharedLink(nodeRef, sharedByUserId)) {
                    // the allowable operations for the shared link
                    qs.setAllowableOperations(Collections.singletonList(Nodes.OP_DELETE));
                }
                Node doc = nodes.getFolderOrDocument(nodeRef, null, null, includeParam, null);
                List<String> allowableOps = doc.getAllowableOperations();
                // the allowable operations for the actual file being shared
                qs.setAllowableOperationsOnTarget(allowableOps);
            }
            // in noAuth mode we don't return the path info
            if (includeParam.contains(PARAM_INCLUDE_PATH)) {
                qs.setPath(nodes.lookupPathInfo(nodeRef, null));
            }
        }
        return qs;
    } catch (InvalidSharedIdException ex) {
        logger.warn("Unable to find: " + sharedId);
        throw new EntityNotFoundException(sharedId);
    } catch (InvalidNodeRefException inre) {
        logger.warn("Unable to find: " + sharedId + " [" + inre.getNodeRef() + "]");
        throw new EntityNotFoundException(sharedId);
    }
}
Also used : Serializable(java.io.Serializable) InvalidSharedIdException(org.alfresco.service.cmr.quickshare.InvalidSharedIdException) HashMap(java.util.HashMap) QName(org.alfresco.service.namespace.QName) Node(org.alfresco.rest.api.model.Node) UserInfo(org.alfresco.rest.api.model.UserInfo) EntityNotFoundException(org.alfresco.rest.framework.core.exceptions.EntityNotFoundException) ContentData(org.alfresco.service.cmr.repository.ContentData) ContentInfo(org.alfresco.rest.api.model.ContentInfo) InvalidNodeRefException(org.alfresco.service.cmr.repository.InvalidNodeRefException) QuickShareLink(org.alfresco.rest.api.model.QuickShareLink)

Example 3 with ContentInfo

use of org.alfresco.rest.api.model.ContentInfo in project alfresco-remote-api by Alfresco.

the class RenditionsImpl method toApiRendition.

protected Rendition toApiRendition(ThumbnailDefinition thumbnailDefinition) {
    ContentInfo contentInfo = new ContentInfo(thumbnailDefinition.getMimetype(), getMimeTypeDisplayName(thumbnailDefinition.getMimetype()), null, null);
    Rendition apiRendition = new Rendition();
    apiRendition.setId(thumbnailDefinition.getName());
    apiRendition.setContent(contentInfo);
    apiRendition.setStatus(RenditionStatus.NOT_CREATED);
    return apiRendition;
}
Also used : ContentInfo(org.alfresco.rest.api.model.ContentInfo) Rendition(org.alfresco.rest.api.model.Rendition)

Example 4 with ContentInfo

use of org.alfresco.rest.api.model.ContentInfo in project records-management by Alfresco.

the class ApiNodesModelFactory method mapRecordInfo.

/**
 * Utility method that maps record specific fields
 *
 * @param record the record to set the fields to
 * @param info info of the record
 * @param includeParam the requested include parameters
 */
private void mapRecordInfo(Record record, FileInfo info, List<String> includeParam) {
    if (includeParam == null || includeParam.isEmpty()) {
        return;
    }
    if (includeParam.contains(Record.PARAM_IS_COMPLETED)) {
        record.setIsCompleted(nodeService.hasAspect(info.getNodeRef(), RecordsManagementModel.ASPECT_DECLARED_RECORD));
    }
    if (includeParam.contains(Record.PARAM_CONTENT)) {
        Serializable val = info.getProperties().get(ContentModel.PROP_CONTENT);
        if ((val != null) && (val instanceof ContentData)) {
            ContentData cd = (ContentData) val;
            String mimeType = cd.getMimetype();
            String mimeTypeName = serviceRegistry.getMimetypeService().getDisplaysByMimetype().get(mimeType);
            ContentInfo contentInfo = new ContentInfo(mimeType, mimeTypeName, cd.getSize(), cd.getEncoding());
            record.setContent(contentInfo);
        }
    }
}
Also used : Serializable(java.io.Serializable) ContentData(org.alfresco.service.cmr.repository.ContentData) ContentInfo(org.alfresco.rest.api.model.ContentInfo)

Aggregations

ContentInfo (org.alfresco.rest.api.model.ContentInfo)4 ContentData (org.alfresco.service.cmr.repository.ContentData)3 Serializable (java.io.Serializable)2 Rendition (org.alfresco.rest.api.model.Rendition)2 HashMap (java.util.HashMap)1 Node (org.alfresco.rest.api.model.Node)1 QuickShareLink (org.alfresco.rest.api.model.QuickShareLink)1 UserInfo (org.alfresco.rest.api.model.UserInfo)1 EntityNotFoundException (org.alfresco.rest.framework.core.exceptions.EntityNotFoundException)1 InvalidSharedIdException (org.alfresco.service.cmr.quickshare.InvalidSharedIdException)1 InvalidNodeRefException (org.alfresco.service.cmr.repository.InvalidNodeRefException)1 QName (org.alfresco.service.namespace.QName)1