Search in sources :

Example 11 with AlarmLevels

use of com.serotonin.m2m2.rt.event.AlarmLevels in project ma-core-public by infiniteautomation.

the class DataSourceVO method jsonRead.

@Override
public void jsonRead(JsonReader reader, JsonObject jsonObject) throws JsonException {
    // Not reading XID so can't do this: super.jsonRead(reader, jsonObject);
    if (jsonObject.containsKey("name"))
        name = getString(jsonObject, "name");
    if (jsonObject.containsKey("enabled"))
        enabled = getBoolean(jsonObject, "enabled");
    JsonObject alarmCodeLevels = jsonObject.getJsonObject("alarmLevels");
    if (alarmCodeLevels != null) {
        ExportCodes eventCodes = getEventCodes();
        if (eventCodes != null && eventCodes.size() > 0) {
            for (String code : alarmCodeLevels.keySet()) {
                int eventId = eventCodes.getId(code);
                if (!eventCodes.isValidId(eventId))
                    throw new TranslatableJsonException("emport.error.eventCode", code, eventCodes.getCodeList());
                String text = alarmCodeLevels.getString(code);
                try {
                    setAlarmLevel(eventId, AlarmLevels.fromName(text));
                } catch (IllegalArgumentException | NullPointerException e) {
                    throw new TranslatableJsonException("emport.error.alarmLevel", text, code, Arrays.asList(AlarmLevels.values()));
                }
            }
        }
    }
    String text = jsonObject.getString("purgeType");
    if (text != null) {
        purgeType = Common.TIME_PERIOD_CODES.getId(text);
        if (purgeType == -1)
            throw new TranslatableJsonException("emport.error.invalid", "purgeType", text, Common.TIME_PERIOD_CODES.getCodeList());
    }
}
Also used : ExportCodes(com.serotonin.m2m2.util.ExportCodes) JsonObject(com.serotonin.json.type.JsonObject) TranslatableJsonException(com.serotonin.m2m2.i18n.TranslatableJsonException)

Example 12 with AlarmLevels

use of com.serotonin.m2m2.rt.event.AlarmLevels in project ma-core-public by infiniteautomation.

the class DataSourceVO method setAlarmLevel.

/**
 * Set an alarm level based on the sub-type of the data source event type
 * which MUST (and already is) one of the codes in getEventCodes()
 */
public void setAlarmLevel(String subType, AlarmLevels level) throws ValidationException {
    ExportCodes codes = getEventCodes();
    int eventId = codes.getId(subType);
    if (eventId == -1) {
        ProcessResult result = new ProcessResult();
        result.addContextualMessage("alarmLevel", "emport.error.eventCode", subType, codes.getCodeList());
        throw new ValidationException(result);
    }
    alarmLevels.put(eventId, level);
}
Also used : ExportCodes(com.serotonin.m2m2.util.ExportCodes) ValidationException(com.infiniteautomation.mango.util.exception.ValidationException) ProcessResult(com.serotonin.m2m2.i18n.ProcessResult)

Example 13 with AlarmLevels

use of com.serotonin.m2m2.rt.event.AlarmLevels in project ma-core-public by infiniteautomation.

the class UserLoginEventTypeDefinition method generatePossibleEventTypesWithReferenceId1.

