From d115c2815956b1e7c24e4fc37b7a100f236c749a Mon Sep 17 00:00:00 2001 From: ndinakar Date: Wed, 22 Feb 2023 17:06:14 +0530 Subject: [PATCH 1/2] fix for SQL LOCK Excpetion --- src/main/java/org/recap/ScsbConstants.java | 2 +- .../RequestItemValidatorController.java | 34 +++++++++++++++---- 2 files changed, 28 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/recap/ScsbConstants.java b/src/main/java/org/recap/ScsbConstants.java index da02ebc5..5fe3c653 100644 --- a/src/main/java/org/recap/ScsbConstants.java +++ b/src/main/java/org/recap/ScsbConstants.java @@ -468,6 +468,6 @@ public static List getRequestTypeList() { public static final String VERSION = "ns1:version"; public static final String SCHEME = "ns1:Scheme"; public static final String XMLNS = "xmlns:ns1"; - + public static final String SQL_EXCEPTION = "PessimisticLockException: could not execute statement"; } diff --git a/src/main/java/org/recap/controller/RequestItemValidatorController.java b/src/main/java/org/recap/controller/RequestItemValidatorController.java index 2e006396..76cfb29e 100644 --- a/src/main/java/org/recap/controller/RequestItemValidatorController.java +++ b/src/main/java/org/recap/controller/RequestItemValidatorController.java @@ -1,6 +1,7 @@ package org.recap.controller; import lombok.extern.slf4j.Slf4j; +import org.recap.ScsbCommonConstants; import org.recap.ScsbConstants; import org.recap.ils.connector.factory.ILSProtocolConnectorFactory; import org.recap.model.request.ItemRequestInformation; @@ -9,6 +10,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; @@ -17,6 +19,9 @@ import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RestController; +import java.sql.SQLException; +import java.util.Date; + /** * Created by hemalathas on 10/11/16. */ @@ -72,13 +77,28 @@ public ResponseEntity validateItemRequestInformations(@RequestBody ItemRequestIn */ @PostMapping(value = "/validateItemRequest", consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity validateItemRequest(@RequestBody ItemRequestInformation itemRequestInformation) { - ResponseEntity responseEntity; - log.info("Request Validation: Start"); - responseEntity = requestParamaterValidatorService.validateItemRequestParameters(itemRequestInformation); - if (responseEntity == null) { - responseEntity = itemValidatorService.itemValidation(itemRequestInformation); + ResponseEntity responseEntity = null; + try { + log.info("Request Validation: Start"); + responseEntity = requestParamaterValidatorService.validateItemRequestParameters(itemRequestInformation); + if (responseEntity == null) { + responseEntity = itemValidatorService.itemValidation(itemRequestInformation); + } + log.info(String.format("Request Validation: %s - %s",responseEntity.getStatusCode(), responseEntity.getBody())); + return responseEntity; + } catch (Exception e) { + if(e instanceof SQLException) + return new ResponseEntity<>(ScsbConstants.SQL_EXCEPTION, getHttpHeaders(), HttpStatus.BAD_REQUEST); + else + return responseEntity; } - log.info(String.format("Request Validation: %s - %s",responseEntity.getStatusCode(), responseEntity.getBody())); - return responseEntity; + + + } + + private HttpHeaders getHttpHeaders() { + HttpHeaders responseHeaders = new HttpHeaders(); + responseHeaders.add(ScsbCommonConstants.RESPONSE_DATE, new Date().toString()); + return responseHeaders; } } From 5bf3d0276f432f3b9687f56dcee2ece81ccad7fc Mon Sep 17 00:00:00 2001 From: ndinakar Date: Wed, 22 Feb 2023 19:04:19 +0530 Subject: [PATCH 2/2] database exceptions captured --- src/main/java/org/recap/ScsbConstants.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/recap/ScsbConstants.java b/src/main/java/org/recap/ScsbConstants.java index 5fe3c653..57ae6406 100644 --- a/src/main/java/org/recap/ScsbConstants.java +++ b/src/main/java/org/recap/ScsbConstants.java @@ -468,6 +468,6 @@ public static List getRequestTypeList() { public static final String VERSION = "ns1:version"; public static final String SCHEME = "ns1:Scheme"; public static final String XMLNS = "xmlns:ns1"; - public static final String SQL_EXCEPTION = "PessimisticLockException: could not execute statement"; + public static final String SQL_EXCEPTION = "Exception captured at Database level while creating request."; }