use of com.wordnik.swagger.annotations.ApiResponses in project ma-core-public by infiniteautomation.
the class MangoDemoRestController method getAllDemos.
@ApiOperation(value = "Get all demos", notes = "Notes for getting all demos")
@ApiResponses(value = { @ApiResponse(code = 200, message = "Ok"), @ApiResponse(code = 403, message = "User does not have access") })
@RequestMapping(method = RequestMethod.GET, produces = { "application/json", "text/csv" }, value = "/list")
public ResponseEntity<List<DemoModel>> getAllDemos(HttpServletRequest request, @ApiParam(value = "Limit the number of results", required = false) @RequestParam(value = "limit", required = false, defaultValue = "100") int limit) {
RestProcessResult<List<DemoModel>> result = new RestProcessResult<List<DemoModel>>(HttpStatus.OK);
this.checkUser(request, result);
if (result.isOk()) {
ASTNode root = new ASTNode("limit", limit);
List<DemoModel> models = queryStore(root);
return result.createResponseEntity(models);
}
return result.createResponseEntity();
}
use of com.wordnik.swagger.annotations.ApiResponses in project ma-modules-public by infiniteautomation.
the class WatchListRestController method queryRQL.
@ApiOperation(value = "Query WatchLists", notes = "", response = WatchListSummaryModel.class, responseContainer = "Array")
@ApiResponses(value = { @ApiResponse(code = 200, message = "Ok", response = WatchListSummaryModel.class), @ApiResponse(code = 403, message = "User does not have access", response = ResponseEntity.class) })
@RequestMapping(method = RequestMethod.GET, produces = { "application/json" })
public ResponseEntity<QueryDataPageStream<WatchListVO>> queryRQL(HttpServletRequest request) {
RestProcessResult<QueryDataPageStream<WatchListVO>> result = new RestProcessResult<QueryDataPageStream<WatchListVO>>(HttpStatus.OK);
User user = this.checkUser(request, result);
if (result.isOk()) {
try {
ASTNode query = parseRQLtoAST(request.getQueryString());
if (!user.isAdmin()) {
// We are going to filter the results, so we need to strip out the limit(limit,offset) or limit(limit) clause.
WatchListStreamCallback callback = new WatchListStreamCallback(this, user);
FilteredPageQueryStream<WatchListVO, WatchListSummaryModel, WatchListDao> stream = new FilteredPageQueryStream<WatchListVO, WatchListSummaryModel, WatchListDao>(WatchListDao.instance, this, query, callback);
stream.setupQuery();
return result.createResponseEntity(stream);
} else
return result.createResponseEntity(getPageStream(query));
} catch (InvalidRQLRestException e) {
LOG.error(e.getMessage(), e);
result.addRestMessage(getInternalServerErrorMessage(e.getMessage()));
return result.createResponseEntity();
}
}
return result.createResponseEntity();
}
use of com.wordnik.swagger.annotations.ApiResponses in project ma-modules-public by infiniteautomation.
the class WatchListRestController method createNew.
@ApiOperation(value = "Create New WatchList", notes = "", response = WatchListModel.class)
@ApiResponses({ @ApiResponse(code = 201, message = "User Created", response = WatchListModel.class), @ApiResponse(code = 401, message = "Unauthorized Access", response = ResponseEntity.class), @ApiResponse(code = 409, message = "WatchList Already Exists") })
@RequestMapping(method = RequestMethod.POST, consumes = { "application/json", "text/csv" }, produces = { "application/json", "text/csv" })
public ResponseEntity<WatchListModel> createNew(@ApiParam(value = "Watchlist to save", required = true) @RequestBody WatchListModel model, UriComponentsBuilder builder, HttpServletRequest request) throws RestValidationFailedException {
RestProcessResult<WatchListModel> result = new RestProcessResult<WatchListModel>(HttpStatus.CREATED);
User user = this.checkUser(request, result);
if (!result.isOk()) {
return result.createResponseEntity();
}
WatchListVO wl = model.getData();
// Check XID if blank and generate one
if (StringUtils.isBlank(wl.getXid())) {
wl.setXid(this.dao.generateUniqueXid());
}
// Add the user
wl.setUserId(user.getId());
// Setup the Points
if (model.getPoints() != null)
for (WatchListDataPointModel pm : model.getPoints()) wl.getPointList().add(pm.getDataPointVO());
// Ready to validate and then save
if (!model.validate()) {
result.addRestMessage(this.getValidationFailedError());
return result.createResponseEntity(model);
}
try {
String initiatorId = request.getHeader("initiatorId");
this.dao.save(wl, initiatorId);
} catch (Exception e) {
LOG.error(e.getMessage(), e);
result.addRestMessage(getInternalServerErrorMessage(e.getMessage()));
}
return result.createResponseEntity(new WatchListModel(wl, this.dao.getPointSummaries(wl.getId())));
}
use of com.wordnik.swagger.annotations.ApiResponses in project ma-modules-public by infiniteautomation.
the class JsonDataRestController method deletePartialJsonData.
@ApiOperation(value = "Partially Delete JSON Data", notes = "{path} is the path to data with dots data.member.submember", response = JsonDataModel.class)
@ApiResponses({ @ApiResponse(code = 201, message = "Data Deleted", response = JsonDataModel.class), @ApiResponse(code = 401, message = "Unauthorized Access", response = ResponseEntity.class), @ApiResponse(code = 403, message = "Data Doesn't Exists") })
@RequestMapping(method = RequestMethod.DELETE, value = "/{xid}/{path:.*}")
public ResponseEntity<JsonDataModel> deletePartialJsonData(@ApiParam(value = "XID", required = true, allowMultiple = false) @PathVariable String xid, @ApiParam(value = "Data path using dots as separator", required = true, allowMultiple = false) @PathVariable String path, UriComponentsBuilder builder, HttpServletRequest request) throws RestValidationFailedException {
RestProcessResult<JsonDataModel> result = new RestProcessResult<JsonDataModel>(HttpStatus.OK);
User user = this.checkUser(request, result);
if (result.isOk()) {
JsonDataVO vo = this.dao.getByXid(xid);
if (vo != null) {
// Check existing permissions
if (!Permissions.hasPermission(user, vo.getEditPermission())) {
result.addRestMessage(getUnauthorizedMessage());
return result.createResponseEntity();
}
JsonDataModel model = new JsonDataModel(vo);
String[] pathParts;
if (path == null || (pathParts = path.split("\\.")).length == 0) {
// Delete the whole thing
this.dao.delete(vo.getId());
} else {
// Delete something from the map
JsonNode existingData = (JsonNode) vo.getJsonData();
boolean deleted = deleteNode(existingData, pathParts);
if (!deleted) {
result.addRestMessage(getDoesNotExistMessage());
return result.createResponseEntity();
}
if (!model.validate()) {
result.addRestMessage(this.getValidationFailedError());
return result.createResponseEntity(model);
}
try {
String initiatorId = request.getHeader("initiatorId");
this.dao.save(vo, initiatorId);
} catch (Exception e) {
LOG.error(e.getMessage(), e);
result.addRestMessage(getInternalServerErrorMessage(e.getMessage()));
}
}
return result.createResponseEntity(model);
} else {
result.addRestMessage(getDoesNotExistMessage());
}
}
return result.createResponseEntity();
}
use of com.wordnik.swagger.annotations.ApiResponses in project ma-modules-public by infiniteautomation.
the class UserRestController method queryRQL.
@ApiOperation(value = "Query Users", notes = "", response = UserModel.class, responseContainer = "Array")
@ApiResponses(value = { @ApiResponse(code = 200, message = "Ok", response = UserModel.class), @ApiResponse(code = 403, message = "User does not have access", response = ResponseEntity.class) })
@RequestMapping(method = RequestMethod.GET, produces = { "application/json" })
public ResponseEntity<QueryDataPageStream<User>> queryRQL(HttpServletRequest request) {
RestProcessResult<QueryDataPageStream<User>> result = new RestProcessResult<QueryDataPageStream<User>>(HttpStatus.OK);
User user = this.checkUser(request, result);
if (result.isOk()) {
try {
// Parse the RQL Query
ASTNode query = parseRQLtoAST(request.getQueryString());
if (!user.isAdmin()) {
query = addAndRestriction(query, new ASTNode("eq", "id", user.getId()));
}
return result.createResponseEntity(getPageStream(query));
} catch (InvalidRQLRestException e) {
LOG.error(e.getMessage(), e);
result.addRestMessage(getInternalServerErrorMessage(e.getMessage()));
return result.createResponseEntity();
}
}
return result.createResponseEntity();
}
Aggregations