use of com.serotonin.m2m2.web.mvc.rest.v1.message.RestProcessResult in project ma-core-public by infiniteautomation.
the class AbstractDataSourceModel method validate.
/*
* (non-Javadoc)
* @see com.serotonin.m2m2.web.mvc.rest.v1.model.AbstractRestModel#validate(com.serotonin.m2m2.web.mvc.rest.v1.message.RestProcessResult)
*/
public void validate(RestProcessResult<?> result) throws RestValidationFailedException {
ProcessResult validation = new ProcessResult();
this.data.validate(validation);
if (validation.getHasMessages()) {
result.addValidationMessages(validation);
throw new RestValidationFailedException(this, result);
}
}
use of com.serotonin.m2m2.web.mvc.rest.v1.message.RestProcessResult 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.serotonin.m2m2.web.mvc.rest.v1.message.RestProcessResult in project ma-modules-public by infiniteautomation.
the class LoggingRestController method getTableModel.
@ApiOperation(value = "Get Explaination For Query", notes = "What is Query-able on this model")
@ApiResponses(value = { @ApiResponse(code = 200, message = "Ok"), @ApiResponse(code = 403, message = "User does not have access") })
@RequestMapping(method = RequestMethod.GET, produces = { "application/json" }, value = "/explain-query")
public ResponseEntity<TableModel> getTableModel(HttpServletRequest request) {
RestProcessResult<TableModel> result = new RestProcessResult<TableModel>(HttpStatus.OK);
this.checkUser(request, result);
if (result.isOk()) {
TableModel model = new TableModel();
List<QueryAttribute> attributes = new ArrayList<QueryAttribute>();
attributes.add(new QueryAttribute("level", null, Types.VARCHAR));
attributes.add(new QueryAttribute("classname", null, Types.VARCHAR));
attributes.add(new QueryAttribute("method", null, Types.VARCHAR));
attributes.add(new QueryAttribute("time", null, Types.INTEGER));
attributes.add(new QueryAttribute("message", null, Types.VARCHAR));
model.setAttributes(attributes);
result.addRestMessage(getSuccessMessage());
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 ModulesRestController method markForDeletion.
@ApiOperation(value = "Set Marked For Deletion state of Module", notes = "Marking a module for deletion will un-install it upon restart")
@RequestMapping(method = RequestMethod.PUT, produces = { "application/json" }, value = "/deletion-state/{moduleName}")
public ResponseEntity<ModuleModel> markForDeletion(@ApiParam(value = "Module name", required = false, allowMultiple = false) @PathVariable(required = false) String moduleName, @ApiParam(value = "Deletion State", required = true, defaultValue = "false", allowMultiple = false) @RequestParam(required = true) boolean delete, @ApiParam(value = "Module model", required = false) @RequestBody(required = false) ModuleModel model, HttpServletRequest request) {
RestProcessResult<ModuleModel> result = new RestProcessResult<ModuleModel>(HttpStatus.OK);
User user = this.checkUser(request, result);
if (result.isOk()) {
if (user.isAdmin()) {
Module module = ModuleRegistry.getModule(moduleName == null ? model.getName() : moduleName);
if (module != null) {
module.setMarkedForDeletion(delete);
if (module.isMarkedForDeletion() != delete)
throw new ModuleRestV2Exception(HttpStatus.BAD_REQUEST, new TranslatableMessage("rest.modules.error.dependencyFailure"));
return result.createResponseEntity(new ModuleModel(module));
} else {
result.addRestMessage(getDoesNotExistMessage());
}
} else {
result.addRestMessage(this.getUnauthorizedMessage());
}
}
return result.createResponseEntity(model);
}
use of com.serotonin.m2m2.web.mvc.rest.v1.message.RestProcessResult in project ma-modules-public by infiniteautomation.
the class ModulesRestController method cancelUpgrade.
@ApiOperation(value = "Cancel Download of Upgrades", notes = "")
@RequestMapping(method = RequestMethod.PUT, consumes = { "application/json" }, produces = { "application/json" }, value = "/upgrade")
public ResponseEntity<Void> cancelUpgrade(HttpServletRequest request) {
RestProcessResult<Void> result = new RestProcessResult<Void>(HttpStatus.OK);
User user = this.checkUser(request, result);
if (result.isOk()) {
if (user.isAdmin()) {
// Cancel if possible
if (ModulesDwr.tryCancelUpgrade()) {
result.addRestMessage(HttpStatus.OK, new TranslatableMessage("common.cancelled"));
} else {
result.addRestMessage(HttpStatus.NOT_MODIFIED, new TranslatableMessage("modules.versionCheck.notRunning"));
}
} else {
result.addRestMessage(this.getUnauthorizedMessage());
}
}
return result.createResponseEntity();
}
Aggregations