Search in sources :

Example 1 with ThumbnailDefinition

use of org.alfresco.repo.thumbnail.ThumbnailDefinition in project alfresco-remote-api by Alfresco.

the class NodesImpl method requestRenditions.

private void requestRenditions(List<ThumbnailDefinition> thumbnailDefs, Node fileNode) {
    if (thumbnailDefs != null) {
        ThumbnailRegistry registry = thumbnailService.getThumbnailRegistry();
        for (ThumbnailDefinition thumbnailDef : thumbnailDefs) {
            NodeRef sourceNodeRef = fileNode.getNodeRef();
            String mimeType = fileNode.getContent().getMimeType();
            long size = fileNode.getContent().getSizeInBytes();
            // Check if anything is currently available to generate thumbnails for the specified mimeType
            if (!registry.isThumbnailDefinitionAvailable(null, mimeType, size, sourceNodeRef, thumbnailDef)) {
                throw new InvalidArgumentException("Unable to create thumbnail '" + thumbnailDef.getName() + "' for " + mimeType + " as no transformer is currently available.");
            }
            Action action = ThumbnailHelper.createCreateThumbnailAction(thumbnailDef, sr);
            // Queue async creation of thumbnail
            actionService.executeAction(action, sourceNodeRef, true, true);
        }
    }
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) ThumbnailDefinition(org.alfresco.repo.thumbnail.ThumbnailDefinition) Action(org.alfresco.service.cmr.action.Action) InvalidArgumentException(org.alfresco.rest.framework.core.exceptions.InvalidArgumentException) ThumbnailRegistry(org.alfresco.repo.thumbnail.ThumbnailRegistry)

Example 2 with ThumbnailDefinition

use of org.alfresco.repo.thumbnail.ThumbnailDefinition 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 3 with ThumbnailDefinition

use of org.alfresco.repo.thumbnail.ThumbnailDefinition in project alfresco-repository by Alfresco.

the class CMISConnector method createThumbnails.

/**
 * Asynchronously generates thumbnails for the given node.
 *
 * @param nodeRef NodeRef
 */
public void createThumbnails(NodeRef nodeRef, Set<String> thumbnailNames) {
    if (thumbnailNames == null || thumbnailNames.size() == 0) {
        return;
    }
    ThumbnailRegistry registry = thumbnailService.getThumbnailRegistry();
    // If there's nothing currently registered to generate thumbnails for the
    // specified mimetype, then log a message and bail out
    Serializable value = this.nodeService.getProperty(nodeRef, ContentModel.PROP_CONTENT);
    ContentData contentData = DefaultTypeConverter.INSTANCE.convert(ContentData.class, value);
    if (contentData == null) {
        logger.info("Unable to create thumbnails as there is no content");
        return;
    }
    long size = contentData.getSize();
    String mimeType = contentData.getMimetype();
    for (String thumbnailName : thumbnailNames) {
        // Use the thumbnail registy to get the details of the thumbail
        ThumbnailDefinition details = registry.getThumbnailDefinition(thumbnailName);
        if (details == null) {
            // Throw exception
            logger.warn("The thumbnail name '" + thumbnailName + "' is not registered");
            continue;
        } else {
            if (registry.isThumbnailDefinitionAvailable(contentData.getContentUrl(), mimeType, size, nodeRef, details)) {
                org.alfresco.service.cmr.action.Action action = ThumbnailHelper.createCreateThumbnailAction(details, serviceRegistry);
                // Queue async creation of thumbnail
                actionService.executeAction(action, nodeRef, true, true);
            } else {
                logger.info("Unable to create thumbnail '" + details.getName() + "' for " + mimeType + " as no transformer is currently available");
            }
        }
    }
}
Also used : Serializable(java.io.Serializable) ThumbnailDefinition(org.alfresco.repo.thumbnail.ThumbnailDefinition) ContentData(org.alfresco.service.cmr.repository.ContentData) ThumbnailRegistry(org.alfresco.repo.thumbnail.ThumbnailRegistry) PropertyString(org.apache.chemistry.opencmis.commons.data.PropertyString)

Example 4 with ThumbnailDefinition

