diff --git a/rm-server/config/alfresco/module/org_alfresco_module_rm/rm-webscript-context.xml b/rm-server/config/alfresco/module/org_alfresco_module_rm/rm-webscript-context.xml index f85392271c..68e37b76c3 100644 --- a/rm-server/config/alfresco/module/org_alfresco_module_rm/rm-webscript-context.xml +++ b/rm-server/config/alfresco/module/org_alfresco_module_rm/rm-webscript-context.xml @@ -655,4 +655,11 @@ parent="rmBaseWebscript"> + + + + + \ No newline at end of file diff --git a/rm-server/config/alfresco/templates/webscripts/org/alfresco/rma/classification/classificationlevels.get.desc.xml b/rm-server/config/alfresco/templates/webscripts/org/alfresco/rma/classification/classificationlevels.get.desc.xml new file mode 100644 index 0000000000..a049a6ecbc --- /dev/null +++ b/rm-server/config/alfresco/templates/webscripts/org/alfresco/rma/classification/classificationlevels.get.desc.xml @@ -0,0 +1,8 @@ + + Records Management Classification Levels + Gets the list of classification levels. + /api/classification/levels + + user + required + \ No newline at end of file diff --git a/rm-server/config/alfresco/templates/webscripts/org/alfresco/rma/classification/classificationlevels.get.json.ftl b/rm-server/config/alfresco/templates/webscripts/org/alfresco/rma/classification/classificationlevels.get.json.ftl new file mode 100644 index 0000000000..fa6de09277 --- /dev/null +++ b/rm-server/config/alfresco/templates/webscripts/org/alfresco/rma/classification/classificationlevels.get.json.ftl @@ -0,0 +1,14 @@ +{ + "data": + { + "items": + [ + <#list levels as level> + { + "id": "${level.id?json_string}", + "displayLabel": "${level.displayLabel?json_string}" + }<#if level_has_next>, + + ] + } +} diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/ClassificationLevel.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/ClassificationLevel.java index 75ebcc4675..34e852cf88 100644 --- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/ClassificationLevel.java +++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/ClassificationLevel.java @@ -18,9 +18,12 @@ */ package org.alfresco.module.org_alfresco_module_rm.classification; +import static org.apache.commons.lang.StringUtils.isNotBlank; + import java.io.Serializable; import org.alfresco.module.org_alfresco_module_rm.util.RMParameterCheck; +import org.apache.commons.lang.StringUtils; import org.springframework.extensions.surf.util.I18NUtil; /** @@ -33,7 +36,7 @@ public final class ClassificationLevel implements Serializable { /** serial version uid */ private static final long serialVersionUID = -3375064867090476422L; - + private final String id; private final String displayLabelKey; @@ -49,7 +52,11 @@ public final class ClassificationLevel implements Serializable public String getId() { return this.id; } /** Returns the localised (current locale) display label for this classification level. */ - public String getDisplayLabel() { return I18NUtil.getMessage(displayLabelKey); } + public String getDisplayLabel() + { + String message = I18NUtil.getMessage(displayLabelKey); + return (isNotBlank(message) ? message : displayLabelKey); + } @Override public String toString() { diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/classification/ClassificationLevelsGet.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/classification/ClassificationLevelsGet.java new file mode 100644 index 0000000000..12c3fd3743 --- /dev/null +++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/classification/ClassificationLevelsGet.java @@ -0,0 +1,66 @@ +/* + * 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; + +import java.util.HashMap; +import java.util.Map; + +import org.alfresco.module.org_alfresco_module_rm.classification.ClassificationService; +import org.alfresco.module.org_alfresco_module_rm.script.AbstractRmWebScript; +import org.springframework.extensions.webscripts.Cache; +import org.springframework.extensions.webscripts.Status; +import org.springframework.extensions.webscripts.WebScriptRequest; + +/** + * Implementation for Java backed webscript to get the classification levels. + * + * @author Tuna Aksoy + * @since 3.0 + */ +public class ClassificationLevelsGet extends AbstractRmWebScript +{ + /** Constants */ + private static final String LEVELS = "levels"; + + /** Classification service */ + private ClassificationService classificationService; + + /** + * Sets the classification service + * + * @param classificatonService The classification service + */ + public void setClassificationService(ClassificationService classificationService) + { + this.classificationService = classificationService; + } + + /** + * @see org.springframework.extensions.webscripts.DeclarativeWebScript#executeImpl(org.springframework.extensions.webscripts.WebScriptRequest, + * org.springframework.extensions.webscripts.Status, + * org.springframework.extensions.webscripts.Cache) + */ + @Override + protected Map executeImpl(WebScriptRequest req, Status status, Cache cache) + { + Map result = new HashMap(); + result.put(LEVELS, classificationService.getClassificationLevels()); + return result; + } +} diff --git a/rm-server/unit-test/java/org/alfresco/module/org_alfresco_module_rm/script/classification/ClassificationLevelsGetTest.java b/rm-server/unit-test/java/org/alfresco/module/org_alfresco_module_rm/script/classification/ClassificationLevelsGetTest.java new file mode 100644 index 0000000000..b9b66ec498 --- /dev/null +++ b/rm-server/unit-test/java/org/alfresco/module/org_alfresco_module_rm/script/classification/ClassificationLevelsGetTest.java @@ -0,0 +1,99 @@ +/* + * 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.script.classification; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.mockito.Mockito.doReturn; + +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; + +import org.alfresco.module.org_alfresco_module_rm.classification.ClassificationLevel; +import org.alfresco.module.org_alfresco_module_rm.classification.ClassificationService; +import org.alfresco.module.org_alfresco_module_rm.test.util.BaseWebScriptUnitTest; +import org.json.JSONObject; +import org.junit.Test; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Spy; +import org.springframework.extensions.webscripts.DeclarativeWebScript; + +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; + +/** + * Tests for the get classification levels API. + * + * @author Tuna Aksoy + * @since 3.0 + */ +public class ClassificationLevelsGetTest extends BaseWebScriptUnitTest +{ + /** Classpath location of ftl template for web script */ + private static final String WEBSCRIPT_TEMPLATE = WEBSCRIPT_ROOT_RM + "classification/classificationlevels.get.json.ftl"; + + /** ClassificationLevelsGet webscript instance */ + private @Spy @InjectMocks ClassificationLevelsGet webScript; + private @Mock ClassificationService mockClassificationService; + + private List classificationLevels; + + /** {@inheritDoc} */ + @Override + protected DeclarativeWebScript getWebScript() + { + return webScript; + } + + /** {@inheritDoc} */ + @Override + protected String getWebScriptTemplate() + { + return WEBSCRIPT_TEMPLATE; + } + + /** + * Test the successful retrieval of two classification levels. + */ + @Test + public void getClassificationLevels() throws Exception + { + // Create test data. + classificationLevels = Arrays.asList( + new ClassificationLevel("id1", "labelKey1"), + new ClassificationLevel("id2", "labelKey2")); + + // setup interactions + doReturn(classificationLevels).when(mockClassificationService).getClassificationLevels(); + + // execute web script + JSONObject json = executeJSONWebScript(new HashMap()); + assertNotNull(json); + String actualJSONString = json.toString(); + + // check the JSON result using Jackson to allow easy equality testing. + ObjectMapper mapper = new ObjectMapper(); + String expectedJSONString = "{\"data\":{\"items\":[{\"displayLabel\":\"labelKey1\",\"id\":\"id1\"},{\"displayLabel\":\"labelKey2\",\"id\":\"id2\"}]}}"; + JsonNode expected = mapper.readTree(expectedJSONString); + assertEquals(expected, mapper.readTree(actualJSONString)); + } +} diff --git a/rm-server/unit-test/java/org/alfresco/module/org_alfresco_module_rm/test/AllUnitTestSuite.java b/rm-server/unit-test/java/org/alfresco/module/org_alfresco_module_rm/test/AllUnitTestSuite.java index 7e32bf93f5..7cdada2dba 100644 --- a/rm-server/unit-test/java/org/alfresco/module/org_alfresco_module_rm/test/AllUnitTestSuite.java +++ b/rm-server/unit-test/java/org/alfresco/module/org_alfresco_module_rm/test/AllUnitTestSuite.java @@ -38,6 +38,7 @@ import org.alfresco.module.org_alfresco_module_rm.record.RecordMetadataBootstrap import org.alfresco.module.org_alfresco_module_rm.record.RecordServiceImplUnitTest; import org.alfresco.module.org_alfresco_module_rm.recorded.version.config.RecordedVersionConfigGetTest; import org.alfresco.module.org_alfresco_module_rm.recorded.version.config.RecordedVersionConfigPostTest; +import org.alfresco.module.org_alfresco_module_rm.script.classification.ClassificationLevelsGetTest; import org.alfresco.module.org_alfresco_module_rm.script.classification.ReasonsGetTest; import org.alfresco.module.org_alfresco_module_rm.script.hold.HoldPostUnitTest; import org.alfresco.module.org_alfresco_module_rm.script.hold.HoldPutUnitTest; @@ -74,7 +75,7 @@ import org.junit.runners.Suite.SuiteClasses; // evaluators TransferEvaluatorUnitTest.class, FrozenEvaluatorUnitTest.class, - + // capabilities EditNonRecordsMetadataCapabilityUnitTest.class, @@ -83,12 +84,13 @@ import org.junit.runners.Suite.SuiteClasses; HoldPostUnitTest.class, HoldPutUnitTest.class, ReasonsGetTest.class, + ClassificationLevelsGetTest.class, // action implementations FileReportActionUnitTest.class, UnlinkFromActionUnitTest.class, DeclareAsVersionRecordActionUnitTest.class, - + // recorded version config RecordedVersionConfigGetTest.class, RecordedVersionConfigPostTest.class,