Search in sources :

Example 51 with RenditionDefinition

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

the class RenditionServiceIntegrationTest method testSuitablyMarkedNodesDoNotGetRenditioned.

/**
 * Tests that source nodes with a suitable marker aspect on them are not renditioned.
 *
 * @since 4.0.1
 */
@Test
public void testSuitablyMarkedNodesDoNotGetRenditioned() throws Exception {
    this.renditionNode = transactionHelper.doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<NodeRef>() {

        public NodeRef execute() throws Throwable {
            // Initially the node that provides the content
            // should not have the rn:renditioned aspect on it.
            assertFalse("Source node has unexpected renditioned aspect.", nodeService.hasAspect(nodeWithImageContent, RenditionModel.ASPECT_RENDITIONED));
            // Add the marker aspect to prevent rendition
            nodeService.addAspect(nodeWithImageContent, RenditionModel.ASPECT_PREVENT_RENDITIONS, null);
            RenditionDefinition action = makeReformatAction(null, MimetypeMap.MIMETYPE_TEXT_PLAIN);
            action.setParameterValue(AbstractRenderingEngine.PARAM_MIME_TYPE, MimetypeMap.MIMETYPE_IMAGE_JPEG);
            ChildAssociationRef renditionAssoc = null;
            boolean expectedExceptionThrown = false;
            try {
                renditionAssoc = renditionService.render(nodeWithImageContent, action);
            } catch (RenditionServiceException expected) {
                expectedExceptionThrown = true;
            }
            assertTrue("Expected exception was not thrown.", expectedExceptionThrown);
            return renditionAssoc == null ? null : renditionAssoc.getChildRef();
        }
    });
}
Also used : RetryingTransactionCallback(org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback) RenditionDefinition(org.alfresco.service.cmr.rendition.RenditionDefinition) CompositeRenditionDefinition(org.alfresco.service.cmr.rendition.CompositeRenditionDefinition) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) RenditionServiceException(org.alfresco.service.cmr.rendition.RenditionServiceException) BaseAlfrescoSpringTest(org.alfresco.util.BaseAlfrescoSpringTest) Test(org.junit.Test) AbstractContentTransformerTest(org.alfresco.repo.content.transform.AbstractContentTransformerTest)

Example 52 with RenditionDefinition

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

the class RenditionServiceIntegrationTest method testHTMLRenderFreeMarkerTemplate.

@Test
public void testHTMLRenderFreeMarkerTemplate() throws Exception {
    final QName renditionName = QName.createQName(NamespaceService.RENDITION_MODEL_1_0_URI, "htmlRenderingDefinition");
    int numberOfItemsInTrashcanBeforeRendition = getNumberOfItemsInTrashcan();
    this.renditionNode = transactionHelper.doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<NodeRef>() {

        @Override
        public NodeRef execute() throws Throwable {
            // create test model
            RenditionDefinition htmlDefinition = renditionService.createRenditionDefinition(renditionName, FreemarkerRenderingEngine.NAME);
            htmlDefinition.setParameterValue(FreemarkerRenderingEngine.PARAM_TEMPLATE_NODE, nodeWithFreeMarkerContent);
            htmlDefinition.setParameterValue(FreemarkerRenderingEngine.PARAM_MIME_TYPE, MimetypeMap.MIMETYPE_HTML);
            Map<String, Serializable> paramMap = new HashMap<String, Serializable>();
            paramMap.put("test", "test");
            htmlDefinition.setParameterValue(FreemarkerRenderingEngine.PARAM_MODEL, (Serializable) paramMap);
            ChildAssociationRef renditionAssoc = renditionService.render(nodeWithDocContent, htmlDefinition);
            assertNotNull("The rendition association was null", renditionAssoc);
            return renditionAssoc.getChildRef();
        }
    });
    // testcase for MNT-14386
    int numberOfItemsInTrashcanAfterRendition = getNumberOfItemsInTrashcan();
    assertEquals(numberOfItemsInTrashcanBeforeRendition, numberOfItemsInTrashcanAfterRendition);
}
Also used : Serializable(java.io.Serializable) RetryingTransactionCallback(org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback) HashMap(java.util.HashMap) 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 53 with RenditionDefinition

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

