From 4b6bf3143485a3b07ac625f5895c41ac708f6195 Mon Sep 17 00:00:00 2001 From: claudemamo <823038+claudemamo@users.noreply.github.com> Date: Wed, 18 May 2022 15:27:56 +0200 Subject: [PATCH] build: add dhis2-json-schema-generator as a Git submodule in order to generate Java POJOs from different versions of the API without having to run dhis2-json-schema-generator for each version from Maven --- .github/workflows/ci.yml | 4 +- .github/workflows/codeql-analysis.yml | 8 +- .gitmodules | 4 + dhis2-json-schema-generator | 1 + pom.xml | 89 ++--- .../{integration/sdk => api/model}/Page.java | 4 +- .../java/org/hisp/dhis/api/model/Pager.java | 309 ++++++++++++++++++ .../internal/LazyIterableDhis2Response.java | 2 +- .../internal/operation/page/PageIterable.java | 2 +- .../dhis/integration/sdk/Environment.java | 13 +- .../DefaultPutOperationTestCase.java | 2 +- .../SimpleCollectOperationTestCase.java | 2 +- .../page/PagingCollectOperationTestCase.java | 2 +- 13 files changed, 360 insertions(+), 82 deletions(-) create mode 100644 .gitmodules create mode 160000 dhis2-json-schema-generator rename src/main/java/org/hisp/dhis/{integration/sdk => api/model}/Page.java (96%) create mode 100644 src/main/java/org/hisp/dhis/api/model/Pager.java diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 709f67c..89985bf 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -13,6 +13,8 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 + with: + submodules: 'true' - uses: actions/setup-java@v2 with: java-version: '11' @@ -30,4 +32,4 @@ jobs: run: | echo $GPG_SECRET_KEYS | base64 --decode | gpg --import --no-tty --batch --yes echo $GPG_OWNERTRUST | base64 --decode | gpg --import-ownertrust - mvn deploy --settings .mvn/settings.xml -Dgpg.skip=false -DskipTests=true -B \ No newline at end of file + mvn clean deploy --settings .mvn/settings.xml -Dgpg.skip=false -Dmaven.test.skip=true -B \ No newline at end of file diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index 182d7e2..0a8eeeb 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -25,10 +25,12 @@ jobs: steps: - name: Checkout repository uses: actions/checkout@v2 + with: + submodules: 'true' # Initializes the CodeQL tools for scanning. - name: Initialize CodeQL - uses: github/codeql-action/init@v1 + uses: github/codeql-action/init@v2 with: languages: ${{ matrix.language }} # If you wish to specify custom queries, you can do so here or in a config file. @@ -39,7 +41,7 @@ jobs: # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). # If this step fails, then you should remove it and run the build manually (see below) - name: Autobuild - uses: github/codeql-action/autobuild@v1 + uses: github/codeql-action/autobuild@v2 # ℹī¸ Command-line programs to run using the OS shell. # 📚 https://git.io/JvXDl @@ -53,4 +55,4 @@ jobs: # make release - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@v1 + uses: github/codeql-action/analyze@v2 diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..9248f44 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,4 @@ +[submodule "dhis2-json-schema-generator"] + path = dhis2-json-schema-generator + url = https://github.com/dhis2/dhis2-json-schema-generator.git + branch = json-schemas diff --git a/dhis2-json-schema-generator b/dhis2-json-schema-generator new file mode 160000 index 0000000..b070078 --- /dev/null +++ b/dhis2-json-schema-generator @@ -0,0 +1 @@ +Subproject commit b07007864dcd60bceef68e856413d99974b74067 diff --git a/pom.xml b/pom.xml index 2ae25f3..df2d547 100644 --- a/pom.xml +++ b/pom.xml @@ -19,58 +19,11 @@ - - org.codehaus.mojo - exec-maven-plugin - 3.0.0 - - - generate-sources - - java - - - - - true - org.hisp.dhis.integration.jsonschemagen.Dhis2JsonSchemaGenerator - target/generated-resources/schemas - - - - org.hisp.dhis.integration - dhis2-json-schema-generator - 1.0.0-SNAPSHOT - - - com.github.dhis2.dhis2-core - dhis-api - 2.37.4 - - - com.github.dhis2.dhis2-core - dhis-service-dxf2 - 2.37.4 - - - org.slf4j - slf4j-api - 1.7.36 - - - junit - junit - 4.13.2 - - - org.jsonschema2pojo jsonschema2pojo-maven-plugin 1.1.1 - ${project.build.directory}/generated-resources/schemas - org.hisp.dhis.api.v2_37_4.model true true true @@ -81,9 +34,34 @@ + v2.37.6 + + generate + + + dhis2-json-schema-generator/schemas/v2.37.6 + org.hisp.dhis.api.v2_37_6.model + + + + v2.36.10 generate + + dhis2-json-schema-generator/schemas/v2.36.10 + org.hisp.dhis.api.v2_36_10.model + + + + v2.35.13 + + generate + + + dhis2-json-schema-generator/schemas/v2.35.13 + org.hisp.dhis.api.v2_35_13.model + @@ -213,23 +191,6 @@ - - - jitpack.io - https://jitpack.io - - - oss.sonatype.org - https://oss.sonatype.org/content/repositories/snapshots - - false - - - true - - - - ossrh diff --git a/src/main/java/org/hisp/dhis/integration/sdk/Page.java b/src/main/java/org/hisp/dhis/api/model/Page.java similarity index 96% rename from src/main/java/org/hisp/dhis/integration/sdk/Page.java rename to src/main/java/org/hisp/dhis/api/model/Page.java index 432b60f..7b0a1a0 100644 --- a/src/main/java/org/hisp/dhis/integration/sdk/Page.java +++ b/src/main/java/org/hisp/dhis/api/model/Page.java @@ -25,13 +25,11 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -package org.hisp.dhis.integration.sdk; +package org.hisp.dhis.api.model; import java.util.HashMap; import java.util.Map; -import org.hisp.dhis.api.v2_37_4.model.Pager; - import com.fasterxml.jackson.annotation.JsonAnyGetter; import com.fasterxml.jackson.annotation.JsonAnySetter; import com.fasterxml.jackson.annotation.JsonIgnore; diff --git a/src/main/java/org/hisp/dhis/api/model/Pager.java b/src/main/java/org/hisp/dhis/api/model/Pager.java new file mode 100644 index 0000000..df5bf3b --- /dev/null +++ b/src/main/java/org/hisp/dhis/api/model/Pager.java @@ -0,0 +1,309 @@ +package org.hisp.dhis.api.model; + +import com.fasterxml.jackson.annotation.JsonAnyGetter; +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; + +import java.util.HashMap; +import java.util.Map; +import java.util.Optional; + +@JsonInclude( JsonInclude.Include.NON_NULL) +@JsonPropertyOrder({"nextPage", "page", "pageCount", "pageSize", "prevPage", "total"}) +public class Pager { + @JsonProperty("nextPage") + private String nextPage; + @JsonProperty("page") + private Integer page; + @JsonProperty("pageCount") + private Integer pageCount; + @JsonProperty("pageSize") + private Integer pageSize; + @JsonProperty("prevPage") + private String prevPage; + @JsonProperty("total") + private Integer total; + @JsonIgnore + private Map additionalProperties = new HashMap(); + protected static final Object NOT_FOUND_VALUE = new Object(); + + public Pager() { + } + + public Pager(Pager source) { + this.nextPage = source.nextPage; + this.page = source.page; + this.pageCount = source.pageCount; + this.pageSize = source.pageSize; + this.prevPage = source.prevPage; + this.total = source.total; + } + + public Pager(String nextPage, Integer page, Integer pageCount, Integer pageSize, String prevPage, Integer total) { + this.nextPage = nextPage; + this.page = page; + this.pageCount = pageCount; + this.pageSize = pageSize; + this.prevPage = prevPage; + this.total = total; + } + + @JsonProperty("nextPage") + public Optional getNextPage() { + return Optional.ofNullable(this.nextPage); + } + + @JsonProperty("nextPage") + public void setNextPage(String nextPage) { + this.nextPage = nextPage; + } + + public Pager withNextPage(String nextPage) { + this.nextPage = nextPage; + return this; + } + + @JsonProperty("page") + public Optional getPage() { + return Optional.ofNullable(this.page); + } + + @JsonProperty("page") + public void setPage(Integer page) { + this.page = page; + } + + public Pager withPage(Integer page) { + this.page = page; + return this; + } + + @JsonProperty("pageCount") + public Optional getPageCount() { + return Optional.ofNullable(this.pageCount); + } + + @JsonProperty("pageCount") + public void setPageCount(Integer pageCount) { + this.pageCount = pageCount; + } + + public Pager withPageCount(Integer pageCount) { + this.pageCount = pageCount; + return this; + } + + @JsonProperty("pageSize") + public Optional getPageSize() { + return Optional.ofNullable(this.pageSize); + } + + @JsonProperty("pageSize") + public void setPageSize(Integer pageSize) { + this.pageSize = pageSize; + } + + public Pager withPageSize(Integer pageSize) { + this.pageSize = pageSize; + return this; + } + + @JsonProperty("prevPage") + public Optional getPrevPage() { + return Optional.ofNullable(this.prevPage); + } + + @JsonProperty("prevPage") + public void setPrevPage(String prevPage) { + this.prevPage = prevPage; + } + + public Pager withPrevPage(String prevPage) { + this.prevPage = prevPage; + return this; + } + + @JsonProperty("total") + public Optional getTotal() { + return Optional.ofNullable(this.total); + } + + @JsonProperty("total") + public void setTotal(Integer total) { + this.total = total; + } + + public Pager withTotal(Integer total) { + this.total = total; + return this; + } + + @JsonAnyGetter + public Map getAdditionalProperties() { + return this.additionalProperties; + } + + @JsonAnySetter + public void setAdditionalProperty(String name, Object value) { + this.additionalProperties.put(name, value); + } + + public Pager withAdditionalProperty(String name, Object value) { + this.additionalProperties.put(name, value); + return this; + } + + protected boolean declaredProperty(String name, Object value) { + switch (name) { + case "nextPage": + if (value instanceof String) { + this.setNextPage((String)value); + return true; + } + + throw new IllegalArgumentException("property \"nextPage\" is of type \"java.lang.String\", but got " + value.getClass().toString()); + case "page": + if (value instanceof Integer) { + this.setPage((Integer)value); + return true; + } + + throw new IllegalArgumentException("property \"page\" is of type \"java.lang.Integer\", but got " + value.getClass().toString()); + case "pageCount": + if (value instanceof Integer) { + this.setPageCount((Integer)value); + return true; + } + + throw new IllegalArgumentException("property \"pageCount\" is of type \"java.lang.Integer\", but got " + value.getClass().toString()); + case "pageSize": + if (value instanceof Integer) { + this.setPageSize((Integer)value); + return true; + } + + throw new IllegalArgumentException("property \"pageSize\" is of type \"java.lang.Integer\", but got " + value.getClass().toString()); + case "prevPage": + if (value instanceof String) { + this.setPrevPage((String)value); + return true; + } + + throw new IllegalArgumentException("property \"prevPage\" is of type \"java.lang.String\", but got " + value.getClass().toString()); + case "total": + if (value instanceof Integer) { + this.setTotal((Integer)value); + return true; + } + + throw new IllegalArgumentException("property \"total\" is of type \"java.lang.Integer\", but got " + value.getClass().toString()); + default: + return false; + } + } + + protected Object declaredPropertyOrNotFound(String name, Object notFoundValue) { + switch (name) { + case "nextPage": + return this.getNextPage(); + case "page": + return this.getPage(); + case "pageCount": + return this.getPageCount(); + case "pageSize": + return this.getPageSize(); + case "prevPage": + return this.getPrevPage(); + case "total": + return this.getTotal(); + default: + return notFoundValue; + } + } + + public T get(String name) { + Object value = this.declaredPropertyOrNotFound(name, NOT_FOUND_VALUE); + return (T) (NOT_FOUND_VALUE != value ? value : this.getAdditionalProperties().get(name)); + } + + public void set(String name, Object value) { + if (!this.declaredProperty(name, value)) { + this.getAdditionalProperties().put(name, value); + } + + } + + public Pager with(String name, Object value) { + if (!this.declaredProperty(name, value)) { + this.getAdditionalProperties().put(name, value); + } + + return this; + } + + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append(Pager.class.getName()).append('@').append(Integer.toHexString(System.identityHashCode(this))).append('['); + sb.append("nextPage"); + sb.append('='); + sb.append(this.nextPage == null ? "" : this.nextPage); + sb.append(','); + sb.append("page"); + sb.append('='); + sb.append(this.page == null ? "" : this.page); + sb.append(','); + sb.append("pageCount"); + sb.append('='); + sb.append(this.pageCount == null ? "" : this.pageCount); + sb.append(','); + sb.append("pageSize"); + sb.append('='); + sb.append(this.pageSize == null ? "" : this.pageSize); + sb.append(','); + sb.append("prevPage"); + sb.append('='); + sb.append(this.prevPage == null ? "" : this.prevPage); + sb.append(','); + sb.append("total"); + sb.append('='); + sb.append(this.total == null ? "" : this.total); + sb.append(','); + sb.append("additionalProperties"); + sb.append('='); + sb.append(this.additionalProperties == null ? "" : this.additionalProperties); + sb.append(','); + if (sb.charAt(sb.length() - 1) == ',') { + sb.setCharAt(sb.length() - 1, ']'); + } else { + sb.append(']'); + } + + return sb.toString(); + } + + public int hashCode() { + int result = 1; + result = result * 31 + (this.pageCount == null ? 0 : this.pageCount.hashCode()); + result = result * 31 + (this.total == null ? 0 : this.total.hashCode()); + result = result * 31 + (this.nextPage == null ? 0 : this.nextPage.hashCode()); + result = result * 31 + (this.pageSize == null ? 0 : this.pageSize.hashCode()); + result = result * 31 + (this.prevPage == null ? 0 : this.prevPage.hashCode()); + result = result * 31 + (this.page == null ? 0 : this.page.hashCode()); + result = result * 31 + (this.additionalProperties == null ? 0 : this.additionalProperties.hashCode()); + return result; + } + + public boolean equals(Object other) { + if (other == this) { + return true; + } else if (!(other instanceof Pager)) { + return false; + } else { + Pager rhs = (Pager)other; + return (this.pageCount == rhs.pageCount || this.pageCount != null && this.pageCount.equals(rhs.pageCount)) && (this.total == rhs.total || this.total != null && this.total.equals(rhs.total)) && (this.nextPage == rhs.nextPage || this.nextPage != null && this.nextPage.equals(rhs.nextPage)) && (this.pageSize == rhs.pageSize || this.pageSize != null && this.pageSize.equals(rhs.pageSize)) && (this.prevPage == rhs.prevPage || this.prevPage != null && this.prevPage.equals(rhs.prevPage)) && (this.page == rhs.page || this.page != null && this.page.equals(rhs.page)) && (this.additionalProperties == rhs.additionalProperties || this.additionalProperties != null && this.additionalProperties.equals(rhs.additionalProperties)); + } + } +} \ No newline at end of file diff --git a/src/main/java/org/hisp/dhis/integration/sdk/internal/LazyIterableDhis2Response.java b/src/main/java/org/hisp/dhis/integration/sdk/internal/LazyIterableDhis2Response.java index 729a5bb..5ea962d 100644 --- a/src/main/java/org/hisp/dhis/integration/sdk/internal/LazyIterableDhis2Response.java +++ b/src/main/java/org/hisp/dhis/integration/sdk/internal/LazyIterableDhis2Response.java @@ -29,7 +29,7 @@ import okhttp3.OkHttpClient; -import org.hisp.dhis.integration.sdk.Page; +import org.hisp.dhis.api.model.Page; import org.hisp.dhis.integration.sdk.api.Dhis2Response; import org.hisp.dhis.integration.sdk.api.IterableDhis2Response; import org.hisp.dhis.integration.sdk.api.converter.ConverterFactory; diff --git a/src/main/java/org/hisp/dhis/integration/sdk/internal/operation/page/PageIterable.java b/src/main/java/org/hisp/dhis/integration/sdk/internal/operation/page/PageIterable.java index d73e7f9..c609b62 100644 --- a/src/main/java/org/hisp/dhis/integration/sdk/internal/operation/page/PageIterable.java +++ b/src/main/java/org/hisp/dhis/integration/sdk/internal/operation/page/PageIterable.java @@ -35,7 +35,7 @@ import okhttp3.OkHttpClient; import okhttp3.Request; -import org.hisp.dhis.integration.sdk.Page; +import org.hisp.dhis.api.model.Page; import org.hisp.dhis.integration.sdk.api.Dhis2Response; import org.hisp.dhis.integration.sdk.api.converter.ConverterFactory; import org.hisp.dhis.integration.sdk.internal.DefaultDhis2Response; diff --git a/src/test/java/org/hisp/dhis/integration/sdk/Environment.java b/src/test/java/org/hisp/dhis/integration/sdk/Environment.java index 2828ca0..874ce86 100644 --- a/src/test/java/org/hisp/dhis/integration/sdk/Environment.java +++ b/src/test/java/org/hisp/dhis/integration/sdk/Environment.java @@ -31,10 +31,11 @@ import java.nio.charset.Charset; import java.time.Duration; import java.util.Date; +import java.util.Map; -import org.hisp.dhis.api.v2_37_4.model.OrganisationUnit; -import org.hisp.dhis.api.v2_37_4.model.OrganisationUnitLevel; -import org.hisp.dhis.api.v2_37_4.model.WebMessage; +import org.hisp.dhis.api.v2_37_6.model.OrganisationUnit; +import org.hisp.dhis.api.v2_37_6.model.OrganisationUnitLevel; +import org.hisp.dhis.api.v2_37_6.model.WebMessage; import org.testcontainers.containers.BindMode; import org.testcontainers.containers.GenericContainer; import org.testcontainers.containers.Network; @@ -71,7 +72,7 @@ private Environment() POSTGRESQL_CONTAINER.start(); DHIS2_CONTAINER = new GenericContainer<>( - "dhis2/core:2.37.4-tomcat-8.5.34-jre8-alpine" ) + "dhis2/core:2.37.6-tomcat-8.5.34-jre8-alpine" ) .dependsOn( POSTGRESQL_CONTAINER ) .withClasspathResourceMapping( "dhis.conf", "/DHIS2_home/dhis.conf", BindMode.READ_WRITE ) .withNetwork( NETWORK ).withExposedPorts( 8080 ) @@ -115,8 +116,8 @@ private static String createOrgUnit() OrganisationUnit organisationUnit = new OrganisationUnit().withName( "Acme" ).withShortName( "Acme" ) .withOpeningDate( new Date() ); - return DHIS2_CLIENT.post( "organisationUnits" ).withResource( organisationUnit ).transfer() - .returnAs( WebMessage.class ).getResponse().get().get( "uid" ); + return (String) ((Map) DHIS2_CLIENT.post( "organisationUnits" ).withResource( organisationUnit ).transfer() + .returnAs( WebMessage.class ).getResponse().get()).get( "uid" ); } private static void createOrgUnitLevel() diff --git a/src/test/java/org/hisp/dhis/integration/sdk/internal/operation/DefaultPutOperationTestCase.java b/src/test/java/org/hisp/dhis/integration/sdk/internal/operation/DefaultPutOperationTestCase.java index 2695c15..abc64f8 100644 --- a/src/test/java/org/hisp/dhis/integration/sdk/internal/operation/DefaultPutOperationTestCase.java +++ b/src/test/java/org/hisp/dhis/integration/sdk/internal/operation/DefaultPutOperationTestCase.java @@ -29,7 +29,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue; -import org.hisp.dhis.api.v2_37_4.model.OrganisationUnit; +import org.hisp.dhis.api.v2_37_6.model.OrganisationUnit; import org.hisp.dhis.integration.sdk.AbstractTestCase; import org.hisp.dhis.integration.sdk.Environment; import org.hisp.dhis.integration.sdk.api.Dhis2Response; diff --git a/src/test/java/org/hisp/dhis/integration/sdk/internal/operation/SimpleCollectOperationTestCase.java b/src/test/java/org/hisp/dhis/integration/sdk/internal/operation/SimpleCollectOperationTestCase.java index a250217..0b66336 100644 --- a/src/test/java/org/hisp/dhis/integration/sdk/internal/operation/SimpleCollectOperationTestCase.java +++ b/src/test/java/org/hisp/dhis/integration/sdk/internal/operation/SimpleCollectOperationTestCase.java @@ -33,7 +33,7 @@ import java.util.stream.Collectors; import java.util.stream.StreamSupport; -import org.hisp.dhis.api.v2_37_4.model.OrganisationUnit; +import org.hisp.dhis.api.v2_37_6.model.OrganisationUnit; import org.hisp.dhis.integration.sdk.AbstractTestCase; import org.junit.jupiter.api.Test; diff --git a/src/test/java/org/hisp/dhis/integration/sdk/internal/operation/page/PagingCollectOperationTestCase.java b/src/test/java/org/hisp/dhis/integration/sdk/internal/operation/page/PagingCollectOperationTestCase.java index 86d7673..8e381ab 100644 --- a/src/test/java/org/hisp/dhis/integration/sdk/internal/operation/page/PagingCollectOperationTestCase.java +++ b/src/test/java/org/hisp/dhis/integration/sdk/internal/operation/page/PagingCollectOperationTestCase.java @@ -33,7 +33,7 @@ import java.util.stream.Collectors; import java.util.stream.StreamSupport; -import org.hisp.dhis.api.v2_37_4.model.OrganisationUnit; +import org.hisp.dhis.api.v2_37_6.model.OrganisationUnit; import org.hisp.dhis.integration.sdk.AbstractTestCase; import org.hisp.dhis.integration.sdk.internal.operation.DefaultGetOperation; import org.junit.jupiter.api.Test;