Search in sources :

Example 6 with RenditionDefinition

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

the class CompositeRenderingEngine method executeCompositeRendition.

private ChildAssociationRef executeCompositeRendition(CompositeRenditionDefinition definition, NodeRef sourceNode) {
    NodeRef source = sourceNode;
    ChildAssociationRef result = null;
    QName assocType = definition.getRenditionAssociationType();
    NodeRef parent = definition.getRenditionParent();
    for (RenditionDefinition subDefinition : definition.getActions()) {
        ChildAssociationRef nextResult = executeSubDefinition(source, subDefinition, parent, assocType);
        if (result != null) {
            // Clean up temporary renditions.
            nodeService.removeChild(parent, result.getChildRef());
            if (logger.isDebugEnabled()) {
                logger.debug("removeChild parentRef:" + parent + ", childRef;" + result.getChildRef());
            }
        }
        result = nextResult;
        source = nextResult.getChildRef();
    }
    return result;
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) QName(org.alfresco.service.namespace.QName) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) RenditionDefinition(org.alfresco.service.cmr.rendition.RenditionDefinition) CompositeRenditionDefinition(org.alfresco.service.cmr.rendition.CompositeRenditionDefinition)

Example 7 with RenditionDefinition

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

the class RenditionServicePermissionsTest method testRenditionAccessPermissions.

/**
 * This test method uses the RenditionService to render a test document and place the
 * rendition under a folder for which the user does not have write permissions.
 * This should be allowed as all renditions are performed as system.
 */
@Test
public void testRenditionAccessPermissions() throws Exception {
    final String normalUser = TEST_USER1.getUsername();
    // As admin, create a user who has read-only access to the testFolder
    transactionHelper.doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<Void>() {

        public Void execute() throws Throwable {
            // Restrict write access to the test folder
            permissionService.setPermission(testFolder, normalUser, PermissionService.CONSUMER, true);
            return null;
        }
    });
    // As the user, render a piece of content with the rendition going to testFolder
    final NodeRef rendition = transactionHelper.doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<NodeRef>() {

        public NodeRef execute() throws Throwable {
            // Set the current security context as a rendition user
            AuthenticationUtil.setFullyAuthenticatedUser(normalUser);
            assertFalse("Source node has unexpected renditioned aspect.", nodeService.hasAspect(nodeWithImageContent, RenditionModel.ASPECT_RENDITIONED));
            String path = testFolderName + "/testRendition.png";
            // Create the rendering action.
            RenditionDefinition action = makeRescaleImageAction();
            action.setParameterValue(RenditionService.PARAM_DESTINATION_PATH_TEMPLATE, path);
            // Perform the action with an explicit destination folder
            logger.debug("Creating rendition of: " + nodeWithImageContent);
            ChildAssociationRef renditionAssoc = renditionService.render(nodeWithImageContent, action);
            logger.debug("Created rendition: " + renditionAssoc.getChildRef());
            NodeRef renditionNode = renditionAssoc.getChildRef();
            testNodes.addNodeRef(renditionNode);
            assertEquals("The parent node was not correct", nodeWithImageContent, renditionAssoc.getParentRef());
            logger.debug("rendition's primary parent: " + nodeService.getPrimaryParent(renditionNode));
            assertEquals("The parent node was not correct", testFolder, nodeService.getPrimaryParent(renditionNode).getParentRef());
            // Now the source content node should have the rn:renditioned aspect
            assertTrue("Source node is missing renditioned aspect.", nodeService.hasAspect(nodeWithImageContent, RenditionModel.ASPECT_RENDITIONED));
            return renditionNode;
        }
    });
    transactionHelper.doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<Void>() {

        public Void execute() throws Throwable {
            // Set the current security context as admin
            AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
            final Serializable renditionCreator = nodeService.getProperty(rendition, ContentModel.PROP_CREATOR);
            assertEquals("Incorrect creator", normalUser, renditionCreator);
            return null;
        }
    });
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) Serializable(java.io.Serializable) RetryingTransactionHelper(org.alfresco.repo.transaction.RetryingTransactionHelper) RenditionDefinition(org.alfresco.service.cmr.rendition.RenditionDefinition) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) Test(org.junit.Test)

