From 23b079f4a66a5dfa0774c5db2972524ac283a5b3 Mon Sep 17 00:00:00 2001 From: Keith Woodlock Date: Fri, 3 May 2013 16:18:14 +0100 Subject: [PATCH] MIFOSX-322: update apidocs for client pagination and sorting. --- api-docs/apiLive.htm | 146 +++++++++++++----- .../ClientReadPlatformServiceImpl.java | 8 +- .../group/service/SearchParameters.java | 6 +- 3 files changed, 117 insertions(+), 43 deletions(-) diff --git a/api-docs/apiLive.htm b/api-docs/apiLive.htm index 1c8e63e87..a8c196cd7 100644 --- a/api-docs/apiLive.htm +++ b/api-docs/apiLive.htm @@ -1908,7 +1908,7 @@ Request Body:  
-

Activate a Client

+

Activate a Client

Clients can be created in a Pending state. This API exists to enable client activation (for when a client becomes approved member of microfinance institue).

If the client happens to be alrady active this API will result in an error.

@@ -1983,6 +1983,74 @@ GET https://DomainName/api/v1/clients/{clientId}

List Clients

+

The list capability of clients can support pagination and sorting.

+
Optional Arguments
+
+
offset
+
+ Integer optional, defaults to 0 +
+
Indicates from what result to start from.
+ +
limit
+
+ Integer optional, defaults to 200 +
+
Restricts the size of results returned.
+ +
orderBy
+
+ String optional, one of displayName, accountNo, officeId, officeName +
+
Orders the results by the field indicated.
+ +
sortBy
+
+ String optional, one of ASC, DESC +
+
Indicates what way to order results if orderBy is used.
+ +
officeId
+
+ Integer optional +
+
Provides ability to restrict list of clients returned based on the office there associated with.
+
underHierarchy
+
+ String optional +
+
Use the office hierarchy string to return all clients under a given hierarchy.
+ +
displayName
+
+ String optional +
+
Use displayName of clients to restrict results.
+ +
firstName
+
+ String optional +
+
Use firstName of clients to restrict results.
+ +
lastName
+
+ String optional +
+
Use lastName of clients to restrict results.
+ +
externalId
+
+ String optional +
+
Use externalId of clients to restrict results.
+ +
sqlSearch
+
+ String optional +
+
Use an sql fragment valid for the underlying client schema to filter results. e.g. display_name like %K%
+

Example Requests:

clients

@@ -1994,46 +2062,44 @@ GET https://DomainName/api/v1/clients/{clientId} GET https://DomainName/api/v1/clients -[ - { - "id": 2, - "accountNo": "000000002", - "status": { - "id": 300, - "code": "clientStatusType.active", - "value": "Active" +{ + "totalFilteredRecords": 2, + "pageItems": [ + { + "id": 1, + "accountNo": "000000001", + "status": { + "id": 300, + "code": "clientStatusType.active", + "value": "Active" + }, + "active": true, + "activationDate": [ + 2013, + 3, + 1 + ], + "fullname": "Small shop", + "displayName": "Small shop", + "officeId": 1, + "officeName": "Head Office" }, - "activationDate": [ - 2009, - 3, - 4 - ], - "fullname": "Client of group", - "displayName": "Client of group", - "officeId": 1, - "officeName": "Head Office" - }, - { - "id": 1, - "accountNo": "000000001", - "externalId": "786YYH7", - "status": { - "id": 300, - "code": "clientStatusType.active", - "value": "Active" - }, - "activationDate": [ - 2009, - 3, - 4 - ], - "firstname": "Petra", - "lastname": "Yton", - "displayName": "Petra Yton", - "officeId": 1, - "officeName": "Head Office" - } -] + { + "id": 2, + "accountNo": "000000002", + "status": { + "id": 100, + "code": "clientStatusType.pending", + "value": "Pending" + }, + "active": false, + "fullname": "Home Farm Produce", + "displayName": "Home Farm Produce", + "officeId": 1, + "officeName": "Head Office" + } + ] +}
diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/client/service/ClientReadPlatformServiceImpl.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/client/service/ClientReadPlatformServiceImpl.java index d28cab6b5..12af6a2b7 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/client/service/ClientReadPlatformServiceImpl.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/client/service/ClientReadPlatformServiceImpl.java @@ -94,7 +94,11 @@ public class ClientReadPlatformServiceImpl implements ClientReadPlatformService // have to scan entire database table. // sql += " order by c.display_name ASC, c.account_no ASC"; if (searchParameters.isOrderByRequested()) { - sqlBuilder.append(" order by ").append(searchParameters.getOrderBy()).append(' ').append(searchParameters.getSortOrder()); + sqlBuilder.append(" order by ").append(searchParameters.getOrderBy()); + + if (searchParameters.isSortOrderProvided()) { + sqlBuilder.append(' ').append(searchParameters.getSortOrder()); + } } if (searchParameters.isLimited()) { @@ -130,7 +134,7 @@ public class ClientReadPlatformServiceImpl implements ClientReadPlatformService } if (externalId != null) { - extraCriteria += " and external_id like " + ApiParameterHelper.sqlEncodeString(externalId); + extraCriteria += " and c.external_id like " + ApiParameterHelper.sqlEncodeString(externalId); } if (displayName != null) { diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/service/SearchParameters.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/service/SearchParameters.java index 69377816c..55662193b 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/service/SearchParameters.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/service/SearchParameters.java @@ -56,7 +56,11 @@ public final class SearchParameters { } public boolean isOrderByRequested() { - return StringUtils.isNotBlank(this.orderBy) && StringUtils.isNotBlank(this.sortOrder); + return StringUtils.isNotBlank(this.orderBy); + } + + public boolean isSortOrderProvided() { + return StringUtils.isNotBlank(this.sortOrder); } public String getSqlSearch() {