Search in sources :

Example 21 with JsonArray

use of com.serotonin.json.type.JsonArray in project ma-core-public by infiniteautomation.

the class VarNames method jsonReadVarContext.

public static void jsonReadVarContext(JsonObject json, List<IntStringPair> context) throws JsonException {
    JsonArray jsonContext = json.getJsonArray("context");
    if (jsonContext != null) {
        context.clear();
        DataPointDao dataPointDao = DataPointDao.instance;
        for (JsonValue jv : jsonContext) {
            JsonObject jo = jv.toJsonObject();
            String xid = jo.getString("dataPointXid");
            if (xid == null)
                throw new TranslatableJsonException("emport.error.meta.missing", "dataPointXid");
            Integer dpid = dataPointDao.getIdByXid(xid);
            if (dpid == null)
                throw new TranslatableJsonException("emport.error.missingPoint", xid);
            String var = jo.getString("varName");
            if (var == null)
                throw new TranslatableJsonException("emport.error.meta.missing", "varName");
            context.add(new IntStringPair(dpid, var));
        }
    }
}
Also used : JsonArray(com.serotonin.json.type.JsonArray) DataPointDao(com.serotonin.m2m2.db.dao.DataPointDao) IntStringPair(com.serotonin.db.pair.IntStringPair) JsonValue(com.serotonin.json.type.JsonValue) JsonObject(com.serotonin.json.type.JsonObject) TranslatableJsonException(com.serotonin.m2m2.i18n.TranslatableJsonException) JsonString(com.serotonin.json.type.JsonString)

Example 22 with JsonArray

use of com.serotonin.json.type.JsonArray in project ma-core-public by infiniteautomation.

the class StoreLatestProductionTest method testThreeTwoReleaseVersion.

// @Test
public void testThreeTwoReleaseVersion() throws JsonException, IOException, HttpException {
    // Setup json
    json.put("upgradeVersionState", UpgradeVersionState.PRODUCTION);
    json.put("currentVersionState", UpgradeVersionState.PRODUCTION);
    jsonModules.put("core", "3.2.0");
    jsonModules.put("mangoApi", "3.2.0");
    String url = baseUrl + "/servlet/versionCheck";
    HttpPost post = new HttpPost(url);
    StringWriter stringWriter = new StringWriter();
    new JsonWriter(JSON_CONTEXT, stringWriter).writeObject(json);
    String requestData = stringWriter.toString();
    post.setEntity(new StringEntity(requestData));
    String responseData = HttpUtils4.getTextContent(getHttpClient(30000), post, 1);
    JsonTypeReader jsonReader = new JsonTypeReader(responseData);
    JsonValue response = jsonReader.read();
    printResponse(response);
    Assert.assertNotNull(response.getJsonValue("versionState"));
    Assert.assertEquals("PRODUCTION", response.getJsonValue("versionState").toString());
    // Assert newInstalls-oldCore should be empty
    Assert.assertNotNull(response.getJsonValue("newInstalls-oldCore"));
    JsonArray newInstallsOldCore = response.getJsonValue("newInstalls-oldCore").toJsonArray();
    Assert.assertEquals(true, newInstallsOldCore.size() == 0);
    // Assert update-versionState
    Assert.assertNull(response.getJsonValue("update-versionState"));
    // Assert updates for this core iff major upgrade available
    Assert.assertNotNull(response.getJsonValue("updates"));
    JsonArray updates = response.getJsonValue("updates").toJsonArray();
    Assert.assertEquals(true, updates.size() == 0);
    // Assert upgrades
    Assert.assertNotNull(response.getJsonValue("upgrades"));
    JsonArray upgrades = response.getJsonValue("upgrades").toJsonArray();
    Assert.assertEquals(true, upgrades.size() == 2);
    for (JsonValue upgrade : upgrades) {
        Assert.assertEquals(true, upgrade.getJsonValue("fullVersion").toString().startsWith(latestProductionCorePrefix));
    }
    // Assert newInstalls should be for latest production core
    Assert.assertNotNull(response.getJsonValue("newInstalls"));
    JsonArray newInstalls = response.getJsonValue("newInstalls").toJsonArray();
    Assert.assertEquals(true, newInstalls.size() > 0);
    for (JsonValue install : newInstalls) {
        Assert.assertEquals(true, install.getJsonValue("fullVersion").toString().startsWith(latestProductionCorePrefix));
    }
}
Also used : JsonArray(com.serotonin.json.type.JsonArray) HttpPost(org.apache.http.client.methods.HttpPost) StringEntity(org.apache.http.entity.StringEntity) StringWriter(java.io.StringWriter) JsonValue(com.serotonin.json.type.JsonValue) JsonWriter(com.serotonin.json.JsonWriter) JsonTypeReader(com.serotonin.json.type.JsonTypeReader)