Example 8 with RenditionDefinition

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

the class RenditionServiceIntegrationTest method testRenderFreeMarkerTemplateOneTransaction.

@Test
public void testRenderFreeMarkerTemplateOneTransaction() throws Exception {
    final QName renditionName = QName.createQName(NamespaceService.RENDITION_MODEL_1_0_URI, FreemarkerRenderingEngine.NAME);
    this.renditionNode = transactionHelper.doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<NodeRef>() {

        public NodeRef execute() throws Throwable {
            // create test model
            RenditionDefinition definition = renditionService.createRenditionDefinition(renditionName, FreemarkerRenderingEngine.NAME);
            definition.setParameterValue(FreemarkerRenderingEngine.PARAM_TEMPLATE_NODE, nodeWithFreeMarkerContent);
            ChildAssociationRef renditionAssoc = renditionService.render(nodeWithDocContent, definition);
            assertNotNull("The rendition association was null", renditionAssoc);
            String output = readTextContent(renditionAssoc.getChildRef());
            assertNotNull("The rendition content was null.", output);
            // check the output contains root node Id as expected.
            assertTrue(output.contains(nodeWithDocContent.getId()));
            return null;
        }
    });
}
Also used : RetryingTransactionCallback(org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback) QName(org.alfresco.service.namespace.QName) RenditionDefinition(org.alfresco.service.cmr.rendition.RenditionDefinition) CompositeRenditionDefinition(org.alfresco.service.cmr.rendition.CompositeRenditionDefinition) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) BaseAlfrescoSpringTest(org.alfresco.util.BaseAlfrescoSpringTest) Test(org.junit.Test) AbstractContentTransformerTest(org.alfresco.repo.content.transform.AbstractContentTransformerTest)

Example 9 with RenditionDefinition

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

the class RenditionServiceIntegrationTest method testBuiltinRenditionDefinitions.

/**
 * This test method ensures that all the 'built-in' renditionDefinitions are
 * available after startup and that their configuration is correct.
 *
 * @throws Exception
 */
@Test
public void testBuiltinRenditionDefinitions() throws Exception {
    final RenditionDefinition mediumRenditionDef = loadAndValidateRenditionDefinition("medium");
    final RenditionDefinition doclibRenditionDef = loadAndValidateRenditionDefinition("doclib");
    final RenditionDefinition imgpreviewRenditionDef = loadAndValidateRenditionDefinition("imgpreview");
    final RenditionDefinition webpreviewRenditionDef = loadAndValidateRenditionDefinition("webpreview");
    final RenditionDefinition avatarRenditionDef = loadAndValidateRenditionDefinition("avatar");
    assertEquals(MimetypeMap.MIMETYPE_IMAGE_JPEG, mediumRenditionDef.getParameterValue(AbstractRenderingEngine.PARAM_MIME_TYPE));
    assertEquals(MimetypeMap.MIMETYPE_IMAGE_PNG, doclibRenditionDef.getParameterValue(AbstractRenderingEngine.PARAM_MIME_TYPE));
    assertEquals(MimetypeMap.MIMETYPE_IMAGE_JPEG, imgpreviewRenditionDef.getParameterValue(AbstractRenderingEngine.PARAM_MIME_TYPE));
    assertEquals(MimetypeMap.MIMETYPE_FLASH, webpreviewRenditionDef.getParameterValue(AbstractRenderingEngine.PARAM_MIME_TYPE));
    assertEquals(MimetypeMap.MIMETYPE_IMAGE_PNG, avatarRenditionDef.getParameterValue(AbstractRenderingEngine.PARAM_MIME_TYPE));
}
Also used : RenditionDefinition(org.alfresco.service.cmr.rendition.RenditionDefinition) CompositeRenditionDefinition(org.alfresco.service.cmr.rendition.CompositeRenditionDefinition) BaseAlfrescoSpringTest(org.alfresco.util.BaseAlfrescoSpringTest) Test(org.junit.Test) AbstractContentTransformerTest(org.alfresco.repo.content.transform.AbstractContentTransformerTest)

