use of com.infiniteautomation.mango.db.query.ConditionSortLimit in project ma-core-public by infiniteautomation.
the class AbstractBasicDao method query.
@Override
public void query(PermissionHolder user, String rql, Consumer<T> consumer) {
ConditionSortLimit csl = rqlToCondition(RQLUtils.parseRQLtoAST(rql), Collections.emptyMap(), Collections.emptyMap(), Collections.emptyMap());
customizedQuery(csl, user, consumer);
}
use of com.infiniteautomation.mango.db.query.ConditionSortLimit in project ma-core-public by infiniteautomation.
the class PublisherAuditTest method getAuditEvents.
protected List<AuditEventInstanceVO> getAuditEvents(String typeName, int objectId) {
Audit auditTable = Audit.AUDIT;
Condition conditions = DSL.and(auditTable.typeName.eq(typeName), auditTable.objectId.eq(objectId));
ConditionSortLimit c = new ConditionSortLimit(conditions, Collections.singletonList(auditTable.id.asc()), null, null);
List<AuditEventInstanceVO> events = new ArrayList<>();
AuditEventService service = Common.getBean(AuditEventService.class);
// Since these are raised in the background processing thread they may have not yet fired
int retries = 4;
while (retries > 0) {
events.clear();
service.customizedQuery(c, events::add);
if (events.size() == 3) {
break;
}
retries--;
try {
Thread.sleep(500);
} catch (InterruptedException ignored) {
}
}
return events;
}
use of com.infiniteautomation.mango.db.query.ConditionSortLimit in project ma-core-public by infiniteautomation.
the class DataPointService method queryDeviceNames.
/**
* Query for device names on data points a user can read
*/
public void queryDeviceNames(Condition conditions, boolean sortAsc, Integer limit, Integer offset, Consumer<String> callback) {
PermissionHolder user = Common.getUser();
List<SortField<?>> sort = new ArrayList<>();
if (sortAsc) {
sort.add(dataPoints.deviceName.asc());
} else {
sort.add(dataPoints.deviceName.desc());
}
ConditionSortLimit csl = new ConditionSortLimit(conditions, sort, limit, offset);
SelectJoinStep<Record> select = this.dao.getSelectQuery(Collections.singletonList(dataPoints.deviceName));
select = dao.joinTables(select, null);
if (!permissionService.hasAdminRole(user)) {
select = dao.joinPermissions(select, user);
}
SelectConnectByStep<Record> afterWhere = conditions == null ? select : select.where(conditions);
SelectHavingStep<Record> afterGroupBy = afterWhere.groupBy(dataPoints.deviceName);
SelectLimitStep<Record> afterSort = afterGroupBy.orderBy(sort);
Select<Record> offsetStep = afterSort;
if (limit != null) {
if (offset != null) {
offsetStep = afterSort.limit(offset, limit);
} else {
offsetStep = afterSort.limit(limit);
}
}
try (Stream<Record> stream = offsetStep.stream()) {
stream.map(r -> r.get(dataPoints.deviceName)).forEach(callback);
}
}
use of com.infiniteautomation.mango.db.query.ConditionSortLimit in project ma-core-public by infiniteautomation.
the class FileStoreService method getStores.
/**
* List all file-stores that the user has read permission for
*/
public List<FileStore> getStores() {
List<FileStore> stores = new ArrayList<>();
this.customizedQuery(new ConditionSortLimit(null, null, null, null), (item) -> stores.add(item));
PermissionHolder user = Common.getUser();
Collection<FileStoreDefinition> moduleDefs = ModuleRegistry.getFileStoreDefinitions().values();
for (FileStoreDefinition def : moduleDefs) {
if (this.permissionService.hasPermission(user, def.getReadPermission())) {
stores.add(def.toFileStore());
}
}
return stores;
}
use of com.infiniteautomation.mango.db.query.ConditionSortLimit in project ma-core-public by MangoAutomation.
the class PublisherAuditTest method getAuditEvents.
protected List<AuditEventInstanceVO> getAuditEvents(String typeName, int objectId) {
Audit auditTable = Audit.AUDIT;
Condition conditions = DSL.and(auditTable.typeName.eq(typeName), auditTable.objectId.eq(objectId));
ConditionSortLimit c = new ConditionSortLimit(conditions, Collections.singletonList(auditTable.id.asc()), null, null);
List<AuditEventInstanceVO> events = new ArrayList<>();
AuditEventService service = Common.getBean(AuditEventService.class);
// Since these are raised in the background processing thread they may have not yet fired
int retries = 4;
while (retries > 0) {
events.clear();
service.customizedQuery(c, events::add);
if (events.size() == 3) {
break;
}
retries--;
try {
Thread.sleep(500);
} catch (InterruptedException ignored) {
}
}
return events;
}
Aggregations