From f2010a9f2fa927d37f26d41294e400b4f76d3a0a Mon Sep 17 00:00:00 2001 From: Tuna Aksoy Date: Fri, 12 Jun 2015 20:39:33 +0000 Subject: [PATCH] RM-2280 (Move the code for checking if the content is classified to the service layer) * moved the check to content classification service +review RM-87 git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/modules/recordsmanagement/HEAD@106090 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../rm-ui-evaluators-context.xml | 1 + .../ContentClassificationService.java | 9 ++++ .../ContentClassificationServiceImpl.java | 21 ++++++++ .../jscript/app/JSONConversionComponent.java | 39 +++++---------- ...tentClassificationServiceImplUnitTest.java | 50 +++++++++++++++++-- 5 files changed, 91 insertions(+), 29 deletions(-) diff --git a/rm-server/config/alfresco/module/org_alfresco_module_rm/rm-ui-evaluators-context.xml b/rm-server/config/alfresco/module/org_alfresco_module_rm/rm-ui-evaluators-context.xml index b23d53b94f..3723b0b490 100644 --- a/rm-server/config/alfresco/module/org_alfresco_module_rm/rm-ui-evaluators-context.xml +++ b/rm-server/config/alfresco/module/org_alfresco_module_rm/rm-ui-evaluators-context.xml @@ -17,6 +17,7 @@ + diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/ContentClassificationService.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/ContentClassificationService.java index 27a606d963..a6309415a6 100644 --- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/ContentClassificationService.java +++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/ContentClassificationService.java @@ -56,6 +56,15 @@ public interface ContentClassificationService void classifyContent(String classificationLevelId, String classificationAuthority, Set classificationReasonIds, NodeRef content) throws LevelIdNotFound, ReasonIdNotFound, InvalidNodeRefException, InvalidNode; + /** + * Checks if the node is classified or not. A node classified + * as "Unclassified" will be treated as not classified. + * + * @param nodeRef Node reference + * @return true if the node is classified, false otherwise + */ + boolean isClassified(NodeRef nodeRef); + /** * Indicates whether the currently authenticated user has clearance to see the * provided node. diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/ContentClassificationServiceImpl.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/ContentClassificationServiceImpl.java index 1c31e4660b..3b2523e1a8 100644 --- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/ContentClassificationServiceImpl.java +++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/ContentClassificationServiceImpl.java @@ -18,6 +18,7 @@ */ package org.alfresco.module.org_alfresco_module_rm.classification; +import static org.alfresco.module.org_alfresco_module_rm.classification.ClassificationLevelManager.UNCLASSIFIED_ID; import static org.alfresco.module.org_alfresco_module_rm.util.RMParameterCheck.checkNotBlank; import static org.alfresco.util.ParameterCheck.mandatory; @@ -144,4 +145,24 @@ public class ContentClassificationServiceImpl extends ServiceBaseImpl implements ClassificationLevel currentClassification = getCurrentClassification(nodeRef); return securityClearanceService.isCurrentUserClearedForClassification(currentClassification.getId()); } + + /** + * @see org.alfresco.module.org_alfresco_module_rm.classification.ContentClassificationService#isClassified(org.alfresco.service.cmr.repository.NodeRef) + */ + @Override + public boolean isClassified(NodeRef nodeRef) + { + mandatory("nodeRef", nodeRef); + + boolean isClassified = false; + String currentClassification = (String) nodeService.getProperty(nodeRef, PROP_CURRENT_CLASSIFICATION); + + if (nodeService.hasAspect(nodeRef, ASPECT_CLASSIFIED) && + !(UNCLASSIFIED_ID).equals(currentClassification)) + { + isClassified = true; + } + + return isClassified; + } } diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/jscript/app/JSONConversionComponent.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/jscript/app/JSONConversionComponent.java index 79242dcaba..63c98bc758 100644 --- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/jscript/app/JSONConversionComponent.java +++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/jscript/app/JSONConversionComponent.java @@ -19,9 +19,6 @@ package org.alfresco.module.org_alfresco_module_rm.jscript.app; import static org.alfresco.module.org_alfresco_module_rm.capability.RMPermissionModel.READ_RECORDS; -import static org.alfresco.module.org_alfresco_module_rm.classification.ClassificationLevelManager.UNCLASSIFIED_ID; -import static org.alfresco.module.org_alfresco_module_rm.classification.model.ClassifiedContentModel.ASPECT_CLASSIFIED; -import static org.alfresco.module.org_alfresco_module_rm.classification.model.ClassifiedContentModel.PROP_CURRENT_CLASSIFICATION; import static org.alfresco.service.cmr.security.AccessStatus.ALLOWED; import java.util.ArrayList; @@ -32,6 +29,7 @@ import java.util.Map; import org.alfresco.model.ContentModel; import org.alfresco.module.org_alfresco_module_rm.capability.CapabilityService; import org.alfresco.module.org_alfresco_module_rm.capability.impl.ViewRecordsCapability; +import org.alfresco.module.org_alfresco_module_rm.classification.ContentClassificationService; import org.alfresco.module.org_alfresco_module_rm.fileplan.FilePlanComponentKind; import org.alfresco.module.org_alfresco_module_rm.fileplan.FilePlanService; import org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementModel; @@ -94,6 +92,9 @@ public class JSONConversionComponent extends org.alfresco.repo.jscript.app.JS /** site service */ private SiteService siteService; + /** Content classification service */ + private ContentClassificationService contentClassificationService; + /** Indicators */ private List indicators = new ArrayList(); @@ -165,6 +166,14 @@ public class JSONConversionComponent extends org.alfresco.repo.jscript.app.JS this.siteService = siteService; } + /** + * @param contentClassificationService the contentClassificationService to set + */ + public void setContentClassificationService(ContentClassificationService contentClassificationService) + { + this.contentClassificationService = contentClassificationService; + } + /** * @param indicator registered indicator */ @@ -249,7 +258,7 @@ public class JSONConversionComponent extends org.alfresco.repo.jscript.app.JS NodeRef nodeRef = nodeInfo.getNodeRef(); // Is the node classified - rootJSONObject.put(IS_CLASSIFIED, isClassified(nodeRef)); + rootJSONObject.put(IS_CLASSIFIED, contentClassificationService.isClassified(nodeRef)); if (AccessStatus.ALLOWED.equals(capabilityService.getCapabilityAccessState(nodeRef, ViewRecordsCapability.NAME))) { @@ -268,28 +277,6 @@ public class JSONConversionComponent extends org.alfresco.repo.jscript.app.JS } } - /** - * Checks if the node is classified or not. A node classified - * as "Unclassified" will be treated as not classified. - * - * @param nodeRef Node reference - * @return true if the node is classified, false otherwise - */ - private boolean isClassified(NodeRef nodeRef) - { - boolean isClassified = false; - - String currentClassification = (String) nodeService.getProperty(nodeRef, PROP_CURRENT_CLASSIFICATION); - - if (nodeService.hasAspect(nodeRef, ASPECT_CLASSIFIED) && - !(UNCLASSIFIED_ID).equals(currentClassification)) - { - isClassified = true; - } - - return isClassified; - } - /** * Checks for the existance of the RM site * diff --git a/rm-server/unit-test/java/org/alfresco/module/org_alfresco_module_rm/classification/ContentClassificationServiceImplUnitTest.java b/rm-server/unit-test/java/org/alfresco/module/org_alfresco_module_rm/classification/ContentClassificationServiceImplUnitTest.java index f5b33b5ef8..857db4be0e 100644 --- a/rm-server/unit-test/java/org/alfresco/module/org_alfresco_module_rm/classification/ContentClassificationServiceImplUnitTest.java +++ b/rm-server/unit-test/java/org/alfresco/module/org_alfresco_module_rm/classification/ContentClassificationServiceImplUnitTest.java @@ -37,9 +37,6 @@ import java.util.List; import java.util.Map; import java.util.Set; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.Sets; - import org.alfresco.model.ContentModel; import org.alfresco.model.QuickShareModel; import org.alfresco.module.org_alfresco_module_rm.classification.ClassificationException.InvalidNode; @@ -60,6 +57,9 @@ import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.MockitoAnnotations; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.Sets; + /** * Unit tests for {@link ContentClassificationServiceImpl}. * @@ -301,4 +301,48 @@ public class ContentClassificationServiceImplUnitTest implements ClassifiedConte assertFalse(contentClassificationServiceImpl.hasClearance(nodeRef)); } + + /** + * Given that I classify a node with a level not equal to "Unclassified" + * When I ask if the node is classified + * Then return true + */ + @Test public void contentClassified_levelNotUnclassified() + { + NodeRef nodeRef = generateNodeRef(mockNodeService); + + when(mockNodeService.getProperty(nodeRef, PROP_CURRENT_CLASSIFICATION)).thenReturn("level1"); + when(mockNodeService.hasAspect(nodeRef, ASPECT_CLASSIFIED)).thenReturn(true); + + assertTrue(contentClassificationServiceImpl.isClassified(nodeRef)); + } + + /** + * Given that I classify a node with level "Unclassified" + * When I ask if the node is classified + * Then return false + */ + @Test public void contentClassified_levelUnclassified() + { + NodeRef nodeRef = generateNodeRef(mockNodeService); + + when(mockNodeService.getProperty(nodeRef, PROP_CURRENT_CLASSIFICATION)).thenReturn(ClassificationLevelManager.UNCLASSIFIED_ID); + when(mockNodeService.hasAspect(nodeRef, ASPECT_CLASSIFIED)).thenReturn(true); + + assertFalse(contentClassificationServiceImpl.isClassified(nodeRef)); + } + + /** + * Given that a node is not classified + * When I ask if the node is classified + * Then return false + */ + @Test public void contentNotClassified() + { + NodeRef nodeRef = generateNodeRef(mockNodeService); + + when(mockNodeService.hasAspect(nodeRef, ASPECT_CLASSIFIED)).thenReturn(false); + + assertFalse(contentClassificationServiceImpl.isClassified(nodeRef)); + } }