Search in sources :

Example 1 with Rendition

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

the class TestPeople method createAvatarDirect.

private NodeRef createAvatarDirect(NodeRef personRef, File avatarFile) {
    // create new avatar node
    nodeService.addAspect(personRef, ContentModel.ASPECT_PREFERENCES, null);
    ChildAssociationRef assoc = nodeService.createNode(personRef, ContentModel.ASSOC_PREFERENCE_IMAGE, QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "origAvatar"), ContentModel.TYPE_CONTENT);
    final NodeRef avatarRef = assoc.getChildRef();
    // JSF client compatibility?
    nodeService.createAssociation(personRef, avatarRef, ContentModel.ASSOC_AVATAR);
    // upload the avatar content
    ContentService contentService = applicationContext.getBean("ContentService", ContentService.class);
    ContentWriter writer = contentService.getWriter(avatarRef, ContentModel.PROP_CONTENT, true);
    writer.guessMimetype(avatarFile.getName());
    writer.putContent(avatarFile);
    Rendition avatarR = new Rendition();
    avatarR.setId("avatar");
    Renditions renditions = applicationContext.getBean("Renditions", Renditions.class);
    renditions.createRendition(avatarRef, avatarR, false, null);
    return avatarRef;
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) ContentWriter(org.alfresco.service.cmr.repository.ContentWriter) Rendition(org.alfresco.rest.api.model.Rendition) Renditions(org.alfresco.rest.api.Renditions) ContentService(org.alfresco.service.cmr.repository.ContentService) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef)

Example 2 with Rendition

use of org.alfresco.rest.api.model.Rendition 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 3 with Rendition

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

the class RenditionsImpl method getRenditions.

@Override
public CollectionWithPagingInfo<Rendition> getRenditions(NodeRef nodeRef, Parameters parameters) {
    final NodeRef validatedNodeRef = validateNode(nodeRef.getStoreRef(), nodeRef.getId());
    String contentMimeType = getMimeType(validatedNodeRef);
    Query query = parameters.getQuery();
    boolean includeCreated = true;
    boolean includeNotCreated = true;
    String status = getStatus(parameters);
    if (status != null) {
        includeCreated = RenditionStatus.CREATED.equals(RenditionStatus.valueOf(status));
        includeNotCreated = !includeCreated;
    }
    Map<String, Rendition> apiRenditions = new TreeMap<>();
    if (includeNotCreated) {
        // List all available thumbnail definitions
        List<ThumbnailDefinition> thumbnailDefinitions = thumbnailService.getThumbnailRegistry().getThumbnailDefinitions(contentMimeType, -1);
        for (ThumbnailDefinition thumbnailDefinition : thumbnailDefinitions) {
            apiRenditions.put(thumbnailDefinition.getName(), toApiRendition(thumbnailDefinition));
        }
    }
    List<ChildAssociationRef> nodeRefRenditions = renditionService.getRenditions(validatedNodeRef);
    if (!nodeRefRenditions.isEmpty()) {
        for (ChildAssociationRef childAssociationRef : nodeRefRenditions) {
            NodeRef renditionNodeRef = childAssociationRef.getChildRef();
            Rendition apiRendition = toApiRendition(renditionNodeRef);
            if (includeCreated) {
                // Replace/append any thumbnail definitions with created rendition info
                apiRenditions.put(apiRendition.getId(), apiRendition);
            } else {
                // Remove any thumbnail definitions that has been created from the list,
                // as the filter requires only the Not_Created renditions
                apiRenditions.remove(apiRendition.getId());
            }
        }
    }
    // Wrap paging info, as the core service doesn't support paging
    Paging paging = parameters.getPaging();
    PagingResults<Rendition> results = Util.wrapPagingResults(paging, apiRenditions.values());
    return CollectionWithPagingInfo.asPaged(paging, results.getPage(), results.hasMoreItems(), results.getTotalResultCount().getFirst());
}
Also used : Query(org.alfresco.rest.framework.resource.parameters.where.Query) Rendition(org.alfresco.rest.api.model.Rendition) Paging(org.alfresco.rest.framework.resource.parameters.Paging) TreeMap(java.util.TreeMap) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) NodeRef(org.alfresco.service.cmr.repository.NodeRef) ThumbnailDefinition(org.alfresco.repo.thumbnail.ThumbnailDefinition)

