use of com.serotonin.m2m2.util.ExportCodes in project ma-core-public by infiniteautomation.
the class PublisherVO method jsonWrite.
@Override
public void jsonWrite(ObjectWriter writer) throws IOException, JsonException {
super.jsonWrite(writer);
writer.writeEntry("type", definition.getPublisherTypeName());
writer.writeEntry("points", points);
writer.writeEntry("snapshotSendPeriodType", Common.TIME_PERIOD_CODES.getCode(snapshotSendPeriodType));
writer.writeEntry("publishType", PUBLISH_TYPE_CODES.getCode(publishType));
ExportCodes eventCodes = getEventCodes();
if (eventCodes != null && eventCodes.size() > 0) {
Map<String, String> alarmCodeLevels = new HashMap<>();
for (int i = 0; i < eventCodes.size(); i++) {
int eventId = eventCodes.getId(i);
int level = getAlarmLevel(eventId, AlarmLevels.URGENT);
alarmCodeLevels.put(eventCodes.getCode(eventId), AlarmLevels.CODES.getCode(level));
}
writer.writeEntry("alarmLevels", alarmCodeLevels);
}
}
use of com.serotonin.m2m2.util.ExportCodes in project ma-core-public by infiniteautomation.
the class DataSourceVO method jsonWrite.
@Override
public void jsonWrite(ObjectWriter writer) throws IOException, JsonException {
super.jsonWrite(writer);
// Write the type
writer.writeEntry("type", this.definition.getDataSourceTypeName());
ExportCodes eventCodes = getEventCodes();
if (eventCodes != null && eventCodes.size() > 0) {
Map<String, String> alarmCodeLevels = new HashMap<>();
for (int i = 0; i < eventCodes.size(); i++) {
int eventId = eventCodes.getId(i);
int level = getAlarmLevel(eventId, AlarmLevels.URGENT);
alarmCodeLevels.put(eventCodes.getCode(eventId), AlarmLevels.CODES.getCode(level));
}
writer.writeEntry("alarmLevels", alarmCodeLevels);
}
writer.writeEntry("purgeType", Common.TIME_PERIOD_CODES.getCode(purgeType));
}
use of com.serotonin.m2m2.util.ExportCodes in project ma-core-public by infiniteautomation.
the class AbstractDataSourceModel method getAlarmLevels.
@JsonGetter(value = "alarmLevels")
public Map<String, String> getAlarmLevels() {
ExportCodes eventCodes = this.data.getEventCodes();
Map<String, String> alarmCodeLevels = new HashMap<>();
if (eventCodes != null && eventCodes.size() > 0) {
for (int i = 0; i < eventCodes.size(); i++) {
int eventId = eventCodes.getId(i);
int level = this.data.getAlarmLevel(eventId, AlarmLevels.URGENT);
alarmCodeLevels.put(eventCodes.getCode(eventId), AlarmLevels.CODES.getCode(level));
}
}
return alarmCodeLevels;
}
use of com.serotonin.m2m2.util.ExportCodes in project ma-core-public by infiniteautomation.
the class AbstractDataSourceModel method setAlarmLevels.
@JsonSetter(value = "alarmLevels")
public void setAlarmLevels(Map<String, String> alarmCodeLevels) throws TranslatableJsonException {
if (alarmCodeLevels != null) {
ExportCodes eventCodes = this.data.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.get(code);
int level = AlarmLevels.CODES.getId(text);
if (!AlarmLevels.CODES.isValidId(level))
throw new TranslatableJsonException("emport.error.alarmLevel", text, code, AlarmLevels.CODES.getCodeList());
this.data.setAlarmLevel(eventId, level);
}
}
}
}
use of com.serotonin.m2m2.util.ExportCodes in project ma-core-public by infiniteautomation.
the class EventType method getInt.
protected int getInt(JsonObject json, String name, ExportCodes codes) throws JsonException {
String text = json.getString(name);
if (text == null)
throw new TranslatableJsonException("emport.error.eventType.missing", name, codes.getCodeList());
int i = codes.getId(text);
if (i == -1)
throw new TranslatableJsonException("emport.error.eventType.invalid", name, text, codes.getCodeList());
return i;
}
Aggregations