mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-31 17:39:05 +00:00
Story: RM-1207 (As a records user I want to remove records from a hold(s) that I have permission to see so that I can unfreeze a record)
Sub-task: RM-1332 (Implement REST API for removing an item from hold(s)) git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/modules/recordsmanagement/HEAD@63860 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -593,10 +593,18 @@
|
|||||||
<property name="holdService" ref="HoldService" />
|
<property name="holdService" ref="HoldService" />
|
||||||
</bean>
|
</bean>
|
||||||
|
|
||||||
|
<!-- Abstract parent bean for many POST and PUT Hold beans -->
|
||||||
|
<bean id="rmBaseHold" parent="webscript" abstract="true">
|
||||||
|
<property name="holdService" ref="HoldService" />
|
||||||
|
</bean>
|
||||||
|
|
||||||
<!-- REST impl for POST Hold -->
|
<!-- REST impl for POST Hold -->
|
||||||
<bean id="webscript.org.alfresco.rma.hold.post"
|
<bean id="webscript.org.alfresco.rma.hold.post"
|
||||||
class="org.alfresco.module.org_alfresco_module_rm.script.hold.HoldPost"
|
class="org.alfresco.module.org_alfresco_module_rm.script.hold.HoldPost"
|
||||||
parent="webscript">
|
parent="rmBaseHold" />
|
||||||
<property name="holdService" ref="HoldService" />
|
|
||||||
</bean>
|
<!-- REST impl for PUT Hold -->
|
||||||
|
<bean id="webscript.org.alfresco.rma.hold.put"
|
||||||
|
class="org.alfresco.module.org_alfresco_module_rm.script.hold.HoldPut"
|
||||||
|
parent="rmBaseHold" />
|
||||||
</beans>
|
</beans>
|
@@ -0,0 +1,17 @@
|
|||||||
|
<webscript>
|
||||||
|
<shortname>Removes an item from the hold(s)</shortname>
|
||||||
|
<description><![CDATA[
|
||||||
|
WebScript to remove an item (record / record folder) from the hold(s) in the holds container.<br/>
|
||||||
|
The body of the put should be in the form<br/>
|
||||||
|
{<br/>
|
||||||
|
"nodeRef" : nodeRef of the item (record / record folder),<br/>
|
||||||
|
"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>
|
@@ -0,0 +1 @@
|
|||||||
|
{}
|
@@ -1,6 +1,12 @@
|
|||||||
<webscript>
|
<webscript>
|
||||||
<shortname>Get the list of holds</shortname>
|
<shortname>Gets the list of the hold(s)</shortname>
|
||||||
<description>WebScript to get the list of available holds in the holds container</description>
|
<description><![CDATA[
|
||||||
|
WebScript to get the list of the available holds in the holds container.
|
||||||
|
If an item node reference has been specified only those holds will be
|
||||||
|
retrieved which have the item node references, otherwise all hold node
|
||||||
|
references will be retrieved.
|
||||||
|
]]>
|
||||||
|
</description>
|
||||||
<url>/api/rma/{store_type}/{store_id}/{id}/holds?itemNodeRef={itemNodeRef?}</url>
|
<url>/api/rma/{store_type}/{store_id}/{id}/holds?itemNodeRef={itemNodeRef?}</url>
|
||||||
<url>/api/rma/holds?itemNodeRef={itemNodeRef?}</url>
|
<url>/api/rma/holds?itemNodeRef={itemNodeRef?}</url>
|
||||||
<format default="json">argument</format>
|
<format default="json">argument</format>
|
||||||
|
@@ -0,0 +1,166 @@
|
|||||||
|
/*
|
||||||
|
* 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;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Base class for the hold webscripts
|
||||||
|
*
|
||||||
|
* @author Tuna Aksoy
|
||||||
|
* @since 2.2
|
||||||
|
*/
|
||||||
|
public abstract class BaseHold extends DeclarativeWebScript
|
||||||
|
{
|
||||||
|
/** Hold Service */
|
||||||
|
private HoldService holdService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the hold service
|
||||||
|
*
|
||||||
|
* @param holdService the hold service
|
||||||
|
*/
|
||||||
|
public void setHoldService(HoldService holdService)
|
||||||
|
{
|
||||||
|
this.holdService = holdService;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the hold service
|
||||||
|
*
|
||||||
|
* @return Returns the hold service
|
||||||
|
*/
|
||||||
|
protected HoldService getHoldService()
|
||||||
|
{
|
||||||
|
return this.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)
|
||||||
|
{
|
||||||
|
JSONObject json = getJSONFromContent(req);
|
||||||
|
List<NodeRef> holds = getHolds(json);
|
||||||
|
NodeRef nodeRef = getItemNodeRef(json);
|
||||||
|
doAction(holds, nodeRef);
|
||||||
|
return new HashMap<String, Object>();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Abstract method which will be implemented in the subclasses.
|
||||||
|
* It will either add the item to the hold(s) or remove it from the hold(s)
|
||||||
|
*
|
||||||
|
* @param holds List of hold {@link NodeRef}(s)
|
||||||
|
* @param nodeRef {@link NodeRef} of an item (record / record folder) which will be either added to the hold(s) or removed from the hol(s)
|
||||||
|
*/
|
||||||
|
abstract void doAction(List<NodeRef> holds, NodeRef nodeRef);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper method the get the json object from the request
|
||||||
|
*
|
||||||
|
* @param req The webscript request
|
||||||
|
* @return The json object which was sent in the request body
|
||||||
|
*/
|
||||||
|
protected JSONObject getJSONFromContent(WebScriptRequest req)
|
||||||
|
{
|
||||||
|
JSONObject json = null;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
String content = req.getContent().getContent();
|
||||||
|
json = new JSONObject(new JSONTokener(content));
|
||||||
|
}
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
return json;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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)
|
||||||
|
*/
|
||||||
|
protected NodeRef getItemNodeRef(JSONObject json)
|
||||||
|
{
|
||||||
|
String nodeRef = null;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
nodeRef = json.getString("nodeRef");
|
||||||
|
}
|
||||||
|
catch (JSONException je)
|
||||||
|
{
|
||||||
|
throw new WebScriptException(Status.STATUS_BAD_REQUEST,
|
||||||
|
"Could not get the nodeRef from the json object.", je);
|
||||||
|
}
|
||||||
|
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)
|
||||||
|
*/
|
||||||
|
protected List<NodeRef> getHolds(JSONObject json)
|
||||||
|
{
|
||||||
|
List<NodeRef> holds = new ArrayList<NodeRef>();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
JSONArray holdsArray = json.getJSONArray("holds");
|
||||||
|
for (int i = 0; i < holdsArray.length(); i++)
|
||||||
|
{
|
||||||
|
String nodeRef = holdsArray.getString(i);
|
||||||
|
holds.add(new NodeRef(nodeRef));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (JSONException je)
|
||||||
|
{
|
||||||
|
throw new WebScriptException(Status.STATUS_BAD_REQUEST,
|
||||||
|
"Could not get information from json array.", je);
|
||||||
|
}
|
||||||
|
return holds;
|
||||||
|
}
|
||||||
|
}
|
@@ -18,105 +18,24 @@
|
|||||||
*/
|
*/
|
||||||
package org.alfresco.module.org_alfresco_module_rm.script.hold;
|
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.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.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.
|
* Implementation for Java backed webscript to add an item to the given hold(s) in the hold container.
|
||||||
*
|
*
|
||||||
* @author Tuna Aksoy
|
* @author Tuna Aksoy
|
||||||
* @since 2.2
|
* @since 2.2
|
||||||
*/
|
*/
|
||||||
public class HoldPost extends DeclarativeWebScript
|
public class HoldPost extends BaseHold
|
||||||
{
|
{
|
||||||
/** Hold Service */
|
|
||||||
private HoldService holdService;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the hold service
|
* @see org.alfresco.module.org_alfresco_module_rm.script.hold.BaseHold#doAction(java.util.List, org.alfresco.service.cmr.repository.NodeRef)
|
||||||
*
|
|
||||||
* @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
|
@Override
|
||||||
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache)
|
void doAction(List<NodeRef> holds, NodeRef nodeRef)
|
||||||
{
|
{
|
||||||
NodeRef nodeRef = null;
|
getHoldService().addToHoldContainers(holds, nodeRef);
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -0,0 +1,41 @@
|
|||||||
|
/*
|
||||||
|
* 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.util.List;
|
||||||
|
|
||||||
|
import org.alfresco.service.cmr.repository.NodeRef;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Implementation for Java backed webscript to remove an item from the given hold(s) in the hold container.
|
||||||
|
*
|
||||||
|
* @author Tuna Aksoy
|
||||||
|
* @since 2.2
|
||||||
|
*/
|
||||||
|
public class HoldPut extends BaseHold
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @see org.alfresco.module.org_alfresco_module_rm.script.hold.BaseHold#doAction(java.util.List, org.alfresco.service.cmr.repository.NodeRef)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
void doAction(List<NodeRef> holds, NodeRef nodeRef)
|
||||||
|
{
|
||||||
|
getHoldService().removeFromHoldContainers(holds, nodeRef);
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user