Search in sources :

Example 1 with ModuleRestV2Exception

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);
}
Also used : RestProcessResult(com.serotonin.m2m2.web.mvc.rest.v1.message.RestProcessResult) User(com.serotonin.m2m2.vo.User) ModuleRestV2Exception(com.infiniteautomation.mango.rest.v2.exception.ModuleRestV2Exception) TranslatableMessage(com.serotonin.m2m2.i18n.TranslatableMessage) Module(com.serotonin.m2m2.module.Module) ModuleModel(com.serotonin.m2m2.web.mvc.rest.v1.model.modules.ModuleModel) CoreModuleModel(com.serotonin.m2m2.web.mvc.rest.v1.model.modules.CoreModuleModel) ApiOperation(com.wordnik.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

ModuleRestV2Exception (com.infiniteautomation.mango.rest.v2.exception.ModuleRestV2Exception)1 TranslatableMessage (com.serotonin.m2m2.i18n.TranslatableMessage)1 Module (com.serotonin.m2m2.module.Module)1 User (com.serotonin.m2m2.vo.User)1 RestProcessResult (com.serotonin.m2m2.web.mvc.rest.v1.message.RestProcessResult)1 CoreModuleModel (com.serotonin.m2m2.web.mvc.rest.v1.model.modules.CoreModuleModel)1 ModuleModel (com.serotonin.m2m2.web.mvc.rest.v1.model.modules.ModuleModel)1 ApiOperation (com.wordnik.swagger.annotations.ApiOperation)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1