From 4873b8f93b7d22b0db59f76489fa8a77fc6882d4 Mon Sep 17 00:00:00 2001 From: Neil McErlean Date: Fri, 30 Jan 2015 16:35:51 +0000 Subject: [PATCH] Code fix for RM-1821. The fix is to strip RM-related aspects from all renditions of a rejected node, as was previously done only for the node itself. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/modules/recordsmanagement/BRANCHES/V2.3@94473 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../rm-service-context.xml | 1 + .../hold/HoldService.java | 2 +- .../record/RecordServiceImpl.java | 65 ++++++++++++------- .../util/ServiceBaseImpl.java | 12 ++++ 4 files changed, 56 insertions(+), 24 deletions(-) diff --git a/rm-server/config/alfresco/module/org_alfresco_module_rm/rm-service-context.xml b/rm-server/config/alfresco/module/org_alfresco_module_rm/rm-service-context.xml index c1f310dd4d..176cf86aad 100644 --- a/rm-server/config/alfresco/module/org_alfresco_module_rm/rm-service-context.xml +++ b/rm-server/config/alfresco/module/org_alfresco_module_rm/rm-service-context.xml @@ -1052,6 +1052,7 @@ + diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/hold/HoldService.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/hold/HoldService.java index b0e8821e7a..d7e2589c54 100644 --- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/hold/HoldService.java +++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/hold/HoldService.java @@ -68,7 +68,7 @@ public interface HoldService /** * Gets the list of item node references which are in the given hold * - * @param ndoeRef {@link NodeRef} of the hold + * @param hold {@link NodeRef} of the hold * @return Lost of item {@link NodeRef}s which are in the given hold */ List getHeld(NodeRef hold); diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/record/RecordServiceImpl.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/record/RecordServiceImpl.java index 2759216410..e88f9cfb27 100644 --- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/record/RecordServiceImpl.java +++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/record/RecordServiceImpl.java @@ -625,7 +625,7 @@ public class RecordServiceImpl extends BaseBehaviourBean afterCal.set(Calendar.MILLISECOND, 0); propertyUnchanged = (beforeCal.compareTo(afterCal) == 0); } - else if ((afterValue instanceof Boolean) && (beforeValue == null) && (afterValue == Boolean.FALSE)) + else if ((afterValue instanceof Boolean) && (beforeValue == null) && (afterValue.equals(Boolean.FALSE))) { propertyUnchanged = true; } @@ -1281,17 +1281,17 @@ public class RecordServiceImpl extends BaseBehaviourBean try { // get record property values - Map properties = nodeService.getProperties(nodeRef); - String recordId = (String)properties.get(PROP_IDENTIFIER); - String documentOwner = (String)properties.get(PROP_RECORD_ORIGINATING_USER_ID); - String origionalName = (String)properties.get(PROP_ORIGIONAL_NAME); - NodeRef originatingLocation = (NodeRef)properties.get(PROP_RECORD_ORIGINATING_LOCATION); + final Map properties = nodeService.getProperties(nodeRef); + final String recordId = (String)properties.get(PROP_IDENTIFIER); + final String documentOwner = (String)properties.get(PROP_RECORD_ORIGINATING_USER_ID); + final String originalName = (String)properties.get(PROP_ORIGIONAL_NAME); + final NodeRef originatingLocation = (NodeRef)properties.get(PROP_RECORD_ORIGINATING_LOCATION); // we can only reject if the originating location is present if (originatingLocation != null) { // first remove the secondary link association - List parentAssocs = nodeService.getParentAssocs(nodeRef); + final List parentAssocs = nodeService.getParentAssocs(nodeRef); for (ChildAssociationRef childAssociationRef : parentAssocs) { if (!childAssociationRef.isPrimary() && childAssociationRef.getParentRef().equals(originatingLocation)) @@ -1301,37 +1301,28 @@ public class RecordServiceImpl extends BaseBehaviourBean } } - // remove all RM related aspects from the node - Set aspects = nodeService.getAspects(nodeRef); - for (QName aspect : aspects) - { - if (RM_URI.equals(aspect.getNamespaceURI())) - { - // remove the aspect - nodeService.removeAspect(nodeRef, aspect); - } - } + removeRmAspectsFrom(nodeRef); // get the records primary parent association - ChildAssociationRef parentAssoc = nodeService.getPrimaryParent(nodeRef); + final ChildAssociationRef parentAssoc = nodeService.getPrimaryParent(nodeRef); // move the record into the collaboration site nodeService.moveNode(nodeRef, originatingLocation, ContentModel.ASSOC_CONTAINS, parentAssoc.getQName()); - // rename to the origional name - if (origionalName != null) + // rename to the original name + if (originalName != null) { - fileFolderService.rename(nodeRef, origionalName); + fileFolderService.rename(nodeRef, originalName); if (logger.isDebugEnabled()) { String name = (String)nodeService.getProperty(nodeRef, ContentModel.PROP_NAME); - logger.debug("Rename " + name + " to " + origionalName); + logger.debug("Rename " + name + " to " + originalName); } } // save the information about the rejection details - Map aspectProperties = new HashMap(3); + final Map aspectProperties = new HashMap<>(3); aspectProperties.put(PROP_RECORD_REJECTION_USER_ID, userId); aspectProperties.put(PROP_RECORD_REJECTION_DATE, new Date()); aspectProperties.put(PROP_RECORD_REJECTION_REASON, reason); @@ -1361,6 +1352,34 @@ public class RecordServiceImpl extends BaseBehaviourBean return null; } + + /** Removes all RM related aspects from the specified node and any rendition children. */ + private void removeRmAspectsFrom(NodeRef nodeRef) + { + // Note that when folder records are supported, we will need to recursively + // remove aspects from their descendants. + final Set aspects = nodeService.getAspects(nodeRef); + for (QName aspect : aspects) + { + if (RM_URI.equals(aspect.getNamespaceURI())) + { + nodeService.removeAspect(nodeRef, aspect); + } + } + for (ChildAssociationRef renditionAssoc : renditionService.getRenditions(nodeRef)) + { + final NodeRef renditionNode = renditionAssoc.getChildRef(); + + // Do not attempt to clean up rendition nodes which are not children of their source node. + final boolean renditionRequiresCleaning = nodeService.exists(renditionNode) && + renditionAssoc.isPrimary(); + + if (renditionRequiresCleaning) + { + removeRmAspectsFrom(renditionNode); + } + } + } }); } diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/util/ServiceBaseImpl.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/util/ServiceBaseImpl.java index f2d9b38525..4f5c6f9b9c 100644 --- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/util/ServiceBaseImpl.java +++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/util/ServiceBaseImpl.java @@ -28,6 +28,7 @@ import org.alfresco.module.org_alfresco_module_rm.hold.HoldService; import org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementModel; import org.alfresco.repo.transaction.TransactionalResourceHelper; import org.alfresco.service.cmr.dictionary.DictionaryService; +import org.alfresco.service.cmr.rendition.RenditionService; import org.alfresco.service.cmr.repository.ChildAssociationRef; import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.repository.NodeService; @@ -51,6 +52,9 @@ public class ServiceBaseImpl implements RecordsManagementModel, ApplicationConte /** Dictionary service */ protected DictionaryService dictionaryService; + /** Rendition service */ + protected RenditionService renditionService; + /** Application context */ protected ApplicationContext applicationContext; @@ -77,6 +81,14 @@ public class ServiceBaseImpl implements RecordsManagementModel, ApplicationConte this.nodeService = nodeService; } + /** + * @param service service + */ + public void setRenditionService(RenditionService service) + { + this.renditionService = service; + } + /** * @param dictionaryService dictionary service */