Search in sources :

Example 1 with RenditionDefinition

use of org.alfresco.service.cmr.rendition.RenditionDefinition in project alfresco-repository by Alfresco.

the class ThumbnailServiceImpl method createRawRenditionDefinition.

/**
 * Creates a {@link RenditionDefinition} with no parameters set.
 * @param thumbnailQName QName
 * @param transformationOptions TransformationOptions
 * @return RenditionDefinition
 */
private RenditionDefinition createRawRenditionDefinition(QName thumbnailQName, final TransformationOptions transformationOptions) {
    // Create the renditionDefinition
    String renderingEngineName = getRenderingEngineNameFor(transformationOptions);
    RenditionDefinition definition = renditionService.createRenditionDefinition(thumbnailQName, renderingEngineName);
    // Track thumbnail rendition actions so cancellation can be requested
    definition.setTrackStatus(true);
    return definition;
}
Also used : RenditionDefinition(org.alfresco.service.cmr.rendition.RenditionDefinition)

Example 2 with RenditionDefinition

use of org.alfresco.service.cmr.rendition.RenditionDefinition in project alfresco-repository by Alfresco.

the class ThumbnailServiceImpl method updateThumbnail.

/**
 * @see org.alfresco.service.cmr.thumbnail.ThumbnailService#updateThumbnail(org.alfresco.service.cmr.repository.NodeRef, org.alfresco.service.cmr.repository.TransformationOptions)
 */
public void updateThumbnail(final NodeRef thumbnail, final TransformationOptions transformationOptions) {
    if (logger.isDebugEnabled() == true) {
        logger.debug("Updating thumbnail (thumbnail=" + thumbnail.toString() + ")");
    }
    // First check that we are dealing with a rendition object
    if (renditionService.isRendition(thumbnail)) {
        // Get the node that is the source of the thumbnail
        ChildAssociationRef parentAssoc = renditionService.getSourceNode(thumbnail);
        if (parentAssoc == null) {
            if (logger.isDebugEnabled() == true) {
                logger.debug("Updating thumbnail: The thumbnails parent cannot be found (thumbnail=" + thumbnail.toString() + ")");
            }
            throw new ThumbnailException(ERR_NO_PARENT);
        }
        final QName renditionAssociationName = parentAssoc.getQName();
        NodeRef sourceNode = parentAssoc.getParentRef();
        // Get the content property
        QName contentProperty = (QName) nodeService.getProperty(thumbnail, ContentModel.PROP_CONTENT_PROPERTY_NAME);
        // Set the basic detail of the transformation options
        transformationOptions.setSourceNodeRef(sourceNode);
        transformationOptions.setSourceContentProperty(contentProperty);
        transformationOptions.setTargetContentProperty(ContentModel.PROP_CONTENT);
        // Do the thumbnail transformation. Rendition Definitions are persisted underneath the Data Dictionary for which Group ALL
        // has Consumer access by default. However, we cannot assume that that access level applies for all deployments. See ALF-7334.
        RenditionDefinition rendDefn = AuthenticationUtil.runAs(new AuthenticationUtil.RunAsWork<RenditionDefinition>() {

            @Override
            public RenditionDefinition doWork() throws Exception {
                return renditionService.loadRenditionDefinition(renditionAssociationName);
            }
        }, AuthenticationUtil.getSystemUserName());
        if (rendDefn == null) {
            String renderingEngineName = getRenderingEngineNameFor(transformationOptions);
            rendDefn = renditionService.createRenditionDefinition(parentAssoc.getQName(), renderingEngineName);
        }
        Map<String, Serializable> params = thumbnailRegistry.getThumbnailRenditionConvertor().convert(transformationOptions, null);
        for (String key : params.keySet()) {
            rendDefn.setParameterValue(key, params.get(key));
        }
        renditionService.render(sourceNode, rendDefn);
    } else {
        if (logger.isDebugEnabled() == true) {
            logger.debug("Updating thumbnail: cannot update a thumbnail node that isn't the correct thumbnail type (thumbnail=" + thumbnail.toString() + ")");
        }
    }
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) Serializable(java.io.Serializable) AuthenticationUtil(org.alfresco.repo.security.authentication.AuthenticationUtil) ThumbnailException(org.alfresco.service.cmr.thumbnail.ThumbnailException) QName(org.alfresco.service.namespace.QName) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) RenditionDefinition(org.alfresco.service.cmr.rendition.RenditionDefinition) RenditionServiceException(org.alfresco.service.cmr.rendition.RenditionServiceException) ThumbnailException(org.alfresco.service.cmr.thumbnail.ThumbnailException)

