Search in sources :

Example 21 with RenditionDefinition

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

the class ThumbnailServiceImplParameterTest method initMockObjects.

@Before
public void initMockObjects() {
    renditionService = new RenditionServiceImpl() {

        @Override
        public RenditionDefinition loadRenditionDefinition(QName renditionDefinitionName) {
            // We're intentionally returning null for this test.
            return null;
        }
    };
    renditionService.setActionService(mockActionService);
    renditionService.setServiceRegistry(new MockedTestServiceRegistry());
    renditionService.setRenditionService2(mockRenditionService2);
    when(mockRenditionService2.isCreatedByRenditionService2(any(), any())).thenReturn(false);
    ThumbnailServiceImpl thumbs = new ThumbnailServiceImpl() {

        @Override
        public NodeRef getThumbnailByName(NodeRef node, QName contentProperty, String thumbnailName) {
            return null;
        }

        /**
         * In this test the thumbnailRef will be null, so we need to ensure
         * it is not dereferenced here.
         */
        @Override
        public NodeRef getThumbnailNode(ChildAssociationRef thumbnailRef) {
            return null;
        }
    };
    thumbs.setRenditionService(renditionService);
    thumbs.setThumbnailRegistry(new ThumbnailRegistry() {

        @Override
        public ThumbnailRenditionConvertor getThumbnailRenditionConvertor() {
            return new ThumbnailRenditionConvertor();
        }
    });
    thumbs.setNodeService(mock(NodeService.class));
    TransactionServiceImpl transactionServiceImpl = new TransactionServiceImpl() {

        @Override
        public boolean getAllowWrite() {
            return true;
        }

        @Override
        public boolean isReadOnly() {
            return false;
        }

        @Override
        public RetryingTransactionHelper getRetryingTransactionHelper() {
            RetryingTransactionHelper rth = new RetryingTransactionHelper() {

                @Override
                public <R> R doInTransaction(RetryingTransactionCallback<R> cb, boolean readOnly, boolean requiresNew) {
                    try {
                        return cb.execute();
                    } catch (Throwable e) {
                        e.printStackTrace();
                    }
                    return null;
                }
            };
            return rth;
        }
    };
    thumbs.setTransactionService(transactionServiceImpl);
    thumbnailService = thumbs;
}
Also used : RetryingTransactionHelper(org.alfresco.repo.transaction.RetryingTransactionHelper) QName(org.alfresco.service.namespace.QName) TransactionServiceImpl(org.alfresco.repo.transaction.TransactionServiceImpl) NodeService(org.alfresco.service.cmr.repository.NodeService) RenditionServiceImpl(org.alfresco.repo.rendition.RenditionServiceImpl) MockedTestServiceRegistry(org.alfresco.repo.rendition.MockedTestServiceRegistry) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) NodeRef(org.alfresco.service.cmr.repository.NodeRef) RenditionDefinition(org.alfresco.service.cmr.rendition.RenditionDefinition) Before(org.junit.Before)

Example 22 with RenditionDefinition

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

the class ScriptRenditionService method createRenditionDefinition.

/**
 * Creates a new {@link ScriptRenditionDefinition} and sets the rendition name and
 * the rendering engine name to the specified values.
 *
 * @param renditionName A unique identifier used to specify the created
 *            {@link ScriptRenditionDefinition}.
 * @param renderingEngineName The name of the rendering engine associated
 *            with this {@link ScriptRenditionDefinition}.
 * @return the created {@link ScriptRenditionDefinition}.
 * @see org.alfresco.service.cmr.rendition.RenditionService#createRenditionDefinition(QName, String)
 */
public ScriptRenditionDefinition createRenditionDefinition(String renditionName, String renderingEngineName) {
    QName renditionQName = createQName(renditionName);
    if (logger.isDebugEnabled()) {
        StringBuilder msg = new StringBuilder();
        msg.append("Creating ScriptRenditionDefinition [").append(renditionName).append(", ").append(renderingEngineName).append("]");
        logger.debug(msg.toString());
    }
    RenderingEngineDefinition engineDefinition = renditionService.getRenderingEngineDefinition(renderingEngineName);
    RenditionDefinition rendDef = renditionService.createRenditionDefinition(renditionQName, renderingEngineName);
    return new ScriptRenditionDefinition(serviceRegistry, this.getScope(), engineDefinition, rendDef);
}
Also used : RenderingEngineDefinition(org.alfresco.service.cmr.rendition.RenderingEngineDefinition) QName(org.alfresco.service.namespace.QName) RenditionDefinition(org.alfresco.service.cmr.rendition.RenditionDefinition)

Example 23 with RenditionDefinition

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

the class ScriptRenditionService method render.

/**
 * This method renders the specified source node using the specified saved
 * rendition definition.
 * @param sourceNode the source node to be rendered.
 * @param renditionDefQName the rendition definition to be used e.g. "cm:doclib" or
 *                          "{http://www.alfresco.org/model/content/1.0}imgpreview"
 * @return the rendition scriptnode.
 * @see org.alfresco.service.cmr.rendition.RenditionService#render(org.alfresco.service.cmr.repository.NodeRef, RenditionDefinition)
 */
public ScriptNode render(ScriptNode sourceNode, String renditionDefQName) {
    if (logger.isDebugEnabled()) {
        StringBuilder msg = new StringBuilder();
        msg.append("Rendering source node '").append(sourceNode).append("' with renditionDef '").append(renditionDefQName).append("'");
        logger.debug(msg.toString());
    }
    RenditionDefinition rendDef = loadRenditionDefinitionImpl(renditionDefQName);
    ChildAssociationRef result = this.renditionService.render(sourceNode.getNodeRef(), rendDef);
    NodeRef renditionNode = result.getChildRef();
    if (logger.isDebugEnabled()) {
        StringBuilder msg = new StringBuilder();
        msg.append("Rendition: ").append(renditionNode);
        logger.debug(msg.toString());
    }
    return new ScriptNode(renditionNode, serviceRegistry);
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) RenditionDefinition(org.alfresco.service.cmr.rendition.RenditionDefinition) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) ScriptNode(org.alfresco.repo.jscript.ScriptNode)

Example 24 with RenditionDefinition

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

the class ScriptRenditionService method loadRenditionDefinitionImpl.

private RenditionDefinition loadRenditionDefinitionImpl(String shortOrLongFormQName) {
    final QName renditionName = createQName(shortOrLongFormQName);
    // 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(renditionName);
        }
    }, AuthenticationUtil.getSystemUserName());
    return rendDefn;
}
Also used : AuthenticationUtil(org.alfresco.repo.security.authentication.AuthenticationUtil) QName(org.alfresco.service.namespace.QName) RenditionDefinition(org.alfresco.service.cmr.rendition.RenditionDefinition)

Example 25 with RenditionDefinition

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

the class ScriptRenditionDefinition method executeImpl.

@Override
protected void executeImpl(ScriptNode node) {
    RenditionDefinition renditionDefinition = getRenditionDefinition();
    this.services.getRenditionService().render(node.getNodeRef(), renditionDefinition);
}
Also used : 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