Search in sources :

Example 26 with ConditionSortLimit

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);
}
Also used : ConditionSortLimit(com.infiniteautomation.mango.db.query.ConditionSortLimit)

Example 27 with ConditionSortLimit

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;
}
Also used : Condition(org.jooq.Condition) Audit(com.infiniteautomation.mango.db.tables.Audit) ArrayList(java.util.ArrayList) ConditionSortLimit(com.infiniteautomation.mango.db.query.ConditionSortLimit) IDataPoint(com.serotonin.m2m2.vo.IDataPoint) AuditEventInstanceVO(com.serotonin.m2m2.vo.event.audit.AuditEventInstanceVO) AuditEventService(com.infiniteautomation.mango.spring.service.AuditEventService)

Example 28 with ConditionSortLimit

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);
    }
}
Also used : InvalidArgumentException(com.serotonin.InvalidArgumentException) DataSourceVO(com.serotonin.m2m2.vo.dataSource.DataSourceVO) Role(com.serotonin.m2m2.vo.role.Role) DataSourceDao(com.serotonin.m2m2.db.dao.DataSourceDao) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) SimplifyTypes(com.serotonin.m2m2.vo.DataPointVO.SimplifyTypes) PermissionHolder(com.serotonin.m2m2.vo.permission.PermissionHolder) StringUtils(org.apache.commons.lang3.StringUtils) Condition(org.jooq.Condition) DataPointVO(com.serotonin.m2m2.vo.DataPointVO) DaoEventType(com.infiniteautomation.mango.spring.events.DaoEventType) DataValue(com.serotonin.m2m2.rt.dataImage.types.DataValue) DataPoints(com.infiniteautomation.mango.db.tables.DataPoints) DataPointDao(com.serotonin.m2m2.db.dao.DataPointDao) Map(java.util.Map) RoleVO(com.serotonin.m2m2.vo.role.RoleVO) DataPointChangeDefinition(com.serotonin.m2m2.module.definitions.dataPoint.DataPointChangeDefinition) Select(org.jooq.Select) ProcessMessage(com.serotonin.m2m2.i18n.ProcessMessage) Unit(javax.measure.unit.Unit) DataPointTagsDao(com.serotonin.m2m2.db.dao.DataPointTagsDao) SetPointSource(com.serotonin.m2m2.rt.dataImage.SetPointSource) SelectLimitStep(org.jooq.SelectLimitStep) EventListener(org.springframework.context.event.EventListener) TranslatableMessage(com.serotonin.m2m2.i18n.TranslatableMessage) RuntimeManager(com.serotonin.m2m2.rt.RuntimeManager) ModuleRegistry(com.serotonin.m2m2.module.ModuleRegistry) ProcessResult(com.serotonin.m2m2.i18n.ProcessResult) List(java.util.List) Stream(java.util.stream.Stream) Rollups(com.serotonin.m2m2.Common.Rollups) Entry(java.util.Map.Entry) SelectConnectByStep(org.jooq.SelectConnectByStep) EventDetectorDao(com.serotonin.m2m2.db.dao.EventDetectorDao) SelectJoinStep(org.jooq.SelectJoinStep) StringValidation(com.serotonin.validation.StringValidation) NotFoundException(com.infiniteautomation.mango.util.exception.NotFoundException) DataPointWithEventDetectors(com.serotonin.m2m2.vo.dataPoint.DataPointWithEventDetectors) ConditionSortLimit(com.infiniteautomation.mango.db.query.ConditionSortLimit) TimePeriods(com.serotonin.m2m2.Common.TimePeriods) DataPointRT(com.serotonin.m2m2.rt.dataImage.DataPointRT) ArrayList(java.util.ArrayList) PointValueCache(com.infiniteautomation.mango.pointvaluecache.PointValueCache) ColorUtils(com.serotonin.m2m2.util.ColorUtils) SI(javax.measure.unit.SI) DataType(com.serotonin.m2m2.DataType) DataPointSummary(com.serotonin.m2m2.vo.DataPointSummary) PlotTypes(com.serotonin.m2m2.vo.DataPointVO.PlotTypes) Service(org.springframework.stereotype.Service) AbstractPointEventDetectorVO(com.serotonin.m2m2.vo.event.detector.AbstractPointEventDetectorVO) ShouldNeverHappenException(com.serotonin.ShouldNeverHappenException) IntervalLoggingTypes(com.serotonin.m2m2.vo.DataPointVO.IntervalLoggingTypes) PointValueTime(com.serotonin.m2m2.rt.dataImage.PointValueTime) SelectHavingStep(org.jooq.SelectHavingStep) Record(org.jooq.Record) Logger(org.slf4j.Logger) Common(com.serotonin.m2m2.Common) EventManager(com.serotonin.m2m2.rt.EventManager) DataPointPermissionDefinition(com.serotonin.m2m2.module.definitions.permissions.DataPointPermissionDefinition) ValidationException(com.infiniteautomation.mango.util.exception.ValidationException) Consumer(java.util.function.Consumer) DaoEvent(com.infiniteautomation.mango.spring.events.DaoEvent) LoggingTypes(com.serotonin.m2m2.vo.DataPointVO.LoggingTypes) SortField(org.jooq.SortField) RTException(com.serotonin.m2m2.rt.RTException) DataSourceDefinition(com.serotonin.m2m2.module.DataSourceDefinition) MangoPermission(com.infiniteautomation.mango.permission.MangoPermission) Collections(java.util.Collections) PermissionException(com.serotonin.m2m2.vo.permission.PermissionException) ArrayList(java.util.ArrayList) SortField(org.jooq.SortField) PermissionHolder(com.serotonin.m2m2.vo.permission.PermissionHolder) ConditionSortLimit(com.infiniteautomation.mango.db.query.ConditionSortLimit) Record(org.jooq.Record)