Example 10 with RenditionDefinition

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

the class RenditionServiceIntegrationTest method testSaveAndLoadCompositeRenditionDefinition.

@Test
public void testSaveAndLoadCompositeRenditionDefinition() throws Exception {
    final QName renditionName = QName.createQName(NamespaceService.RENDITION_MODEL_1_0_URI, "composite");
    final CompositeRenditionDefinition compositeDefinition = makeCompositeReformatAndResizeDefinition(renditionName, 20, 30);
    final List<RenditionDefinition> savedRenditionDefinitions = new ArrayList<RenditionDefinition>();
    try {
        // First save composite rendition definition.
        transactionHelper.doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<Void>() {

            public Void execute() throws Throwable {
                renditionService.saveRenditionDefinition(compositeDefinition);
                return null;
            }
        });
        // Then load the definition back up and check it matches the
        // original.
        transactionHelper.doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<Void>() {

            public Void execute() throws Throwable {
                RenditionDefinition result = renditionService.loadRenditionDefinition(renditionName);
                // Check basic rendition definition properties.
                assertEquals(renditionName, result.getRenditionName());
                assertEquals(compositeDefinition.getActionDefinitionName(), result.getActionDefinitionName());
                assertEquals(compositeDefinition.getCompensatingAction(), result.getCompensatingAction());
                assertEquals(compositeDefinition.getDescription(), result.getDescription());
                assertEquals(compositeDefinition.getExecuteAsychronously(), result.getExecuteAsychronously());
                assertEquals(compositeDefinition.getModifiedDate(), result.getModifiedDate());
                assertEquals(compositeDefinition.getModifier(), result.getModifier());
                assertEquals(compositeDefinition.getTitle(), result.getTitle());
                // Check sub-actions.
                if (result instanceof CompositeRenditionDefinition) {
                    CompositeRenditionDefinition compositeResult = (CompositeRenditionDefinition) result;
                    savedRenditionDefinitions.add(compositeResult);
                    List<RenditionDefinition> subDefinitions = compositeResult.getActions();
                    assertEquals(2, subDefinitions.size());
                    // Check the first sub-definition is correct.
                    RenditionDefinition firstDef = subDefinitions.get(0);
                    assertEquals(ReformatRenderingEngine.NAME, firstDef.getActionDefinitionName());
                    // Check the second sub-definition is correct.
                    RenditionDefinition secondDef = subDefinitions.get(1);
                    assertEquals(ImageRenderingEngine.NAME, secondDef.getActionDefinitionName());
                } else
                    fail("The retrieved rendition should be a CompositeRenditionDefinition.");
                return null;
            }
        });
    } finally {
        cleanUpPersistedActions(savedRenditionDefinitions);
    }
}
Also used : RetryingTransactionHelper(org.alfresco.repo.transaction.RetryingTransactionHelper) QName(org.alfresco.service.namespace.QName) CompositeRenditionDefinition(org.alfresco.service.cmr.rendition.CompositeRenditionDefinition) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) RenditionDefinition(org.alfresco.service.cmr.rendition.RenditionDefinition) CompositeRenditionDefinition(org.alfresco.service.cmr.rendition.CompositeRenditionDefinition) BaseAlfrescoSpringTest(org.alfresco.util.BaseAlfrescoSpringTest) Test(org.junit.Test) AbstractContentTransformerTest(org.alfresco.repo.content.transform.AbstractContentTransformerTest)

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