Search in sources :

Example 36 with AlarmLevels

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

the class PublisherVO 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");
    // Legacy conversion for publishType
    if (jsonObject.containsKey("publishType")) {
        String publishTypeCode = jsonObject.getString("publishType");
        int publishTypeId = PUBLISH_TYPE_CODES.getId(publishTypeCode);
        if (publishTypeId == -1)
            throw new TranslatableJsonException("emport.error.invalid", "publishType", publishTypeCode, PUBLISH_TYPE_CODES.getCodeList());
        publishType = publishTypeId;
    } else if (jsonObject.containsKey("changesOnly")) {
        boolean changesOnly = getBoolean(jsonObject, "changesOnly");
        if (changesOnly) {
            this.publishType = PublishType.CHANGES_ONLY;
        } else {
            this.publishType = PublishType.ALL;
        }
    }
    String text = jsonObject.getString("snapshotSendPeriodType");
    if (text != null) {
        snapshotSendPeriodType = Common.TIME_PERIOD_CODES.getId(text);
        if (snapshotSendPeriodType == -1)
            throw new TranslatableJsonException("emport.error.invalid", "snapshotSendPeriodType", text, Common.TIME_PERIOD_CODES.getCodeList());
    }
    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());
                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()));
                }
            }
        }
    }
}
Also used : ExportCodes(com.serotonin.m2m2.util.ExportCodes) TranslatableJsonException(com.serotonin.m2m2.i18n.TranslatableJsonException) JsonObject(com.serotonin.json.type.JsonObject)

Example 37 with AlarmLevels

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

the class EventInstanceDaoTest method testPurgeEventsBeforeByAlarmLevel.

@Test
public void testPurgeEventsBeforeByAlarmLevel() {
    long refTime = System.currentTimeMillis();
    createEvents(10, 2, refTime);
    assertEquals(10, eventDao.getEventCount());
    assertEquals(20, userCommentDao.count());
    AlarmLevels alarmLevel = newVO().getAlarmLevel();
    int count = eventDao.purgeEventsBefore(refTime, alarmLevel);
    assertEquals(5, count);
    assertEquals(5, eventDao.getEventCount());
    assertEquals(10, userCommentDao.count());
}
Also used : AlarmLevels(com.serotonin.m2m2.rt.event.AlarmLevels) Test(org.junit.Test)

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