From cc07996323b6cb141b3ab512d8d22d68c2d1bcf9 Mon Sep 17 00:00:00 2001 From: cagache Date: Wed, 7 Aug 2019 12:38:18 +0300 Subject: [PATCH] fix sonar issues --- .../hold/HoldServiceImpl.java | 16 +++---- .../model/rma/aspect/FrozenAspect.java | 44 ++++++++----------- 2 files changed, 27 insertions(+), 33 deletions(-) diff --git a/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/hold/HoldServiceImpl.java b/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/hold/HoldServiceImpl.java index 9045c1144b..93ca463d99 100644 --- a/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/hold/HoldServiceImpl.java +++ b/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/hold/HoldServiceImpl.java @@ -294,13 +294,13 @@ public class HoldServiceImpl extends ServiceBaseImpl List result = new ArrayList<>(); // get all the immediate parent holds - Set holdsIncludingNodeRef = getParentHolds(nodeRef); + final Set holdsIncludingNodeRef = getParentHolds(nodeRef); // check whether the record is held by virtue of it's record folder if (isRecord(nodeRef)) { final List recordFolders = recordFolderService.getRecordFolders(nodeRef); - for (NodeRef recordFolder : recordFolders) + for (final NodeRef recordFolder : recordFolders) { holdsIncludingNodeRef.addAll(getParentHolds(recordFolder)); } @@ -311,11 +311,11 @@ public class HoldServiceImpl extends ServiceBaseImpl final Set filePlans = filePlanService.getFilePlans(); if (!CollectionUtils.isEmpty(filePlans)) { - List holdsNotIncludingNodeRef = new ArrayList<>(); + final List holdsNotIncludingNodeRef = new ArrayList<>(); filePlans.forEach(filePlan -> { // invert list to get list of holds that do not contain this node - List allHolds = getHolds(filePlan); + final List allHolds = getHolds(filePlan); holdsNotIncludingNodeRef.addAll(ListUtils.subtract(allHolds, new ArrayList<>(holdsIncludingNodeRef))); }); result = holdsNotIncludingNodeRef; @@ -559,7 +559,7 @@ public class HoldServiceImpl extends ServiceBaseImpl { if (!isHold(hold)) { - String holdName = (String) nodeService.getProperty(hold, ContentModel.PROP_NAME); + final String holdName = (String) nodeService.getProperty(hold, ContentModel.PROP_NAME); throw new IntegrityException(I18NUtil.getMessage("rm.hold.not-hold", holdName), null); } @@ -574,7 +574,7 @@ public class HoldServiceImpl extends ServiceBaseImpl // run as system to ensure we have all the appropriate permissions to perform the manipulations we require authenticationUtil.runAsSystem((RunAsWork) () -> { // gather freeze properties - Map props = new HashMap<>(2); + final Map props = new HashMap<>(2); props.put(PROP_FROZEN_AT, new Date()); props.put(PROP_FROZEN_BY, AuthenticationUtil.getFullyAuthenticatedUser()); @@ -589,7 +589,7 @@ public class HoldServiceImpl extends ServiceBaseImpl // Mark all the folders contents as frozen if (isRecordFolder(nodeRef)) { - List records = recordService.getRecords(nodeRef); + final List records = recordService.getRecords(nodeRef); records.forEach(record -> addFrozenAspect(record, props)); } @@ -608,7 +608,7 @@ public class HoldServiceImpl extends ServiceBaseImpl { if (!isRecord(nodeRef) && !isRecordFolder(nodeRef) && !instanceOf(nodeRef, ContentModel.TYPE_CONTENT)) { - String nodeName = (String) nodeService.getProperty(nodeRef, ContentModel.PROP_NAME); + final String nodeName = (String) nodeService.getProperty(nodeRef, ContentModel.PROP_NAME); throw new IntegrityException(I18NUtil.getMessage("rm.hold.add-to-hold-invalid-type", nodeName), null); } diff --git a/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/model/rma/aspect/FrozenAspect.java b/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/model/rma/aspect/FrozenAspect.java index deadb823e2..c3dcc1f4fb 100644 --- a/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/model/rma/aspect/FrozenAspect.java +++ b/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/model/rma/aspect/FrozenAspect.java @@ -157,37 +157,31 @@ public class FrozenAspect extends BaseBehaviourBean ) public void onAddAspect(final NodeRef nodeRef, final QName aspectTypeQName) { - AuthenticationUtil.runAsSystem(new RunAsWork() - { - @Override - public Void doWork() + AuthenticationUtil.runAsSystem((RunAsWork) () -> { + if (nodeService.exists(nodeRef) && (isRecord(nodeRef) || instanceOf(nodeRef, TYPE_CONTENT))) { - if (nodeService.exists(nodeRef) && (isRecord(nodeRef) || instanceOf(nodeRef, TYPE_CONTENT))) + // get the owning folder + final NodeRef parentRef = nodeService.getPrimaryParent(nodeRef).getParentRef(); + // check that the aspect has been added + if (nodeService.hasAspect(parentRef, ASPECT_HELD_CHILDREN)) { - // get the owning folder - final NodeRef parentRef = nodeService.getPrimaryParent(nodeRef).getParentRef(); - // check that the aspect has been added - if (nodeService.hasAspect(parentRef, ASPECT_HELD_CHILDREN)) + // increment current count + int currentCount = (Integer) nodeService.getProperty(parentRef, PROP_HELD_CHILDREN_COUNT); + currentCount = currentCount + 1; + nodeService.setProperty(parentRef, PROP_HELD_CHILDREN_COUNT, currentCount); + } else + { + if (instanceOf(parentRef, TYPE_FOLDER) && !nodeService.hasAspect(parentRef, ASPECT_SITE_CONTAINER)) { - // increment current count - int currentCount = (Integer) nodeService.getProperty(parentRef, PROP_HELD_CHILDREN_COUNT); - currentCount = currentCount + 1; - nodeService.setProperty(parentRef, PROP_HELD_CHILDREN_COUNT, currentCount); - } - else - { - if(instanceOf(parentRef, TYPE_FOLDER) && !nodeService.hasAspect(parentRef, ASPECT_SITE_CONTAINER)) - { - // add aspect and set count to 1 - Map props = new HashMap<>(1); - props.put(PROP_HELD_CHILDREN_COUNT, 1); - getInternalNodeService().addAspect(parentRef, ASPECT_HELD_CHILDREN, props); - } + // add aspect and set count to 1 + final Map props = new HashMap<>(1); + props.put(PROP_HELD_CHILDREN_COUNT, 1); + getInternalNodeService().addAspect(parentRef, ASPECT_HELD_CHILDREN, props); } } - return null; } - }); + return null; + }); } @Override