Skip to content

Commit

Permalink
Merge pull request #296 from ndinakar/v6-dev
Browse files Browse the repository at this point in the history
Gateway requests log changes, handling sql exceptions in circulation.
  • Loading branch information
srinduri04 authored Feb 24, 2023
2 parents a99cb6b + 8ad5ed0 commit 2544003
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/main/java/org/recap/ScsbConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,6 @@ public static List<String> 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 = "Exception captured at Database level while creating request.";

}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand All @@ -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.
*/
Expand Down Expand Up @@ -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;
}
}

0 comments on commit 2544003

Please sign in to comment.