diff --git a/src/main/java/org/hisp/dhis/model/Pager.java b/src/main/java/org/hisp/dhis/model/Pager.java index bd59efdc..b3188e68 100644 --- a/src/main/java/org/hisp/dhis/model/Pager.java +++ b/src/main/java/org/hisp/dhis/model/Pager.java @@ -45,4 +45,17 @@ public class Pager { @JsonProperty private Long total; @JsonProperty private String nextPage; + + /** + * Constructor. + * + * @param page the page number. + * @param pageSize the page size. + */ + public Pager(Integer page, Integer pageSize) { + this.page = page; + this.pageSize = pageSize; + this.pageCount = -1L; + this.total = -1L; + } } diff --git a/src/main/java/org/hisp/dhis/response/PagedResponse.java b/src/main/java/org/hisp/dhis/response/PagedResponse.java new file mode 100644 index 00000000..5fa6dcac --- /dev/null +++ b/src/main/java/org/hisp/dhis/response/PagedResponse.java @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2004-2026, 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.response; + +import com.fasterxml.jackson.annotation.JsonProperty; +import java.util.List; +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import org.hisp.dhis.model.Pager; + +/** Response containing a paged list of objects. */ +@Getter +@RequiredArgsConstructor +public class PagedResponse { + /** Paging information. */ + @JsonProperty private final Pager pager; + + /** List of objects. */ + @JsonProperty private final List objects; +} diff --git a/src/main/java/org/hisp/dhis/response/data/DataResponse.java b/src/main/java/org/hisp/dhis/response/data/DataResponse.java index 241aba57..84242af1 100644 --- a/src/main/java/org/hisp/dhis/response/data/DataResponse.java +++ b/src/main/java/org/hisp/dhis/response/data/DataResponse.java @@ -30,6 +30,7 @@ import static org.hisp.dhis.util.TextUtils.newToStringBuilder; import com.fasterxml.jackson.annotation.JsonProperty; +import java.util.Map; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; @@ -61,4 +62,14 @@ public DataResponse(Status status, HttpStatus httpStatus, String message, Object public String toString() { return newToStringBuilder(this, super.toString()).append("data", data).toString(); } + + /** + * Creates a map with a single entry where the key is "id" and the value is the provided value. + * + * @param id the identifier value. + * @return a map containing the "id" entry. + */ + public static Map getIdMap(String id) { + return Map.of("id", id); + } }