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();
}
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;
}
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();
}
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();
}
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);
}
Aggregations