use of org.alfresco.service.cmr.rendition.RenditionDefinition in project alfresco-repository by Alfresco.
the class RenditionServiceIntegrationTest method makeReformatAction.
/**
* Creates a RenderingAction (RenditionDefinition) for the
* ReformatActionExecutor, setting the mimetype parameter value to plain
* text.
*
* @param renditionObjectType requested node type of the rendition object
* @param targetMimetype
* @return A new RenderingAction.
*/
private RenditionDefinition makeReformatAction(QName renditionObjectType, String targetMimetype) {
// Create the rendering action.
RenditionDefinition action = renditionService.createRenditionDefinition(REFORMAT_RENDER_DEFN_NAME, ReformatRenderingEngine.NAME);
action.setParameterValue(AbstractRenderingEngine.PARAM_MIME_TYPE, targetMimetype);
if (renditionObjectType != null) {
action.setParameterValue(RenditionService.PARAM_RENDITION_NODETYPE, renditionObjectType);
}
return action;
}
use of org.alfresco.service.cmr.rendition.RenditionDefinition in project alfresco-repository by Alfresco.
the class RenditionServiceIntegrationTest method testRenderValidContentThenUpdateToInvalidContent.
/**
* This test checks that for a node with an existing rendition, that if you update its content with content
* that cannot be renditioned (thumbnailed), that existing rendition nodes for failed re-renditions are removed.
* See ALF-6730.
*
* @since 3.4.2
*/
@Test
public void testRenderValidContentThenUpdateToInvalidContent() throws Exception {
transactionHelper.doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<Void>() {
public Void execute() throws Throwable {
// Need to use one of the standard, persisted rendition definitions, as non-persisted rendition definitions
// do not get automatcially updated.
RenditionDefinition doclib = loadAndValidateRenditionDefinition("doclib");
// We want the rendition to be asynchronous, but we don't care about called-back data.
RenderCallback dummyCallback = new RenderCallback() {
@Override
public void handleFailedRendition(Throwable t) {
}
@Override
public void handleSuccessfulRendition(ChildAssociationRef primaryParentOfNewRendition) {
}
};
renditionService.render(nodeWithDocContent, doclib, dummyCallback);
return null;
}
}, false, true);
// Now wait for the actionService thread to complete the rendering.
Thread.sleep(5000);
// The rendition should have succeeded.
transactionHelper.doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<Void>() {
public Void execute() throws Throwable {
List<ChildAssociationRef> renditions = renditionService.getRenditions(nodeWithDocContent);
assertNotNull("Renditions missing.", renditions);
assertEquals("Wrong rendition count", 1, renditions.size());
return null;
}
}, false, true);
// Now update the content to a corrupt PDF file that cannot be rendered.
transactionHelper.doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<Void>() {
public Void execute() throws Throwable {
ContentWriter writer = contentService.getWriter(nodeWithDocContent, ContentModel.PROP_CONTENT, true);
writer.setMimetype(MimetypeMap.MIMETYPE_PDF);
writer.setEncoding("UTF-8");
InputStream corruptIn = applicationContext.getResource("classpath:/quick/quickCorrupt.pdf").getInputStream();
writer.putContent(corruptIn);
corruptIn.close();
return null;
}
}, false, true);
// Now wait for the actionService thread to complete the rendition removal.
Thread.sleep(5000);
transactionHelper.doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<Void>() {
public Void execute() throws Throwable {
List<ChildAssociationRef> renditions = renditionService.getRenditions(nodeWithDocContent);
assertNotNull("Renditions missing.", renditions);
assertEquals("Wrong rendition count", 0, renditions.size());
return null;
}
}, false, true);
}
use of org.alfresco.service.cmr.rendition.RenditionDefinition in project alfresco-repository by Alfresco.
the class RenditionServiceIntegrationTest method renderPdfDocumentLongRunningTest.
protected void renderPdfDocumentLongRunningTest(AbstractNodeModifyingRunnable nodeModifyingRunnable, boolean joinNodeModifyingThread) throws Exception {
// Spawn a new thread that waits a bit then tries to modify the node
Thread nodeModifyingThread = new Thread(nodeModifyingRunnable);
nodeModifyingThread.start();
// Start the long running rendition
try {
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));
RenditionDefinition action = makeReformatAction(null, TEST_LONG_RUNNING_MIME_TYPE);
// Cancellation is only possible with tracking enabled
action.setTrackStatus(true);
// Render the content and put the result underneath the content node
ChildAssociationRef renditionAssoc = renditionService.render(nodeWithDocContent, action);
// Now the source content node should have the renditioned aspect
assertTrue("Source node is missing renditioned aspect.", nodeService.hasAspect(nodeWithDocContent, RenditionModel.ASPECT_RENDITIONED));
return renditionAssoc.getChildRef();
}
}, false, true);
} catch (RenditionCancelledException e) {
// expected cancellation exception
}
// Give a moment for roll back of rendition and commit of node modification to occur
Thread.sleep(3000);
if (joinNodeModifyingThread) {
nodeModifyingThread.join();
}
// be false if there was a failure
if (nodeModifyingRunnable.getModificationException() != null) {
throw new RuntimeException("Modification of node during long running rendition failed", nodeModifyingRunnable.getModificationException());
}
}
use of org.alfresco.service.cmr.rendition.RenditionDefinition in project alfresco-repository by Alfresco.
the class RenditionServiceIntegrationTest method loadAndValidateRenditionDefinition.
private RenditionDefinition loadAndValidateRenditionDefinition(String renditionLocalName) {
QName renditionQName = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, renditionLocalName);
RenditionDefinition renditionDefinition = renditionService.loadRenditionDefinition(renditionQName);
assertNotNull("'" + renditionLocalName + "' rendition definition was missing.", renditionDefinition);
assertEquals("'" + renditionLocalName + "' renditionDefinition had wrong renditionName", renditionQName, renditionDefinition.getRenditionName());
assertNotNull("'" + renditionLocalName + "' renditionDefinition had null " + RenditionDefinitionImpl.RENDITION_DEFINITION_NAME + " parameter", renditionDefinition.getParameterValue(RenditionDefinitionImpl.RENDITION_DEFINITION_NAME));
// All builtin renditions should be "runas" system
assertEquals(AuthenticationUtil.getSystemUserName(), renditionDefinition.getParameterValue(AbstractRenderingEngine.PARAM_RUN_AS));
return renditionDefinition;
}
use of org.alfresco.service.cmr.rendition.RenditionDefinition in project alfresco-repository by Alfresco.
the class RenditionServiceIntegrationTest method testRenderFreemarkerTemplatePath.
@Test
public void testRenderFreemarkerTemplatePath() throws Exception {
// TODO displayName paths.
final QName renditionName1 = QName.createQName(NamespaceService.RENDITION_MODEL_1_0_URI, FreemarkerRenderingEngine.NAME + "_UpdateOnAnyPropChange");
final QName renditionName2 = QName.createQName(NamespaceService.RENDITION_MODEL_1_0_URI, FreemarkerRenderingEngine.NAME + "_UpdateOnContentPropChange");
final Pair<NodeRef, NodeRef> renditions = transactionHelper.doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<Pair<NodeRef, NodeRef>>() {
public Pair<NodeRef, NodeRef> execute() throws Throwable {
ChildAssociationRef parentAssoc = nodeService.getPrimaryParent(nodeWithFreeMarkerContent);
QName assocName = parentAssoc.getQName();
String templatePath = "/app:company_home/" + assocName.toPrefixString(namespaceService);
// create test model 1 - rendition to update on any property change
RenditionDefinition definition1 = renditionService.createRenditionDefinition(renditionName1, FreemarkerRenderingEngine.NAME);
definition1.setParameterValue(FreemarkerRenderingEngine.PARAM_TEMPLATE_PATH, templatePath);
definition1.setParameterValue(AbstractRenderingEngine.PARAM_UPDATE_RENDITIONS_ON_ANY_PROPERTY_CHANGE, Boolean.TRUE);
// create test model 2 - rendition to update on content property change
RenditionDefinition definition2 = renditionService.createRenditionDefinition(renditionName2, FreemarkerRenderingEngine.NAME);
definition2.setParameterValue(FreemarkerRenderingEngine.PARAM_TEMPLATE_PATH, templatePath);
definition2.setParameterValue(AbstractRenderingEngine.PARAM_UPDATE_RENDITIONS_ON_ANY_PROPERTY_CHANGE, Boolean.FALSE);
// for automatic update.
if (null == renditionService.loadRenditionDefinition(renditionName1)) {
renditionService.saveRenditionDefinition(definition1);
}
if (null == renditionService.loadRenditionDefinition(renditionName2)) {
renditionService.saveRenditionDefinition(definition2);
}
ChildAssociationRef renditionAssoc1 = renditionService.render(nodeWithDocContent, definition1);
assertNotNull("The rendition association was null", renditionAssoc1);
ChildAssociationRef renditionAssoc2 = renditionService.render(nodeWithDocContent, definition2);
assertNotNull("The rendition association was null", renditionAssoc2);
Pair<NodeRef, NodeRef> result = new Pair<NodeRef, NodeRef>(renditionAssoc1.getChildRef(), renditionAssoc2.getChildRef());
return result;
}
});
final String titleInitialValue = "Original test title";
transactionHelper.doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<Void>() {
public Void execute() throws Throwable {
assertEquals("The source node should have title " + titleInitialValue, titleInitialValue, nodeService.getProperty(nodeWithDocContent, ContentModel.PROP_TITLE));
String output1 = readTextContent(renditions.getFirst());
assertNotNull("The rendition content was null.", output1);
assertRenditionContainsTitle(titleInitialValue, output1);
// check the output contains root node Id as expected.
assertTrue(output1.contains(nodeWithDocContent.getId()));
String output2 = readTextContent(renditions.getSecond());
assertNotNull("The rendition content was null.", output2);
assertRenditionContainsTitle(titleInitialValue, output2);
return null;
}
});
// Now change some properties on the source node and ensure that the renditions
// are updated appropriately
final String updatedTitle = "updatedTitle";
transactionHelper.doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<Void>() {
public Void execute() throws Throwable {
nodeService.setProperty(nodeWithDocContent, ContentModel.PROP_TITLE, updatedTitle);
return null;
}
});
RetryingTransactionCallback<Void> checkRenditionCallback = new RetryingTransactionCallback<Void>() {
public Void execute() throws Throwable {
String output1 = readTextContent(renditions.getFirst());
assertNotNull("The rendition content was null.", output1);
assertRenditionContainsTitle(updatedTitle, output1);
String output2 = readTextContent(renditions.getSecond());
assertNotNull("The rendition content was null.", output2);
assertRenditionContainsTitle(titleInitialValue, output2);
return null;
}
};
// Sleep to let the asynchronous action queue perform the updates to the renditions.
int count = 0;
while (count < 60) {
count++;
Thread.sleep(1000L);
// Get the renditions and check their content for the new title
try {
transactionHelper.doInTransaction(checkRenditionCallback);
// Success
break;
} catch (Exception e) {
// Failure
if (count > 60) {
throw e;
}
}
}
transactionHelper.doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<Void>() {
public Void execute() throws Throwable {
renditionService.render(nodeWithDocContent, renditionName1, new RenderCallback() {
@Override
public void handleSuccessfulRendition(ChildAssociationRef primaryParentOfNewRendition) {
assertNotNull("The rendition association was null", primaryParentOfNewRendition);
}
@Override
public void handleFailedRendition(Throwable t) {
fail("No error should be thrown: " + t.getMessage());
}
});
return null;
}
});
}
Aggregations