use of com.serotonin.m2m2.web.mvc.rest.v1.message.RestProcessResult in project ma-modules-public by infiniteautomation.
the class MailingListRestController method get.
@ApiOperation(value = "Get Mailing List by XID", notes = "Returns a Mailing List")
@RequestMapping(method = RequestMethod.GET, produces = { "application/json", "text/csv" }, value = "/{xid}")
public ResponseEntity<MailingListModel> get(@ApiParam(value = "Valid mailing list xid", required = true, allowMultiple = false) @PathVariable String xid, HttpServletRequest request) {
RestProcessResult<MailingListModel> result = new RestProcessResult<MailingListModel>(HttpStatus.OK);
this.checkUser(request, result);
if (result.isOk()) {
MailingList list = this.dao.getMailingList(xid);
if (list != null) {
MailingListModel model = new MailingListModel(list);
return result.createResponseEntity(model);
} else {
result.addRestMessage(getDoesNotExistMessage());
}
}
return result.createResponseEntity();
}
use of com.serotonin.m2m2.web.mvc.rest.v1.message.RestProcessResult in project ma-modules-public by infiniteautomation.
the class MailingListRestController method getAll.
@ApiOperation(value = "Get Mailing List", notes = "Returns all Mailing Lists, eventually will be RQL endpoint")
@RequestMapping(method = RequestMethod.GET, produces = { "application/json", "text/csv" })
public ResponseEntity<List<MailingListModel>> getAll(HttpServletRequest request) {
RestProcessResult<List<MailingListModel>> result = new RestProcessResult<List<MailingListModel>>(HttpStatus.OK);
this.checkUser(request, result);
if (result.isOk()) {
List<MailingList> lists = this.dao.getMailingLists();
if (lists != null) {
List<MailingListModel> models = new ArrayList<MailingListModel>();
for (MailingList list : lists) {
models.add(new MailingListModel(list));
}
return result.createResponseEntity(models);
} else {
result.addRestMessage(getDoesNotExistMessage());
}
}
return result.createResponseEntity();
}
use of com.serotonin.m2m2.web.mvc.rest.v1.message.RestProcessResult in project ma-modules-public by infiniteautomation.
the class ModulesRestController method upgrade.
@ApiOperation(value = "Download Upgrades and optionally backup and restart", notes = "Use Modules web socket to track progress")
@RequestMapping(method = RequestMethod.POST, consumes = { "application/json" }, produces = { "application/json" }, value = "/upgrade")
public ResponseEntity<Void> upgrade(@ApiParam(value = "Perform Backup first", required = false, defaultValue = "false", allowMultiple = false) @RequestParam(required = false, defaultValue = "false") boolean backup, @ApiParam(value = "Restart when completed", required = false, defaultValue = "false", allowMultiple = false) @RequestParam(required = false, defaultValue = "false") boolean restart, @ApiParam(value = "Desired Upgrades", required = true) @RequestBody(required = true) ModuleUpgradesModel model, UriComponentsBuilder builder, HttpServletRequest request) {
RestProcessResult<Void> result = new RestProcessResult<Void>(HttpStatus.OK);
User user = this.checkUser(request, result);
if (result.isOk()) {
if (user.isAdmin()) {
// Start Downloads
String status = ModulesDwr.startDownloads(model.fullModulesList(), backup, restart);
if (status == null) {
return result.createResponseEntity();
} else {
result.addRestMessage(HttpStatus.NOT_MODIFIED, new TranslatableMessage("common.default", status));
}
} else {
result.addRestMessage(this.getUnauthorizedMessage());
}
}
return result.createResponseEntity();
}
use of com.serotonin.m2m2.web.mvc.rest.v1.message.RestProcessResult 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.message.RestProcessResult 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();
}
Aggregations