mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-24 17:32:48 +00:00
[fix/MNT-24172-fixRecreationOfRendition2] Fix of recreation of rendition2 (#3155)
Co-authored-by: mohit-singh4 <mohit.singh@contractors.hyland.com>
This commit is contained in:
@@ -2,7 +2,7 @@
|
|||||||
* #%L
|
* #%L
|
||||||
* Alfresco Repository
|
* Alfresco Repository
|
||||||
* %%
|
* %%
|
||||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
* Copyright (C) 2005 - 2025 Alfresco Software Limited
|
||||||
* %%
|
* %%
|
||||||
* This file is part of the Alfresco software.
|
* This file is part of the Alfresco software.
|
||||||
* If the software was purchased under a paid Alfresco license, the terms of
|
* If the software was purchased under a paid Alfresco license, the terms of
|
||||||
@@ -994,7 +994,29 @@ public abstract class AbstractRenderingEngine extends ActionExecuterAbstractBase
|
|||||||
{
|
{
|
||||||
String msg = "A rendition of name: " + renditionQName + " should have been created for source node: "
|
String msg = "A rendition of name: " + renditionQName + " should have been created for source node: "
|
||||||
+ sourceNode;
|
+ sourceNode;
|
||||||
throw new RenditionServiceException(msg);
|
if (logger.isDebugEnabled())
|
||||||
|
{
|
||||||
|
logger.debug(msg);
|
||||||
|
}
|
||||||
|
// Check if the node has the applied renditioned aspect, and if it does,
|
||||||
|
// remove the existing rendition node and assign the newly created rendition node.
|
||||||
|
if (nodeService.hasAspect(sourceNode, RenditionModel.ASPECT_RENDITIONED))
|
||||||
|
{
|
||||||
|
List<ChildAssociationRef> renditions = nodeService.getChildAssocs(sourceNode, RenditionModel.ASSOC_RENDITION, renditionQName);
|
||||||
|
if (!renditions.isEmpty())
|
||||||
|
{
|
||||||
|
ChildAssociationRef existingRendition = renditions.get(0);
|
||||||
|
nodeService.removeChild(sourceNode, existingRendition.getChildRef());
|
||||||
|
renditionAssoc = renditionNode;
|
||||||
|
|
||||||
|
if (logger.isDebugEnabled())
|
||||||
|
{
|
||||||
|
logger.debug("Removing the existing rendition node that doesn't have contentData and "
|
||||||
|
+ "assigning the newly created rendition node: " + renditionAssoc);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// Return the link between the source and the new, final rendition
|
// Return the link between the source and the new, final rendition
|
||||||
return renditionAssoc;
|
return renditionAssoc;
|
||||||
|
@@ -717,4 +717,63 @@ public class RenditionService2IntegrationTest extends AbstractRenditionIntegrati
|
|||||||
renditionService2.setEnabled(true);
|
renditionService2.setEnabled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testRecreationOfRendition2()
|
||||||
|
{
|
||||||
|
renditionService2.setEnabled(true);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
NodeRef sourceNodeRef = createSource(ADMIN, "quick.docx");
|
||||||
|
assertNotNull("Node not generated", sourceNodeRef);
|
||||||
|
|
||||||
|
// Get content hash code for the source node.
|
||||||
|
int sourceNodeContentHashCode = getSourceContentHashCode(sourceNodeRef);
|
||||||
|
|
||||||
|
// Trigger the pdf rendition.
|
||||||
|
render(ADMIN, sourceNodeRef, PDF);
|
||||||
|
NodeRef pdfRenditionNodeRef = waitForRendition(ADMIN, sourceNodeRef, PDF, true);
|
||||||
|
assertNotNull("pdf rendition was not generated", pdfRenditionNodeRef);
|
||||||
|
assertNotNull("pdf rendition was not generated",
|
||||||
|
nodeService.getProperty(pdfRenditionNodeRef, PROP_CONTENT));
|
||||||
|
|
||||||
|
// Check the pdf rendition content hash code is valid
|
||||||
|
int pdfRenditionContentHashCode = getRenditionContentHashCode(pdfRenditionNodeRef);
|
||||||
|
assertEquals("pdf rendition content hash code is different from source node content hash code",
|
||||||
|
sourceNodeContentHashCode, pdfRenditionContentHashCode);
|
||||||
|
|
||||||
|
// Calling 'clearRenditionContentData' method directly so that rendition content will be cleaned.
|
||||||
|
AuthenticationUtil.runAs(
|
||||||
|
(AuthenticationUtil.RunAsWork<Void>) () -> transactionService.getRetryingTransactionHelper()
|
||||||
|
.doInTransaction(() -> {
|
||||||
|
renditionService2.clearRenditionContentData(sourceNodeRef, PDF);
|
||||||
|
return null;
|
||||||
|
}),
|
||||||
|
ADMIN);
|
||||||
|
|
||||||
|
assertNull("Rendition has content", nodeService.getProperty(pdfRenditionNodeRef, PROP_CONTENT));
|
||||||
|
|
||||||
|
pdfRenditionContentHashCode = getRenditionContentHashCode(pdfRenditionNodeRef);
|
||||||
|
assertFalse("Rendition has content hash code",
|
||||||
|
isValidRenditionContentHashCode(pdfRenditionContentHashCode));
|
||||||
|
|
||||||
|
renditionService2.setEnabled(false);
|
||||||
|
|
||||||
|
final QName pdfRendDefQName = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "pdf");
|
||||||
|
transactionService.getRetryingTransactionHelper()
|
||||||
|
.doInTransaction(() -> AuthenticationUtil.runAs(
|
||||||
|
() -> renditionService.render(sourceNodeRef, pdfRendDefQName), ADMIN));
|
||||||
|
|
||||||
|
renditionService2.setEnabled(true);
|
||||||
|
|
||||||
|
NodeRef pdfRecreatedRenditionNodeRef = waitForRendition(ADMIN, sourceNodeRef, PDF, true);
|
||||||
|
assertNotEquals(" Rendition before deletion and after previewing are identical",
|
||||||
|
pdfRenditionNodeRef.getId(), pdfRecreatedRenditionNodeRef.getId());
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
renditionService2.setEnabled(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user