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 cdd73604f3..7d0452627e 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
@@ -65,13 +65,14 @@
-
+ parent="rmCustomReferenceDefinitionBase">
+
+
paramNames)
- {
- for (String name : paramNames)
- {
- checkMandatoryJsonParam(json, name);
- }
- }
-
- /**
- * Gets the template variable substitutions map
- *
- * @param req The webscript request
- * @return The template variable substitutions
- */
- protected Map getTemplateVars(WebScriptRequest req)
- {
- if (req == null)
- {
- throw new WebScriptException(Status.STATUS_BAD_REQUEST, "The webscript request is null.");
- }
-
- if (req.getServiceMatch() == null)
- {
- throw new WebScriptException(Status.STATUS_BAD_REQUEST, "The matching API Service for the request is null.");
- }
-
- Map templateVars = req.getServiceMatch().getTemplateVars();
- if (templateVars == null)
- {
- throw new WebScriptException(Status.STATUS_BAD_REQUEST, "The template variable substitutions map is null");
- }
-
- return templateVars;
- }
-
- /**
- * Gets the value of a request parameter
- *
- * @param req The webscript request
- * @param parameter The request parameter
- * @return The value of the request parameter
- */
- protected String getRequestParameterValue(WebScriptRequest req, String parameter)
- {
- Map templateVars = getTemplateVars(req);
- return templateVars.get(parameter);
- }
-
- /**
- * Gets the request content as JSON object
- *
- * @param req The webscript request
- * @return The request content as JSON object
- */
- protected JSONObject getRequestContentAsJsonObject(WebScriptRequest req)
- {
- Content reqContent = req.getContent();
- if (reqContent == null)
- {
- throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Missing request body.");
- }
-
- String content;
- try
- {
- content = reqContent.getContent();
- }
- catch (IOException error)
- {
- throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Could not get conent from the request.", error);
- }
-
- if (StringUtils.isBlank(content))
- {
- throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Content does not exist.");
- }
-
- JSONTokener jsonTokener;
- try
- {
- jsonTokener = new JSONTokener(req.getContent().getContent());
- }
- catch (IOException error)
- {
- throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Could not get content.", error);
- }
-
- JSONObject json;
- try
- {
- json = new JSONObject(jsonTokener);
- }
- catch (JSONException error)
- {
- throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Unable to parse request body.", error);
- }
-
- return json;
- }
-
- /**
- * Gets the value of a given key from a json object
- *
- * @param jsonObject The json object from which the value should be retrieved
- * @param key The key for which the value is requested
- * @return The value of the given key from the json object
- */
- protected Serializable getJSONObjectValue(JSONObject jsonObject, String key)
- {
- Serializable value;
-
- try
- {
- checkMandatoryJsonParam(jsonObject, key);
- value = (Serializable) jsonObject.get(key);
- }
- catch (JSONException error)
- {
- throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Could not get value for the key '" + key + "'.", error);
- }
-
- return value;
- }
}
\ No newline at end of file
diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/CustomReferenceDefinitionBase.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/CustomReferenceDefinitionBase.java
index 1f57ab74e1..a3eef06e9c 100644
--- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/CustomReferenceDefinitionBase.java
+++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/CustomReferenceDefinitionBase.java
@@ -18,14 +18,13 @@
*/
package org.alfresco.module.org_alfresco_module_rm.script;
+import static org.alfresco.util.WebScriptUtils.getStringValueFromJSONObject;
+
import org.alfresco.module.org_alfresco_module_rm.admin.RecordsManagementAdminService;
-import org.alfresco.service.cmr.dictionary.DictionaryService;
import org.alfresco.service.namespace.QName;
-import org.apache.commons.lang.StringUtils;
import org.json.JSONObject;
import org.springframework.extensions.webscripts.Status;
import org.springframework.extensions.webscripts.WebScriptException;
-import org.springframework.extensions.webscripts.WebScriptRequest;
/**
* Base class for custom reference definition classes
@@ -48,9 +47,6 @@ public class CustomReferenceDefinitionBase extends AbstractRmWebScript
/** Records Management Admin Service */
private RecordsManagementAdminService rmAdminService;
- /** Dictionary Service */
- private DictionaryService dictionaryService;
-
/**
* Sets the records management admin service
*
@@ -71,26 +67,6 @@ public class CustomReferenceDefinitionBase extends AbstractRmWebScript
return this.rmAdminService;
}
- /**
- * Sets the dictionary service
- *
- * @param dictionaryService The dictionary service
- */
- public void setDictionaryService(DictionaryService dictionaryService)
- {
- this.dictionaryService = dictionaryService;
- }
-
- /**
- * Gets the dictionary service instance
- *
- * @return The dictionary service instance
- */
- protected DictionaryService getDictionaryService()
- {
- return this.dictionaryService;
- }
-
/**
* Gets the QName for the given custom reference id
*
@@ -121,22 +97,7 @@ public class CustomReferenceDefinitionBase extends AbstractRmWebScript
*/
protected CustomReferenceType getCustomReferenceType(JSONObject requestContent)
{
- String referenceType = (String) getJSONObjectValue(requestContent, REFERENCE_TYPE);
- if (StringUtils.isBlank(referenceType))
- {
- throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Reference type is missing.");
- }
+ String referenceType = getStringValueFromJSONObject(requestContent, REFERENCE_TYPE);
return CustomReferenceType.getEnumFromString(referenceType);
}
-
- /**
- * Gets the service path from the webscript request
- *
- * @param req The webscript request
- * @return The service path
- */
- protected String getServicePath(WebScriptRequest req)
- {
- return req.getServicePath();
- }
}
diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/CustomReferenceDefinitionPost.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/CustomReferenceDefinitionPost.java
index 0d063e4471..f2f65f9a6e 100644
--- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/CustomReferenceDefinitionPost.java
+++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/CustomReferenceDefinitionPost.java
@@ -18,11 +18,13 @@
*/
package org.alfresco.module.org_alfresco_module_rm.script;
+import static org.alfresco.util.WebScriptUtils.getRequestContentAsJsonObject;
+import static org.alfresco.util.WebScriptUtils.getStringValueFromJSONObject;
+
import java.util.HashMap;
import java.util.Map;
import org.alfresco.service.namespace.QName;
-import org.apache.commons.lang.StringUtils;
import org.json.JSONObject;
import org.springframework.extensions.webscripts.Cache;
import org.springframework.extensions.webscripts.Status;
@@ -49,7 +51,7 @@ public class CustomReferenceDefinitionPost extends CustomReferenceDefinitionBase
QName customReference = addCustomReference(requestContent, customReferenceType);
Map model = new HashMap();
- String servicePath = getServicePath(req);
+ String servicePath = req.getServicePath();
Map customReferenceData = getCustomReferenceData(customReferenceType, customReference, servicePath);
model.putAll(customReferenceData);
@@ -69,28 +71,13 @@ public class CustomReferenceDefinitionPost extends CustomReferenceDefinitionBase
if (CustomReferenceType.PARENT_CHILD.equals(customReferenceType))
{
- String source = (String) getJSONObjectValue(requestContent, SOURCE);
- if (StringUtils.isBlank(source))
- {
- throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Source is blank.");
- }
-
- String target = (String) getJSONObjectValue(requestContent, TARGET);
- if (StringUtils.isBlank(target))
- {
- throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Target is blank.");
- }
-
+ String source = getStringValueFromJSONObject(requestContent, SOURCE);
+ String target = getStringValueFromJSONObject(requestContent, TARGET);
referenceQName = getRmAdminService().addCustomChildAssocDefinition(source, target);
}
else if (CustomReferenceType.BIDIRECTIONAL.equals(customReferenceType))
{
- String label = (String) getJSONObjectValue(requestContent, LABEL);
- if (StringUtils.isBlank(label))
- {
- throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Label is blank.");
- }
-
+ String label = getStringValueFromJSONObject(requestContent, LABEL);
referenceQName = getRmAdminService().addCustomAssocDefinition(label);
}
else
diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/CustomReferenceDefinitionPut.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/CustomReferenceDefinitionPut.java
index 169c2cfd37..323d5e3ebc 100644
--- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/CustomReferenceDefinitionPut.java
+++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/CustomReferenceDefinitionPut.java
@@ -18,11 +18,14 @@
*/
package org.alfresco.module.org_alfresco_module_rm.script;
+import static org.alfresco.util.WebScriptUtils.getRequestContentAsJsonObject;
+import static org.alfresco.util.WebScriptUtils.getRequestParameterValue;
+import static org.alfresco.util.WebScriptUtils.getStringValueFromJSONObject;
+
import java.util.HashMap;
import java.util.Map;
import org.alfresco.service.namespace.QName;
-import org.apache.commons.lang.StringUtils;
import org.json.JSONObject;
import org.springframework.extensions.webscripts.Cache;
import org.springframework.extensions.webscripts.Status;
@@ -46,33 +49,17 @@ public class CustomReferenceDefinitionPut extends CustomReferenceDefinitionBase
protected Map executeImpl(WebScriptRequest req, Status status, Cache cache)
{
JSONObject requestContent = getRequestContentAsJsonObject(req);
- String referenceId = getReferenceId(req);
+ String referenceId = getRequestParameterValue(req, REF_ID);
updateCustomReference(requestContent, referenceId);
Map model = new HashMap();
- String servicePath = getServicePath(req);
+ String servicePath = req.getServicePath();
Map customReferenceData = getCustomReferenceData(servicePath, referenceId);
model.putAll(customReferenceData);
return model;
}
- /**
- * Gets the reference id from the webscript request
- *
- * @param req The webscript request
- * @return The reference id
- */
- private String getReferenceId(WebScriptRequest req)
- {
- String referenceId = getRequestParameterValue(req, REF_ID);
- if (StringUtils.isBlank(referenceId))
- {
- throw new WebScriptException(Status.STATUS_NOT_FOUND, "Reference id is blank.");
- }
- return referenceId;
- }
-
/**
* Updates the custom reference
*
@@ -86,28 +73,13 @@ public class CustomReferenceDefinitionPut extends CustomReferenceDefinitionBase
if (CustomReferenceType.PARENT_CHILD.equals(customReferenceType))
{
- String source = (String) getJSONObjectValue(requestContent, SOURCE);
- if (StringUtils.isBlank(source))
- {
- throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Source is blank.");
- }
-
- String target = (String) getJSONObjectValue(requestContent, TARGET);
- if (StringUtils.isBlank(target))
- {
- throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Target is blank.");
- }
-
+ String source = getStringValueFromJSONObject(requestContent, SOURCE);
+ String target = getStringValueFromJSONObject(requestContent, TARGET);
getRmAdminService().updateCustomChildAssocDefinition(referenceQName, source, target);
}
else if (CustomReferenceType.BIDIRECTIONAL.equals(customReferenceType))
{
- String label = (String) getJSONObjectValue(requestContent, LABEL);
- if (StringUtils.isBlank(label))
- {
- throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Label is blank.");
- }
-
+ String label = getStringValueFromJSONObject(requestContent, LABEL);
getRmAdminService().updateCustomAssocDefinition(referenceQName, label);
}
else
diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/CustomReferenceDefinitionsGet.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/CustomReferenceDefinitionsGet.java
index 31cd0904d7..e33520547a 100644
--- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/CustomReferenceDefinitionsGet.java
+++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/CustomReferenceDefinitionsGet.java
@@ -18,6 +18,8 @@
*/
package org.alfresco.module.org_alfresco_module_rm.script;
+import static org.alfresco.util.WebScriptUtils.getRequestParameterValue;
+
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@@ -26,6 +28,7 @@ import java.util.Map.Entry;
import org.alfresco.service.cmr.dictionary.AssociationDefinition;
import org.alfresco.service.cmr.dictionary.ChildAssociationDefinition;
+import org.alfresco.service.cmr.dictionary.DictionaryService;
import org.alfresco.service.namespace.QName;
import org.apache.commons.lang.StringUtils;
import org.springframework.extensions.webscripts.Cache;
@@ -41,13 +44,36 @@ import org.springframework.extensions.webscripts.WebScriptRequest;
*/
public class CustomReferenceDefinitionsGet extends CustomReferenceDefinitionBase
{
+ /** Dictionary Service */
+ private DictionaryService dictionaryService;
+
+ /**
+ * Sets the dictionary service
+ *
+ * @param dictionaryService The dictionary service
+ */
+ public void setDictionaryService(DictionaryService dictionaryService)
+ {
+ this.dictionaryService = dictionaryService;
+ }
+
+ /**
+ * Gets the dictionary service instance
+ *
+ * @return The dictionary service instance
+ */
+ protected DictionaryService getDictionaryService()
+ {
+ return this.dictionaryService;
+ }
+
/**
* @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)
{
- String referenceId = getRequestParameterValue(req, REF_ID);
+ String referenceId = getRequestParameterValue(req, REF_ID, false);
Map customReferenceDefinitions = getCustomReferenceDefinitions(referenceId);
List