use of com.serotonin.m2m2.watchlist.WatchListVO in project ma-modules-public by infiniteautomation.
the class WatchListDwr method updateWatchListName.
@DwrPermission(user = true)
public void updateWatchListName(String name) {
User user = Common.getUser();
WatchListVO watchList = getWatchList(user);
WatchListCommon.ensureWatchListEditPermission(user, watchList);
watchList.setName(name);
WatchListDao.instance.saveWatchList(watchList);
}
use of com.serotonin.m2m2.watchlist.WatchListVO in project ma-modules-public by infiniteautomation.
the class WatchListDwr method deleteWatchList.
@DwrPermission(user = true)
public boolean deleteWatchList(int watchListId) {
User user = Common.getUser();
WatchListVO watchList = getWatchList(user);
if (watchList == null || watchListId != watchList.getId())
watchList = WatchListDao.instance.get(watchListId);
if (watchList == null || WatchListDao.instance.getWatchLists(user).size() == 1)
// Only one watch list left. Leave it.
return false;
// Allow the delete if the user is an editor.
if (watchList.isEditor(user)) {
WatchListDao.instance.deleteWatchList(watchListId);
return true;
}
return false;
}
use of com.serotonin.m2m2.watchlist.WatchListVO in project ma-modules-public by infiniteautomation.
the class WatchListEmportDefinition method doImport.
@Override
public void doImport(JsonValue jsonValue, ImportContext importContext) throws JsonException {
JsonObject watchListJson = jsonValue.toJsonObject();
String xid = watchListJson.getString("xid");
if (StringUtils.isBlank(xid))
xid = WatchListDao.instance.generateUniqueXid();
WatchListVO watchList = WatchListDao.instance.getWatchList(xid);
if (watchList == null) {
watchList = new WatchListVO();
watchList.setXid(xid);
}
try {
importContext.getReader().readInto(watchList, watchListJson);
// Now validate it. Use a new response object so we can distinguish errors in this user from other
// errors.
ProcessResult watchListResponse = new ProcessResult();
watchList.validate(watchListResponse);
if (watchListResponse.getHasMessages())
// Too bad. Copy the errors into the actual response.
importContext.copyValidationMessages(watchListResponse, "emport.watchList.prefix", xid);
else {
// Sweet. Save it.
boolean isnew = watchList.getId() == Common.NEW_ID;
WatchListDao.instance.save(watchList);
importContext.addSuccessMessage(isnew, "emport.watchList.prefix", xid);
}
} catch (TranslatableJsonException e) {
importContext.getResult().addGenericMessage("emport.watchList.prefix", xid, e.getMsg());
} catch (JsonException e) {
importContext.getResult().addGenericMessage("emport.watchList.prefix", xid, importContext.getJsonExceptionMessage(e));
}
}
use of com.serotonin.m2m2.watchlist.WatchListVO 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();
}
use of com.serotonin.m2m2.watchlist.WatchListVO in project ma-modules-public by infiniteautomation.
the class WatchListRestController method delete.
@ApiOperation(value = "Delete a WatchList ", notes = "Only the owner or an admin can delete", response = WatchListModel.class)
@RequestMapping(method = RequestMethod.DELETE, consumes = { "application/*" }, produces = { "*/*" }, value = "/{xid}")
public ResponseEntity<Void> delete(@PathVariable String xid, HttpServletRequest request) throws RestValidationFailedException {
RestProcessResult<Void> result = new RestProcessResult<Void>(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 (isOwner(user, wl)) {
String initiatorId = request.getHeader("initiatorId");
this.dao.delete(wl.getId(), initiatorId);
result.addRestMessage(HttpStatus.NO_CONTENT, new TranslatableMessage("common.deleted"));
return result.createResponseEntity();
} else {
result.addRestMessage(this.getUnauthorizedMessage());
return result.createResponseEntity();
}
}
} catch (Exception e) {
LOG.warn(e.getMessage(), e);
result.addRestMessage(getInternalServerErrorMessage(e.getMessage()));
}
return result.createResponseEntity();
}
Aggregations