use of com.serotonin.json.type.JsonObject in project ma-core-public by infiniteautomation.
the class EmailEventHandlerVO method jsonWrite.
@Override
public void jsonWrite(ObjectWriter writer) throws IOException, JsonException {
super.jsonWrite(writer);
writer.writeEntry("activeRecipients", activeRecipients);
writer.writeEntry("sendEscalation", sendEscalation);
if (sendEscalation) {
writer.writeEntry("escalationDelayType", Common.TIME_PERIOD_CODES.getCode(escalationDelayType));
writer.writeEntry("escalationDelay", escalationDelay);
writer.writeEntry("escalationRecipients", escalationRecipients);
writer.writeEntry("keepSendingEscalations", repeatEscalations);
}
writer.writeEntry("sendInactive", sendInactive);
if (sendInactive) {
writer.writeEntry("inactiveOverride", inactiveOverride);
if (inactiveOverride)
writer.writeEntry("inactiveRecipients", inactiveRecipients);
}
writer.writeEntry("includeSystemInformation", includeSystemInfo);
writer.writeEntry("includePointValueCount", includePointValueCount);
writer.writeEntry("includeLogfile", includeLogfile);
writer.writeEntry("customTemplate", customTemplate);
JsonArray context = new JsonArray();
for (IntStringPair pnt : additionalContext) {
DataPointVO dpvo = DataPointDao.instance.get(pnt.getKey());
if (dpvo != null) {
JsonObject point = new JsonObject();
point.put("dataPointXid", dpvo.getXid());
point.put("contextKey", pnt.getValue());
context.add(point);
}
}
writer.writeEntry("additionalContext", context);
writer.writeEntry("script", script);
if (scriptPermissions != null) {
JsonObject permissions = new JsonObject();
permissions.put(ScriptPermissions.DATA_SOURCE, scriptPermissions.getDataSourcePermissions());
permissions.put(ScriptPermissions.DATA_POINT_READ, scriptPermissions.getDataPointReadPermissions());
permissions.put(ScriptPermissions.DATA_POINT_SET, scriptPermissions.getDataPointSetPermissions());
writer.writeEntry("scriptPermissions", permissions);
} else {
writer.writeEntry("scriptPermissions", null);
}
}
use of com.serotonin.json.type.JsonObject in project ma-core-public by infiniteautomation.
the class EmailEventHandlerVO method jsonRead.
@SuppressWarnings("unchecked")
@Override
public void jsonRead(JsonReader reader, JsonObject jsonObject) throws JsonException {
super.jsonRead(reader, jsonObject);
String text = null;
TypeDefinition recipType = new TypeDefinition(List.class, RecipientListEntryBean.class);
JsonArray jsonActiveRecipients = jsonObject.getJsonArray("activeRecipients");
if (jsonActiveRecipients != null)
activeRecipients = (List<RecipientListEntryBean>) reader.read(recipType, jsonActiveRecipients);
JsonBoolean b = jsonObject.getJsonBoolean("sendEscalation");
if (b != null)
sendEscalation = b.booleanValue();
if (sendEscalation) {
text = jsonObject.getString("escalationDelayType");
if (text != null) {
escalationDelayType = Common.TIME_PERIOD_CODES.getId(text);
if (escalationDelayType == -1)
throw new TranslatableJsonException("emport.error.invalid", "escalationDelayType", text, Common.TIME_PERIOD_CODES.getCodeList());
}
Integer i = jsonObject.getInt("escalationDelay", 1);
if (i != null)
escalationDelay = i;
JsonArray jsonEscalationRecipients = jsonObject.getJsonArray("escalationRecipients");
if (jsonEscalationRecipients != null)
escalationRecipients = (List<RecipientListEntryBean>) reader.read(recipType, jsonEscalationRecipients);
b = jsonObject.getJsonBoolean("keepSendingEscalations");
if (b != null)
repeatEscalations = b.booleanValue();
}
b = jsonObject.getJsonBoolean("sendInactive");
if (b != null)
sendInactive = b.booleanValue();
if (sendInactive) {
b = jsonObject.getJsonBoolean("inactiveOverride");
if (b != null)
inactiveOverride = b.booleanValue();
if (inactiveOverride) {
JsonArray jsonInactiveRecipients = jsonObject.getJsonArray("inactiveRecipients");
if (jsonInactiveRecipients != null)
inactiveRecipients = (List<RecipientListEntryBean>) reader.read(recipType, jsonInactiveRecipients);
}
}
b = jsonObject.getJsonBoolean("includeSystemInformation");
if (b != null)
includeSystemInfo = b.booleanValue();
includePointValueCount = jsonObject.getInt("includePointValueCount", 0);
b = jsonObject.getJsonBoolean("includeLogfile");
if (b != null)
includeSystemInfo = b.booleanValue();
customTemplate = jsonObject.getString("customTemplate");
JsonArray context = jsonObject.getJsonArray("additionalContext");
if (context != null) {
List<IntStringPair> additionalContext = new ArrayList<>();
for (JsonValue jv : context) {
JsonObject jo = jv.toJsonObject();
String dataPointXid = jo.getString("dataPointXid");
if (dataPointXid == null)
throw new TranslatableJsonException("emport.error.context.missing", "dataPointXid");
DataPointVO dpvo = DataPointDao.instance.getByXid(dataPointXid);
if (dpvo == null)
throw new TranslatableJsonException("emport.error.missingPoint", dataPointXid);
String contextKey = jo.getString("contextKey");
if (contextKey == null)
throw new TranslatableJsonException("emport.error.context.missing", "contextKey");
additionalContext.add(new IntStringPair(dpvo.getId(), contextKey));
}
this.additionalContext = additionalContext;
} else
this.additionalContext = new ArrayList<>();
script = jsonObject.getString("script");
JsonObject permissions = jsonObject.getJsonObject("scriptPermissions");
ScriptPermissions scriptPermissions = new ScriptPermissions();
if (permissions != null) {
String perm = permissions.getString(ScriptPermissions.DATA_SOURCE);
if (perm != null)
scriptPermissions.setDataSourcePermissions(perm);
perm = permissions.getString(ScriptPermissions.DATA_POINT_READ);
if (perm != null)
scriptPermissions.setDataPointReadPermissions(perm);
perm = permissions.getString(ScriptPermissions.DATA_POINT_SET);
if (perm != null)
scriptPermissions.setDataPointSetPermissions(perm);
}
this.scriptPermissions = scriptPermissions;
}
use of com.serotonin.json.type.JsonObject in project ma-core-public by infiniteautomation.
the class DataPointVO 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");
String text = jsonObject.getString("loggingType");
if (text != null) {
loggingType = LOGGING_TYPE_CODES.getId(text);
if (loggingType == -1)
throw new TranslatableJsonException("emport.error.invalid", "loggingType", text, LOGGING_TYPE_CODES.getCodeList());
}
text = jsonObject.getString("intervalLoggingPeriodType");
if (text != null) {
intervalLoggingPeriodType = Common.TIME_PERIOD_CODES.getId(text);
if (intervalLoggingPeriodType == -1)
throw new TranslatableJsonException("emport.error.invalid", "intervalLoggingPeriodType", text, Common.TIME_PERIOD_CODES.getCodeList());
}
text = jsonObject.getString("intervalLoggingType");
if (text != null) {
intervalLoggingType = INTERVAL_LOGGING_TYPE_CODES.getId(text);
if (intervalLoggingType == -1)
throw new TranslatableJsonException("emport.error.invalid", "intervalLoggingType", text, INTERVAL_LOGGING_TYPE_CODES.getCodeList());
}
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(TimePeriods.MILLISECONDS, TimePeriods.SECONDS, TimePeriods.MINUTES, TimePeriods.HOURS));
}
JsonObject locatorJson = jsonObject.getJsonObject("pointLocator");
if (locatorJson != null)
reader.readInto(pointLocator, locatorJson);
JsonArray pedArray = jsonObject.getJsonArray("eventDetectors");
if (pedArray != null) {
for (JsonValue jv : pedArray) {
JsonObject pedObject = jv.toJsonObject();
String pedXid = pedObject.getString("xid");
if (StringUtils.isBlank(pedXid))
throw new TranslatableJsonException("emport.error.ped.missingAttr", "xid");
// Use the ped xid to lookup an existing ped.
AbstractEventDetectorVO<?> ped = null;
for (AbstractPointEventDetectorVO<?> existing : eventDetectors) {
if (StringUtils.equals(pedXid, existing.getXid())) {
ped = existing;
break;
}
}
JsonArray handlerXids = pedObject.getJsonArray("handlers");
if (handlerXids != null)
for (int k = 0; k < handlerXids.size(); k += 1) {
AbstractEventHandlerVO<?> eh = EventHandlerDao.instance.getByXid(handlerXids.getString(k));
if (eh == null) {
throw new TranslatableJsonException("emport.eventHandler.missing", handlerXids.getString(k));
}
}
if (ped == null) {
String typeStr = pedObject.getString("type");
if (typeStr == null)
throw new TranslatableJsonException("emport.error.ped.missingAttr", "type");
EventDetectorDefinition<?> def = ModuleRegistry.getEventDetectorDefinition(typeStr);
if (def == null)
throw new TranslatableJsonException("emport.error.ped.invalid", "type", typeStr, ModuleRegistry.getEventDetectorDefinitionTypes());
else {
ped = def.baseCreateEventDetectorVO();
ped.setDefinition(def);
}
// Create a new one
ped.setId(Common.NEW_ID);
ped.setXid(pedXid);
AbstractPointEventDetectorVO<?> dped = (AbstractPointEventDetectorVO<?>) ped;
dped.njbSetDataPoint(this);
eventDetectors.add(dped);
}
reader.readInto(ped, pedObject);
}
}
text = jsonObject.getString("unit");
if (text != null) {
unit = parseUnitString(text, "unit");
unitString = UnitUtil.formatUcum(unit);
}
text = jsonObject.getString("integralUnit");
if (text != null) {
useIntegralUnit = true;
integralUnit = parseUnitString(text, "integralUnit");
integralUnitString = UnitUtil.formatUcum(integralUnit);
}
text = jsonObject.getString("renderedUnit");
if (text != null) {
useRenderedUnit = true;
renderedUnit = parseUnitString(text, "renderedUnit");
renderedUnitString = UnitUtil.formatUcum(renderedUnit);
}
text = jsonObject.getString("plotType");
if (text != null) {
plotType = PLOT_TYPE_CODES.getId(text);
if (plotType == -1)
throw new TranslatableJsonException("emport.error.invalid", "plotType", text, PLOT_TYPE_CODES.getCodeList());
}
// Rollup
text = jsonObject.getString("rollup");
if (text != null) {
rollup = Common.ROLLUP_CODES.getId(text);
if (rollup == -1)
throw new TranslatableJsonException("emport.error.chart.invalid", "rollup", text, Common.ROLLUP_CODES.getCodeList());
}
// Simplify
text = jsonObject.getString("simplifyType");
if (text != null) {
simplifyType = SIMPLIFY_TYPE_CODES.getId(text);
if (simplifyType == -1)
throw new TranslatableJsonException("emport.error.invalid", "simplifyType", text, SIMPLIFY_TYPE_CODES.getCodeList());
}
int simplifyTarget = jsonObject.getInt("simplifyTarget", Integer.MIN_VALUE);
if (simplifyTarget != Integer.MIN_VALUE)
this.simplifyTarget = simplifyTarget;
double simplifyTolerance = jsonObject.getDouble("simplifyTolerance", Double.NaN);
if (simplifyTolerance != Double.NaN)
this.simplifyTolerance = simplifyTolerance;
}
use of com.serotonin.json.type.JsonObject 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.json.type.JsonObject in project ma-core-public by infiniteautomation.
the class ModulesDwr method upgradesAvailable.
/**
* How many upgrades are available
* @return
* @throws Exception
*/
public static int upgradesAvailable() throws Exception {
JsonValue jsonResponse = getAvailableUpgrades();
if (jsonResponse instanceof JsonString)
throw new Exception("Mango Store Response Error: " + jsonResponse.toString());
JsonObject root = jsonResponse.toJsonObject();
int size = root.getJsonArray("upgrades").size();
if (size > 0) {
// Notify the listeners
JsonValue jsonUpgrades = root.get("upgrades");
JsonArray jsonUpgradesArray = jsonUpgrades.toJsonArray();
for (JsonValue v : jsonUpgradesArray) {
for (ModuleNotificationListener l : listeners) l.moduleUpgradeAvailable(v.getJsonValue("name").toString(), v.getJsonValue("version").toString());
}
JsonValue jsonInstalls = root.get("newInstalls");
JsonArray jsonInstallsArray = jsonInstalls.toJsonArray();
for (JsonValue v : jsonInstallsArray) {
for (ModuleNotificationListener l : listeners) l.newModuleAvailable(v.getJsonValue("name").toString(), v.getJsonValue("version").toString());
}
}
return size;
}
Aggregations