use of org.alfresco.repo.thumbnail.ThumbnailDefinition in project alfresco-repository by Alfresco.

the class ScriptThumbnail method update.

/**
 * Updates the thumbnails content
 */
public void update() {
    List<ChildAssociationRef> parentRefs = services.getNodeService().getParentAssocs(nodeRef, RenditionModel.ASSOC_RENDITION, RegexQNamePattern.MATCH_ALL);
    // There should in fact only ever be one parent association of type rendition on any rendition node.
    if (parentRefs.size() != 1) {
        StringBuilder msg = new StringBuilder();
        msg.append("Node ").append(nodeRef).append(" has ").append(parentRefs.size()).append(" rendition parents. Unable to update.");
        if (logger.isWarnEnabled()) {
            logger.warn(msg.toString());
        }
        throw new AlfrescoRuntimeException(msg.toString());
    }
    String name = parentRefs.get(0).getQName().getLocalName();
    ThumbnailDefinition def = services.getThumbnailService().getThumbnailRegistry().getThumbnailDefinition(name);
    services.getThumbnailService().updateThumbnail(this.nodeRef, def.getTransformationOptions());
}
Also used : ThumbnailDefinition(org.alfresco.repo.thumbnail.ThumbnailDefinition) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef)

Example 5 with ThumbnailDefinition

use of org.alfresco.repo.thumbnail.ThumbnailDefinition in project alfresco-repository by Alfresco.

the class ScriptNode method getThumbnailDefinitions.

/**
 * Returns the names of the thumbnail defintions that can be applied to the content property of
 * this node.
 * <p>
 * Thumbanil defintions only appear in this list if they can produce a thumbnail for the content
 * found in the content property.  This will be determined by looking at the mimetype of the content
 * and the destinatino mimetype of the thumbnail.
 *
 * @return  String[]    array of thumbnail names that are valid for the current content type
 */
public String[] getThumbnailDefinitions() {
    ThumbnailService thumbnailService = this.services.getThumbnailService();
    List<String> result = new ArrayList<String>(7);
    Serializable value = this.nodeService.getProperty(nodeRef, ContentModel.PROP_CONTENT);
    ContentData contentData = DefaultTypeConverter.INSTANCE.convert(ContentData.class, value);
    if (ContentData.hasContent(contentData)) {
        String mimetype = contentData.getMimetype();
        List<ThumbnailDefinition> thumbnailDefinitions = thumbnailService.getThumbnailRegistry().getThumbnailDefinitions(mimetype, contentData.getSize());
        for (ThumbnailDefinition thumbnailDefinition : thumbnailDefinitions) {
            result.add(thumbnailDefinition.getName());
        }
    }
    return (String[]) result.toArray(new String[result.size()]);
}
Also used : Serializable(java.io.Serializable) ThumbnailDefinition(org.alfresco.repo.thumbnail.ThumbnailDefinition) ContentData(org.alfresco.service.cmr.repository.ContentData) ThumbnailService(org.alfresco.service.cmr.thumbnail.ThumbnailService) ArrayList(java.util.ArrayList)

Aggregations

ThumbnailDefinition (org.alfresco.repo.thumbnail.ThumbnailDefinition)12 ThumbnailRegistry (org.alfresco.repo.thumbnail.ThumbnailRegistry)5 ContentData (org.alfresco.service.cmr.repository.ContentData)5 NodeRef (org.alfresco.service.cmr.repository.NodeRef)5 Serializable (java.io.Serializable)4 Action (org.alfresco.service.cmr.action.Action)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)2 DisabledServiceException (org.alfresco.rest.framework.core.exceptions.DisabledServiceException)2 InvalidArgumentException (org.alfresco.rest.framework.core.exceptions.InvalidArgumentException)2 NotFoundException (org.alfresco.rest.framework.core.exceptions.NotFoundException)2 ChildAssociationRef (org.alfresco.service.cmr.repository.ChildAssociationRef)2 ThumbnailService (org.alfresco.service.cmr.thumbnail.ThumbnailService)2 Date (java.util.Date)1 LinkedList (java.util.LinkedList)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1