From 3bcad6ee1ef0646b762f4f241cdb279d58b11133 Mon Sep 17 00:00:00 2001 From: Tom Page Date: Fri, 19 Jun 2015 14:28:20 +0000 Subject: [PATCH] RM-2320 Java API for getExemptionCategories. Also RM-2321 automation testing for the initial loading of exemption categories. +review RM git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/modules/recordsmanagement/HEAD@106565 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../classified-content-context.xml | 1 + .../ClassificationSchemeService.java | 7 ++ .../ClassificationSchemeServiceImpl.java | 10 +++ .../ExemptionCategoryManager.java | 1 + .../ExemptionCategoriesTest.java | 79 +++++++++++++++++++ .../rm-exemption-categories.json | 10 +++ 6 files changed, 108 insertions(+) create mode 100644 rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/integration/classification/ExemptionCategoriesTest.java create mode 100644 rm-server/test/resources/alfresco/module/org_alfresco_module_rm/classification/rm-exemption-categories.json diff --git a/rm-server/config/alfresco/module/org_alfresco_module_rm/classified-content-context.xml b/rm-server/config/alfresco/module/org_alfresco_module_rm/classified-content-context.xml index 1474d8a5fc..1ae526ec16 100644 --- a/rm-server/config/alfresco/module/org_alfresco_module_rm/classified-content-context.xml +++ b/rm-server/config/alfresco/module/org_alfresco_module_rm/classified-content-context.xml @@ -82,6 +82,7 @@ org.alfresco.module.org_alfresco_module_rm.classification.ClassificationSchemeService.getClassificationLevelById=ACL_ALLOW org.alfresco.module.org_alfresco_module_rm.classification.ClassificationSchemeService.getClassificationReasonById=ACL_ALLOW org.alfresco.module.org_alfresco_module_rm.classification.ClassificationSchemeService.getUnclassifiedClassificationLevel=ACL_ALLOW + org.alfresco.module.org_alfresco_module_rm.classification.ClassificationSchemeService.getExemptionCategories=ACL_ALLOW org.alfresco.module.org_alfresco_module_rm.classification.ClassificationSchemeService.*=ACL_DENY diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/ClassificationSchemeService.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/ClassificationSchemeService.java index d04eb11448..b655ed4ba8 100644 --- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/ClassificationSchemeService.java +++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/ClassificationSchemeService.java @@ -71,4 +71,11 @@ public interface ClassificationSchemeService * @throws ReasonIdNotFound If the given classification reason id is not found */ ClassificationReason getClassificationReasonById(String classificationReasonId) throws ReasonIdNotFound; + + /** + * Returns an immutable list of the defined exemption categories. + * + * @return The exemption categories in the order that they are defined. + */ + List getExemptionCategories(); } diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/ClassificationSchemeServiceImpl.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/ClassificationSchemeServiceImpl.java index a80888aaf4..b40d6c21bd 100644 --- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/ClassificationSchemeServiceImpl.java +++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/ClassificationSchemeServiceImpl.java @@ -40,6 +40,8 @@ public class ClassificationSchemeServiceImpl extends ServiceBaseImpl implements private ClassificationLevelManager levelManager; /** The classification reasons currently configured in this server. */ private ClassificationReasonManager reasonManager; + /** The exemption categories currently configured in this server. */ + private ExemptionCategoryManager exemptionCategoryManager; private SecurityClearanceService securityClearanceService; private ClassificationServiceBootstrap classificationServiceBootstrap; @@ -52,6 +54,7 @@ public class ClassificationSchemeServiceImpl extends ServiceBaseImpl implements { levelManager = classificationServiceBootstrap.getClassificationLevelManager(); reasonManager = classificationServiceBootstrap.getClassificationReasonManager(); + exemptionCategoryManager = classificationServiceBootstrap.getExemptionCategoryManager(); } /** @@ -112,4 +115,11 @@ public class ClassificationSchemeServiceImpl extends ServiceBaseImpl implements checkNotBlank("classificationReasonId", classificationReasonId); return reasonManager.findReasonById(classificationReasonId); } + + @Override + public List getExemptionCategories() + { + return (exemptionCategoryManager == null ? Collections.emptyList() : + Collections.unmodifiableList(exemptionCategoryManager.getExemptionCategories())); + } } diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/ExemptionCategoryManager.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/ExemptionCategoryManager.java index b0938da276..7ced27ee5b 100644 --- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/ExemptionCategoryManager.java +++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/ExemptionCategoryManager.java @@ -27,6 +27,7 @@ import org.alfresco.module.org_alfresco_module_rm.classification.ClassificationE * Container for the configured {@link ExemptionCategory} objects. * * @author tpage + * @since 3.0 */ public class ExemptionCategoryManager { diff --git a/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/integration/classification/ExemptionCategoriesTest.java b/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/integration/classification/ExemptionCategoriesTest.java new file mode 100644 index 0000000000..06c3e00b8e --- /dev/null +++ b/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/integration/classification/ExemptionCategoriesTest.java @@ -0,0 +1,79 @@ +/* + * 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.test.integration.classification; + +import java.util.List; + +import org.alfresco.module.org_alfresco_module_rm.classification.ClassificationServiceBootstrap; +import org.alfresco.module.org_alfresco_module_rm.classification.ExemptionCategory; +import org.alfresco.module.org_alfresco_module_rm.test.util.BaseRMTestCase; +import org.springframework.context.ApplicationEvent; + +/** + * Tests of exemption category loading. + * + * @author tpage + * @since 3.0 + */ +public class ExemptionCategoriesTest extends BaseRMTestCase +{ + /** + * Initial exemption category loading. + *

+ * RM-2321

+     * Given that I have a clean system
+     * When I boot it for the first time
+     * Then the default set of exemption categories are loaded
+     * And are available throughout the application
+     * 

+ * Note that this test requires a clean db, as otherwise the classification scheme service will use + * the persisted exemption categories in preference to those given on the classpath (see the logic in + * {@link ClassificationServiceBootstrap#onBootstrap(ApplicationEvent)}). + */ + public void testLoadBootstrappedExemptionCategories() throws Exception + { + doBehaviourDrivenTest(new BehaviourDrivenTest() + { + public void given() throws Exception + { + // NOOP: I have a clean system. + } + + public void when() throws Exception + { + // NOOP: I boot it for the first time. + } + + public void then() throws Exception + { + // Check the classification scheme service exposes the classification reasons. + List exemptionCategories = classificationSchemeService.getExemptionCategories(); + assertNotNull(exemptionCategories); + assertEquals("The default exemption categories in test/resources/alfresco/module/" + + "org_alfresco_module_rm/classification/rm-exemption-categories.json " + + "contains three categories.", 3, exemptionCategories.size()); + // Check a couple of fields in the loaded data. + assertEquals("Unexpected id for the first test category.", "Test Category 1", exemptionCategories.get(0).getId()); + assertEquals("Unexpected displayLabelKey for the third test category.", + "rm.test.exemption-category.three", exemptionCategories.get(2).getDisplayLabel()); + } + }); + } +} diff --git a/rm-server/test/resources/alfresco/module/org_alfresco_module_rm/classification/rm-exemption-categories.json b/rm-server/test/resources/alfresco/module/org_alfresco_module_rm/classification/rm-exemption-categories.json new file mode 100644 index 0000000000..3dc7c42239 --- /dev/null +++ b/rm-server/test/resources/alfresco/module/org_alfresco_module_rm/classification/rm-exemption-categories.json @@ -0,0 +1,10 @@ +[{ + "id" : "Test Category 1", + "displayLabel" : "rm.test.exemption-category.one" + },{ + "id" : "Test Category 2", + "displayLabel" : "rm.test.exemption-category.two" + },{ + "id" : "Test Category 3", + "displayLabel" : "rm.test.exemption-category.three" +}] \ No newline at end of file