use of org.alfresco.service.cmr.rendition.RenditionDefinition in project alfresco-repository by Alfresco.
the class CompositeRenderingEngine method executeCompositeRendition.
private ChildAssociationRef executeCompositeRendition(CompositeRenditionDefinition definition, NodeRef sourceNode) {
NodeRef source = sourceNode;
ChildAssociationRef result = null;
QName assocType = definition.getRenditionAssociationType();
NodeRef parent = definition.getRenditionParent();
for (RenditionDefinition subDefinition : definition.getActions()) {
ChildAssociationRef nextResult = executeSubDefinition(source, subDefinition, parent, assocType);
if (result != null) {
// Clean up temporary renditions.
nodeService.removeChild(parent, result.getChildRef());
if (logger.isDebugEnabled()) {
logger.debug("removeChild parentRef:" + parent + ", childRef;" + result.getChildRef());
}
}
result = nextResult;
source = nextResult.getChildRef();
}
return result;
}
use of org.alfresco.service.cmr.rendition.RenditionDefinition in project alfresco-repository by Alfresco.
the class RenditionServicePermissionsTest method testRenditionAccessPermissions.
/**
* This test method uses the RenditionService to render a test document and place the
* rendition under a folder for which the user does not have write permissions.
* This should be allowed as all renditions are performed as system.
*/
@Test
public void testRenditionAccessPermissions() throws Exception {
final String normalUser = TEST_USER1.getUsername();
// As admin, create a user who has read-only 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.CONSUMER, 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.
RenditionDefinition action = makeRescaleImageAction();
action.setParameterValue(RenditionService.PARAM_DESTINATION_PATH_TEMPLATE, path);
// 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();
testNodes.addNodeRef(renditionNode);
assertEquals("The parent node was not correct", nodeWithImageContent, renditionAssoc.getParentRef());
logger.debug("rendition's primary parent: " + nodeService.getPrimaryParent(renditionNode));
assertEquals("The parent node was not correct", testFolder, nodeService.getPrimaryParent(renditionNode).getParentRef());
// Now the source content node should have the rn:renditioned aspect
assertTrue("Source node is missing renditioned aspect.", nodeService.hasAspect(nodeWithImageContent, RenditionModel.ASPECT_RENDITIONED));
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 RenditionServiceIntegrationTest method testRenderFreeMarkerTemplateOneTransaction.
@Test
public void testRenderFreeMarkerTemplateOneTransaction() throws Exception {
final QName renditionName = QName.createQName(NamespaceService.RENDITION_MODEL_1_0_URI, FreemarkerRenderingEngine.NAME);
this.renditionNode = transactionHelper.doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<NodeRef>() {
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);
String output = readTextContent(renditionAssoc.getChildRef());
assertNotNull("The rendition content was null.", output);
// check the output contains root node Id as expected.
assertTrue(output.contains(nodeWithDocContent.getId()));
return null;
}
});
}
use of org.alfresco.service.cmr.rendition.RenditionDefinition in project alfresco-repository by Alfresco.
the class RenditionServiceIntegrationTest method testBuiltinRenditionDefinitions.
/**
* This test method ensures that all the 'built-in' renditionDefinitions are
* available after startup and that their configuration is correct.
*
* @throws Exception
*/
@Test
public void testBuiltinRenditionDefinitions() throws Exception {
final RenditionDefinition mediumRenditionDef = loadAndValidateRenditionDefinition("medium");
final RenditionDefinition doclibRenditionDef = loadAndValidateRenditionDefinition("doclib");
final RenditionDefinition imgpreviewRenditionDef = loadAndValidateRenditionDefinition("imgpreview");
final RenditionDefinition webpreviewRenditionDef = loadAndValidateRenditionDefinition("webpreview");
final RenditionDefinition avatarRenditionDef = loadAndValidateRenditionDefinition("avatar");
assertEquals(MimetypeMap.MIMETYPE_IMAGE_JPEG, mediumRenditionDef.getParameterValue(AbstractRenderingEngine.PARAM_MIME_TYPE));
assertEquals(MimetypeMap.MIMETYPE_IMAGE_PNG, doclibRenditionDef.getParameterValue(AbstractRenderingEngine.PARAM_MIME_TYPE));
assertEquals(MimetypeMap.MIMETYPE_IMAGE_JPEG, imgpreviewRenditionDef.getParameterValue(AbstractRenderingEngine.PARAM_MIME_TYPE));
assertEquals(MimetypeMap.MIMETYPE_FLASH, webpreviewRenditionDef.getParameterValue(AbstractRenderingEngine.PARAM_MIME_TYPE));
assertEquals(MimetypeMap.MIMETYPE_IMAGE_PNG, avatarRenditionDef.getParameterValue(AbstractRenderingEngine.PARAM_MIME_TYPE));
}
use of org.alfresco.service.cmr.rendition.RenditionDefinition in project alfresco-repository by Alfresco.
the class RenditionServiceIntegrationTest method testSaveAndLoadCompositeRenditionDefinition.
@Test
public void testSaveAndLoadCompositeRenditionDefinition() throws Exception {
final QName renditionName = QName.createQName(NamespaceService.RENDITION_MODEL_1_0_URI, "composite");
final CompositeRenditionDefinition compositeDefinition = makeCompositeReformatAndResizeDefinition(renditionName, 20, 30);
final List<RenditionDefinition> savedRenditionDefinitions = new ArrayList<RenditionDefinition>();
try {
// First save composite rendition definition.
transactionHelper.doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<Void>() {
public Void execute() throws Throwable {
renditionService.saveRenditionDefinition(compositeDefinition);
return null;
}
});
// Then load the definition back up and check it matches the
// original.
transactionHelper.doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<Void>() {
public Void execute() throws Throwable {
RenditionDefinition result = renditionService.loadRenditionDefinition(renditionName);
// Check basic rendition definition properties.
assertEquals(renditionName, result.getRenditionName());
assertEquals(compositeDefinition.getActionDefinitionName(), result.getActionDefinitionName());
assertEquals(compositeDefinition.getCompensatingAction(), result.getCompensatingAction());
assertEquals(compositeDefinition.getDescription(), result.getDescription());
assertEquals(compositeDefinition.getExecuteAsychronously(), result.getExecuteAsychronously());
assertEquals(compositeDefinition.getModifiedDate(), result.getModifiedDate());
assertEquals(compositeDefinition.getModifier(), result.getModifier());
assertEquals(compositeDefinition.getTitle(), result.getTitle());
// Check sub-actions.
if (result instanceof CompositeRenditionDefinition) {
CompositeRenditionDefinition compositeResult = (CompositeRenditionDefinition) result;
savedRenditionDefinitions.add(compositeResult);
List<RenditionDefinition> subDefinitions = compositeResult.getActions();
assertEquals(2, subDefinitions.size());
// Check the first sub-definition is correct.
RenditionDefinition firstDef = subDefinitions.get(0);
assertEquals(ReformatRenderingEngine.NAME, firstDef.getActionDefinitionName());
// Check the second sub-definition is correct.
RenditionDefinition secondDef = subDefinitions.get(1);
assertEquals(ImageRenderingEngine.NAME, secondDef.getActionDefinitionName());
} else
fail("The retrieved rendition should be a CompositeRenditionDefinition.");
return null;
}
});
} finally {
cleanUpPersistedActions(savedRenditionDefinitions);
}
}
Aggregations