use of com.serotonin.json.type.JsonValue 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.JsonValue 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.JsonValue in project ma-core-public by infiniteautomation.
the class PublisherVO method jsonRead.
@Override
public void jsonRead(JsonReader reader, JsonObject jsonObject) throws JsonException {
// Not reading XID so can't do this: super.jsonRead(reader, jsonObject);
name = jsonObject.getString("name");
enabled = jsonObject.getBoolean("enabled");
// Legacy conversion for publishType
if (jsonObject.containsKey("publishType")) {
String publishTypeCode = jsonObject.getString("publishType");
int publishTypeId = PUBLISH_TYPE_CODES.getId(publishTypeCode);
if (publishTypeId == -1)
throw new TranslatableJsonException("emport.error.invalid", "publishType", publishTypeCode, PUBLISH_TYPE_CODES.getCodeList());
publishType = publishTypeId;
} else if (jsonObject.containsKey("changesOnly")) {
boolean changesOnly = jsonObject.getBoolean("changesOnly");
if (changesOnly) {
this.publishType = PublishType.CHANGES_ONLY;
} else {
this.publishType = PublishType.ALL;
}
}
// Could wrap the readInto with a try-catch in case one dataPointId entry is null,
// however this would be a silent suppression of the issue, so we have elected not to.
// infiniteautomation/ma-core-public#948
JsonArray arr = jsonObject.getJsonArray("points");
if (arr != null) {
points.clear();
for (JsonValue jv : arr) {
T point = createPublishedPointInstance();
reader.readInto(point, jv.toJsonObject());
points.add(point);
}
}
String text = jsonObject.getString("snapshotSendPeriodType");
if (text != null) {
snapshotSendPeriodType = Common.TIME_PERIOD_CODES.getId(text);
if (snapshotSendPeriodType == -1)
throw new TranslatableJsonException("emport.error.invalid", "snapshotSendPeriodType", text, Common.TIME_PERIOD_CODES.getCodeList());
}
JsonObject alarmCodeLevels = jsonObject.getJsonObject("alarmLevels");
if (alarmCodeLevels != null) {
ExportCodes eventCodes = getEventCodes();
if (eventCodes != null && eventCodes.size() > 0) {
for (String code : alarmCodeLevels.keySet()) {
int eventId = eventCodes.getId(code);
if (!eventCodes.isValidId(eventId))
throw new TranslatableJsonException("emport.error.eventCode", code, eventCodes.getCodeList());
text = alarmCodeLevels.getString(code);
int level = AlarmLevels.CODES.getId(text);
if (!AlarmLevels.CODES.isValidId(level))
throw new TranslatableJsonException("emport.error.alarmLevel", text, code, AlarmLevels.CODES.getCodeList());
setAlarmLevel(eventId, level);
}
}
}
}
use of com.serotonin.json.type.JsonValue in project ma-core-public by infiniteautomation.
the class PopulateTest method main.
public static void main(String[] args) throws Exception {
context = new JsonContext();
context.addFactory(new ObjectFactory() {
@Override
public Object create(JsonValue jsonValue) throws JsonException {
if (jsonValue.toJsonObject().containsKey("sub1Value"))
return new Subclass1();
if (jsonValue.toJsonObject().containsKey("sub2Value"))
return new Subclass2();
throw new JsonException("Unknown BaseClass: " + jsonValue);
}
}, BaseClass.class);
test1();
test2();
}
use of com.serotonin.json.type.JsonValue in project ma-core-public by infiniteautomation.
the class CollectionConverter method jsonRead.
@Override
public void jsonRead(JsonReader reader, JsonValue jsonValue, Object obj, Type type) throws JsonException {
JsonArray jsonArray = (JsonArray) jsonValue;
@SuppressWarnings("unchecked") Collection<Object> collection = (Collection<Object>) obj;
Type innerType = TypeUtils.getActualTypeArgument(type, 0);
for (JsonValue element : jsonArray) collection.add(reader.read(innerType, element));
}
Aggregations