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);
}
}
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);
}
}
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);
}
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);
}
Aggregations