Search in sources :

Example 11 with ApiResponses

use of com.wordnik.swagger.annotations.ApiResponses in project ma-core-public by infiniteautomation.

the class MangoDemoRestController method getAllDemos.

@ApiOperation(value = "Get all demos", notes = "Notes for getting all demos")
@ApiResponses(value = { @ApiResponse(code = 200, message = "Ok"), @ApiResponse(code = 403, message = "User does not have access") })
@RequestMapping(method = RequestMethod.GET, produces = { "application/json", "text/csv" }, value = "/list")
public ResponseEntity<List<DemoModel>> getAllDemos(HttpServletRequest request, @ApiParam(value = "Limit the number of results", required = false) @RequestParam(value = "limit", required = false, defaultValue = "100") int limit) {
    RestProcessResult<List<DemoModel>> result = new RestProcessResult<List<DemoModel>>(HttpStatus.OK);
    this.checkUser(request, result);
    if (result.isOk()) {
        ASTNode root = new ASTNode("limit", limit);
        List<DemoModel> models = queryStore(root);
        return result.createResponseEntity(models);
    }
    return result.createResponseEntity();
}
Also used : DemoModel(com.serotonin.m2m2.web.mvc.rest.v1.model.DemoModel) RestProcessResult(com.serotonin.m2m2.web.mvc.rest.v1.message.RestProcessResult) ASTNode(net.jazdw.rql.parser.ASTNode) ArrayList(java.util.ArrayList) List(java.util.List) ApiOperation(com.wordnik.swagger.annotations.ApiOperation) ApiResponses(com.wordnik.swagger.annotations.ApiResponses) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 12 with ApiResponses

use of com.wordnik.swagger.annotations.ApiResponses in project ma-modules-public by infiniteautomation.

the class WatchListRestController method queryRQL.

@ApiOperation(value = "Query WatchLists", notes = "", response = WatchListSummaryModel.class, responseContainer = "Array")
@ApiResponses(value = { @ApiResponse(code = 200, message = "Ok", response = WatchListSummaryModel.class), @ApiResponse(code = 403, message = "User does not have access", response = ResponseEntity.class) })
@RequestMapping(method = RequestMethod.GET, produces = { "application/json" })
public ResponseEntity<QueryDataPageStream<WatchListVO>> queryRQL(HttpServletRequest request) {
    RestProcessResult<QueryDataPageStream<WatchListVO>> result = new RestProcessResult<QueryDataPageStream<WatchListVO>>(HttpStatus.OK);
    User user = this.checkUser(request, result);
    if (result.isOk()) {
        try {
            ASTNode query = parseRQLtoAST(request.getQueryString());
            if (!user.isAdmin()) {
                // We are going to filter the results, so we need to strip out the limit(limit,offset) or limit(limit) clause.
                WatchListStreamCallback callback = new WatchListStreamCallback(this, user);
                FilteredPageQueryStream<WatchListVO, WatchListSummaryModel, WatchListDao> stream = new FilteredPageQueryStream<WatchListVO, WatchListSummaryModel, WatchListDao>(WatchListDao.instance, this, query, callback);
                stream.setupQuery();
                return result.createResponseEntity(stream);
            } else
                return result.createResponseEntity(getPageStream(query));
        } catch (InvalidRQLRestException e) {
            LOG.error(e.getMessage(), e);
            result.addRestMessage(getInternalServerErrorMessage(e.getMessage()));
            return result.createResponseEntity();
        }
    }
    return result.createResponseEntity();
}
Also used : RestProcessResult(com.serotonin.m2m2.web.mvc.rest.v1.message.RestProcessResult) QueryDataPageStream(com.serotonin.m2m2.web.mvc.rest.v1.model.QueryDataPageStream) User(com.serotonin.m2m2.vo.User) InvalidRQLRestException(com.infiniteautomation.mango.rest.v2.exception.InvalidRQLRestException) WatchListDao(com.serotonin.m2m2.watchlist.WatchListDao) WatchListSummaryModel(com.serotonin.m2m2.web.mvc.rest.v1.model.WatchListSummaryModel) ASTNode(net.jazdw.rql.parser.ASTNode) FilteredPageQueryStream(com.serotonin.m2m2.web.mvc.rest.v1.model.FilteredPageQueryStream) WatchListVO(com.serotonin.m2m2.watchlist.WatchListVO) ApiOperation(com.wordnik.swagger.annotations.ApiOperation) ApiResponses(com.wordnik.swagger.annotations.ApiResponses) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 13 with ApiResponses

use of com.wordnik.swagger.annotations.ApiResponses in project ma-modules-public by infiniteautomation.

the class WatchListRestController method createNew.

