Search in sources :

Example 56 with RenditionDefinition

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

the class RenditionServiceIntegrationTest method testRenderFreeMarkerTemplate.

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

        @Override
        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);
            return renditionAssoc.getChildRef();
        }
    });
    transactionHelper.doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<Void>() {

        @Override
        public Void execute() throws Throwable {
            String output = readTextContent(renditionNode);
            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) RetryingTransactionHelper(org.alfresco.repo.transaction.RetryingTransactionHelper) 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 57 with RenditionDefinition

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

the class RenditionServiceImplTest method testCreateRenditionDefinition.

public void testCreateRenditionDefinition() throws Exception {
    RenditionDefinition renderingAction = renditionService.createRenditionDefinition(ACTION_NAME, ENGINE_NAME);
    assertNotNull(renderingAction);
    assertEquals(ENGINE_NAME, renderingAction.getActionDefinitionName());
    assertEquals(ACTION_NAME, renderingAction.getRenditionName());
    String id = renderingAction.getId();
    assertNotNull(id);
    assertTrue(id.length() > 0);
}
Also used : RenditionDefinition(org.alfresco.service.cmr.rendition.RenditionDefinition)

Example 58 with RenditionDefinition

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

the class ThumbnailServiceImplParameterTest method createThumbnailPassesParametersToActionService.

/**
 * This test method ensures that the parameters on thumbnail-create are
 * passed through the RenditionService to the ActionService
 */
@Test
public void createThumbnailPassesParametersToActionService() {
    // As most of the services are mocked out, the actual values used here
    // don't matter.
    final Map<String, Serializable> parametersUnderTest = new HashMap<String, Serializable>();
    parametersUnderTest.put(ImageRenderingEngine.PARAM_RESIZE_WIDTH, new Integer(42));
    parametersUnderTest.put(ImageRenderingEngine.PARAM_RESIZE_HEIGHT, new Integer(93));
    parametersUnderTest.put(ImageRenderingEngine.PARAM_COMMAND_OPTIONS, "foo");
    parametersUnderTest.put(ImageRenderingEngine.PARAM_MAINTAIN_ASPECT_RATIO, Boolean.TRUE);
    parametersUnderTest.put(ImageRenderingEngine.PARAM_RESIZE_TO_THUMBNAIL, Boolean.FALSE);
    parametersUnderTest.put(ImageRenderingEngine.PARAM_ALLOW_ENLARGEMENT, Boolean.TRUE);
    parametersUnderTest.put(AbstractRenderingEngine.PARAM_TARGET_CONTENT_PROPERTY, ContentModel.PROP_CONTENT);
    parametersUnderTest.put(RenditionService.PARAM_DESTINATION_NODE, dummyNodeRef2);
    parametersUnderTest.put(PagedSourceOptionsSerializer.PARAM_SOURCE_START_PAGE, new Integer(2));
    parametersUnderTest.put(PagedSourceOptionsSerializer.PARAM_SOURCE_END_PAGE, new Integer(2));
    parametersUnderTest.put(TemporalSourceOptionsSerializer.PARAM_SOURCE_TIME_OFFSET, "00:00:00.5");
    ImageTransformationOptions imageTransOpts = new ImageTransformationOptions();
    imageTransOpts.setTargetNodeRef(dummyNodeRef2);
    imageTransOpts.setTargetContentProperty((QName) parametersUnderTest.get(ImageRenderingEngine.PARAM_TARGET_CONTENT_PROPERTY));
    imageTransOpts.setCommandOptions((String) parametersUnderTest.get(ImageRenderingEngine.PARAM_COMMAND_OPTIONS));
    ImageResizeOptions resizeOptions = new ImageResizeOptions();
    resizeOptions.setHeight((Integer) parametersUnderTest.get(ImageRenderingEngine.PARAM_RESIZE_HEIGHT));
    resizeOptions.setWidth((Integer) parametersUnderTest.get(ImageRenderingEngine.PARAM_RESIZE_WIDTH));
    resizeOptions.setMaintainAspectRatio((Boolean) parametersUnderTest.get(ImageRenderingEngine.PARAM_MAINTAIN_ASPECT_RATIO));
    resizeOptions.setResizeToThumbnail((Boolean) parametersUnderTest.get(ImageRenderingEngine.PARAM_RESIZE_TO_THUMBNAIL));
    resizeOptions.setAllowEnlargement((Boolean) parametersUnderTest.get(ImageRenderingEngine.PARAM_ALLOW_ENLARGEMENT));
    imageTransOpts.setResizeOptions(resizeOptions);
    PagedSourceOptions pagedSourceOptions = new PagedSourceOptions();
    pagedSourceOptions.setStartPageNumber((Integer) parametersUnderTest.get(PagedSourceOptionsSerializer.PARAM_SOURCE_START_PAGE));
    pagedSourceOptions.setEndPageNumber((Integer) parametersUnderTest.get(PagedSourceOptionsSerializer.PARAM_SOURCE_END_PAGE));
    imageTransOpts.addSourceOptions(pagedSourceOptions);
    TemporalSourceOptions temporalSourceOptions = new TemporalSourceOptions();
    temporalSourceOptions.setOffset((String) parametersUnderTest.get(TemporalSourceOptionsSerializer.PARAM_SOURCE_TIME_OFFSET));
    imageTransOpts.addSourceOptions(temporalSourceOptions);
    ThumbnailParentAssociationDetails assocDetails = new ThumbnailParentAssociationDetails(dummyNodeRef3, ContentModel.ASSOC_CONTAINS, QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "homerSimpson"));
    // Now request the creation of the the thumbnail.
    thumbnailService.createThumbnail(dummyNodeRef1, ContentModel.PROP_CONTENT, MimetypeMap.MIMETYPE_IMAGE_JPEG, imageTransOpts, "bartSimpson", assocDetails);
    ArgumentCaptor<Action> argument = ArgumentCaptor.forClass(Action.class);
    verify(mockActionService).executeAction(argument.capture(), any(NodeRef.class), anyBoolean(), anyBoolean());
    final Action action = argument.getValue();
    final RenditionDefinition renditionDefn = (RenditionDefinition) action;
    Map<String, Serializable> parameters = renditionDefn.getParameterValues();
    for (String s : parametersUnderTest.keySet()) {
        if (parameters.keySet().contains(s) == false || parameters.get(s) == null || parameters.get(s).toString().length() == 0) {
            fail("Missing parameter " + s);
        }
        assertEquals("Parameter " + s + " had wrong value.", parametersUnderTest.get(s), parameters.get(s));
    }
}
Also used : TemporalSourceOptions(org.alfresco.service.cmr.repository.TemporalSourceOptions) Serializable(java.io.Serializable) Action(org.alfresco.service.cmr.action.Action) HashMap(java.util.HashMap) ImageTransformationOptions(org.alfresco.repo.content.transform.magick.ImageTransformationOptions) PagedSourceOptions(org.alfresco.service.cmr.repository.PagedSourceOptions) NodeRef(org.alfresco.service.cmr.repository.NodeRef) ImageResizeOptions(org.alfresco.repo.content.transform.magick.ImageResizeOptions) ThumbnailParentAssociationDetails(org.alfresco.service.cmr.thumbnail.ThumbnailParentAssociationDetails) RenditionDefinition(org.alfresco.service.cmr.rendition.RenditionDefinition) Test(org.junit.Test)

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