use of com.serotonin.json.type.JsonObject in project ma-modules-public by infiniteautomation.
the class CompoundComponent method jsonRead.
@Override
public void jsonRead(JsonReader reader, JsonObject jsonObject) throws JsonException {
super.jsonRead(reader, jsonObject);
JsonObject jsonChildren = jsonObject.getJsonObject("children");
if (jsonChildren != null) {
for (Map.Entry<String, JsonValue> jsonChild : jsonChildren.entrySet()) {
CompoundChild child = getChild(jsonChild.getKey());
if (child == null || !child.getViewComponent().isPointComponent())
throw new TranslatableJsonException("emport.error.compound.invalidChildId", jsonChild.getKey(), definition().getId(), getPointComponentChildIds());
jsonReadDataPoint(jsonChild.getValue(), (PointComponent) child.getViewComponent());
}
}
}
use of com.serotonin.json.type.JsonObject in project ma-modules-public by infiniteautomation.
the class MultistateGraphicComponent method jsonRead.
@Override
public void jsonRead(JsonReader reader, JsonObject jsonObject) throws JsonException {
super.jsonRead(reader, jsonObject);
JsonArray jsonStateList = jsonObject.getJsonArray("stateImageMappings");
if (jsonStateList != null) {
stateImageMap.clear();
for (JsonValue jv : jsonStateList) {
JsonObject jsonMapping = jv.toJsonObject();
Integer state = jsonMapping.getInt("state");
if (state == null)
throw new TranslatableJsonException("emport.error.missingValue", "state");
Integer index = jsonMapping.getInt("imageIndex");
if (index == null)
throw new TranslatableJsonException("emport.error.missingValue", "index");
stateImageMap.put(state, index);
}
}
}
use of com.serotonin.json.type.JsonObject in project ma-modules-public by infiniteautomation.
the class ModulesRestController method getUpgrades.
@ApiOperation(value = "Get Available Upgrades", notes = "Check the store for Upgrades")
@RequestMapping(method = RequestMethod.GET, value = "/upgrades-available", produces = { "application/json" })
public ResponseEntity<ModuleUpgradesModel> getUpgrades(HttpServletRequest request) {
RestProcessResult<ModuleUpgradesModel> result = new RestProcessResult<ModuleUpgradesModel>(HttpStatus.OK);
User user = this.checkUser(request, result);
if (result.isOk()) {
if (Permissions.hasAdmin(user)) {
// Do the check
try {
JsonValue jsonResponse = ModulesDwr.getAvailableUpgrades();
if (jsonResponse instanceof JsonString) {
result.addRestMessage(getInternalServerErrorMessage(jsonResponse.toString()));
} else {
List<ModuleUpgradeModel> upgrades = new ArrayList<>();
List<ModuleUpgradeModel> newInstalls = new ArrayList<>();
ModuleUpgradesModel model = new ModuleUpgradesModel(upgrades, newInstalls);
JsonObject root = jsonResponse.toJsonObject();
JsonValue jsonUpgrades = root.get("upgrades");
JsonArray jsonUpgradesArray = jsonUpgrades.toJsonArray();
Iterator<JsonValue> it = jsonUpgradesArray.iterator();
while (it.hasNext()) {
JsonValue v = it.next();
if (v.getJsonValue("name") == null) {
it.remove();
continue;
}
String name = v.getJsonValue("name").toString();
Module module = "core".equals(name) ? ModuleRegistry.getCoreModule() : ModuleRegistry.getModule(name);
if (module == null) {
it.remove();
continue;
}
upgrades.add(new ModuleUpgradeModel(module, v));
}
JsonValue jsonInstalls = root.get("newInstalls");
JsonArray jsonInstallsArray = jsonInstalls.toJsonArray();
for (JsonValue v : jsonInstallsArray) {
newInstalls.add(new ModuleUpgradeModel(v));
}
return result.createResponseEntity(model);
}
} catch (SocketTimeoutException e) {
result.addRestMessage(HttpStatus.INTERNAL_SERVER_ERROR, new TranslatableMessage("rest.error.requestTimeout", Common.envProps.getString("store.url")));
} catch (UnknownHostException e) {
result.addRestMessage(HttpStatus.INTERNAL_SERVER_ERROR, new TranslatableMessage("rest.error.unknownHost", Common.envProps.getString("store.url")));
} catch (Exception e) {
result.addRestMessage(getInternalServerErrorMessage(e.getMessage()));
}
} else {
result.addRestMessage(this.getUnauthorizedMessage());
}
}
return result.createResponseEntity();
}
use of com.serotonin.json.type.JsonObject in project ma-modules-public by infiniteautomation.
the class ModuleUpgradeModel method loadFromStoreJson.
public void loadFromStoreJson(JsonValue v) {
this.dependencyVersions = new HashMap<>();
JsonValue sub = v.getJsonValue("name");
if (sub != null)
this.name = sub.toString();
sub = v.getJsonValue("version");
if (sub != null)
this.newVersion = sub.toString();
sub = v.getJsonValue("fullVersion");
if (sub != null)
this.newVersion = sub.toString();
sub = v.getJsonValue("shortDescription");
if (sub != null)
this.description = sub.toString();
sub = v.getJsonValue("longDescription");
if (sub != null)
this.longDescription = sub.toString();
sub = v.getJsonValue("vendorName");
if (sub != null)
this.vendor = sub.toString();
sub = v.getJsonValue("vendorUrl");
if (sub != null)
this.vendorUrl = sub.toString();
sub = v.getJsonValue("releaseNotes");
if (sub != null)
this.releaseNotes = sub.toString();
JsonValue dependencies = v.getJsonValue("dependencies");
JsonValue fullDependencies = v.getJsonValue("fullDependencies");
if (dependencies instanceof JsonArray && !(fullDependencies instanceof JsonObject)) {
dependencies.toList().forEach((obj) -> {
String moduleName = obj.toString();
String versionRange = Common.getVersion().getMajorVersion() + "." + Common.getVersion().getMinorVersion();
this.dependencyVersions.put(moduleName, versionRange);
});
}
if (fullDependencies instanceof JsonObject) {
fullDependencies.toMap().forEach((key, value) -> {
this.dependencyVersions.put(key, value.toString());
});
}
this.dependencies = this.dependencyVersions.entrySet().stream().map((entry) -> {
return entry.getKey() + ":" + entry.getValue();
}).collect(Collectors.joining(","));
}
use of com.serotonin.json.type.JsonObject 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