@ApiOperation(value = "Create New WatchList", notes = "", response = WatchListModel.class)
@ApiResponses({ @ApiResponse(code = 201, message = "User Created", response = WatchListModel.class), @ApiResponse(code = 401, message = "Unauthorized Access", response = ResponseEntity.class), @ApiResponse(code = 409, message = "WatchList Already Exists") })
@RequestMapping(method = RequestMethod.POST, consumes = { "application/json", "text/csv" }, produces = { "application/json", "text/csv" })
public ResponseEntity<WatchListModel> createNew(@ApiParam(value = "Watchlist to save", required = true) @RequestBody WatchListModel model, UriComponentsBuilder builder, HttpServletRequest request) throws RestValidationFailedException {
    RestProcessResult<WatchListModel> result = new RestProcessResult<WatchListModel>(HttpStatus.CREATED);
    User user = this.checkUser(request, result);
    if (!result.isOk()) {
        return result.createResponseEntity();
    }
    WatchListVO wl = model.getData();
    // Check XID if blank and generate one
    if (StringUtils.isBlank(wl.getXid())) {
        wl.setXid(this.dao.generateUniqueXid());
    }
    // Add the user
    wl.setUserId(user.getId());
    // Setup the Points
    if (model.getPoints() != null)
        for (WatchListDataPointModel pm : model.getPoints()) wl.getPointList().add(pm.getDataPointVO());
    // Ready to validate and then save
    if (!model.validate()) {
        result.addRestMessage(this.getValidationFailedError());
        return result.createResponseEntity(model);
    }
    try {
        String initiatorId = request.getHeader("initiatorId");
        this.dao.save(wl, initiatorId);
    } catch (Exception e) {
        LOG.error(e.getMessage(), e);
        result.addRestMessage(getInternalServerErrorMessage(e.getMessage()));
    }
    return result.createResponseEntity(new WatchListModel(wl, this.dao.getPointSummaries(wl.getId())));
}
Also used : RestProcessResult(com.serotonin.m2m2.web.mvc.rest.v1.message.RestProcessResult) WatchListDataPointModel(com.serotonin.m2m2.web.mvc.rest.v1.model.WatchListDataPointModel) User(com.serotonin.m2m2.vo.User) WatchListModel(com.serotonin.m2m2.web.mvc.rest.v1.model.WatchListModel) RestValidationFailedException(com.serotonin.m2m2.web.mvc.rest.v1.exception.RestValidationFailedException) InvalidRQLRestException(com.infiniteautomation.mango.rest.v2.exception.InvalidRQLRestException) IOException(java.io.IOException) WatchListVO(com.serotonin.m2m2.watchlist.WatchListVO) ApiOperation(com.wordnik.swagger.annotations.ApiOperation) ApiResponses(com.wordnik.swagger.annotations.ApiResponses) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 14 with ApiResponses

use of com.wordnik.swagger.annotations.ApiResponses in project ma-modules-public by infiniteautomation.

the class JsonDataRestController method deletePartialJsonData.