Example 3 with RenditionDefinition

use of org.alfresco.service.cmr.rendition.RenditionDefinition in project alfresco-repository by Alfresco.

the class ThumbnailRenditionConvertor method convert.

/**
 * Given the specified {@link ThumbnailDefinition thumbnailDefinition} and
 * {@link ThumbnailParentAssociationDetails assocDetails},
 * create and return an equivalent {@link RenditionDefinition} object.
 *
 * @param thumbnailDefinition ThumbnailDefinition
 * @param assocDetails ThumbnailParentAssociationDetails
 * @return RenditionDefinitions
 */
public RenditionDefinition convert(ThumbnailDefinition thumbnailDefinition, ThumbnailParentAssociationDetails assocDetails) {
    // We must always have a valid name for a thumbnail definition
    if (thumbnailDefinition == null || thumbnailDefinition.getName() == null || thumbnailDefinition.getName().trim().length() == 0) {
        throw new IllegalArgumentException("Thumbnail Definition and Name must be non-null and non-empty.");
    }
    TransformationOptions transformationOptions = thumbnailDefinition.getTransformationOptions();
    Map<String, Serializable> parameters = this.convert(transformationOptions, assocDetails);
    // Extract parameters defined directly within the ThumbnailDefinition object.
    putParameterIfNotNull(AbstractRenderingEngine.PARAM_MIME_TYPE, thumbnailDefinition.getMimetype(), parameters);
    putParameterIfNotNull(AbstractRenderingEngine.PARAM_PLACEHOLDER_RESOURCE_PATH, thumbnailDefinition.getPlaceHolderResourcePath(), parameters);
    putParameterIfNotNull(AbstractRenderingEngine.PARAM_RUN_AS, thumbnailDefinition.getRunAs(), parameters);
    QName namespacedRenditionName = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, thumbnailDefinition.getName());
    // The built-in RenditionDefinitions are all non-composites.
    // They are either "imageRenderingEngine" or "reformat"
    boolean isImageThumbnail = isImageBasedRendition(thumbnailDefinition);
    String renderingEngineName = isImageThumbnail ? ImageRenderingEngine.NAME : ReformatRenderingEngine.NAME;
    RenditionDefinition renditionDef = renditionService.createRenditionDefinition(namespacedRenditionName, renderingEngineName);
    for (String paramName : parameters.keySet()) {
        renditionDef.setParameterValue(paramName, parameters.get(paramName));
    }
    return renditionDef;
}
Also used : Serializable(java.io.Serializable) QName(org.alfresco.service.namespace.QName) RenditionDefinition(org.alfresco.service.cmr.rendition.RenditionDefinition) SWFTransformationOptions(org.alfresco.repo.content.transform.swf.SWFTransformationOptions) ImageTransformationOptions(org.alfresco.repo.content.transform.magick.ImageTransformationOptions) TransformationOptions(org.alfresco.service.cmr.repository.TransformationOptions)

Example 4 with RenditionDefinition

use of org.alfresco.service.cmr.rendition.RenditionDefinition in project alfresco-repository by Alfresco.

the class RenditionServiceImpl method render.

/*
     * (non-Javadoc)
     * @see org.alfresco.service.cmr.rendition.RenditionService#render(org.alfresco.service.cmr.repository.NodeRef, org.alfresco.service.namespace.QName)
     */
