use of com.serotonin.m2m2.web.mvc.rest.v1.model.modules.UpgradeStatusModel 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();
}
Aggregations