Search in sources :

Example 6 with ConditionSortLimit

use of com.infiniteautomation.mango.db.query.ConditionSortLimit in project ma-core-public by infiniteautomation.

the class AbstractBasicVOServiceWithPermissionsTestBase method testCountQueryReadPermissionEnforcement.

@Test
public void testCountQueryReadPermissionEnforcement() {
    VO vo = newVO(editUser);
    setReadPermission(MangoPermission.requireAnyRole(editRole), vo);
    service.insert(vo);
    runAs.runAs(readUser, () -> {
        ConditionSortLimit conditions = new ConditionSortLimit(null, null, null, 0);
        int count = getService().customizedCount(conditions);
        assertEquals(0, count);
    });
    VO vo2 = newVO(editUser);
    setReadPermission(MangoPermission.requireAnyRole(editRole), vo2);
    service.insert(vo2);
    runAs.runAs(editUser, () -> {
        ConditionSortLimit conditions = new ConditionSortLimit(null, null, null, 0);
        int count = getService().customizedCount(conditions);
        assertEquals(2, count);
    });
}
Also used : AbstractBasicVO(com.serotonin.m2m2.vo.AbstractBasicVO) ConditionSortLimit(com.infiniteautomation.mango.db.query.ConditionSortLimit) Test(org.junit.Test)

Example 7 with ConditionSortLimit

use of com.infiniteautomation.mango.db.query.ConditionSortLimit in project ma-core-public by infiniteautomation.

the class AbstractBasicDao method rqlQuery.

public void rqlQuery(ASTNode rql, MappedRowCallback<T> callback) {
    ConditionSortLimit result = this.rqlToCondition(rql);
    this.customizedQuery(result, callback);
}
Also used : ConditionSortLimit(com.infiniteautomation.mango.db.query.ConditionSortLimit)

Example 8 with ConditionSortLimit

use of com.infiniteautomation.mango.db.query.ConditionSortLimit in project ma-modules-public by infiniteautomation.

the class WatchListService method getDataPoints.

/**
 * Get the full data points for a list (TAG_TYPE not supported)
 */
public void getDataPoints(WatchListVO vo, Consumer<DataPointVO> callback) {
    PermissionHolder user = Common.getUser();
    switch(vo.getType()) {
        case STATIC:
            this.dao.getPoints(vo.getId(), (dp) -> {
                if (dataPointService.hasReadPermission(user, dp)) {
                    callback.accept(dp);
                }
            });
            break;
        case QUERY:
            if (vo.getParams().size() > 0)
                throw new ServerErrorException(new TranslatableMessage("watchList.queryParametersNotSupported"));
            ASTNode rql = RQLUtils.parseRQLtoAST(vo.getQuery());
            ConditionSortLimit conditions = dataPointService.rqlToCondition(rql, null, null, null);
            dataPointService.customizedQuery(conditions, callback);
            break;
        case TAGS:
            throw new ServerErrorException(new TranslatableMessage("watchList.queryParametersNotSupported"));
        default:
            throw new ServerErrorException(new TranslatableMessage("common.default", "unknown watchlist type: " + vo.getType()));
    }
}
Also used : ASTNode(net.jazdw.rql.parser.ASTNode) ServerErrorException(com.infiniteautomation.mango.rest.latest.exception.ServerErrorException) TranslatableMessage(com.serotonin.m2m2.i18n.TranslatableMessage) PermissionHolder(com.serotonin.m2m2.vo.permission.PermissionHolder) ConditionSortLimit(com.infiniteautomation.mango.db.query.ConditionSortLimit)

Example 9 with ConditionSortLimit

use of com.infiniteautomation.mango.db.query.ConditionSortLimit in project ma-modules-public by infiniteautomation.

the class EventsRestController method acknowledgeManyEvents.

@ApiOperation(value = "Acknowledge many existing events")
@RequestMapping(method = RequestMethod.POST, value = "/acknowledge")
@Async
public CompletableFuture<Integer> acknowledgeManyEvents(@RequestBody(required = false) TranslatableMessageModel message, ASTNode rql) {
    TranslatableMessage tlm;
    if (message != null) {
        tlm = new TranslatableMessage(message.getKey(), message.getArgs().toArray());
    } else {
        tlm = null;
    }
    // Ensure we supply the mappings when converting the RQL
    ConditionSortLimit conditions = service.rqlToCondition(rql, null, fieldMap, valueConverters);
    int count = service.acknowledgeMany(conditions, tlm);
    return CompletableFuture.completedFuture(count);
}
Also used : TranslatableMessage(com.serotonin.m2m2.i18n.TranslatableMessage) ConditionSortLimit(com.infiniteautomation.mango.db.query.ConditionSortLimit) Async(org.springframework.scheduling.annotation.Async) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 10 with ConditionSortLimit

use of com.infiniteautomation.mango.db.query.ConditionSortLimit in project ma-modules-public by infiniteautomation.

the class EventsRestController method eventCounts.

@ApiOperation("Query for event counts using RQL")
@RequestMapping(method = RequestMethod.POST, path = "/counts")
public List<PeriodCounts> eventCounts(@AuthenticationPrincipal PermissionHolder user, @RequestBody List<Date> periodBoundaries, ASTNode rql) {
    // TODO Clean up, add model, move restrictions to service
    Assert.isTrue(periodBoundaries.size() >= 2, "periodBoundaries must have at least 2 elements");
    List<Date> sorted = new ArrayList<>(periodBoundaries);
    Collections.sort(sorted);
    Date from = sorted.get(0);
    Date to = sorted.get(periodBoundaries.size() - 1);
    rql = RQLUtils.addAndRestriction(rql, new ASTNode("ge", "activeTs", from));
    rql = RQLUtils.addAndRestriction(rql, new ASTNode("lt", "activeTs", to));
    ConditionSortLimit conditions = service.rqlToCondition(rql, Collections.emptyMap(), fieldMap, valueConverters);
    return service.countQuery(conditions, sorted);
}
Also used : ArrayList(java.util.ArrayList) ASTNode(net.jazdw.rql.parser.ASTNode) ConditionSortLimit(com.infiniteautomation.mango.db.query.ConditionSortLimit) Date(java.util.Date) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

ConditionSortLimit (com.infiniteautomation.mango.db.query.ConditionSortLimit)20 ArrayList (java.util.ArrayList)7 Condition (org.jooq.Condition)7 TranslatableMessage (com.serotonin.m2m2.i18n.TranslatableMessage)4 AbstractBasicVO (com.serotonin.m2m2.vo.AbstractBasicVO)4 PermissionHolder (com.serotonin.m2m2.vo.permission.PermissionHolder)4 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)4 Test (org.junit.Test)4 ApiOperation (io.swagger.annotations.ApiOperation)3 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3 MangoPermission (com.infiniteautomation.mango.permission.MangoPermission)2 ShouldNeverHappenException (com.serotonin.ShouldNeverHappenException)2 Common (com.serotonin.m2m2.Common)2 ModuleRegistry (com.serotonin.m2m2.module.ModuleRegistry)2 ASTNode (net.jazdw.rql.parser.ASTNode)2 Record1 (org.jooq.Record1)2 Audit (com.infiniteautomation.mango.db.tables.Audit)1 DataPoints (com.infiniteautomation.mango.db.tables.DataPoints)1 Events (com.infiniteautomation.mango.db.tables.Events)1 MintermsRoles (com.infiniteautomation.mango.db.tables.MintermsRoles)1