Search in sources :

Example 1 with ModuleModel

use of com.serotonin.m2m2.web.mvc.rest.v1.model.modules.ModuleModel in project ma-modules-public by infiniteautomation.

the class ModulesRestController method getUpgradeStatus.

@ApiOperation(value = "Get Current Upgrade Task Status", notes = "")
@RequestMapping(method = RequestMethod.GET, value = "/upgrade-status", produces = { "application/json" })
public ResponseEntity<UpgradeStatusModel> getUpgradeStatus(HttpServletRequest request) {
    RestProcessResult<UpgradeStatusModel> result = new RestProcessResult<UpgradeStatusModel>(HttpStatus.OK);
    User user = this.checkUser(request, result);
    if (result.isOk()) {
        if (Permissions.hasAdmin(user)) {
            ProcessResult status = ModulesDwr.monitorDownloads();
            UpgradeStatusModel model = new UpgradeStatusModel();
            if (status.getHasMessages()) {
                // Not running
                model.setRunning(false);
            } else {
                List<ModuleModel> modules = new ArrayList<ModuleModel>();
                @SuppressWarnings("unchecked") List<StringStringPair> results = (List<StringStringPair>) status.getData().get("results");
                for (StringStringPair r : results) modules.add(new ModuleModel(r.getKey(), r.getValue()));
                model.setResults(modules);
                model.setFinished((boolean) status.getData().get("finished"));
                model.setCancelled((boolean) status.getData().get("cancelled"));
                model.setWillRestart((boolean) status.getData().get("restart"));
                Object error = status.getData().get("error");
                if (error != null)
                    model.setError((String) error);
                model.setStage((String) status.getData().get("stage"));
            }
            return result.createResponseEntity(model);
        } else {
            result.addRestMessage(this.getUnauthorizedMessage());
        }
    }
    return result.createResponseEntity();
}
Also used : StringStringPair(com.serotonin.db.pair.StringStringPair) User(com.serotonin.m2m2.vo.User) RestProcessResult(com.serotonin.m2m2.web.mvc.rest.v1.message.RestProcessResult) ProcessResult(com.serotonin.m2m2.i18n.ProcessResult) ArrayList(java.util.ArrayList) JsonString(com.serotonin.json.type.JsonString) ModuleModel(com.serotonin.m2m2.web.mvc.rest.v1.model.modules.ModuleModel) CoreModuleModel(com.serotonin.m2m2.web.mvc.rest.v1.model.modules.CoreModuleModel) RestProcessResult(com.serotonin.m2m2.web.mvc.rest.v1.message.RestProcessResult) List(java.util.List) ArrayList(java.util.ArrayList) JsonObject(com.serotonin.json.type.JsonObject) UpgradeStatusModel(com.serotonin.m2m2.web.mvc.rest.v1.model.modules.UpgradeStatusModel) ApiOperation(com.wordnik.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with ModuleModel

use of com.serotonin.m2m2.web.mvc.rest.v1.model.modules.ModuleModel in project ma-modules-public by infiniteautomation.

the class ModulesRestController method getCoreModule.

/**
 * Create a Core Module Model
 *
 * @return
 */
private ModuleModel getCoreModule() {
    CoreModuleModel coreModel = new CoreModuleModel(ModuleRegistry.getCoreModule());
    coreModel.setGuid(Providers.get(ICoreLicense.class).getGuid());
    coreModel.setInstanceDescription(SystemSettingsDao.getValue(SystemSettingsDao.INSTANCE_DESCRIPTION));
    coreModel.setDistributor(Common.envProps.getString("distributor"));
    coreModel.setUpgradeVersionState(SystemSettingsDao.getIntValue(SystemSettingsDao.UPGRADE_VERSION_STATE));
    return coreModel;
}
Also used : CoreModuleModel(com.serotonin.m2m2.web.mvc.rest.v1.model.modules.CoreModuleModel)

Example 3 with ModuleModel

use of com.serotonin.m2m2.web.mvc.rest.v1.model.modules.ModuleModel in project ma-modules-public by infiniteautomation.

the class ModulesRestController method getCore.

@ApiOperation(value = "Get Core Module", notes = "For checking current licensing and version")
@RequestMapping(method = RequestMethod.GET, value = "/core", produces = { "application/json" })
public ResponseEntity<MappingJacksonValue> getCore(HttpServletRequest request) {
    RestProcessResult<MappingJacksonValue> result = new RestProcessResult<>(HttpStatus.OK);
    User user = this.checkUser(request, result);
    if (result.isOk()) {
        ModuleModel coreModule = getCoreModule();
        MappingJacksonValue jacksonValue = new MappingJacksonValue(coreModule);
        if (Permissions.hasAdmin(user)) {
            jacksonValue.setSerializationView(ModuleModel.AdminView.class);
        } else {
            jacksonValue.setSerializationView(Object.class);
        }
        return result.createResponseEntity(jacksonValue);
    }
    return result.createResponseEntity();
}
Also used : RestProcessResult(com.serotonin.m2m2.web.mvc.rest.v1.message.RestProcessResult) User(com.serotonin.m2m2.vo.User) MappingJacksonValue(org.springframework.http.converter.json.MappingJacksonValue) 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)

