Search in sources :

Example 1 with StreamedVORqlQueryWithTotal

use of com.infiniteautomation.mango.rest.latest.model.StreamedVORqlQueryWithTotal in project ma-modules-public by infiniteautomation.

the class PublishedPointsRestController method query.

@ApiOperation(value = "Query Published Points", notes = "RQL Formatted Query", responseContainer = "List")
@RequestMapping(method = RequestMethod.GET)
public StreamedArrayWithTotal query(HttpServletRequest request, @ApiParam(value = "User", required = true) @AuthenticationPrincipal PermissionHolder user, UriComponentsBuilder builder) {
    ASTNode rql = RQLUtils.parseRQLtoAST(request.getQueryString());
    permissionService.ensureAdminRole(user);
    return new StreamedVORqlQueryWithTotal<>(service, rql, null, fieldMap, null, vo -> map.apply(vo, user));
}
Also used : StreamedVORqlQueryWithTotal(com.infiniteautomation.mango.rest.latest.model.StreamedVORqlQueryWithTotal) ASTNode(net.jazdw.rql.parser.ASTNode) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with StreamedVORqlQueryWithTotal

use of com.infiniteautomation.mango.rest.latest.model.StreamedVORqlQueryWithTotal in project ma-modules-public by infiniteautomation.

the class DataPointTagsRestController method queryTagsForDataPointCSV.

@ApiOperation(value = "Query for data point tags using RQL", notes = "User must have read permission for the data points")
@RequestMapping(method = RequestMethod.GET, value = "/points", produces = MediaTypes.CSV_VALUE)
public StreamedArrayWithTotal queryTagsForDataPointCSV(HttpServletRequest request, @AuthenticationPrincipal PermissionHolder user) {
    ASTNode rql = RQLUtils.parseRQLtoAST(request.getQueryString());
    ConditionSortLimitWithTagKeys conditions = (ConditionSortLimitWithTagKeys) dataPointDao.rqlToCondition(rql, null, null, null);
    return new StreamedVORqlQueryWithTotal<>(dataPointService, conditions, dataPoint -> {
        Map<String, String> tags = dataPointTagsDao.getTagsForDataPointId(dataPoint.getId());
        // we set the tags on the data point then retrieve them so that the device and name tags are removed
        dataPoint.setTags(tags);
        ActionAndTags individualRequest = new ActionAndTags();
        individualRequest.setAction(BulkTagAction.MERGE);
        individualRequest.setXid(dataPoint.getXid());
        individualRequest.setTags(dataPoint.getTags());
        return individualRequest;
    });
}
Also used : StreamedVORqlQueryWithTotal(com.infiniteautomation.mango.rest.latest.model.StreamedVORqlQueryWithTotal) ASTNode(net.jazdw.rql.parser.ASTNode) ConditionSortLimitWithTagKeys(com.infiniteautomation.mango.db.query.ConditionSortLimitWithTagKeys) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with StreamedVORqlQueryWithTotal

use of com.infiniteautomation.mango.rest.latest.model.StreamedVORqlQueryWithTotal in project ma-modules-public by infiniteautomation.

the class DataPointTagsRestController method queryTagsForDataPoint.

@ApiOperation(value = "Query for data point tags using RQL", notes = "User must have read permission for the data points")
@RequestMapping(method = RequestMethod.GET, value = "/points")
public StreamedArrayWithTotal queryTagsForDataPoint(HttpServletRequest request, @AuthenticationPrincipal PermissionHolder user) {
    ASTNode rql = RQLUtils.parseRQLtoAST(request.getQueryString());
    ConditionSortLimitWithTagKeys conditions = (ConditionSortLimitWithTagKeys) dataPointDao.rqlToCondition(rql, null, null, null);
    return new StreamedVORqlQueryWithTotal<>(dataPointService, conditions, dataPoint -> {
        Map<String, String> tags = dataPointTagsDao.getTagsForDataPointId(dataPoint.getId());
        // we set the tags on the data point then retrieve them so that the device and name tags are removed
        dataPoint.setTags(tags);
        TagIndividualRequest individualRequest = new TagIndividualRequest();
        individualRequest.setAction(BulkTagAction.MERGE);
        individualRequest.setXid(dataPoint.getXid());
        individualRequest.setBody(dataPoint.getTags());
        return individualRequest;
    });
}
Also used : StreamedVORqlQueryWithTotal(com.infiniteautomation.mango.rest.latest.model.StreamedVORqlQueryWithTotal) ASTNode(net.jazdw.rql.parser.ASTNode) ConditionSortLimitWithTagKeys(com.infiniteautomation.mango.db.query.ConditionSortLimitWithTagKeys) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 4 with StreamedVORqlQueryWithTotal

use of com.infiniteautomation.mango.rest.latest.model.StreamedVORqlQueryWithTotal in project ma-modules-public by infiniteautomation.

the class MaintenanceEventsRestController method doQuery.

public StreamedArrayWithTotal doQuery(ASTNode rql, PermissionHolder user, Function<MaintenanceEventVO, Object> transformVO) {
    // If we are admin or have overall data source permission we can view all
    if (permissionService.hasPermission(user, dataSourcePermissionDefinition.getPermission())) {
        return new StreamedVORqlQueryWithTotal<>(service, rql, null, null, null, transformVO);
    } else {
        return new StreamedVORqlQueryWithTotal<>(service, rql, null, null, null, item -> {
            if (item.getDataPoints().size() > 0) {
                DataPointPermissionsCheckCallback callback = new DataPointPermissionsCheckCallback(user, true, permissionService, dataPointService);
                dao.getPoints(item.getId(), callback);
                if (!callback.hasPermission())
                    return false;
            }
            if (item.getDataSources().size() > 0) {
                DataSourcePermissionsCheckCallback callback = new DataSourcePermissionsCheckCallback(user, true, permissionService);
                dao.getDataSources(item.getId(), callback);
                if (!callback.hasPermission())
                    return false;
            }
            return true;
        }, transformVO);
    }
}
Also used : StreamedVORqlQueryWithTotal(com.infiniteautomation.mango.rest.latest.model.StreamedVORqlQueryWithTotal) DataPointPermissionsCheckCallback(com.infiniteautomation.mango.spring.service.maintenanceEvents.MaintenanceEventsService.DataPointPermissionsCheckCallback) DataSourcePermissionsCheckCallback(com.infiniteautomation.mango.spring.service.maintenanceEvents.MaintenanceEventsService.DataSourcePermissionsCheckCallback)

Aggregations

StreamedVORqlQueryWithTotal (com.infiniteautomation.mango.rest.latest.model.StreamedVORqlQueryWithTotal)4 ApiOperation (io.swagger.annotations.ApiOperation)3 ASTNode (net.jazdw.rql.parser.ASTNode)3 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3 ConditionSortLimitWithTagKeys (com.infiniteautomation.mango.db.query.ConditionSortLimitWithTagKeys)2 DataPointPermissionsCheckCallback (com.infiniteautomation.mango.spring.service.maintenanceEvents.MaintenanceEventsService.DataPointPermissionsCheckCallback)1 DataSourcePermissionsCheckCallback (com.infiniteautomation.mango.spring.service.maintenanceEvents.MaintenanceEventsService.DataSourcePermissionsCheckCallback)1