use of org.alfresco.service.cmr.rendition.RenditionDefinition in project alfresco-repository by Alfresco.
the class RenditionServiceIntegrationTest method testALF3733.
@Test
public void testALF3733() throws Exception {
// ALF-3733 was caused by ${cwd} evaluating to the empty string and a path "//sourceNodeName"
// being passed to the FileFolderService for creation. This then splits the string using '/' as
// a delimiter which leads to the attempted creation of nodes with the empty string as a name,
// which is illegal.
QName renditionDefName = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "myDummyRendition");
String renderingEngineName = "imageRenderingEngine";
RenditionDefinition renditionDef = renditionService.createRenditionDefinition(renditionDefName, renderingEngineName);
Map<String, Serializable> params = new HashMap<String, Serializable>();
params.put(ImageRenderingEngine.PARAM_RESIZE_WIDTH, 99);
params.put(ImageRenderingEngine.PARAM_RESIZE_HEIGHT, 99);
params.put(RenditionService.PARAM_DESTINATION_PATH_TEMPLATE, "${cwd}/resized/${name}_Thumb.${extension}");
renditionDef.addParameterValues(params);
ChildAssociationRef rendition = renditionService.render(this.nodeWithImageContent, renditionDef);
assertNotNull("rendition was null.", rendition);
assertTrue(nodeService.hasAspect(rendition.getChildRef(), RenditionModel.ASPECT_VISIBLE_RENDITION));
// The rendition should have 2 parents.
List<ChildAssociationRef> allParents = nodeService.getParentAssocs(rendition.getChildRef());
assertEquals(2, allParents.size());
// The rendition should be created under a new folder called 'resized'
NodeRef primaryParent = nodeService.getPrimaryParent(rendition.getChildRef()).getParentRef();
assertEquals("resized", nodeService.getProperty(primaryParent, ContentModel.PROP_NAME));
assertEquals(ContentModel.TYPE_FOLDER, nodeService.getType(primaryParent));
// The rendition should have the source node as a non-primary parent.
NodeRef nonPrimaryParent = null;
for (ChildAssociationRef chAss : allParents) {
if (!chAss.getParentRef().equals(primaryParent)) {
nonPrimaryParent = chAss.getParentRef();
}
}
assertNotNull("Non-primary parent was not found.", nonPrimaryParent);
assertEquals(nodeWithImageContent, nonPrimaryParent);
}
use of org.alfresco.service.cmr.rendition.RenditionDefinition in project alfresco-repository by Alfresco.
the class RenditionServiceIntegrationTest method testRenderDocumentInAnotherFormatInSitu.
/**
* This test method uses the RenditionService to render a test document (of
* type PDF) into a different format (of type plain_text) and place the
* rendition under the source node.
*/
@Test
public void testRenderDocumentInAnotherFormatInSitu() throws Exception {
this.renditionNode = transactionHelper.doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<NodeRef>() {
public NodeRef execute() throws Throwable {
// Initially the node that provides the content
// should not have the rn:renditioned aspect on it.
assertFalse("Source node has unexpected renditioned aspect.", nodeService.hasAspect(nodeWithDocContent, RenditionModel.ASPECT_RENDITIONED));
// and no renditions
assertTrue("Renditions should have been empty", renditionService.getRenditions(nodeWithDocContent).isEmpty());
assertNull("Renditions should have been null", renditionService.getRenditionByName(nodeWithDocContent, REFORMAT_RENDER_DEFN_NAME));
validateRenderingActionDefinition(ReformatRenderingEngine.NAME);
RenditionDefinition action = makeReformatAction(null, MimetypeMap.MIMETYPE_TEXT_PLAIN);
// Render the content and put the result underneath
// the content node
ChildAssociationRef renditionAssoc = renditionService.render(nodeWithDocContent, action);
NodeRef rendition = renditionAssoc.getChildRef();
assertEquals("The parent node was not correct", nodeWithDocContent, renditionAssoc.getParentRef());
validateRenditionAssociation(renditionAssoc, REFORMAT_RENDER_DEFN_NAME);
// The rendition node should have no other
// parent-associations - in this case
assertEquals("Wrong value for rendition node parent count.", 1, nodeService.getParentAssocs(rendition).size());
// Now the source content node should have the
// renditioned aspect
assertTrue("Source node is missing renditioned aspect.", nodeService.hasAspect(nodeWithDocContent, RenditionModel.ASPECT_RENDITIONED));
// and one rendition
assertEquals("Renditions size wrong", 1, renditionService.getRenditions(nodeWithDocContent).size());
assertNotNull("Renditions should not have been null", renditionService.getRenditionByName(nodeWithDocContent, REFORMAT_RENDER_DEFN_NAME));
return rendition;
}
});
// Now in a separate transaction, we'll check that the reformatted
// content is actually there.
assertNotNull("The rendition node was null.", renditionNode);
transactionHelper.doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<Void>() {
public Void execute() throws Throwable {
String contentAsString = readTextContent(renditionNode);
assertTrue("Wrong content in rendition", contentAsString.contains(QUICK_CONTENT));
return null;
}
});
}
use of org.alfresco.service.cmr.rendition.RenditionDefinition in project alfresco-repository by Alfresco.
the class RenditionServiceIntegrationTest method testRenditionPlacements.
/**
* Using a dummy rendition engine, perform a number of
* renditions, both single and composite, to check that
* the renditions always end up as they should do.
*/
@Test
public void testRenditionPlacements() throws Exception {
QName plainQName = QName.createQName("Plain");
RenditionDefinition rdPlain = renditionService.createRenditionDefinition(plainQName, DummyHelloWorldRenditionEngine.ENGINE_NAME);
QName compositeQName = QName.createQName("Composite");
CompositeRenditionDefinition rdComposite = renditionService.createCompositeRenditionDefinition(compositeQName);
rdComposite.addAction(renditionService.createRenditionDefinition(QName.createQName("CompositePart1"), DummyHelloWorldRenditionEngine.ENGINE_NAME));
rdComposite.addAction(renditionService.createRenditionDefinition(QName.createQName("CompositePart2"), DummyHelloWorldRenditionEngine.ENGINE_NAME));
// ============================================== //
// Anonymous Rendition, no existing one there //
// ============================================== //
assertNotNull(nodeWithDocContent);
assertEquals(0, renditionService.getRenditions(nodeWithDocContent).size());
assertEquals(0, nodeService.getChildAssocs(nodeWithDocContent).size());
// Do a plain rendition, and check we acquired the one node
renditionService.render(nodeWithDocContent, rdPlain);
ChildAssociationRef renditionAssoc = renditionService.getRenditionByName(nodeWithDocContent, plainQName);
assertNotNull(renditionAssoc);
assertEquals(1, nodeService.getChildAssocs(nodeWithDocContent).size());
assertEquals(plainQName, nodeService.getChildAssocs(nodeWithDocContent).get(0).getQName());
// Tidy
nodeService.deleteNode(renditionService.getRenditions(nodeWithDocContent).get(0).getChildRef());
assertNotNull(nodeWithDocContent);
assertEquals(0, renditionService.getRenditions(nodeWithDocContent).size());
assertEquals(0, nodeService.getChildAssocs(nodeWithDocContent).size());
// Now do a composite rendition
// Should once again have one node, despite there having been intermediate
// nodes created during the composite stage
renditionService.render(nodeWithDocContent, rdComposite);
assertEquals(1, renditionService.getRenditions(nodeWithDocContent).size());
assertEquals(1, nodeService.getChildAssocs(nodeWithDocContent).size());
renditionAssoc = renditionService.getRenditionByName(nodeWithDocContent, compositeQName);
assertNotNull(renditionAssoc);
assertEquals(compositeQName, nodeService.getChildAssocs(nodeWithDocContent).get(0).getQName());
// Tidy
nodeService.deleteNode(renditionService.getRenditions(nodeWithDocContent).get(0).getChildRef());
// ================================================ //
// Anonymous Rendition, existing one, same type //
// ================================================ //
// Create one of the right type for a plain rendition
renditionService.render(nodeWithDocContent, rdPlain);
assertEquals(1, renditionService.getRenditions(nodeWithDocContent).size());
assertEquals(1, nodeService.getChildAssocs(nodeWithDocContent).size());
renditionAssoc = renditionService.getRenditionByName(nodeWithDocContent, plainQName);
assertNotNull(renditionAssoc);
// Run again, shouldn't change, should re-use the node
renditionNode = renditionAssoc.getChildRef();
renditionService.render(nodeWithDocContent, rdPlain);
assertEquals(1, renditionService.getRenditions(nodeWithDocContent).size());
assertEquals(1, nodeService.getChildAssocs(nodeWithDocContent).size());
renditionAssoc = renditionService.getRenditionByName(nodeWithDocContent, plainQName);
assertNotNull(renditionAssoc);
assertEquals(renditionNode, renditionAssoc.getChildRef());
assertEquals(plainQName, nodeService.getChildAssocs(nodeWithDocContent).get(0).getQName());
// Tidy, and re-create for composite
nodeService.deleteNode(renditionService.getRenditions(nodeWithDocContent).get(0).getChildRef());
renditionService.render(nodeWithDocContent, rdComposite);
assertEquals(1, renditionService.getRenditions(nodeWithDocContent).size());
assertEquals(1, nodeService.getChildAssocs(nodeWithDocContent).size());
renditionAssoc = renditionService.getRenditionByName(nodeWithDocContent, compositeQName);
assertNotNull(renditionAssoc);
// Run again, shouldn't change, should re-use the node
renditionNode = renditionAssoc.getChildRef();
renditionService.render(nodeWithDocContent, rdComposite);
assertEquals(1, renditionService.getRenditions(nodeWithDocContent).size());
assertEquals(1, nodeService.getChildAssocs(nodeWithDocContent).size());
renditionAssoc = renditionService.getRenditionByName(nodeWithDocContent, compositeQName);
assertNotNull(renditionAssoc);
assertEquals(renditionNode, renditionAssoc.getChildRef());
assertEquals(compositeQName, nodeService.getChildAssocs(nodeWithDocContent).get(0).getQName());
// Tidy
nodeService.deleteNode(renditionService.getRenditions(nodeWithDocContent).get(0).getChildRef());
// ================================================= //
// Anonymous Rendition, existing one, wrong type //
// Note - this situation is not possible! //
// ================================================= //
// ================================================= //
// Switch to being path based //
// ================================================= //
String fileName = "HelloWorld.txt";
String path = "/" + (String) nodeService.getProperty(repositoryHelper.getCompanyHome(), ContentModel.PROP_NAME) + "/" + (String) nodeService.getProperty(testTargetFolder, ContentModel.PROP_NAME) + "/" + fileName;
rdPlain.setParameterValue(RenditionService.PARAM_DESTINATION_PATH_TEMPLATE, path);
rdComposite.setParameterValue(RenditionService.PARAM_DESTINATION_PATH_TEMPLATE, path);
QName expectedName = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, fileName);
// ================================================= //
// Path based rendition, no existing one there //
// ================================================= //
assertNotNull(nodeWithDocContent);
assertEquals(0, renditionService.getRenditions(nodeWithDocContent).size());
assertEquals(0, nodeService.getChildAssocs(nodeWithDocContent).size());
List<ChildAssociationRef> children = nodeService.getChildAssocs(testTargetFolder);
assertEquals(0, children.size());
// Do a plain rendition, and check we acquired the one node
renditionService.render(nodeWithDocContent, rdPlain);
assertEquals(1, renditionService.getRenditions(nodeWithDocContent).size());
assertEquals(1, nodeService.getChildAssocs(nodeWithDocContent).size());
renditionAssoc = renditionService.getRenditionByName(nodeWithDocContent, plainQName);
assertNotNull(renditionAssoc);
assertFalse(renditionAssoc.isPrimary());
children = nodeService.getChildAssocs(testTargetFolder);
assertEquals(1, children.size());
ChildAssociationRef childAssoc = children.get(0);
assertEquals(expectedName, childAssoc.getQName());
assertTrue(childAssoc.isPrimary());
nodeService.deleteNode(renditionService.getRenditions(nodeWithDocContent).get(0).getChildRef());
assertNotNull(nodeWithDocContent);
assertEquals(0, renditionService.getRenditions(nodeWithDocContent).size());
// FIXME There is a bug in the NodeService whereby associations to children in the archive store
// i.e. deleted children, are included in the results to the getChildAssocs call.
// Therefore, pending a fix to that, we need to suppress this check and similar checks below.
// assertEquals(0, nodeService.getChildAssocs(nodeWithDocContent).size());
assertEquals(0, nodeService.getChildAssocs(testTargetFolder).size());
// Now do a composite rendition
// Should once again have one node, despite there having been intermediate
// nodes created during the composite stage
renditionService.render(nodeWithDocContent, rdComposite);
assertEquals(1, renditionService.getRenditions(nodeWithDocContent).size());
// assertEquals(1, nodeService.getChildAssocs(nodeWithDocContent).size());
renditionAssoc = renditionService.getRenditionByName(nodeWithDocContent, compositeQName);
assertNotNull(renditionAssoc);
assertFalse(renditionAssoc.isPrimary());
children = nodeService.getChildAssocs(testTargetFolder);
assertEquals(1, children.size());
childAssoc = children.get(0);
assertEquals(expectedName, childAssoc.getQName());
assertTrue(childAssoc.isPrimary());
// Tidy
nodeService.deleteNode(renditionService.getRenditions(nodeWithDocContent).get(0).getChildRef());
// ================================================= //
// Path Based Rendition, existing one, same type //
// ================================================= //
// Create one of the right type for a plain rendition
renditionService.render(nodeWithDocContent, rdPlain);
assertEquals(1, renditionService.getRenditions(nodeWithDocContent).size());
// assertEquals(1, nodeService.getChildAssocs(nodeWithDocContent).size());
assertEquals(1, children.size());
renditionAssoc = renditionService.getRenditionByName(nodeWithDocContent, plainQName);
assertNotNull(renditionAssoc);
// Run again, shouldn't change, should re-use the node
renditionNode = renditionAssoc.getChildRef();
renditionService.render(nodeWithDocContent, rdPlain);
assertEquals(1, renditionService.getRenditions(nodeWithDocContent).size());
// assertEquals(1, nodeService.getChildAssocs(nodeWithDocContent).size());
renditionAssoc = renditionService.getRenditionByName(nodeWithDocContent, plainQName);
assertNotNull(renditionAssoc);
assertFalse(renditionAssoc.isPrimary());
assertEquals(renditionNode, renditionAssoc.getChildRef());
children = nodeService.getChildAssocs(testTargetFolder);
assertEquals(1, children.size());
childAssoc = children.get(0);
assertEquals(expectedName, childAssoc.getQName());
assertTrue(childAssoc.isPrimary());
assertEquals(renditionNode, childAssoc.getChildRef());
// Tidy, and re-create for composite
nodeService.deleteNode(renditionService.getRenditions(nodeWithDocContent).get(0).getChildRef());
renditionService.render(nodeWithDocContent, rdComposite);
assertEquals(1, renditionService.getRenditions(nodeWithDocContent).size());
// assertEquals(1, nodeService.getChildAssocs(nodeWithDocContent).size());
assertEquals(1, children.size());
renditionAssoc = renditionService.getRenditionByName(nodeWithDocContent, compositeQName);
assertNotNull(renditionAssoc);
// Run again, shouldn't change, should re-use the node
renditionNode = renditionAssoc.getChildRef();
renditionService.render(nodeWithDocContent, rdComposite);
assertEquals(1, renditionService.getRenditions(nodeWithDocContent).size());
// assertEquals(1, nodeService.getChildAssocs(nodeWithDocContent).size());
renditionAssoc = renditionService.getRenditionByName(nodeWithDocContent, compositeQName);
assertNotNull(renditionAssoc);
assertFalse(renditionAssoc.isPrimary());
assertEquals(renditionNode, renditionAssoc.getChildRef());
children = nodeService.getChildAssocs(testTargetFolder);
assertEquals(1, children.size());
childAssoc = children.get(0);
assertEquals(expectedName, childAssoc.getQName());
assertTrue(childAssoc.isPrimary());
assertEquals(renditionNode, childAssoc.getChildRef());
// ================================================= //
// Path Based Rendition, existing one, wrong type //
// ================================================= //
// We currently have a composite one
assertEquals(expectedName, children.get(0).getQName());
// Run the plain rendition, the composite one should be replaced
// with the new one
renditionNode = children.get(0).getChildRef();
// linked to its source node by a rn:rendition association of the same name as the new rendition.
try {
renditionService.render(nodeWithDocContent, rdPlain);
fail("Expected RenditionServiceException not thrown");
} catch (RenditionServiceException expected) {
// Do Nothing.
}
}
use of org.alfresco.service.cmr.rendition.RenditionDefinition in project alfresco-repository by Alfresco.
the class RenditionServiceIntegrationTest method makeCompositeReformatAndResizeDefinition.
private CompositeRenditionDefinition makeCompositeReformatAndResizeDefinition(final QName renditionName, final int newX, final int newY) {
CompositeRenditionDefinition compositeDefinition = renditionService.createCompositeRenditionDefinition(renditionName);
RenditionDefinition reformatDefinition = makeReformatAction(null, MimetypeMap.MIMETYPE_IMAGE_JPEG);
RenditionDefinition rescaleImageDefinition = makeRescaleImageAction();
rescaleImageDefinition.setParameterValue(ImageRenderingEngine.PARAM_RESIZE_WIDTH, newX);
rescaleImageDefinition.setParameterValue(ImageRenderingEngine.PARAM_RESIZE_HEIGHT, newY);
compositeDefinition.addAction(reformatDefinition);
compositeDefinition.addAction(rescaleImageDefinition);
return compositeDefinition;
}
use of org.alfresco.service.cmr.rendition.RenditionDefinition in project alfresco-repository by Alfresco.
the class RenditionServiceIntegrationTest method testLoadRenderingAction.
/**
* This test method saves one RenderingAction to the repository and loads it
* back up asserting that it is equivalent to the original. It then saves
* some further RenderingActions, loads them back with a RenderingEngine
* filter and asserts that the results are correct.
*
* @throws Exception
*/
@Test
public void testLoadRenderingAction() throws Exception {
final RenditionDefinition reformatAction = makeReformatAction(null, MimetypeMap.MIMETYPE_TEXT_PLAIN);
final RenditionDefinition rescaleAction = makeRescaleImageAction();
final List<RenditionDefinition> savedRenditionDefinitions = new ArrayList<RenditionDefinition>();
try {
// First save one action.
transactionHelper.doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<Void>() {
public Void execute() throws Throwable {
savedRenditionDefinitions.add(reformatAction);
renditionService.saveRenditionDefinition(reformatAction);
return null;
}
});
// Then load the action back up and check it matches the original.
transactionHelper.doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<Void>() {
public Void execute() throws Throwable {
QName renditionName = reformatAction.getRenditionName();
RenditionDefinition result = renditionService.loadRenditionDefinition(renditionName);
assertEquals(renditionName, result.getRenditionName());
assertEquals(reformatAction.getActionDefinitionName(), result.getActionDefinitionName());
assertEquals(reformatAction.getCompensatingAction(), result.getCompensatingAction());
assertEquals(reformatAction.getDescription(), result.getDescription());
assertEquals(reformatAction.getExecuteAsychronously(), result.getExecuteAsychronously());
assertEquals(reformatAction.getModifiedDate(), result.getModifiedDate());
assertEquals(reformatAction.getModifier(), result.getModifier());
assertEquals(reformatAction.getTitle(), result.getTitle());
return null;
}
});
// Now save the second action.
transactionHelper.doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<Void>() {
public Void execute() throws Throwable {
savedRenditionDefinitions.add(rescaleAction);
renditionService.saveRenditionDefinition(rescaleAction);
return null;
}
});
// Then load the actions back up and check they exist and are
// filtered correctly.
transactionHelper.doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<Void>() {
public Void execute() throws Throwable {
// Retrieve persisted Rendering Definitions by name.
RenditionDefinition firstLoadedAction = renditionService.loadRenditionDefinition(reformatAction.getRenditionName());
RenditionDefinition secondLoadedAction = renditionService.loadRenditionDefinition(rescaleAction.getRenditionName());
assertNotNull("The reformat action was null.", firstLoadedAction);
assertNotNull("The rescale action was null.", secondLoadedAction);
/*
* We'll not retest the action metadata here as that is
* tested in this method above. Just the names to ensure
* they are distinct.
*/
assertEquals(reformatAction.getRenditionName(), firstLoadedAction.getRenditionName());
assertEquals(rescaleAction.getRenditionName(), secondLoadedAction.getRenditionName());
return null;
}
});
} finally {
cleanUpPersistedActions(savedRenditionDefinitions);
}
}
Aggregations