Example 23 with JsonArray

use of com.serotonin.json.type.JsonArray in project ma-core-public by infiniteautomation.

the class StoreLatestProductionTest method testThreeTwoPreviousDevelopmentVersion.

// @Test
public void testThreeTwoPreviousDevelopmentVersion() throws JsonException, IOException, HttpException {
    // Setup json
    json.put("upgradeVersionState", UpgradeVersionState.DEVELOPMENT);
    json.put("currentVersionState", UpgradeVersionState.DEVELOPMENT);
    jsonModules.put("core", "3.2.2-SNAPSHOT");
    jsonModules.put("mangoApi", "3.2.3-SNAPSHOT");
    String url = baseUrl + "/servlet/versionCheck";
    HttpPost post = new HttpPost(url);
    StringWriter stringWriter = new StringWriter();
    new JsonWriter(JSON_CONTEXT, stringWriter).writeObject(json);
    String requestData = stringWriter.toString();
    post.setEntity(new StringEntity(requestData));
    String responseData = HttpUtils4.getTextContent(getHttpClient(30000), post, 1);
    JsonTypeReader jsonReader = new JsonTypeReader(responseData);
    JsonValue response = jsonReader.read();
    printResponse(response);
    Assert.assertNotNull(response.getJsonValue("versionState"));
    Assert.assertEquals("PRODUCTION", response.getJsonValue("versionState").toString());
    // Assert newInstalls-oldCore should be empty
    Assert.assertNotNull(response.getJsonValue("newInstalls-oldCore"));
    JsonArray newInstallsOldCore = response.getJsonValue("newInstalls-oldCore").toJsonArray();
    Assert.assertEquals(true, newInstallsOldCore.size() == 0);
    // Assert update-versionState
    Assert.assertNull(response.getJsonValue("update-versionState"));
    // Assert updates for this core iff major upgrade available
    Assert.assertNotNull(response.getJsonValue("updates"));
    JsonArray updates = response.getJsonValue("updates").toJsonArray();
    Assert.assertEquals(true, updates.size() == 0);
    // Assert upgrades
    Assert.assertNotNull(response.getJsonValue("upgrades"));
    JsonArray upgrades = response.getJsonValue("upgrades").toJsonArray();
    Assert.assertEquals(true, upgrades.size() > 0);
    for (JsonValue upgrade : upgrades) {
        Assert.assertEquals(true, upgrade.getJsonValue("fullVersion").toString().startsWith(latestProductionCorePrefix));
    }
    // Assert newInstalls should be for latest production core
    Assert.assertNotNull(response.getJsonValue("newInstalls"));
    JsonArray newInstalls = response.getJsonValue("newInstalls").toJsonArray();
    Assert.assertEquals(true, newInstalls.size() > 0);
    for (JsonValue install : newInstalls) {
        Assert.assertEquals(true, install.getJsonValue("fullVersion").toString().startsWith(latestProductionCorePrefix));
    }
}
Also used : JsonArray(com.serotonin.json.type.JsonArray) HttpPost(org.apache.http.client.methods.HttpPost) StringEntity(org.apache.http.entity.StringEntity) StringWriter(java.io.StringWriter) JsonValue(com.serotonin.json.type.JsonValue) JsonWriter(com.serotonin.json.JsonWriter) JsonTypeReader(com.serotonin.json.type.JsonTypeReader)