Example 4 with Rendition

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

the class DeletedNodesImpl method getRendition.

@Override
public Rendition getRendition(String archivedId, String renditionId, Parameters parameters) {
    NodeRef nodeRef = new NodeRef(StoreRef.STORE_REF_ARCHIVE_SPACESSTORE, archivedId);
    Rendition rendition = renditions.getRendition(nodeRef, renditionId, parameters);
    return rendition;
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) Rendition(org.alfresco.rest.api.model.Rendition)

Example 5 with Rendition

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

the class PeopleImpl method uploadAvatarContent.

@Override
public Person uploadAvatarContent(String personId, BasicContentInfo contentInfo, InputStream stream, Parameters parameters) {
    if (!thumbnailService.getThumbnailsEnabled()) {
        throw new DisabledServiceException("Thumbnail generation has been disabled.");
    }
    personId = validatePerson(personId);
    checkCurrentUserOrAdmin(personId);
    NodeRef personNode = personService.getPerson(personId);
    NodeRef avatarOrigNodeRef = getAvatarOriginal(personNode);
    if (avatarOrigNodeRef != null) {
        deleteAvatar(avatarOrigNodeRef);
    }
    QName origAvatarQName = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "origAvatar");
    nodeService.addAspect(personNode, ContentModel.ASPECT_PREFERENCES, null);
    ChildAssociationRef assoc = nodeService.createNode(personNode, ContentModel.ASSOC_PREFERENCE_IMAGE, origAvatarQName, ContentModel.TYPE_CONTENT);
    NodeRef avatar = assoc.getChildRef();
    String avatarOriginalNodeId = avatar.getId();
    // TODO do we still need this ? - backward compatible with JSF web-client avatar
    nodeService.createAssociation(personNode, avatar, ContentModel.ASSOC_AVATAR);
    Node n = nodes.updateContent(avatarOriginalNodeId, contentInfo, stream, parameters);
    String mimeType = n.getContent().getMimeType();
    if (mimeType.indexOf("image/") != 0) {
        throw new InvalidArgumentException("Uploaded content must be an image (content type determined to be '" + mimeType + "')");
    }
    // create thumbnail synchronously
    Rendition avatarR = new Rendition();
    avatarR.setId("avatar");
    renditions.createRendition(avatar, avatarR, false, parameters);
    List<String> include = Arrays.asList(PARAM_INCLUDE_ASPECTNAMES, PARAM_INCLUDE_PROPERTIES);
    return getPersonWithProperties(personId, include);
}
Also used : DisabledServiceException(org.alfresco.rest.framework.core.exceptions.DisabledServiceException) NodeRef(org.alfresco.service.cmr.repository.NodeRef) InvalidArgumentException(org.alfresco.rest.framework.core.exceptions.InvalidArgumentException) QName(org.alfresco.service.namespace.QName) Rendition(org.alfresco.rest.api.model.Rendition) Node(org.alfresco.rest.api.model.Node) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef)

Aggregations

Rendition (org.alfresco.rest.api.model.Rendition)6 NodeRef (org.alfresco.service.cmr.repository.NodeRef)4 ChildAssociationRef (org.alfresco.service.cmr.repository.ChildAssociationRef)3 ContentInfo (org.alfresco.rest.api.model.ContentInfo)2 TreeMap (java.util.TreeMap)1 ThumbnailDefinition (org.alfresco.repo.thumbnail.ThumbnailDefinition)1 Renditions (org.alfresco.rest.api.Renditions)1 Node (org.alfresco.rest.api.model.Node)1 DisabledServiceException (org.alfresco.rest.framework.core.exceptions.DisabledServiceException)1 InvalidArgumentException (org.alfresco.rest.framework.core.exceptions.InvalidArgumentException)1 Paging (org.alfresco.rest.framework.resource.parameters.Paging)1 Query (org.alfresco.rest.framework.resource.parameters.where.Query)1 ContentData (org.alfresco.service.cmr.repository.ContentData)1 ContentService (org.alfresco.service.cmr.repository.ContentService)1 ContentWriter (org.alfresco.service.cmr.repository.ContentWriter)1 QName (org.alfresco.service.namespace.QName)1