use of com.serotonin.m2m2.web.mvc.rest.v1.message.RestProcessResult in project ma-modules-public by infiniteautomation.
the class WorkItemRestController method getAll.
@ApiOperation(value = "Get all work items", notes = "Returns a list of all work items, optionally filterable on classname")
@RequestMapping(method = RequestMethod.GET, produces = { "application/json" })
public ResponseEntity<List<WorkItemModel>> getAll(@RequestParam(value = "classname", required = false, defaultValue = "") String classname, HttpServletRequest request) {
RestProcessResult<List<WorkItemModel>> result = new RestProcessResult<List<WorkItemModel>>(HttpStatus.OK);
User user = this.checkUser(request, result);
if (result.isOk()) {
if (Permissions.hasAdmin(user)) {
List<WorkItemModel> modelList = new ArrayList<WorkItemModel>();
modelList.addAll(Common.backgroundProcessing.getHighPriorityServiceItems());
modelList.addAll(Common.backgroundProcessing.getMediumPriorityServiceQueueItems());
modelList.addAll(Common.backgroundProcessing.getLowPriorityServiceQueueItems());
if (!classname.isEmpty()) {
List<WorkItemModel> filteredList = new ArrayList<WorkItemModel>();
for (WorkItemModel model : modelList) {
if (model.getClassname().equalsIgnoreCase(classname)) {
filteredList.add(model);
}
}
return result.createResponseEntity(filteredList);
}
return result.createResponseEntity(modelList);
} else {
LOG.warn("Non admin user: " + user.getUsername() + " attempted to access all work items");
result.addRestMessage(this.getUnauthorizedMessage());
return result.createResponseEntity();
}
}
return result.createResponseEntity();
}
use of com.serotonin.m2m2.web.mvc.rest.v1.message.RestProcessResult 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.serotonin.m2m2.web.mvc.rest.v1.message.RestProcessResult in project ma-modules-public by infiniteautomation.
the class WatchListRestController method update.
@ApiOperation(value = "Update a WatchList", notes = "", response = WatchListModel.class)
@RequestMapping(method = RequestMethod.PUT, consumes = { "application/json", "text/csv" }, produces = { "application/json", "text/csv" }, value = "/{xid}")
public ResponseEntity<WatchListModel> update(@PathVariable String xid, @RequestBody WatchListModel model, HttpServletRequest request) throws RestValidationFailedException {
RestProcessResult<WatchListModel> result = new RestProcessResult<WatchListModel>(HttpStatus.OK);
User user = this.checkUser(request, result);
if (!result.isOk()) {
return result.createResponseEntity();
}
WatchListVO wl = this.dao.getByXid(xid);
if (wl == null) {
result.addRestMessage(getDoesNotExistMessage());
return result.createResponseEntity();
}
if (!hasEditPermission(user, wl)) {
result.addRestMessage(getUnauthorizedMessage());
return result.createResponseEntity();
}
WatchListVO update = model.getData();
// Set the id
update.setId(wl.getId());
// Add the user
update.setUserId(wl.getUserId());
// Setup the Points
if (model.getPoints() != null)
for (WatchListDataPointModel pm : model.getPoints()) update.getPointList().add(pm.getDataPointVO());
if (!model.validate()) {
result.addRestMessage(this.getValidationFailedError());
return result.createResponseEntity(model);
}
try {
String initiatorId = request.getHeader("initiatorId");
this.dao.save(update, initiatorId);
} catch (Exception e) {
LOG.error(e.getMessage(), e);
result.addRestMessage(getInternalServerErrorMessage(e.getMessage()));
}
return result.createResponseEntity(model);
}
use of com.serotonin.m2m2.web.mvc.rest.v1.message.RestProcessResult 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.serotonin.m2m2.web.mvc.rest.v1.message.RestProcessResult in project ma-modules-public by infiniteautomation.
the class LoggingRestController method query.
@PreAuthorize("isAdmin()")
@ApiOperation(value = "Query ma.log logs", notes = "Returns a list of recent logs, ie. /by-filename/ma.log?limit(10)\n" + "<br>Query Examples: \n" + "by-filename/ma.log/?level=gt=DEBUG\n" + "by-filename/ma.log/?thread=qtp-1\n" + "by-filename/ma.log/?message=setPointValue\n" + "NOTE: Querying non ma.log files is not supported.")
@RequestMapping(method = RequestMethod.GET, produces = { "application/json" }, value = "/by-filename/{filename}")
public ResponseEntity<QueryArrayStream<?>> query(@PathVariable String filename, HttpServletRequest request) {
RestProcessResult<QueryArrayStream<?>> result = new RestProcessResult<QueryArrayStream<?>>(HttpStatus.OK);
try {
ASTNode query = parseRQLtoAST(request.getQueryString());
File file = new File(Common.getLogsDir(), filename);
if (file.exists()) {
// Pattern pattern = new
if (filename.matches(LogQueryArrayStream.LOGFILE_REGEX)) {
LogQueryArrayStream stream = new LogQueryArrayStream(filename, query);
return result.createResponseEntity(stream);
} else {
throw new AccessDeniedException("Non ma.log files are not accessible on this endpoint.");
}
} else {
result.addRestMessage(getDoesNotExistMessage());
}
} catch (InvalidRQLRestException e) {
LOG.error(e.getMessage(), e);
result.addRestMessage(getInternalServerErrorMessage(e.getMessage()));
return result.createResponseEntity();
}
return result.createResponseEntity();
}
Aggregations