use of com.serotonin.m2m2.vo.comment.UserCommentVO in project ma-modules-public by infiniteautomation.
the class UserCommentRestController method deleteUserComment.
@ApiOperation(value = "Delete A User Comment by XID")
@RequestMapping(method = RequestMethod.DELETE, produces = { "application/json" }, value = "/{xid}")
public ResponseEntity<UserCommentModel> deleteUserComment(@ApiParam(value = "xid", required = true, allowMultiple = false) @PathVariable String xid, HttpServletRequest request) throws RestValidationFailedException {
RestProcessResult<UserCommentModel> result = new RestProcessResult<UserCommentModel>(HttpStatus.OK);
User user = this.checkUser(request, result);
if (result.isOk()) {
UserCommentVO u = UserCommentDao.instance.getByXid(xid);
if (u == null) {
result.addRestMessage(getDoesNotExistMessage());
return result.createResponseEntity();
}
// Check permissions
if (hasEditPermission(u, user)) {
// Delete it
String initiatorId = request.getHeader("initiatorId");
UserCommentDao.instance.delete(u.getId(), initiatorId);
} else {
LOG.warn("Non admin user: " + user.getUsername() + " attempted to delete user comment : " + u.getUsername());
result.addRestMessage(this.getUnauthorizedMessage());
}
}
return result.createResponseEntity();
}
use of com.serotonin.m2m2.vo.comment.UserCommentVO in project ma-modules-public by infiniteautomation.
the class UserCommentRestController method queryRQL.
@ApiOperation(value = "Query User Comments", notes = "", response = UserCommentModel.class, responseContainer = "Array")
@RequestMapping(method = RequestMethod.GET, produces = { "application/json" })
public ResponseEntity<QueryDataPageStream<UserCommentVO>> queryRQL(HttpServletRequest request) {
RestProcessResult<QueryDataPageStream<UserCommentVO>> result = new RestProcessResult<QueryDataPageStream<UserCommentVO>>(HttpStatus.OK);
this.checkUser(request, result);
if (result.isOk()) {
try {
ASTNode query = parseRQLtoAST(request.getQueryString());
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.vo.comment.UserCommentVO in project ma-modules-public by infiniteautomation.
the class UserCommentRestController method getUserComment.
@ApiOperation(value = "Get user comment by xid", notes = "Returns the user comment specified by the given xid")
@RequestMapping(method = RequestMethod.GET, produces = { "application/json" }, value = "/{xid}")
public ResponseEntity<UserCommentModel> getUserComment(@ApiParam(value = "Valid xid", required = true, allowMultiple = false) @PathVariable String xid, HttpServletRequest request) {
RestProcessResult<UserCommentModel> result = new RestProcessResult<UserCommentModel>(HttpStatus.OK);
this.checkUser(request, result);
if (result.isOk()) {
UserCommentVO u = UserCommentDao.instance.getByXid(xid);
if (u == null) {
result.addRestMessage(getDoesNotExistMessage());
return result.createResponseEntity();
} else {
UserCommentModel model = new UserCommentModel(u);
return result.createResponseEntity(model);
}
}
return result.createResponseEntity();
}
use of com.serotonin.m2m2.vo.comment.UserCommentVO in project ma-modules-public by infiniteautomation.
the class UserCommentRestController method updateUserComment.
@ApiOperation(value = "Updates a user comment")
@RequestMapping(method = RequestMethod.PUT, consumes = { "application/json" }, produces = { "application/json" }, value = "/{xid}")
public ResponseEntity<UserCommentModel> updateUserComment(@PathVariable String xid, @RequestBody(required = true) UserCommentModel model, UriComponentsBuilder builder, HttpServletRequest request) throws RestValidationFailedException {
RestProcessResult<UserCommentModel> result = new RestProcessResult<UserCommentModel>(HttpStatus.OK);
User user = this.checkUser(request, result);
if (result.isOk()) {
UserCommentVO u = UserCommentDao.instance.getByXid(xid);
if (u == null) {
result.addRestMessage(getDoesNotExistMessage());
return result.createResponseEntity();
} else {
// Change the owner
if (model.getUserId() == 0) {
model.setUserId(user.getId());
model.setUsername(user.getUsername());
}
// Check permissions
if (hasEditPermission(model.getData(), user)) {
// Validate and Update
if (!model.validate()) {
result.addRestMessage(this.getValidationFailedError());
} else {
UserCommentDao.instance.save(model.getData());
URI location = builder.path("v1/comments/{xid}").buildAndExpand(model.getXid()).toUri();
result.addRestMessage(getResourceUpdatedMessage(location));
}
return result.createResponseEntity(model);
} else {
result.addRestMessage(this.getUnauthorizedMessage());
return result.createResponseEntity();
}
}
}
return result.createResponseEntity();
}
use of com.serotonin.m2m2.vo.comment.UserCommentVO in project ma-modules-public by infiniteautomation.
the class UserCommentModel method getDataAsComment.
/**
* @return
*/
@JsonIgnore
public UserCommentVO getDataAsComment() {
UserCommentVO comment = new UserCommentVO();
comment.setId(this.data.getId());
comment.setXid(this.data.getXid());
comment.setUserId(this.data.getUserId());
comment.setUsername(this.data.getUsername());
comment.setTs(this.data.getTs());
comment.setComment(this.data.getComment());
return comment;
}
Aggregations