use of com.serotonin.json.JsonException in project ma-core-public by infiniteautomation.
the class JsonSerializableUtility method gatherJsonPropertyNames.
private Map<String, JsonProperty> gatherJsonPropertyNames(Class<?> clazz) throws JsonException {
// Ignore Object.
if (clazz == Object.class)
return null;
Map<String, JsonProperty> jsonProperties = new HashMap<>();
Field[] fields = clazz.getDeclaredFields();
for (Field field : fields) {
JsonProperty anno = field.getAnnotation(JsonProperty.class);
if (anno != null)
jsonProperties.put(field.getName(), anno);
}
Method[] methods = clazz.getDeclaredMethods();
for (Method method : methods) {
JsonProperty anno = method.getAnnotation(JsonProperty.class);
if (anno == null)
continue;
// Convert the method name to a property name using the JavaBean rules.
String name = method.getName();
if (method.getReturnType() == Boolean.TYPE) {
if (!name.startsWith("is"))
throw new JsonException("Non-JavaBean get methods cannot be marked with JsonRemoteProperty: " + clazz.getName() + "." + name);
name = Character.toLowerCase(name.charAt(2)) + name.substring(3);
} else {
if (!name.startsWith("get") && !name.startsWith("set"))
throw new JsonException("Non-JavaBean get methods cannot be marked with JsonRemoteProperty: " + clazz.getName() + "." + name);
name = Character.toLowerCase(name.charAt(3)) + name.substring(4);
}
jsonProperties.put(name, anno);
}
return jsonProperties;
}
use of com.serotonin.json.JsonException in project ma-core-public by infiniteautomation.
the class AuditEventType method raiseDeletedEvent.
public static void raiseDeletedEvent(String auditEventType, AbstractVO<?> o) {
Map<String, Object> context = new HashMap<String, Object>();
JsonSerializableUtility scanner = new JsonSerializableUtility();
try {
context = scanner.findValues(o);
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException | JsonException | IOException e) {
LOG.error(e.getMessage(), e);
}
raiseEvent(AuditEventInstanceVO.CHANGE_TYPE_DELETE, auditEventType, o, "event.audit.extended.deleted", context);
}
use of com.serotonin.json.JsonException in project ma-core-public by infiniteautomation.
the class AuditEventType method raiseAddedEvent.
public static void raiseAddedEvent(String auditEventType, AbstractVO<?> o) {
Map<String, Object> context = new HashMap<String, Object>();
JsonSerializableUtility scanner = new JsonSerializableUtility();
try {
context = scanner.findValues(o);
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException | JsonException | IOException e) {
LOG.error(e.getMessage(), e);
}
raiseEvent(AuditEventInstanceVO.CHANGE_TYPE_CREATE, auditEventType, o, "event.audit.extended.added", context);
}
use of com.serotonin.json.JsonException 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));
}
}
use of com.serotonin.json.JsonException in project ma-modules-public by infiniteautomation.
the class ReportEmportDefinition method doImport.
@Override
public void doImport(JsonValue jsonValue, ImportContext importContext) throws JsonException {
JsonObject reportJson = jsonValue.toJsonObject();
String xid = reportJson.getString("xid");
if (StringUtils.isBlank(xid))
xid = ReportDao.instance.generateUniqueXid();
ReportVO report = null;
try {
report = ReportDao.instance.getReport(xid);
} catch (IncorrectResultSizeDataAccessException e) {
importContext.getResult().addGenericMessage("reports.emport.duplicateXids", xid);
return;
}
if (report == null) {
report = new ReportVO();
report.setXid(xid);
}
try {
importContext.getReader().readInto(report, reportJson);
// Now validate it. Use a new response object so we can distinguish errors in this user from other
// errors.
ProcessResult reportResponse = new ProcessResult();
report.validate(reportResponse);
if (reportResponse.getHasMessages())
// Too bad. Copy the errors into the actual response.
importContext.copyValidationMessages(reportResponse, "emport.report.prefix", xid);
else {
// Sweet. Save it.
boolean isnew = report.getId() == Common.NEW_ID;
ReportDao.instance.saveReport(report);
importContext.addSuccessMessage(isnew, "emport.report.prefix", xid);
}
} catch (TranslatableJsonException e) {
importContext.getResult().addGenericMessage("emport.report.prefix", xid, e.getMsg());
} catch (JsonException e) {
importContext.getResult().addGenericMessage("emport.report.prefix", xid, importContext.getJsonExceptionMessage(e));
}
}
Aggregations