public ChildAssociationRef render(NodeRef sourceNode, final QName renditionDefinitionQName) {
    checkSourceNodeForPreventionClass(sourceNode);
    RenditionDefinition rendDefn = AuthenticationUtil.runAs(new AuthenticationUtil.RunAsWork<RenditionDefinition>() {

        public RenditionDefinition doWork() throws Exception {
            return loadRenditionDefinition(renditionDefinitionQName);
        }
    }, AuthenticationUtil.getSystemUserName());
    if (rendDefn == null) {
        throw new RenditionServiceException("Rendition Definition " + renditionDefinitionQName + " was not found.");
    }
    return this.render(sourceNode, rendDefn);
}
Also used : AuthenticationUtil(org.alfresco.repo.security.authentication.AuthenticationUtil) RenditionDefinition(org.alfresco.service.cmr.rendition.RenditionDefinition) CompositeRenditionDefinition(org.alfresco.service.cmr.rendition.CompositeRenditionDefinition) RenditionServiceException(org.alfresco.service.cmr.rendition.RenditionServiceException) RenditionServiceException(org.alfresco.service.cmr.rendition.RenditionServiceException) RenditionPreventedException(org.alfresco.service.cmr.rendition.RenditionPreventedException)

Example 5 with RenditionDefinition

use of org.alfresco.service.cmr.rendition.RenditionDefinition in project alfresco-repository by Alfresco.

the class RenditionServiceImpl method render.

/*
     * (non-Javadoc)
     * @see org.alfresco.service.cmr.rendition.RenditionService#render(org.alfresco.service.cmr.repository.NodeRef, org.alfresco.service.namespace.QName, org.alfresco.service.cmr.rendition.RenderCallback)
     */
public void render(NodeRef sourceNode, final QName renditionDefinitionQName, RenderCallback callback) {
    checkSourceNodeForPreventionClass(sourceNode);
    RenditionDefinition rendDefn = AuthenticationUtil.runAs(new AuthenticationUtil.RunAsWork<RenditionDefinition>() {

        public RenditionDefinition doWork() throws Exception {
            return loadRenditionDefinition(renditionDefinitionQName);
        }
    }, AuthenticationUtil.getSystemUserName());
    if (rendDefn == null) {
        throw new RenditionServiceException("Rendition Definition " + renditionDefinitionQName + " was not found.");
    }
    this.render(sourceNode, rendDefn, callback);
}
Also used : AuthenticationUtil(org.alfresco.repo.security.authentication.AuthenticationUtil) RenditionDefinition(org.alfresco.service.cmr.rendition.RenditionDefinition) CompositeRenditionDefinition(org.alfresco.service.cmr.rendition.CompositeRenditionDefinition) RenditionServiceException(org.alfresco.service.cmr.rendition.RenditionServiceException) RenditionServiceException(org.alfresco.service.cmr.rendition.RenditionServiceException) RenditionPreventedException(org.alfresco.service.cmr.rendition.RenditionPreventedException)

Aggregations

RenditionDefinition (org.alfresco.service.cmr.rendition.RenditionDefinition)58 ChildAssociationRef (org.alfresco.service.cmr.repository.ChildAssociationRef)32 QName (org.alfresco.service.namespace.QName)28 Test (org.junit.Test)25 CompositeRenditionDefinition (org.alfresco.service.cmr.rendition.CompositeRenditionDefinition)22 BaseAlfrescoSpringTest (org.alfresco.util.BaseAlfrescoSpringTest)21 AbstractContentTransformerTest (org.alfresco.repo.content.transform.AbstractContentTransformerTest)14 NodeRef (org.alfresco.service.cmr.repository.NodeRef)13 Serializable (java.io.Serializable)11 RetryingTransactionHelper (org.alfresco.repo.transaction.RetryingTransactionHelper)11 RetryingTransactionCallback (org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback)9 RenditionServiceException (org.alfresco.service.cmr.rendition.RenditionServiceException)9 ArrayList (java.util.ArrayList)6 ContentReader (org.alfresco.service.cmr.repository.ContentReader)6 AuthenticationUtil (org.alfresco.repo.security.authentication.AuthenticationUtil)5 FileInfo (org.alfresco.service.cmr.model.FileInfo)5 HashMap (java.util.HashMap)3 RenderingContext (org.alfresco.repo.rendition.executer.AbstractRenderingEngine.RenderingContext)3 List (java.util.List)2 ImageTransformationOptions (org.alfresco.repo.content.transform.magick.ImageTransformationOptions)2