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();
}
}
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();
}
}
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();
}
}
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;
}
});
}
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;
}
Aggregations