Search in sources :

Example 1 with DataPointFilter

use of com.serotonin.m2m2.web.mvc.rest.v1.model.dataPoint.DataPointFilter in project ma-modules-public by infiniteautomation.

the class DataPointRestController method doQuery.

private static StreamedArrayWithTotal doQuery(ASTNode rql, User user) {
    if (user.isAdmin()) {
        return new StreamedVOQueryWithTotal<>(DataPointDao.instance, rql, item -> {
            DataPointDao.instance.loadPartialRelationalData(item);
            return new DataPointModel(item);
        });
    } else {
        // Add some conditions to restrict based on user permissions
        ConditionSortLimitWithTagKeys conditions = DataPointDao.instance.rqlToCondition(rql);
        conditions.addCondition(DataPointDao.instance.userHasPermission(user));
        DataPointFilter dataPointFilter = new DataPointFilter(user);
        return new StreamedVOQueryWithTotal<>(DataPointDao.instance, conditions, item -> {
            boolean oldFilterMatches = dataPointFilter.hasDataPointReadPermission(item);
            // this is just a double check, permissions should be accounted for via SQL restrictions added by DataPointDao.userHasPermission()
            if (!oldFilterMatches) {
                throw new RuntimeException("Data point does not match old permission filter");
            }
            return true;
        }, item -> {
            DataPointDao.instance.loadPartialRelationalData(item);
            return new DataPointModel(item);
        });
    }
}
Also used : StreamedVOQueryWithTotal(com.infiniteautomation.mango.rest.v2.model.StreamedVOQueryWithTotal) DataPointModel(com.infiniteautomation.mango.rest.v2.model.dataPoint.DataPointModel) ConditionSortLimitWithTagKeys(com.infiniteautomation.mango.db.query.ConditionSortLimitWithTagKeys) DataPointFilter(com.serotonin.m2m2.web.mvc.rest.v1.model.dataPoint.DataPointFilter)

Aggregations

ConditionSortLimitWithTagKeys (com.infiniteautomation.mango.db.query.ConditionSortLimitWithTagKeys)1 StreamedVOQueryWithTotal (com.infiniteautomation.mango.rest.v2.model.StreamedVOQueryWithTotal)1 DataPointModel (com.infiniteautomation.mango.rest.v2.model.dataPoint.DataPointModel)1 DataPointFilter (com.serotonin.m2m2.web.mvc.rest.v1.model.dataPoint.DataPointFilter)1