[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:
mohit-singh4
2025-04-23 12:16:57 +05:30
committed by GitHub
parent 71eed6822d
commit cfb5cb2c6d
2 changed files with 83 additions and 2 deletions

View File

@@ -2,7 +2,7 @@
* #%L
* Alfresco Repository
* %%
* Copyright (C) 2005 - 2016 Alfresco Software Limited
* Copyright (C) 2005 - 2025 Alfresco Software Limited
* %%
* This file is part of the Alfresco software.
* 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: "
+ 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 renditionAssoc;

View File

@@ -717,4 +717,63 @@ public class RenditionService2IntegrationTest extends AbstractRenditionIntegrati
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);
}
}
}