Search in sources :

Example 26 with RenditionDefinition

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

the class ThumbnailServiceImpl method createThumbnailNode.

private NodeRef createThumbnailNode(final NodeRef node, final QName contentProperty, final String mimetype, final TransformationOptions transformationOptions, final String thumbnailName, final ThumbnailParentAssociationDetails assocDetails) {
    // Get the name of the thumbnail and add to properties map
    QName thumbnailQName = getThumbnailQName(thumbnailName);
    RenditionDefinition definition = createRenditionDefinition(contentProperty, mimetype, transformationOptions, thumbnailQName, assocDetails);
    try {
        ChildAssociationRef thumbnailAssoc = renditionService.render(node, definition);
        NodeRef thumbnail = getThumbnailNode(thumbnailAssoc);
        setThumbnailNameProperty(thumbnail, thumbnailName);
        return thumbnail;
    } catch (RenditionServiceException rsx) {
        throw new ThumbnailException(rsx.getMessage(), rsx);
    }
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) QName(org.alfresco.service.namespace.QName) ThumbnailException(org.alfresco.service.cmr.thumbnail.ThumbnailException) RenditionDefinition(org.alfresco.service.cmr.rendition.RenditionDefinition) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) RenditionServiceException(org.alfresco.service.cmr.rendition.RenditionServiceException)

Example 27 with RenditionDefinition

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

the class ThumbnailRegistry method initThumbnailDefinitionsTransaction.

private void initThumbnailDefinitionsTransaction() {
    RetryingTransactionHelper transactionHelper = transactionService.getRetryingTransactionHelper();
    transactionHelper.doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<Void>() {

        @Override
        public Void execute() throws Throwable {
            for (String thumbnailDefName : thumbnailDefinitions.keySet()) {
                final ThumbnailDefinition thumbnailDefinition = thumbnailDefinitions.get(thumbnailDefName);
                // Built-in thumbnailDefinitions do not provide any non-standard values
                // for the ThumbnailParentAssociationDetails object. Hence the null
                RenditionDefinition renditionDef = thumbnailRenditionConvertor.convert(thumbnailDefinition, null);
                // Thumbnail definitions are saved into the repository as actions
                renditionService.saveRenditionDefinition(renditionDef);
            }
            return null;
        }
    });
}
Also used : RetryingTransactionHelper(org.alfresco.repo.transaction.RetryingTransactionHelper) RenditionDefinition(org.alfresco.service.cmr.rendition.RenditionDefinition)

Example 28 with RenditionDefinition

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

the class ThumbnailServiceImpl method createRenditionDefinition.

/**
 * Creates a fully parameterized {@link RenditionDefinition}.
 * @param contentProperty QName
 * @param mimetype String
 * @param transformationOptions TransformationOptions
 * @param thumbnailQName QName
 * @param assocDetails ThumbnailParentAssociationDetails
 * @return RenditionDefinition
 */
private RenditionDefinition createRenditionDefinition(final QName contentProperty, final String mimetype, final TransformationOptions transformationOptions, final QName thumbnailQName, final ThumbnailParentAssociationDetails assocDetails) {
    RenditionDefinition definition = createRawRenditionDefinition(thumbnailQName, transformationOptions);
    // Convert the TransformationOptions and ThumbnailParentAssocDetails to
    // rendition-style parameters
    Map<String, Serializable> params = thumbnailRegistry.getThumbnailRenditionConvertor().convert(transformationOptions, assocDetails);
    // Add the other parameters given in this method signature.
    params.put(AbstractRenderingEngine.PARAM_SOURCE_CONTENT_PROPERTY, contentProperty);
    params.put(AbstractRenderingEngine.PARAM_MIME_TYPE, mimetype);
    // Set the parameters on the rendition definition.
    definition.addParameterValues(params);
    return definition;
}
Also used : Serializable(java.io.Serializable) RenditionDefinition(org.alfresco.service.cmr.rendition.RenditionDefinition)

Example 29 with RenditionDefinition

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

