Search in sources :

Example 1 with TimePageData

use of org.thingsboard.server.common.data.page.TimePageData in project thingsboard by thingsboard.

the class BaseAlarmService method findHighestAlarmSeverity.

@Override
public AlarmSeverity findHighestAlarmSeverity(EntityId entityId, AlarmSearchStatus alarmSearchStatus, AlarmStatus alarmStatus) {
    TimePageLink nextPageLink = new TimePageLink(100);
    boolean hasNext = true;
    AlarmSeverity highestSeverity = null;
    AlarmQuery query;
    while (hasNext && AlarmSeverity.CRITICAL != highestSeverity) {
        query = new AlarmQuery(entityId, nextPageLink, alarmSearchStatus, alarmStatus, false);
        List<AlarmInfo> alarms;
        try {
            alarms = alarmDao.findAlarms(query).get();
        } catch (ExecutionException | InterruptedException e) {
            log.warn("Failed to find highest alarm severity. EntityId: [{}], AlarmSearchStatus: [{}], AlarmStatus: [{}]", entityId, alarmSearchStatus, alarmStatus);
            throw new RuntimeException(e);
        }
        hasNext = alarms.size() == nextPageLink.getLimit();
        if (hasNext) {
            nextPageLink = new TimePageData<>(alarms, nextPageLink).getNextPageLink();
        }
        AlarmSeverity severity = detectHighestSeverity(alarms);
        if (severity == null) {
            continue;
        }
        if (severity == AlarmSeverity.CRITICAL || highestSeverity == null) {
            highestSeverity = severity;
        } else {
            highestSeverity = highestSeverity.compareTo(severity) < 0 ? highestSeverity : severity;
        }
    }
    return highestSeverity;
}
Also used : TimePageLink(org.thingsboard.server.common.data.page.TimePageLink) ExecutionException(java.util.concurrent.ExecutionException) TimePageData(org.thingsboard.server.common.data.page.TimePageData)

Aggregations

ExecutionException (java.util.concurrent.ExecutionException)1 TimePageData (org.thingsboard.server.common.data.page.TimePageData)1 TimePageLink (org.thingsboard.server.common.data.page.TimePageLink)1