Story: RM-1206 (As a records user I want to be able to add records to a hold(s) I have permission to see so that I can freeze a record)

Sub-tasl: RM-1327 (Implement REST API for adding a record to the hold(s))

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/modules/recordsmanagement/HEAD@63794 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Tuna Aksoy
2014-03-08 21:42:40 +00:00
parent 3d74303155
commit 67cf34c213
6 changed files with 153 additions and 6 deletions

View File

@@ -103,7 +103,7 @@
<type name="rma:holdContainer">
<title>Hold Container</title>
<parent>rma:recordsManagementContainer</parent>
<parent>rma:hold</parent>
<mandatory-aspects>
<aspect>rma:countable</aspect>
</mandatory-aspects>
@@ -111,7 +111,7 @@
<type name="rma:holdContainerChild">
<title>Hold Container Child</title>
<parent>rma:recordsManagementContainer</parent>
<parent>rma:hold</parent>
</type>
<type name="rma:transferContainer">

View File

@@ -592,4 +592,11 @@
<property name="nodeService" ref="NodeService" />
<property name="holdService" ref="HoldService" />
</bean>
<!-- REST impl for POST Hold -->
<bean id="webscript.org.alfresco.rma.hold.post"
class="org.alfresco.module.org_alfresco_module_rm.script.hold.HoldPost"
parent="webscript">
<property name="holdService" ref="HoldService" />
</bean>
</beans>

View File

@@ -0,0 +1,17 @@
<webscript>
<shortname>Adds an item to the hold(s)</shortname>
<description><![CDATA[
WebScript to add an item (record / record folder) to the hold(s) in the holds container.<br/>
The body of the post should be in the form<br/>
{<br/>
&nbsp;&nbsp;&nbsp;"nodeRef" : nodeRef of the item (record / record folder),<br/>
&nbsp;&nbsp;&nbsp;"holds" : array of nodeRef for the hold(s)<br/>
}<br/>
]]>
</description>
<url>/api/rma/holds</url>
<format default="json">argument</format>
<authentication>user</authentication>
<transaction>required</transaction>
<lifecycle>internal</lifecycle>
</webscript>

View File

@@ -214,10 +214,6 @@ public class FilePlanServiceImpl extends ServiceBaseImpl
{
result = FilePlanComponentKind.RECORD;
}
else if (getFreezeService().isHold(nodeRef) == true)
{
result = FilePlanComponentKind.HOLD;
}
else if (instanceOf(nodeRef, TYPE_HOLD_CONTAINER))
{
result = FilePlanComponentKind.HOLD_CONTAINER;
@@ -226,6 +222,10 @@ public class FilePlanServiceImpl extends ServiceBaseImpl
{
result = FilePlanComponentKind.HOLD_CONTAINER_CHILD;
}
else if (getFreezeService().isHold(nodeRef) == true)
{
result = FilePlanComponentKind.HOLD;
}
else if (getTransferService().isTransfer(nodeRef) == true)
{
result = FilePlanComponentKind.TRANSFER;

View File

@@ -0,0 +1,122 @@
/*
* 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.hold;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.alfresco.module.org_alfresco_module_rm.fileplan.hold.HoldService;
import org.alfresco.service.cmr.repository.NodeRef;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.json.JSONTokener;
import org.springframework.extensions.webscripts.Cache;
import org.springframework.extensions.webscripts.DeclarativeWebScript;
import org.springframework.extensions.webscripts.Status;
import org.springframework.extensions.webscripts.WebScriptException;
import org.springframework.extensions.webscripts.WebScriptRequest;
/**
* Implementation for Java backed webscript to add an item to the given hold in the hold container.
*
* @author Tuna Aksoy
* @since 2.2
*/
public class HoldPost extends DeclarativeWebScript
{
/** Hold Service */
private HoldService holdService;
/**
* Set the hold service
*
* @param holdService the hold service
*/
public void setHoldService(HoldService holdService)
{
this.holdService = holdService;
}
/**
* @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)
{
NodeRef nodeRef = null;
List<NodeRef> holds = new ArrayList<NodeRef>();
try
{
String content = req.getContent().getContent();
JSONObject json = new JSONObject(new JSONTokener(content));
nodeRef = getItemNodeRef(json);
holds.addAll(getHolds(json));
}
catch (IOException iox)
{
throw new WebScriptException(Status.STATUS_BAD_REQUEST,
"Could not read content from req.", iox);
}
catch (JSONException je)
{
throw new WebScriptException(Status.STATUS_BAD_REQUEST,
"Could not parse JSON from req.", je);
}
holdService.addToHoldContainers(holds, nodeRef);
return new HashMap<String, Object>();
}
/**
* Helper method to get the {@link NodeRef} for the item (record / record folder) which will be added to the hold(s)
*
* @param json The request content as JSON object
* @return The {@link NodeRef} of the item which will be added to the hold(s)
* @throws JSONException If there is no string value for the key
*/
private NodeRef getItemNodeRef(JSONObject json) throws JSONException
{
String nodeRef = json.getString("nodeRef");
return new NodeRef(nodeRef);
}
/**
* Helper method to get the list of {@link NodeRef}(s) for the hold(s) which will contain the item (record / record folder)
*
* @param json The request content as JSON object
* @return List of {@link NodeRef}(s) of the hold(s)
* @throws JSONException If there is no string value for the key
*/
private List<NodeRef> getHolds(JSONObject json) throws JSONException
{
JSONArray holdsArray = json.getJSONArray("holds");
List<NodeRef> holds = new ArrayList<NodeRef>();
for (int i = 0; i < holdsArray.length(); i++)
{
String nodeRef = holdsArray.getString(i);
holds.add(new NodeRef(nodeRef));
}
return holds;
}
}