the class RenditionedAspect method onUpdateProperties.

/**
 * @see org.alfresco.repo.node.NodeServicePolicies.OnUpdatePropertiesPolicy#onUpdateProperties(org.alfresco.service.cmr.repository.NodeRef, java.util.Map, java.util.Map)
 */
public void onUpdateProperties(NodeRef nodeRef, Map<QName, Serializable> before, Map<QName, Serializable> after) {
    if (this.nodeService.exists(nodeRef)) {
        // Find the changed properties
        List<QName> changedProperties = getChangedProperties(before, after);
        // There may be a different policy for different rendition kinds.
        List<ChildAssociationRef> renditions = getRenditionChildAssociations(nodeRef);
        for (ChildAssociationRef chAssRef : renditions) {
            final QName renditionAssocName = chAssRef.getQName();
            // 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(renditionAssocName);
                }
            }, AuthenticationUtil.getSystemUserName());
            if (rendDefn == null) {
                if (logger.isDebugEnabled()) {
                    // We will see this debug if a new RenditionService2 definition exists.
                    StringBuilder msg = new StringBuilder();
                    msg.append("Cannot update rendition ").append(renditionAssocName).append(" on node ").append(nodeRef).append(" as the renditionDefinition could not be loaded.");
                    logger.debug(msg.toString());
                }
                continue;
            }
            Serializable updateRenditionsPolicy = rendDefn.getParameterValue(AbstractRenderingEngine.PARAM_UPDATE_RENDITIONS_ON_ANY_PROPERTY_CHANGE);
            boolean updateRenditionsAlways = updateRenditionsPolicy == null ? false : (Boolean) updateRenditionsPolicy;
            boolean renditionUpdateRequired = false;
            for (QName qname : changedProperties) {
                try {
                    PropertyDefinition propertyDef = dictionaryService.getProperty(qname);
                    if (propertyDef == null) {
                        // the property is not recognised
                        continue;
                    } else if (!propertyDef.getDataType().getName().equals(DataTypeDefinition.CONTENT)) {
                        // not a content type
                        if (updateRenditionsAlways) {
                            renditionUpdateRequired = true;
                        }
                        continue;
                    } else {
                        // it is a content property. We always update renditions for changes to content.
                        renditionUpdateRequired = true;
                    }
                } catch (ClassCastException ccx) {
                    // the property does not confirm to the model
                    continue;
                }
            }
            if (renditionUpdateRequired) {
                this.queueUpdate(nodeRef, rendDefn, chAssRef);
            }
        }
    }
}
Also used : Serializable(java.io.Serializable) QName(org.alfresco.service.namespace.QName) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) PropertyDefinition(org.alfresco.service.cmr.dictionary.PropertyDefinition) AuthenticationUtil(org.alfresco.repo.security.authentication.AuthenticationUtil) RenditionDefinition(org.alfresco.service.cmr.rendition.RenditionDefinition)

Example 30 with RenditionDefinition

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

the class AbstractRenderingEngine method executeRenditionImpl.

protected void executeRenditionImpl(Action action, NodeRef sourceNode) {
    if (logger.isDebugEnabled()) {
        StringBuilder msg = new StringBuilder();
        msg.append("Executing rendering engine; name:").append(this.name).append(", class:").append(this.getClass().getName());
        logger.debug(msg.toString());
    }
    checkParameterValues(action);
    RenditionDefinition renditionDefinition = checkActionIsRenditionDefinition(action);
    checkSourceNodeExists(sourceNode);
    QName targetContentProp = getRenditionContentProperty(renditionDefinition);
    RenderingContext context = new RenderingContext(sourceNode, renditionDefinition, targetContentProp);
    render(context);
    // This is a workaround for the fact that actions don't have return
    // values.
    action.getParameterValues().put(PARAM_RESULT, context.getChildAssociationRef());
}
Also used : QName(org.alfresco.service.namespace.QName) RenditionDefinition(org.alfresco.service.cmr.rendition.RenditionDefinition)

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