Example 4 with ModuleModel

use of com.serotonin.m2m2.web.mvc.rest.v1.model.modules.ModuleModel in project ma-modules-public by infiniteautomation.

the class ModulesRestController method listModules.

@ApiOperation(value = "List Current Installed Modules", notes = "List all installed")
@RequestMapping(method = RequestMethod.GET, value = "/list", produces = { "application/json" })
public ResponseEntity<List<ModuleModel>> listModules(HttpServletRequest request) {
    RestProcessResult<List<ModuleModel>> result = new RestProcessResult<List<ModuleModel>>(HttpStatus.OK);
    User user = this.checkUser(request, result);
    if (result.isOk()) {
        if (Permissions.hasAdmin(user)) {
            List<ModuleModel> models = new ArrayList<ModuleModel>();
            ModuleModel core = getCoreModule();
            List<Module> modules = ModuleRegistry.getModules();
            models.add(core);
            for (Module module : modules) models.add(new ModuleModel(module));
            // Add the unloaded modules at the end?
            List<Module> unloaded = ModuleRegistry.getUnloadedModules();
            for (Module module : unloaded) {
                ModuleModel model = new ModuleModel(module);
                model.setUnloaded(true);
                models.add(model);
            }
            return result.createResponseEntity(models);
        } else {
            result.addRestMessage(this.getUnauthorizedMessage());
        }
    }
    return result.createResponseEntity();
}
Also used : RestProcessResult(com.serotonin.m2m2.web.mvc.rest.v1.message.RestProcessResult) User(com.serotonin.m2m2.vo.User) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) 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)

Example 5 with ModuleModel

use of com.serotonin.m2m2.web.mvc.rest.v1.model.modules.ModuleModel 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

CoreModuleModel (com.serotonin.m2m2.web.mvc.rest.v1.model.modules.CoreModuleModel)5 User (com.serotonin.m2m2.vo.User)4 RestProcessResult (com.serotonin.m2m2.web.mvc.rest.v1.message.RestProcessResult)4 ModuleModel (com.serotonin.m2m2.web.mvc.rest.v1.model.modules.ModuleModel)4 ApiOperation (com.wordnik.swagger.annotations.ApiOperation)4 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)4 Module (com.serotonin.m2m2.module.Module)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 ModuleRestV2Exception (com.infiniteautomation.mango.rest.v2.exception.ModuleRestV2Exception)1 StringStringPair (com.serotonin.db.pair.StringStringPair)1 JsonObject (com.serotonin.json.type.JsonObject)1 JsonString (com.serotonin.json.type.JsonString)1 ProcessResult (com.serotonin.m2m2.i18n.ProcessResult)1 TranslatableMessage (com.serotonin.m2m2.i18n.TranslatableMessage)1 UpgradeStatusModel (com.serotonin.m2m2.web.mvc.rest.v1.model.modules.UpgradeStatusModel)1 MappingJacksonValue (org.springframework.http.converter.json.MappingJacksonValue)1