Search in sources :

Example 6 with RestProcessResult

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();
}
Also used : RestProcessResult(com.serotonin.m2m2.web.mvc.rest.v1.message.RestProcessResult) MailingList(com.serotonin.m2m2.vo.mailingList.MailingList) MailingListModel(com.serotonin.m2m2.web.mvc.rest.v1.model.email.MailingListModel) ApiOperation(com.wordnik.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 7 with RestProcessResult

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();
}
Also used : RestProcessResult(com.serotonin.m2m2.web.mvc.rest.v1.message.RestProcessResult) MailingList(com.serotonin.m2m2.vo.mailingList.MailingList) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) MailingList(com.serotonin.m2m2.vo.mailingList.MailingList) List(java.util.List) MailingListModel(com.serotonin.m2m2.web.mvc.rest.v1.model.email.MailingListModel) ApiOperation(com.wordnik.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 8 with RestProcessResult

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();
}
Also used : RestProcessResult(com.serotonin.m2m2.web.mvc.rest.v1.message.RestProcessResult) User(com.serotonin.m2m2.vo.User) JsonString(com.serotonin.json.type.JsonString) TranslatableMessage(com.serotonin.m2m2.i18n.TranslatableMessage) ApiOperation(com.wordnik.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 9 with RestProcessResult

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();
}
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 10 with RestProcessResult

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

Aggregations

RestProcessResult (com.serotonin.m2m2.web.mvc.rest.v1.message.RestProcessResult)132 ApiOperation (com.wordnik.swagger.annotations.ApiOperation)125 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)125 User (com.serotonin.m2m2.vo.User)113 TranslatableMessage (com.serotonin.m2m2.i18n.TranslatableMessage)33 ArrayList (java.util.ArrayList)30 PermissionException (com.serotonin.m2m2.vo.permission.PermissionException)29 DataPointVO (com.serotonin.m2m2.vo.DataPointVO)28 List (java.util.List)27 InvalidRQLRestException (com.infiniteautomation.mango.rest.v2.exception.InvalidRQLRestException)23 ASTNode (net.jazdw.rql.parser.ASTNode)23 RestValidationFailedException (com.serotonin.m2m2.web.mvc.rest.v1.exception.RestValidationFailedException)22 URI (java.net.URI)18 NotFoundRestException (com.infiniteautomation.mango.rest.v2.exception.NotFoundRestException)15 HashMap (java.util.HashMap)14 ApiResponses (com.wordnik.swagger.annotations.ApiResponses)13 ValidationFailedRestException (com.infiniteautomation.mango.rest.v2.exception.ValidationFailedRestException)11 RTException (com.serotonin.m2m2.rt.RTException)11 DataPointModel (com.serotonin.m2m2.web.mvc.rest.v1.model.DataPointModel)11 QueryDataPageStream (com.serotonin.m2m2.web.mvc.rest.v1.model.QueryDataPageStream)11