Search in sources :

Example 1 with SemanticVersion

use of org.openecard.common.SemanticVersion in project open-ecard by ecsec.

the class VersionUpdate method fromJson.

public static VersionUpdate fromJson(JSONObject jsonObject) throws InvalidUpdateDefinition {
    try {
        SemanticVersion version = new SemanticVersion(jsonObject.getString("version"));
        URL dlPage = new URL(jsonObject.getString("download_page"));
        URL dlUrl = new URL(jsonObject.getString("download_url"));
        Status status;
        try {
            status = Status.valueOf(jsonObject.getString("status"));
        } catch (IllegalArgumentException ex) {
            status = Status.UNKNOWN;
        }
        if (version.getMajor() == 0 && version.getMinor() == 0 && version.getPatch() == 0) {
            throw new InvalidUpdateDefinition("Invalid version specified.");
        }
        if (!"http".equalsIgnoreCase(dlPage.getProtocol()) && !"https".equalsIgnoreCase(dlPage.getProtocol())) {
            throw new InvalidUpdateDefinition("Download Page URL is not an http URL.");
        }
        if (!"http".equalsIgnoreCase(dlUrl.getProtocol()) && !"https".equalsIgnoreCase(dlUrl.getProtocol())) {
            throw new InvalidUpdateDefinition("Download URL is not an http URL.");
        }
        return new VersionUpdate(version, dlPage, dlUrl, status);
    } catch (MalformedURLException ex) {
        throw new InvalidUpdateDefinition("At least one of the download URLs is not a valid URL.", ex);
    } catch (JSONException ex) {
        throw new InvalidUpdateDefinition("Incomplete JSON data received.", ex);
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) JSONException(org.json.JSONException) URL(java.net.URL) SemanticVersion(org.openecard.common.SemanticVersion)

Example 2 with SemanticVersion

use of org.openecard.common.SemanticVersion in project open-ecard by ecsec.

the class VersionUpdate method fromJson.

public static VersionUpdate fromJson(JSONObject jsonObject) throws InvalidUpdateDefinition {
    try {
        SemanticVersion version = new SemanticVersion((String) jsonObject.get("version"));
        URL dlPage = new URL((String) jsonObject.get("download_page"));
        URL dlUrl = new URL((String) jsonObject.get("download_url"));
        Status status;
        try {
            status = Status.valueOf((String) jsonObject.get("status"));
        } catch (IllegalArgumentException ex) {
            status = Status.UNKNOWN;
        }
        if (version.getMajor() == 0 && version.getMinor() == 0 && version.getPatch() == 0) {
            throw new InvalidUpdateDefinition("Invalid version specified.");
        }
        if (!"http".equalsIgnoreCase(dlPage.getProtocol()) && !"https".equalsIgnoreCase(dlPage.getProtocol())) {
            throw new InvalidUpdateDefinition("Download Page URL is not an http URL.");
        }
        if (!"http".equalsIgnoreCase(dlUrl.getProtocol()) && !"https".equalsIgnoreCase(dlUrl.getProtocol())) {
            throw new InvalidUpdateDefinition("Download URL is not an http URL.");
        }
        return new VersionUpdate(version, dlPage, dlUrl, status);
    } catch (MalformedURLException | NullPointerException ex) {
        throw new InvalidUpdateDefinition("Incomplete JSON data received.", ex);
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) InvalidUpdateDefinition(org.openecard.common.util.InvalidUpdateDefinition) URL(java.net.URL) SemanticVersion(org.openecard.common.SemanticVersion)

Example 3 with SemanticVersion

use of org.openecard.common.SemanticVersion in project open-ecard by ecsec.

the class TestRealVersionUpdate method validVersionUpdate.

@Test(enabled = true)
public void validVersionUpdate() throws InvalidUpdateDefinition, MalformedURLException {
    // Same values as the default values of the JSONObjectBuilder
    String downloadPage = "http://www.google.de/downloadpage";
    String downloadUrl = "http://www.google.de/downloadurl";
    String version = "1.3.0";
    String status = Status.MAINTAINED.name();
    JSONObject obj = new JSONObjectBuilder().build();
    VersionUpdate update = VersionUpdate.fromJson(obj);
    Assert.assertEquals(update.getDownloadPage(), new URL(downloadPage));
    Assert.assertEquals(update.getDownloadLink(), new URL(downloadUrl));
    Assert.assertEquals(update.getVersion().compareTo(new SemanticVersion(version)), 0);
    Assert.assertEquals(update.getStatus(), Status.valueOf(status));
    VersionUpdate newerVersion = new VersionUpdate(new SemanticVersion("1.3.1"), new URL(downloadPage), new URL(downloadUrl), Status.MAINTAINED);
    Assert.assertEquals(update.compareTo(newerVersion), -1);
    Assert.assertEquals(newerVersion.compareTo(update), 1);
}
Also used : JSONObject(org.jose4j.json.internal.json_simple.JSONObject) URL(java.net.URL) SemanticVersion(org.openecard.common.SemanticVersion) Test(org.testng.annotations.Test)

Example 4 with SemanticVersion

use of org.openecard.common.SemanticVersion in project open-ecard by ecsec.

the class ChipGateway method isUpdateNecessary.

private boolean isUpdateNecessary(String minimumVersion) {
    SemanticVersion requiredVersion = new SemanticVersion(minimumVersion);
    SemanticVersion appVersion = AppVersion.getVersion();
    return appVersion.isOlder(requiredVersion);
}
Also used : SemanticVersion(org.openecard.common.SemanticVersion)

Aggregations

SemanticVersion (org.openecard.common.SemanticVersion)4 URL (java.net.URL)3 MalformedURLException (java.net.MalformedURLException)2 JSONObject (org.jose4j.json.internal.json_simple.JSONObject)1 JSONException (org.json.JSONException)1 InvalidUpdateDefinition (org.openecard.common.util.InvalidUpdateDefinition)1 Test (org.testng.annotations.Test)1