Search in sources :

Example 6 with InvalidRQLRestException

use of com.infiniteautomation.mango.rest.v2.exception.InvalidRQLRestException 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)

Example 7 with InvalidRQLRestException

use of com.infiniteautomation.mango.rest.v2.exception.InvalidRQLRestException in project ma-modules-public by infiniteautomation.

the class AuditRestController method queryRQL.

@ApiOperation(value = "Query Audit Events", notes = "Admin access only", response = AuditEventInstanceModel.class, responseContainer = "Array")
@RequestMapping(method = RequestMethod.GET)
public ResponseEntity<PageQueryStream<AuditEventInstanceVO, AuditEventInstanceModel, AuditEventDao>> queryRQL(HttpServletRequest request) {
    RestProcessResult<PageQueryStream<AuditEventInstanceVO, AuditEventInstanceModel, AuditEventDao>> result = new RestProcessResult<PageQueryStream<AuditEventInstanceVO, AuditEventInstanceModel, AuditEventDao>>(HttpStatus.OK);
    User user = this.checkUser(request, result);
    if (result.isOk()) {
        try {
            if (!user.isAdmin()) {
                result.addRestMessage(getUnauthorizedMessage());
                return result.createResponseEntity();
            } else {
                // Limit our results based on the fact that our permissions should be in the permissions strings
                ASTNode root = parseRQLtoAST(request.getQueryString());
                return result.createResponseEntity(getPageStream(root));
            }
        } catch (InvalidRQLRestException e) {
            result.addRestMessage(getInternalServerErrorMessage(e.getMessage()));
            return result.createResponseEntity();
        }
    }
    return result.createResponseEntity();
}
Also used : AuditEventInstanceModel(com.serotonin.m2m2.web.mvc.rest.v1.model.audit.AuditEventInstanceModel) RestProcessResult(com.serotonin.m2m2.web.mvc.rest.v1.message.RestProcessResult) User(com.serotonin.m2m2.vo.User) InvalidRQLRestException(com.infiniteautomation.mango.rest.v2.exception.InvalidRQLRestException) ASTNode(net.jazdw.rql.parser.ASTNode) AuditEventDao(com.serotonin.m2m2.db.dao.AuditEventDao) PageQueryStream(com.serotonin.m2m2.web.mvc.rest.v1.model.PageQueryStream) AuditEventInstanceVO(com.serotonin.m2m2.vo.event.audit.AuditEventInstanceVO) ApiOperation(com.wordnik.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 8 with InvalidRQLRestException

use of com.infiniteautomation.mango.rest.v2.exception.InvalidRQLRestException in project ma-modules-public by infiniteautomation.

the class DataPointRestController method bulkClearSetPermissions.

@ApiOperation(value = "Bulk Clear Set Permissions", notes = "", response = Long.class)
@RequestMapping(method = RequestMethod.POST, consumes = { "application/json" }, produces = { "application/json" }, value = "/bulk-clear-set-permissions")
public ResponseEntity<Long> bulkClearSetPermissions(HttpServletRequest request) {
    RestProcessResult<Long> result = new RestProcessResult<Long>(HttpStatus.OK);
    User user = this.checkUser(request, result);
    if (result.isOk()) {
        if (!user.isAdmin()) {
            LOG.warn("User " + user.getUsername() + " attempted to clear bulk permissions");
            result.addRestMessage(getUnauthorizedMessage());
            return result.createResponseEntity();
        }
        try {
            ASTNode node = parseRQLtoAST(request.getQueryString());
            long changed = this.dao.bulkClearPermissions(node, true);
            return result.createResponseEntity(changed);
        } 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) 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) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 9 with InvalidRQLRestException

use of com.infiniteautomation.mango.rest.v2.exception.InvalidRQLRestException in project ma-modules-public by infiniteautomation.

the class DataPointRestController method bulkClearReadPermissions.

@ApiOperation(value = "Bulk Clear Read Permissions", notes = "", response = Long.class)
@RequestMapping(method = RequestMethod.POST, consumes = { "application/json" }, produces = { "application/json" }, value = "/bulk-clear-read-permissions")
public ResponseEntity<Long> bulkClearReadPermissions(HttpServletRequest request) {
    RestProcessResult<Long> result = new RestProcessResult<Long>(HttpStatus.OK);
    User user = this.checkUser(request, result);
    if (result.isOk()) {
        if (!user.isAdmin()) {
            LOG.warn("User " + user.getUsername() + " attempted to clear bulk permissions");
            result.addRestMessage(getUnauthorizedMessage());
            return result.createResponseEntity();
        }
        try {
            ASTNode node = parseRQLtoAST(request.getQueryString());
            long changed = this.dao.bulkClearPermissions(node, false);
            return result.createResponseEntity(changed);
        } 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) 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) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 10 with InvalidRQLRestException

use of com.infiniteautomation.mango.rest.v2.exception.InvalidRQLRestException in project ma-modules-public by infiniteautomation.

the class DataPointRestController method bulkApplySetPermissions.

@ApiOperation(value = "Bulk Update Set Permissions", notes = "", response = Long.class)
@RequestMapping(method = RequestMethod.POST, consumes = { "application/json" }, produces = { "application/json" }, value = "/bulk-apply-set-permissions")
public ResponseEntity<Long> bulkApplySetPermissions(@ApiParam(value = "Permissions", required = true) @RequestBody(required = true) String permissions, HttpServletRequest request) {
    RestProcessResult<Long> result = new RestProcessResult<Long>(HttpStatus.OK);
    User user = this.checkUser(request, result);
    if (result.isOk()) {
        if (!user.isAdmin()) {
            LOG.warn("User " + user.getUsername() + " attempted to set bulk permissions");
            result.addRestMessage(getUnauthorizedMessage());
            return result.createResponseEntity();
        }
        try {
            ASTNode node = parseRQLtoAST(request.getQueryString());
            long changed = this.dao.bulkUpdatePermissions(node, permissions, true);
            return result.createResponseEntity(changed);
        } 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) 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) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

InvalidRQLRestException (com.infiniteautomation.mango.rest.v2.exception.InvalidRQLRestException)16 RestProcessResult (com.serotonin.m2m2.web.mvc.rest.v1.message.RestProcessResult)16 ApiOperation (com.wordnik.swagger.annotations.ApiOperation)16 ASTNode (net.jazdw.rql.parser.ASTNode)16 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)16 User (com.serotonin.m2m2.vo.User)13 QueryDataPageStream (com.serotonin.m2m2.web.mvc.rest.v1.model.QueryDataPageStream)8 FilteredPageQueryStream (com.serotonin.m2m2.web.mvc.rest.v1.model.FilteredPageQueryStream)3 DataPointVO (com.serotonin.m2m2.vo.DataPointVO)2 ApiResponses (com.wordnik.swagger.annotations.ApiResponses)2 AuditEventDao (com.serotonin.m2m2.db.dao.AuditEventDao)1 DataPointDao (com.serotonin.m2m2.db.dao.DataPointDao)1 EventHandlerDao (com.serotonin.m2m2.db.dao.EventHandlerDao)1 TranslatableMessage (com.serotonin.m2m2.i18n.TranslatableMessage)1 UserCommentVO (com.serotonin.m2m2.vo.comment.UserCommentVO)1 DataSourceVO (com.serotonin.m2m2.vo.dataSource.DataSourceVO)1 AbstractEventHandlerVO (com.serotonin.m2m2.vo.event.AbstractEventHandlerVO)1 EventInstanceVO (com.serotonin.m2m2.vo.event.EventInstanceVO)1 AuditEventInstanceVO (com.serotonin.m2m2.vo.event.audit.AuditEventInstanceVO)1 WatchListDao (com.serotonin.m2m2.watchlist.WatchListDao)1