Good Practice to get response in webscript

Body requestBodyObject = JsonUtility.buildRequestBodyObject(jsonRequest);
Map<String,Object> mapOfParams = requestBodyObject.getBody();
String noderef = JavaUtility.extractParameterFromMap(mapOfParams,"noderef");
NodeRef fileNodeRef = new NodeRef(noderef);


public static String extractParameterFromMap(Map<String,Object> mapOfParams,String paramName)
{
String paramValue = "";
if(mapOfParams.containsKey(paramName)){
paramValue = (String)mapOfParams.get(paramName);
}
return paramValue;
}


public class JsonUtility {
public static Body buildRequestBodyObject(String jsonRequest){
Gson gson = new GsonBuilder().create();
return gson.fromJson(jsonRequest, Body.class);
}
}


===============================================================================
public class Response {
private ResponseContainer response;
public ResponseContainer getResponse() {
return response;
}
public void setResponse(ResponseContainer response) {
this.response = response;
}
}
public class ResponseContainer {
private Integer code;
private String message;
private ResponseBody body;
public Integer getCode() {
return code;
}
public void setCode(Integer code) {
this.code = code;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public ResponseBody getBody() {
return body;
}
public void setBody(ResponseBody body) {
this.body = body;
}
}


public class ResponseBody {
private Map<String,Object> valueMap;
public Map<String, Object> getValueMap() {
return valueMap;
}
public void setValueMap(Map<String, Object> valueMap) {
this.valueMap = valueMap;
}
}


public class Body {
private Map<String,Object> body;
public Map<String, Object> getBody() {
return body;
}
public void setBody(Map<String, Object> body) {
this.body = body;
}
}
=================================================================
Map<String,Object> valueMap = new HashMap<String,Object>();
valueMap.put("nodeRef", "workspace://SpacesStore/5bc2fd7c-9b00-4d66-8f01-ad742cb7d31d");
valueMap.put("permissionSet",ps);


Body b = new Body();
b.setBody(valueMap);


Gson gson = new Gson();
String json = gson.toJson(b);
==============================================================
"{
'body':
{ 'permissionSet':
{ 'entities':
[
{ 'name':'GROUP_One', 'permissionCode':'1' },
{ 'name':'ABCC', 'permissionCode':'4' }
]
},
'noderef':'"+folderNodeRef+"'
}
}";

"{ 'body':{'firstName':'Ratik','lastName':'Singhal','age:'32','address':'Noida'}}"

Comments

Popular posts from this blog

Install Alfresco Content Service 6.0 on ubuntu 16 using distribution zip

Alfresco basic authentication

Lucene and fts-search