use of com.serotonin.json.type.JsonArray in project ma-core-public by infiniteautomation.
the class CollectionConverter method jsonWrite.
@Override
public JsonValue jsonWrite(JsonTypeWriter writer, Object value) throws JsonException {
JsonArray jsonArray = new JsonArray();
Iterator<?> iterator = ((Collection<?>) value).iterator();
while (iterator.hasNext()) {
Object o = iterator.next();
jsonArray.add(writer.writeObject(o));
}
return jsonArray;
}
use of com.serotonin.json.type.JsonArray in project ma-core-public by infiniteautomation.
the class JsonEmportScriptUtility method doExclusions.
private void doExclusions(JsonObject jo) {
for (JsonImportExclusion exclusion : importExclusions) {
if (jo.containsKey(exclusion.getImporterType())) {
JsonArray ja = jo.getJsonArray(exclusion.getImporterType());
int size = ja.size();
for (int k = 0; k < size; k += 1) {
JsonObject obj = ja.getJsonObject(k);
if (obj.containsKey(exclusion.getKey()) && obj.getString(exclusion.getKey()).equals(exclusion.getValue())) {
ja.remove(k);
k -= 1;
size -= 1;
}
}
}
}
}
use of com.serotonin.json.type.JsonArray in project ma-core-public by infiniteautomation.
the class ScriptContextVariable method jsonWriteVarContext.
public static void jsonWriteVarContext(ObjectWriter writer, List<ScriptContextVariable> context) throws IOException, JsonException {
DataPointDao dataPointDao = DataPointDao.instance;
JsonArray pointList = new JsonArray();
for (ScriptContextVariable p : context) {
String xid = dataPointDao.getXidById(p.getDataPointId());
JsonObject point = new JsonObject();
pointList.add(point);
point.put("varName", new JsonString(p.getVariableName()));
point.put("dataPointXid", new JsonString(xid));
point.put("updateContext", new JsonBoolean(p.isContextUpdate()));
}
writer.writeEntry("context", pointList);
}
use of com.serotonin.json.type.JsonArray in project ma-core-public by infiniteautomation.
the class ScriptContextVariable method jsonReadVarContext.
/**
* Read in context,
* @param json
* @param context
* @return if my XID is in the context, return the name it has to map into the VO otherwise return null
* @throws JsonException
*/
public static String jsonReadVarContext(JsonObject json, List<ScriptContextVariable> context, boolean isContextUpdate) throws JsonException {
JsonArray jsonContext = json.getJsonArray("context");
if (jsonContext != null) {
context.clear();
DataPointDao dataPointDao = DataPointDao.instance;
for (JsonValue jv : jsonContext) {
JsonObject jo = jv.toJsonObject();
String xid = jo.getString("dataPointXid");
if (xid == null)
throw new TranslatableJsonException("emport.error.context.missing", "dataPointXid");
Integer dpid = dataPointDao.getIdByXid(xid);
if (dpid == null) {
// This can also happen if the point is in its own context (Bug from legacy systems).
throw new TranslatableJsonException("emport.error.missingPoint", xid);
}
// For compatibility with varName and variableName json types
String var = jo.getString("varName");
if (var == null) {
var = jo.getString("variableName");
if (var == null)
throw new TranslatableJsonException("emport.error.context.missing", "varName");
}
// Default for legacy systems
if (jo.containsKey("updateContext"))
isContextUpdate = jo.getBoolean("updateContext");
context.add(new ScriptContextVariable(dpid, var, isContextUpdate));
}
}
return json.getString("variableName");
}
Aggregations