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);
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
{
@@ -759,7 +775,7 @@ public class ThumbnailServiceImpl implements ThumbnailService,
* @param nodeRef A {@link NodeRef} representing a thumbnail to provide last modification data for.
*/
@SuppressWarnings("unchecked")
public void addThumbnailModificationData(final NodeRef nodeRef, final String thumbnailName)
private void addThumbnailModificationData(final NodeRef nodeRef, final String thumbnailName)
{
if (nodeService.exists(nodeRef))
{
@@ -774,16 +790,6 @@ public class ThumbnailServiceImpl implements ThumbnailService,
// Create the value we want to set...
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
// set the property to indicate which thumbnail the checksum refers to...
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.
behaviourFilter.disableBehaviour(parentNode, ContentModel.ASPECT_AUDITABLE);
behaviourFilter.disableBehaviour(parentNode, ContentModel.ASPECT_VERSIONABLE);
try
{
if (nodeService.hasAspect(parentNode, ContentModel.ASPECT_THUMBNAIL_MODIFICATION))
@@ -825,8 +832,7 @@ public class ThumbnailServiceImpl implements ThumbnailService,
// Set the property...
if (logger.isDebugEnabled())
{
logger.debug("Setting thumbnail last modified date to " + lastModifiedValue +
" on parent node: " + parentNode);
logger.debug("Setting thumbnail last modified date to " + lastModifiedValue +" on parent node: " + parentNode);
}
ruleService.disableRuleType(RuleType.UPDATE);
try
@@ -850,8 +856,7 @@ public class ThumbnailServiceImpl implements ThumbnailService,
if (logger.isDebugEnabled())
{
logger.debug("Adding " + ContentModel.ASPECT_THUMBNAIL_MODIFICATION +
" aspect to parent node: " + parentNode);
logger.debug("Adding " + ContentModel.ASPECT_THUMBNAIL_MODIFICATION + " aspect to parent node: " + parentNode);
}
ruleService.disableRuleType(RuleType.UPDATE);
try
@@ -867,12 +872,9 @@ public class ThumbnailServiceImpl implements ThumbnailService,
finally
{
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.");
}
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)
{
NodeRef thumbnailNodeRef = childAssoc.getChildRef();
NodeRef sourceNodeRef = childAssoc.getParentRef();
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...
if (logger.isDebugEnabled())
{
@@ -905,11 +920,12 @@ public class ThumbnailServiceImpl implements ThumbnailService,
}
addThumbnailModificationData(thumbnailNodeRef, thumbnailName);
}
finally
{
behaviourFilter.enableBehaviour(sourceNodeRef, ContentModel.ASPECT_VERSIONABLE);
}
}
return null;
}
}, false, true);
return null;
}
}, AuthenticationUtil.getSystemUserName());
}
}
}