Example 29 with ConditionSortLimit

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;
}
Also used : FileStore(com.serotonin.m2m2.vo.FileStore) ArrayList(java.util.ArrayList) PermissionHolder(com.serotonin.m2m2.vo.permission.PermissionHolder) ConditionSortLimit(com.infiniteautomation.mango.db.query.ConditionSortLimit) FileStoreDefinition(com.serotonin.m2m2.module.FileStoreDefinition)

Example 30 with ConditionSortLimit

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;
}
Also used : Condition(org.jooq.Condition) Audit(com.infiniteautomation.mango.db.tables.Audit) ArrayList(java.util.ArrayList) ConditionSortLimit(com.infiniteautomation.mango.db.query.ConditionSortLimit) IDataPoint(com.serotonin.m2m2.vo.IDataPoint) AuditEventInstanceVO(com.serotonin.m2m2.vo.event.audit.AuditEventInstanceVO) AuditEventService(com.infiniteautomation.mango.spring.service.AuditEventService)

Aggregations

ConditionSortLimit (com.infiniteautomation.mango.db.query.ConditionSortLimit)35 Condition (org.jooq.Condition)14 ArrayList (java.util.ArrayList)12 Test (org.junit.Test)10 AbstractBasicVO (com.serotonin.m2m2.vo.AbstractBasicVO)8 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)8 PermissionHolder (com.serotonin.m2m2.vo.permission.PermissionHolder)7 TranslatableMessage (com.serotonin.m2m2.i18n.TranslatableMessage)6 MangoPermission (com.infiniteautomation.mango.permission.MangoPermission)4 ShouldNeverHappenException (com.serotonin.ShouldNeverHappenException)4 Common (com.serotonin.m2m2.Common)4 ModuleRegistry (com.serotonin.m2m2.module.ModuleRegistry)4 ApiOperation (io.swagger.annotations.ApiOperation)3 List (java.util.List)3 Record (org.jooq.Record)3 Record1 (org.jooq.Record1)3 SelectJoinStep (org.jooq.SelectJoinStep)3 Logger (org.slf4j.Logger)3 LoggerFactory (org.slf4j.LoggerFactory)3 Autowired (org.springframework.beans.factory.annotation.Autowired)3