use of com.serotonin.json.type.JsonString in project ma-core-public by infiniteautomation.
the class ModulesDwr method upgradesAvailable.
/**
* How many upgrades are available
* @return
* @throws Exception
*/
public static int upgradesAvailable() throws Exception {
JsonValue jsonResponse = getAvailableUpgrades();
if (jsonResponse instanceof JsonString)
throw new Exception("Mango Store Response Error: " + jsonResponse.toString());
JsonObject root = jsonResponse.toJsonObject();
int size = root.getJsonArray("upgrades").size();
if (size > 0) {
// Notify the listeners
JsonValue jsonUpgrades = root.get("upgrades");
JsonArray jsonUpgradesArray = jsonUpgrades.toJsonArray();
for (JsonValue v : jsonUpgradesArray) {
for (ModuleNotificationListener l : listeners) l.moduleUpgradeAvailable(v.getJsonValue("name").toString(), v.getJsonValue("version").toString());
}
JsonValue jsonInstalls = root.get("newInstalls");
JsonArray jsonInstallsArray = jsonInstalls.toJsonArray();
for (JsonValue v : jsonInstallsArray) {
for (ModuleNotificationListener l : listeners) l.newModuleAvailable(v.getJsonValue("name").toString(), v.getJsonValue("version").toString());
}
}
return size;
}
use of com.serotonin.json.type.JsonString in project ma-core-public by infiniteautomation.
the class ModulesDwr method versionCheck.
@DwrPermission(admin = true)
public ProcessResult versionCheck() {
ProcessResult result = new ProcessResult();
if (UPGRADE_DOWNLOADER != null) {
result.addData("error", Common.translate("modules.versionCheck.occupied"));
return result;
}
try {
JsonValue jsonResponse = getAvailableUpgrades();
if (jsonResponse instanceof JsonString)
result.addData("error", jsonResponse.toString());
else {
JsonObject root = jsonResponse.toJsonObject();
result.addData("upgrades", root.get("upgrades").toNative());
result.addData("newInstalls", root.get("newInstalls").toNative());
if (root.containsKey("upgradesError"))
result.addData("upgradesError", root.getString("upgradesError"));
if (root.containsKey("updates")) {
result.addData("updates", root.get("updates").toNative());
result.addData("newInstalls-oldCore", root.get("newInstalls-oldCore").toNative());
}
if (root.containsKey("missingModules"))
result.addData("missingModules", root.getJsonArray("missingModules").toNative());
}
} catch (UnknownHostException e) {
LOG.error("", e);
result.addData("unknownHost", e.getMessage());
} catch (Exception e) {
LOG.error("", e);
result.addData("error", e.getMessage());
}
return result;
}
use of com.serotonin.json.type.JsonString 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.JsonString in project ma-core-public by infiniteautomation.
the class VarNames method jsonWriteVarContext.
public static void jsonWriteVarContext(ObjectWriter writer, List<IntStringPair> context) throws IOException, JsonException {
DataPointDao dataPointDao = DataPointDao.instance;
JsonArray pointList = new JsonArray();
for (IntStringPair p : context) {
JsonObject point = new JsonObject();
pointList.add(point);
point.put("varName", new JsonString(p.getValue()));
point.put("dataPointXid", new JsonString(dataPointDao.getXidById(p.getKey())));
}
writer.writeEntry("context", pointList);
}
use of com.serotonin.json.type.JsonString 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);
}
Aggregations