Search in sources :

Example 1 with TranslatableRuntimeException

use of com.infiniteautomation.mango.util.exception.TranslatableRuntimeException in project ma-core-public by infiniteautomation.

the class EventInstanceService method acknowledgeMany.

public int acknowledgeMany(ConditionSortLimit conditions, TranslatableMessage message) {
    // only users can ack events as it stores user id in events table
    User user = Objects.requireNonNull(Common.getUser().getUser());
    AtomicInteger total = new AtomicInteger();
    long ackTimestamp = Common.timer.currentTimeMillis();
    try {
        if (!ackManyLock.tryLock(10, TimeUnit.SECONDS)) {
            throw new TranslatableRuntimeException(new TranslatableMessage("events.acknowledgeManyFailed"));
        }
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
        throw new RuntimeException(e);
    }
    try {
        customizedQuery(conditions, (EventInstanceVO vo) -> {
            if (hasEditPermission(user, vo)) {
                EventInstance event = Common.eventManager.acknowledgeEventById(vo.getId(), ackTimestamp, user, message);
                if (event != null && event.isAcknowledged()) {
                    total.incrementAndGet();
                }
            }
        });
    } finally {
        ackManyLock.unlock();
    }
    return total.get();
}
Also used : EventInstance(com.serotonin.m2m2.rt.event.EventInstance) User(com.serotonin.m2m2.vo.User) TranslatableRuntimeException(com.infiniteautomation.mango.util.exception.TranslatableRuntimeException) EventInstanceVO(com.serotonin.m2m2.vo.event.EventInstanceVO) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TranslatableMessage(com.serotonin.m2m2.i18n.TranslatableMessage) TranslatableRuntimeException(com.infiniteautomation.mango.util.exception.TranslatableRuntimeException)

Example 2 with TranslatableRuntimeException

use of com.infiniteautomation.mango.util.exception.TranslatableRuntimeException in project ma-core-public by infiniteautomation.

the class QueryBuilder method close.

public QueryBuilder<T> close() {
    if (stack.isEmpty()) {
        throw new TranslatableRuntimeException(new TranslatableMessage("dao.query.noGroupOpen"));
    }
    Condition condition = group.toCondition();
    group = stack.pop();
    group.conditions.add(condition);
    return this;
}
Also used : Condition(org.jooq.Condition) TranslatableMessage(com.serotonin.m2m2.i18n.TranslatableMessage) TranslatableRuntimeException(com.infiniteautomation.mango.util.exception.TranslatableRuntimeException)

Aggregations

TranslatableRuntimeException (com.infiniteautomation.mango.util.exception.TranslatableRuntimeException)2 TranslatableMessage (com.serotonin.m2m2.i18n.TranslatableMessage)2 EventInstance (com.serotonin.m2m2.rt.event.EventInstance)1 User (com.serotonin.m2m2.vo.User)1 EventInstanceVO (com.serotonin.m2m2.vo.event.EventInstanceVO)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Condition (org.jooq.Condition)1