From 34d3ad9a4143cc929736eafc80fb8d25d5467b0c Mon Sep 17 00:00:00 2001 From: TayGov Date: Mon, 21 Nov 2022 07:36:49 -0800 Subject: [PATCH 1/2] Trim org ticket number --- .../bc/gov/open/ecrc/service/EcrcServicesImpl.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/ecrc-api/src/main/java/ca/bc/gov/open/ecrc/service/EcrcServicesImpl.java b/src/ecrc-api/src/main/java/ca/bc/gov/open/ecrc/service/EcrcServicesImpl.java index da3a08ff..ecb7b83f 100644 --- a/src/ecrc-api/src/main/java/ca/bc/gov/open/ecrc/service/EcrcServicesImpl.java +++ b/src/ecrc-api/src/main/java/ca/bc/gov/open/ecrc/service/EcrcServicesImpl.java @@ -46,7 +46,7 @@ public class EcrcServicesImpl implements EcrcServices { public ResponseEntity doAuthenticateUser(String orgTicketNumber, String requestGuid) throws EcrcServiceException { logger.info("For request guid: [{}] Authenticating using org ticket number", requestGuid); - String doAuthenticateUserUri = String.format(ecrcProps.getDoAuthenticateUserUri(), orgTicketNumber); + String doAuthenticateUserUri = String.format(ecrcProps.getDoAuthenticateUserUri(), orgTicketNumber.trim()); return ecrcWebMethodsService.callWebMethodsService(doAuthenticateUserUri, new DoAuthenticateUser(), requestGuid); } @@ -59,7 +59,7 @@ public ResponseEntity getProvinceList(String requestGuid) throws EcrcSer } public ResponseEntity getNextSessionId(String orgTicketNumber, String requestGuid) throws EcrcServiceException { - String nextSessionIdUri = String.format(ecrcProps.getGetNextSessionIdUri(), orgTicketNumber); + String nextSessionIdUri = String.format(ecrcProps.getGetNextSessionIdUri(), orgTicketNumber.trim()); return ecrcWebMethodsService.callWebMethodsService(nextSessionIdUri, new GetNextSessionId(), requestGuid); } @@ -80,7 +80,7 @@ public ResponseEntity updateServiceFinancialTxn(RequestUpdateServiceFina } public ResponseEntity getServiceFeeAmount(String orgTicketNumber, String scheduleTypeCd, String scopeLevelCd, String requestGuid) throws EcrcServiceException { - String serviceFeeAmountUri = String.format(ecrcProps.getGetServiceFeeAmountUri(), orgTicketNumber, scheduleTypeCd, scopeLevelCd); + String serviceFeeAmountUri = String.format(ecrcProps.getGetServiceFeeAmountUri(), orgTicketNumber.trim(), scheduleTypeCd, scopeLevelCd); return ecrcWebMethodsService.callWebMethodsService(serviceFeeAmountUri, new GetServiceFeeAmount(), requestGuid); } @@ -91,7 +91,7 @@ public ResponseEntity logPaymentFailure(RequestLogPaymentFailure payment } public ResponseEntity getNextInvoiceId(String orgTicketNumber, String requestGuid) throws EcrcServiceException { - String nextInvoiceIdUri = String.format(ecrcProps.getGetNextInvoiceIdUri(), orgTicketNumber); + String nextInvoiceIdUri = String.format(ecrcProps.getGetNextInvoiceIdUri(), orgTicketNumber.trim()); return ecrcWebMethodsService.callWebMethodsService(nextInvoiceIdUri, new GetNextInvoiceId(), requestGuid); } @@ -200,7 +200,7 @@ private ResponseEntity saveServiceInfo(RequestNewCRCApplicant requestNew return clientResp; } ResponseEntity getNextSession = getNextSessionId( - requestNewCRCApplicant.getRequestCreateApplicant().getOrgTicketNumber(), + requestNewCRCApplicant.getRequestCreateApplicant().getOrgTicketNumber().trim(), requestNewCRCApplicant.getRequestGuid()); if (getNextSession.getStatusCode() == HttpStatus.OK) { obj = new JSONObject(getNextSession.getBody()); @@ -213,7 +213,7 @@ private ResponseEntity saveServiceInfo(RequestNewCRCApplicant requestNew if (requestNewCRCApplicant.getApplType().equalsIgnoreCase(EMPLOYEE_TYPE) || requestNewCRCApplicant.getApplType().equalsIgnoreCase(ONETIME_TYPE)) { ResponseEntity getNextInvoice = getNextInvoiceId( - requestNewCRCApplicant.getRequestCreateApplicant().getOrgTicketNumber(), + requestNewCRCApplicant.getRequestCreateApplicant().getOrgTicketNumber().trim(), requestNewCRCApplicant.getRequestGuid()); if (getNextInvoice.getStatusCode() == HttpStatus.OK) { obj = new JSONObject(getNextInvoice.getBody()); From 2a51df59da62af0b0d05166e3151c00df8986faa Mon Sep 17 00:00:00 2001 From: TayGov Date: Mon, 21 Nov 2022 08:21:21 -0800 Subject: [PATCH 2/2] make inputs null safe --- .../open/ecrc/model/RequestNewCRCService.java | 8 ++++++- .../open/ecrc/service/EcrcServicesImpl.java | 23 ++++++++++++++----- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/src/ecrc-api/src/main/java/ca/bc/gov/open/ecrc/model/RequestNewCRCService.java b/src/ecrc-api/src/main/java/ca/bc/gov/open/ecrc/model/RequestNewCRCService.java index f02881cf..bbf90c56 100644 --- a/src/ecrc-api/src/main/java/ca/bc/gov/open/ecrc/model/RequestNewCRCService.java +++ b/src/ecrc-api/src/main/java/ca/bc/gov/open/ecrc/model/RequestNewCRCService.java @@ -1,5 +1,7 @@ package ca.bc.gov.open.ecrc.model; +import org.apache.cxf.common.util.StringUtils; + /*** * Object for requesting new CRC Service */ @@ -22,7 +24,11 @@ public class RequestNewCRCService { private String requestGuid; public String getOrgTicketNumber() { - return orgTicketNumber; + if (!StringUtils.isEmpty(orgTicketNumber)) + return orgTicketNumber.trim(); + + return null; + } public void setOrgTicketNumber(String orgTicketNumber) { diff --git a/src/ecrc-api/src/main/java/ca/bc/gov/open/ecrc/service/EcrcServicesImpl.java b/src/ecrc-api/src/main/java/ca/bc/gov/open/ecrc/service/EcrcServicesImpl.java index ecb7b83f..a3cc5454 100644 --- a/src/ecrc-api/src/main/java/ca/bc/gov/open/ecrc/service/EcrcServicesImpl.java +++ b/src/ecrc-api/src/main/java/ca/bc/gov/open/ecrc/service/EcrcServicesImpl.java @@ -6,6 +6,7 @@ import ca.bc.gov.open.ecrc.model.*; import ca.bc.gov.open.ecrc.objects.*; import com.google.gson.Gson; +import org.apache.cxf.common.util.StringUtils; import org.json.JSONObject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -46,7 +47,7 @@ public class EcrcServicesImpl implements EcrcServices { public ResponseEntity doAuthenticateUser(String orgTicketNumber, String requestGuid) throws EcrcServiceException { logger.info("For request guid: [{}] Authenticating using org ticket number", requestGuid); - String doAuthenticateUserUri = String.format(ecrcProps.getDoAuthenticateUserUri(), orgTicketNumber.trim()); + String doAuthenticateUserUri = String.format(ecrcProps.getDoAuthenticateUserUri(), trimString(orgTicketNumber)); return ecrcWebMethodsService.callWebMethodsService(doAuthenticateUserUri, new DoAuthenticateUser(), requestGuid); } @@ -59,7 +60,7 @@ public ResponseEntity getProvinceList(String requestGuid) throws EcrcSer } public ResponseEntity getNextSessionId(String orgTicketNumber, String requestGuid) throws EcrcServiceException { - String nextSessionIdUri = String.format(ecrcProps.getGetNextSessionIdUri(), orgTicketNumber.trim()); + String nextSessionIdUri = String.format(ecrcProps.getGetNextSessionIdUri(), trimString(orgTicketNumber)); return ecrcWebMethodsService.callWebMethodsService(nextSessionIdUri, new GetNextSessionId(), requestGuid); } @@ -80,7 +81,7 @@ public ResponseEntity updateServiceFinancialTxn(RequestUpdateServiceFina } public ResponseEntity getServiceFeeAmount(String orgTicketNumber, String scheduleTypeCd, String scopeLevelCd, String requestGuid) throws EcrcServiceException { - String serviceFeeAmountUri = String.format(ecrcProps.getGetServiceFeeAmountUri(), orgTicketNumber.trim(), scheduleTypeCd, scopeLevelCd); + String serviceFeeAmountUri = String.format(ecrcProps.getGetServiceFeeAmountUri(), trimString(orgTicketNumber), scheduleTypeCd, scopeLevelCd); return ecrcWebMethodsService.callWebMethodsService(serviceFeeAmountUri, new GetServiceFeeAmount(), requestGuid); } @@ -91,7 +92,7 @@ public ResponseEntity logPaymentFailure(RequestLogPaymentFailure payment } public ResponseEntity getNextInvoiceId(String orgTicketNumber, String requestGuid) throws EcrcServiceException { - String nextInvoiceIdUri = String.format(ecrcProps.getGetNextInvoiceIdUri(), orgTicketNumber.trim()); + String nextInvoiceIdUri = String.format(ecrcProps.getGetNextInvoiceIdUri(), trimString(orgTicketNumber)); return ecrcWebMethodsService.callWebMethodsService(nextInvoiceIdUri, new GetNextInvoiceId(), requestGuid); } @@ -200,7 +201,7 @@ private ResponseEntity saveServiceInfo(RequestNewCRCApplicant requestNew return clientResp; } ResponseEntity getNextSession = getNextSessionId( - requestNewCRCApplicant.getRequestCreateApplicant().getOrgTicketNumber().trim(), + requestNewCRCApplicant.getRequestCreateApplicant().getOrgTicketNumber(), requestNewCRCApplicant.getRequestGuid()); if (getNextSession.getStatusCode() == HttpStatus.OK) { obj = new JSONObject(getNextSession.getBody()); @@ -213,7 +214,7 @@ private ResponseEntity saveServiceInfo(RequestNewCRCApplicant requestNew if (requestNewCRCApplicant.getApplType().equalsIgnoreCase(EMPLOYEE_TYPE) || requestNewCRCApplicant.getApplType().equalsIgnoreCase(ONETIME_TYPE)) { ResponseEntity getNextInvoice = getNextInvoiceId( - requestNewCRCApplicant.getRequestCreateApplicant().getOrgTicketNumber().trim(), + requestNewCRCApplicant.getRequestCreateApplicant().getOrgTicketNumber(), requestNewCRCApplicant.getRequestGuid()); if (getNextInvoice.getStatusCode() == HttpStatus.OK) { obj = new JSONObject(getNextInvoice.getBody()); @@ -266,4 +267,14 @@ private ResponseEntity handlePayment(RequestNewCRCApplicant requestNewCR return null; } + private String trimString(String input) { + + if (StringUtils.isEmpty(input)) { + return ""; + } + + return input.trim(); + + } + }