use of com.infiniteautomation.mango.db.query.ConditionSortLimitWithTagKeys 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);
});
}
}
use of com.infiniteautomation.mango.db.query.ConditionSortLimitWithTagKeys in project ma-core-public by infiniteautomation.
the class JsonEmportScriptUtility method dataPointQuery.
public String dataPointQuery(String query, int prettyIndent) {
Map<String, Object> data = new LinkedHashMap<>();
if (admin) {
ASTNode root = parser.parse(query);
List<DataPointVO> dataPoints = new ArrayList<>();
ConditionSortLimitWithTagKeys conditions = DataPointDao.instance.rqlToCondition(root);
DataPointDao.instance.customizedQuery(conditions, new MappedRowCallback<DataPointVO>() {
@Override
public void row(DataPointVO item, int index) {
dataPoints.add(item);
}
});
data.put(ConfigurationExportData.DATA_POINTS, dataPoints);
}
return EmportDwr.export(data, prettyIndent);
}
use of com.infiniteautomation.mango.db.query.ConditionSortLimitWithTagKeys in project ma-core-public by infiniteautomation.
the class DataPointTagsDao method getTagValuesForKey.
public Set<String> getTagValuesForKey(String tagKey, ASTNode restrictions, User user) {
RQLToConditionWithTagKeys visitor = new RQLToConditionWithTagKeys();
Name tagKeyColumn = visitor.columnNameForTagKey(tagKey);
List<Condition> conditionList = new ArrayList<>();
ConditionSortLimitWithTagKeys conditions = visitor.visit(restrictions);
if (conditions.getCondition() != null) {
conditionList.add(conditions.getCondition());
}
Map<String, Name> tagKeyToColumn = conditions.getTagKeyToColumn();
Table<Record> from = createTagPivotSql(tagKeyToColumn).asTable().as(DATA_POINT_TAGS_PIVOT_ALIAS);
if (!user.isAdmin()) {
from = joinPointPermissions(from, PIVOT_ALIAS_DATA_POINT_ID, user);
}
SelectJoinStep<Record1<String>> query = this.create.selectDistinct(DSL.field(DATA_POINT_TAGS_PIVOT_ALIAS.append(tagKeyColumn), String.class)).from(from);
Select<Record1<String>> result = query;
if (!conditionList.isEmpty()) {
result = query.where(DSL.and(conditionList));
}
try (Stream<Record1<String>> stream = result.stream()) {
return stream.map(r -> r.value1()).collect(Collectors.toSet());
}
}
use of com.infiniteautomation.mango.db.query.ConditionSortLimitWithTagKeys in project ma-core-public by infiniteautomation.
the class DataPointQuery method query.
/**
* Perform a query on the data points table
* @param query
* @return
*/
public List<DataPointWrapper> query(String query) {
ASTNode root = parser.parse(query);
List<DataPointVO> dataPoints = new ArrayList<>();
ConditionSortLimitWithTagKeys conditions = DataPointDao.instance.rqlToCondition(root);
DataPointDao.instance.customizedQuery(conditions, new MappedRowCallback<DataPointVO>() {
@Override
public void row(DataPointVO item, int index) {
dataPoints.add(item);
}
});
List<DataPointWrapper> results = new ArrayList<DataPointWrapper>();
// Filter on permissions
DataPointRT rt = null;
AbstractPointWrapper wrapper = null;
for (DataPointVO dp : dataPoints) {
// Can we read or write to this point?
if (Permissions.hasDataPointSetPermission(permissions.getDataPointSetPermissions(), dp) || Permissions.hasDataPointReadPermission(permissions.getDataPointReadPermissions(), dp)) {
rt = Common.runtimeManager.getDataPoint(dp.getId());
if (rt != null)
wrapper = ScriptUtils.wrapPoint(engine, rt, setter);
else
wrapper = null;
results.add(new DataPointWrapper(dp, wrapper));
}
}
return results;
}
Aggregations