Search in sources :

Example 6 with RenditionDefinitionRegistry2

use of org.alfresco.repo.rendition2.RenditionDefinitionRegistry2 in project alfresco-repository by Alfresco.

the class ScriptNode method createThumbnail.

/**
 * Creates a thumbnail for the content property of the node.
 *
 * The thumbnail name corresponds to pre-set thumbnail details stored in the
 * repository.
 *
 * If the thumbnail is created asynchronously then the result will be null and creation
 * of the thumbnail will occure at some point in the background.
 *
 * If foce param specified system.thumbnail.generate is ignoring. Could be used for preview creation
 *
 * @param  thumbnailName    the name of the thumbnail
 * @param  async            indicates whether the thumbnail is create asynchronously or not
 * @param  force            ignore system.thumbnail.generate=false
 * @return ScriptThumbnail  the newly create thumbnail node or null if async creation occures
 *
 * @deprecated The async flag in the method signature will not be applicable as all of
 * the future transformations will be asynchronous
 */
@Deprecated
public ScriptThumbnail createThumbnail(String thumbnailName, boolean async, boolean force) {
    final ThumbnailService thumbnailService = services.getThumbnailService();
    ScriptThumbnail result = null;
    // We need to create preview for node even if system.thumbnail.generate=false
    if (force || thumbnailService.getThumbnailsEnabled()) {
        // Use the thumbnail registy to get the details of the thumbail
        ThumbnailRegistry registry = thumbnailService.getThumbnailRegistry();
        ThumbnailDefinition details = registry.getThumbnailDefinition(thumbnailName);
        if (details == null) {
            // Throw exception
            throw new ScriptException("The thumbnail name '" + thumbnailName + "' is not registered");
        }
        // If there's nothing currently registered to generate thumbnails for the
        // specified mimetype, then log a message and bail out
        String nodeMimeType = getMimetype();
        Serializable value = this.nodeService.getProperty(nodeRef, ContentModel.PROP_CONTENT);
        ContentData contentData = DefaultTypeConverter.INSTANCE.convert(ContentData.class, value);
        if (!ContentData.hasContent(contentData)) {
            if (logger.isDebugEnabled())
                logger.debug("Unable to create thumbnail '" + details.getName() + "' as there is no content");
            return null;
        }
        if (!registry.isThumbnailDefinitionAvailable(contentData.getContentUrl(), nodeMimeType, getSize(), nodeRef, details)) {
            logger.info("Unable to create thumbnail '" + details.getName() + "' for " + nodeMimeType + " as no transformer is currently available.");
            return null;
        }
        // Have the thumbnail created
        if (async == false) {
            try {
                // Create the thumbnail
                NodeRef thumbnailNodeRef = thumbnailService.createThumbnail(this.nodeRef, ContentModel.PROP_CONTENT, details.getMimetype(), details.getTransformationOptions(), details.getName());
                // Create the thumbnail script object
                result = new ScriptThumbnail(thumbnailNodeRef, this.services, this.scope);
            } catch (AlfrescoRuntimeException e) {
                Throwable rootCause = e.getRootCause();
                if (rootCause instanceof UnimportantTransformException) {
                    logger.debug("Unable to create thumbnail '" + details.getName() + "' as " + rootCause.getMessage());
                    return null;
                }
                throw e;
            }
        } else {
            RenditionDefinition2 renditionDefinition = renditionDefinitionRegistry2.getRenditionDefinition(thumbnailName);
            if (renditionDefinition != null) {
                renditionService2.render(nodeRef, thumbnailName);
            } else {
                Action action = ThumbnailHelper.createCreateThumbnailAction(details, services);
                // Queue async creation of thumbnail
                this.services.getActionService().executeAction(action, this.nodeRef, true, true);
            }
        }
    }
    return result;
}
Also used : Serializable(java.io.Serializable) Action(org.alfresco.service.cmr.action.Action) ThumbnailService(org.alfresco.service.cmr.thumbnail.ThumbnailService) ThumbnailRegistry(org.alfresco.repo.thumbnail.ThumbnailRegistry) UnimportantTransformException(org.alfresco.repo.content.transform.UnimportantTransformException) ScriptException(org.alfresco.scripts.ScriptException) NodeRef(org.alfresco.service.cmr.repository.NodeRef) ThumbnailDefinition(org.alfresco.repo.thumbnail.ThumbnailDefinition) ContentData(org.alfresco.service.cmr.repository.ContentData) ScriptThumbnail(org.alfresco.repo.thumbnail.script.ScriptThumbnail) RenditionDefinition2(org.alfresco.repo.rendition2.RenditionDefinition2) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException)

