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 97c275ffd0..e23278fd75 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 @@ -690,4 +690,11 @@ parent="rmBaseWebscript"> + + + + + \ No newline at end of file diff --git a/rm-server/config/alfresco/templates/webscripts/org/alfresco/rma/classification/exemptioncategories.get.desc.xml b/rm-server/config/alfresco/templates/webscripts/org/alfresco/rma/classification/exemptioncategories.get.desc.xml new file mode 100644 index 0000000000..18a9683922 --- /dev/null +++ b/rm-server/config/alfresco/templates/webscripts/org/alfresco/rma/classification/exemptioncategories.get.desc.xml @@ -0,0 +1,8 @@ + + Records Management Exemption Categories + Gets the list of exemption categories. + /api/classification/exemptioncategories + + user + required + \ No newline at end of file diff --git a/rm-server/config/alfresco/templates/webscripts/org/alfresco/rma/classification/exemptioncategories.get.json.ftl b/rm-server/config/alfresco/templates/webscripts/org/alfresco/rma/classification/exemptioncategories.get.json.ftl new file mode 100644 index 0000000000..9d55e2cfed --- /dev/null +++ b/rm-server/config/alfresco/templates/webscripts/org/alfresco/rma/classification/exemptioncategories.get.json.ftl @@ -0,0 +1,15 @@ +{ + "data": + { + "items": + [ + <#list exemptionCategories as exemptionCategory> + { + "id": "${exemptionCategory.id?json_string}", + "displayLabel": "${exemptionCategory.displayLabel?json_string}", + "fullCategory": "${exemptionCategory.id?json_string}: ${exemptionCategory.displayLabel?json_string}" + }<#if exemptionCategory_has_next>, + + ] + } +} diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/classification/ExemptionCategoriesGet.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/classification/ExemptionCategoriesGet.java new file mode 100644 index 0000000000..a5965adbe7 --- /dev/null +++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/classification/ExemptionCategoriesGet.java @@ -0,0 +1,61 @@ +/* + * 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 java.util.HashMap; +import java.util.Map; + +import org.alfresco.module.org_alfresco_module_rm.classification.ClassificationSchemeService; +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 exemption categories. + * + * @author tpage + * @since 3.0 + */ +public class ExemptionCategoriesGet extends AbstractRmWebScript +{ + /** The exemption category key for the map. */ + private static final String EXEMPTION_CATEGORIES = "exemptionCategories"; + + /** The classification scheme service. */ + private ClassificationSchemeService classificationSchemeService; + + /** + * Sets the classification scheme service. + * + * @param classificationSchemeService The classification scheme service. + */ + public void setClassificationSchemeService(ClassificationSchemeService classificationSchemeService) + { + this.classificationSchemeService = classificationSchemeService; + } + + @Override + protected Map executeImpl(WebScriptRequest req, Status status, Cache cache) + { + Map result = new HashMap(); + result.put(EXEMPTION_CATEGORIES, classificationSchemeService.getExemptionCategories()); + return result; + } +} diff --git a/rm-server/unit-test/java/org/alfresco/module/org_alfresco_module_rm/script/classification/ExemptionCategoriesGetUnitTest.java b/rm-server/unit-test/java/org/alfresco/module/org_alfresco_module_rm/script/classification/ExemptionCategoriesGetUnitTest.java new file mode 100644 index 0000000000..137f0c3b04 --- /dev/null +++ b/rm-server/unit-test/java/org/alfresco/module/org_alfresco_module_rm/script/classification/ExemptionCategoriesGetUnitTest.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 java.util.Map; + +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import org.alfresco.module.org_alfresco_module_rm.classification.ClassificationSchemeService; +import org.alfresco.module.org_alfresco_module_rm.classification.ExemptionCategory; +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; + +/** + * Tests for the get exemption categories API. + * + * @author tpage + */ +public class ExemptionCategoriesGetUnitTest extends BaseWebScriptUnitTest +{ + /** Classpath location of ftl template for web script */ + private static final String WEBSCRIPT_TEMPLATE = WEBSCRIPT_ROOT_RM + "classification/exemptioncategories.get.json.ftl"; + + /** Webscript instance */ + private @Spy @InjectMocks ExemptionCategoriesGet webScript; + private @Mock ClassificationSchemeService mockClassificationSchemeService; + + /** {@inheritDoc} */ + @Override + protected DeclarativeWebScript getWebScript() + { + return webScript; + } + + /** {@inheritDoc} */ + @Override + protected String getWebScriptTemplate() + { + return WEBSCRIPT_TEMPLATE; + } + + /** + * Test the successful retrieval of two exemption categories. + */ + @Test + public void getExemptionCategories() throws Exception + { + // Create test data. + ExemptionCategory exemptionCategoryA = new ExemptionCategory("idA", "labelA"); + ExemptionCategory exemptionCategoryB = new ExemptionCategory("idB", "labelB"); + List exemptionCategories = Arrays.asList(exemptionCategoryA, exemptionCategoryB); + + // setup interactions + doReturn(exemptionCategories).when(mockClassificationSchemeService).getExemptionCategories(); + + // setup web script parameters + Map parameters = new HashMap(); + + // execute web script + JSONObject json = executeJSONWebScript(parameters); + 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\":\"labelA\",\"id\":\"idA\",\"fullCategory\":\"idA: labelA\"},{\"displayLabel\":\"labelB\",\"id\":\"idB\",\"fullCategory\":\"idB: labelB\"}]}}"; + JsonNode expected = mapper.readTree(expectedJSONString); + assertEquals(expected, mapper.readTree(actualJSONString)); + } +}