Search in sources :

Example 16 with RenditionDefinition

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

the class XSLTRenderingEngineTest method testSimplestStringTemplate.

@Test
public void testSimplestStringTemplate() throws Exception {
    try {
        FileInfo file = createXmlFile(companyHome);
        FileInfo xslFile = createXmlFile(companyHome, verySimpleXSLT);
        RenditionDefinition def = renditionService.createRenditionDefinition(QName.createQName("Test"), XSLTRenderingEngine.NAME);
        def.setParameterValue(XSLTRenderingEngine.PARAM_TEMPLATE_NODE, xslFile.getNodeRef());
        ChildAssociationRef rendition = renditionService.render(file.getNodeRef(), def);
        assertNotNull(rendition);
        ContentReader reader = contentService.getReader(rendition.getChildRef(), ContentModel.PROP_CONTENT);
        assertNotNull(reader);
        String output = reader.getContentString();
        log.debug("XSLT Processor output: " + output);
        assertEquals("Avocado DipBagels, New York StyleBeef Frankfurter, Quarter PoundChicken Pot PieCole SlawEggsHazelnut SpreadPotato ChipsSoy Patties, GrilledTruffles, Dark Chocolate", output);
    } catch (Exception ex) {
        log.error("Error!", ex);
        fail();
    }
}
Also used : FileInfo(org.alfresco.service.cmr.model.FileInfo) ContentReader(org.alfresco.service.cmr.repository.ContentReader) RenditionDefinition(org.alfresco.service.cmr.rendition.RenditionDefinition) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) BaseAlfrescoSpringTest(org.alfresco.util.BaseAlfrescoSpringTest) Test(org.junit.Test)

Example 17 with RenditionDefinition

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

the class XSLTRenderingEngineTest method testParseXMLDocuments.

@Test
public void testParseXMLDocuments() throws Exception {
    try {
        FileInfo file = createXmlFile(companyHome);
        String path = "path/to/xml/files";
        List<String> pathElements = Arrays.asList(path.split("/"));
        FileInfo folder = FileFolderServiceImpl.makeFolders(fileFolderService, companyHome, pathElements, ContentModel.TYPE_FOLDER);
        createXmlFile(folder.getNodeRef());
        createXmlFile(folder.getNodeRef());
        createXmlFile(folder.getNodeRef());
        createXmlFile(folder.getNodeRef());
        createXmlFile(folder.getNodeRef());
        FileInfo xslFile = createXmlFile(companyHome, callParseXmlDocuments);
        RenditionDefinition def = renditionService.createRenditionDefinition(QName.createQName("Test"), XSLTRenderingEngine.NAME);
        def.setParameterValue(XSLTRenderingEngine.PARAM_TEMPLATE_NODE, xslFile.getNodeRef());
        ChildAssociationRef rendition = renditionService.render(file.getNodeRef(), def);
        assertNotNull(rendition);
        ContentReader reader = contentService.getReader(rendition.getChildRef(), ContentModel.PROP_CONTENT);
        assertNotNull(reader);
        String output = reader.getContentString();
        log.debug("XSLT Processor output: " + output);
        assertEquals("Avocado DipBagels, New York StyleBeef Frankfurter, Quarter PoundChicken Pot PieCole SlawEggsHazelnut SpreadPotato ChipsSoy Patties, GrilledTruffles, Dark Chocolate" + "Avocado DipBagels, New York StyleBeef Frankfurter, Quarter PoundChicken Pot PieCole SlawEggsHazelnut SpreadPotato ChipsSoy Patties, GrilledTruffles, Dark Chocolate" + "Avocado DipBagels, New York StyleBeef Frankfurter, Quarter PoundChicken Pot PieCole SlawEggsHazelnut SpreadPotato ChipsSoy Patties, GrilledTruffles, Dark Chocolate" + "Avocado DipBagels, New York StyleBeef Frankfurter, Quarter PoundChicken Pot PieCole SlawEggsHazelnut SpreadPotato ChipsSoy Patties, GrilledTruffles, Dark Chocolate" + "Avocado DipBagels, New York StyleBeef Frankfurter, Quarter PoundChicken Pot PieCole SlawEggsHazelnut SpreadPotato ChipsSoy Patties, GrilledTruffles, Dark Chocolate", output);
    } catch (Exception ex) {
        log.error("Error!", ex);
        fail();
    }
}
Also used : FileInfo(org.alfresco.service.cmr.model.FileInfo) ContentReader(org.alfresco.service.cmr.repository.ContentReader) RenditionDefinition(org.alfresco.service.cmr.rendition.RenditionDefinition) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) BaseAlfrescoSpringTest(org.alfresco.util.BaseAlfrescoSpringTest) Test(org.junit.Test)

