diff --git a/rm-server/config/alfresco/module/org_alfresco_module_rm/rm-webscript-context.xml b/rm-server/config/alfresco/module/org_alfresco_module_rm/rm-webscript-context.xml
index a7f7d52564..344dd7f7d9 100644
--- a/rm-server/config/alfresco/module/org_alfresco_module_rm/rm-webscript-context.xml
+++ b/rm-server/config/alfresco/module/org_alfresco_module_rm/rm-webscript-context.xml
@@ -593,10 +593,18 @@
+
+
+
+
+
-
-
+ parent="rmBaseHold" />
+
+
+
\ No newline at end of file
diff --git a/rm-server/config/alfresco/templates/webscripts/org/alfresco/rma/hold.put.desc.xml b/rm-server/config/alfresco/templates/webscripts/org/alfresco/rma/hold.put.desc.xml
new file mode 100644
index 0000000000..f035d72e3b
--- /dev/null
+++ b/rm-server/config/alfresco/templates/webscripts/org/alfresco/rma/hold.put.desc.xml
@@ -0,0 +1,17 @@
+
+ Removes an item from the hold(s)
+
+ The body of the put should be in the form
+ {
+ "nodeRef" : nodeRef of the item (record / record folder),
+ "holds" : array of nodeRef for the hold(s)
+ }
+ ]]>
+
+ /api/rma/holds
+ argument
+ user
+ required
+ internal
+
\ No newline at end of file
diff --git a/rm-server/config/alfresco/templates/webscripts/org/alfresco/rma/hold.put.json.ftl b/rm-server/config/alfresco/templates/webscripts/org/alfresco/rma/hold.put.json.ftl
new file mode 100644
index 0000000000..9e26dfeeb6
--- /dev/null
+++ b/rm-server/config/alfresco/templates/webscripts/org/alfresco/rma/hold.put.json.ftl
@@ -0,0 +1 @@
+{}
\ No newline at end of file
diff --git a/rm-server/config/alfresco/templates/webscripts/org/alfresco/rma/holds.get.desc.xml b/rm-server/config/alfresco/templates/webscripts/org/alfresco/rma/holds.get.desc.xml
index f1dacc6da2..14a2876bb8 100644
--- a/rm-server/config/alfresco/templates/webscripts/org/alfresco/rma/holds.get.desc.xml
+++ b/rm-server/config/alfresco/templates/webscripts/org/alfresco/rma/holds.get.desc.xml
@@ -1,6 +1,12 @@
- Get the list of holds
- WebScript to get the list of available holds in the holds container
+ Gets the list of the hold(s)
+
+
/api/rma/{store_type}/{store_id}/{id}/holds?itemNodeRef={itemNodeRef?}
/api/rma/holds?itemNodeRef={itemNodeRef?}
argument
diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/hold/BaseHold.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/hold/BaseHold.java
new file mode 100644
index 0000000000..9221866b92
--- /dev/null
+++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/hold/BaseHold.java
@@ -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 .
+ */
+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 executeImpl(WebScriptRequest req, Status status, Cache cache)
+ {
+ JSONObject json = getJSONFromContent(req);
+ List holds = getHolds(json);
+ NodeRef nodeRef = getItemNodeRef(json);
+ doAction(holds, nodeRef);
+ return new HashMap();
+ }
+
+ /**
+ * 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 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 getHolds(JSONObject json)
+ {
+ List holds = new ArrayList();
+ 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;
+ }
+}
diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/hold/HoldPost.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/hold/HoldPost.java
index be34665558..c816a76339 100644
--- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/hold/HoldPost.java
+++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/hold/HoldPost.java
@@ -18,105 +18,24 @@
*/
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.
+ * Implementation for Java backed webscript to add an item to the given hold(s) in the hold container.
*
* @author Tuna Aksoy
* @since 2.2
*/
-public class HoldPost extends DeclarativeWebScript
+public class HoldPost extends BaseHold
{
- /** 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)
+ * @see org.alfresco.module.org_alfresco_module_rm.script.hold.BaseHold#doAction(java.util.List, org.alfresco.service.cmr.repository.NodeRef)
*/
@Override
- protected Map executeImpl(WebScriptRequest req, Status status, Cache cache)
+ void doAction(List holds, NodeRef nodeRef)
{
- NodeRef nodeRef = null;
- List holds = new ArrayList();
- 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();
- }
-
- /**
- * 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 getHolds(JSONObject json) throws JSONException
- {
- JSONArray holdsArray = json.getJSONArray("holds");
- List holds = new ArrayList();
- for (int i = 0; i < holdsArray.length(); i++)
- {
- String nodeRef = holdsArray.getString(i);
- holds.add(new NodeRef(nodeRef));
- }
- return holds;
+ getHoldService().addToHoldContainers(holds, nodeRef);
}
}
diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/hold/HoldPut.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/hold/HoldPut.java
new file mode 100644
index 0000000000..c86368d22c
--- /dev/null
+++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/hold/HoldPut.java
@@ -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 .
+ */
+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 holds, NodeRef nodeRef)
+ {
+ getHoldService().removeFromHoldContainers(holds, nodeRef);
+ }
+}