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