Search in sources :

Example 41 with RenditionDefinition

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

the class StandardRenditionLocationResolverTest method testChildAssociationFinder.

@Test
public void testChildAssociationFinder() {
    QName renditionKind = QName.createQName(NamespaceService.APP_MODEL_1_0_URI, "test");
    NodeRef sourceNode = makeNode(companyHome, ContentModel.TYPE_CONTENT);
    NodeRef tempRenditionNode = makeNode(sourceNode, ContentModel.TYPE_CONTENT);
    RenditionDefinition renditionDef = renditionService.createRenditionDefinition(renditionKind, "brians_test_engine");
    // Test default behaviour, no destination path or NodeRef specified.
    RenditionLocation location = locationResolver.getRenditionLocation(sourceNode, renditionDef, tempRenditionNode);
    assertEquals(sourceNode, location.getParentRef());
    assertNull(location.getChildName());
    assertNull(location.getChildRef());
    // Test fully specified path.
    NodeRef targetFolder = makeNode(companyHome, ContentModel.TYPE_FOLDER);
    String companyHomeName = (String) nodeService.getProperty(companyHome, ContentModel.PROP_NAME);
    String targetFolderName = (String) nodeService.getProperty(targetFolder, ContentModel.PROP_NAME);
    String template = "/" + companyHomeName + "/" + targetFolderName + "/brian.xml";
    renditionDef.setParameterValue(RenditionService.PARAM_DESTINATION_PATH_TEMPLATE, template);
    location = locationResolver.getRenditionLocation(sourceNode, renditionDef, tempRenditionNode);
    assertEquals(targetFolder, location.getParentRef());
    assertEquals("brian.xml", location.getChildName());
    assertNull(location.getChildRef());
    // Test path with name substitution.
    template = targetFolderName + "/test-${sourceContentType}.xml";
    renditionDef.setParameterValue(RenditionService.PARAM_DESTINATION_PATH_TEMPLATE, template);
    location = locationResolver.getRenditionLocation(sourceNode, renditionDef, tempRenditionNode);
    assertEquals(targetFolder, location.getParentRef());
    assertEquals("test-" + ContentModel.PROP_CONTENT.getLocalName() + ".xml", location.getChildName());
    assertNull(location.getChildRef());
    // Test that when the template path specifies an existing node then that
    // node is set as the 'childRef' property on the RenditionLocation.
    NodeRef destinationNode = makeNode(targetFolder, ContentModel.TYPE_CONTENT);
    String destinationName = (String) nodeService.getProperty(destinationNode, ContentModel.PROP_NAME);
    template = targetFolderName + "/" + destinationName;
    renditionDef.setParameterValue(RenditionService.PARAM_DESTINATION_PATH_TEMPLATE, template);
    location = locationResolver.getRenditionLocation(sourceNode, renditionDef, tempRenditionNode);
    assertEquals(targetFolder, location.getParentRef());
    assertEquals(destinationName, location.getChildName());
    assertEquals(destinationNode, location.getChildRef());
    // Test that the 'destination node' param takes precedence over the 'template path' param.
    template = "/" + targetFolderName + "/brian.xml";
    renditionDef.setParameterValue(RenditionService.PARAM_DESTINATION_PATH_TEMPLATE, template);
    renditionDef.setParameterValue(RenditionService.PARAM_DESTINATION_NODE, destinationNode);
    location = locationResolver.getRenditionLocation(sourceNode, renditionDef, tempRenditionNode);
    assertEquals(targetFolder, location.getParentRef());
    assertEquals(destinationName, location.getChildName());
    assertEquals(destinationNode, location.getChildRef());
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) QName(org.alfresco.service.namespace.QName) RenditionDefinition(org.alfresco.service.cmr.rendition.RenditionDefinition) Test(org.junit.Test) BaseAlfrescoSpringTest(org.alfresco.util.BaseAlfrescoSpringTest)

Example 42 with RenditionDefinition

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

the class StandardRenditionLocationResolverTest method testCreatesFoldersForTemplatedLocation.

