use of com.infiniteautomation.mango.rest.v2.exception.ModuleRestV2Exception 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);
}
Aggregations