From 672ea68a4ee294ef4c2e2bc6e301cfc51d654250 Mon Sep 17 00:00:00 2001 From: Rajithkonara Date: Mon, 10 Jul 2017 17:09:02 +0530 Subject: [PATCH 1/4] added offset and limit --- .../sandbox/service/PaymentService_v1_3.java | 6 +++++- .../PaymentListTransactionRequestWrapper.java | 19 +++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/dep-sandbox/src/main/java/com/wso2telco/services/dep/sandbox/service/PaymentService_v1_3.java b/dep-sandbox/src/main/java/com/wso2telco/services/dep/sandbox/service/PaymentService_v1_3.java index c8fb3bcc..85852b79 100644 --- a/dep-sandbox/src/main/java/com/wso2telco/services/dep/sandbox/service/PaymentService_v1_3.java +++ b/dep-sandbox/src/main/java/com/wso2telco/services/dep/sandbox/service/PaymentService_v1_3.java @@ -124,11 +124,15 @@ public Response makePayment( @ApiImplicitParam(name = "sandbox", value = "Authorization token", required = true, dataType = "string", paramType = "header")}) public Response getAttributeServices( @ApiParam(value = "endUserId", required = false) @PathParam("endUserId") String endUserId, + @ApiParam(value = "offset", required = false) @QueryParam("offset") String offSet, + @ApiParam(value = "limit", required = false) @QueryParam("limit") String limit, @Context HttpServletRequest request) { - LOG.debug("/{endUserId}/transactions invorked :" + endUserId); + LOG.debug("/{endUserId}/transactions invorked :" + endUserId + offSet + limit); PaymentListTransactionRequestWrapper requestDTO = new PaymentListTransactionRequestWrapper(); requestDTO.setHttpRequest(request); requestDTO.setEndUserId(endUserId); + requestDTO.setOffSet(offSet); + requestDTO.setLimit(limit); requestDTO.setRequestType(RequestType.PAYMENT); RequestHandleable handler = RequestBuilderFactory.getInstance(requestDTO); diff --git a/dep-sandbox/src/main/java/com/wso2telco/services/dep/sandbox/servicefactory/payment/PaymentListTransactionRequestWrapper.java b/dep-sandbox/src/main/java/com/wso2telco/services/dep/sandbox/servicefactory/payment/PaymentListTransactionRequestWrapper.java index 6a874112..a1dbea14 100644 --- a/dep-sandbox/src/main/java/com/wso2telco/services/dep/sandbox/servicefactory/payment/PaymentListTransactionRequestWrapper.java +++ b/dep-sandbox/src/main/java/com/wso2telco/services/dep/sandbox/servicefactory/payment/PaymentListTransactionRequestWrapper.java @@ -21,6 +21,10 @@ public class PaymentListTransactionRequestWrapper extends RequestDTO { private String endUserId; + private String offSet; + + private String limit; + public String getEndUserId() { return endUserId; } @@ -29,4 +33,19 @@ public void setEndUserId(String endUserId) { this.endUserId = endUserId; } + public String getOffSet() { + return offSet; + } + + public void setOffSet(String offSet) { + this.offSet = offSet; + } + + public String getLimit() { + return limit; + } + + public void setLimit(String limit) { + this.limit = limit; + } } From b32332aeb89dd17fa0de339506825ca76e60cbfa Mon Sep 17 00:00:00 2001 From: Rajithkonara Date: Mon, 10 Jul 2017 17:29:58 +0530 Subject: [PATCH 2/4] updated .gitignore --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index aec0e7e5..0db0034e 100644 --- a/.gitignore +++ b/.gitignore @@ -22,5 +22,5 @@ target *.ipr .idea log -dep-sanbox/log +dep-sanbox/log/ From 6c356a66d64737fcfe4098e32f282c04435e917d Mon Sep 17 00:00:00 2001 From: Rajithkonara Date: Mon, 10 Jul 2017 17:33:25 +0530 Subject: [PATCH 3/4] return requests with offset and limit --- .../services/dep/sandbox/dao/LoggingDAO.java | 4 +- .../dao/hibernate/HibernateLoggingDao.java | 80 +++++++++++++++++++ .../PaymentListTransactionRequestHandler.java | 19 ++++- 3 files changed, 98 insertions(+), 5 deletions(-) diff --git a/dep-sandbox/src/main/java/com/wso2telco/services/dep/sandbox/dao/LoggingDAO.java b/dep-sandbox/src/main/java/com/wso2telco/services/dep/sandbox/dao/LoggingDAO.java index 0f704260..0057b3b8 100644 --- a/dep-sandbox/src/main/java/com/wso2telco/services/dep/sandbox/dao/LoggingDAO.java +++ b/dep-sandbox/src/main/java/com/wso2telco/services/dep/sandbox/dao/LoggingDAO.java @@ -12,5 +12,7 @@ public interface LoggingDAO { public int saveMessageLog(MessageLog messageLog) throws Exception; public List getMessageLogs(int userid, List serviceNameIds, String reference, String value, Date startTimeStamp, Date endTimeStamp) throws Exception; - + + public List getResponseLists(int userid, List serviceNameIds, String reference, String value, Date startTimeStamp, Date endTimeStamp, int offSet, int limit) throws Exception; + } \ No newline at end of file diff --git a/dep-sandbox/src/main/java/com/wso2telco/services/dep/sandbox/dao/hibernate/HibernateLoggingDao.java b/dep-sandbox/src/main/java/com/wso2telco/services/dep/sandbox/dao/hibernate/HibernateLoggingDao.java index 6f1d0d1e..6406bcca 100644 --- a/dep-sandbox/src/main/java/com/wso2telco/services/dep/sandbox/dao/hibernate/HibernateLoggingDao.java +++ b/dep-sandbox/src/main/java/com/wso2telco/services/dep/sandbox/dao/hibernate/HibernateLoggingDao.java @@ -109,4 +109,84 @@ public List getMessageLogs(int userid, List serviceNameIds, } } + @Override + public List getResponseLists(int userid, List serviceNameIds, String ref, String val, Date startTimeStamp, Date endTimeStamp, int offSet, int limit) throws Exception { + Session session = getSession(); + Map parameterMap = new HashMap(); + List messageLogs = new ArrayList(); + String reference = CommonUtil.getNullOrTrimmedValue(ref); + String value = CommonUtil.getNullOrTrimmedValue(val); + try { + StringBuilder hqlQueryBuilder = new StringBuilder(); + hqlQueryBuilder.append("from MessageLog ml "); + hqlQueryBuilder.append("where 1=1 "); + + if(userid != 0){ + hqlQueryBuilder.append(" AND ml.userid = :id"); + parameterMap.put("id", userid); + + } + + if(serviceNameIds != null){ + hqlQueryBuilder.append(" AND ml.servicenameid in (:servicenameidList)"); + parameterMap.put("servicenameidList", serviceNameIds); + } + + if(reference != null && value != null){ + hqlQueryBuilder.append(" AND ml.reference = :reference AND ml.value = :value"); + parameterMap.put("reference", reference); + parameterMap.put("value", value); + } + + if(startTimeStamp != null && endTimeStamp != null){ + hqlQueryBuilder.append(" AND ml.messageTimestamp between :startTimeStamp and :endTimeStamp"); + parameterMap.put("startTimeStamp", startTimeStamp); + parameterMap.put("endTimeStamp", endTimeStamp); + + }else if(startTimeStamp != null){ + hqlQueryBuilder.append(" AND ml.messageTimestamp >= :startTimeStamp"); + parameterMap.put("startTimeStamp", startTimeStamp); + if(endTimeStamp != null){ + hqlQueryBuilder.append(" AND ml.messageTimestamp <= :endTimeStamp"); + parameterMap.put("endTimeStamp", endTimeStamp); + } + }else if(endTimeStamp != null){ + hqlQueryBuilder.append(" AND ml.messageTimestamp <= :endTimeStamp"); + parameterMap.put("endTimeStamp", endTimeStamp); + } + + Query query = session.createQuery(hqlQueryBuilder.toString()); + + if (offSet > 0) { + query.setFirstResult(offSet); + } + + if (limit > 0) { + query.setMaxResults(limit); + } + + Set> entrySet = parameterMap.entrySet(); + + for (Entry entry : entrySet) { + if(entry.getValue() instanceof List ){ + query.setParameterList(entry.getKey(), (List)entry.getValue()); + }else{ + query.setParameter(entry.getKey(), entry.getValue()); + } + + } + + messageLogs = (List) query.getResultList(); + + } catch (Exception ex) { + LOG.error("Error in getMessageLogs " , ex); + throw ex; + } + if (messageLogs==null){ + return Collections.emptyList(); + }else{ + return messageLogs; + } + } + } \ No newline at end of file diff --git a/dep-sandbox/src/main/java/com/wso2telco/services/dep/sandbox/servicefactory/payment/PaymentListTransactionRequestHandler.java b/dep-sandbox/src/main/java/com/wso2telco/services/dep/sandbox/servicefactory/payment/PaymentListTransactionRequestHandler.java index 1c45a484..f4fd27a3 100644 --- a/dep-sandbox/src/main/java/com/wso2telco/services/dep/sandbox/servicefactory/payment/PaymentListTransactionRequestHandler.java +++ b/dep-sandbox/src/main/java/com/wso2telco/services/dep/sandbox/servicefactory/payment/PaymentListTransactionRequestHandler.java @@ -74,10 +74,15 @@ protected List getAddress() { protected boolean validate(PaymentListTransactionRequestWrapper wrapperDTO) throws Exception { String endUserId = CommonUtil.getNullOrTrimmedValue(wrapperDTO.getEndUserId()); - + String offset = CommonUtil.getNullOrTrimmedValue(wrapperDTO.getOffSet()); + String limit = CommonUtil.getNullOrTrimmedValue(wrapperDTO.getLimit()); try { - ValidationRule[] validationRules = {new ValidationRule( - ValidationRule.VALIDATION_TYPE_MANDATORY_TEL_END_USER_ID, "endUserId", endUserId)}; + ValidationRule[] validationRules = { + new ValidationRule(ValidationRule.VALIDATION_TYPE_MANDATORY_TEL_END_USER_ID, "endUserId", endUserId), + new ValidationRule(ValidationRule.VALIDATION_TYPE_OPTIONAL_INT_GE_ZERO, "offset", offset ), + new ValidationRule(ValidationRule.VALIDATION_TYPE_OPTIONAL_INT_GE_ZERO, "limit", limit) + }; + Validation.checkRequestParams(validationRules); } catch (CustomException ex) { @@ -103,6 +108,10 @@ protected Returnable process(PaymentListTransactionRequestWrapper extendedReques String msisdn = extendedRequestDTO.getEndUserId(); String endUserId = getLastMobileNumber(msisdn); Integer userId = extendedRequestDTO.getUser().getId(); + Integer offset = CommonUtil + .convertStringToInteger(extendedRequestDTO.getOffSet()); + Integer limit = CommonUtil + .convertStringToInteger(extendedRequestDTO.getLimit()); String serviceCallPayment = ServiceName.ChargeUser.toString(); String serviceCallRefund = ServiceName.RefundUser.toString(); @@ -123,7 +132,9 @@ protected Returnable process(PaymentListTransactionRequestWrapper extendedReques PaymentListTransactionResponseBean paymentTransaction = new PaymentListTransactionResponseBean(); List listNodes = new ArrayList(); - List responses = loggingDAO.getMessageLogs(userId, list, "msisdn", "tel:+" + endUserId, null, null); + List responses = loggingDAO.getResponseLists(userId, list, "msisdn", "tel:+" + endUserId, null, null, offset, limit + + ); String jsonString = null; From 500239c546550701048ec36afecb2f5eb8a59f50 Mon Sep 17 00:00:00 2001 From: Rajithkonara Date: Thu, 10 Aug 2017 17:09:59 +0530 Subject: [PATCH 4/4] bug fixed offset and limit in PaymentListTransaction --- .../wso2telco/services/dep/sandbox/dao/LoggingDAO.java | 2 +- .../dep/sandbox/dao/hibernate/HibernateLoggingDao.java | 10 ++++++++-- .../payment/PaymentListTransactionRequestHandler.java | 6 ++---- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/dep-sandbox/src/main/java/com/wso2telco/services/dep/sandbox/dao/LoggingDAO.java b/dep-sandbox/src/main/java/com/wso2telco/services/dep/sandbox/dao/LoggingDAO.java index 0057b3b8..80aee2c0 100644 --- a/dep-sandbox/src/main/java/com/wso2telco/services/dep/sandbox/dao/LoggingDAO.java +++ b/dep-sandbox/src/main/java/com/wso2telco/services/dep/sandbox/dao/LoggingDAO.java @@ -13,6 +13,6 @@ public interface LoggingDAO { public List getMessageLogs(int userid, List serviceNameIds, String reference, String value, Date startTimeStamp, Date endTimeStamp) throws Exception; - public List getResponseLists(int userid, List serviceNameIds, String reference, String value, Date startTimeStamp, Date endTimeStamp, int offSet, int limit) throws Exception; + public List getResponseLists(int userid, List serviceNameIds, String reference, String value, Date startTimeStamp, Date endTimeStamp, int offSet, int limit, int type) throws Exception; } \ No newline at end of file diff --git a/dep-sandbox/src/main/java/com/wso2telco/services/dep/sandbox/dao/hibernate/HibernateLoggingDao.java b/dep-sandbox/src/main/java/com/wso2telco/services/dep/sandbox/dao/hibernate/HibernateLoggingDao.java index 6406bcca..c312097e 100644 --- a/dep-sandbox/src/main/java/com/wso2telco/services/dep/sandbox/dao/hibernate/HibernateLoggingDao.java +++ b/dep-sandbox/src/main/java/com/wso2telco/services/dep/sandbox/dao/hibernate/HibernateLoggingDao.java @@ -110,7 +110,8 @@ public List getMessageLogs(int userid, List serviceNameIds, } @Override - public List getResponseLists(int userid, List serviceNameIds, String ref, String val, Date startTimeStamp, Date endTimeStamp, int offSet, int limit) throws Exception { + public List getResponseLists(int userid, List serviceNameIds, + String ref, String val, Date startTimeStamp, Date endTimeStamp, int offSet, int limit, int type) throws Exception { Session session = getSession(); Map parameterMap = new HashMap(); List messageLogs = new ArrayList(); @@ -138,6 +139,11 @@ public List getResponseLists(int userid, List serviceNameId parameterMap.put("value", value); } + if (type != 0) { + hqlQueryBuilder.append(" AND ml.type = :type"); + parameterMap.put("type", type); + } + if(startTimeStamp != null && endTimeStamp != null){ hqlQueryBuilder.append(" AND ml.messageTimestamp between :startTimeStamp and :endTimeStamp"); parameterMap.put("startTimeStamp", startTimeStamp); @@ -158,7 +164,7 @@ public List getResponseLists(int userid, List serviceNameId Query query = session.createQuery(hqlQueryBuilder.toString()); if (offSet > 0) { - query.setFirstResult(offSet); + query.setFirstResult(offSet-1); } if (limit > 0) { diff --git a/dep-sandbox/src/main/java/com/wso2telco/services/dep/sandbox/servicefactory/payment/PaymentListTransactionRequestHandler.java b/dep-sandbox/src/main/java/com/wso2telco/services/dep/sandbox/servicefactory/payment/PaymentListTransactionRequestHandler.java index f4fd27a3..078bb082 100644 --- a/dep-sandbox/src/main/java/com/wso2telco/services/dep/sandbox/servicefactory/payment/PaymentListTransactionRequestHandler.java +++ b/dep-sandbox/src/main/java/com/wso2telco/services/dep/sandbox/servicefactory/payment/PaymentListTransactionRequestHandler.java @@ -128,13 +128,11 @@ protected Returnable process(PaymentListTransactionRequestWrapper extendedReques JSONObject object = new JSONObject(); object.put("endUserId", msisdn); - + int type = MessageType.Response.getValue(); PaymentListTransactionResponseBean paymentTransaction = new PaymentListTransactionResponseBean(); List listNodes = new ArrayList(); - List responses = loggingDAO.getResponseLists(userId, list, "msisdn", "tel:+" + endUserId, null, null, offset, limit - - ); + List responses = loggingDAO.getResponseLists(userId, list, "msisdn", "tel:+" + endUserId, null, null, offset, limit, type); String jsonString = null;