Search in sources :

Example 6 with CompositeRenditionDefinition

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

the class RenditionServiceIntegrationTest method testCompositeReformatAndResizeRendition.

@Test
public void testCompositeReformatAndResizeRendition() throws Exception {
    final QName renditionName = QName.createQName(NamespaceService.RENDITION_MODEL_1_0_URI, "composite");
    final int newX = 20;
    final int newY = 30;
    renditionNode = transactionHelper.doInTransaction(new // 
    RetryingTransactionHelper.RetryingTransactionCallback<NodeRef>() {

        public NodeRef execute() throws Throwable {
            CompositeRenditionDefinition compositeDefinition = makeCompositeReformatAndResizeDefinition(renditionName, newX, newY);
            ChildAssociationRef renditionAssoc = renditionService.render(nodeWithDocContent, compositeDefinition);
            validateRenditionAssociation(renditionAssoc, renditionName);
            return renditionAssoc.getChildRef();
        }
    });
    transactionHelper.doInTransaction(new // 
    RetryingTransactionHelper.RetryingTransactionCallback<Void>() {

        public Void execute() throws Throwable {
            List<ChildAssociationRef> renditions = renditionService.getRenditions(nodeWithDocContent);
            assertEquals("There should only be one rendition", 1, renditions.size());
            ChildAssociationRef renditionAssoc = renditions.get(0);
            assertEquals("The association name should match the composite rendition name", renditionName, renditionAssoc.getQName());
            NodeRef rendition = renditionAssoc.getChildRef();
            ContentReader reader = contentService.getReader(rendition, ContentModel.PROP_CONTENT);
            assertEquals("The mimetype is wrong", MimetypeMap.MIMETYPE_IMAGE_JPEG, reader.getMimetype());
            assertNotNull("Reader to rendered image was null", reader);
            BufferedImage img = ImageIO.read(reader.getContentInputStream());
            assertEquals("Rendered image had wrong height", newY, img.getHeight());
            assertEquals("Rendered image had wrong width", newX, img.getWidth());
            return null;
        }
    });
}
Also used : RetryingTransactionHelper(org.alfresco.repo.transaction.RetryingTransactionHelper) QName(org.alfresco.service.namespace.QName) ContentReader(org.alfresco.service.cmr.repository.ContentReader) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) BufferedImage(java.awt.image.BufferedImage) NodeRef(org.alfresco.service.cmr.repository.NodeRef) RetryingTransactionCallback(org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback) CompositeRenditionDefinition(org.alfresco.service.cmr.rendition.CompositeRenditionDefinition) List(java.util.List) ArrayList(java.util.ArrayList) BaseAlfrescoSpringTest(org.alfresco.util.BaseAlfrescoSpringTest) Test(org.junit.Test) AbstractContentTransformerTest(org.alfresco.repo.content.transform.AbstractContentTransformerTest)

Aggregations

CompositeRenditionDefinition (org.alfresco.service.cmr.rendition.CompositeRenditionDefinition)6 RenditionDefinition (org.alfresco.service.cmr.rendition.RenditionDefinition)4 ChildAssociationRef (org.alfresco.service.cmr.repository.ChildAssociationRef)4 QName (org.alfresco.service.namespace.QName)4 AbstractContentTransformerTest (org.alfresco.repo.content.transform.AbstractContentTransformerTest)3 BaseAlfrescoSpringTest (org.alfresco.util.BaseAlfrescoSpringTest)3 Test (org.junit.Test)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 RetryingTransactionHelper (org.alfresco.repo.transaction.RetryingTransactionHelper)2 RenditionServiceException (org.alfresco.service.cmr.rendition.RenditionServiceException)2 NodeRef (org.alfresco.service.cmr.repository.NodeRef)2 BufferedImage (java.awt.image.BufferedImage)1 RetryingTransactionCallback (org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback)1 ContentReader (org.alfresco.service.cmr.repository.ContentReader)1