classificationReasonIds, NodeRef content)
+ throws LevelIdNotFound, ReasonIdNotFound, InvalidNodeRefException, InvalidNode;
+
+ /**
+ * Indicates whether the currently authenticated user has clearance to see the
+ * provided node.
+ *
+ * Note that users, regardless of their clearance level, are always cleared to see a node that has no classification
+ * applied.
+ *
+ * @param nodeRef node reference
+ * @return boolean true if cleared to see node, false otherwise
+ */
+ boolean hasClearance(NodeRef nodeRef);
+}
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
new file mode 100644
index 0000000000..3ffd6d31f8
--- /dev/null
+++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/ContentClassificationServiceImpl.java
@@ -0,0 +1,168 @@
+/*
+ * Copyright (C) 2005-2015 Alfresco Software Limited.
+ *
+ * This file is part of Alfresco
+ *
+ * Alfresco is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Alfresco is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with Alfresco. If not, see .
+ */
+package org.alfresco.module.org_alfresco_module_rm.classification;
+
+import static org.alfresco.module.org_alfresco_module_rm.util.RMParameterCheck.checkNotBlank;
+import static org.alfresco.util.ParameterCheck.mandatory;
+
+import java.io.Serializable;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.alfresco.model.ContentModel;
+import org.alfresco.module.org_alfresco_module_rm.classification.ClassificationServiceException.InvalidNode;
+import org.alfresco.module.org_alfresco_module_rm.classification.model.ClassifiedContentModel;
+import org.alfresco.module.org_alfresco_module_rm.util.ServiceBaseImpl;
+import org.alfresco.service.cmr.dictionary.DictionaryService;
+import org.alfresco.service.cmr.repository.NodeRef;
+import org.alfresco.service.cmr.repository.NodeService;
+import org.alfresco.service.namespace.QName;
+
+/**
+ * A service to handle the classification of content.
+ *
+ * @author tpage
+ */
+public class ContentClassificationServiceImpl extends ServiceBaseImpl implements ContentClassificationService,
+ ClassifiedContentModel
+{
+ private ClassificationLevelManager levelManager;
+ private ClassificationReasonManager reasonManager;
+ private NodeService nodeService;
+ private DictionaryService dictionaryService;
+ private SecurityClearanceService securityClearanceService;
+ private ClassificationServiceBootstrap classificationServiceBootstrap;
+
+ public void setLevelManager(ClassificationLevelManager levelManager) { this.levelManager = levelManager; }
+ public void setReasonManager(ClassificationReasonManager reasonManager) { this.reasonManager = reasonManager; }
+ public void setNodeService(NodeService nodeService) { this.nodeService = nodeService; }
+ public void setDictionaryService(DictionaryService dictionaryService) { this.dictionaryService = dictionaryService; }
+ public void setSecurityClearanceService(SecurityClearanceService securityClearanceService) { this.securityClearanceService = securityClearanceService; }
+ public void setClassificationServiceBootstrap(ClassificationServiceBootstrap classificationServiceBootstrap) { this.classificationServiceBootstrap = classificationServiceBootstrap; }
+
+ public void init()
+ {
+ this.levelManager = classificationServiceBootstrap.getClassificationLevelManager();
+ this.reasonManager = classificationServiceBootstrap.getClassificationReasonManager();
+ }
+
+ @Override
+ public ClassificationLevel getCurrentClassification(NodeRef nodeRef)
+ {
+ // by default everything is unclassified
+ ClassificationLevel result = ClassificationLevelManager.UNCLASSIFIED;
+
+ if (nodeService.hasAspect(nodeRef, ASPECT_CLASSIFIED))
+ {
+ String classificationId = (String)nodeService.getProperty(nodeRef, PROP_CURRENT_CLASSIFICATION);
+ result = levelManager.findLevelById(classificationId);
+ }
+
+ return result;
+ };
+
+ @Override
+ public void classifyContent(String classificationLevelId, String classificationAuthority,
+ Set classificationReasonIds, NodeRef content)
+ {
+ checkNotBlank("classificationLevelId", classificationLevelId);
+ checkNotBlank("classificationAuthority", classificationAuthority);
+ mandatory("classificationReasonIds", classificationReasonIds);
+ mandatory("content", content);
+
+ if (!dictionaryService.isSubClass(nodeService.getType(content), ContentModel.TYPE_CONTENT))
+ {
+ throw new InvalidNode(content, "The supplied node is not a content node.");
+ }
+ if (nodeService.hasAspect(content, ASPECT_CLASSIFIED))
+ {
+ throw new UnsupportedOperationException(
+ "The content has already been classified. Reclassification is currently not supported.");
+ }
+
+ Map properties = new HashMap();
+ // Check the classification level id - an exception will be thrown if the id cannot be found
+ levelManager.findLevelById(classificationLevelId);
+
+ // Initial classification id
+ if (nodeService.getProperty(content, PROP_INITIAL_CLASSIFICATION) == null)
+ {
+ properties.put(PROP_INITIAL_CLASSIFICATION, classificationLevelId);
+ }
+
+ // Current classification id
+ properties.put(PROP_CURRENT_CLASSIFICATION, classificationLevelId);
+
+ // Classification authority
+ properties.put(PROP_CLASSIFICATION_AUTHORITY, classificationAuthority);
+
+ // Classification reason ids
+ HashSet classificationReasons = new HashSet<>();
+ for (String classificationReasonId : classificationReasonIds)
+ {
+ // Check the classification reason id - an exception will be thrown if the id cannot be found
+ reasonManager.findReasonById(classificationReasonId);
+ classificationReasons.add(classificationReasonId);
+ }
+ properties.put(PROP_CLASSIFICATION_REASONS, classificationReasons);
+
+ // Add aspect
+ nodeService.addAspect(content, ASPECT_CLASSIFIED, properties);
+ }
+
+ @Override
+ public boolean hasClearance(NodeRef nodeRef)
+ {
+ boolean result = false;
+
+ // Get the node's current classification
+ ClassificationLevel currentClassification = getCurrentClassification(nodeRef);
+ if (ClassificationLevelManager.UNCLASSIFIED.equals(currentClassification))
+ {
+ // since the node is not classified user has clearance
+ result = true;
+ }
+ else
+ {
+ // Get the user's security clearance
+ SecurityClearance securityClearance = securityClearanceService.getUserSecurityClearance();
+ if (!ClearanceLevelManager.NO_CLEARANCE.equals(securityClearance.getClearanceLevel()))
+ {
+ // get the users highest classification clearance
+ ClassificationLevel highestClassification = securityClearance.getClearanceLevel().getHighestClassificationLevel();
+
+ // if classification is less than or equal to highest classification then user has clearance
+ List allClassificationLevels = levelManager.getClassificationLevels();
+ int highestIndex = allClassificationLevels.indexOf(highestClassification);
+ int currentIndex = allClassificationLevels.indexOf(currentClassification);
+
+ if (highestIndex <= currentIndex)
+ {
+ // user has clearance
+ result = true;
+ }
+ }
+ }
+
+ return result;
+ }
+}
diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/SecurityClearanceService.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/SecurityClearanceService.java
index 7599687434..82a2251d2e 100644
--- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/SecurityClearanceService.java
+++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/SecurityClearanceService.java
@@ -19,7 +19,6 @@
package org.alfresco.module.org_alfresco_module_rm.classification;
import org.alfresco.query.PagingResults;
-import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.security.NoSuchPersonException;
import java.util.List;
@@ -33,18 +32,6 @@ import java.util.List;
*/
public interface SecurityClearanceService
{
- /**
- * Indicates whether the currently authenticated user has clearance to see the
- * provided node.
- *
- * Note that users, regardless of their clearance level, are always cleared to see a node that has no classification
- * applied.
- *
- * @param nodeRef node reference
- * @return boolean true if cleared to see node, false otherwise
- */
- boolean hasClearance(NodeRef nodeRef);
-
/**
* Get the currently authenticated user's security clearance.
*
diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/SecurityClearanceServiceImpl.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/SecurityClearanceServiceImpl.java
index 017a449934..dbc69fdf4a 100644
--- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/SecurityClearanceServiceImpl.java
+++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/SecurityClearanceServiceImpl.java
@@ -25,6 +25,8 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
+import com.google.common.collect.ImmutableList;
+import org.alfresco.module.org_alfresco_module_rm.classification.ClassificationServiceException.LevelIdNotFound;
import org.alfresco.module.org_alfresco_module_rm.util.ServiceBaseImpl;
import org.alfresco.query.PagingRequest;
import org.alfresco.query.PagingResults;
@@ -43,75 +45,23 @@ public class SecurityClearanceServiceImpl extends ServiceBaseImpl implements Sec
{
/** The clearance levels currently configured in this server. */
private ClearanceLevelManager clearanceManager;
-
- private ClassificationService classificationService;
- private PersonService personService;
+ /** The object containing the {@link ClassificationLevel}s in the system. */
+ private ClassificationLevelManager classificationLevelManager;
+ private PersonService personService;
+ private ClassificationServiceBootstrap classificationServiceBootstrap;
public void setClearanceManager(ClearanceLevelManager clearanceManager) { this.clearanceManager = clearanceManager; }
- public void setClassificationService(ClassificationService service) { this.classificationService = service; }
+ public void setClassificationLevelManager(ClassificationLevelManager classificationLevelManager) { this.classificationLevelManager = classificationLevelManager; }
public void setPersonService(PersonService service) { this.personService = service; }
+ public void setClassificationServiceBootstrap(ClassificationServiceBootstrap classificationServiceBootstrap) { this.classificationServiceBootstrap = classificationServiceBootstrap; }
- /**
- * Initialise and create a {@link ClearanceLevelManager}. This assumes that the {@link ClassificationService} has
- * already been initialised.
- */
- void initialise()
+ /** Store the references to the classification and clearance level managers in this class. */
+ public void init()
{
- ArrayList clearanceLevels = new ArrayList();
- List classificationLevels = classificationService.getClassificationLevels();
- for (ClassificationLevel classificationLevel : classificationLevels)
- {
- if (!ClassificationLevelManager.UNCLASSIFIED.equals(classificationLevel))
- {
- clearanceLevels.add(new ClearanceLevel(classificationLevel, classificationLevel.getDisplayLabelKey()));
- }
- }
- this.clearanceManager = new ClearanceLevelManager(clearanceLevels);
+ this.classificationLevelManager = classificationServiceBootstrap.getClassificationLevelManager();
+ this.clearanceManager = classificationServiceBootstrap.getClearanceLevelManager();
}
- /** Get the clearance manager (for use in unit testing). */
- protected ClearanceLevelManager getClearanceManager() { return clearanceManager; }
-
- /**
- * @see org.alfresco.module.org_alfresco_module_rm.classification.SecurityClearanceService#hasClearance(org.alfresco.service.cmr.repository.NodeRef)
- */
- @Override
- public boolean hasClearance(NodeRef nodeRef)
- {
- boolean result = false;
-
- // get the nodes current classification
- ClassificationLevel currentClassification = classificationService.getCurrentClassification(nodeRef);
- if (ClassificationLevelManager.UNCLASSIFIED.equals(currentClassification))
- {
- // since the node is not classified user has clearance
- result = true;
- }
- else
- {
- // get the users security clearance
- SecurityClearance securityClearance = getUserSecurityClearance();
- if (!ClearanceLevelManager.NO_CLEARANCE.equals(securityClearance.getClearanceLevel()))
- {
- // get the users highest classification clearance
- ClassificationLevel highestClassification = securityClearance.getClearanceLevel().getHighestClassificationLevel();
-
- // if classification is less than or equal to highest classification then user has clearance
- List allClassificationLevels = classificationService.getClassificationLevels();
- int highestIndex = allClassificationLevels.indexOf(highestClassification);
- int currentIndex = allClassificationLevels.indexOf(currentClassification);
-
- if (highestIndex <= currentIndex)
- {
- // user has clearance
- result = true;
- }
- }
- }
-
- return result;
- }
-
@Override
public SecurityClearance getUserSecurityClearance()
{
@@ -123,7 +73,7 @@ public class SecurityClearanceServiceImpl extends ServiceBaseImpl implements Sec
/**
* Gets the users security clearnace.
- *
+ *
* @param userName user name
* @return {@link SecurityClearance} provides information about the user and their clearance level
*/
@@ -132,21 +82,14 @@ public class SecurityClearanceServiceImpl extends ServiceBaseImpl implements Sec
final NodeRef personNode = personService.getPerson(userName, false);
final PersonInfo personInfo = personService.getPerson(personNode);
- final ClassificationLevel classificationLevel;
-
+ ClearanceLevel clearanceLevel = ClearanceLevelManager.NO_CLEARANCE;
if (nodeService.hasAspect(personNode, ASPECT_SECURITY_CLEARANCE))
{
- final String clearanceLevelValue = (String)nodeService.getProperty(personNode, PROP_CLEARANCE_LEVEL);
-
- classificationLevel = clearanceLevelValue == null ? classificationService.getUnclassifiedClassificationLevel() :
- classificationService.getClassificationLevelById(clearanceLevelValue);
- }
- else
- {
- classificationLevel = classificationService.getUnclassifiedClassificationLevel();
+ final String clearanceLevelId = (String)nodeService.getProperty(personNode, PROP_CLEARANCE_LEVEL);
+ clearanceLevel = (clearanceLevelId == null ? ClearanceLevelManager.NO_CLEARANCE
+ : clearanceManager.findLevelByClassificationLevelId(clearanceLevelId));
}
- ClearanceLevel clearanceLevel = clearanceManager.findLevelByClassificationLevelId(classificationLevel.getId());
return new SecurityClearance(personInfo, clearanceLevel);
}
@@ -182,6 +125,33 @@ public class SecurityClearanceServiceImpl extends ServiceBaseImpl implements Sec
};
}
+ /**
+ * Check if a classification can be accessed by a user with a given clearance.
+ *
+ * @param clearance The clearance of the user.
+ * @param classificationId The classification level to look for.
+ * @return {@code true} if the user can access the classification level.
+ */
+ protected boolean isClearedForClassification(SecurityClearance clearance, String classificationId)
+ {
+ ImmutableList classificationLevels = classificationLevelManager.getClassificationLevels();
+
+ String clearanceId = clearance.getClearanceLevel().getHighestClassificationLevel().getId();
+ for (ClassificationLevel classificationLevel : classificationLevels)
+ {
+ if (classificationLevel.getId().equals(clearanceId))
+ {
+ return true;
+ }
+ else if (classificationLevel.getId().equals(classificationId))
+ {
+ return false;
+ }
+ }
+ // Neither the clearance id nor the classification id were found - something's gone wrong.
+ throw new LevelIdNotFound(classificationId);
+ }
+
@Override
public SecurityClearance setUserSecurityClearance(String userName, String clearanceId)
{
@@ -189,9 +159,13 @@ public class SecurityClearanceServiceImpl extends ServiceBaseImpl implements Sec
ParameterCheck.mandatoryString("clearanceId", clearanceId);
final NodeRef personNode = personService.getPerson(userName, false);
- // This is just used to check the current user has clearance to see the specified level; it will throw a
- // LevelIdNotFound exception if not.
- classificationService.getClassificationLevelById(clearanceId);
+
+ // Check the current user has clearance to see the specified level.
+ SecurityClearance userSecurityClearance = getUserSecurityClearance();
+ if (!isClearedForClassification(userSecurityClearance, clearanceId))
+ {
+ throw new LevelIdNotFound(clearanceId);
+ }
nodeService.setProperty(personNode, PROP_CLEARANCE_LEVEL, clearanceId);
diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/model/ClassifiedContentModel.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/model/ClassifiedContentModel.java
index d463657c96..a8c6996e3b 100644
--- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/model/ClassifiedContentModel.java
+++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/model/ClassifiedContentModel.java
@@ -18,6 +18,8 @@
*/
package org.alfresco.module.org_alfresco_module_rm.classification.model;
+import java.io.Serializable;
+
import org.alfresco.service.namespace.QName;
/**
@@ -34,6 +36,9 @@ public interface ClassifiedContentModel
String CLF_URI = "http://www.alfresco.org/model/classifiedcontent/1.0";
String CLF_PREFIX = "clf";
+ Serializable[] LEVELS_KEY = new String[] { "org.alfresco", "module.org_alfresco_module_rm", "classification.levels" };
+ Serializable[] REASONS_KEY = new String[] { "org.alfresco", "module.org_alfresco_module_rm", "classification.reasons" };
+
/** Classified aspect */
QName ASPECT_CLASSIFIED = QName.createQName(CLF_URI, "classified");
QName PROP_INITIAL_CLASSIFICATION = QName.createQName(CLF_URI, "initialClassification");
diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/classification/ClassifyContentPost.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/classification/ClassifyContentPost.java
index dd8f423354..89dff922b9 100644
--- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/classification/ClassifyContentPost.java
+++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/classification/ClassifyContentPost.java
@@ -1,19 +1,19 @@
/*
- * Copyright (C) 2005-2014 Alfresco Software Limited.
- *
- * This file is part of Alfresco
- *
- * Alfresco is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * Alfresco is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
+ * Copyright (C) 2005-2014 Alfresco Software Limited.
+ *
+ * This file is part of Alfresco
+ *
+ * Alfresco is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Alfresco is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see .
*/
package org.alfresco.module.org_alfresco_module_rm.script.classification;
@@ -28,7 +28,7 @@ import java.util.HashSet;
import java.util.Map;
import java.util.Set;
-import org.alfresco.module.org_alfresco_module_rm.classification.ClassificationService;
+import org.alfresco.module.org_alfresco_module_rm.classification.ContentClassificationService;
import org.alfresco.module.org_alfresco_module_rm.script.AbstractRmWebScript;
import org.alfresco.service.cmr.repository.NodeRef;
import org.json.JSONArray;
@@ -50,23 +50,17 @@ public class ClassifyContentPost extends AbstractRmWebScript
public static final String CLASSIFICATION_AUTHORITY = "classificationAuthority";
public static final String CLASSIFICATION_REASONS = "classificationReasons";
- /** Classification service */
- private ClassificationService classificationService;
+ /** The service responsible for classifying content. */
+ private ContentClassificationService contentClassificationService;
/**
- * @return the classificationService
+ * Set the service responsible for classifying content.
+ *
+ * @param contentClassificationService The service responsible for classifying content.
*/
- protected ClassificationService getClassificationService()
+ public void setContentClassificationService(ContentClassificationService contentClassificationService)
{
- return this.classificationService;
- }
-
- /**
- * @param classificationService the classificationService to set
- */
- public void setClassificationService(ClassificationService classificationService)
- {
- this.classificationService = classificationService;
+ this.contentClassificationService = contentClassificationService;
}
/**
@@ -83,7 +77,7 @@ public class ClassifyContentPost extends AbstractRmWebScript
Set classificationReasonIds = getClassificationReasonIds(jsonObject);
NodeRef document = parseRequestForNodeRef(req);
- getClassificationService().classifyContent(classificationLevelId, classificationAuthority, classificationReasonIds, document);
+ contentClassificationService.classifyContent(classificationLevelId, classificationAuthority, classificationReasonIds, document);
Map model = new HashMap(1);
model.put(SUCCESS, true);
diff --git a/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/integration/classification/ClassificationLevelsTest.java b/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/integration/classification/ClassificationLevelsTest.java
index 4a3a13ed85..367d832edd 100644
--- a/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/integration/classification/ClassificationLevelsTest.java
+++ b/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/integration/classification/ClassificationLevelsTest.java
@@ -64,7 +64,7 @@ public class ClassificationLevelsTest extends BaseRMTestCase
{
List levels = classificationService.getClassificationLevels();
assertNotNull(levels);
- assertEquals(5, levels.size());
+ assertEquals("Expected 5 levels to be configured (4 defined in the test plus Unclassified)", 5, levels.size());
ClassificationLevel level1 = levels.get(0);
ClassificationLevel level2 = levels.get(1);
diff --git a/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/integration/classification/ClassifyTest.java b/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/integration/classification/ClassifyTest.java
index 9f79cd9b6c..57f64521a9 100644
--- a/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/integration/classification/ClassifyTest.java
+++ b/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/integration/classification/ClassifyTest.java
@@ -34,12 +34,12 @@ import org.alfresco.service.cmr.repository.NodeRef;
*/
public class ClassifyTest extends BaseRMTestCase
{
- /** test data */
- private static final String CLASSIFICATION_LEVEL = "level1";
- private static final String CLASSIFICATION_REASON = "Test Reason 1";
- private static final String CLASSIFICATION_AUTHORITY = "classification authority";
- private static final String RECORD_NAME = "recordname.txt";
-
+ /** test data */
+ private static final String CLASSIFICATION_LEVEL = "level1";
+ private static final String CLASSIFICATION_REASON = "Test Reason 1";
+ private static final String CLASSIFICATION_AUTHORITY = "classification authority";
+ private static final String RECORD_NAME = "recordname.txt";
+
/**
* Given that a record is frozen
* And unclassified
@@ -50,27 +50,27 @@ public class ClassifyTest extends BaseRMTestCase
{
doBehaviourDrivenTest(new BehaviourDrivenTest(AccessDeniedException.class)
{
- private NodeRef record;
-
+ private NodeRef record;
+
public void given() throws Exception
{
- record = utils.createRecord(rmFolder, RECORD_NAME);
-
- NodeRef hold = holdService.createHold(filePlan, "my hold", "for test", "for test");
- holdService.addToHold(hold, record);
+ record = utils.createRecord(rmFolder, RECORD_NAME);
+
+ NodeRef hold = holdService.createHold(filePlan, "my hold", "for test", "for test");
+ holdService.addToHold(hold, record);
}
public void when() throws Exception
{
- classificationService.classifyContent(
- CLASSIFICATION_LEVEL,
- CLASSIFICATION_AUTHORITY,
- Collections.singleton(CLASSIFICATION_REASON),
- record);
+ contentClassificationService.classifyContent(
+ CLASSIFICATION_LEVEL,
+ CLASSIFICATION_AUTHORITY,
+ Collections.singleton(CLASSIFICATION_REASON),
+ record);
}
});
}
-
+
/**
* Given that a record is complete
* And unclassified
@@ -80,31 +80,31 @@ public class ClassifyTest extends BaseRMTestCase
{
doBehaviourDrivenTest(new BehaviourDrivenTest()
{
- private NodeRef record;
-
+ private NodeRef record;
+
public void given() throws Exception
{
- record = utils.createRecord(rmFolder, RECORD_NAME);
- utils.completeRecord(record);
+ record = utils.createRecord(rmFolder, RECORD_NAME);
+ utils.completeRecord(record);
}
public void when() throws Exception
{
- classificationService.classifyContent(
- CLASSIFICATION_LEVEL,
- CLASSIFICATION_AUTHORITY,
- Collections.singleton(CLASSIFICATION_REASON),
- record);
+ contentClassificationService.classifyContent(
+ CLASSIFICATION_LEVEL,
+ CLASSIFICATION_AUTHORITY,
+ Collections.singleton(CLASSIFICATION_REASON),
+ record);
}
@SuppressWarnings("unchecked")
- public void then() throws Exception
+ public void then() throws Exception
{
- assertTrue(nodeService.hasAspect(record, ClassifiedContentModel.ASPECT_CLASSIFIED));
- assertEquals(CLASSIFICATION_LEVEL, (String)nodeService.getProperty(record, ClassifiedContentModel.PROP_INITIAL_CLASSIFICATION));
- assertEquals(CLASSIFICATION_LEVEL, (String)nodeService.getProperty(record, ClassifiedContentModel.PROP_CURRENT_CLASSIFICATION));
- assertEquals(CLASSIFICATION_AUTHORITY, (String)nodeService.getProperty(record, ClassifiedContentModel.PROP_CLASSIFICATION_AUTHORITY));
- assertEquals(Collections.singletonList(CLASSIFICATION_REASON), (List)nodeService.getProperty(record, ClassifiedContentModel.PROP_CLASSIFICATION_REASONS));
+ assertTrue(nodeService.hasAspect(record, ClassifiedContentModel.ASPECT_CLASSIFIED));
+ assertEquals(CLASSIFICATION_LEVEL, (String)nodeService.getProperty(record, ClassifiedContentModel.PROP_INITIAL_CLASSIFICATION));
+ assertEquals(CLASSIFICATION_LEVEL, (String)nodeService.getProperty(record, ClassifiedContentModel.PROP_CURRENT_CLASSIFICATION));
+ assertEquals(CLASSIFICATION_AUTHORITY, (String)nodeService.getProperty(record, ClassifiedContentModel.PROP_CLASSIFICATION_AUTHORITY));
+ assertEquals(Collections.singletonList(CLASSIFICATION_REASON), (List)nodeService.getProperty(record, ClassifiedContentModel.PROP_CLASSIFICATION_REASONS));
}
});
}
diff --git a/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/util/BaseRMTestCase.java b/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/util/BaseRMTestCase.java
index c304645469..36b66555ef 100644
--- a/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/util/BaseRMTestCase.java
+++ b/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/util/BaseRMTestCase.java
@@ -30,6 +30,7 @@ import org.alfresco.module.org_alfresco_module_rm.audit.RecordsManagementAuditSe
import org.alfresco.module.org_alfresco_module_rm.capability.CapabilityService;
import org.alfresco.module.org_alfresco_module_rm.capability.RMPermissionModel;
import org.alfresco.module.org_alfresco_module_rm.classification.ClassificationService;
+import org.alfresco.module.org_alfresco_module_rm.classification.ContentClassificationService;
import org.alfresco.module.org_alfresco_module_rm.dataset.DataSetService;
import org.alfresco.module.org_alfresco_module_rm.disposition.DispositionSchedule;
import org.alfresco.module.org_alfresco_module_rm.disposition.DispositionService;
@@ -162,6 +163,7 @@ public abstract class BaseRMTestCase extends RetryingTransactionHelperTestCase
protected InplaceRecordService inplaceRecordService;
protected RelationshipService relationshipService;
protected ClassificationService classificationService;
+ protected ContentClassificationService contentClassificationService;
/** test data */
protected String siteId;
@@ -273,7 +275,7 @@ public abstract class BaseRMTestCase extends RetryingTransactionHelperTestCase
*/
protected boolean isRMSiteTest()
{
- return true;
+ return true;
}
/**
@@ -402,6 +404,7 @@ public abstract class BaseRMTestCase extends RetryingTransactionHelperTestCase
inplaceRecordService = (InplaceRecordService) applicationContext.getBean("InplaceRecordService");
relationshipService = (RelationshipService) applicationContext.getBean("RelationshipService");
classificationService = (ClassificationService) applicationContext.getBean("ClassificationService");
+ contentClassificationService = (ContentClassificationService) applicationContext.getBean("ContentClassificationService");
}
/**
@@ -482,44 +485,44 @@ public abstract class BaseRMTestCase extends RetryingTransactionHelperTestCase
*/
protected void setupTestData()
{
- doTestInTransaction(new Test()
+ doTestInTransaction(new Test()
{
public Void run()
{
- setupTestDataImpl();
+ setupTestDataImpl();
- if (isRecordTest() && isRMSiteTest())
- {
- setupTestRecords();
- }
+ if (isRecordTest() && isRMSiteTest())
+ {
+ setupTestRecords();
+ }
- return null;
+ return null;
}
@Override
public void test(Void result) throws Exception
{
- if (isRMSiteTest())
- {
- if (isRecordTest())
- {
- // declare a record
- utils.completeRecord(recordDeclaredOne);
- utils.completeRecord(recordDeclaredTwo);
- }
+ if (isRMSiteTest())
+ {
+ if (isRecordTest())
+ {
+ // declare a record
+ utils.completeRecord(recordDeclaredOne);
+ utils.completeRecord(recordDeclaredTwo);
+ }
- // unfiled container
- unfiledContainer = filePlanService.getUnfiledContainer(filePlan);
- assertNotNull(unfiledContainer);
+ // unfiled container
+ unfiledContainer = filePlanService.getUnfiledContainer(filePlan);
+ assertNotNull(unfiledContainer);
- // holds container
- holdsContainer = filePlanService.getHoldContainer(filePlan);
- assertNotNull(holdsContainer);
+ // holds container
+ holdsContainer = filePlanService.getHoldContainer(filePlan);
+ assertNotNull(holdsContainer);
- // transfers container
- transfersContainer = filePlanService.getTransferContainer(filePlan);
- assertNotNull(transfersContainer);
- }
+ // transfers container
+ transfersContainer = filePlanService.getTransferContainer(filePlan);
+ assertNotNull(transfersContainer);
+ }
}
}, AuthenticationUtil.getSystemUserName());
}
@@ -556,28 +559,28 @@ public abstract class BaseRMTestCase extends RetryingTransactionHelperTestCase
if (isRMSiteTest())
{
- siteId = GUID.generate();
- siteInfo = siteService.createSite(
- "rm-site-dashboard",
- siteId,
- "title",
- "descrition",
- SiteVisibility.PUBLIC,
- RecordsManagementModel.TYPE_RM_SITE);
+ siteId = GUID.generate();
+ siteInfo = siteService.createSite(
+ "rm-site-dashboard",
+ siteId,
+ "title",
+ "descrition",
+ SiteVisibility.PUBLIC,
+ RecordsManagementModel.TYPE_RM_SITE);
- filePlan = siteService.getContainer(siteId, RmSiteType.COMPONENT_DOCUMENT_LIBRARY);
- assertNotNull("Site document library container was not created successfully.", filePlan);
+ filePlan = siteService.getContainer(siteId, RmSiteType.COMPONENT_DOCUMENT_LIBRARY);
+ assertNotNull("Site document library container was not created successfully.", filePlan);
- // Create RM container
- rmContainer = filePlanService.createRecordCategory(filePlan, "rmContainer");
- assertNotNull("Could not create rm container", rmContainer);
+ // Create RM container
+ rmContainer = filePlanService.createRecordCategory(filePlan, "rmContainer");
+ assertNotNull("Could not create rm container", rmContainer);
- // Create disposition schedule
- dispositionSchedule = utils.createBasicDispositionSchedule(rmContainer);
+ // Create disposition schedule
+ dispositionSchedule = utils.createBasicDispositionSchedule(rmContainer);
- // Create RM folder
- rmFolder = recordFolderService.createRecordFolder(rmContainer, "rmFolder");
- assertNotNull("Could not create rm folder", rmFolder);
+ // Create RM folder
+ rmFolder = recordFolderService.createRecordFolder(rmContainer, "rmFolder");
+ assertNotNull("Could not create rm folder", rmFolder);
}
}
diff --git a/rm-server/unit-test/java/org/alfresco/module/org_alfresco_module_rm/classification/ClassificationLevelManagerUnitTest.java b/rm-server/unit-test/java/org/alfresco/module/org_alfresco_module_rm/classification/ClassificationLevelManagerUnitTest.java
index f9c8f6c7fe..29d8febfc6 100644
--- a/rm-server/unit-test/java/org/alfresco/module/org_alfresco_module_rm/classification/ClassificationLevelManagerUnitTest.java
+++ b/rm-server/unit-test/java/org/alfresco/module/org_alfresco_module_rm/classification/ClassificationLevelManagerUnitTest.java
@@ -29,7 +29,7 @@ import org.junit.Test;
/**
* Unit tests for the {@link ClassificationLevelManager}.
- *
+ *
* @author tpage
*/
public class ClassificationLevelManagerUnitTest
@@ -43,7 +43,8 @@ public class ClassificationLevelManagerUnitTest
@Before public void setup()
{
- classificationLevelManager = new ClassificationLevelManager(LEVELS);
+ classificationLevelManager = new ClassificationLevelManager();
+ classificationLevelManager.setClassificationLevels(LEVELS);
}
@Test public void findClassificationById_found()
diff --git a/rm-server/unit-test/java/org/alfresco/module/org_alfresco_module_rm/classification/ClassificationReasonManagerUnitTest.java b/rm-server/unit-test/java/org/alfresco/module/org_alfresco_module_rm/classification/ClassificationReasonManagerUnitTest.java
index 682e4a8843..16cdcf1168 100644
--- a/rm-server/unit-test/java/org/alfresco/module/org_alfresco_module_rm/classification/ClassificationReasonManagerUnitTest.java
+++ b/rm-server/unit-test/java/org/alfresco/module/org_alfresco_module_rm/classification/ClassificationReasonManagerUnitTest.java
@@ -29,7 +29,7 @@ import org.junit.Test;
/**
* Unit tests for the {@link ClassificationReasonManager}.
- *
+ *
* @author tpage
*/
public class ClassificationReasonManagerUnitTest
@@ -43,7 +43,8 @@ public class ClassificationReasonManagerUnitTest
@Before public void setup()
{
- classificationReasonManager = new ClassificationReasonManager(REASONS);
+ classificationReasonManager = new ClassificationReasonManager();
+ classificationReasonManager.setClassificationReasons(REASONS);
}
@Test public void findClassificationById_found()
diff --git a/rm-server/unit-test/java/org/alfresco/module/org_alfresco_module_rm/classification/ClassificationServiceBootstrapUnitTest.java b/rm-server/unit-test/java/org/alfresco/module/org_alfresco_module_rm/classification/ClassificationServiceBootstrapUnitTest.java
new file mode 100644
index 0000000000..0ae13faf8d
--- /dev/null
+++ b/rm-server/unit-test/java/org/alfresco/module/org_alfresco_module_rm/classification/ClassificationServiceBootstrapUnitTest.java
@@ -0,0 +1,236 @@
+/*
+ * Copyright (C) 2005-2015 Alfresco Software Limited.
+ *
+ * This file is part of Alfresco
+ *
+ * Alfresco is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Alfresco is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with Alfresco. If not, see .
+ */
+package org.alfresco.module.org_alfresco_module_rm.classification;
+
+import static java.util.Arrays.asList;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.anyString;
+import static org.mockito.Matchers.eq;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.stream.Stream;
+
+import com.google.common.collect.ImmutableList;
+import org.alfresco.module.org_alfresco_module_rm.classification.ClassificationServiceException.MissingConfiguration;
+import org.alfresco.module.org_alfresco_module_rm.test.util.MockAuthenticationUtilHelper;
+import org.alfresco.module.org_alfresco_module_rm.util.AuthenticationUtil;
+import org.alfresco.service.cmr.attributes.AttributeService;
+import org.apache.log4j.Appender;
+import org.apache.log4j.Level;
+import org.apache.log4j.spi.LoggingEvent;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.ArgumentCaptor;
+import org.mockito.Captor;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+
+/**
+ * Unit tests for the {@link ClassificationServiceBootstrap}.
+ *
+ * @author tpage
+ */
+public class ClassificationServiceBootstrapUnitTest
+{
+ private static final List DEFAULT_CLASSIFICATION_LEVELS = asLevelList("Top Secret", "rm.classification.topSecret",
+ "Secret", "rm.classification.secret",
+ "Confidential", "rm.classification.confidential",
+ "No Clearance", "rm.classification.noClearance");
+ private static final List ALT_CLASSIFICATION_LEVELS = asLevelList("Board", "B",
+ "Executive Management", "EM",
+ "Employee", "E",
+ "Public", "P");
+ private static final List PLACEHOLDER_CLASSIFICATION_REASONS = asList(new ClassificationReason("id1", "label1"),
+ new ClassificationReason("id2", "label2"));
+ private static final List ALTERNATIVE_CLASSIFICATION_REASONS = asList(new ClassificationReason("id8", "label8"),
+ new ClassificationReason("id9", "label9"));
+
+ /**
+ * A convenience method for turning lists of level id Strings into lists
+ * of {@code ClassificationLevel} objects.
+ *
+ * @param idsAndLabels A varargs/array of Strings like so: [ id0, label0, id1, label1... ]
+ * @throws IllegalArgumentException if {@code idsAndLabels} has a non-even length.
+ */
+ public static List asLevelList(String ... idsAndLabels)
+ {
+ if (idsAndLabels.length % 2 != 0)
+ {
+ throw new IllegalArgumentException(String.format("Cannot create %s objects with %d args.",
+ ClassificationLevel.class.getSimpleName(), idsAndLabels.length));
+ }
+
+ final List levels = new ArrayList<>(idsAndLabels.length / 2);
+
+ for (int i = 0; i < idsAndLabels.length; i += 2)
+ {
+ levels.add(new ClassificationLevel(idsAndLabels[i], idsAndLabels[i+1]));
+ }
+
+ return levels;
+ }
+
+ @InjectMocks ClassificationServiceBootstrap classificationServiceBootstrap;
+ @Mock ClassificationServiceDAO mockClassificationServiceDAO;
+ @Mock AttributeService mockAttributeService;
+ @Mock AuthenticationUtil mockAuthenticationUtil;
+ /** Using a mock appender in the class logger so that we can verify some of the logging requirements. */
+ @Mock Appender mockAppender;
+ @Captor ArgumentCaptor loggingEventCaptor;
+
+ @Before public void setUp()
+ {
+ MockitoAnnotations.initMocks(this);
+ MockAuthenticationUtilHelper.setup(mockAuthenticationUtil);
+ }
+
+ @Test public void defaultLevelsConfigurationVanillaSystem()
+ {
+ when(mockClassificationServiceDAO.getConfiguredLevels()).thenReturn(DEFAULT_CLASSIFICATION_LEVELS);
+ when(mockAttributeService.getAttribute(anyString(), anyString(), anyString())).thenReturn(null);
+
+ classificationServiceBootstrap.initConfiguredClassificationLevels();
+
+ verify(mockAttributeService).setAttribute(eq((Serializable) DEFAULT_CLASSIFICATION_LEVELS),
+ anyString(), anyString(), anyString());
+ }
+
+ @Test public void alternativeLevelsConfigurationPreviouslyStartedSystem()
+ {
+ when(mockClassificationServiceDAO.getConfiguredLevels()).thenReturn(ALT_CLASSIFICATION_LEVELS);
+ when(mockAttributeService.getAttribute(anyString(), anyString(), anyString()))
+ .thenReturn((Serializable) DEFAULT_CLASSIFICATION_LEVELS);
+
+ classificationServiceBootstrap.initConfiguredClassificationLevels();
+
+ verify(mockAttributeService).setAttribute(eq((Serializable) ALT_CLASSIFICATION_LEVELS),
+ anyString(), anyString(), anyString());
+ }
+
+ @Test (expected=MissingConfiguration.class)
+ public void missingLevelsConfigurationVanillaSystemShouldFail() throws Exception
+ {
+ when(mockAttributeService.getAttribute(anyString(), anyString(), anyString())).thenReturn(null);
+
+ classificationServiceBootstrap.initConfiguredClassificationLevels();
+ }
+
+ @Test public void pristineSystemShouldBootstrapReasonsConfiguration()
+ {
+ // There are no classification reasons stored in the AttributeService.
+ when(mockAttributeService.getAttribute(anyString(), anyString(), anyString())).thenReturn(null);
+
+ // We'll use a small set of placeholder classification reasons.
+ when(mockClassificationServiceDAO.getConfiguredReasons()).thenReturn(PLACEHOLDER_CLASSIFICATION_REASONS);
+
+ classificationServiceBootstrap.initConfiguredClassificationReasons();
+
+ verify(mockAttributeService).setAttribute(eq((Serializable)PLACEHOLDER_CLASSIFICATION_REASONS),
+ anyString(), anyString(), anyString());
+ }
+
+ @Test public void checkAttributesNotTouchedIfConfiguredReasonsHaveNotChanged()
+ {
+ // The classification reasons stored are the same values that are found on the classpath.
+ when(mockAttributeService.getAttribute(anyString(), anyString(), anyString())).thenReturn((Serializable)PLACEHOLDER_CLASSIFICATION_REASONS);
+ when(mockClassificationServiceDAO.getConfiguredReasons()).thenReturn(PLACEHOLDER_CLASSIFICATION_REASONS);
+
+ classificationServiceBootstrap.initConfiguredClassificationReasons();
+
+ verify(mockAttributeService, never()).setAttribute(any(Serializable.class),
+ anyString(), anyString(), anyString());
+ }
+
+ /**
+ * Check that if the reasons supplied on the classpath differ from those already persisted then a warning is logged
+ * and no change is made to the persisted reasons.
+ *
+ * This test uses the underlying log4j implementation to insert a mock Appender, and tests this for the warning
+ * message. If the underlying logging framework is changed then this unit test will fail, and it may not be
+ * possible to/worth fixing.
+ */
+ @Test public void previouslyStartedSystemShouldWarnIfConfiguredReasonsHaveChanged()
+ {
+ // The classification reasons stored are different from those found on the classpath.
+ when(mockAttributeService.getAttribute(anyString(), anyString(), anyString())).thenReturn(
+ (Serializable) PLACEHOLDER_CLASSIFICATION_REASONS);
+ when(mockClassificationServiceDAO.getConfiguredReasons()).thenReturn(ALTERNATIVE_CLASSIFICATION_REASONS);
+
+ // Put the mock Appender into the log4j logger and allow warning messages to be received.
+ org.apache.log4j.Logger log4jLogger = org.apache.log4j.Logger.getLogger(ClassificationServiceBootstrap.class);
+ log4jLogger.addAppender(mockAppender);
+ Level normalLevel = log4jLogger.getLevel();
+ log4jLogger.setLevel(Level.WARN);
+
+ // Call the method under test.
+ classificationServiceBootstrap.initConfiguredClassificationReasons();
+
+ // Reset the logging level for other tests.
+ log4jLogger.setLevel(normalLevel);
+
+ // Check the persisted values weren't changed.
+ verify(mockAttributeService, never()).setAttribute(any(Serializable.class),
+ anyString(), anyString(), anyString());
+
+ // Check that the warning message was logged.
+ verify(mockAppender).doAppend(loggingEventCaptor.capture());
+ List loggingEvents = loggingEventCaptor.getAllValues();
+ Stream messages = loggingEvents.stream().map(event -> event.getRenderedMessage());
+ String expectedMessage = "Classification reasons configured in classpath do not match those stored in Alfresco. Alfresco will use the unchanged values stored in the database.";
+ assertTrue("Warning message not found in log.", messages.anyMatch(message -> message == expectedMessage));
+ }
+
+ @Test(expected = MissingConfiguration.class)
+ public void noReasonsFoundCausesException()
+ {
+ when(mockAttributeService.getAttribute(anyString(), anyString(), anyString()))
+ .thenReturn((Serializable) null);
+ when(mockClassificationServiceDAO.getConfiguredReasons()).thenReturn(null);
+
+ classificationServiceBootstrap.initConfiguredClassificationReasons();
+ }
+
+ /**
+ * Check that the initialise method creates a clearance level corresponding to each classification level and that
+ * the display label for the lowest clearance level is "No Clearance" (rather than "Unclassified").
+ */
+ @Test public void initConfiguredClearanceLevels()
+ {
+ ClassificationLevel topSecret = new ClassificationLevel("1", "TopSecret");
+ ClassificationLevel secret = new ClassificationLevel("2", "Secret");
+ ImmutableList classificationLevels = ImmutableList.of(topSecret, secret, ClassificationLevelManager.UNCLASSIFIED);
+
+ // Call the method under test.
+ classificationServiceBootstrap.initConfiguredClearanceLevels(classificationLevels);
+
+ List clearanceLevels = classificationServiceBootstrap.getClearanceLevelManager().getClearanceLevels();
+ assertEquals("There should be one clearance level for each classification level.", classificationLevels.size(), clearanceLevels.size());
+ assertEquals("TopSecret", clearanceLevels.get(0).getDisplayLabel());
+ assertEquals("Secret", clearanceLevels.get(1).getDisplayLabel());
+ assertEquals("rm.classification.noClearance", clearanceLevels.get(2).getDisplayLabel());
+ }
+}
diff --git a/rm-server/unit-test/java/org/alfresco/module/org_alfresco_module_rm/classification/ClassificationServiceImplUnitTest.java b/rm-server/unit-test/java/org/alfresco/module/org_alfresco_module_rm/classification/ClassificationServiceImplUnitTest.java
index 460110497f..07be295efd 100644
--- a/rm-server/unit-test/java/org/alfresco/module/org_alfresco_module_rm/classification/ClassificationServiceImplUnitTest.java
+++ b/rm-server/unit-test/java/org/alfresco/module/org_alfresco_module_rm/classification/ClassificationServiceImplUnitTest.java
@@ -18,45 +18,21 @@
*/
package org.alfresco.module.org_alfresco_module_rm.classification;
-import static java.util.Arrays.asList;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.anyString;
-import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.doThrow;
-import static org.mockito.Mockito.never;
-import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
-import static org.mockito.Mockito.verifyNoMoreInteractions;
-import static org.alfresco.module.org_alfresco_module_rm.test.util.AlfMock.generateNodeRef;
-import static org.alfresco.module.org_alfresco_module_rm.test.util.AlfMock.generateText;
import java.io.Serializable;
import java.util.ArrayList;
-import java.util.HashSet;
import java.util.List;
import java.util.Map;
-import java.util.Set;
-import java.util.stream.Stream;
-import org.alfresco.model.ContentModel;
-import org.alfresco.module.org_alfresco_module_rm.classification.ClassificationServiceException.InvalidNode;
import org.alfresco.module.org_alfresco_module_rm.classification.ClassificationServiceException.LevelIdNotFound;
-import org.alfresco.module.org_alfresco_module_rm.classification.ClassificationServiceException.MissingConfiguration;
import org.alfresco.module.org_alfresco_module_rm.classification.ClassificationServiceException.ReasonIdNotFound;
-import org.alfresco.module.org_alfresco_module_rm.classification.model.ClassifiedContentModel;
import org.alfresco.module.org_alfresco_module_rm.test.util.ExceptionUtils;
-import org.alfresco.module.org_alfresco_module_rm.test.util.MockAuthenticationUtilHelper;
-import org.alfresco.module.org_alfresco_module_rm.util.AuthenticationUtil;
-import org.alfresco.service.cmr.attributes.AttributeService;
import org.alfresco.service.cmr.dictionary.DictionaryService;
-import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.namespace.QName;
-import org.apache.log4j.Appender;
-import org.apache.log4j.Level;
-import org.apache.log4j.spi.LoggingEvent;
import org.junit.Before;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
@@ -65,8 +41,6 @@ import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
-import com.google.common.collect.Sets;
-
/**
* Unit tests for {@link ClassificationServiceImpl}.
*
@@ -79,18 +53,7 @@ public class ClassificationServiceImplUnitTest
"Secret", "rm.classification.secret",
"Confidential", "rm.classification.confidential",
"No Clearance", "rm.classification.noClearance");
- private static final List ALT_CLASSIFICATION_LEVELS = asLevelList("Board", "B",
- "Executive Management", "EM",
- "Employee", "E",
- "Public", "P");
- private static final List PLACEHOLDER_CLASSIFICATION_REASONS = asList(new ClassificationReason("id1", "label1"),
- new ClassificationReason("id2", "label2"));
- private static final List ALTERNATIVE_CLASSIFICATION_REASONS = asList(new ClassificationReason("id8", "label8"),
- new ClassificationReason("id9", "label9"));
-
- private static final String CLASSIFICATION_LEVEL_ID = "classificationLevelId";
- private static final ClassificationLevel CLASSIFICATION_LEVEL = new ClassificationLevel(CLASSIFICATION_LEVEL_ID, generateText());
-
+
/**
* A convenience method for turning lists of level id Strings into lists
* of {@code ClassificationLevel} objects.
@@ -117,128 +80,15 @@ public class ClassificationServiceImplUnitTest
@InjectMocks private ClassificationServiceImpl classificationServiceImpl;
- @Mock private AttributeService mockedAttributeService;
- @Mock private AuthenticationUtil mockedAuthenticationUtil;
- @Mock private ClassificationServiceDAO mockClassificationServiceDAO;
@Mock private NodeService mockNodeService;
@Mock private DictionaryService mockDictionaryService;
- /** Using a mock appender in the class logger so that we can verify some of the logging requirements. */
- @Mock private Appender mockAppender;
@Mock private ClassificationLevelManager mockLevelManager;
@Mock private ClassificationReasonManager mockReasonManager;
- @Captor private ArgumentCaptor loggingEventCaptor;
@Captor private ArgumentCaptor