use of com.serotonin.json.type.JsonArray in project ma-core-public by infiniteautomation.
the class SetPointEventHandlerVO method jsonRead.
@Override
public void jsonRead(JsonReader reader, JsonObject jsonObject) throws JsonException {
super.jsonRead(reader, jsonObject);
DataPointDao dataPointDao = DataPointDao.instance;
String xid = jsonObject.getString("targetPointId");
if (xid != null) {
Integer id = dataPointDao.getIdByXid(xid);
if (id == null)
throw new TranslatableJsonException("emport.error.missingPoint", xid);
targetPointId = id;
}
// Active
String text = jsonObject.getString("activeAction");
if (text != null) {
activeAction = SET_ACTION_CODES.getId(text);
if (!SET_ACTION_CODES.isValidId(activeAction))
throw new TranslatableJsonException("emport.error.eventHandler.invalid", "activeAction", text, SET_ACTION_CODES.getCodeList());
}
if (activeAction == SET_ACTION_POINT_VALUE) {
xid = jsonObject.getString("activePointId");
if (xid != null) {
Integer id = dataPointDao.getIdByXid(xid);
if (id == null)
throw new TranslatableJsonException("emport.error.missingPoint", xid);
activePointId = id;
}
} else if (activeAction == SET_ACTION_STATIC_VALUE) {
text = jsonObject.getString("activeValueToSet");
if (text != null)
activeValueToSet = text;
} else if (activeAction == SET_ACTION_SCRIPT_VALUE) {
text = jsonObject.getString("activeScript");
if (text == null)
throw new TranslatableJsonException("emport.error.eventHandler.invalid", "inactiveScript");
activeValueToSet = text;
}
// Inactive
text = jsonObject.getString("inactiveAction");
if (text != null) {
inactiveAction = SET_ACTION_CODES.getId(text);
if (!SET_ACTION_CODES.isValidId(inactiveAction))
throw new TranslatableJsonException("emport.error.eventHandler.invalid", "inactiveAction", text, SET_ACTION_CODES.getCodeList());
}
if (inactiveAction == SET_ACTION_POINT_VALUE) {
xid = jsonObject.getString("inactivePointId");
if (xid != null) {
Integer id = dataPointDao.getIdByXid(xid);
if (id == null)
throw new TranslatableJsonException("emport.error.missingPoint", xid);
inactivePointId = id;
}
} else if (inactiveAction == SET_ACTION_STATIC_VALUE) {
text = jsonObject.getString("inactiveValueToSet");
if (text != null)
inactiveValueToSet = text;
} else if (inactiveAction == SET_ACTION_SCRIPT_VALUE) {
text = jsonObject.getString("inactiveScript");
if (text == null)
throw new TranslatableJsonException("emport.error.eventHandler.invalid", "inactiveScript");
inactiveValueToSet = text;
}
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");
Integer id = DataPointDao.instance.getIdByXid(dataPointXid);
if (id == 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(id, contextKey));
}
this.additionalContext = additionalContext;
} else
this.additionalContext = new ArrayList<>();
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.JsonArray in project ma-core-public by infiniteautomation.
the class SetPointEventHandlerVO method jsonWrite.
@Override
public void jsonWrite(ObjectWriter writer) throws IOException, JsonException {
super.jsonWrite(writer);
String dpXid = DataPointDao.instance.getXidById(targetPointId);
writer.writeEntry("targetPointId", dpXid);
// Active
writer.writeEntry("activeAction", SET_ACTION_CODES.getCode(activeAction));
if (activeAction == SET_ACTION_POINT_VALUE) {
dpXid = DataPointDao.instance.getXidById(activePointId);
writer.writeEntry("activePointId", dpXid);
} else if (activeAction == SET_ACTION_STATIC_VALUE)
writer.writeEntry("activeValueToSet", activeValueToSet);
else if (activeAction == SET_ACTION_SCRIPT_VALUE)
writer.writeEntry("activeScript", activeScript);
// Inactive
writer.writeEntry("inactiveAction", SET_ACTION_CODES.getCode(inactiveAction));
if (inactiveAction == SET_ACTION_POINT_VALUE) {
dpXid = DataPointDao.instance.getXidById(inactivePointId);
writer.writeEntry("inactivePointId", dpXid);
} else if (inactiveAction == SET_ACTION_STATIC_VALUE)
writer.writeEntry("inactiveValueToSet", inactiveValueToSet);
else if (inactiveAction == SET_ACTION_SCRIPT_VALUE)
writer.writeEntry("inactiveScript", inactiveScript);
JsonArray context = new JsonArray();
for (IntStringPair pnt : additionalContext) {
DataPointVO dpvo = DataPointDao.instance.getDataPoint(pnt.getKey(), false);
if (dpvo != null) {
JsonObject point = new JsonObject();
point.put("dataPointXid", dpvo.getXid());
point.put("contextKey", pnt.getValue());
context.add(point);
}
}
writer.writeEntry("additionalContext", context);
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.JsonArray in project ma-core-public by infiniteautomation.
the class AbstractEventDetectorVO method jsonRead.
@Override
public void jsonRead(JsonReader reader, JsonObject jsonObject) throws JsonException {
name = jsonObject.getString("alias");
// In keeping with data points, the import can only add mappings
// The "handlers" key is removed by the EventDetectorRowMapper
JsonArray handlers = jsonObject.getJsonArray("handlers");
if (handlers != null) {
addedEventHandlerXids = new ArrayList<String>(handlers.size());
Iterator<JsonValue> iter = handlers.iterator();
while (iter.hasNext()) addedEventHandlerXids.add(iter.next().toString());
}
}
use of com.serotonin.json.type.JsonArray in project ma-core-public by infiniteautomation.
the class PointFolder method jsonRead.
@Override
public void jsonRead(JsonReader reader, JsonObject jsonObject) throws JsonException {
JsonArray jsonPoints = jsonObject.getJsonArray("points");
if (jsonPoints != null) {
points.clear();
DataPointDao dataPointDao = DataPointDao.instance;
for (JsonValue jv : jsonPoints) {
String xid = jv.toString();
DataPointVO dp = dataPointDao.getDataPoint(xid);
if (dp == null)
throw new TranslatableJsonException("emport.error.missingPoint", xid);
points.add(new DataPointSummary(dp));
}
}
}
use of com.serotonin.json.type.JsonArray in project ma-core-public by infiniteautomation.
the class VarNames method jsonWriteVarContext.
public static void jsonWriteVarContext(ObjectWriter writer, List<IntStringPair> context) throws IOException, JsonException {
DataPointDao dataPointDao = DataPointDao.instance;
JsonArray pointList = new JsonArray();
for (IntStringPair p : context) {
JsonObject point = new JsonObject();
pointList.add(point);
point.put("varName", new JsonString(p.getValue()));
point.put("dataPointXid", new JsonString(dataPointDao.getXidById(p.getKey())));
}
writer.writeEntry("context", pointList);
}
Aggregations