use of com.serotonin.json.type.JsonArray in project ma-core-public by infiniteautomation.
the class EventDetectorImporter method importImpl.
@Override
protected void importImpl() {
String dataPointXid = json.getString("dataPointXid");
DataPointVO dpvo;
// Everyone is in the same thread so no synchronization on dataPointMap required.
if (dataPointMap.containsKey(dataPointXid))
dpvo = dataPointMap.get(dataPointXid);
else if (StringUtils.isEmpty(dataPointXid) || (dpvo = DataPointDao.instance.getByXid(dataPointXid)) == null) {
addFailureMessage("emport.error.missingPoint", dataPointXid);
return;
} else {
dataPointMap.put(dataPointXid, dpvo);
// We're only going to use this to house event detectors imported in the eventDetectors object.
dpvo.setEventDetectors(new ArrayList<AbstractPointEventDetectorVO<?>>());
}
String typeStr = json.getString("type");
if (typeStr == null)
addFailureMessage("emport.error.ped.missingAttr", "type");
EventDetectorDefinition<?> def = ModuleRegistry.getEventDetectorDefinition(typeStr);
if (def == null) {
addFailureMessage("emport.error.ped.invalid", "type", typeStr, ModuleRegistry.getEventDetectorDefinitionTypes());
return;
}
JsonArray handlerXids = json.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) {
addFailureMessage("emport.eventHandler.missing", handlerXids.getString(k));
return;
}
}
AbstractEventDetectorVO<?> importing = def.baseCreateEventDetectorVO();
importing.setDefinition(def);
String xid = json.getString("xid");
// Create a new one
importing.setId(Common.NEW_ID);
importing.setXid(xid);
AbstractPointEventDetectorVO<?> dped = (AbstractPointEventDetectorVO<?>) importing;
dped.njbSetDataPoint(dpvo);
dpvo.getEventDetectors().add(dped);
try {
ctx.getReader().readInto(importing, json);
// try {
// if(Common.runtimeManager.getState() == RuntimeManager.RUNNING){
// Common.runtimeManager.saveDataPoint(dpvo);
// addSuccessMessage(isNew, "emport.eventDetector.prefix", xid);
// }else{
// addFailureMessage(new ProcessMessage("Runtime Manager not running point with xid: " + xid + " not saved."));
// }
// } catch(LicenseViolatedException e) {
// addFailureMessage(new ProcessMessage(e.getErrorMessage()));
// }
} catch (TranslatableJsonException e) {
addFailureMessage("emport.eventDetector.prefix", xid, e.getMsg());
} catch (JsonException e) {
addFailureMessage("emport.eventDetector.prefix", xid, getJsonExceptionMessage(e));
}
}
use of com.serotonin.json.type.JsonArray in project ma-core-public by infiniteautomation.
the class JsonArrayConverter method jsonRead.
@Override
public void jsonRead(JsonReader reader, JsonValue jsonValue, Object obj, Type type) throws JsonException {
JsonArray jsonArray = (JsonArray) obj;
jsonArray.clear();
jsonArray.addAll(jsonValue.toJsonArray());
}
use of com.serotonin.json.type.JsonArray in project ma-core-public by infiniteautomation.
the class ArrayConverter method jsonWrite.
@Override
public JsonValue jsonWrite(JsonTypeWriter writer, Object value) throws JsonException {
int length = Array.getLength(value);
JsonArray jsonArray = new JsonArray();
for (int i = 0; i < length; i++) jsonArray.add(writer.writeObject(Array.get(value, i)));
return jsonArray;
}
use of com.serotonin.json.type.JsonArray in project ma-core-public by infiniteautomation.
the class ArrayConverter method newInstance.
@Override
protected Object newInstance(JsonContext context, JsonValue jsonValue, Type type) {
JsonArray jsonArray = (JsonArray) jsonValue;
Class<?> clazz = TypeUtils.getRawClass(type).getComponentType();
return Array.newInstance(clazz, jsonArray.size());
}
use of com.serotonin.json.type.JsonArray in project ma-core-public by infiniteautomation.
the class ArrayConverter method jsonRead.
@Override
public void jsonRead(JsonReader reader, JsonValue jsonValue, Object array, Type type) throws JsonException {
JsonArray jsonArray = (JsonArray) jsonValue;
Class<?> clazz = array.getClass().getComponentType();
for (int i = 0; i < jsonArray.size(); i++) {
try {
Array.set(array, i, reader.read(clazz, jsonArray.get(i)));
} catch (Exception e) {
throw new JsonException("JsonException reading array element " + i, e);
}
}
}
Aggregations