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