use of org.alfresco.service.cmr.rendition.CompositeRenditionDefinition 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);
}
}
use of org.alfresco.service.cmr.rendition.CompositeRenditionDefinition 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.CompositeRenditionDefinition in project alfresco-repository by Alfresco.
the class CompositeRenderingEngine method executeRenditionImpl.
/*
* (non-Javadoc)
* @see org.alfresco.repo.rendition.executer.AbstractRenderingEngine#executeRenditionImpl(org.alfresco.service.cmr.action.Action, org.alfresco.service.cmr.repository.NodeRef)
*/
@Override
protected void executeRenditionImpl(Action action, NodeRef sourceNode) {
checkSourceNodeExists(sourceNode);
if (action instanceof CompositeRenditionDefinition) {
CompositeRenditionDefinition compositeDefinition = (CompositeRenditionDefinition) action;
ChildAssociationRef renditionAssoc = executeCompositeRendition(compositeDefinition, sourceNode);
// Setting result.
compositeDefinition.setParameterValue(PARAM_RESULT, renditionAssoc);
} else {
String msg = "This method requires that the RenditionDefinition be of type CompositeRenditionDefinition";
logger.warn(msg);
throw new RenditionServiceException(msg);
}
}
use of org.alfresco.service.cmr.rendition.CompositeRenditionDefinition 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.CompositeRenditionDefinition 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;
}
Aggregations