Example 24 with JsonArray

use of com.serotonin.json.type.JsonArray in project ma-core-public by infiniteautomation.

the class StoreLatestProductionTest method testThreeThreeDevelopmentVersion.

// @Test
public void testThreeThreeDevelopmentVersion() throws JsonException, IOException, HttpException {
    // Setup json
    json.put("upgradeVersionState", UpgradeVersionState.DEVELOPMENT);
    json.put("currentVersionState", UpgradeVersionState.DEVELOPMENT);
    jsonModules.put("core", "3.3.0-SNAPSHOT");
    jsonModules.put("mangoApi", "3.3.0-SNAPSHOT");
    String url = baseUrl + "/servlet/versionCheck";
    HttpPost post = new HttpPost(url);
    StringWriter stringWriter = new StringWriter();
    new JsonWriter(JSON_CONTEXT, stringWriter).writeObject(json);
    String requestData = stringWriter.toString();
    post.setEntity(new StringEntity(requestData));
    String responseData = HttpUtils4.getTextContent(getHttpClient(30000), post, 1);
    JsonTypeReader jsonReader = new JsonTypeReader(responseData);
    JsonValue response = jsonReader.read();
    // printResponse(response);
    Assert.assertNotNull(response.getJsonValue("versionState"));
    Assert.assertEquals("PRODUCTION", response.getJsonValue("versionState").toString());
    // Assert newInstalls-oldCore should be empty
    Assert.assertNotNull(response.getJsonValue("newInstalls-oldCore"));
    JsonArray newInstallsOldCore = response.getJsonValue("newInstalls-oldCore").toJsonArray();
    Assert.assertEquals(true, newInstallsOldCore.size() == 0);
    // Assert update-versionState
    Assert.assertNull(response.getJsonValue("update-versionState"));
    // Assert updates for this core iff major upgrade available
    Assert.assertNotNull(response.getJsonValue("updates"));
    JsonArray updates = response.getJsonValue("updates").toJsonArray();
    Assert.assertEquals(true, updates.size() == 0);
    // Assert upgrades
    Assert.assertNotNull(response.getJsonValue("upgrades"));
    JsonArray upgrades = response.getJsonValue("upgrades").toJsonArray();
    Assert.assertEquals(true, upgrades.size() > 0);
    for (JsonValue upgrade : upgrades) {
        Assert.assertEquals(true, upgrade.getJsonValue("fullVersion").toString().startsWith(latestProductionCorePrefix));
    }
    // Assert newInstalls should be for latest production core
    Assert.assertNotNull(response.getJsonValue("newInstalls"));
    JsonArray newInstalls = response.getJsonValue("newInstalls").toJsonArray();
    Assert.assertEquals(true, newInstalls.size() > 0);
    for (JsonValue install : newInstalls) {
        Assert.assertEquals(true, install.getJsonValue("fullVersion").toString().startsWith(latestProductionCorePrefix));
    }
}
Also used : JsonArray(com.serotonin.json.type.JsonArray) HttpPost(org.apache.http.client.methods.HttpPost) StringEntity(org.apache.http.entity.StringEntity) StringWriter(java.io.StringWriter) JsonValue(com.serotonin.json.type.JsonValue) JsonWriter(com.serotonin.json.JsonWriter) JsonTypeReader(com.serotonin.json.type.JsonTypeReader)

Example 25 with JsonArray

use of com.serotonin.json.type.JsonArray in project ma-core-public by infiniteautomation.

the class StoreLatestProductionTest method testThreeTwoDevelopmentVersion.

