mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-31 17:39:05 +00:00
RM-1842 (View users security clearance)
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/modules/recordsmanagement/HEAD@101590 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -655,4 +655,11 @@
|
||||
parent="rmBaseWebscript">
|
||||
<property name="classificationService" ref="ClassificationService" />
|
||||
</bean>
|
||||
|
||||
<!-- REST impl for GET classification levels -->
|
||||
<bean id="webscript.org.alfresco.rma.classification.classificationlevels.get"
|
||||
class="org.alfresco.module.org_alfresco_module_rm.script.classification.ClassificationLevelsGet"
|
||||
parent="rmBaseWebscript">
|
||||
<property name="classificationService" ref="ClassificationService" />
|
||||
</bean>
|
||||
</beans>
|
@@ -0,0 +1,8 @@
|
||||
<webscript>
|
||||
<shortname>Records Management Classification Levels</shortname>
|
||||
<description>Gets the list of classification levels.</description>
|
||||
<url>/api/classification/levels</url>
|
||||
<format default="json"/>
|
||||
<authentication>user</authentication>
|
||||
<transaction allow="readonly">required</transaction>
|
||||
</webscript>
|
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"data":
|
||||
{
|
||||
"items":
|
||||
[
|
||||
<#list levels as level>
|
||||
{
|
||||
"id": "${level.id?json_string}",
|
||||
"displayLabel": "${level.displayLabel?json_string}"
|
||||
}<#if level_has_next>,</#if>
|
||||
</#list>
|
||||
]
|
||||
}
|
||||
}
|
@@ -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()
|
||||
{
|
||||
|
@@ -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 <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.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<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache)
|
||||
{
|
||||
Map<String, Object> result = new HashMap<String, Object>();
|
||||
result.put(LEVELS, classificationService.getClassificationLevels());
|
||||
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 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<ClassificationLevel> 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<String, String>());
|
||||
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));
|
||||
}
|
||||
}
|
@@ -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,
|
||||
|
Reference in New Issue
Block a user