-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Linted and branching from linter_done
- Loading branch information
Showing
38 changed files
with
1,772 additions
and
220 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
...dk/dpppt-backend-sdk-model/src/main/java/org/dpppt/backend/sdk/semver/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# Semver | ||
|
||
## Introduction | ||
This implementation follows the official specification found for [Semver 2.0 ](https://semver.org/). | ||
The regular expression used for matching is taken from the official specification ans was slightly adjusted. | ||
The following changes were made, to allow using extended SemVer: | ||
|
||
- it is allowed to have a prefix specifying the OS used. The following regex is used | ||
> (?:(?<platform>ios|android)-)? | ||
- Only the major version is required. If minor or patch version are not given, a value of `0` i assumed. This was added as a `?` in the original regex for the minor and patch version. | ||
|
||
## IsAndroid/IsIos | ||
|
||
To allow for simple OS testing the following two implementations are added: | ||
|
||
```java | ||
public boolean isAndroid() { | ||
return platform.contains("android") || metaInfo.contains("android"); | ||
} | ||
public boolean isIOS() { | ||
return platform.contains("ios") || metaInfo.contains("ios"); | ||
} | ||
``` | ||
Whereas in SemVer it would be normal to specify further information in the `metaInfo` field, the dp3t clients use the prefix `ios` or `android`. This implementation though should be compatible with a more SemVer approach. |
249 changes: 249 additions & 0 deletions
249
...ckend-sdk/dpppt-backend-sdk-model/src/main/java/org/dpppt/backend/sdk/semver/Version.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,249 @@ | ||
package org.dpppt.backend.sdk.semver; | ||
|
||
import java.util.Objects; | ||
import java.util.regex.Pattern; | ||
|
||
public class Version implements Comparable<Version> { | ||
private Integer major; | ||
private Integer minor; | ||
private Integer patch; | ||
private String preReleaseString = ""; | ||
private String metaInfo = ""; | ||
private String platform = ""; | ||
|
||
private final Pattern semVerPattern = | ||
Pattern.compile( | ||
"^(?:(?<platform>ios|android)-)?(?<major>0|[1-9]\\d*)(\\.(?<minor>0|[1-9]\\d*))?(\\.(?<patch>0|[1-9]\\d*))?(?:-(?<prerelease>(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\\+(?<buildmetadata>[0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?$"); | ||
|
||
public Version() {} | ||
|
||
public Version(String versionString) { | ||
if (versionString == null) { | ||
this.setInvalidValue(); | ||
return; | ||
} | ||
this.major = -1; | ||
this.minor = 0; | ||
this.patch = 0; | ||
|
||
var matches = semVerPattern.matcher(versionString.trim()); | ||
if (matches.find()) { | ||
this.major = Integer.parseInt(matches.group("major")); | ||
if (matches.group("minor") != null) { | ||
this.minor = Integer.parseInt(matches.group("minor")); | ||
} | ||
if (matches.group("patch") != null) { | ||
this.patch = Integer.parseInt(matches.group("patch")); | ||
} | ||
if (matches.group("platform") != null) { | ||
this.platform = matches.group("platform"); | ||
} | ||
if (matches.group("prerelease") != null) { | ||
this.preReleaseString = matches.group("prerelease"); | ||
} | ||
if (matches.group("buildmetadata") != null) { | ||
this.metaInfo = matches.group("buildmetadata"); | ||
} | ||
} else { | ||
this.setInvalidValue(); | ||
} | ||
} | ||
|
||
public Version(Integer major, Integer minor, Integer patch) { | ||
this.major = major; | ||
this.minor = minor; | ||
this.patch = patch; | ||
this.preReleaseString = ""; | ||
this.metaInfo = ""; | ||
} | ||
|
||
public Version(Integer major, Integer minor) { | ||
this.major = major; | ||
this.minor = minor; | ||
this.patch = 0; | ||
this.preReleaseString = ""; | ||
this.metaInfo = ""; | ||
} | ||
|
||
public Version(Integer major) { | ||
this.major = major; | ||
this.minor = 0; | ||
this.patch = 0; | ||
this.preReleaseString = ""; | ||
this.metaInfo = ""; | ||
} | ||
|
||
public Version( | ||
Integer major, Integer minor, Integer patch, String preReleaseString, String metaInfo) { | ||
this.major = major; | ||
this.minor = minor; | ||
this.patch = patch; | ||
this.preReleaseString = preReleaseString; | ||
this.metaInfo = metaInfo; | ||
} | ||
|
||
private void setInvalidValue() { | ||
this.major = -1; | ||
this.minor = -1; | ||
this.patch = -1; | ||
this.preReleaseString = ""; | ||
this.metaInfo = ""; | ||
} | ||
|
||
public boolean isValid() { | ||
return major.compareTo(Integer.valueOf(0)) >= 0 | ||
&& minor.compareTo(Integer.valueOf(0)) >= 0 | ||
&& patch.compareTo(Integer.valueOf(0)) >= 0; | ||
} | ||
|
||
public Integer getMajor() { | ||
return this.major; | ||
} | ||
|
||
public void setMajor(Integer major) { | ||
this.major = major; | ||
} | ||
|
||
public Integer getMinor() { | ||
return this.minor; | ||
} | ||
|
||
public void setMinor(Integer minor) { | ||
this.minor = minor; | ||
} | ||
|
||
public Integer getPatch() { | ||
return this.patch; | ||
} | ||
|
||
public void setPatch(Integer patch) { | ||
this.patch = patch; | ||
} | ||
|
||
public String getPreReleaseString() { | ||
return this.preReleaseString; | ||
} | ||
|
||
public void setPreReleaseString(String preReleaseString) { | ||
this.preReleaseString = preReleaseString; | ||
} | ||
|
||
public String getMetaInfo() { | ||
return this.metaInfo; | ||
} | ||
|
||
public void setMetaInfo(String metaInfo) { | ||
this.metaInfo = metaInfo; | ||
} | ||
|
||
public String getPlatform() { | ||
return this.platform; | ||
} | ||
|
||
public void setPlatform(String platform) { | ||
this.platform = platform; | ||
} | ||
|
||
public Version major(Integer major) { | ||
this.major = major; | ||
return this; | ||
} | ||
|
||
public Version minor(Integer minor) { | ||
this.minor = minor; | ||
return this; | ||
} | ||
|
||
public Version patch(Integer patch) { | ||
this.patch = patch; | ||
return this; | ||
} | ||
|
||
public Version preReleaseString(String preReleaseString) { | ||
this.preReleaseString = preReleaseString; | ||
return this; | ||
} | ||
|
||
public Version metaInfo(String metaInfo) { | ||
this.metaInfo = metaInfo; | ||
return this; | ||
} | ||
|
||
public boolean isPrerelease() { | ||
return !preReleaseString.isEmpty(); | ||
} | ||
|
||
public boolean isAndroid() { | ||
return platform.contains("android") || metaInfo.contains("android"); | ||
} | ||
|
||
public boolean isIOS() { | ||
return platform.contains("ios") || metaInfo.contains("ios"); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (o == this) return true; | ||
if (!(o instanceof Version)) { | ||
return false; | ||
} | ||
Version version = (Version) o; | ||
return Objects.equals(major, version.major) | ||
&& Objects.equals(minor, version.minor) | ||
&& Objects.equals(patch, version.patch) | ||
&& Objects.equals(preReleaseString, version.preReleaseString) | ||
&& Objects.equals(metaInfo, version.metaInfo) | ||
&& Objects.equals(platform, version.platform); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(major, minor, patch, preReleaseString, metaInfo); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return getMajor() | ||
+ "." | ||
+ getMinor() | ||
+ "." | ||
+ getPatch() | ||
+ (getPreReleaseString().isEmpty() ? "" : "-" + getPreReleaseString()) | ||
+ (getMetaInfo().isEmpty() ? "" : "+" + getMetaInfo()); | ||
} | ||
|
||
@Override | ||
public int compareTo(Version o) { | ||
if (this.major.compareTo(o.major) != 0) { | ||
return this.major.compareTo(o.major); | ||
} | ||
if (this.minor.compareTo(o.minor) != 0) { | ||
return this.minor.compareTo(o.minor); | ||
} | ||
if (this.patch.compareTo(o.patch) != 0) { | ||
return this.patch.compareTo(o.patch); | ||
} | ||
if (this.isPrerelease() && o.isPrerelease()) { | ||
if (this.preReleaseString.compareTo(o.preReleaseString) != 0) { | ||
return this.preReleaseString.compareTo(o.preReleaseString); | ||
} | ||
} else if (this.isPrerelease() && !o.isPrerelease()) { | ||
return -1; | ||
} else if (!this.isPrerelease() && o.isPrerelease()) { | ||
return 1; | ||
} | ||
return 0; | ||
} | ||
|
||
public boolean isSmallerVersionThan(Version other) { | ||
return this.compareTo(other) < 0; | ||
} | ||
|
||
public boolean isLargerVersionThan(Version other) { | ||
return this.compareTo(other) > 0; | ||
} | ||
|
||
public boolean isSameVersionAs(Version other) { | ||
return this.compareTo(other) == 0; | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
...sdk/dpppt-backend-sdk-model/src/main/java/org/dpppt/backend/sdk/utils/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# UTC Instant | ||
|
||
## Why a new class? | ||
|
||
During the development of this project, various different time formats came into play. Mostly the 10 minute intervals used by GAEN and the default milliseconds used by the dp3t API. But time handling is hard. So `OffsetDateTimes` at UTC offsets were used, and sometimes `Dates` were needed, and some classes wanted different Objects and and and.... | ||
|
||
We ended up with a mess of 300 character lines, converting from one object into the other. For this reason we added this class, which gathers all usages and conversions we needed during development. It also should ensure that different people write the same code, by providing _one thing who times 'em all_. | ||
|
||
This also allowed us to the name the functions in a concise and natural way. The first example reads more natural than the second one. | ||
|
||
```java | ||
if(UTCInstant.of(keyDate, GaenUnit.TenMinutes).isBeforeDateOf(UTCInstant.now().atStartOfDay().plusDays(2)) { | ||
|
||
} | ||
``` | ||
|
||
```java | ||
if(Instant.ofEpochMilli(Duration.of(10, GaenUnit.TenMinutes).toMillis()).isBefore(LocalDate.now().atStartOfDay().plusDays(2).toInstant(ZoneOffset.UTC))) { | ||
|
||
} | ||
``` |
3 changes: 3 additions & 0 deletions
3
...dk/dpppt-backend-sdk-ws/src/main/java/org/dpppt/backend/sdk/ws/config/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Configurations | ||
|
||
This package holds all possible configurations. For the Swiss-Covid App the cloud-configurations, together with the `MultipleJWTConfig` and the `ActuatorSecurity` are used. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.