Merged 5.2.N-LAST-T-MOD (5.2.1) to 5.2.N (5.2.1)

134687 amorarasu: REPO-1580 / MNT-17113: Preview not updated after new versions/content
      - The fix is similar to the proposed patch + some code moving (disabling audit and versioning)


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/DEV/5.2.N/root@134717 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Jan Vonka
2017-01-23 14:04:34 +00:00
parent e03e26f6ba
commit 76d670370e

View File

@@ -279,6 +279,22 @@ public class ThumbnailServiceImpl implements ThumbnailService,
} }
TransactionalResourceHelper.getSet(THUMBNAIL_PARENT_NODES).add(childAssoc); TransactionalResourceHelper.getSet(THUMBNAIL_PARENT_NODES).add(childAssoc);
TransactionSupportUtil.bindListener(this.transactionListener, 0); TransactionSupportUtil.bindListener(this.transactionListener, 0);
// For new version/content the child association contains a temporary thumbnail node, that gets removed later.
// We need to add the original thumbnail node to the TransactionalResourceHelper instead.
QName thumbnailQname = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, thumbnailName);
if (!childAssoc.getQName().equals(thumbnailQname))
{
List<ChildAssociationRef> allAssocList = nodeService.getChildAssocs(childAssoc.getParentRef(), RegexQNamePattern.MATCH_ALL, thumbnailQname);
for (ChildAssociationRef aChildAssoc : allAssocList)
{
if (logger.isDebugEnabled())
{
logger.debug("Caching original thumbnail " + aChildAssoc + " in transaction resources, thumbnail " + thumbnailName);
}
TransactionalResourceHelper.getSet(THUMBNAIL_PARENT_NODES).add(aChildAssoc);
}
}
} }
else else
{ {
@@ -759,7 +775,7 @@ public class ThumbnailServiceImpl implements ThumbnailService,
* @param nodeRef A {@link NodeRef} representing a thumbnail to provide last modification data for. * @param nodeRef A {@link NodeRef} representing a thumbnail to provide last modification data for.
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public void addThumbnailModificationData(final NodeRef nodeRef, final String thumbnailName) private void addThumbnailModificationData(final NodeRef nodeRef, final String thumbnailName)
{ {
if (nodeService.exists(nodeRef)) if (nodeService.exists(nodeRef))
{ {
@@ -774,16 +790,6 @@ public class ThumbnailServiceImpl implements ThumbnailService,
// Create the value we want to set... // Create the value we want to set...
final String lastModifiedValue = thumbnailName + ":" + timestamp; final String lastModifiedValue = thumbnailName + ":" + timestamp;
RetryingTransactionHelper txnHelper = transactionService.getRetryingTransactionHelper();
txnHelper.setForceWritable(true);
// MNT-15135: Do the property update in a new transaction, in case the parent node was already changed (has a different version) in another transaction.
// This way the failures will not propagate up the retry stack.
txnHelper.doInTransaction(new RetryingTransactionCallback<Void>()
{
@Override
public Void execute() throws Throwable
{
// Get the parent node (there should be only one) and apply the aspect and // Get the parent node (there should be only one) and apply the aspect and
// set the property to indicate which thumbnail the checksum refers to... // set the property to indicate which thumbnail the checksum refers to...
for (ChildAssociationRef parent: nodeService.getParentAssocs(nodeRef)) for (ChildAssociationRef parent: nodeService.getParentAssocs(nodeRef))
@@ -794,6 +800,7 @@ public class ThumbnailServiceImpl implements ThumbnailService,
// we don't want to audit any changes to the parent here. // we don't want to audit any changes to the parent here.
behaviourFilter.disableBehaviour(parentNode, ContentModel.ASPECT_AUDITABLE); behaviourFilter.disableBehaviour(parentNode, ContentModel.ASPECT_AUDITABLE);
behaviourFilter.disableBehaviour(parentNode, ContentModel.ASPECT_VERSIONABLE);
try try
{ {
if (nodeService.hasAspect(parentNode, ContentModel.ASPECT_THUMBNAIL_MODIFICATION)) if (nodeService.hasAspect(parentNode, ContentModel.ASPECT_THUMBNAIL_MODIFICATION))
@@ -825,8 +832,7 @@ public class ThumbnailServiceImpl implements ThumbnailService,
// Set the property... // Set the property...
if (logger.isDebugEnabled()) if (logger.isDebugEnabled())
{ {
logger.debug("Setting thumbnail last modified date to " + lastModifiedValue + logger.debug("Setting thumbnail last modified date to " + lastModifiedValue +" on parent node: " + parentNode);
" on parent node: " + parentNode);
} }
ruleService.disableRuleType(RuleType.UPDATE); ruleService.disableRuleType(RuleType.UPDATE);
try try
@@ -850,8 +856,7 @@ public class ThumbnailServiceImpl implements ThumbnailService,
if (logger.isDebugEnabled()) if (logger.isDebugEnabled())
{ {
logger.debug("Adding " + ContentModel.ASPECT_THUMBNAIL_MODIFICATION + logger.debug("Adding " + ContentModel.ASPECT_THUMBNAIL_MODIFICATION + " aspect to parent node: " + parentNode);
" aspect to parent node: " + parentNode);
} }
ruleService.disableRuleType(RuleType.UPDATE); ruleService.disableRuleType(RuleType.UPDATE);
try try
@@ -867,12 +872,9 @@ public class ThumbnailServiceImpl implements ThumbnailService,
finally finally
{ {
behaviourFilter.enableBehaviour(parentNode, ContentModel.ASPECT_AUDITABLE); behaviourFilter.enableBehaviour(parentNode, ContentModel.ASPECT_AUDITABLE);
behaviourFilter.enableBehaviour(parentNode, ContentModel.ASPECT_VERSIONABLE);
} }
} }
return null;
}
}, false, true);
} }
} }
} }
@@ -887,16 +889,29 @@ public class ThumbnailServiceImpl implements ThumbnailService,
{ {
logger.debug("Starting aftercommit listener execution."); logger.debug("Starting aftercommit listener execution.");
} }
Set<ChildAssociationRef> childAssocs = TransactionalResourceHelper.getSet(THUMBNAIL_PARENT_NODES); final Set<ChildAssociationRef> childAssocs = TransactionalResourceHelper.getSet(THUMBNAIL_PARENT_NODES);
AuthenticationUtil.runAs(new AuthenticationUtil.RunAsWork<Void>()
{
@Override
public Void doWork() throws Exception
{
// MNT-15135: Do the property update in a new transaction, in case the parent node was already changed (has a different version) in another transaction.
// This way the failures will not propagate up the retry stack.
RetryingTransactionHelper txnHelper = transactionService.getRetryingTransactionHelper();
txnHelper.setForceWritable(true);
txnHelper.doInTransaction(new RetryingTransactionCallback<Void>()
{
@Override
public Void execute() throws Throwable
{
for (ChildAssociationRef childAssoc : childAssocs) for (ChildAssociationRef childAssoc : childAssocs)
{ {
NodeRef thumbnailNodeRef = childAssoc.getChildRef(); NodeRef thumbnailNodeRef = childAssoc.getChildRef();
NodeRef sourceNodeRef = childAssoc.getParentRef(); NodeRef sourceNodeRef = childAssoc.getParentRef();
String thumbnailName = (String) nodeService.getProperty(thumbnailNodeRef, ContentModel.PROP_NAME); String thumbnailName = (String) nodeService.getProperty(thumbnailNodeRef, ContentModel.PROP_NAME);
try //behaviourFilter.disableBehaviour(sourceNodeRef, ContentModel.ASPECT_VERSIONABLE);
{
behaviourFilter.disableBehaviour(sourceNodeRef, ContentModel.ASPECT_VERSIONABLE);
// Update the parent node with the thumbnail update... // Update the parent node with the thumbnail update...
if (logger.isDebugEnabled()) if (logger.isDebugEnabled())
{ {
@@ -905,11 +920,12 @@ public class ThumbnailServiceImpl implements ThumbnailService,
} }
addThumbnailModificationData(thumbnailNodeRef, thumbnailName); addThumbnailModificationData(thumbnailNodeRef, thumbnailName);
} }
finally return null;
{ }
behaviourFilter.enableBehaviour(sourceNodeRef, ContentModel.ASPECT_VERSIONABLE); }, false, true);
} return null;
} }
}, AuthenticationUtil.getSystemUserName());
} }
} }
} }