diff --git a/api-docs/apiLive.htm b/api-docs/apiLive.htm index fba6976dc..ab6eed3ed 100644 --- a/api-docs/apiLive.htm +++ b/api-docs/apiLive.htm @@ -10657,8 +10657,8 @@ Content-Type: application/json
Get a list of audits that match the criteria supplied, - and are within the requestors' data scope.
+Get a 200 list of audits that match the criteria supplied and sorted by audit id in descending order, + and are within the requestors' data scope. Also it supports pagination and sorting
Example Requests:
@@ -10842,6 +10871,65 @@ GET https://DomainName/api/v1/audits },... ] +
+GET https://DomainName/api/v1/audits?paged=true&limit=5
+
+
+{
+ "totalFilteredRecords": 30,
+ "pageItems": [
+ {
+ "id": 671,
+ "actionName": "PERMISSIONS",
+ "entityName": "ROLE",
+ "resourceId": 6,
+ "maker": "keithwoodlock",
+ "madeOnDate": 1365014262000,
+ "processingResult": "processed"
+ },
+ {
+ "id": 670,
+ "actionName": "CREATE",
+ "entityName": "CLIENTNOTE",
+ "resourceId": 287,
+ "maker": "keithwoodlock",
+ "madeOnDate": 1365014204000,
+ "processingResult": "awaiting.approval",
+ "officeName": "my office",
+ "clientName": "gg ggg"
+ },
+ {
+ "id": 668,
+ "actionName": "UPDATE",
+ "entityName": "PERMISSION",
+ "maker": "keithwoodlock",
+ "madeOnDate": 1365014186000,
+ "processingResult": "processed"
+ },
+ {
+ "id": 667,
+ "actionName": "CREATE",
+ "entityName": "CLIENTNOTE",
+ "resourceId": 286,
+ "maker": "keithwoodlock",
+ "madeOnDate": 1365014169000,
+ "processingResult": "processed",
+ "officeName": "my office name",
+ "clientName": "gg ggg"
+ },
+ {
+ "id": 666,
+ "actionName": "CREATE",
+ "entityName": "CLIENT",
+ "resourceId": 363,
+ "maker": "keithwoodlock",
+ "madeOnDate": 1365012843000,
+ "processingResult": "awaiting.approval",
+ "officeName": "my office name"
+ }
+ ]
+}
+
+ * Immutable data object representing pagination parameter values. + *
+ */ +public class PaginationParameters { + + private final boolean paged; + private final Integer offset; + private final Integer limit; + private final String orderBy; + private final String sortOrder; + + public static PaginationParameters instance (Boolean paged, Integer offset, Integer limit, String orderBy, String sortOrder){ + if( null == paged) { + paged = false; + } + + final Integer maxLimitAllowed = getCheckedLimit(limit); + + return new PaginationParameters(paged, offset, maxLimitAllowed, orderBy, sortOrder); + } + + private PaginationParameters(boolean paged, Integer offset, Integer limit, String orderBy, String sortOrder) { + this.paged = paged; + this.offset = offset; + this.limit = limit; + this.orderBy = orderBy; + this.sortOrder = sortOrder; + } + + public static Integer getCheckedLimit(final Integer limit) { + + final Integer maxLimitAllowed = 200; + // default to max limit first off + Integer checkedLimit = maxLimitAllowed; + + if (limit != null && limit > 0) { + checkedLimit = limit; + } else if (limit != null) { + // unlimited case: limit provided and 0 or less + checkedLimit = null; + } + + return checkedLimit; + } + + public boolean isPaged() { + return this.paged; + } + + public Integer getOffset() { + return this.offset; + } + + public Integer getLimit() { + return this.limit; + } + + public String getOrderBy() { + return this.orderBy; + } + + public String getSortOrder() { + return this.sortOrder; + } + + public boolean isOrderByRequested() { + return StringUtils.isNotBlank(this.orderBy); + } + + public boolean isSortOrderProvided() { + return StringUtils.isNotBlank(this.sortOrder); + } + + public boolean isLimited() { + return this.limit != null && this.limit.intValue() > 0; + } + + public boolean isOffset() { + return this.offset != null; + } + + public String orderBySql(){ + final StringBuffer sql = new StringBuffer(); + + if (this.isOrderByRequested()) { + sql.append(" order by ").append(this.getOrderBy()); + if (this.isSortOrderProvided()) { + sql.append(' ').append(this.getSortOrder()); + } + } + return sql.toString(); + } + + public String limitSql(){ + final StringBuffer sql = new StringBuffer(); + if (this.isLimited()) { + sql.append(" limit ").append(this.getLimit()); + if (this.isOffset()) { + sql.append(" offset ").append(this.getOffset()); + } + } + return sql.toString(); + } +} \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/core/data/PaginationParametersDataValidator.java b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/core/data/PaginationParametersDataValidator.java new file mode 100644 index 000000000..c6f086acf --- /dev/null +++ b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/core/data/PaginationParametersDataValidator.java @@ -0,0 +1,44 @@ +/** + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. + */ +package org.mifosplatform.infrastructure.core.data; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import org.mifosplatform.infrastructure.core.exception.PlatformApiDataValidationException; +import org.springframework.stereotype.Component; + +@Component +public class PaginationParametersDataValidator { + public static Set