Search in sources :

Example 1 with ModuleRestException

use of com.infiniteautomation.mango.rest.latest.exception.ModuleRestException in project ma-modules-public by infiniteautomation.

the class ModulesRestController method markModuleForDeletion.

@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, value = "/deletion-state")
public ModuleModel markModuleForDeletion(@ApiParam(value = "Deletion State", required = true, defaultValue = "false", allowMultiple = false) @RequestParam(name = "delete", required = true) boolean delete, @ApiParam(value = "Module model") @RequestBody() ModuleModel model, @AuthenticationPrincipal PermissionHolder user, HttpServletRequest request) {
    permissionService.ensureAdminRole(user);
    Module module = ModuleRegistry.getModule(model.getName());
    if (module == null)
        throw new NotFoundException();
    module.setMarkedForDeletion(delete);
    if (module.isMarkedForDeletion() != delete)
        throw new ModuleRestException(HttpStatus.BAD_REQUEST, new TranslatableMessage("rest.modules.error.dependencyFailure"));
    return new ModuleModel(module);
}
Also used : ModuleRestException(com.infiniteautomation.mango.rest.latest.exception.ModuleRestException) FileNotFoundException(java.io.FileNotFoundException) NotFoundException(com.infiniteautomation.mango.util.exception.NotFoundException) TranslatableMessage(com.serotonin.m2m2.i18n.TranslatableMessage) Module(com.serotonin.m2m2.module.Module) CoreModule(com.serotonin.m2m2.module.ModuleRegistry.CoreModule) InvalidModule(com.infiniteautomation.mango.rest.latest.model.modules.UpgradeUploadResult.InvalidModule) ModuleModel(com.infiniteautomation.mango.rest.latest.model.modules.ModuleModel) CoreModuleModel(com.infiniteautomation.mango.rest.latest.model.modules.CoreModuleModel) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with ModuleRestException

use of com.infiniteautomation.mango.rest.latest.exception.ModuleRestException 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, value = "/deletion-state/{moduleName}")
public ResponseEntity<ModuleModel> markForDeletion(@PathVariable String moduleName, @ApiParam(value = "Deletion State", required = true, defaultValue = "false", allowMultiple = false) @RequestParam(name = "delete", required = true) boolean delete, @AuthenticationPrincipal PermissionHolder user, HttpServletRequest request) {
    Module module = ModuleRegistry.getModule(moduleName);
    if (module == null)
        throw new NotFoundException();
    module.setMarkedForDeletion(delete);
    if (module.isMarkedForDeletion() != delete)
        throw new ModuleRestException(HttpStatus.BAD_REQUEST, new TranslatableMessage("rest.modules.error.dependencyFailure"));
    return ResponseEntity.ok(new ModuleModel(module));
}
Also used : ModuleRestException(com.infiniteautomation.mango.rest.latest.exception.ModuleRestException) FileNotFoundException(java.io.FileNotFoundException) NotFoundException(com.infiniteautomation.mango.util.exception.NotFoundException) TranslatableMessage(com.serotonin.m2m2.i18n.TranslatableMessage) Module(com.serotonin.m2m2.module.Module) CoreModule(com.serotonin.m2m2.module.ModuleRegistry.CoreModule) InvalidModule(com.infiniteautomation.mango.rest.latest.model.modules.UpgradeUploadResult.InvalidModule) ModuleModel(com.infiniteautomation.mango.rest.latest.model.modules.ModuleModel) CoreModuleModel(com.infiniteautomation.mango.rest.latest.model.modules.CoreModuleModel) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

ModuleRestException (com.infiniteautomation.mango.rest.latest.exception.ModuleRestException)2 CoreModuleModel (com.infiniteautomation.mango.rest.latest.model.modules.CoreModuleModel)2 ModuleModel (com.infiniteautomation.mango.rest.latest.model.modules.ModuleModel)2 InvalidModule (com.infiniteautomation.mango.rest.latest.model.modules.UpgradeUploadResult.InvalidModule)2 NotFoundException (com.infiniteautomation.mango.util.exception.NotFoundException)2 TranslatableMessage (com.serotonin.m2m2.i18n.TranslatableMessage)2 Module (com.serotonin.m2m2.module.Module)2 CoreModule (com.serotonin.m2m2.module.ModuleRegistry.CoreModule)2 ApiOperation (io.swagger.annotations.ApiOperation)2 FileNotFoundException (java.io.FileNotFoundException)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2