Skip to content

Commit

Permalink
Changing JsonData GET endpoints to return model instead of just data
Browse files Browse the repository at this point in the history
  • Loading branch information
terrypacker committed Mar 15, 2016
1 parent 37804a5 commit 436776d
Showing 1 changed file with 9 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,62 +90,28 @@ public ResponseEntity<List<String>> list(

return result.createResponseEntity();
}


@ApiOperation(
value = "Get JSON Data Model",
notes = "Retreive a full model",
response = JsonDataModel.class
)
@RequestMapping(method = RequestMethod.GET, value="/full/{xid}", produces={"application/json"})
public ResponseEntity<JsonDataModel> getFull(
HttpServletRequest request,

@ApiParam(value = "Data xid", required = true, allowMultiple = false)
@PathVariable String xid
){

RestProcessResult<JsonDataModel> result = new RestProcessResult<JsonDataModel>(HttpStatus.OK);
User user = this.checkUser(request, result);
if(result.isOk()){
JsonDataVO vo = JsonDataDao.instance.getByXid(xid);
if(vo == null){
result.addRestMessage(getDoesNotExistMessage());
}else{
//Check existing permissions
if(!Permissions.hasPermission(user, vo.getReadPermission())){
result.addRestMessage(getUnauthorizedMessage());
return result.createResponseEntity();
}
return result.createResponseEntity(new JsonDataModel(vo));
}
}

return result.createResponseEntity();
}


@ApiOperation(
value = "Get JSON Data",
notes = "Returns only the data"
)
@RequestMapping(method = RequestMethod.GET, value="/{xid}", produces={"application/json"})
public ResponseEntity<Object> getData(
public ResponseEntity<JsonDataModel> getData(
HttpServletRequest request,

@ApiParam(value = "XID", required = true, allowMultiple = false)
@PathVariable String xid
){
return getDataWithPath(request, xid, null);
}



@ApiOperation(
value = "Get JSON Data using a path",
notes = "To get a sub component of the data use a path of member.submember"
)
@RequestMapping(method = RequestMethod.GET, value="/{xid}/{path:.*}", produces={"application/json"})
public ResponseEntity<Object> getDataWithPath(
public ResponseEntity<JsonDataModel> getDataWithPath(
HttpServletRequest request,

@ApiParam(value = "XID", required = true, allowMultiple = false)
Expand All @@ -155,7 +121,7 @@ public ResponseEntity<Object> getDataWithPath(
@PathVariable String path
){

RestProcessResult<Object> result = new RestProcessResult<Object>(HttpStatus.OK);
RestProcessResult<JsonDataModel> result = new RestProcessResult<JsonDataModel>(HttpStatus.OK);
User user = this.checkUser(request, result);
if(result.isOk()){

Expand All @@ -170,7 +136,7 @@ public ResponseEntity<Object> getDataWithPath(
}

if(path == null)
return result.createResponseEntity(vo.getJsonData());
return result.createResponseEntity(new JsonDataModel(vo));
else{
String[] pathParts;
if(path.contains("."))
Expand All @@ -181,8 +147,10 @@ public ResponseEntity<Object> getDataWithPath(
if(data == null){
result.addRestMessage(getDoesNotExistMessage());
return result.createResponseEntity();
}else
return result.createResponseEntity(data);
}else{
vo.setJsonData(data);
return result.createResponseEntity(new JsonDataModel(vo));
}
}
}
}
Expand Down

0 comments on commit 436776d

Please sign in to comment.