Search in sources :

Example 6 with ExportCodes

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);
    }
}
Also used : ExportCodes(com.serotonin.m2m2.util.ExportCodes) HashMap(java.util.HashMap)

Example 7 with ExportCodes

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));
}
Also used : ExportCodes(com.serotonin.m2m2.util.ExportCodes) HashMap(java.util.HashMap)

Example 8 with ExportCodes

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;
}
Also used : ExportCodes(com.serotonin.m2m2.util.ExportCodes) HashMap(java.util.HashMap) JsonGetter(com.fasterxml.jackson.annotation.JsonGetter)

Example 9 with ExportCodes

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);
            }
        }
    }
}
Also used : ExportCodes(com.serotonin.m2m2.util.ExportCodes) TranslatableJsonException(com.serotonin.m2m2.i18n.TranslatableJsonException) JsonSetter(com.fasterxml.jackson.annotation.JsonSetter)

Example 10 with ExportCodes

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;
}
Also used : TranslatableJsonException(com.serotonin.m2m2.i18n.TranslatableJsonException)

Aggregations

ExportCodes (com.serotonin.m2m2.util.ExportCodes)8 TranslatableJsonException (com.serotonin.m2m2.i18n.TranslatableJsonException)5 HashMap (java.util.HashMap)5 JsonObject (com.serotonin.json.type.JsonObject)2 JsonGetter (com.fasterxml.jackson.annotation.JsonGetter)1 JsonSetter (com.fasterxml.jackson.annotation.JsonSetter)1 JsonArray (com.serotonin.json.type.JsonArray)1 JsonValue (com.serotonin.json.type.JsonValue)1 ProcessResult (com.serotonin.m2m2.i18n.ProcessResult)1 PublisherRT (com.serotonin.m2m2.rt.publish.PublisherRT)1 ValidationException (com.serotonin.m2m2.vo.exception.ValidationException)1 RestProcessResult (com.serotonin.m2m2.web.mvc.rest.v1.message.RestProcessResult)1 ApiOperation (com.wordnik.swagger.annotations.ApiOperation)1 URI (java.net.URI)1 Map (java.util.Map)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1