Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: OpenAPI - WebMessage response as oneOf schema [DHIS2-18251] #18858

Merged
merged 13 commits into from
Oct 21, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -223,6 +224,12 @@ public FlattenedDataIntegrityReport(Map<String, DataIntegrityDetails> detailsByN
DataIntegrityCheckType.PROGRAM_RULE_ACTIONS_WITHOUT_STAGE_ID.getName()));
}

@Nonnull
@Override
public Class<? extends WebMessageResponse> getResponseClassType() {
return FlattenedDataIntegrityReport.class;
}

private List<String> listOfDisplayNameOrUid(DataIntegrityDetails details) {
return details == null
? null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 <[email protected]>
*/
@JacksonXmlRootElement(localName = "importSummary", namespace = DxfNamespaces.DXF_2_0)
@OpenApi.Shared(name = "ImportTypesSummary")
public class ImportSummary {
private ImportCount importCount = new ImportCount();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -72,6 +73,12 @@ public GeoJsonImportReport(
this.totalConflictOccurrenceCount = totalConflictOccurrenceCount;
}

@Nonnull
@Override
public Class<? extends WebMessageResponse> getResponseClassType() {
return GeoJsonImportReport.class;
}

@JsonProperty
public ImportStatus getStatus() {
int ignored = importCount.getIgnored();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public enum ImportStatus {
WARNING(2),
ERROR(3);

private int order;
private final int order;

ImportStatus(int order) {
this.order = order;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 <[email protected]>
*/
@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<ImportSummary> importSummaries = new ArrayList<>();

public ImportSummaries() {}

@Nonnull
@Override
public Class<? extends WebMessageResponse> getResponseClassType() {
return ImportSummaries.class;
}

public void addImportSummaries(ImportSummaries importSummaries) {
importSummaries.getImportSummaries().forEach(this::addImportSummary);
}
Expand Down Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -91,6 +93,12 @@ public ImportSummary(ImportStatus status, String description, ImportCount import
this.importCount = importCount;
}

@Nonnull
@Override
public Class<? extends WebMessageResponse> getResponseClassType() {
return ImportSummary.class;
}

// -------------------------------------------------------------------------
// Logic
// -------------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<? extends WebMessageResponse> getResponseClassType() {
return MetadataSyncSummary.class;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
Expand All @@ -64,6 +60,12 @@ public JobConfigurationWebMessageResponse(JobConfiguration jobConfiguration) {
this.relativeNotifierEndpoint = "/api/system/tasks/" + this.jobType + "/" + this.id;
}

@Nonnull
@Override
public Class<? extends WebMessageResponse> getResponseClassType() {
return JobConfigurationWebMessageResponse.class;
}

@JacksonXmlProperty
@JsonProperty
public String getName() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 <[email protected]>
*/
public class ErrorReportsWebMessageResponse extends AbstractWebMessageResponse {
private List<ErrorReport> errorReports = new ArrayList<>();
@Setter
@Getter
@RequiredArgsConstructor
public class ErrorReportsWebMessageResponse implements WebMessageResponse {

public ErrorReportsWebMessageResponse(List<ErrorReport> errorReports) {
this.errorReports = errorReports;
private final List<ErrorReport> errorReports;

@Nonnull
@Override
public Class<? extends WebMessageResponse> getResponseClassType() {
return ErrorReportsWebMessageResponse.class;
}

@JsonProperty
Expand All @@ -55,8 +64,4 @@ public ErrorReportsWebMessageResponse(List<ErrorReport> errorReports) {
public List<ErrorReport> getErrorReports() {
return errorReports;
}

public void setErrorReports(List<ErrorReport> errorReports) {
this.errorReports = errorReports;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<? extends WebMessageResponse> getResponseClassType() {
return FileResourceWebMessageResponse.class;
}
}
Loading
Loading