Search in sources :

Example 1 with RQLToObjectListQuery

use of com.infiniteautomation.mango.db.query.pojo.RQLToObjectListQuery in project ma-modules-public by infiniteautomation.

the class DataPointRestController method getBulkDataPointOperations.

@ApiOperation(value = "Get a list of current bulk data point operations", notes = "User can only get their own bulk data point operations unless they are an admin")
@RequestMapping(method = RequestMethod.GET, value = "/bulk")
public MappingJacksonValue getBulkDataPointOperations(@AuthenticationPrincipal User user, HttpServletRequest request) {
    List<TemporaryResource<DataPointBulkResponse, AbstractRestV2Exception>> preFiltered = this.bulkResourceManager.list().stream().filter((tr) -> user.isAdmin() || user.getId() == tr.getUserId()).collect(Collectors.toList());
    List<TemporaryResource<DataPointBulkResponse, AbstractRestV2Exception>> results = preFiltered;
    ASTNode query = BaseMangoRestController.parseRQLtoAST(request.getQueryString());
    if (query != null) {
        results = query.accept(new RQLToObjectListQuery<TemporaryResource<DataPointBulkResponse, AbstractRestV2Exception>>(), preFiltered);
    }
    PageQueryResultModel<TemporaryResource<DataPointBulkResponse, AbstractRestV2Exception>> result = new PageQueryResultModel<>(results, preFiltered.size());
    // hide result property by setting a view
    MappingJacksonValue resultWithView = new MappingJacksonValue(result);
    resultWithView.setSerializationView(Object.class);
    return resultWithView;
}
Also used : BadRequestException(com.infiniteautomation.mango.rest.v2.exception.BadRequestException) PathVariable(org.springframework.web.bind.annotation.PathVariable) UriComponentsBuilder(org.springframework.web.util.UriComponentsBuilder) DataSourceVO(com.serotonin.m2m2.vo.dataSource.DataSourceVO) RequestParam(org.springframework.web.bind.annotation.RequestParam) DataSourceDao(com.serotonin.m2m2.db.dao.DataSourceDao) DataPointVO(com.serotonin.m2m2.vo.DataPointVO) ApiParam(com.wordnik.swagger.annotations.ApiParam) DataPointDao(com.serotonin.m2m2.db.dao.DataPointDao) VoIndividualRequest(com.infiniteautomation.mango.rest.v2.bulk.VoIndividualRequest) URI(java.net.URI) ConditionSortLimitWithTagKeys(com.infiniteautomation.mango.db.query.ConditionSortLimitWithTagKeys) BaseMangoRestController(com.serotonin.m2m2.web.mvc.rest.BaseMangoRestController) TemporaryResourceWebSocketHandler(com.infiniteautomation.mango.rest.v2.temporaryResource.TemporaryResourceWebSocketHandler) HttpHeaders(org.springframework.http.HttpHeaders) ApiOperation(com.wordnik.swagger.annotations.ApiOperation) RequestMethod(org.springframework.web.bind.annotation.RequestMethod) TranslatableMessage(com.serotonin.m2m2.i18n.TranslatableMessage) VoAction(com.infiniteautomation.mango.rest.v2.bulk.VoAction) Collectors(java.util.stream.Collectors) RestController(org.springframework.web.bind.annotation.RestController) ModuleRegistry(com.serotonin.m2m2.module.ModuleRegistry) StreamedArrayWithTotal(com.infiniteautomation.mango.rest.v2.model.StreamedArrayWithTotal) List(java.util.List) Permissions(com.serotonin.m2m2.vo.permission.Permissions) ASTNode(net.jazdw.rql.parser.ASTNode) TemporaryResourceManager(com.infiniteautomation.mango.rest.v2.temporaryResource.TemporaryResourceManager) VoIndividualResponse(com.infiniteautomation.mango.rest.v2.bulk.VoIndividualResponse) DataPointModel(com.infiniteautomation.mango.rest.v2.model.dataPoint.DataPointModel) LogFactory(org.apache.commons.logging.LogFactory) BulkRequest(com.infiniteautomation.mango.rest.v2.bulk.BulkRequest) BulkResponse(com.infiniteautomation.mango.rest.v2.bulk.BulkResponse) TemporaryResourceWebSocketDefinition(com.serotonin.m2m2.web.mvc.rest.v1.publisher.TemporaryResourceWebSocketDefinition) User(com.serotonin.m2m2.vo.User) RQLToObjectListQuery(com.infiniteautomation.mango.db.query.pojo.RQLToObjectListQuery) AbstractRestV2Exception(com.infiniteautomation.mango.rest.v2.exception.AbstractRestV2Exception) TemporaryResourceStatusUpdate(com.infiniteautomation.mango.rest.v2.temporaryResource.TemporaryResourceStatusUpdate) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) RequestBody(org.springframework.web.bind.annotation.RequestBody) TemplateDao(com.serotonin.m2m2.db.dao.TemplateDao) HttpServletRequest(javax.servlet.http.HttpServletRequest) Api(com.wordnik.swagger.annotations.Api) MappingJacksonValue(org.springframework.http.converter.json.MappingJacksonValue) AccessDeniedException(com.infiniteautomation.mango.rest.v2.exception.AccessDeniedException) DataPointPropertiesTemplateVO(com.serotonin.m2m2.vo.template.DataPointPropertiesTemplateVO) Common(com.serotonin.m2m2.Common) TemporaryResourceStatus(com.infiniteautomation.mango.rest.v2.temporaryResource.TemporaryResource.TemporaryResourceStatus) DataPointFilter(com.serotonin.m2m2.web.mvc.rest.v1.model.dataPoint.DataPointFilter) TemporaryResource(com.infiniteautomation.mango.rest.v2.temporaryResource.TemporaryResource) HttpStatus(org.springframework.http.HttpStatus) PageQueryResultModel(com.serotonin.m2m2.web.mvc.rest.v1.model.PageQueryResultModel) StreamedVOQueryWithTotal(com.infiniteautomation.mango.rest.v2.model.StreamedVOQueryWithTotal) AuthenticationPrincipal(org.springframework.security.core.annotation.AuthenticationPrincipal) Log(org.apache.commons.logging.Log) ResponseEntity(org.springframework.http.ResponseEntity) MangoTaskTemporaryResourceManager(com.infiniteautomation.mango.rest.v2.temporaryResource.MangoTaskTemporaryResourceManager) NotFoundRestException(com.infiniteautomation.mango.rest.v2.exception.NotFoundRestException) ASTNode(net.jazdw.rql.parser.ASTNode) AbstractRestV2Exception(com.infiniteautomation.mango.rest.v2.exception.AbstractRestV2Exception) TemporaryResource(com.infiniteautomation.mango.rest.v2.temporaryResource.TemporaryResource) MappingJacksonValue(org.springframework.http.converter.json.MappingJacksonValue) RQLToObjectListQuery(com.infiniteautomation.mango.db.query.pojo.RQLToObjectListQuery) PageQueryResultModel(com.serotonin.m2m2.web.mvc.rest.v1.model.PageQueryResultModel) ApiOperation(com.wordnik.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with RQLToObjectListQuery

use of com.infiniteautomation.mango.db.query.pojo.RQLToObjectListQuery in project ma-modules-public by infiniteautomation.

the class DataPointTagsRestController method getBulkDataPointTagOperations.

@ApiOperation(value = "Get a list of current bulk tag operations", notes = "User can only get their own bulk tag operations unless they are an admin")
@RequestMapping(method = RequestMethod.GET, value = "/bulk")
public MappingJacksonValue getBulkDataPointTagOperations(@AuthenticationPrincipal User user, HttpServletRequest request) {
    List<TemporaryResource<TagBulkResponse, AbstractRestV2Exception>> preFiltered = this.bulkResourceManager.list().stream().filter((tr) -> user.isAdmin() || user.getId() == tr.getUserId()).collect(Collectors.toList());
    List<TemporaryResource<TagBulkResponse, AbstractRestV2Exception>> results = preFiltered;
    ASTNode query = BaseMangoRestController.parseRQLtoAST(request.getQueryString());
    if (query != null) {
        results = query.accept(new RQLToObjectListQuery<TemporaryResource<TagBulkResponse, AbstractRestV2Exception>>(), preFiltered);
    }
    PageQueryResultModel<TemporaryResource<TagBulkResponse, AbstractRestV2Exception>> result = new PageQueryResultModel<>(results, preFiltered.size());
    // hide result property by setting a view
    MappingJacksonValue resultWithView = new MappingJacksonValue(result);
    resultWithView.setSerializationView(Object.class);
    return resultWithView;
}
Also used : BadRequestException(com.infiniteautomation.mango.rest.v2.exception.BadRequestException) PathVariable(org.springframework.web.bind.annotation.PathVariable) UriComponentsBuilder(org.springframework.web.util.UriComponentsBuilder) RQLToObjectListQuery(com.infiniteautomation.mango.db.query.pojo.RQLToObjectListQuery) AbstractRestV2Exception(com.infiniteautomation.mango.rest.v2.exception.AbstractRestV2Exception) TemporaryResourceStatusUpdate(com.infiniteautomation.mango.rest.v2.temporaryResource.TemporaryResourceStatusUpdate) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) HashMap(java.util.HashMap) DataPointVO(com.serotonin.m2m2.vo.DataPointVO) RequestBody(org.springframework.web.bind.annotation.RequestBody) ApiParam(com.wordnik.swagger.annotations.ApiParam) HttpServletRequest(javax.servlet.http.HttpServletRequest) DataPointDao(com.serotonin.m2m2.db.dao.DataPointDao) Map(java.util.Map) Api(com.wordnik.swagger.annotations.Api) MappingJacksonValue(org.springframework.http.converter.json.MappingJacksonValue) AccessDeniedException(com.infiniteautomation.mango.rest.v2.exception.AccessDeniedException) BaseMangoRestController(com.serotonin.m2m2.web.mvc.rest.BaseMangoRestController) TemporaryResourceWebSocketHandler(com.infiniteautomation.mango.rest.v2.temporaryResource.TemporaryResourceWebSocketHandler) DataPointTagsDao(com.serotonin.m2m2.db.dao.DataPointTagsDao) HttpHeaders(org.springframework.http.HttpHeaders) ApiOperation(com.wordnik.swagger.annotations.ApiOperation) Set(java.util.Set) RequestMethod(org.springframework.web.bind.annotation.RequestMethod) TranslatableMessage(com.serotonin.m2m2.i18n.TranslatableMessage) IndividualRequest(com.infiniteautomation.mango.rest.v2.bulk.IndividualRequest) TemporaryResourceStatus(com.infiniteautomation.mango.rest.v2.temporaryResource.TemporaryResource.TemporaryResourceStatus) Collectors(java.util.stream.Collectors) RestController(org.springframework.web.bind.annotation.RestController) ModuleRegistry(com.serotonin.m2m2.module.ModuleRegistry) TemporaryResource(com.infiniteautomation.mango.rest.v2.temporaryResource.TemporaryResource) HttpStatus(org.springframework.http.HttpStatus) List(java.util.List) PageQueryResultModel(com.serotonin.m2m2.web.mvc.rest.v1.model.PageQueryResultModel) Permissions(com.serotonin.m2m2.vo.permission.Permissions) ASTNode(net.jazdw.rql.parser.ASTNode) Entry(java.util.Map.Entry) AuthenticationPrincipal(org.springframework.security.core.annotation.AuthenticationPrincipal) TemporaryResourceManager(com.infiniteautomation.mango.rest.v2.temporaryResource.TemporaryResourceManager) ResponseEntity(org.springframework.http.ResponseEntity) MangoTaskTemporaryResourceManager(com.infiniteautomation.mango.rest.v2.temporaryResource.MangoTaskTemporaryResourceManager) BulkRequest(com.infiniteautomation.mango.rest.v2.bulk.BulkRequest) BulkResponse(com.infiniteautomation.mango.rest.v2.bulk.BulkResponse) NotFoundRestException(com.infiniteautomation.mango.rest.v2.exception.NotFoundRestException) TemporaryResourceWebSocketDefinition(com.serotonin.m2m2.web.mvc.rest.v1.publisher.TemporaryResourceWebSocketDefinition) User(com.serotonin.m2m2.vo.User) RestExceptionIndividualResponse(com.infiniteautomation.mango.rest.v2.bulk.RestExceptionIndividualResponse) ASTNode(net.jazdw.rql.parser.ASTNode) AbstractRestV2Exception(com.infiniteautomation.mango.rest.v2.exception.AbstractRestV2Exception) TemporaryResource(com.infiniteautomation.mango.rest.v2.temporaryResource.TemporaryResource) MappingJacksonValue(org.springframework.http.converter.json.MappingJacksonValue) RQLToObjectListQuery(com.infiniteautomation.mango.db.query.pojo.RQLToObjectListQuery) PageQueryResultModel(com.serotonin.m2m2.web.mvc.rest.v1.model.PageQueryResultModel) ApiOperation(com.wordnik.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with RQLToObjectListQuery

use of com.infiniteautomation.mango.db.query.pojo.RQLToObjectListQuery in project ma-modules-public by infiniteautomation.

the class RealTimeDataRestController method query.

/**
 * Query the User's Real Time Data
 * @param request
 * @param limit
 * @return
 */
@ApiOperation(value = "Query realtime values", notes = "Check the status member to ensure the point is OK not DISABLED or UNRELIABLE")
@RequestMapping(method = RequestMethod.GET, produces = { "application/json" })
public ResponseEntity<List<RealTimeModel>> query(HttpServletRequest request) {
    RestProcessResult<List<RealTimeModel>> result = new RestProcessResult<List<RealTimeModel>>(HttpStatus.OK);
    User user = this.checkUser(request, result);
    if (result.isOk()) {
        ASTNode model;
        try {
            model = parseRQLtoAST(request.getQueryString());
            if (model == null) {
                result.addRestMessage(new RestMessage(HttpStatus.NOT_ACCEPTABLE, new TranslatableMessage("common.default", "Query Required")));
                return result.createResponseEntity();
            }
            List<RealTimeDataPointValue> values = RealTimeDataPointValueCache.instance.getUserView(user);
            values = model.accept(new RQLToObjectListQuery<RealTimeDataPointValue>(), values);
            List<RealTimeModel> models = new ArrayList<RealTimeModel>();
            UriComponentsBuilder imageServletBuilder = UriComponentsBuilder.fromPath("/imageValue/{ts}_{id}.jpg");
            for (RealTimeDataPointValue value : values) {
                if (value.getDataTypeId() == DataTypes.IMAGE) {
                    models.add(new RealTimeModel(value, imageServletBuilder.buildAndExpand(value.getTimestamp(), value.getDataPointId()).toUri()));
                } else {
                    models.add(new RealTimeModel(value, value.getValue()));
                }
            }
            return result.createResponseEntity(models);
        } catch (Exception e) {
            LOG.error(e.getMessage(), e);
            result.addRestMessage(getInternalServerErrorMessage(e.getMessage()));
            return result.createResponseEntity();
        }
    }
    return result.createResponseEntity();
}
Also used : User(com.serotonin.m2m2.vo.User) RealTimeDataPointValue(com.serotonin.m2m2.rt.dataImage.RealTimeDataPointValue) ArrayList(java.util.ArrayList) RealTimeModel(com.serotonin.m2m2.web.mvc.rest.v1.model.RealTimeModel) RQLToObjectListQuery(com.infiniteautomation.mango.db.query.pojo.RQLToObjectListQuery) RestProcessResult(com.serotonin.m2m2.web.mvc.rest.v1.message.RestProcessResult) RestMessage(com.serotonin.m2m2.web.mvc.rest.v1.message.RestMessage) UriComponentsBuilder(org.springframework.web.util.UriComponentsBuilder) ASTNode(net.jazdw.rql.parser.ASTNode) ArrayList(java.util.ArrayList) List(java.util.List) TranslatableMessage(com.serotonin.m2m2.i18n.TranslatableMessage) ApiOperation(com.wordnik.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 4 with RQLToObjectListQuery

use of com.infiniteautomation.mango.db.query.pojo.RQLToObjectListQuery in project ma-modules-public by infiniteautomation.

the class RealTimeDataRestController method get.

@ApiOperation(value = "Get realtime value of point based on XID", notes = "Check the status member to ensure the point is OK not DISABLED or UNRELIABLE")
@RequestMapping(method = RequestMethod.GET, value = "/by-xid/{xid}", produces = { "application/json" })
public ResponseEntity<RealTimeModel> get(@PathVariable String xid, HttpServletRequest request) {
    RestProcessResult<RealTimeModel> result = new RestProcessResult<RealTimeModel>(HttpStatus.OK);
    // Check the user
    User user = checkUser(request, result);
    // If no messages then go for it
    if (result.isOk()) {
        List<RealTimeDataPointValue> values = RealTimeDataPointValueCache.instance.getUserView(user);
        ASTNode root = new ASTNode("eq", "xid", xid);
        values = root.accept(new RQLToObjectListQuery<RealTimeDataPointValue>(), values);
        if (values.size() == 0) {
            LOG.debug("Attempted access of Real time point that DNE.");
            result.addRestMessage(HttpStatus.NOT_FOUND, new TranslatableMessage("common.default", "Point doesn't exist or is not enabled."));
            return result.createResponseEntity();
        }
        RealTimeModel model;
        RealTimeDataPointValue value = values.get(0);
        if (value.getDataTypeId() != DataTypes.IMAGE)
            model = new RealTimeModel(value, value.getValue());
        else {
            UriComponentsBuilder imageServletBuilder = UriComponentsBuilder.fromPath("/imageValue/{ts}_{id}.jpg");
            model = new RealTimeModel(value, imageServletBuilder.buildAndExpand(value.getTimestamp(), value.getDataPointId()).toUri());
        }
        return result.createResponseEntity(model);
    } else {
        return result.createResponseEntity();
    }
}
Also used : RestProcessResult(com.serotonin.m2m2.web.mvc.rest.v1.message.RestProcessResult) User(com.serotonin.m2m2.vo.User) RealTimeDataPointValue(com.serotonin.m2m2.rt.dataImage.RealTimeDataPointValue) UriComponentsBuilder(org.springframework.web.util.UriComponentsBuilder) ASTNode(net.jazdw.rql.parser.ASTNode) TranslatableMessage(com.serotonin.m2m2.i18n.TranslatableMessage) RealTimeModel(com.serotonin.m2m2.web.mvc.rest.v1.model.RealTimeModel) RQLToObjectListQuery(com.infiniteautomation.mango.db.query.pojo.RQLToObjectListQuery) ApiOperation(com.wordnik.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 5 with RQLToObjectListQuery

use of com.infiniteautomation.mango.db.query.pojo.RQLToObjectListQuery in project ma-modules-public by infiniteautomation.

the class RealTimeDataRestController method getAll.

/**
 * Get all of the Users Real Time Data
 * @param request
 * @param limit
 * @return
 */
@ApiOperation(value = "List realtime values", notes = "Check the status member to ensure the point is OK not DISABLED or UNRELIABLE")
@RequestMapping(method = RequestMethod.GET, value = "/list", produces = { "application/json" })
public ResponseEntity<List<RealTimeModel>> getAll(HttpServletRequest request, @ApiParam(value = "Limit the number of results", required = false) @RequestParam(value = "limit", required = false, defaultValue = "100") int limit) {
    RestProcessResult<List<RealTimeModel>> result = new RestProcessResult<List<RealTimeModel>>(HttpStatus.OK);
    User user = this.checkUser(request, result);
    if (result.isOk()) {
        List<RealTimeDataPointValue> values = RealTimeDataPointValueCache.instance.getUserView(user);
        ASTNode root = new ASTNode("limit", limit);
        values = root.accept(new RQLToObjectListQuery<RealTimeDataPointValue>(), values);
        List<RealTimeModel> models = new ArrayList<RealTimeModel>();
        UriComponentsBuilder imageServletBuilder = UriComponentsBuilder.fromPath("/imageValue/{ts}_{id}.jpg");
        for (RealTimeDataPointValue value : values) {
            if (value.getDataTypeId() == DataTypes.IMAGE) {
                models.add(new RealTimeModel(value, imageServletBuilder.buildAndExpand(value.getTimestamp(), value.getDataPointId()).toUri()));
            } else {
                models.add(new RealTimeModel(value, value.getValue()));
            }
        }
        return result.createResponseEntity(models);
    }
    return result.createResponseEntity();
}
Also used : RestProcessResult(com.serotonin.m2m2.web.mvc.rest.v1.message.RestProcessResult) User(com.serotonin.m2m2.vo.User) RealTimeDataPointValue(com.serotonin.m2m2.rt.dataImage.RealTimeDataPointValue) UriComponentsBuilder(org.springframework.web.util.UriComponentsBuilder) ASTNode(net.jazdw.rql.parser.ASTNode) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) RealTimeModel(com.serotonin.m2m2.web.mvc.rest.v1.model.RealTimeModel) RQLToObjectListQuery(com.infiniteautomation.mango.db.query.pojo.RQLToObjectListQuery) ApiOperation(com.wordnik.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

RQLToObjectListQuery (com.infiniteautomation.mango.db.query.pojo.RQLToObjectListQuery)5 User (com.serotonin.m2m2.vo.User)5 ApiOperation (com.wordnik.swagger.annotations.ApiOperation)5 TranslatableMessage (com.serotonin.m2m2.i18n.TranslatableMessage)4 List (java.util.List)4 ASTNode (net.jazdw.rql.parser.ASTNode)4 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)4 UriComponentsBuilder (org.springframework.web.util.UriComponentsBuilder)4 RealTimeDataPointValue (com.serotonin.m2m2.rt.dataImage.RealTimeDataPointValue)3 RestProcessResult (com.serotonin.m2m2.web.mvc.rest.v1.message.RestProcessResult)3 RealTimeModel (com.serotonin.m2m2.web.mvc.rest.v1.model.RealTimeModel)3 BulkRequest (com.infiniteautomation.mango.rest.v2.bulk.BulkRequest)2 BulkResponse (com.infiniteautomation.mango.rest.v2.bulk.BulkResponse)2 AbstractRestV2Exception (com.infiniteautomation.mango.rest.v2.exception.AbstractRestV2Exception)2 AccessDeniedException (com.infiniteautomation.mango.rest.v2.exception.AccessDeniedException)2 BadRequestException (com.infiniteautomation.mango.rest.v2.exception.BadRequestException)2 NotFoundRestException (com.infiniteautomation.mango.rest.v2.exception.NotFoundRestException)2 MangoTaskTemporaryResourceManager (com.infiniteautomation.mango.rest.v2.temporaryResource.MangoTaskTemporaryResourceManager)2 TemporaryResource (com.infiniteautomation.mango.rest.v2.temporaryResource.TemporaryResource)2 TemporaryResourceStatus (com.infiniteautomation.mango.rest.v2.temporaryResource.TemporaryResource.TemporaryResourceStatus)2