Skip to content

Commit

Permalink
fix: Set and get correct page number of records. (#27)
Browse files Browse the repository at this point in the history
* fix: Set and get correct page number of records.

* change other pageNumner implementatios.
  • Loading branch information
EdwinBetanc0urt authored Jun 17, 2022
1 parent 044c4ab commit 9eedab3
Show file tree
Hide file tree
Showing 10 changed files with 42 additions and 39 deletions.
5 changes: 4 additions & 1 deletion src/main/java/org/spin/base/util/RecordUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,15 @@ public static int getPageSize(int pageSize) {
* @return
*/
public static int getPageNumber(String sessionUuid, String pageToken) {
int page = 0;
int page = 1;
String pagePrefix = getPagePrefix(sessionUuid);
if(!Util.isEmpty(pageToken)) {
if(pageToken.startsWith(pagePrefix)) {
try {
page = Integer.parseInt(pageToken.replace(pagePrefix, ""));
if (page < 1) {
page = 1;
}
} catch (Exception e) {
//
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ private ListRolesResponse.Builder convertRolesList(ListRolesRequest request) {
String nexPageToken = null;
int pageNumber = RecordUtil.getPageNumber(request.getSessionUuid(), request.getPageToken());
int limit = RecordUtil.getPageSize(request.getPageSize());
int offset = pageNumber * RecordUtil.getPageSize(request.getPageSize());
int offset = (pageNumber - 1) * RecordUtil.getPageSize(request.getPageSize());
Query query = new Query(Env.getCtx(), I_AD_Role.Table_Name,
"EXISTS(SELECT 1 FROM AD_User_Roles ur WHERE ur.AD_Role_ID = AD_Role.AD_Role_ID AND ur.AD_User_ID = ?)", null)
.setParameters(session.getCreatedBy());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,7 @@ private ListEntitiesResponse.Builder convertEntitiesList(Properties context, Lis
String nexPageToken = null;
int pageNumber = RecordUtil.getPageNumber(request.getClientRequest().getSessionUuid(), request.getPageToken());
int limit = RecordUtil.getPageSize(request.getPageSize());
int offset = pageNumber * RecordUtil.getPageSize(request.getPageSize());
int offset = (pageNumber - 1) * RecordUtil.getPageSize(request.getPageSize());
int count = 0;
ListEntitiesResponse.Builder builder = ListEntitiesResponse.newBuilder();
//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ private ListBusinessPartnersResponse.Builder getBusinessPartnerList(ListBusiness
ListBusinessPartnersResponse.Builder builder = ListBusinessPartnersResponse.newBuilder();
String nexPageToken = null;
int pageNumber = RecordUtil.getPageNumber(request.getClientRequest().getSessionUuid(), request.getPageToken());
int offset = pageNumber * RecordUtil.getPageSize(request.getPageSize());
int offset = (pageNumber - 1) * RecordUtil.getPageSize(request.getPageSize());
int limit = (pageNumber + 1) * RecordUtil.getPageSize(request.getPageSize());
// Get business partner list
// Dynamic where clause
Expand Down Expand Up @@ -764,7 +764,7 @@ private ListOrganizationsResponse.Builder convertOrganizationsList(ListOrganizat
// Get page and count
String nexPageToken = null;
int pageNumber = RecordUtil.getPageNumber(request.getClientRequest().getSessionUuid(), request.getPageToken());
int offset = pageNumber * RecordUtil.getPageSize(request.getPageSize());
int offset = (pageNumber - 1) * RecordUtil.getPageSize(request.getPageSize());
int limit = (pageNumber + 1) * RecordUtil.getPageSize(request.getPageSize());
Query query = new Query(Env.getCtx(), I_AD_Org.Table_Name, whereClause, null)
.setParameters(parameters)
Expand Down Expand Up @@ -798,7 +798,7 @@ private ListWarehousesResponse.Builder convertWarehousesList(ListWarehousesReque
// Get page and count
String nexPageToken = null;
int pageNumber = RecordUtil.getPageNumber(request.getClientRequest().getSessionUuid(), request.getPageToken());
int offset = pageNumber * RecordUtil.getPageSize(request.getPageSize());
int offset = (pageNumber - 1) * RecordUtil.getPageSize(request.getPageSize());
int limit = (pageNumber + 1) * RecordUtil.getPageSize(request.getPageSize());
int id = request.getOrganizationId();
if(id <= 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ private ListWorkflowLogsResponse.Builder convertWorkflowLogs(ListWorkflowLogsReq
String nexPageToken = null;
int pageNumber = RecordUtil.getPageNumber(request.getClientRequest().getSessionUuid(), request.getPageToken());
int limit = RecordUtil.getPageSize(request.getPageSize());
int offset = pageNumber * RecordUtil.getPageSize(request.getPageSize());
int offset = (pageNumber - 1) * RecordUtil.getPageSize(request.getPageSize());
Query query = new Query(Env.getCtx(), I_AD_WF_Process.Table_Name, whereClause.toString(), null)
.setParameters(parameters);
int count = query.count();
Expand Down Expand Up @@ -405,7 +405,7 @@ private ListEntityLogsResponse.Builder convertEntityLogs(ListEntityLogsRequest r
String nexPageToken = null;
int pageNumber = RecordUtil.getPageNumber(request.getClientRequest().getSessionUuid(), request.getPageToken());
int limit = RecordUtil.getPageSize(request.getPageSize());
int offset = pageNumber * RecordUtil.getPageSize(request.getPageSize());
int offset = (pageNumber - 1) * RecordUtil.getPageSize(request.getPageSize());
Query query = new Query(Env.getCtx(), I_AD_ChangeLog.Table_Name, whereClause.toString(), null)
.setParameters(parameters);
int count = query.count();
Expand Down Expand Up @@ -867,7 +867,7 @@ private ListChatEntriesResponse.Builder convertChatEntries(ListChatEntriesReques
String nexPageToken = null;
int pageNumber = RecordUtil.getPageNumber(request.getClientRequest().getSessionUuid(), request.getPageToken());
int limit = RecordUtil.getPageSize(request.getPageSize());
int offset = pageNumber * RecordUtil.getPageSize(request.getPageSize());
int offset = (pageNumber - 1) * RecordUtil.getPageSize(request.getPageSize());
int id = request.getId();
if(id <= 0) {
id = RecordUtil.getIdFromUuid(I_CM_Chat.Table_Name, request.getUuid(), null);
Expand Down Expand Up @@ -929,7 +929,7 @@ private ListEntityChatsResponse.Builder convertEntityChats(ListEntityChatsReques
String nexPageToken = null;
int pageNumber = RecordUtil.getPageNumber(request.getClientRequest().getSessionUuid(), request.getPageToken());
int limit = RecordUtil.getPageSize(request.getPageSize());
int offset = pageNumber * RecordUtil.getPageSize(request.getPageSize());
int offset = (pageNumber - 1) * RecordUtil.getPageSize(request.getPageSize());
Query query = new Query(Env.getCtx(), I_CM_Chat.Table_Name, whereClause.toString(), null)
.setParameters(parameters);
int count = query.count();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1212,7 +1212,7 @@ public void listCustomerBankAccounts(ListCustomerBankAccountsRequest request, St
String nexPageToken = null;
int pageNumber = RecordUtil.getPageNumber(request.getClientRequest().getSessionUuid(), request.getPageToken());
int limit = RecordUtil.getPageSize(request.getPageSize());
int offset = pageNumber * RecordUtil.getPageSize(request.getPageSize());
int offset = (pageNumber - 1) * RecordUtil.getPageSize(request.getPageSize());
// Dynamic where clause
// Get Product list
Query query = new Query(Env.getCtx(), I_C_BP_BankAccount.Table_Name, I_C_BP_BankAccount.COLUMNNAME_C_BPartner_ID + " = ?", null)
Expand Down Expand Up @@ -1648,7 +1648,7 @@ private ListAvailableSellersResponse.Builder listAvailableSellers(ListAvailableS
String nexPageToken = null;
int pageNumber = RecordUtil.getPageNumber(request.getClientRequest().getSessionUuid(), request.getPageToken());
int limit = RecordUtil.getPageSize(request.getPageSize());
int offset = pageNumber * RecordUtil.getPageSize(request.getPageSize());
int offset = (pageNumber - 1) * RecordUtil.getPageSize(request.getPageSize());
int posId = RecordUtil.getIdFromUuid(I_C_POS.Table_Name, request.getPosUuid(), null);
//
StringBuffer whereClause = new StringBuffer();
Expand Down Expand Up @@ -1798,7 +1798,7 @@ private ListCashSummaryMovementsResponse.Builder listCashSummaryMovements(ListCa
String nexPageToken = null;
int pageNumber = RecordUtil.getPageNumber(request.getClientRequest().getSessionUuid(), request.getPageToken());
int limit = RecordUtil.getPageSize(request.getPageSize());
int offset = pageNumber * RecordUtil.getPageSize(request.getPageSize());
int offset = (pageNumber - 1) * RecordUtil.getPageSize(request.getPageSize());
int count = 0;
try {
// Get Bank statement
Expand Down Expand Up @@ -2183,7 +2183,7 @@ private ListShipmentLinesResponse.Builder listShipmentLines(ListShipmentLinesReq
String nexPageToken = null;
int pageNumber = RecordUtil.getPageNumber(request.getClientRequest().getSessionUuid(), request.getPageToken());
int limit = RecordUtil.getPageSize(request.getPageSize());
int offset = pageNumber * RecordUtil.getPageSize(request.getPageSize());
int offset = (pageNumber - 1) * RecordUtil.getPageSize(request.getPageSize());
int shipmentId = RecordUtil.getIdFromUuid(I_M_InOut.Table_Name, request.getShipmentUuid(), null);
// Get Product list
Query query = new Query(Env.getCtx(), I_M_InOutLine.Table_Name, I_M_InOutLine.COLUMNNAME_M_InOut_ID + " = ?", null)
Expand Down Expand Up @@ -2225,7 +2225,7 @@ private ListPaymentReferencesResponse.Builder listPaymentReferencesLines(ListPay
String nexPageToken = null;
int pageNumber = RecordUtil.getPageNumber(request.getClientRequest().getSessionUuid(), request.getPageToken());
int limit = RecordUtil.getPageSize(request.getPageSize());
int offset = pageNumber * RecordUtil.getPageSize(request.getPageSize());
int offset = (pageNumber - 1) * RecordUtil.getPageSize(request.getPageSize());
List<Object> parameters = new ArrayList<Object>();
StringBuffer whereClause = new StringBuffer("IsPaid = 'N' AND Processed = 'N'");
if(!Util.isEmpty(request.getOrderUuid())) {
Expand Down Expand Up @@ -2921,7 +2921,7 @@ private ListAvailableWarehousesResponse.Builder listWarehouses(ListAvailableWare
String nexPageToken = null;
int pageNumber = RecordUtil.getPageNumber(request.getClientRequest().getSessionUuid(), request.getPageToken());
int limit = RecordUtil.getPageSize(request.getPageSize());
int offset = pageNumber * RecordUtil.getPageSize(request.getPageSize());
int offset = (pageNumber - 1) * RecordUtil.getPageSize(request.getPageSize());
// Aisle Seller
int posId = RecordUtil.getIdFromUuid(I_C_POS.Table_Name, request.getPosUuid(), null);
// Get Product list
Expand Down Expand Up @@ -2971,7 +2971,7 @@ private ListAvailablePriceListResponse.Builder listPriceList(ListAvailablePriceL
String nexPageToken = null;
int pageNumber = RecordUtil.getPageNumber(request.getClientRequest().getSessionUuid(), request.getPageToken());
int limit = RecordUtil.getPageSize(request.getPageSize());
int offset = pageNumber * RecordUtil.getPageSize(request.getPageSize());
int offset = (pageNumber - 1) * RecordUtil.getPageSize(request.getPageSize());
// Dynamic where clause
// Aisle Seller
int posId = RecordUtil.getIdFromUuid(I_C_POS.Table_Name, request.getPosUuid(), null);
Expand Down Expand Up @@ -3028,7 +3028,7 @@ private ListAvailablePaymentMethodsResponse.Builder listPaymentMethods(ListAvail
String nexPageToken = null;
int pageNumber = RecordUtil.getPageNumber(request.getClientRequest().getSessionUuid(), request.getPageToken());
int limit = RecordUtil.getPageSize(request.getPageSize());
int offset = pageNumber * RecordUtil.getPageSize(request.getPageSize());
int offset = (pageNumber - 1) * RecordUtil.getPageSize(request.getPageSize());
// Dynamic where clause
// Aisle Seller
int posId = RecordUtil.getIdFromUuid(I_C_POS.Table_Name, request.getPosUuid(), null);
Expand Down Expand Up @@ -3092,7 +3092,7 @@ private ListAvailableDocumentTypesResponse.Builder listDocumentTypes(ListAvailab
String nexPageToken = null;
int pageNumber = RecordUtil.getPageNumber(request.getClientRequest().getSessionUuid(), request.getPageToken());
int limit = RecordUtil.getPageSize(request.getPageSize());
int offset = pageNumber * RecordUtil.getPageSize(request.getPageSize());
int offset = (pageNumber - 1) * RecordUtil.getPageSize(request.getPageSize());
// Dynamic where clause
// Aisle Seller
int posId = RecordUtil.getIdFromUuid(I_C_POS.Table_Name, request.getPosUuid(), null);
Expand Down Expand Up @@ -3137,7 +3137,7 @@ private ListAvailableCurrenciesResponse.Builder listCurrencies(ListAvailableCurr
String nexPageToken = null;
int pageNumber = RecordUtil.getPageNumber(request.getClientRequest().getSessionUuid(), request.getPageToken());
int limit = RecordUtil.getPageSize(request.getPageSize());
int offset = pageNumber * RecordUtil.getPageSize(request.getPageSize());
int offset = (pageNumber - 1) * RecordUtil.getPageSize(request.getPageSize());
// Dynamic where clause
String whereClause = "EXISTS(SELECT 1 FROM C_Conversion_Rate cr "
+ "WHERE (cr.C_Currency_ID = C_Currency.C_Currency_ID OR cr.C_Currency_ID_To = C_Currency.C_Currency_ID) "
Expand Down Expand Up @@ -3709,7 +3709,7 @@ private ListOrdersResponse.Builder listOrders(ListOrdersRequest request) {
String nexPageToken = null;
int pageNumber = RecordUtil.getPageNumber(request.getClientRequest().getSessionUuid(), request.getPageToken());
int limit = RecordUtil.getPageSize(request.getPageSize());
int offset = pageNumber * RecordUtil.getPageSize(request.getPageSize());
int offset = (pageNumber - 1) * RecordUtil.getPageSize(request.getPageSize());
// Dynamic where clause
int posId = RecordUtil.getIdFromUuid(I_C_POS.Table_Name, request.getPosUuid(), null);
int salesRepresentativeId = RecordUtil.getIdFromUuid(I_AD_User.Table_Name, request.getSalesRepresentativeUuid(), null);
Expand Down Expand Up @@ -3830,7 +3830,7 @@ private ListPaymentsResponse.Builder listPayments(ListPaymentsRequest request) {
String nexPageToken = null;
int pageNumber = RecordUtil.getPageNumber(request.getClientRequest().getSessionUuid(), request.getPageToken());
int limit = RecordUtil.getPageSize(request.getPageSize());
int offset = pageNumber * RecordUtil.getPageSize(request.getPageSize());
int offset = (pageNumber - 1) * RecordUtil.getPageSize(request.getPageSize());
// Dynamic where clause
StringBuffer whereClause = new StringBuffer();
// Parameters
Expand Down Expand Up @@ -3897,7 +3897,7 @@ private ListOrderLinesResponse.Builder listOrderLines(ListOrderLinesRequest requ
String nexPageToken = null;
int pageNumber = RecordUtil.getPageNumber(request.getClientRequest().getSessionUuid(), request.getPageToken());
int limit = RecordUtil.getPageSize(request.getPageSize());
int offset = pageNumber * RecordUtil.getPageSize(request.getPageSize());
int offset = (pageNumber - 1) * RecordUtil.getPageSize(request.getPageSize());
StringBuffer whereClause = new StringBuffer(I_C_OrderLine.COLUMNNAME_C_Order_ID + " = ?");
List<Object> parameters = new ArrayList<>();
parameters.add(orderId);
Expand Down Expand Up @@ -4756,7 +4756,7 @@ private ListPointOfSalesResponse.Builder convertPointOfSalesList(ListPointOfSale
String nexPageToken = null;
int pageNumber = RecordUtil.getPageNumber(request.getClientRequest().getSessionUuid(), request.getPageToken());
int limit = RecordUtil.getPageSize(request.getPageSize());
int offset = pageNumber * RecordUtil.getPageSize(request.getPageSize());
int offset = (pageNumber - 1) * RecordUtil.getPageSize(request.getPageSize());
// Get POS List
boolean isAppliedNewFeaturesPOS = M_Element.get(Env.getCtx(), "IsSharedPOS") != null && M_Element.get(Env.getCtx(), "IsAllowsAllocateSeller") != null;
StringBuffer whereClause = new StringBuffer("SalesRep_ID = ? OR EXISTS(SELECT 1 FROM AD_User u WHERE u.AD_User_ID = ? AND IsPOSManager = 'Y')");
Expand Down Expand Up @@ -5572,7 +5572,7 @@ private ListProductPriceResponse.Builder getProductPriceList(ListProductPriceReq
String nexPageToken = null;
int pageNumber = RecordUtil.getPageNumber(request.getClientRequest().getSessionUuid(), request.getPageToken());
int limit = RecordUtil.getPageSize(request.getPageSize());
int offset = pageNumber * RecordUtil.getPageSize(request.getPageSize());
int offset = (pageNumber - 1) * RecordUtil.getPageSize(request.getPageSize());
// Dynamic where clause
StringBuffer whereClause = new StringBuffer();
// Parameters
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/org/spin/grpc/service/UpdateImplementation.java
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ private ListStepsResponse.Builder convertStepsList(ListStepsRequest request) {
String nexPageToken = null;
int pageNumber = RecordUtil.getPageNumber("page-token", request.getPageToken());
int limit = RecordUtil.getPageSize(request.getPageSize());
int offset = pageNumber * RecordUtil.getPageSize(request.getPageSize());
int offset = (pageNumber - 1) * RecordUtil.getPageSize(request.getPageSize());
// Get POS List
StringBuffer whereClause = new StringBuffer("AD_Migration_ID = ?");
List<Object> parameters = new ArrayList<>();
Expand Down Expand Up @@ -230,7 +230,7 @@ private ListUpdatesResponse.Builder convertUpdatesList(ListUpdatesRequest reques
String nexPageToken = null;
int pageNumber = RecordUtil.getPageNumber("page-token", request.getPageToken());
int limit = RecordUtil.getPageSize(request.getPageSize());
int offset = pageNumber * RecordUtil.getPageSize(request.getPageSize());
int offset = (pageNumber - 1) * RecordUtil.getPageSize(request.getPageSize());
// Get POS List
StringBuffer whereClause = new StringBuffer("EntityType = ?");
List<Object> parameters = new ArrayList<>();
Expand Down Expand Up @@ -303,7 +303,7 @@ private ListPackagesResponse.Builder convertPackagesList(ListPackagesRequest req
String nexPageToken = null;
int pageNumber = RecordUtil.getPageNumber("page-token", request.getPageToken());
int limit = RecordUtil.getPageSize(request.getPageSize());
int offset = pageNumber * RecordUtil.getPageSize(request.getPageSize());
int offset = (pageNumber - 1) * RecordUtil.getPageSize(request.getPageSize());
// Get POS List
String whereClause = null;
List<Object> parameters = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1039,7 +1039,7 @@ private ListTabEntitiesResponse.Builder convertEntitiesList(Properties context,
String nexPageToken = null;
int pageNumber = RecordUtil.getPageNumber(request.getClientRequest().getSessionUuid(), request.getPageToken());
int limit = RecordUtil.getPageSize(request.getPageSize());
int offset = pageNumber * RecordUtil.getPageSize(request.getPageSize());
int offset = (pageNumber - 1) * RecordUtil.getPageSize(request.getPageSize());
int count = 0;
ListTabEntitiesResponse.Builder builder = ListTabEntitiesResponse.newBuilder();
//
Expand Down Expand Up @@ -2665,7 +2665,7 @@ private ListLookupItemsResponse.Builder convertLookupItemsList(ListLookupItemsRe
String nexPageToken = null;
int pageNumber = RecordUtil.getPageNumber(request.getClientRequest().getSessionUuid(), request.getPageToken());
int limit = RecordUtil.getPageSize(request.getPageSize());
int offset = pageNumber * RecordUtil.getPageSize(request.getPageSize());
int offset = (pageNumber - 1) * RecordUtil.getPageSize(request.getPageSize());
int count = 0;
// Count records
count = RecordUtil.countRecords(sql, reference.TableName, parameters);
Expand Down Expand Up @@ -2962,7 +2962,7 @@ private ListBrowserItemsResponse.Builder convertBrowserList(ListBrowserItemsRequ
}
int pageNumber = RecordUtil.getPageNumber(request.getClientRequest().getSessionUuid(), request.getPageToken());
int limit = RecordUtil.getPageSize(request.getPageSize());
int offset = pageNumber * RecordUtil.getPageSize(request.getPageSize());
int offset = (pageNumber - 1) * RecordUtil.getPageSize(request.getPageSize());
// Add Row Number
parsedSQL = RecordUtil.getQueryWithLimit(parsedSQL, limit, offset);
// Add Order By
Expand Down
Loading

0 comments on commit 9eedab3

Please sign in to comment.