@Override
public List<EventTypeVO> generatePossibleEventTypesWithReferenceId1(PermissionHolder user, String subtype) {
    if (!StringUtils.equals(SystemEventType.TYPE_USER_LOGIN, subtype))
        return Collections.emptyList();
    AlarmLevels level = AlarmLevels.fromValue(systemSettingsDao.getIntValue(SystemEventType.SYSTEM_SETTINGS_PREFIX + SystemEventType.TYPE_USER_LOGIN));
    List<User> users;
    if (permissionService.hasAdminRole(user)) {
        users = userDao.getEnabledUsers();
    } else if (user.getUser() != null) {
        users = Collections.singletonList(user.getUser());
    } else {
        users = Collections.emptyList();
    }
    return users.stream().map(u -> new EventTypeVO(new SystemEventType(SystemEventType.TYPE_USER_LOGIN, u.getId()), new TranslatableMessage("event.system.userLoginForUser", u.getName()), level)).collect(Collectors.toList());
}
Also used : SystemEventTypeDefinition(com.serotonin.m2m2.module.SystemEventTypeDefinition) Autowired(org.springframework.beans.factory.annotation.Autowired) TranslatableMessage(com.serotonin.m2m2.i18n.TranslatableMessage) SystemEventType(com.serotonin.m2m2.rt.event.type.SystemEventType) Translations(com.serotonin.m2m2.i18n.Translations) PermissionHolder(com.serotonin.m2m2.vo.permission.PermissionHolder) Collectors(java.util.stream.Collectors) StringUtils(org.apache.commons.lang3.StringUtils) List(java.util.List) SystemSettingsDao(com.serotonin.m2m2.db.dao.SystemSettingsDao) AlarmLevels(com.serotonin.m2m2.rt.event.AlarmLevels) Collections(java.util.Collections) User(com.serotonin.m2m2.vo.User) PermissionService(com.infiniteautomation.mango.spring.service.PermissionService) UserDao(com.serotonin.m2m2.db.dao.UserDao) EventTypeVO(com.serotonin.m2m2.vo.event.EventTypeVO) SystemEventType(com.serotonin.m2m2.rt.event.type.SystemEventType) User(com.serotonin.m2m2.vo.User) EventTypeVO(com.serotonin.m2m2.vo.event.EventTypeVO) TranslatableMessage(com.serotonin.m2m2.i18n.TranslatableMessage) AlarmLevels(com.serotonin.m2m2.rt.event.AlarmLevels)

Example 14 with AlarmLevels

use of com.serotonin.m2m2.rt.event.AlarmLevels in project ma-core-public by infiniteautomation.

the class EventInstanceServiceTest method testUnackSummaryCount.

@Test
public void testUnackSummaryCount() {
    long refTime = System.currentTimeMillis();
    createEvents(5, 0, refTime);
    List<UserEventLevelSummary> summaries = service.getUnacknowledgedSummary();
    AlarmLevels alarmLevel = newVO(editUser).getAlarmLevel();
    UserEventLevelSummary summary = summaries.get(alarmLevel.value());
    assertEquals(5, summary.getCount());
}
Also used : UserEventLevelSummary(com.serotonin.m2m2.rt.event.UserEventLevelSummary) AlarmLevels(com.serotonin.m2m2.rt.event.AlarmLevels) Test(org.junit.Test)

Example 15 with AlarmLevels

use of com.serotonin.m2m2.rt.event.AlarmLevels in project ma-core-public by infiniteautomation.

the class EventInstanceWithTagsQueryTest method insertEvents.

protected List<EventInstance> insertEvents(DataPointVO point, AbstractPointEventDetectorVO detector, int count, AlarmLevels level) {
    List<EventInstance> list = new ArrayList<>();
    for (int i = 0; i < count; i++) {
        EventInstance evt = createDataPointEventInstance(point, detector, level);
        evt.setReadPermission(point.getReadPermission());
        dao.saveEvent(evt);
        list.add(evt);
    }
    return list;
}
Also used : EventInstance(com.serotonin.m2m2.rt.event.EventInstance) ArrayList(java.util.ArrayList)

Aggregations

AlarmLevels (com.serotonin.m2m2.rt.event.AlarmLevels)19 ExportCodes (com.serotonin.m2m2.util.ExportCodes)14 TranslatableMessage (com.serotonin.m2m2.i18n.TranslatableMessage)11 ArrayList (java.util.ArrayList)11 EventInstance (com.serotonin.m2m2.rt.event.EventInstance)9 PermissionHolder (com.serotonin.m2m2.vo.permission.PermissionHolder)8 UserEventLevelSummary (com.serotonin.m2m2.rt.event.UserEventLevelSummary)7 HashMap (java.util.HashMap)7 EventTypeVO (com.serotonin.m2m2.vo.event.EventTypeVO)6 ProcessResult (com.serotonin.m2m2.i18n.ProcessResult)5 TranslatableJsonException (com.serotonin.m2m2.i18n.TranslatableJsonException)5 User (com.serotonin.m2m2.vo.User)5 ValidationException (com.infiniteautomation.mango.util.exception.ValidationException)4 SystemEventType (com.serotonin.m2m2.rt.event.type.SystemEventType)4 EnumMap (java.util.EnumMap)4 Test (org.junit.Test)4 JsonObject (com.serotonin.json.type.JsonObject)3 UserEventListener (com.serotonin.m2m2.rt.event.UserEventListener)3 Collections (java.util.Collections)3 HashSet (java.util.HashSet)3