use of com.serotonin.json.type.JsonObject in project ma-core-public by infiniteautomation.
the class JsonEmportScriptUtility method doImportGetStatus.
public List<ProcessMessage> doImportGetStatus(String json) throws Exception {
if (admin) {
JsonTypeReader reader = new JsonTypeReader(json);
JsonValue value = reader.read();
JsonObject jo = value.toJsonObject();
if (importExclusions != null)
doExclusions(jo);
ScriptImportTask sit = new ScriptImportTask(jo);
sit.run(Common.timer.currentTimeMillis());
return sit.getMessages();
}
return null;
}
use of com.serotonin.json.type.JsonObject in project ma-core-public by infiniteautomation.
the class JsonEmportScriptUtility method doImport.
public void doImport(String json) throws Exception {
if (admin) {
JsonTypeReader reader = new JsonTypeReader(json);
JsonValue value = reader.read();
JsonObject jo = value.toJsonObject();
if (importExclusions != null)
doExclusions(jo);
ScriptImportTask sit = new ScriptImportTask(jo);
sit.run(Common.timer.currentTimeMillis());
}
}
use of com.serotonin.json.type.JsonObject in project ma-core-public by infiniteautomation.
the class VirtualSerialPortConfigResolver method resolve.
@Override
public Type resolve(JsonValue jsonValue) throws JsonException {
if (jsonValue == null)
return null;
JsonObject json = jsonValue.toJsonObject();
String text = json.getString("type");
if (text == null)
throw new TranslatableJsonException("emport.error.virtual.comm.missing", "type", VirtualSerialPortConfig.PORT_TYPE_CODES);
return findClass(text);
}
use of com.serotonin.json.type.JsonObject in project ma-core-public by infiniteautomation.
the class EventTypeResolver method resolve.
@Override
public Type resolve(JsonValue jsonValue) throws JsonException {
if (jsonValue == null)
throw new TranslatableJsonException("emport.error.eventType.null");
JsonObject json = jsonValue.toJsonObject();
String text = json.getString("sourceType");
if (text == null)
throw new TranslatableJsonException("emport.error.eventType.missing", "sourceType", EventType.SOURCE_NAMES.getCodeList());
if (!EventType.SOURCE_NAMES.hasCode(text))
throw new TranslatableJsonException("emport.error.eventType.invalid", "sourceType", text, EventType.SOURCE_NAMES.getCodeList());
if (text.equalsIgnoreCase(EventTypeNames.DATA_POINT))
return DataPointEventType.class;
if (text.equalsIgnoreCase(EventTypeNames.DATA_SOURCE))
return DataSourceEventType.class;
if (text.equalsIgnoreCase(EventTypeNames.SYSTEM))
return SystemEventType.class;
if (text.equalsIgnoreCase(EventTypeNames.PUBLISHER))
return PublisherEventType.class;
if (text.equalsIgnoreCase(EventTypeNames.AUDIT))
return AuditEventType.class;
EventTypeDefinition def = ModuleRegistry.getEventTypeDefinition(text);
if (def != null)
return def.getEventTypeClass();
return null;
}
use of com.serotonin.json.type.JsonObject in project ma-modules-public by infiniteautomation.
the class GraphicalViewEmportDefinition method doImport.
@Override
public void doImport(JsonValue jsonValue, ImportContext importContext) throws JsonException {
JsonObject viewJson = jsonValue.toJsonObject();
String xid = viewJson.getString("xid");
if (StringUtils.isBlank(xid))
xid = graphicalViewDao.generateUniqueXid();
ensureDao();
GraphicalView view = graphicalViewDao.getViewByXid(xid);
if (view == null) {
view = new GraphicalView();
view.setXid(xid);
}
try {
importContext.getReader().readInto(view, viewJson);
// Now validate it. Use a new response object so we can distinguish errors in this view from other
// errors.
ProcessResult viewResponse = new ProcessResult();
view.validate(viewResponse);
if (viewResponse.getHasMessages())
// Too bad. Copy the errors into the actual response.
importContext.copyValidationMessages(viewResponse, "emport.view.prefix", xid);
else {
// Sweet. Save it.
boolean isnew = view.isNew();
graphicalViewDao.saveView(view);
importContext.addSuccessMessage(isnew, "emport.view.prefix", xid);
}
} catch (TranslatableJsonException e) {
importContext.getResult().addGenericMessage("emport.view.prefix", xid, e.getMsg());
} catch (JsonException e) {
importContext.getResult().addGenericMessage("emport.view.prefix", xid, importContext.getJsonExceptionMessage(e));
}
}
Aggregations