// @Test
public void testThreeTwoDevelopmentVersion() throws JsonException, IOException, HttpException {
    // Setup json
    json.put("upgradeVersionState", UpgradeVersionState.DEVELOPMENT);
    json.put("currentVersionState", UpgradeVersionState.DEVELOPMENT);
    jsonModules.put("core", latestDevelopmentCore);
    jsonModules.put("mangoApi", "3.2.3-SNAPSHOT");
    String url = baseUrl + "/servlet/versionCheck";
    HttpPost post = new HttpPost(url);
    StringWriter stringWriter = new StringWriter();
    new JsonWriter(JSON_CONTEXT, stringWriter).writeObject(json);
    String requestData = stringWriter.toString();
    post.setEntity(new StringEntity(requestData));
    String responseData = HttpUtils4.getTextContent(getHttpClient(30000), post, 1);
    JsonTypeReader jsonReader = new JsonTypeReader(responseData);
    JsonValue response = jsonReader.read();
    printResponse(response);
    Assert.assertNotNull(response.getJsonValue("versionState"));
    Assert.assertEquals("PRODUCTION", response.getJsonValue("versionState").toString());
    // Assert newInstalls-oldCore should be empty
    Assert.assertNotNull(response.getJsonValue("newInstalls-oldCore"));
    JsonArray newInstallsOldCore = response.getJsonValue("newInstalls-oldCore").toJsonArray();
    Assert.assertEquals(true, newInstallsOldCore.size() == 0);
    // Assert update-versionState
    Assert.assertNull(response.getJsonValue("update-versionState"));
    // Assert updates for this core iff major upgrade available
    Assert.assertNotNull(response.getJsonValue("updates"));
    JsonArray updates = response.getJsonValue("updates").toJsonArray();
    Assert.assertEquals(true, updates.size() == 0);
    // Assert upgrades
    Assert.assertNotNull(response.getJsonValue("upgrades"));
    JsonArray upgrades = response.getJsonValue("upgrades").toJsonArray();
    Assert.assertEquals(true, upgrades.size() > 0);
    for (JsonValue upgrade : upgrades) {
        Assert.assertEquals(true, upgrade.getJsonValue("fullVersion").toString().startsWith(latestProductionCorePrefix));
    }
    // Assert newInstalls should be for latest production core
    Assert.assertNotNull(response.getJsonValue("newInstalls"));
    JsonArray newInstalls = response.getJsonValue("newInstalls").toJsonArray();
    Assert.assertEquals(true, newInstalls.size() > 0);
    for (JsonValue install : newInstalls) {
        Assert.assertEquals(true, install.getJsonValue("fullVersion").toString().startsWith(latestProductionCorePrefix));
    }
}
Also used : JsonArray(com.serotonin.json.type.JsonArray) HttpPost(org.apache.http.client.methods.HttpPost) StringEntity(org.apache.http.entity.StringEntity) StringWriter(java.io.StringWriter) JsonValue(com.serotonin.json.type.JsonValue) JsonWriter(com.serotonin.json.JsonWriter) JsonTypeReader(com.serotonin.json.type.JsonTypeReader)

Aggregations

JsonArray (com.serotonin.json.type.JsonArray)39 JsonValue (com.serotonin.json.type.JsonValue)26 JsonObject (com.serotonin.json.type.JsonObject)17 TranslatableJsonException (com.serotonin.m2m2.i18n.TranslatableJsonException)14 JsonWriter (com.serotonin.json.JsonWriter)10 JsonTypeReader (com.serotonin.json.type.JsonTypeReader)10 StringWriter (java.io.StringWriter)10 HttpPost (org.apache.http.client.methods.HttpPost)10 StringEntity (org.apache.http.entity.StringEntity)10 DataPointDao (com.serotonin.m2m2.db.dao.DataPointDao)8 IntStringPair (com.serotonin.db.pair.IntStringPair)6 JsonString (com.serotonin.json.type.JsonString)6 DataPointVO (com.serotonin.m2m2.vo.DataPointVO)6 ArrayList (java.util.ArrayList)5 JsonException (com.serotonin.json.JsonException)4 User (com.serotonin.m2m2.vo.User)4 JsonBoolean (com.serotonin.json.type.JsonBoolean)3 IOException (java.io.IOException)3 TypeDefinition (com.serotonin.json.util.TypeDefinition)2 ScriptPermissions (com.serotonin.m2m2.rt.script.ScriptPermissions)2