diff --git a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/OpenApi.java b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/OpenApi.java index 57d68f8ab746..0829c2d447b4 100644 --- a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/OpenApi.java +++ b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/OpenApi.java @@ -345,9 +345,6 @@ @Repeatable(ParamsRepeat.class) @interface Params { /** - * As web classes cannot be used outside the web API module a {@code WebMessage} response value - * can also be indicated by {@link org.hisp.dhis.webmessage.WebMessageResponse}. - * * @return a complex parameter object type. All properties of that type become individual * parameters. */ diff --git a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataintegrity/FlattenedDataIntegrityReport.java b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataintegrity/FlattenedDataIntegrityReport.java index 23dcd6c623ca..2ffe5f10e8ea 100644 --- a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataintegrity/FlattenedDataIntegrityReport.java +++ b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataintegrity/FlattenedDataIntegrityReport.java @@ -38,6 +38,7 @@ import java.util.Map; import java.util.SortedMap; import java.util.TreeMap; +import javax.annotation.Nonnull; import org.hisp.dhis.dataintegrity.DataIntegrityDetails.DataIntegrityIssue; import org.hisp.dhis.webmessage.WebMessageResponse; @@ -223,6 +224,12 @@ public FlattenedDataIntegrityReport(Map detailsByN DataIntegrityCheckType.PROGRAM_RULE_ACTIONS_WITHOUT_STAGE_ID.getName())); } + @Nonnull + @Override + public Class getResponseClassType() { + return FlattenedDataIntegrityReport.class; + } + private List listOfDisplayNameOrUid(DataIntegrityDetails details) { return details == null ? null diff --git a/dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/common/ImportSummary.java b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dxf2/common/ImportSummary.java similarity index 97% rename from dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/common/ImportSummary.java rename to dhis-2/dhis-api/src/main/java/org/hisp/dhis/dxf2/common/ImportSummary.java index 08756e7e1055..962c8117f8ef 100644 --- a/dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/common/ImportSummary.java +++ b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dxf2/common/ImportSummary.java @@ -34,12 +34,14 @@ import java.util.ArrayList; import java.util.List; import org.hisp.dhis.common.DxfNamespaces; +import org.hisp.dhis.common.OpenApi; import org.hisp.dhis.dxf2.importsummary.ImportCount; /** * @author Morten Olav Hansen */ @JacksonXmlRootElement(localName = "importSummary", namespace = DxfNamespaces.DXF_2_0) +@OpenApi.Shared(name = "ImportTypesSummary") public class ImportSummary { private ImportCount importCount = new ImportCount(); diff --git a/dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/common/ImportTypeSummary.java b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dxf2/common/ImportTypeSummary.java similarity index 100% rename from dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/common/ImportTypeSummary.java rename to dhis-2/dhis-api/src/main/java/org/hisp/dhis/dxf2/common/ImportTypeSummary.java diff --git a/dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/geojson/GeoJsonImportConflict.java b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dxf2/geojson/GeoJsonImportConflict.java similarity index 100% rename from dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/geojson/GeoJsonImportConflict.java rename to dhis-2/dhis-api/src/main/java/org/hisp/dhis/dxf2/geojson/GeoJsonImportConflict.java diff --git a/dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/geojson/GeoJsonImportReport.java b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dxf2/geojson/GeoJsonImportReport.java similarity index 96% rename from dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/geojson/GeoJsonImportReport.java rename to dhis-2/dhis-api/src/main/java/org/hisp/dhis/dxf2/geojson/GeoJsonImportReport.java index 3c0cff17d864..e72c4792a875 100644 --- a/dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/geojson/GeoJsonImportReport.java +++ b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dxf2/geojson/GeoJsonImportReport.java @@ -32,6 +32,7 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import javax.annotation.Nonnull; import lombok.Getter; import org.hisp.dhis.dxf2.importsummary.ImportConflict; import org.hisp.dhis.dxf2.importsummary.ImportConflicts; @@ -72,6 +73,12 @@ public GeoJsonImportReport( this.totalConflictOccurrenceCount = totalConflictOccurrenceCount; } + @Nonnull + @Override + public Class getResponseClassType() { + return GeoJsonImportReport.class; + } + @JsonProperty public ImportStatus getStatus() { int ignored = importCount.getIgnored(); diff --git a/dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/importsummary/ImportConflict.java b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dxf2/importsummary/ImportConflict.java similarity index 100% rename from dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/importsummary/ImportConflict.java rename to dhis-2/dhis-api/src/main/java/org/hisp/dhis/dxf2/importsummary/ImportConflict.java diff --git a/dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/importsummary/ImportConflictDescriptor.java b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dxf2/importsummary/ImportConflictDescriptor.java similarity index 100% rename from dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/importsummary/ImportConflictDescriptor.java rename to dhis-2/dhis-api/src/main/java/org/hisp/dhis/dxf2/importsummary/ImportConflictDescriptor.java diff --git a/dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/importsummary/ImportConflicts.java b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dxf2/importsummary/ImportConflicts.java similarity index 100% rename from dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/importsummary/ImportConflicts.java rename to dhis-2/dhis-api/src/main/java/org/hisp/dhis/dxf2/importsummary/ImportConflicts.java diff --git a/dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/importsummary/ImportCount.java b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dxf2/importsummary/ImportCount.java similarity index 100% rename from dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/importsummary/ImportCount.java rename to dhis-2/dhis-api/src/main/java/org/hisp/dhis/dxf2/importsummary/ImportCount.java diff --git a/dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/importsummary/ImportStatus.java b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dxf2/importsummary/ImportStatus.java similarity index 98% rename from dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/importsummary/ImportStatus.java rename to dhis-2/dhis-api/src/main/java/org/hisp/dhis/dxf2/importsummary/ImportStatus.java index e537e4a76cc5..24b9c76486b4 100644 --- a/dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/importsummary/ImportStatus.java +++ b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dxf2/importsummary/ImportStatus.java @@ -32,7 +32,7 @@ public enum ImportStatus { WARNING(2), ERROR(3); - private int order; + private final int order; ImportStatus(int order) { this.order = order; diff --git a/dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/importsummary/ImportSummaries.java b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dxf2/importsummary/ImportSummaries.java similarity index 95% rename from dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/importsummary/ImportSummaries.java rename to dhis-2/dhis-api/src/main/java/org/hisp/dhis/dxf2/importsummary/ImportSummaries.java index e17b8266af6e..f0ea40726cff 100644 --- a/dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/importsummary/ImportSummaries.java +++ b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dxf2/importsummary/ImportSummaries.java @@ -36,31 +36,33 @@ import java.util.Comparator; import java.util.List; import java.util.Optional; +import javax.annotation.Nonnull; import org.hisp.dhis.common.DxfNamespaces; import org.hisp.dhis.dxf2.common.ImportOptions; -import org.hisp.dhis.dxf2.webmessage.AbstractWebMessageResponse; +import org.hisp.dhis.webmessage.WebMessageResponse; /** * @author Morten Olav Hansen */ @JacksonXmlRootElement(localName = "importSummaries", namespace = DxfNamespaces.DXF_2_0) -public class ImportSummaries extends AbstractWebMessageResponse { - private ImportStatus status = ImportStatus.SUCCESS; +public class ImportSummaries implements WebMessageResponse { + private ImportStatus status = ImportStatus.SUCCESS; private int imported; - private int updated; - private int deleted; - private int ignored; - private ImportOptions importOptions; - private List importSummaries = new ArrayList<>(); public ImportSummaries() {} + @Nonnull + @Override + public Class getResponseClassType() { + return ImportSummaries.class; + } + public void addImportSummaries(ImportSummaries importSummaries) { importSummaries.getImportSummaries().forEach(this::addImportSummary); } @@ -167,14 +169,12 @@ public int getIgnored() { return ignored; } - @JsonProperty + @JsonProperty(access = JsonProperty.Access.READ_ONLY) @JacksonXmlProperty(namespace = DxfNamespaces.DXF_2_0) public int getTotal() { return imported + updated + deleted + ignored; } - public void setTotal(int total) {} - @JsonProperty @JacksonXmlProperty(namespace = DxfNamespaces.DXF_2_0) public ImportOptions getImportOptions() { diff --git a/dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/importsummary/ImportSummary.java b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dxf2/importsummary/ImportSummary.java similarity index 96% rename from dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/importsummary/ImportSummary.java rename to dhis-2/dhis-api/src/main/java/org/hisp/dhis/dxf2/importsummary/ImportSummary.java index cc7091e42159..107f1a0145b7 100644 --- a/dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/importsummary/ImportSummary.java +++ b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dxf2/importsummary/ImportSummary.java @@ -37,12 +37,14 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import javax.annotation.Nonnull; import org.hisp.dhis.common.DxfNamespaces; import org.hisp.dhis.dxf2.common.ImportOptions; -import org.hisp.dhis.dxf2.webmessage.AbstractWebMessageResponse; +import org.hisp.dhis.webmessage.WebMessageResponse; @JacksonXmlRootElement(localName = "importSummary", namespace = DxfNamespaces.DXF_2_0) -public class ImportSummary extends AbstractWebMessageResponse implements ImportConflicts { +public class ImportSummary implements WebMessageResponse, ImportConflicts { + private ImportStatus status = ImportStatus.SUCCESS; private ImportOptions importOptions; @@ -91,6 +93,12 @@ public ImportSummary(ImportStatus status, String description, ImportCount import this.importCount = importCount; } + @Nonnull + @Override + public Class getResponseClassType() { + return ImportSummary.class; + } + // ------------------------------------------------------------------------- // Logic // ------------------------------------------------------------------------- diff --git a/dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/feedback/ImportReport.java b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dxf2/metadata/feedback/ImportReport.java similarity index 100% rename from dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/feedback/ImportReport.java rename to dhis-2/dhis-api/src/main/java/org/hisp/dhis/dxf2/metadata/feedback/ImportReport.java diff --git a/dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/sync/MetadataSyncSummary.java b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dxf2/metadata/sync/MetadataSyncSummary.java similarity index 58% rename from dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/sync/MetadataSyncSummary.java rename to dhis-2/dhis-api/src/main/java/org/hisp/dhis/dxf2/metadata/sync/MetadataSyncSummary.java index f297edf9f14d..d2884c9d4264 100644 --- a/dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/sync/MetadataSyncSummary.java +++ b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dxf2/metadata/sync/MetadataSyncSummary.java @@ -28,9 +28,10 @@ package org.hisp.dhis.dxf2.metadata.sync; import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; -import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement; -import org.hisp.dhis.common.DxfNamespaces; +import javax.annotation.Nonnull; +import lombok.Getter; +import lombok.Setter; +import lombok.ToString; import org.hisp.dhis.dxf2.common.ImportSummary; import org.hisp.dhis.dxf2.metadata.feedback.ImportReport; import org.hisp.dhis.metadata.version.MetadataVersion; @@ -41,53 +42,18 @@ * * @author vanyas */ -@JacksonXmlRootElement(localName = "metadataSyncSummary", namespace = DxfNamespaces.DXF_2_0) +@Getter +@Setter +@ToString public class MetadataSyncSummary implements WebMessageResponse { - private ImportReport importReport; - private ImportSummary importSummary; - - private MetadataVersion metadataVersion; - - @JsonProperty - @JacksonXmlProperty(namespace = DxfNamespaces.DXF_2_0) - public MetadataVersion getMetadataVersion() { - return metadataVersion; - } - - public void setMetadataVersion(MetadataVersion metadataVersion) { - this.metadataVersion = metadataVersion; - } - - @JsonProperty - @JacksonXmlProperty(namespace = DxfNamespaces.DXF_2_0) - public ImportSummary getImportSummary() { - return importSummary; - } - - public void setImportSummary(ImportSummary importSummary) { - this.importSummary = importSummary; - } - - @JsonProperty - @JacksonXmlProperty(namespace = DxfNamespaces.DXF_2_0) - public ImportReport getImportReport() { - return importReport; - } - - public void setImportReport(ImportReport importReport) { - this.importReport = importReport; - } + @JsonProperty private ImportReport importReport; + @JsonProperty private ImportSummary importSummary; + @JsonProperty private MetadataVersion metadataVersion; + @Nonnull @Override - public String toString() { - return "MetadataSyncSummary{" - + "importReport=" - + importReport - + ", importSummary=" - + importSummary - + ", metadataVersion=" - + metadataVersion - + '}'; + public Class getResponseClassType() { + return MetadataSyncSummary.class; } } diff --git a/dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/scheduling/JobConfigurationWebMessageResponse.java b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dxf2/scheduling/JobConfigurationWebMessageResponse.java similarity index 88% rename from dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/scheduling/JobConfigurationWebMessageResponse.java rename to dhis-2/dhis-api/src/main/java/org/hisp/dhis/dxf2/scheduling/JobConfigurationWebMessageResponse.java index 42d7cd952b64..5ebc7937a28e 100644 --- a/dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/scheduling/JobConfigurationWebMessageResponse.java +++ b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dxf2/scheduling/JobConfigurationWebMessageResponse.java @@ -30,6 +30,7 @@ import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; import java.util.Date; +import javax.annotation.Nonnull; import org.hisp.dhis.scheduling.JobConfiguration; import org.hisp.dhis.scheduling.JobParameters; import org.hisp.dhis.scheduling.JobStatus; @@ -40,19 +41,14 @@ * @author Henning HÃ¥konsen */ public class JobConfigurationWebMessageResponse implements WebMessageResponse { - private String name; - private String id; - - private Date created; - - private JobType jobType; - - private JobStatus jobStatus; - - private JobParameters jobParameters; - - private String relativeNotifierEndpoint; + private final String name; + private final String id; + private final Date created; + private final JobType jobType; + private final JobStatus jobStatus; + private final JobParameters jobParameters; + private final String relativeNotifierEndpoint; public JobConfigurationWebMessageResponse(JobConfiguration jobConfiguration) { this.name = jobConfiguration.getDisplayName(); @@ -64,6 +60,12 @@ public JobConfigurationWebMessageResponse(JobConfiguration jobConfiguration) { this.relativeNotifierEndpoint = "/api/system/tasks/" + this.jobType + "/" + this.id; } + @Nonnull + @Override + public Class getResponseClassType() { + return JobConfigurationWebMessageResponse.class; + } + @JacksonXmlProperty @JsonProperty public String getName() { diff --git a/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/security/ApiTokenCreationResponse.java b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dxf2/webmessage/responses/ApiTokenCreationResponse.java similarity index 94% rename from dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/security/ApiTokenCreationResponse.java rename to dhis-2/dhis-api/src/main/java/org/hisp/dhis/dxf2/webmessage/responses/ApiTokenCreationResponse.java index 907d86cfa15c..9eb42165a399 100644 --- a/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/security/ApiTokenCreationResponse.java +++ b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dxf2/webmessage/responses/ApiTokenCreationResponse.java @@ -25,11 +25,10 @@ * (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.webapi.controller.security; +package org.hisp.dhis.dxf2.webmessage.responses; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; -import org.hisp.dhis.dxf2.webmessage.responses.ObjectReportWebMessageResponse; import org.hisp.dhis.feedback.ObjectReport; /** diff --git a/dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/webmessage/responses/ErrorReportsWebMessageResponse.java b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dxf2/webmessage/responses/ErrorReportsWebMessageResponse.java similarity index 82% rename from dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/webmessage/responses/ErrorReportsWebMessageResponse.java rename to dhis-2/dhis-api/src/main/java/org/hisp/dhis/dxf2/webmessage/responses/ErrorReportsWebMessageResponse.java index d9c128c69a4a..6e15d855d2ce 100644 --- a/dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/webmessage/responses/ErrorReportsWebMessageResponse.java +++ b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dxf2/webmessage/responses/ErrorReportsWebMessageResponse.java @@ -30,20 +30,29 @@ import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper; import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; -import java.util.ArrayList; import java.util.List; +import javax.annotation.Nonnull; +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import lombok.Setter; import org.hisp.dhis.common.DxfNamespaces; -import org.hisp.dhis.dxf2.webmessage.AbstractWebMessageResponse; import org.hisp.dhis.feedback.ErrorReport; +import org.hisp.dhis.webmessage.WebMessageResponse; /** * @author Morten Olav Hansen */ -public class ErrorReportsWebMessageResponse extends AbstractWebMessageResponse { - private List errorReports = new ArrayList<>(); +@Setter +@Getter +@RequiredArgsConstructor +public class ErrorReportsWebMessageResponse implements WebMessageResponse { - public ErrorReportsWebMessageResponse(List errorReports) { - this.errorReports = errorReports; + private final List errorReports; + + @Nonnull + @Override + public Class getResponseClassType() { + return ErrorReportsWebMessageResponse.class; } @JsonProperty @@ -55,8 +64,4 @@ public ErrorReportsWebMessageResponse(List errorReports) { public List getErrorReports() { return errorReports; } - - public void setErrorReports(List errorReports) { - this.errorReports = errorReports; - } } diff --git a/dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/webmessage/responses/FileResourceWebMessageResponse.java b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dxf2/webmessage/responses/FileResourceWebMessageResponse.java similarity index 74% rename from dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/webmessage/responses/FileResourceWebMessageResponse.java rename to dhis-2/dhis-api/src/main/java/org/hisp/dhis/dxf2/webmessage/responses/FileResourceWebMessageResponse.java index 29611eda7276..d68d201db741 100644 --- a/dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/webmessage/responses/FileResourceWebMessageResponse.java +++ b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dxf2/webmessage/responses/FileResourceWebMessageResponse.java @@ -28,25 +28,24 @@ package org.hisp.dhis.dxf2.webmessage.responses; import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; -import org.hisp.dhis.common.DxfNamespaces; -import org.hisp.dhis.dxf2.webmessage.AbstractWebMessageResponse; +import javax.annotation.Nonnull; +import lombok.Getter; +import lombok.RequiredArgsConstructor; import org.hisp.dhis.fileresource.FileResource; +import org.hisp.dhis.webmessage.WebMessageResponse; /** * @author Halvdan Hoem Grelland */ -public class FileResourceWebMessageResponse extends AbstractWebMessageResponse { - private FileResource fileResource; +@Getter +@RequiredArgsConstructor +public class FileResourceWebMessageResponse implements WebMessageResponse { - public FileResourceWebMessageResponse(FileResource fileResource) { - this.setResponseType(FileResource.class.getSimpleName()); - this.fileResource = fileResource; - } + @JsonProperty private final FileResource fileResource; - @JsonProperty - @JacksonXmlProperty(namespace = DxfNamespaces.DXF_2_0) - public FileResource getFileResource() { - return fileResource; + @Nonnull + @Override + public Class getResponseClassType() { + return FileResourceWebMessageResponse.class; } } diff --git a/dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/webmessage/AbstractWebMessageResponse.java b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dxf2/webmessage/responses/ImportCountWebMessageResponse.java similarity index 64% rename from dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/webmessage/AbstractWebMessageResponse.java rename to dhis-2/dhis-api/src/main/java/org/hisp/dhis/dxf2/webmessage/responses/ImportCountWebMessageResponse.java index 57ebc4bbfce5..c5a05d611917 100644 --- a/dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/webmessage/AbstractWebMessageResponse.java +++ b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dxf2/webmessage/responses/ImportCountWebMessageResponse.java @@ -25,39 +25,30 @@ * (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.dxf2.webmessage; +package org.hisp.dhis.dxf2.webmessage.responses; import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; +import javax.annotation.Nonnull; +import lombok.Getter; +import lombok.RequiredArgsConstructor; import org.hisp.dhis.webmessage.WebMessageResponse; /** * @author Morten Olav Hansen */ -public class AbstractWebMessageResponse implements WebMessageResponse { - /** - * Optional type property. Since we are using the somewhat generic name 'response' for the data - * part of the message, this can be used to signal what kind of response this is. - * - *

Some examples might be 'ImportCount', 'ImportSummary', etc. - */ - private String responseType; +@Getter +@RequiredArgsConstructor +@JsonPropertyOrder({"type", "created", "updated", "deleted"}) +public class ImportCountWebMessageResponse implements WebMessageResponse { - public AbstractWebMessageResponse() { - this.responseType = getClass().getSimpleName().replaceFirst("WebMessageResponse", ""); - } - - public AbstractWebMessageResponse(String responseType) { - this.responseType = responseType; - } - - @JsonProperty - @JacksonXmlProperty(isAttribute = true) - public String getResponseType() { - return responseType; - } + @JsonProperty private final int created; + @JsonProperty private final int updated; + @JsonProperty private final int deleted; - public void setResponseType(String responseType) { - this.responseType = responseType; + @Nonnull + @Override + public Class getResponseClassType() { + return ImportCountWebMessageResponse.class; } } diff --git a/dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/webmessage/responses/ImportReportWebMessageResponse.java b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dxf2/webmessage/responses/ImportReportWebMessageResponse.java similarity index 87% rename from dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/webmessage/responses/ImportReportWebMessageResponse.java rename to dhis-2/dhis-api/src/main/java/org/hisp/dhis/dxf2/webmessage/responses/ImportReportWebMessageResponse.java index 32c0f40f9905..4ec6ea5f5e08 100644 --- a/dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/webmessage/responses/ImportReportWebMessageResponse.java +++ b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dxf2/webmessage/responses/ImportReportWebMessageResponse.java @@ -32,24 +32,28 @@ import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement; import java.util.List; +import javax.annotation.Nonnull; +import lombok.RequiredArgsConstructor; import org.hisp.dhis.common.DxfNamespaces; import org.hisp.dhis.dxf2.metadata.feedback.ImportReport; -import org.hisp.dhis.dxf2.webmessage.AbstractWebMessageResponse; import org.hisp.dhis.feedback.Stats; import org.hisp.dhis.feedback.Status; import org.hisp.dhis.feedback.TypeReport; -import org.springframework.util.Assert; +import org.hisp.dhis.webmessage.WebMessageResponse; /** * @author Morten Olav Hansen */ +@RequiredArgsConstructor @JacksonXmlRootElement(localName = "importReport", namespace = DxfNamespaces.DXF_2_0) -public class ImportReportWebMessageResponse extends AbstractWebMessageResponse { - private final ImportReport importReport; +public class ImportReportWebMessageResponse implements WebMessageResponse { - public ImportReportWebMessageResponse(ImportReport importReport) { - Assert.notNull(importReport, "ImportReport is require to be non-null."); - this.importReport = importReport; + @Nonnull private final ImportReport importReport; + + @Nonnull + @Override + public Class getResponseClassType() { + return ImportReportWebMessageResponse.class; } @JsonProperty diff --git a/dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/webmessage/responses/MergeWebResponse.java b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dxf2/webmessage/responses/MergeWebResponse.java similarity index 93% rename from dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/webmessage/responses/MergeWebResponse.java rename to dhis-2/dhis-api/src/main/java/org/hisp/dhis/dxf2/webmessage/responses/MergeWebResponse.java index 702af14c8e07..4e00bfb25e8f 100644 --- a/dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/webmessage/responses/MergeWebResponse.java +++ b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dxf2/webmessage/responses/MergeWebResponse.java @@ -29,6 +29,7 @@ import com.fasterxml.jackson.annotation.JsonProperty; import javax.annotation.Nonnull; +import lombok.Getter; import org.hisp.dhis.feedback.MergeReport; import org.hisp.dhis.merge.MergeType; import org.hisp.dhis.webmessage.WebMessageResponse; @@ -36,6 +37,7 @@ /** * @author david mackessy */ +@Getter public class MergeWebResponse implements WebMessageResponse { @JsonProperty private MergeReport mergeReport; @@ -47,4 +49,10 @@ public MergeWebResponse(@Nonnull MergeReport mergeReport) { ? "%s merge has errors".formatted(mergeType) : "%s merge complete".formatted(mergeType)); } + + @Nonnull + @Override + public Class getResponseClassType() { + return MergeWebResponse.class; + } } diff --git a/dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/webmessage/responses/ObjectReportWebMessageResponse.java b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dxf2/webmessage/responses/ObjectReportWebMessageResponse.java similarity index 70% rename from dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/webmessage/responses/ObjectReportWebMessageResponse.java rename to dhis-2/dhis-api/src/main/java/org/hisp/dhis/dxf2/webmessage/responses/ObjectReportWebMessageResponse.java index 54c5cf9302c8..e5216b5d7dc0 100644 --- a/dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/webmessage/responses/ObjectReportWebMessageResponse.java +++ b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dxf2/webmessage/responses/ObjectReportWebMessageResponse.java @@ -28,41 +28,38 @@ package org.hisp.dhis.dxf2.webmessage.responses; import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper; -import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; import java.util.List; -import org.hisp.dhis.common.DxfNamespaces; -import org.hisp.dhis.dxf2.webmessage.AbstractWebMessageResponse; +import javax.annotation.Nonnull; +import lombok.RequiredArgsConstructor; import org.hisp.dhis.feedback.ErrorReport; import org.hisp.dhis.feedback.ObjectReport; -import org.springframework.util.Assert; +import org.hisp.dhis.webmessage.WebMessageResponse; /** * @author Morten Olav Hansen */ -public class ObjectReportWebMessageResponse extends AbstractWebMessageResponse { - private final ObjectReport objectReport; +@RequiredArgsConstructor +public class ObjectReportWebMessageResponse implements WebMessageResponse { - public ObjectReportWebMessageResponse(ObjectReport objectReport) { - Assert.notNull(objectReport, "ObjectReport is required to be non-null."); - this.objectReport = objectReport; + @Nonnull private final ObjectReport objectReport; + + @Nonnull + @Override + public Class getResponseClassType() { + return ObjectReportWebMessageResponse.class; } @JsonProperty - @JacksonXmlProperty(isAttribute = true) public Class getKlass() { return objectReport.getKlass(); } @JsonProperty - @JacksonXmlProperty(isAttribute = true) public String getUid() { return objectReport.getUid(); } @JsonProperty - @JacksonXmlElementWrapper(localName = "errorReports", namespace = DxfNamespaces.DXF_2_0) - @JacksonXmlProperty(localName = "errorReport", namespace = DxfNamespaces.DXF_2_0) public List getErrorReports() { return objectReport.getErrorReports(); } diff --git a/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/system/SoftwareUpdateResponse.java b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dxf2/webmessage/responses/SoftwareUpdateResponse.java similarity index 72% rename from dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/system/SoftwareUpdateResponse.java rename to dhis-2/dhis-api/src/main/java/org/hisp/dhis/dxf2/webmessage/responses/SoftwareUpdateResponse.java index 0feb018586b7..99f08108b316 100644 --- a/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/system/SoftwareUpdateResponse.java +++ b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dxf2/webmessage/responses/SoftwareUpdateResponse.java @@ -25,27 +25,27 @@ * (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.webapi.controller.system; +package org.hisp.dhis.dxf2.webmessage.responses; import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; -import com.vdurmont.semver4j.Semver; import java.util.Map; -import org.hisp.dhis.dxf2.webmessage.AbstractWebMessageResponse; +import javax.annotation.Nonnull; +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import org.hisp.dhis.webmessage.WebMessageResponse; /** * @author Morten Svanaes */ -public class SoftwareUpdateResponse extends AbstractWebMessageResponse { - private final Map> versionMetadata; +@Getter +@RequiredArgsConstructor +public class SoftwareUpdateResponse implements WebMessageResponse { - public SoftwareUpdateResponse(Map> versionMetadata) { - this.versionMetadata = versionMetadata; - } + @JsonProperty private final Map> versionMetadata; - @JsonProperty - @JacksonXmlProperty(isAttribute = true) - public Map> getVersionMetadata() { - return versionMetadata; + @Nonnull + @Override + public Class getResponseClassType() { + return SoftwareUpdateResponse.class; } } diff --git a/dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/webmessage/responses/TypeReportWebMessageResponse.java b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dxf2/webmessage/responses/TypeReportWebMessageResponse.java similarity index 86% rename from dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/webmessage/responses/TypeReportWebMessageResponse.java rename to dhis-2/dhis-api/src/main/java/org/hisp/dhis/dxf2/webmessage/responses/TypeReportWebMessageResponse.java index 57d752068292..a5d18e4230ef 100644 --- a/dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/webmessage/responses/TypeReportWebMessageResponse.java +++ b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dxf2/webmessage/responses/TypeReportWebMessageResponse.java @@ -31,23 +31,27 @@ import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper; import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; import java.util.List; +import javax.annotation.Nonnull; +import lombok.RequiredArgsConstructor; import org.hisp.dhis.common.DxfNamespaces; -import org.hisp.dhis.dxf2.webmessage.AbstractWebMessageResponse; import org.hisp.dhis.feedback.ObjectReport; import org.hisp.dhis.feedback.Stats; import org.hisp.dhis.feedback.Status; import org.hisp.dhis.feedback.TypeReport; -import org.springframework.util.Assert; +import org.hisp.dhis.webmessage.WebMessageResponse; /** * @author Morten Olav Hansen */ -public class TypeReportWebMessageResponse extends AbstractWebMessageResponse { - private final TypeReport typeReport; +@RequiredArgsConstructor +public class TypeReportWebMessageResponse implements WebMessageResponse { - public TypeReportWebMessageResponse(TypeReport typeReport) { - Assert.notNull(typeReport, "ImportReport is require to be non-null."); - this.typeReport = typeReport; + @Nonnull private final TypeReport typeReport; + + @Nonnull + @Override + public Class getResponseClassType() { + return TypeReportWebMessageResponse.class; } @JsonProperty diff --git a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/feedback/BadRequestException.java b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/feedback/BadRequestException.java index cd43c5e3fd5a..f6e831454762 100644 --- a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/feedback/BadRequestException.java +++ b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/feedback/BadRequestException.java @@ -37,11 +37,11 @@ import lombok.Setter; import lombok.experimental.Accessors; import org.hisp.dhis.common.OpenApi; -import org.hisp.dhis.webmessage.WebMessageResponse; +import org.hisp.dhis.webmessage.BasicWebMessage; @Getter @Accessors(chain = true) -@OpenApi.Response(status = BAD_REQUEST, value = WebMessageResponse.class) +@OpenApi.Response(status = BAD_REQUEST, value = BasicWebMessage.class) @SuppressWarnings({"java:S1165", "java:S1948"}) public final class BadRequestException extends Exception implements Error { public static V on(Class type, Supplier operation) diff --git a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/feedback/ConflictException.java b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/feedback/ConflictException.java index eee1d55f88db..21ed550e161e 100644 --- a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/feedback/ConflictException.java +++ b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/feedback/ConflictException.java @@ -36,11 +36,11 @@ import lombok.Setter; import lombok.experimental.Accessors; import org.hisp.dhis.common.OpenApi; -import org.hisp.dhis.webmessage.WebMessageResponse; +import org.hisp.dhis.webmessage.BasicWebMessage; @Getter @Accessors(chain = true) -@OpenApi.Response(status = CONFLICT, value = WebMessageResponse.class) +@OpenApi.Response(status = CONFLICT, value = BasicWebMessage.class) @SuppressWarnings({"java:S1165", "java:S1948"}) public final class ConflictException extends Exception implements Error { public static V on(Class type, Supplier operation) diff --git a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/feedback/ForbiddenException.java b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/feedback/ForbiddenException.java index 7de3a4f669e9..886e9ac84850 100644 --- a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/feedback/ForbiddenException.java +++ b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/feedback/ForbiddenException.java @@ -35,11 +35,11 @@ import lombok.Getter; import lombok.experimental.Accessors; import org.hisp.dhis.common.OpenApi; -import org.hisp.dhis.webmessage.WebMessageResponse; +import org.hisp.dhis.webmessage.BasicWebMessage; @Getter @Accessors(chain = true) -@OpenApi.Response(status = FORBIDDEN, value = WebMessageResponse.class) +@OpenApi.Response(status = FORBIDDEN, value = BasicWebMessage.class) public final class ForbiddenException extends Exception implements Error { public static V on(Class type, Supplier operation) throws ForbiddenException { diff --git a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/feedback/HiddenNotFoundException.java b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/feedback/HiddenNotFoundException.java index f1faac18db54..60541f35ba89 100644 --- a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/feedback/HiddenNotFoundException.java +++ b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/feedback/HiddenNotFoundException.java @@ -35,11 +35,11 @@ import lombok.Getter; import lombok.experimental.Accessors; import org.hisp.dhis.common.OpenApi; -import org.hisp.dhis.webmessage.WebMessageResponse; +import org.hisp.dhis.webmessage.BasicWebMessage; @Getter @Accessors(chain = true) -@OpenApi.Response(status = OK, value = WebMessageResponse.class) +@OpenApi.Response(status = OK, value = BasicWebMessage.class) public final class HiddenNotFoundException extends Exception implements Error { public static V on(Class type, Supplier operation) throws HiddenNotFoundException { diff --git a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/feedback/NotFoundException.java b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/feedback/NotFoundException.java index 94bd4d17426e..3ef0609c05fa 100644 --- a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/feedback/NotFoundException.java +++ b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/feedback/NotFoundException.java @@ -35,11 +35,11 @@ import lombok.Getter; import lombok.experimental.Accessors; import org.hisp.dhis.common.OpenApi; -import org.hisp.dhis.webmessage.WebMessageResponse; +import org.hisp.dhis.webmessage.BasicWebMessage; @Getter @Accessors(chain = true) -@OpenApi.Response(status = NOT_FOUND, value = WebMessageResponse.class) +@OpenApi.Response(status = NOT_FOUND, value = BasicWebMessage.class) public final class NotFoundException extends Exception implements Error { public static V on(Class type, Supplier operation) throws NotFoundException { diff --git a/dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/predictor/PredictionStatus.java b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/predictor/PredictionStatus.java similarity index 100% rename from dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/predictor/PredictionStatus.java rename to dhis-2/dhis-api/src/main/java/org/hisp/dhis/predictor/PredictionStatus.java diff --git a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/predictor/PredictionSummary.java b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/predictor/PredictionSummary.java new file mode 100644 index 000000000000..691a10fe3568 --- /dev/null +++ b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/predictor/PredictionSummary.java @@ -0,0 +1,89 @@ +/* + * Copyright (c) 2004-2022, University of Oslo + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * Neither the name of the HISP project nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (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.predictor; + +import com.fasterxml.jackson.annotation.JsonProperty; +import javax.annotation.Nonnull; +import lombok.Getter; +import lombok.ToString; +import org.hisp.dhis.webmessage.WebMessageResponse; + +/** + * @author Jim Grace + */ +@ToString +@Getter +public class PredictionSummary implements WebMessageResponse { + + @JsonProperty private PredictionStatus status = PredictionStatus.SUCCESS; + + @JsonProperty private String description; + + @JsonProperty private int predictors = 0; + @JsonProperty private int inserted = 0; + @JsonProperty private int updated = 0; + @JsonProperty private int deleted = 0; + @JsonProperty private int unchanged = 0; + + public PredictionSummary() {} + + public PredictionSummary(PredictionStatus status, String description) { + this.status = status; + this.description = description; + } + + @Nonnull + @Override + public Class getResponseClassType() { + return PredictionSummary.class; + } + + public void incrementInserted() { + inserted += 1; + } + + public void incrementPredictors() { + predictors += 1; + } + + public void incrementUpdated() { + updated += 1; + } + + public void incrementDeleted() { + deleted += 1; + } + + public void incrementUnchanged() { + unchanged += 1; + } + + public int getPredictions() { + return inserted + updated + unchanged; + } +} diff --git a/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/tracker/imports/TrackerJobWebMessageResponse.java b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/webapi/controller/tracker/imports/TrackerJobWebMessageResponse.java similarity index 91% rename from dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/tracker/imports/TrackerJobWebMessageResponse.java rename to dhis-2/dhis-api/src/main/java/org/hisp/dhis/webapi/controller/tracker/imports/TrackerJobWebMessageResponse.java index 3251757dc7ba..b0fa4bd1bff4 100644 --- a/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/tracker/imports/TrackerJobWebMessageResponse.java +++ b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/webapi/controller/tracker/imports/TrackerJobWebMessageResponse.java @@ -28,6 +28,7 @@ package org.hisp.dhis.webapi.controller.tracker.imports; import com.fasterxml.jackson.annotation.JsonProperty; +import javax.annotation.Nonnull; import lombok.Builder; import lombok.Data; import org.hisp.dhis.webmessage.WebMessageResponse; @@ -35,7 +36,13 @@ @Data @Builder public class TrackerJobWebMessageResponse implements WebMessageResponse { - @JsonProperty private final String id; + @JsonProperty private final String id; @JsonProperty private final String location; + + @Nonnull + @Override + public Class getResponseClassType() { + return TrackerJobWebMessageResponse.class; + } } diff --git a/dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/webmessage/responses/ImportCountWebMessageResponse.java b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/webmessage/BasicWebMessage.java similarity index 56% rename from dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/webmessage/responses/ImportCountWebMessageResponse.java rename to dhis-2/dhis-api/src/main/java/org/hisp/dhis/webmessage/BasicWebMessage.java index 8f02cba842eb..a3c4424a888e 100644 --- a/dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/webmessage/responses/ImportCountWebMessageResponse.java +++ b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/webmessage/BasicWebMessage.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004-2022, University of Oslo + * Copyright (c) 2004-2024, University of Oslo * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -25,58 +25,58 @@ * (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.dxf2.webmessage.responses; +package org.hisp.dhis.webmessage; import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.annotation.JsonPropertyOrder; import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; +import lombok.Getter; import org.hisp.dhis.common.DxfNamespaces; -import org.hisp.dhis.dxf2.webmessage.AbstractWebMessageResponse; +import org.hisp.dhis.common.OpenApi; +import org.hisp.dhis.feedback.ErrorCode; +import org.hisp.dhis.feedback.Status; /** - * @author Morten Olav Hansen + * The core information of a standard web response message. + * + *

The main reason for this class is that it does not depend on web layer classes. Fields that + * require these are first added by {@code WebMessage}. + * + * @author Jan Bernitt */ -@JsonPropertyOrder({"type", "created", "updated", "deleted"}) -public class ImportCountWebMessageResponse extends AbstractWebMessageResponse { - private int created; - - private int updated; - - private int deleted; - - public ImportCountWebMessageResponse(int created, int updated, int deleted) { - this.created = created; - this.updated = updated; - this.deleted = deleted; - } +@Getter +@OpenApi.Kind("WebMessageResponse") +public class BasicWebMessage { + /** + * Message status, currently two statuses are available: OK, ERROR. Default value is OK. + * + * @see Status + */ @JsonProperty - @JacksonXmlProperty(namespace = DxfNamespaces.DXF_2_0) - public int getCreated() { - return created; - } - - public void setCreated(int created) { - this.created = created; - } + @JacksonXmlProperty(isAttribute = true) + protected Status status = Status.OK; + /** + * Internal code for this message. Should be used to help with third party clients which should + * not have to resort to string parsing of message to know what is happening. + */ @JsonProperty - @JacksonXmlProperty(namespace = DxfNamespaces.DXF_2_0) - public int getUpdated() { - return updated; - } - - public void setUpdated(int updated) { - this.updated = updated; - } + @JacksonXmlProperty(isAttribute = true) + protected Integer code; + /** + * The {@link ErrorCode} which describes a potential error. Only relevant for {@link + * Status#ERROR}. + */ + @JacksonXmlProperty(isAttribute = true) @JsonProperty - @JacksonXmlProperty(namespace = DxfNamespaces.DXF_2_0) - public int getDeleted() { - return deleted; - } + protected ErrorCode errorCode; - public void setDeleted(int deleted) { - this.deleted = deleted; - } + /** + * Non-technical message, should be simple and could possibly be used to display message to an + * end-user. + */ + @JacksonXmlProperty(namespace = DxfNamespaces.DXF_2_0) + @JsonProperty + protected String message; } diff --git a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/webmessage/WebMessageResponse.java b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/webmessage/WebMessageResponse.java index 567ec4eb0552..d793738ef53f 100644 --- a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/webmessage/WebMessageResponse.java +++ b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/webmessage/WebMessageResponse.java @@ -27,7 +27,23 @@ */ package org.hisp.dhis.webmessage; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonProperty; +import javax.annotation.Nonnull; +import org.hisp.dhis.common.OpenApi; + /** * @author Morten Olav Hansen */ -public interface WebMessageResponse {} +@OpenApi.Kind("WebMessageResponse") +public interface WebMessageResponse { + + @Nonnull + @JsonIgnore + Class getResponseClassType(); + + @JsonProperty + default String getResponseType() { + return getResponseClassType().getSimpleName(); + } +} diff --git a/dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/sync/DefaultSynchronizationManager.java b/dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/sync/DefaultSynchronizationManager.java index 84b518ab05cb..72888f2f54be 100644 --- a/dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/sync/DefaultSynchronizationManager.java +++ b/dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/sync/DefaultSynchronizationManager.java @@ -46,7 +46,6 @@ import org.hisp.dhis.dxf2.metadata.MetadataImportService; import org.hisp.dhis.dxf2.metadata.MetadataObjects; import org.hisp.dhis.dxf2.metadata.feedback.ImportReport; -import org.hisp.dhis.dxf2.webmessage.AbstractWebMessageResponse; import org.hisp.dhis.dxf2.webmessage.WebMessageParseException; import org.hisp.dhis.schema.SchemaService; import org.hisp.dhis.setting.SystemSettings; @@ -54,6 +53,7 @@ import org.hisp.dhis.system.util.CodecUtils; import org.hisp.dhis.user.CurrentUserUtil; import org.hisp.dhis.user.UserDetails; +import org.hisp.dhis.webmessage.WebMessageResponse; import org.springframework.http.MediaType; import org.springframework.stereotype.Component; import org.springframework.web.client.RequestCallback; @@ -157,7 +157,7 @@ private ImportConflicts executeDataValuePush(SystemInstance instance) final int maxSyncAttempts = settingsService.getCurrentSettings().getSyncMaxAttempts(); - Optional responseSummary = + Optional responseSummary = SyncUtils.runSyncRequest( restTemplate, requestCallback, diff --git a/dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/sync/SyncEndpoint.java b/dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/sync/SyncEndpoint.java index ff92e13d2834..d229fa4d4389 100644 --- a/dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/sync/SyncEndpoint.java +++ b/dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/sync/SyncEndpoint.java @@ -31,7 +31,7 @@ import lombok.AllArgsConstructor; import lombok.Getter; import org.hisp.dhis.dxf2.importsummary.ImportSummary; -import org.hisp.dhis.dxf2.webmessage.AbstractWebMessageResponse; +import org.hisp.dhis.webmessage.WebMessageResponse; /** * @author David Katuscak @@ -44,5 +44,5 @@ public enum SyncEndpoint { private final String path; - private final Class klass; + private final Class klass; } diff --git a/dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/sync/SyncUtils.java b/dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/sync/SyncUtils.java index 5c4e7b3ecfc9..dae2bfa94487 100644 --- a/dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/sync/SyncUtils.java +++ b/dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/sync/SyncUtils.java @@ -36,12 +36,12 @@ import org.hisp.dhis.dxf2.importsummary.ImportStatus; import org.hisp.dhis.dxf2.importsummary.ImportSummaries; import org.hisp.dhis.dxf2.importsummary.ImportSummary; -import org.hisp.dhis.dxf2.webmessage.AbstractWebMessageResponse; import org.hisp.dhis.dxf2.webmessage.WebMessageParseException; import org.hisp.dhis.dxf2.webmessage.utils.WebMessageParseUtils; import org.hisp.dhis.setting.SystemSettings; import org.hisp.dhis.system.util.CodecUtils; import org.hisp.dhis.system.util.HttpUtils; +import org.hisp.dhis.webmessage.WebMessageResponse; import org.springframework.http.HttpEntity; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; @@ -83,7 +83,7 @@ static boolean sendSyncRequest( SystemInstance instance, SyncEndpoint endpoint) { final int maxSyncAttempts = settings.getSyncMaxAttempts(); - Optional responseSummaries = + Optional responseSummaries = runSyncRequest( restTemplate, requestCallback, endpoint.getKlass(), instance.getUrl(), maxSyncAttempts); @@ -101,18 +101,17 @@ static boolean sendSyncRequest( return false; } - public static Optional runSyncRequest( + public static Optional runSyncRequest( RestTemplate restTemplate, RequestCallback requestCallback, - Class klass, + Class klass, String syncUrl, int maxSyncAttempts) { boolean networkErrorOccurred = true; int syncAttemptsDone = 0; - ResponseExtractor responseExtractor = - getResponseExtractor(klass); - AbstractWebMessageResponse responseSummary = null; + ResponseExtractor responseExtractor = getResponseExtractor(klass); + WebMessageResponse responseSummary = null; while (networkErrorOccurred) { networkErrorOccurred = false; @@ -147,8 +146,8 @@ public static Optional runSyncRequest( return Optional.ofNullable(responseSummary); } - private static ResponseExtractor getResponseExtractor( - Class klass) { + private static ResponseExtractor getResponseExtractor( + Class klass) { if (ImportSummaries.class.isAssignableFrom(klass)) { return new ImportSummariesResponseExtractor(); } else if (ImportSummary.class.isAssignableFrom(klass)) { diff --git a/dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/webmessage/WebMessage.java b/dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/webmessage/WebMessage.java index 01fce5f33de7..b61f3c3e9db0 100644 --- a/dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/webmessage/WebMessage.java +++ b/dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/webmessage/WebMessage.java @@ -27,19 +27,35 @@ */ package org.hisp.dhis.dxf2.webmessage; -import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonPropertyOrder; -import com.fasterxml.jackson.databind.node.ObjectNode; import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement; import com.google.common.base.MoreObjects; import javax.annotation.Nonnull; -import org.hisp.dhis.common.DhisApiVersion; +import lombok.Getter; import org.hisp.dhis.common.DxfNamespaces; import org.hisp.dhis.common.OpenApi; +import org.hisp.dhis.dataintegrity.FlattenedDataIntegrityReport; +import org.hisp.dhis.dxf2.common.ImportTypeSummary; +import org.hisp.dhis.dxf2.geojson.GeoJsonImportReport; +import org.hisp.dhis.dxf2.importsummary.ImportSummaries; +import org.hisp.dhis.dxf2.importsummary.ImportSummary; +import org.hisp.dhis.dxf2.metadata.sync.MetadataSyncSummary; +import org.hisp.dhis.dxf2.scheduling.JobConfigurationWebMessageResponse; +import org.hisp.dhis.dxf2.webmessage.responses.ApiTokenCreationResponse; +import org.hisp.dhis.dxf2.webmessage.responses.ErrorReportsWebMessageResponse; +import org.hisp.dhis.dxf2.webmessage.responses.FileResourceWebMessageResponse; +import org.hisp.dhis.dxf2.webmessage.responses.ImportCountWebMessageResponse; +import org.hisp.dhis.dxf2.webmessage.responses.ImportReportWebMessageResponse; +import org.hisp.dhis.dxf2.webmessage.responses.MergeWebResponse; +import org.hisp.dhis.dxf2.webmessage.responses.ObjectReportWebMessageResponse; +import org.hisp.dhis.dxf2.webmessage.responses.SoftwareUpdateResponse; import org.hisp.dhis.feedback.ErrorCode; import org.hisp.dhis.feedback.Status; +import org.hisp.dhis.predictor.PredictionSummary; +import org.hisp.dhis.webapi.controller.tracker.imports.TrackerJobWebMessageResponse; +import org.hisp.dhis.webmessage.BasicWebMessage; import org.hisp.dhis.webmessage.WebMessageResponse; import org.springframework.http.HttpStatus; @@ -56,35 +72,11 @@ "devMessage", "response" }) -public class WebMessage implements WebMessageResponse { - /** - * Message status, currently two statuses are available: OK, ERROR. Default value is OK. - * - * @see Status - */ - private Status status = Status.OK; - - /** - * Internal code for this message. Should be used to help with third party clients which should - * not have to resort to string parsing of message to know what is happening. - */ - private Integer code; +public class WebMessage extends BasicWebMessage { /** HTTP status. */ private HttpStatus httpStatus = HttpStatus.OK; - /** - * The {@link ErrorCode} which describes a potential error. Only relevant for {@link - * Status#ERROR}. - */ - private ErrorCode errorCode; - - /** - * Non-technical message, should be simple and could possibly be used to display message to an - * end-user. - */ - private String message; - /** * Technical message that should explain as much details as possible, mainly to be used for * debugging. @@ -93,16 +85,31 @@ public class WebMessage implements WebMessageResponse { /** * When a simple text feedback is not enough, you can use this interface to implement your own - * message responses. - * - * @see WebMessageResponse + * response payload object. */ - @OpenApi.Property({ObjectNode.class}) + @OpenApi.Property({ + ApiTokenCreationResponse.class, + ErrorReportsWebMessageResponse.class, + FileResourceWebMessageResponse.class, + FlattenedDataIntegrityReport.class, + GeoJsonImportReport.class, + ImportCountWebMessageResponse.class, + ImportReportWebMessageResponse.class, + ImportSummaries.class, + ImportSummary.class, + ImportTypeSummary.class, + JobConfigurationWebMessageResponse.class, + MergeWebResponse.class, + MetadataSyncSummary.class, + ObjectReportWebMessageResponse.class, + PredictionSummary.class, + SoftwareUpdateResponse.class, + TrackerJobWebMessageResponse.class, + TrackerJobWebMessageResponse.class + }) private WebMessageResponse response; - private DhisApiVersion plainResponseBefore; - - private String location; + @Getter private String location; // ------------------------------------------------------------------------- // Constructors @@ -136,28 +143,11 @@ public boolean isError() { // Get and set methods // ------------------------------------------------------------------------- - @JsonProperty - @JacksonXmlProperty(isAttribute = true) - public Status getStatus() { - return status; - } - public WebMessage setStatus(Status status) { this.status = status; return this; } - @JsonProperty - @JacksonXmlProperty(isAttribute = true) - public Integer getCode() { - return code; - } - - public WebMessage setCode(Integer code) { - this.code = code; - return this; - } - @JsonProperty @JacksonXmlProperty(isAttribute = true) public String getHttpStatus() { @@ -176,23 +166,11 @@ public Integer getHttpStatusCode() { return httpStatus.value(); } - @JsonProperty - @JacksonXmlProperty(isAttribute = true) - public ErrorCode getErrorCode() { - return errorCode; - } - public WebMessage setErrorCode(ErrorCode errorCode) { this.errorCode = errorCode; return this; } - @JsonProperty - @JacksonXmlProperty(namespace = DxfNamespaces.DXF_2_0) - public String getMessage() { - return message; - } - public WebMessage setMessage(String message) { this.message = message; return this; @@ -220,25 +198,11 @@ public WebMessage setResponse(WebMessageResponse response) { return this; } - public String getLocation() { - return location; - } - public WebMessage setLocation(String location) { this.location = location; return this; } - public WebMessage withPlainResponseBefore(DhisApiVersion version) { - this.plainResponseBefore = version; - return this; - } - - @JsonIgnore - public DhisApiVersion getPlainResponseBefore() { - return plainResponseBefore; - } - @Override public String toString() { return MoreObjects.toStringHelper(this) diff --git a/dhis-2/dhis-services/dhis-service-reporting/pom.xml b/dhis-2/dhis-services/dhis-service-reporting/pom.xml index ead9adc3aae5..601925c4f8ed 100644 --- a/dhis-2/dhis-services/dhis-service-reporting/pom.xml +++ b/dhis-2/dhis-services/dhis-service-reporting/pom.xml @@ -139,10 +139,6 @@ com.fasterxml.jackson.core jackson-core - - com.fasterxml.jackson.dataformat - jackson-dataformat-xml - com.google.guava guava diff --git a/dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/predictor/PredictionSummary.java b/dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/predictor/PredictionSummary.java deleted file mode 100644 index 6407e411db3a..000000000000 --- a/dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/predictor/PredictionSummary.java +++ /dev/null @@ -1,158 +0,0 @@ -/* - * Copyright (c) 2004-2022, University of Oslo - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * Neither the name of the HISP project nor the names of its contributors may - * be used to endorse or promote products derived from this software without - * specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR - * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (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.predictor; - -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; -import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement; -import org.hisp.dhis.common.DxfNamespaces; -import org.hisp.dhis.dxf2.webmessage.AbstractWebMessageResponse; - -/** - * @author Jim Grace - */ -@JacksonXmlRootElement(localName = "predictionSummary", namespace = DxfNamespaces.DXF_2_0) -public class PredictionSummary extends AbstractWebMessageResponse { - private PredictionStatus status = PredictionStatus.SUCCESS; - - private String description; - - private int predictors = 0; - - private int inserted = 0; - - private int updated = 0; - - private int deleted = 0; - - private int unchanged = 0; - - public PredictionSummary() {} - - public PredictionSummary(PredictionStatus status, String description) { - this.status = status; - this.description = description; - } - - public void incrementInserted() { - inserted += 1; - } - - public void incrementPredictors() { - predictors += 1; - } - - public void incrementUpdated() { - updated += 1; - } - - public void incrementDeleted() { - deleted += 1; - } - - public void incrementUnchanged() { - unchanged += 1; - } - - public int getPredictions() { - return inserted + updated + unchanged; - } - - @JsonProperty - @JacksonXmlProperty(namespace = DxfNamespaces.DXF_2_0) - public PredictionStatus getStatus() { - return status; - } - - public PredictionSummary setStatus(PredictionStatus status) { - this.status = status; - return this; - } - - @JsonProperty - @JacksonXmlProperty(namespace = DxfNamespaces.DXF_2_0) - public String getDescription() { - return description; - } - - public PredictionSummary setDescription(String description) { - this.description = description; - return this; - } - - @JsonProperty - @JacksonXmlProperty(namespace = DxfNamespaces.DXF_2_0) - public int getPredictors() { - return predictors; - } - - @JsonProperty - @JacksonXmlProperty(namespace = DxfNamespaces.DXF_2_0) - public int getInserted() { - return inserted; - } - - @JsonProperty - @JacksonXmlProperty(namespace = DxfNamespaces.DXF_2_0) - public int getUpdated() { - return updated; - } - - @JsonProperty - @JacksonXmlProperty(namespace = DxfNamespaces.DXF_2_0) - public int getDeleted() { - return deleted; - } - - @JsonProperty - @JacksonXmlProperty(namespace = DxfNamespaces.DXF_2_0) - public int getUnchanged() { - return unchanged; - } - - @Override - public String toString() { - return "PredictionSummary{" - + "status=" - + status - + ", description='" - + description - + '\'' - + ", predictors=" - + predictors - + ", inserted=" - + inserted - + ", updated=" - + updated - + ", deleted=" - + deleted - + ", unchanged=" - + unchanged - + '}'; - } -} diff --git a/dhis-2/dhis-support/dhis-support-commons/src/main/java/org/hisp/dhis/commons/jackson/jsonpatch/JsonPatchException.java b/dhis-2/dhis-support/dhis-support-commons/src/main/java/org/hisp/dhis/commons/jackson/jsonpatch/JsonPatchException.java index f9996532d7cd..51e1db0647f9 100644 --- a/dhis-2/dhis-support/dhis-support-commons/src/main/java/org/hisp/dhis/commons/jackson/jsonpatch/JsonPatchException.java +++ b/dhis-2/dhis-support/dhis-support-commons/src/main/java/org/hisp/dhis/commons/jackson/jsonpatch/JsonPatchException.java @@ -30,12 +30,12 @@ import static org.hisp.dhis.common.OpenApi.Response.Status.BAD_REQUEST; import org.hisp.dhis.common.OpenApi; -import org.hisp.dhis.webmessage.WebMessageResponse; +import org.hisp.dhis.webmessage.BasicWebMessage; /** * @author Morten Olav Hansen */ -@OpenApi.Response(status = BAD_REQUEST, value = WebMessageResponse.class) +@OpenApi.Response(status = BAD_REQUEST, value = BasicWebMessage.class) public class JsonPatchException extends Exception { public JsonPatchException(String message) { super(message); diff --git a/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/CompleteDataSetRegistrationControllerTest.java b/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/CompleteDataSetRegistrationControllerTest.java index 1f9b265459c3..1e9015f7bbf0 100644 --- a/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/CompleteDataSetRegistrationControllerTest.java +++ b/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/CompleteDataSetRegistrationControllerTest.java @@ -40,7 +40,6 @@ import org.hisp.dhis.http.HttpStatus; import org.hisp.dhis.test.webapi.H2ControllerIntegrationTestBase; -import org.hisp.dhis.test.webapi.json.domain.JsonImportSummary; import org.junit.jupiter.api.Test; import org.springframework.http.MediaType; import org.springframework.transaction.annotation.Transactional; @@ -63,16 +62,6 @@ void testPostCompleteRegistrationsJson() { POST("/38/completeDataSetRegistrations", "{}").content(HttpStatus.CONFLICT)); } - @Test - void testPostCompleteRegistrationsJson_Pre38() { - JsonImportSummary summary = - POST("/37/completeDataSetRegistrations", "{}") - .content(HttpStatus.OK) - .as(JsonImportSummary.class); - assertEquals("ImportSummary", summary.getResponseType()); - assertEquals("ERROR", summary.getStatus()); - } - @Test void testPostCompleteRegistrationsXml() { HttpResponse response = @@ -86,19 +75,6 @@ void testPostCompleteRegistrationsXml() { assertTrue(content.startsWith(""), - ContentType(CONTENT_TYPE_XML), - Accept(CONTENT_TYPE_XML)); - assertEquals(HttpStatus.OK, response.status()); - String content = response.content(MediaType.APPLICATION_XML.toString()); - assertTrue(content.startsWith(""), - ContentType(CONTENT_TYPE_XML_ADX), - Accept(CONTENT_TYPE_XML)); - assertEquals(HttpStatus.OK, response.status()); - assertTrue(response.content(APPLICATION_XML.toString()).startsWith(""), - ContentType(APPLICATION_XML), - Accept(CONTENT_TYPE_XML)); - assertEquals(HttpStatus.OK, response.status()); - assertTrue(response.content(APPLICATION_XML.toString()).startsWith(""), ContentType("application/xml")) - .content(HttpStatus.OK); - assertEquals("OK", report.getString("status").string()); - assertEquals("ImportReport", report.getString("responseType").string()); - } - @Test void testPostProgramStageWithoutProgram() { JsonWebMessage message = diff --git a/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/OpenApiControllerTest.java b/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/OpenApiControllerTest.java index 3275f2dae27f..87d4a1e385da 100644 --- a/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/OpenApiControllerTest.java +++ b/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/OpenApiControllerTest.java @@ -89,7 +89,7 @@ void testGetOpenApiDocument_PathFilter() { "/api/users/invites", "/api/users/sharing")); assertLessOrEqual(26, doc.getObject("paths").size()); - assertLessOrEqual(60, doc.getObject("components.schemas").size()); + assertLessOrEqual(100, doc.getObject("components.schemas").size()); } @Test @@ -104,7 +104,7 @@ void testGetOpenApiDocument_DomainFilter() { "/api/users/invites", "/api/users/sharing")); assertLessOrEqual(151, doc.getObject("paths").size()); - assertLessOrEqual(80, doc.getObject("components.schemas").size()); + assertLessOrEqual(120, doc.getObject("components.schemas").size()); } @Test diff --git a/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/PredictionControllerTest.java b/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/PredictionControllerTest.java index 70499558e26b..964c17ccd752 100644 --- a/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/PredictionControllerTest.java +++ b/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/PredictionControllerTest.java @@ -29,10 +29,8 @@ import static org.hisp.dhis.test.utils.Assertions.assertStartsWith; import static org.hisp.dhis.test.webapi.Assertions.assertWebMessage; -import static org.junit.jupiter.api.Assertions.assertEquals; import org.hisp.dhis.http.HttpStatus; -import org.hisp.dhis.jsontree.JsonObject; import org.hisp.dhis.test.webapi.PostgresControllerIntegrationTestBase; import org.hisp.dhis.test.webapi.json.domain.JsonWebMessage; import org.junit.jupiter.api.Test; @@ -56,14 +54,6 @@ void testRunPredictors() { POST("/38/predictions?startDate=2020-01-01&endDate=2021-01-01").content(HttpStatus.OK)); } - @Test - void testRunPredictors_Pre38() { - JsonObject summary = - POST("/37/predictions?startDate=2020-01-01&endDate=2021-01-01").content(HttpStatus.OK); - assertEquals("SUCCESS", summary.getString("status").string()); - assertEquals(0, summary.getNumber("predictors").intValue()); - } - @Test void testRunPredictors_Async() { JsonWebMessage msg = diff --git a/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/UserControllerTest.java b/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/UserControllerTest.java index e8d97fe77078..c01e7cf5917b 100644 --- a/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/UserControllerTest.java +++ b/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/UserControllerTest.java @@ -858,20 +858,6 @@ void testPutJsonObject_WithSettings() { .content("text/plain")); } - @Test - void testPutJsonObject_Pre38() { - JsonObject user = GET("/users/{uid}", peter.getUid()).content(); - JsonImportSummary summary = - PUT("/37/users/" + peter.getUid(), user.toString()) - .content(HttpStatus.OK) - .as(JsonImportSummary.class); - assertEquals("ImportReport", summary.getResponseType()); - assertEquals("OK", summary.getStatus()); - assertEquals(1, summary.getStats().getUpdated()); - assertEquals( - peter.getUid(), summary.getTypeReports().get(0).getObjectReports().get(0).getUid()); - } - @Test void testPutProperty_InvalidWhatsapp() { JsonWebMessage msg = diff --git a/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/dataintegrity/DataIntegrityReportControllerTest.java b/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/dataintegrity/DataIntegrityReportControllerTest.java index 4e762bc1a203..1a7fed302eb8 100644 --- a/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/dataintegrity/DataIntegrityReportControllerTest.java +++ b/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/dataintegrity/DataIntegrityReportControllerTest.java @@ -63,15 +63,17 @@ void testNoViolations() { // if the report does not have any strings in the JSON tree there are no // errors since all collection/maps have string values JsonDataIntegrityReport report = getDataIntegrityReport(); - assertEquals(0, report.node().count(JsonNodeType.STRING)); + assertEquals(1, report.node().count(JsonNodeType.STRING)); + assertEquals("FlattenedDataIntegrityReport", report.getString("responseType").string()); } @Test void testDataElementChecksOnly() { JsonDataIntegrityReport report = getDataIntegrityReport("/dataIntegrity?checks=data-element*"); - assertEquals(5, report.size()); + assertEquals(6, report.size()); assertTrue( report.has( + "responseType", "dataElementsWithoutDataSet", "dataElementsWithoutGroups", "dataElementsAssignedToDataSetsWithDifferentPeriodTypes", @@ -83,9 +85,10 @@ void testDataElementChecksOnly() { void testExclusiveGroupsChecksOnly() { JsonDataIntegrityReport report = getDataIntegrityReport("/dataIntegrity?checks=*exclusive-group*"); - assertEquals(3, report.size()); + assertEquals(4, report.size()); assertTrue( report.has( + "responseType", "dataElementsViolatingExclusiveGroupSets", "indicatorsViolatingExclusiveGroupSets", "organisationUnitsViolatingExclusiveGroupSets")); @@ -95,7 +98,7 @@ void testExclusiveGroupsChecksOnly() { void testPeriodsDuplicatesOnly() { JsonDataIntegrityReport report = getDataIntegrityReport("/dataIntegrity?checks=periods_same_start_date_period_type"); - assertEquals(1, report.size()); + assertEquals(2, report.size()); assertTrue(report.getArray("duplicatePeriods").exists()); } diff --git a/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/CompleteDataSetRegistrationController.java b/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/CompleteDataSetRegistrationController.java index 402bd0472abe..7702ec5cc9f2 100644 --- a/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/CompleteDataSetRegistrationController.java +++ b/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/CompleteDataSetRegistrationController.java @@ -155,7 +155,7 @@ public WebMessage postCompleteRegistrationsXml( registrationExchangeService.saveCompleteDataSetRegistrationsXml( request.getInputStream(), importOptions); summary.setImportOptions(importOptions); - return importSummary(summary).withPlainResponseBefore(DhisApiVersion.V38); + return importSummary(summary); } @PostMapping(consumes = CONTENT_TYPE_JSON, produces = CONTENT_TYPE_JSON) @@ -170,7 +170,7 @@ public WebMessage postCompleteRegistrationsJson( registrationExchangeService.saveCompleteDataSetRegistrationsJson( request.getInputStream(), importOptions); summary.setImportOptions(importOptions); - return importSummary(summary).withPlainResponseBefore(DhisApiVersion.V38); + return importSummary(summary); } // ------------------------------------------------------------------------- diff --git a/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/DataValueSetController.java b/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/DataValueSetController.java index 45a2f8b43362..a15f13d005bb 100644 --- a/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/DataValueSetController.java +++ b/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/DataValueSetController.java @@ -27,7 +27,6 @@ */ package org.hisp.dhis.webapi.controller; -import static org.hisp.dhis.common.DhisApiVersion.V38; import static org.hisp.dhis.dxf2.webmessage.WebMessageUtils.importSummary; import static org.hisp.dhis.dxf2.webmessage.WebMessageUtils.jobConfigurationReport; import static org.hisp.dhis.scheduling.JobType.DATAVALUE_IMPORT; @@ -241,7 +240,7 @@ public WebMessage postDxf2DataValueSet(ImportOptions importOptions, HttpServletR dataValueSetService.importDataValueSetXml(request.getInputStream(), importOptions); summary.setImportOptions(importOptions); - return importSummary(summary).withPlainResponseBefore(V38); + return importSummary(summary); } @PostMapping(consumes = CONTENT_TYPE_XML_ADX) @@ -256,7 +255,7 @@ public WebMessage postAdxDataValueSet(ImportOptions importOptions, HttpServletRe adxDataService.saveDataValueSet(request.getInputStream(), importOptions, null); summary.setImportOptions(importOptions); - return importSummary(summary).withPlainResponseBefore(V38); + return importSummary(summary); } @PostMapping(consumes = APPLICATION_JSON_VALUE) @@ -271,7 +270,7 @@ public WebMessage postJsonDataValueSet(ImportOptions importOptions, HttpServletR dataValueSetService.importDataValueSetJson(request.getInputStream(), importOptions); summary.setImportOptions(importOptions); - return importSummary(summary).withPlainResponseBefore(V38); + return importSummary(summary); } @PostMapping(consumes = "application/csv") @@ -286,7 +285,7 @@ public WebMessage postCsvDataValueSet(ImportOptions importOptions, HttpServletRe dataValueSetService.importDataValueSetCsv(request.getInputStream(), importOptions); summary.setImportOptions(importOptions); - return importSummary(summary).withPlainResponseBefore(V38); + return importSummary(summary); } @PostMapping(consumes = CONTENT_TYPE_PDF) @@ -301,7 +300,7 @@ public WebMessage postPdfDataValueSet(ImportOptions importOptions, HttpServletRe dataValueSetService.importDataValueSetPdf(request.getInputStream(), importOptions); summary.setImportOptions(importOptions); - return importSummary(summary).withPlainResponseBefore(V38); + return importSummary(summary); } // ------------------------------------------------------------------------- diff --git a/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/PredictionController.java b/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/PredictionController.java index 6d2b4c2ae30e..1f6d8c0935f5 100644 --- a/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/PredictionController.java +++ b/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/PredictionController.java @@ -105,8 +105,6 @@ public WebMessage runPredictors( predictionService.predictTask( startDate, endDate, predictors, predictorGroups, JobProgress.noop()); - return new WebMessage(Status.OK, HttpStatus.OK) - .setResponse(predictionSummary) - .withPlainResponseBefore(DhisApiVersion.V38); + return new WebMessage(Status.OK, HttpStatus.OK).setResponse(predictionSummary); } } diff --git a/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/WebMessageControllerAdvice.java b/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/WebMessageControllerAdvice.java index de2875a77b0f..0edf838b41b0 100644 --- a/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/WebMessageControllerAdvice.java +++ b/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/WebMessageControllerAdvice.java @@ -27,12 +27,11 @@ */ package org.hisp.dhis.webapi.controller; -import org.hisp.dhis.common.DhisApiVersion; +import javax.annotation.Nonnull; import org.hisp.dhis.dxf2.webmessage.WebMessage; import org.hisp.dhis.system.util.HttpUtils; import org.hisp.dhis.webapi.service.ContextService; import org.hisp.dhis.webapi.utils.ContextUtils; -import org.hisp.dhis.webmessage.WebMessageResponse; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.core.MethodParameter; import org.springframework.http.CacheControl; @@ -45,42 +44,40 @@ import org.springframework.web.servlet.mvc.method.annotation.ResponseBodyAdvice; /** - * When returning {@link WebMessage} or even subclasses of {@link WebMessage}s the message's {@link - * WebMessage#getHttpStatusCode()} is used to set the HTTP response status code. + * When returning {@link WebMessage} the message's {@link WebMessage#getHttpStatusCode()} is used to + * set the HTTP response status code. * *

In case the response is a 4xx or 5xx caching is turned off. * * @author Jan Bernitt */ @ControllerAdvice -public class WebMessageControllerAdvice implements ResponseBodyAdvice { +public class WebMessageControllerAdvice implements ResponseBodyAdvice { @Autowired private ContextService contextService; @Override public boolean supports( - MethodParameter returnType, Class> selectedConverterType) { + MethodParameter returnType, + @Nonnull Class> selectedConverterType) { return WebMessage.class.isAssignableFrom(returnType.getParameterType()); } @Override - public WebMessageResponse beforeBodyWrite( - WebMessageResponse body, - MethodParameter returnType, - MediaType selectedContentType, - Class> selectedConverterType, - ServerHttpRequest request, - ServerHttpResponse response) { - WebMessage message = (WebMessage) body; - String location = message.getLocation(); + public WebMessage beforeBodyWrite( + WebMessage body, + @Nonnull MethodParameter returnType, + @Nonnull MediaType selectedContentType, + @Nonnull Class> selectedConverterType, + @Nonnull ServerHttpRequest request, + @Nonnull ServerHttpResponse response) { + if (body == null) return null; + String location = body.getLocation(); if (location != null) { response .getHeaders() .addIfAbsent(ContextUtils.HEADER_LOCATION, contextService.getApiPath() + location); } - if (isPlainResponse(request, message)) { - return ((WebMessage) body).getResponse(); - } - HttpStatus httpStatus = HttpUtils.resolve(message.getHttpStatusCode()); + HttpStatus httpStatus = HttpUtils.resolve(body.getHttpStatusCode()); if (httpStatus != null) { response.setStatusCode(httpStatus); if (httpStatus.is4xxClientError() || httpStatus.is5xxServerError()) { @@ -91,11 +88,4 @@ public WebMessageResponse beforeBodyWrite( } return body; } - - private boolean isPlainResponse(ServerHttpRequest request, WebMessage message) { - DhisApiVersion plainBefore = message.getPlainResponseBefore(); - return plainBefore == DhisApiVersion.ALL - || plainBefore != null - && DhisApiVersion.getVersionFromPath(request.getURI().getPath()).lt(plainBefore); - } } diff --git a/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/metadata/MetadataImportExportController.java b/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/metadata/MetadataImportExportController.java index 71239752f9bb..502445f3f018 100644 --- a/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/metadata/MetadataImportExportController.java +++ b/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/metadata/MetadataImportExportController.java @@ -132,7 +132,7 @@ public WebMessage postJsonMetadata(HttpServletRequest request) ImportReport importReport = metadataImportService.importMetadata(params, new MetadataObjects(objects)); - return importReport(importReport).withPlainResponseBefore(DhisApiVersion.V38); + return importReport(importReport); } @PostMapping(value = "", consumes = "application/csv") @@ -165,7 +165,7 @@ public WebMessage postCsvMetadata(HttpServletRequest request) params, new MetadataObjects().addMetadata(schemaService.getMetadataSchemas(), metadata)); - return importReport(report).withPlainResponseBefore(DhisApiVersion.V38); + return importReport(report); } @PostMapping(value = "/gml", consumes = APPLICATION_XML_VALUE) @@ -179,7 +179,7 @@ public WebMessage postGmlMetadata(HttpServletRequest request) } ImportReport importReport = gmlImportService.importGml(request.getInputStream(), params, JobProgress.noop()); - return importReport(importReport).withPlainResponseBefore(DhisApiVersion.V38); + return importReport(importReport); } @GetMapping("/csvImportClasses") diff --git a/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/metadata/sync/MetadataSyncController.java b/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/metadata/sync/MetadataSyncController.java index 8dabd8ce7d05..2a6a2262dfc5 100644 --- a/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/metadata/sync/MetadataSyncController.java +++ b/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/metadata/sync/MetadataSyncController.java @@ -29,8 +29,6 @@ import static org.hisp.dhis.security.Authorities.F_METADATA_MANAGE; -import jakarta.servlet.http.HttpServletRequest; -import jakarta.servlet.http.HttpServletResponse; import org.hisp.dhis.common.DhisApiVersion; import org.hisp.dhis.common.OpenApi; import org.hisp.dhis.dxf2.metadata.Metadata; @@ -50,7 +48,6 @@ import org.hisp.dhis.webapi.controller.exception.MetadataSyncException; import org.hisp.dhis.webapi.mvc.annotation.ApiVersion; import org.hisp.dhis.webapi.service.ContextService; -import org.hisp.dhis.webmessage.WebMessageResponse; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; @@ -74,14 +71,13 @@ public class MetadataSyncController { @RequiresAuthority(anyOf = F_METADATA_MANAGE) @GetMapping - public ResponseEntity metadataSync( - HttpServletRequest request, HttpServletResponse response) + public ResponseEntity metadataSync() throws MetadataSyncException, BadRequestException, MetadataImportConflictException, ForbiddenException { MetadataSyncParams syncParams; - MetadataSyncSummary metadataSyncSummary = null; + MetadataSyncSummary metadataSyncSummary; synchronized (metadataSyncService) { try { diff --git a/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/security/ApiTokenController.java b/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/security/ApiTokenController.java index 50c4325c238d..aae15f8500f0 100644 --- a/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/security/ApiTokenController.java +++ b/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/security/ApiTokenController.java @@ -45,6 +45,7 @@ import org.hisp.dhis.dxf2.metadata.MetadataObjects; import org.hisp.dhis.dxf2.metadata.feedback.ImportReportMode; import org.hisp.dhis.dxf2.webmessage.WebMessage; +import org.hisp.dhis.dxf2.webmessage.responses.ApiTokenCreationResponse; import org.hisp.dhis.feedback.ConflictException; import org.hisp.dhis.feedback.ForbiddenException; import org.hisp.dhis.feedback.ObjectReport; diff --git a/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/security/UserAccountController.java b/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/security/UserAccountController.java index 0987cb8fe58d..191973a2f13f 100644 --- a/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/security/UserAccountController.java +++ b/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/security/UserAccountController.java @@ -40,6 +40,7 @@ import org.hisp.dhis.common.OpenApi; import org.hisp.dhis.common.auth.UserInviteParams; import org.hisp.dhis.common.auth.UserRegistrationParams; +import org.hisp.dhis.dxf2.webmessage.WebMessage; import org.hisp.dhis.external.conf.DhisConfigurationProvider; import org.hisp.dhis.feedback.BadRequestException; import org.hisp.dhis.feedback.ConflictException; @@ -57,7 +58,6 @@ import org.hisp.dhis.user.UserAccountService; import org.hisp.dhis.user.UserService; import org.hisp.dhis.webapi.mvc.annotation.ApiVersion; -import org.hisp.dhis.webmessage.WebMessageResponse; import org.springframework.http.HttpStatus; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; @@ -178,7 +178,7 @@ public void resetPassword(@RequestBody ResetPasswordRequest request, SystemSetti @PostMapping("/registration") @ResponseStatus(HttpStatus.CREATED) - public WebMessageResponse registerUser( + public WebMessage registerUser( @RequestBody UserRegistrationParams params, HttpServletRequest request) throws BadRequestException, IOException { log.info("Self registration received"); @@ -192,7 +192,7 @@ public WebMessageResponse registerUser( @PostMapping("/invite") @ResponseStatus(HttpStatus.OK) - public WebMessageResponse invite(@RequestBody UserInviteParams params, HttpServletRequest request) + public WebMessage invite(@RequestBody UserInviteParams params, HttpServletRequest request) throws BadRequestException, IOException { log.info("Invite registration received"); diff --git a/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/system/SystemUpdateNotifyController.java b/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/system/SystemUpdateNotifyController.java index 2aa99b745b0c..074930bc638b 100644 --- a/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/system/SystemUpdateNotifyController.java +++ b/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/system/SystemUpdateNotifyController.java @@ -33,6 +33,7 @@ import org.hisp.dhis.common.OpenApi; import org.hisp.dhis.dxf2.webmessage.WebMessage; import org.hisp.dhis.dxf2.webmessage.WebMessageUtils; +import org.hisp.dhis.dxf2.webmessage.responses.SoftwareUpdateResponse; import org.hisp.dhis.scheduling.JobProgress; import org.hisp.dhis.system.SystemUpdateNotificationService; import org.hisp.dhis.webapi.controller.Server; @@ -72,6 +73,7 @@ public WebMessage checkForSystemUpdates( service.sendMessageForEachVersion(newerVersions, JobProgress.noop()); WebMessage ok = WebMessageUtils.ok(); + ok.setResponse(new SoftwareUpdateResponse(newerVersions)); return ok; } diff --git a/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/user/UserController.java b/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/user/UserController.java index 4c5645b48996..fcf4e531117b 100644 --- a/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/user/UserController.java +++ b/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/user/UserController.java @@ -56,7 +56,6 @@ import org.apache.commons.lang3.StringUtils; import org.hisp.dhis.attribute.Attribute; import org.hisp.dhis.common.CodeGenerator; -import org.hisp.dhis.common.DhisApiVersion; import org.hisp.dhis.common.IdentifiableObjects; import org.hisp.dhis.common.IllegalQueryException; import org.hisp.dhis.common.MergeMode; @@ -560,7 +559,7 @@ public WebMessage putJsonObject( HttpServletRequest request) throws IOException, ConflictException, ForbiddenException, NotFoundException { User inputUser = renderService.fromJson(request.getInputStream(), getEntityClass()); - return importReport(updateUser(pvUid, inputUser)).withPlainResponseBefore(DhisApiVersion.V38); + return importReport(updateUser(pvUid, inputUser)); } protected ImportReport updateUser(String userUid, User inputUser) diff --git a/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/openapi/ApiExtractor.java b/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/openapi/ApiExtractor.java index 3d69fefba420..d463ce6cdd8b 100644 --- a/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/openapi/ApiExtractor.java +++ b/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/openapi/ApiExtractor.java @@ -73,7 +73,6 @@ import org.hisp.dhis.common.Maturity; import org.hisp.dhis.common.OpenApi; import org.hisp.dhis.common.UID; -import org.hisp.dhis.dxf2.webmessage.WebMessage; import org.hisp.dhis.jsontree.Json; import org.hisp.dhis.jsontree.JsonList; import org.hisp.dhis.jsontree.JsonMap; @@ -81,7 +80,6 @@ import org.hisp.dhis.security.RequiresAuthority; import org.hisp.dhis.system.util.HttpUtils; import org.hisp.dhis.webapi.openapi.Api.Parameter.In; -import org.hisp.dhis.webmessage.WebMessageResponse; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; @@ -757,8 +755,13 @@ private Api.Property extractObjectProperty( } Type type = getSubstitutedType(endpoint, property, source); OpenApi.Property annotated = source.getAnnotation(OpenApi.Property.class); - if (type instanceof Class && isGeneratorType((Class) type) && annotated != null) { - return toProperty.apply(extractGeneratorSchema(endpoint, type, annotated.value())); + if (annotated != null) { + if (type instanceof Class && isGeneratorType((Class) type)) { + return toProperty.apply(extractGeneratorSchema(endpoint, type, annotated.value())); + } + if (annotated.value().length > 1) { // oneOf type + return toProperty.apply(extractSchema(endpoint, type, annotated.value())); + } } if (config.ignoreTypeAs) { return toProperty.apply(extractTypeSchema(endpoint, type)); @@ -874,9 +877,6 @@ private static Class getSubstitutedType(Api.Endpoint endpoint, Class type) if (type == OpenApi.EntityType[].class && endpoint.getEntityType() != null) { return Array.newInstance(endpoint.getEntityType(), 0).getClass(); } - if (type == WebMessageResponse.class) { - return WebMessage.class; - } return type; } diff --git a/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/openapi/DirectType.java b/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/openapi/DirectType.java index d8fd08c5c204..e78275613a74 100644 --- a/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/openapi/DirectType.java +++ b/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/openapi/DirectType.java @@ -72,7 +72,6 @@ import org.hisp.dhis.tracker.export.FileResourceStream; import org.hisp.dhis.webapi.webdomain.EndDateTime; import org.hisp.dhis.webapi.webdomain.StartDateTime; -import org.hisp.dhis.webmessage.WebMessageResponse; import org.intellij.lang.annotations.Language; import org.locationtech.jts.geom.Geometry; import org.springframework.core.io.InputStreamResource; @@ -254,7 +253,6 @@ private static void share(Class source) { oneOf(JsonDate.class, schema -> schema.type("string").format("date-time")); oneOf(Geometry.class, schema -> schema.type("object")); - oneOf(WebMessageResponse.class, schema -> schema.type("object")); oneOf(JobParameters.class, schema -> schema.type("object")); } diff --git a/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/openapi/Property.java b/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/openapi/Property.java index b1ec324dd942..7a1fb520746a 100644 --- a/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/openapi/Property.java +++ b/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/openapi/Property.java @@ -70,6 +70,7 @@ @Value @AllArgsConstructor(access = AccessLevel.PRIVATE) class Property { + private static final Map, List> PROPERTIES = new ConcurrentHashMap<>(); @Nonnull String name; @@ -225,7 +226,8 @@ private static Type getType(AnnotatedElement source, Type type) { if (type instanceof Class && ((Class) type).isAnnotationPresent(OpenApi.Property.class) && ((Class) type).getAnnotation(OpenApi.Property.class).value().length > 0) { - // TODO this does not allow oneOf types for Property annotations ;( + // Note: this does not support oneOf directly but the annotation is checked again + // then properties are converted to an Api.Schema return ((Class) type).getAnnotation(OpenApi.Property.class).value()[0]; } return type;