mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
RM-2326 Rest API for GET exemption categories.
+review RM git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/modules/recordsmanagement/HEAD@106576 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -690,4 +690,11 @@
|
|||||||
parent="rmBaseWebscript">
|
parent="rmBaseWebscript">
|
||||||
<property name="securityClearanceService" ref="SecurityClearanceService"/>
|
<property name="securityClearanceService" ref="SecurityClearanceService"/>
|
||||||
</bean>
|
</bean>
|
||||||
|
|
||||||
|
<!-- REST impl for GET exemption categories -->
|
||||||
|
<bean id="webscript.org.alfresco.rma.classification.exemptioncategories.get"
|
||||||
|
class="org.alfresco.module.org_alfresco_module_rm.script.classification.ExemptionCategoriesGet"
|
||||||
|
parent="rmBaseWebscript">
|
||||||
|
<property name="classificationSchemeService" ref="ClassificationSchemeService" />
|
||||||
|
</bean>
|
||||||
</beans>
|
</beans>
|
@@ -0,0 +1,8 @@
|
|||||||
|
<webscript>
|
||||||
|
<shortname>Records Management Exemption Categories</shortname>
|
||||||
|
<description>Gets the list of exemption categories.</description>
|
||||||
|
<url>/api/classification/exemptioncategories</url>
|
||||||
|
<format default="json"/>
|
||||||
|
<authentication>user</authentication>
|
||||||
|
<transaction allow="readonly">required</transaction>
|
||||||
|
</webscript>
|
@@ -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>,</#if>
|
||||||
|
</#list>
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
@@ -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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
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<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache)
|
||||||
|
{
|
||||||
|
Map<String, Object> result = new HashMap<String, Object>();
|
||||||
|
result.put(EXEMPTION_CATEGORIES, classificationSchemeService.getExemptionCategories());
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
@@ -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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
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<ExemptionCategory> exemptionCategories = Arrays.asList(exemptionCategoryA, exemptionCategoryB);
|
||||||
|
|
||||||
|
// setup interactions
|
||||||
|
doReturn(exemptionCategories).when(mockClassificationSchemeService).getExemptionCategories();
|
||||||
|
|
||||||
|
// setup web script parameters
|
||||||
|
Map<String, String> parameters = new HashMap<String, String>();
|
||||||
|
|
||||||
|
// 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));
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user