@ApiOperation(value = "Partially Delete JSON Data", notes = "{path} is the path to data with dots data.member.submember", response = JsonDataModel.class)
@ApiResponses({ @ApiResponse(code = 201, message = "Data Deleted", response = JsonDataModel.class), @ApiResponse(code = 401, message = "Unauthorized Access", response = ResponseEntity.class), @ApiResponse(code = 403, message = "Data Doesn't Exists") })
@RequestMapping(method = RequestMethod.DELETE, value = "/{xid}/{path:.*}")
public ResponseEntity<JsonDataModel> deletePartialJsonData(@ApiParam(value = "XID", required = true, allowMultiple = false) @PathVariable String xid, @ApiParam(value = "Data path using dots as separator", required = true, allowMultiple = false) @PathVariable String path, UriComponentsBuilder builder, HttpServletRequest request) throws RestValidationFailedException {
    RestProcessResult<JsonDataModel> result = new RestProcessResult<JsonDataModel>(HttpStatus.OK);
    User user = this.checkUser(request, result);
    if (result.isOk()) {
        JsonDataVO vo = this.dao.getByXid(xid);
        if (vo != null) {
            // Check existing permissions
            if (!Permissions.hasPermission(user, vo.getEditPermission())) {
                result.addRestMessage(getUnauthorizedMessage());
                return result.createResponseEntity();
            }
            JsonDataModel model = new JsonDataModel(vo);
            String[] pathParts;
            if (path == null || (pathParts = path.split("\\.")).length == 0) {
                // Delete the whole thing
                this.dao.delete(vo.getId());
            } else {
                // Delete something from the map
                JsonNode existingData = (JsonNode) vo.getJsonData();
                boolean deleted = deleteNode(existingData, pathParts);
                if (!deleted) {
                    result.addRestMessage(getDoesNotExistMessage());
                    return result.createResponseEntity();
                }
                if (!model.validate()) {
                    result.addRestMessage(this.getValidationFailedError());
                    return result.createResponseEntity(model);
                }
                try {
                    String initiatorId = request.getHeader("initiatorId");
                    this.dao.save(vo, initiatorId);
                } catch (Exception e) {
                    LOG.error(e.getMessage(), e);
                    result.addRestMessage(getInternalServerErrorMessage(e.getMessage()));
                }
            }
            return result.createResponseEntity(model);
        } else {
            result.addRestMessage(getDoesNotExistMessage());
        }
    }
    return result.createResponseEntity();
}
Also used : RestProcessResult(com.serotonin.m2m2.web.mvc.rest.v1.message.RestProcessResult) User(com.serotonin.m2m2.vo.User) JsonDataVO(com.serotonin.m2m2.vo.json.JsonDataVO) JsonDataModel(com.serotonin.m2m2.web.mvc.rest.v1.model.jsondata.JsonDataModel) JsonNode(com.fasterxml.jackson.databind.JsonNode) BadRequestException(com.infiniteautomation.mango.rest.v2.exception.BadRequestException) RestValidationFailedException(com.serotonin.m2m2.web.mvc.rest.v1.exception.RestValidationFailedException) NotFoundRestException(com.infiniteautomation.mango.rest.v2.exception.NotFoundRestException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ApiOperation(com.wordnik.swagger.annotations.ApiOperation) ApiResponses(com.wordnik.swagger.annotations.ApiResponses) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 15 with ApiResponses

use of com.wordnik.swagger.annotations.ApiResponses in project ma-modules-public by infiniteautomation.

the class UserRestController method queryRQL.

@ApiOperation(value = "Query Users", notes = "", response = UserModel.class, responseContainer = "Array")
@ApiResponses(value = { @ApiResponse(code = 200, message = "Ok", response = UserModel.class), @ApiResponse(code = 403, message = "User does not have access", response = ResponseEntity.class) })
@RequestMapping(method = RequestMethod.GET, produces = { "application/json" })
public ResponseEntity<QueryDataPageStream<User>> queryRQL(HttpServletRequest request) {
    RestProcessResult<QueryDataPageStream<User>> result = new RestProcessResult<QueryDataPageStream<User>>(HttpStatus.OK);
    User user = this.checkUser(request, result);
    if (result.isOk()) {
        try {
            // Parse the RQL Query
            ASTNode query = parseRQLtoAST(request.getQueryString());
            if (!user.isAdmin()) {
                query = addAndRestriction(query, new ASTNode("eq", "id", user.getId()));
            }
            return result.createResponseEntity(getPageStream(query));
        } catch (InvalidRQLRestException e) {
            LOG.error(e.getMessage(), e);
            result.addRestMessage(getInternalServerErrorMessage(e.getMessage()));
            return result.createResponseEntity();
        }
    }
    return result.createResponseEntity();
}
Also used : RestProcessResult(com.serotonin.m2m2.web.mvc.rest.v1.message.RestProcessResult) QueryDataPageStream(com.serotonin.m2m2.web.mvc.rest.v1.model.QueryDataPageStream) User(com.serotonin.m2m2.vo.User) InvalidRQLRestException(com.infiniteautomation.mango.rest.v2.exception.InvalidRQLRestException) ASTNode(net.jazdw.rql.parser.ASTNode) ApiOperation(com.wordnik.swagger.annotations.ApiOperation) ApiResponses(com.wordnik.swagger.annotations.ApiResponses) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

ApiResponses (com.wordnik.swagger.annotations.ApiResponses)47 ApiOperation (com.wordnik.swagger.annotations.ApiOperation)44 Path (javax.ws.rs.Path)21 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)19 Produces (javax.ws.rs.Produces)17 POST (javax.ws.rs.POST)14 RestProcessResult (com.serotonin.m2m2.web.mvc.rest.v1.message.RestProcessResult)13 IOException (java.io.IOException)10 User (com.serotonin.m2m2.vo.User)9 Consumes (javax.ws.rs.Consumes)9 GET (javax.ws.rs.GET)9 ArrayList (java.util.ArrayList)8 WebApplicationException (javax.ws.rs.WebApplicationException)8 CertificateEncodingException (java.security.cert.CertificateEncodingException)6 GluuSAMLTrustRelationship (org.gluu.oxtrust.model.GluuSAMLTrustRelationship)6 BaseMappingException (org.gluu.persist.exception.mapping.BaseMappingException)6 TranslatableMessage (com.serotonin.m2m2.i18n.TranslatableMessage)5 ResponseEntity (org.springframework.http.ResponseEntity)5 SingularityRequestWithState (com.hubspot.singularity.SingularityRequestWithState)4 InvalidRQLRestException (com.infiniteautomation.mango.rest.v2.exception.InvalidRQLRestException)4