Search in sources :

Example 1 with ModuleNotificationListener

use of com.serotonin.m2m2.module.ModuleNotificationListener 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;
}
Also used : JsonArray(com.serotonin.json.type.JsonArray) ModuleNotificationListener(com.serotonin.m2m2.module.ModuleNotificationListener) JsonValue(com.serotonin.json.type.JsonValue) JsonObject(com.serotonin.json.type.JsonObject) JsonString(com.serotonin.json.type.JsonString) JsonException(com.serotonin.json.JsonException) HttpException(org.apache.http.HttpException) ShouldNeverHappenException(com.serotonin.ShouldNeverHappenException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException)

Aggregations

ShouldNeverHappenException (com.serotonin.ShouldNeverHappenException)1 JsonException (com.serotonin.json.JsonException)1 JsonArray (com.serotonin.json.type.JsonArray)1 JsonObject (com.serotonin.json.type.JsonObject)1 JsonString (com.serotonin.json.type.JsonString)1 JsonValue (com.serotonin.json.type.JsonValue)1 ModuleNotificationListener (com.serotonin.m2m2.module.ModuleNotificationListener)1 IOException (java.io.IOException)1 UnknownHostException (java.net.UnknownHostException)1 HttpException (org.apache.http.HttpException)1