Search in sources :

Example 1 with ThumbnailRegistry

use of org.alfresco.repo.thumbnail.ThumbnailRegistry 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 ThumbnailRegistry

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

the class NodesImpl method getThumbnailDefs.

private List<ThumbnailDefinition> getThumbnailDefs(Set<String> renditionNames) {
    List<ThumbnailDefinition> thumbnailDefs = null;
    if (renditionNames != null) {
        // If thumbnail generation has been configured off, then don't bother.
        if (!thumbnailService.getThumbnailsEnabled()) {
            throw new DisabledServiceException("Thumbnail generation has been disabled.");
        }
        thumbnailDefs = new ArrayList<>(renditionNames.size());
        ThumbnailRegistry registry = thumbnailService.getThumbnailRegistry();
        for (String renditionName : renditionNames) {
            // Use the thumbnail registry to get the details of the thumbnail
            ThumbnailDefinition thumbnailDef = registry.getThumbnailDefinition(renditionName);
            if (thumbnailDef == null) {
                throw new NotFoundException(renditionName + " is not registered.");
            }
            thumbnailDefs.add(thumbnailDef);
        }
    }
    return thumbnailDefs;
}
Also used : DisabledServiceException(org.alfresco.rest.framework.core.exceptions.DisabledServiceException) ThumbnailDefinition(org.alfresco.repo.thumbnail.ThumbnailDefinition) ThumbnailRegistry(org.alfresco.repo.thumbnail.ThumbnailRegistry) NotFoundException(org.alfresco.rest.framework.core.exceptions.NotFoundException) FileNotFoundException(org.alfresco.service.cmr.model.FileNotFoundException) EntityNotFoundException(org.alfresco.rest.framework.core.exceptions.EntityNotFoundException)

Example 3 with ThumbnailRegistry

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

the class RenditionsImpl method createRendition.

@Override
public void createRendition(NodeRef nodeRef, Rendition rendition, boolean executeAsync, Parameters parameters) {
    // If thumbnail generation has been configured off, then don't bother.
    if (!thumbnailService.getThumbnailsEnabled()) {
        throw new DisabledServiceException("Thumbnail generation has been disabled.");
    }
    final NodeRef sourceNodeRef = validateNode(nodeRef.getStoreRef(), nodeRef.getId());
    final NodeRef renditionNodeRef = getRenditionByName(sourceNodeRef, rendition.getId(), parameters);
    if (renditionNodeRef != null) {
        throw new ConstraintViolatedException(rendition.getId() + " rendition already exists.");
    }
    // Use the thumbnail registry to get the details of the thumbnail
    ThumbnailRegistry registry = thumbnailService.getThumbnailRegistry();
    ThumbnailDefinition thumbnailDefinition = registry.getThumbnailDefinition(rendition.getId());
    if (thumbnailDefinition == null) {
        throw new NotFoundException(rendition.getId() + " is not registered.");
    }
    ContentData contentData = getContentData(sourceNodeRef, true);
    // Check if anything is currently available to generate thumbnails for the specified mimeType
    if (!registry.isThumbnailDefinitionAvailable(contentData.getContentUrl(), contentData.getMimetype(), contentData.getSize(), sourceNodeRef, thumbnailDefinition)) {
        throw new InvalidArgumentException("Unable to create thumbnail '" + thumbnailDefinition.getName() + "' for " + contentData.getMimetype() + " as no transformer is currently available.");
    }
    Action action = ThumbnailHelper.createCreateThumbnailAction(thumbnailDefinition, serviceRegistry);
    // Create thumbnail - or else queue for async creation
    actionService.executeAction(action, sourceNodeRef, true, executeAsync);
}
Also used : DisabledServiceException(org.alfresco.rest.framework.core.exceptions.DisabledServiceException) NodeRef(org.alfresco.service.cmr.repository.NodeRef) ThumbnailDefinition(org.alfresco.repo.thumbnail.ThumbnailDefinition) Action(org.alfresco.service.cmr.action.Action) ContentData(org.alfresco.service.cmr.repository.ContentData) InvalidArgumentException(org.alfresco.rest.framework.core.exceptions.InvalidArgumentException) ThumbnailRegistry(org.alfresco.repo.thumbnail.ThumbnailRegistry) NotFoundException(org.alfresco.rest.framework.core.exceptions.NotFoundException) ConstraintViolatedException(org.alfresco.rest.framework.core.exceptions.ConstraintViolatedException)

Aggregations

ThumbnailDefinition (org.alfresco.repo.thumbnail.ThumbnailDefinition)3 ThumbnailRegistry (org.alfresco.repo.thumbnail.ThumbnailRegistry)3 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 Action (org.alfresco.service.cmr.action.Action)2 NodeRef (org.alfresco.service.cmr.repository.NodeRef)2 ConstraintViolatedException (org.alfresco.rest.framework.core.exceptions.ConstraintViolatedException)1 EntityNotFoundException (org.alfresco.rest.framework.core.exceptions.EntityNotFoundException)1 FileNotFoundException (org.alfresco.service.cmr.model.FileNotFoundException)1 ContentData (org.alfresco.service.cmr.repository.ContentData)1