RM-2028 Create a rest API to get classification reasons.

The API can be accessed through the following URI:
http://localhost:8080/alfresco/service/api/classification/reasons

Note that the private classificationService bean is currently being used
as there is an issue with the authentication when using the public bean.

Log error message contains:
Caused by: net.sf.acegisecurity.AccessDeniedException: Access is denied.
RM method security check was performed.
Failed on method:  getClassificationReasons()
; nested exception is net.sf.acegisecurity.AccessDeniedException: Access is denied.
	at org.alfresco.module.org_alfresco_module_rm.security.RMMethodSecurityInterceptor.beforeInvocation(RMMethodSecurityInterceptor.java:299)

+review RM @taksoy

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/modules/recordsmanagement/HEAD@101042 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Tom Page
2015-04-01 12:27:01 +00:00
parent 58cbb31951
commit 10e3036d05
6 changed files with 127 additions and 3 deletions

View File

@@ -9,6 +9,6 @@
},
{
"id" : "1.4(c)",
"displayLabel" : "rm.classification.intelligenceActivities"
"displayLabel" : "rm.classification-reason.intelligenceActivities"
}
]

View File

@@ -648,4 +648,11 @@
parent="rmBaseWebscript">
<property name="relationshipService" ref="RelationshipService" />
</bean>
<!-- REST impl for GET classied reasons -->
<bean id="webscript.org.alfresco.rma.classification.reasons.get"
class="org.alfresco.module.org_alfresco_module_rm.script.classification.ReasonsGet"
parent="rmBaseWebscript">
<property name="classificationService" ref="classificationService" /> <!-- TODO Change to "C" -->
</bean>
</beans>

View File

@@ -0,0 +1,8 @@
<webscript>
<shortname>Records Management Classification Reasons</shortname>
<description>Gets the list of classification reasons.</description>
<url>/api/classification/reasons</url>
<format default="json"/>
<authentication>user</authentication>
<transaction allow="readonly">required</transaction>
</webscript>

View File

@@ -0,0 +1,16 @@
<#escape x as jsonUtils.encodeJSONString(x)>
{
"data":
{
"items":
[
<#list reasons as reason>
{
"id": "<#noescape>${reason.id}</#noescape>",
"displayLabel": "<#noescape>${reason.displayLabel}</#noescape>"
}<#if reason_has_next>,</#if>
</#list>
]
}
}
</#escape>

View File

@@ -44,6 +44,7 @@ public final class ClassificationReason implements Serializable
public ClassificationReason(final String id, final String displayLabelKey)
{
if (id == null || id.trim().equals("")) { throw new IllegalArgumentException("Illegal id: '" + id + "'"); }
if (displayLabelKey == null || displayLabelKey.trim().equals("")) { throw new IllegalArgumentException("Illegal displayLabelKey: '" + displayLabelKey + "'"); }
this.id = id;
this.displayLabelKey = displayLabelKey;
}
@@ -57,11 +58,13 @@ public final class ClassificationReason implements Serializable
}
/**
* Returns the localised (current locale) display label for this classification reason.
* Returns the localised (current locale) display label for this classification reason. If no translation is found
* then return the key instead.
*/
public String getDisplayLabel()
{
return I18NUtil.getMessage(displayLabelKey);
String message = I18NUtil.getMessage(displayLabelKey);
return (message != null ? message : displayLabelKey);
}
@Override

View File

@@ -0,0 +1,90 @@
/*
* 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.jscript.app.JSONConversionComponent;
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 reasons.
*
* @author tpage
* @since 3.0
*/
public class ReasonsGet extends AbstractRmWebScript
{
/** Constants */
private static final String REASONS = "reasons";
/** Classification service */
private ClassificationService classificationService;
/** JSON conversion component */
private JSONConversionComponent jsonConversionComponent;
/**
* Gets the JSON conversion component
*
* @return The JSON conversion component
*/
protected JSONConversionComponent getJsonConversionComponent()
{
return this.jsonConversionComponent;
}
/**
* Sets the classification service
*
* @param classificatonService The classification service
*/
public void setClassificationService(ClassificationService classificationService)
{
this.classificationService = classificationService;
}
/**
* Sets the JSON conversion component
*
* @param jsonConversionComponent The JSON conversion component
*/
public void setJsonConversionComponent(JSONConversionComponent jsonConversionComponent)
{
this.jsonConversionComponent = jsonConversionComponent;
}
/**
* @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(REASONS, classificationService.getClassificationReasons());
return result;
}
}