Search in sources :

Example 1 with ExportCodes

use of com.serotonin.m2m2.util.ExportCodes in project ma-core-public by infiniteautomation.

the class AbstractPublisherModel method getAlarmLevels.

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)

Example 2 with ExportCodes

use of com.serotonin.m2m2.util.ExportCodes in project ma-core-public by infiniteautomation.

the class AbstractPublisherModel method setAlarmLevels.

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)

Example 3 with ExportCodes

use of com.serotonin.m2m2.util.ExportCodes 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);
    name = jsonObject.getString("name");
    enabled = jsonObject.getBoolean("enabled");
    // Don't change the type.
    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);
                int level = AlarmLevels.CODES.getId(text);
                if (!AlarmLevels.CODES.isValidId(level))
                    throw new TranslatableJsonException("emport.error.alarmLevel", text, code, AlarmLevels.CODES.getCodeList());
                setAlarmLevel(eventId, level);
            }
        }
    }
    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());
    }
}
Also used : ExportCodes(com.serotonin.m2m2.util.ExportCodes) JsonObject(com.serotonin.json.type.JsonObject) TranslatableJsonException(com.serotonin.m2m2.i18n.TranslatableJsonException)

Example 4 with ExportCodes

use of com.serotonin.m2m2.util.ExportCodes in project ma-core-public by infiniteautomation.

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);
    name = jsonObject.getString("name");
    enabled = jsonObject.getBoolean("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 = jsonObject.getBoolean("changesOnly");
        if (changesOnly) {
            this.publishType = PublishType.CHANGES_ONLY;
        } else {
            this.publishType = PublishType.ALL;
        }
    }
    // Could wrap the readInto with a try-catch in case one dataPointId entry is null,
    // however this would be a silent suppression of the issue, so we have elected not to.
    // infiniteautomation/ma-core-public#948
    JsonArray arr = jsonObject.getJsonArray("points");
    if (arr != null) {
        points.clear();
        for (JsonValue jv : arr) {
            T point = createPublishedPointInstance();
            reader.readInto(point, jv.toJsonObject());
            points.add(point);
        }
    }
    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);
                int level = AlarmLevels.CODES.getId(text);
                if (!AlarmLevels.CODES.isValidId(level))
                    throw new TranslatableJsonException("emport.error.alarmLevel", text, code, AlarmLevels.CODES.getCodeList());
                setAlarmLevel(eventId, level);
            }
        }
    }
}
Also used : JsonArray(com.serotonin.json.type.JsonArray) ExportCodes(com.serotonin.m2m2.util.ExportCodes) PublisherRT(com.serotonin.m2m2.rt.publish.PublisherRT) JsonValue(com.serotonin.json.type.JsonValue) TranslatableJsonException(com.serotonin.m2m2.i18n.TranslatableJsonException) JsonObject(com.serotonin.json.type.JsonObject)

Example 5 with ExportCodes

use of com.serotonin.m2m2.util.ExportCodes in project ma-modules-public by infiniteautomation.

the class SystemSettingsRestController method updateMany.

@ApiOperation(value = "Update Many System Settings", notes = "Admin Privs Required")
@RequestMapping(method = RequestMethod.POST, consumes = { "application/json" }, produces = { "application/json" })
public ResponseEntity<Map<String, Object>> updateMany(@ApiParam(value = "Updated settings", required = true) @RequestBody(required = true) Map<String, Object> settings, UriComponentsBuilder builder, HttpServletRequest request) {
    RestProcessResult<Map<String, Object>> result = new RestProcessResult<Map<String, Object>>(HttpStatus.OK);
    this.checkUser(request, result);
    if (result.isOk()) {
        ProcessResult response = new ProcessResult();
        // Convert incoming ExportCodes to int values
        settings = this.dao.convertCodesToValues(settings);
        this.dao.validate(settings, response);
        if (response.getHasMessages()) {
            throw new ValidationException(response);
        }
        this.dao.updateSettings(settings);
        // J.W. WTF is this for?
        // Put a link to the updated data in the header
        URI location = builder.path("/v1/system-settings").buildAndExpand().toUri();
        result.addRestMessage(getResourceUpdatedMessage(location));
        return result.createResponseEntity(settings);
    }
    return result.createResponseEntity();
}
Also used : RestProcessResult(com.serotonin.m2m2.web.mvc.rest.v1.message.RestProcessResult) ValidationException(com.serotonin.m2m2.vo.exception.ValidationException) RestProcessResult(com.serotonin.m2m2.web.mvc.rest.v1.message.RestProcessResult) ProcessResult(com.serotonin.m2m2.i18n.ProcessResult) HashMap(java.util.HashMap) Map(java.util.Map) URI(java.net.URI) ApiOperation(com.wordnik.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

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