use of org.jooq.SelectJoinStep 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());
}
}
Aggregations