the class RenditionServiceIntegrationTest method makeRescaleImageAction.

/**
 * Creates a RenderingAction (RenditionDefinition) for the
 * RescaleImageActionExecutor.
 *
 * @return A new RenderingAction.
 */
private RenditionDefinition makeRescaleImageAction() {
    RenditionDefinition action = renditionService.createRenditionDefinition(RESCALE_RENDER_DEFN_NAME, ImageRenderingEngine.NAME);
    action.setParameterValue(ImageRenderingEngine.PARAM_RESIZE_WIDTH, 42);
    return action;
}
Also used : RenditionDefinition(org.alfresco.service.cmr.rendition.RenditionDefinition) CompositeRenditionDefinition(org.alfresco.service.cmr.rendition.CompositeRenditionDefinition)

Example 54 with RenditionDefinition

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

the class RenditionServiceIntegrationTest method testReformatImage.

/**
 * Tests that the ReformatActionExecutor can be used to render images into
 * different formats.
 *
 * @throws Exception
 */
@Test
public void testReformatImage() throws Exception {
    this.renditionNode = transactionHelper.doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<NodeRef>() {

        public NodeRef execute() throws Throwable {
            // Initially the node that provides the content
            // should not have the rn:renditioned aspect on it.
            assertFalse("Source node has unexpected renditioned aspect.", nodeService.hasAspect(nodeWithImageContent, RenditionModel.ASPECT_RENDITIONED));
            RenditionDefinition action = makeReformatAction(null, MimetypeMap.MIMETYPE_TEXT_PLAIN);
            // Set output Mimetype to JPEG.
            action.setParameterValue(AbstractRenderingEngine.PARAM_MIME_TYPE, MimetypeMap.MIMETYPE_IMAGE_JPEG);
            ChildAssociationRef renditionAssoc = renditionService.render(nodeWithImageContent, action);
            return renditionAssoc.getChildRef();
        }
    });
    transactionHelper.doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<Void>() {

        public Void execute() throws Throwable {
            ContentReader reader = contentService.getReader(renditionNode, ContentModel.PROP_CONTENT);
            assertNotNull("Reader to rendered image was null", reader);
            assertEquals(MimetypeMap.MIMETYPE_IMAGE_JPEG, reader.getMimetype());
            BufferedImage img = ImageIO.read(reader.getContentInputStream());
            assertEquals("Rendered image had wrong height", 512, img.getHeight());
            assertEquals("Rendered image had wrong width", 512, img.getWidth());
            // The upper left pixel of the image should be pure black.
            int rgbAtTopLeft = img.getRGB(1, 1);
            assertTrue("Incorrect image content.", Integer.toHexString(rgbAtTopLeft).endsWith(BLACK));
            // The lower right pixel of the image should be pure white
            int rgbAtBottomRight = img.getRGB(img.getWidth() - 1, img.getHeight() - 1);
            assertTrue("Incorrect image content.", Integer.toHexString(rgbAtBottomRight).endsWith(WHITE));
            return null;
        }
    });
}
Also used : RetryingTransactionCallback(org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback) RetryingTransactionHelper(org.alfresco.repo.transaction.RetryingTransactionHelper) ContentReader(org.alfresco.service.cmr.repository.ContentReader) RenditionDefinition(org.alfresco.service.cmr.rendition.RenditionDefinition) CompositeRenditionDefinition(org.alfresco.service.cmr.rendition.CompositeRenditionDefinition) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) BufferedImage(java.awt.image.BufferedImage) BaseAlfrescoSpringTest(org.alfresco.util.BaseAlfrescoSpringTest) Test(org.junit.Test) AbstractContentTransformerTest(org.alfresco.repo.content.transform.AbstractContentTransformerTest)

Example 55 with RenditionDefinition

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

the class RenditionServiceIntegrationTest method testGetRenditionsForNode.

