use of com.infiniteautomation.mango.spring.service.EventInstanceService.AlarmPointTagCount in project ma-core-public by infiniteautomation.
the class EventInstanceDao method queryDataPointEventCountsByRQL.
/**
* @param conditions supplied by {@link #createEventCountsConditions(net.jazdw.rql.parser.ASTNode)}
* @param from from timestamp
* @param to to timestamp
* @param user user executing the query
* @param callback result consumer
*/
public void queryDataPointEventCountsByRQL(@NonNull ConditionSortLimitWithTagKeys conditions, @Nullable Long from, @Nullable Long to, @NonNull PermissionHolder user, @NonNull Consumer<AlarmPointTagCount> callback) {
Table<Record6<Integer, String, Integer, Integer, Long, Long>> eventCountsTable = eventCountsTable(from, to, user);
Map<String, Field<String>> tagFields = conditions.getTagFields();
SelectJoinStep<Record> joinStep = create.select(eventCountsFields.values()).select(tagFields.values()).from(eventCountsTable).leftOuterJoin(dataPoints).on(dataPoints.id.equal(eventCountsTable.field(table.typeRef1)));
SelectConditionStep<Record> conditionStep = dataPointTagsDao.joinTags(joinStep, dataPoints.id, tagFields).where(conditions.getCondition());
Select<Record> select = applySortLimitOffset(conditionStep, conditions);
try (Stream<Record> stream = select.stream()) {
stream.map(record -> {
AlarmPointTagCount result = new AlarmPointTagCount();
result.setXid(record.get(dataPoints.xid));
result.setName(record.get(dataPoints.name));
result.setDeviceName(record.get(dataPoints.deviceName));
result.setMessage(readTranslatableMessage(record.get(eventCountsTable.field(table.message))));
result.setAlarmLevel(AlarmLevels.fromValue(record.get(eventCountsTable.field(table.alarmLevel))));
result.setCount(record.get(eventCountsTable.field(count)));
result.setLatestActiveTs(record.get(eventCountsTable.field(latestActive)));
result.setLatestRtnTs(record.get(eventCountsTable.field(latestRtn)));
Map<String, String> tags = new HashMap<>();
for (Entry<String, Field<String>> entry : tagFields.entrySet()) {
String value = record.get(entry.getValue());
if (value != null) {
tags.put(entry.getKey(), value);
}
}
result.setTags(tags);
return result;
}).forEach(callback);
}
}
Aggregations