use of com.serotonin.m2m2.web.mvc.rest.v1.model.WatchListDataPointModel 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.model.WatchListDataPointModel 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.model.WatchListDataPointModel in project ma-modules-public by infiniteautomation.
the class WatchListRestController method get.
@ApiOperation(value = "Get a Watchlist", notes = "", response = WatchListModel.class)
@RequestMapping(method = RequestMethod.GET, produces = { "application/json", "text/csv" }, value = "/{xid}")
public ResponseEntity<WatchListModel> get(@PathVariable String xid, HttpServletRequest request) throws RestValidationFailedException {
RestProcessResult<WatchListModel> result = new RestProcessResult<WatchListModel>(HttpStatus.OK);
try {
User user = this.checkUser(request, result);
if (result.isOk()) {
WatchListVO wl = this.dao.getByXid(xid);
if (wl == null) {
result.addRestMessage(getDoesNotExistMessage());
return result.createResponseEntity();
}
if (hasReadPermission(user, wl)) {
List<WatchListDataPointModel> points = this.dao.getPointSummaries(wl.getId());
// Filter them on read permission
ListIterator<WatchListDataPointModel> it = points.listIterator();
while (it.hasNext()) {
if (!Permissions.hasPermission(user, it.next().getReadPermission()))
it.remove();
}
return result.createResponseEntity(new WatchListModel(wl, points));
} else {
result.addRestMessage(getUnauthorizedMessage());
}
}
} catch (Exception e) {
LOG.warn(e.getMessage(), e);
result.addRestMessage(getInternalServerErrorMessage(e.getMessage()));
}
return result.createResponseEntity();
}
Aggregations