@Test
public void testGetRenditionsForNode() throws Exception {
    this.renditionNode = transactionHelper.doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<NodeRef>() {

        public NodeRef execute() throws Throwable {
            // Initially the node that provides the content
            // should have no renditions
            assertTrue("Test node should have no renditions initially", renditionService.getRenditions(nodeWithImageContent).isEmpty());
            // Create 4 arbitrary rendition definitions
            QName rendName1 = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "definition1" + System.currentTimeMillis());
            RenditionDefinition action1 = renditionService.createRenditionDefinition(rendName1, ReformatRenderingEngine.NAME);
            action1.setParameterValue(AbstractRenderingEngine.PARAM_MIME_TYPE, MimetypeMap.MIMETYPE_IMAGE_GIF);
            QName rendName2 = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "definition2" + System.currentTimeMillis());
            RenditionDefinition action2 = renditionService.createRenditionDefinition(rendName2, ReformatRenderingEngine.NAME);
            action2.setParameterValue(AbstractRenderingEngine.PARAM_MIME_TYPE, MimetypeMap.MIMETYPE_IMAGE_JPEG);
            QName rendName3 = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "definition3" + System.currentTimeMillis());
            RenditionDefinition action3 = renditionService.createRenditionDefinition(rendName3, ImageRenderingEngine.NAME);
            action3.setParameterValue(ImageRenderingEngine.PARAM_RESIZE_WIDTH, 64);
            action3.setParameterValue(ImageRenderingEngine.PARAM_RESIZE_HEIGHT, 64);
            action3.setParameterValue(AbstractRenderingEngine.PARAM_MIME_TYPE, MimetypeMap.MIMETYPE_IMAGE_PNG);
            // The 4th intentionally reuses the rendition name
            // from the third
            QName rendName4 = rendName3;
            RenditionDefinition action4 = renditionService.createRenditionDefinition(rendName4, ImageRenderingEngine.NAME);
            action4.setParameterValue(ImageRenderingEngine.PARAM_RESIZE_WIDTH, 128);
            action4.setParameterValue(ImageRenderingEngine.PARAM_RESIZE_HEIGHT, 128);
            action4.setParameterValue(AbstractRenderingEngine.PARAM_MIME_TYPE, MimetypeMap.MIMETYPE_IMAGE_PNG);
            // Execute the 4 renditions.
            ChildAssociationRef createdRendition1 = renditionService.render(nodeWithImageContent, action1);
            ChildAssociationRef createdRendition2 = renditionService.render(nodeWithImageContent, action2);
            ChildAssociationRef createdRendition3 = renditionService.render(nodeWithImageContent, action3);
            ChildAssociationRef createdRendition4 = renditionService.render(nodeWithImageContent, action4);
            // Now validate the getRenditions methods
            List<ChildAssociationRef> allRenditions = renditionService.getRenditions(nodeWithImageContent);
            ChildAssociationRef retrievedRendition1 = renditionService.getRenditionByName(nodeWithImageContent, rendName1);
            ChildAssociationRef retrievedRendition2 = renditionService.getRenditionByName(nodeWithImageContent, rendName2);
            ChildAssociationRef retrievedRendition3 = renditionService.getRenditionByName(nodeWithImageContent, rendName3);
            ChildAssociationRef retrievedRendition4 = renditionService.getRenditionByName(nodeWithImageContent, rendName4);
            // allRenditions should contain only 3 renditions.
            // The 4th should have replaced the 3rd.
            assertEquals(3, allRenditions.size());
            assertTrue(allRenditions.contains(createdRendition1));
            assertTrue(allRenditions.contains(createdRendition2));
            assertTrue(allRenditions.contains(createdRendition4));
            for (ChildAssociationRef rendition : allRenditions) {
                assertNotSame(createdRendition3, rendition);
            }
            assertEquals(createdRendition1, retrievedRendition1);
            assertEquals(createdRendition2, retrievedRendition2);
            assertEquals(createdRendition4, retrievedRendition3);
            assertEquals(createdRendition4, retrievedRendition4);
            // CMIS-style filters. image/*
            List<ChildAssociationRef> imageRenditions = renditionService.getRenditions(nodeWithImageContent, "image");
            assertEquals(3, imageRenditions.size());
            List<ChildAssociationRef> imageSlashJRenditions = renditionService.getRenditions(nodeWithImageContent, "image/j");
            assertEquals(1, imageSlashJRenditions.size());
            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)

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