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()));
}
}
}
}
}
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());
}
Aggregations