Example 18 with RenditionDefinition

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

the class XSLTRenderingEngineTest method testSimplestTemplateWithTargetPath.

@Test
public void testSimplestTemplateWithTargetPath() throws Exception {
    // We need to run this test as Administrator. The ScriptAction has to run as a full user (instead of as System)
    // so that we can setup the Person object in the ScriptNode
    AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
    try {
        FileInfo file = createXmlFile(companyHome);
        FileInfo xslFile = createXmlFile(companyHome, verySimpleXSLT);
        RenditionDefinition def = renditionService.createRenditionDefinition(QName.createQName("Test"), XSLTRenderingEngine.NAME);
        def.setParameterValue(XSLTRenderingEngine.PARAM_TEMPLATE_NODE, xslFile.getNodeRef());
        def.setParameterValue(RenditionService.PARAM_DESTINATION_PATH_TEMPLATE, "output/path/for/rendition/output.txt");
        ChildAssociationRef rendition = renditionService.render(file.getNodeRef(), def);
        assertNotNull(rendition);
        assertEquals(2, nodeService.getParentAssocs(rendition.getChildRef()).size());
        ContentReader reader = contentService.getReader(rendition.getChildRef(), ContentModel.PROP_CONTENT);
        assertNotNull(reader);
        String output = reader.getContentString();
        log.debug("XSLT Processor output: " + output);
        assertEquals("Avocado DipBagels, New York StyleBeef Frankfurter, Quarter PoundChicken Pot PieCole SlawEggsHazelnut SpreadPotato ChipsSoy Patties, GrilledTruffles, Dark Chocolate", output);
    } catch (Exception ex) {
        log.error("Error!", ex);
        fail();
    } finally {
        AuthenticationUtil.clearCurrentSecurityContext();
    }
}
Also used : FileInfo(org.alfresco.service.cmr.model.FileInfo) ContentReader(org.alfresco.service.cmr.repository.ContentReader) RenditionDefinition(org.alfresco.service.cmr.rendition.RenditionDefinition) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) BaseAlfrescoSpringTest(org.alfresco.util.BaseAlfrescoSpringTest) Test(org.junit.Test)

Example 19 with RenditionDefinition

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

the class RenditionServicePermissionsTest method testRenditionUserPreserved.

/**
 * This test method uses the RenditionService to render a test document and
 * check that the content transformer has access to the original initiating username
 */
@Test
public void testRenditionUserPreserved() throws Exception {
    final String normalUser = TEST_USER1.getUsername();
    // As admin, create a user who has coordinator 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.COORDINATOR, 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.
            QName renditionName = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "PreserveUser" + System.currentTimeMillis());
            RenditionDefinition action = renditionService.createRenditionDefinition(renditionName, MockRenderingEngine.NAME);
            action.setParameterValue(RenditionService.PARAM_DESTINATION_PATH_TEMPLATE, path);
            action.setParameterValue(AbstractRenderingEngine.PARAM_MIME_TYPE, TEST_USER_MIME_TYPE);
            // 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();
            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) QName(org.alfresco.service.namespace.QName) RenditionDefinition(org.alfresco.service.cmr.rendition.RenditionDefinition) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) Test(org.junit.Test)

Example 20 with RenditionDefinition

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

the class RenditionServicePermissionsTest method makeRescaleImageAction.

/**
 * Creates a RenditionDefinition for the RescaleImageActionExecutor.
 *
 * @return A new RenderingAction.
 */
private RenditionDefinition makeRescaleImageAction() {
    RenditionDefinition result = renditionService.createRenditionDefinition(RESCALE_RENDER_DEFN_NAME, ImageRenderingEngine.NAME);
    result.setParameterValue(ImageRenderingEngine.PARAM_RESIZE_WIDTH, 42);
    return result;
}
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