@Test
public void testCreatesFoldersForTemplatedLocation() throws Exception {
    QName fooName = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "testFooFolder");
    QName barName = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "testBarFolder");
    String fooPath = "/testFooFolder";
    String barPath = fooPath + "/testBarFolder";
    List<ChildAssociationRef> childAssocs = nodeService.getChildAssocs(companyHome, ContentModel.ASSOC_CONTAINS, fooName);
    assertTrue("Folder " + fooPath + " should not exist!", childAssocs.isEmpty());
    QName renditionKind = QName.createQName(NamespaceService.APP_MODEL_1_0_URI, "test");
    NodeRef sourceFolder = makeNode(companyHome, ContentModel.TYPE_FOLDER);
    NodeRef sourceNode = makeNode(sourceFolder, ContentModel.TYPE_CONTENT);
    NodeRef tempRenditionNode = makeNode(companyHome, ContentModel.TYPE_CONTENT);
    RenditionDefinition renditionDef = renditionService.createRenditionDefinition(renditionKind, "nicks_test_engine");
    String pathTemplate = barPath + "${cwd}nick.xml";
    renditionDef.setParameterValue(RenditionService.PARAM_DESTINATION_PATH_TEMPLATE, pathTemplate);
    RenditionLocation location = locationResolver.getRenditionLocation(sourceNode, renditionDef, tempRenditionNode);
    NodeRef fooNode = checkFolder(fooName, companyHome, "Foo");
    NodeRef barNode = checkFolder(barName, fooNode, "Bar");
    NodeRef finalFolderNode = checkFolder(nodeService.getPrimaryParent(sourceFolder).getQName(), barNode, "Final Folder");
    assertEquals("Final folder is not the rendition parent!", finalFolderNode, location.getParentRef());
    assertEquals("nick.xml", location.getChildName());
}
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) Test(org.junit.Test) BaseAlfrescoSpringTest(org.alfresco.util.BaseAlfrescoSpringTest)

Example 43 with RenditionDefinition

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

the class HTMLRenderingEngineTest method before.

@Before
public void before() throws Exception {
    super.before();
    this.nodeService = (NodeService) this.applicationContext.getBean("NodeService");
    this.contentService = (ContentService) this.applicationContext.getBean("ContentService");
    this.renditionService = (RenditionService) this.applicationContext.getBean("RenditionService");
    this.repositoryHelper = (Repository) this.applicationContext.getBean("repositoryHelper");
    this.dictionaryService = (DictionaryService) this.applicationContext.getBean("dictionaryService");
    this.companyHome = repositoryHelper.getCompanyHome();
    createTargetFolder();
    // Setup the basic rendition definition
    QName renditionName = QName.createQName("Test");
    RenditionDefinition rd = renditionService.loadRenditionDefinition(renditionName);
    if (rd != null) {
        RenditionDefinitionPersisterImpl rdp = new RenditionDefinitionPersisterImpl();
        rdp.setNodeService(nodeService);
        rdp.deleteRenditionDefinition(rd);
    }
    def = renditionService.createRenditionDefinition(renditionName, HTMLRenderingEngine.NAME);
}
Also used : QName(org.alfresco.service.namespace.QName) RenditionDefinitionPersisterImpl(org.alfresco.repo.rendition.RenditionDefinitionPersisterImpl) RenditionDefinition(org.alfresco.service.cmr.rendition.RenditionDefinition) Before(org.junit.Before)

Example 44 with RenditionDefinition

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

the class XSLTRenderingEngineTest method testParseXMLDocument.

@Test
public void testParseXMLDocument() throws Exception {
    try {
        FileInfo file = createXmlFile(companyHome);
        createXmlFile(companyHome, "TestXML.xml", sampleXML);
        FileInfo xslFile = createXmlFile(companyHome, callParseXmlDocument);
        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 45 with RenditionDefinition

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

the class XSLTRenderingEngineTest method testImportXMLDocument.

@Test
public void testImportXMLDocument() throws Exception {
    try {
        FileInfo file = createXmlFile(companyHome);
        createXmlFile(companyHome, "TestTableXML.xml", testTableXml);
        FileInfo testImportTable = createXmlFile(companyHome, "TestImportTableXML.xml", testImportTableXml);
        RenditionDefinition def = renditionService.createRenditionDefinition(QName.createQName("Test"), XSLTRenderingEngine.NAME);
        def.setParameterValue(XSLTRenderingEngine.PARAM_TEMPLATE_NODE, testImportTable.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);
        Diff myDiff = new Diff("<html>\n<body>\n<h2>My CD Collection</h2>\n<table border=\"1\">\n<tr bgcolor=\"#9acd32\">\n<th>Title</th><th>Artist</th>\n</tr>\n<tr>\n<td></td><td></td>\n</tr>\n</table>\n</body>\n</html>\n", output);
        assertTrue("Pieces of XML are similar " + myDiff, myDiff.similar());
    } catch (Exception ex) {
        log.error("Error!", ex);
        fail();
    }
}
Also used : FileInfo(org.alfresco.service.cmr.model.FileInfo) Diff(org.custommonkey.xmlunit.Diff) 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)

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