Example 7 with RenditionDefinitionRegistry2

use of org.alfresco.repo.rendition2.RenditionDefinitionRegistry2 in project alfresco-repository by Alfresco.

the class ThumbnailRegistry method getEquivalentRenditionDefinition2.

private RenditionDefinition2 getEquivalentRenditionDefinition2(ThumbnailDefinition thumbnailDefinition) {
    String renditionName = thumbnailDefinition.getName();
    RenditionDefinition2 renditionDefinition = renditionDefinitionRegistry2.getRenditionDefinition(renditionName);
    if (renditionDefinition != null) {
        String thumbnailTargetMimetype = thumbnailDefinition.getMimetype();
        String renditionTargetMimetype = renditionDefinition.getTargetMimetype();
        if (!renditionTargetMimetype.equals(thumbnailTargetMimetype)) {
            renditionDefinition = null;
        }
    }
    return renditionDefinition;
}
Also used : RenditionDefinition2(org.alfresco.repo.rendition2.RenditionDefinition2)

Example 8 with RenditionDefinitionRegistry2

use of org.alfresco.repo.rendition2.RenditionDefinitionRegistry2 in project alfresco-repository by Alfresco.

the class RenditionServiceImpl method getEquivalentRenditionDefinition2.

// Finds a RenditionDefinition2 with the same name (local part) and target mimetype.
private RenditionDefinition2 getEquivalentRenditionDefinition2(RenditionDefinition rendDefn) {
    QName renditionQName = rendDefn.getRenditionName();
    String renditionName = renditionQName.getLocalName();
    RenditionDefinitionRegistry2 renditionDefinitionRegistry2 = renditionService2.getRenditionDefinitionRegistry2();
    RenditionDefinition2 renditionDefinition2 = renditionDefinitionRegistry2.getRenditionDefinition(renditionName);
    RenditionDefinition2 equivalentRenditionDefinition2 = null;
    if (renditionDefinition2 != null) {
        String targetMimetype = (String) rendDefn.getParameterValue(AbstractRenderingEngine.PARAM_MIME_TYPE);
        String targetMimetype2 = renditionDefinition2.getTargetMimetype();
        equivalentRenditionDefinition2 = targetMimetype.equals(targetMimetype2) ? renditionDefinition2 : null;
    }
    return equivalentRenditionDefinition2;
}
Also used : QName(org.alfresco.service.namespace.QName) RenditionDefinition2(org.alfresco.repo.rendition2.RenditionDefinition2) RenditionDefinitionRegistry2(org.alfresco.repo.rendition2.RenditionDefinitionRegistry2)

Aggregations

RenditionDefinition2 (org.alfresco.repo.rendition2.RenditionDefinition2)6 RenditionDefinitionRegistry2 (org.alfresco.repo.rendition2.RenditionDefinitionRegistry2)6 NodeRef (org.alfresco.service.cmr.repository.NodeRef)5 Rendition (org.alfresco.rest.api.model.Rendition)3 NotFoundException (org.alfresco.rest.framework.core.exceptions.NotFoundException)3 ContentData (org.alfresco.service.cmr.repository.ContentData)3 ConstraintViolatedException (org.alfresco.rest.framework.core.exceptions.ConstraintViolatedException)2 DisabledServiceException (org.alfresco.rest.framework.core.exceptions.DisabledServiceException)2 IOException (java.io.IOException)1 Serializable (java.io.Serializable)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 StringJoiner (java.util.StringJoiner)1 TreeMap (java.util.TreeMap)1 AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)1 ContentLimitViolationException (org.alfresco.repo.content.ContentLimitViolationException)1 UnimportantTransformException (org.alfresco.repo.content.transform.UnimportantTransformException)1 IntegrityException (org.alfresco.repo.node.integrity.IntegrityException)1 AccessDeniedException (org.alfresco.repo.security.permissions.AccessDeniedException)1 ThumbnailDefinition (org.alfresco.repo.thumbnail.ThumbnailDefinition)1