Skip to content

Commit

Permalink
Merge pull request #216 from ResearchCollectionsAndPreservation/stage…
Browse files Browse the repository at this point in the history
…3-dev

Stage3 dev to UAT
  • Loading branch information
srinduri04 authored Sep 6, 2021
2 parents 7ae877c + fe9f453 commit 9faee86
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import org.recap.ims.model.*;
import org.recap.model.IMSConfigProperties;
import org.recap.model.gfa.GFAItemStatusCheckResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.*;
import org.springframework.http.client.SimpleClientHttpRequestFactory;
import org.springframework.stereotype.Service;
Expand All @@ -25,7 +24,6 @@
@Slf4j
public class GFALasImsLocationConnector extends AbstractLASImsLocationConnector {

@Autowired
private GFALasServiceUtil gfaLasServiceUtil;

@Override
Expand Down Expand Up @@ -63,6 +61,18 @@ private HttpHeaders getHttpHeaders() {
return headers;
}

/**
* Get GFA LAS Service Util class
*
* @return GFALasServiceUtil
*/
public GFALasServiceUtil getGfaLasServiceUtil() {
if (null == gfaLasServiceUtil) {
gfaLasServiceUtil = new GFALasServiceUtil();
}
return gfaLasServiceUtil;
}

/**
* Item status check gfa heart beat check response.
*
Expand Down Expand Up @@ -144,7 +154,7 @@ public GFARetrieveItemResponse itemRetrieval(GFARetrieveItemRequest gfaRetrieveI
ResponseEntity<GFARetrieveItemResponse> responseEntity = getRestTemplate().exchange(this.imsConfigProperties.getImsItemRetrievalOrderEndpoint(), HttpMethod.POST, requestEntity, GFARetrieveItemResponse.class);
if (responseEntity.getStatusCode() == HttpStatus.OK) {
gfaRetrieveItemResponse = responseEntity.getBody();
gfaRetrieveItemResponse = gfaLasServiceUtil.getLASRetrieveResponse(gfaRetrieveItemResponse);
gfaRetrieveItemResponse = getGfaLasServiceUtil().getLASRetrieveResponse(gfaRetrieveItemResponse);
} else {
gfaRetrieveItemResponse = new GFARetrieveItemResponse();
gfaRetrieveItemResponse.setSuccess(false);
Expand Down Expand Up @@ -179,7 +189,7 @@ public GFAEddItemResponse itemEDDRetrieval(GFARetrieveEDDItemRequest gfaRetrieve
ResponseEntity<GFAEddItemResponse> responseEntity = getRestTemplate().exchange(this.imsConfigProperties.getImsItemEddOrderEndpoint(), HttpMethod.POST, requestEntity, GFAEddItemResponse.class);
if (responseEntity.getStatusCode() == HttpStatus.OK) {
gfaEddItemResponse = responseEntity.getBody();
gfaEddItemResponse = gfaLasServiceUtil.getLASEddResponse(gfaEddItemResponse);
gfaEddItemResponse = getGfaLasServiceUtil().getLASEddResponse(gfaEddItemResponse);
} else {
gfaEddItemResponse = new GFAEddItemResponse();
gfaEddItemResponse.setSuccess(false);
Expand Down Expand Up @@ -211,14 +221,14 @@ public GFAPwdResponse gfaPermanentWithdrawalDirect(GFAPwdRequest gfaPwdRequest)
GFAPwdResponse gfaPwdResponse = null;
try {
HttpEntity<GFAPwdRequest> requestEntity = new HttpEntity<>(gfaPwdRequest, getHttpHeaders());
log.info("GFA PWD Request at {} : {}", this.imsLocationCode, gfaLasServiceUtil.convertJsonToString(requestEntity.getBody()));
log.info("GFA PWD Request at {} : {}", this.imsLocationCode, getGfaLasServiceUtil().convertJsonToString(requestEntity.getBody()));
RestTemplate restTemplate = getRestTemplate();
((SimpleClientHttpRequestFactory) restTemplate.getRequestFactory()).setConnectTimeout(Integer.parseInt(this.imsConfigProperties.getImsServerResponseTimeoutMillis()));
((SimpleClientHttpRequestFactory) restTemplate.getRequestFactory()).setReadTimeout(Integer.parseInt(this.imsConfigProperties.getImsServerResponseTimeoutMillis()));
ResponseEntity<GFAPwdResponse> responseEntity = restTemplate.exchange(this.imsConfigProperties.getImsPermanentWithdrawalDirectEndpoint(), HttpMethod.POST, requestEntity, GFAPwdResponse.class);
gfaPwdResponse = responseEntity.getBody();
log.info("GFA PWD Response Status Code at {} : {}", this.imsLocationCode, responseEntity.getStatusCode());
log.info("GFA PWD Response at {} : {}", this.imsLocationCode, gfaLasServiceUtil.convertJsonToString(responseEntity.getBody()));
log.info("GFA PWD Response at {} : {}", this.imsLocationCode, getGfaLasServiceUtil().convertJsonToString(responseEntity.getBody()));
log.info("GFA PWD item status processed at {}", this.imsLocationCode);
} catch (Exception e) {
log.error(ScsbCommonConstants.REQUEST_EXCEPTION, e);
Expand All @@ -237,14 +247,14 @@ public GFAPwiResponse gfaPermanentWithdrawalInDirect(GFAPwiRequest gfaPwiRequest
GFAPwiResponse gfaPwiResponse = null;
try {
HttpEntity<GFAPwiRequest> requestEntity = new HttpEntity<>(gfaPwiRequest, getHttpHeaders());
log.info("GFA PWI Request at {} : {}", this.imsLocationCode, gfaLasServiceUtil.convertJsonToString(requestEntity.getBody()));
log.info("GFA PWI Request at {} : {}", this.imsLocationCode, getGfaLasServiceUtil().convertJsonToString(requestEntity.getBody()));
RestTemplate restTemplate = getRestTemplate();
((SimpleClientHttpRequestFactory) restTemplate.getRequestFactory()).setConnectTimeout(Integer.parseInt(this.imsConfigProperties.getImsServerResponseTimeoutMillis()));
((SimpleClientHttpRequestFactory) restTemplate.getRequestFactory()).setReadTimeout(Integer.parseInt(this.imsConfigProperties.getImsServerResponseTimeoutMillis()));
ResponseEntity<GFAPwiResponse> responseEntity = restTemplate.exchange(this.imsConfigProperties.getImsPermanentWithdrawalIndirectEndpoint(), HttpMethod.POST, requestEntity, GFAPwiResponse.class);
gfaPwiResponse = responseEntity.getBody();
log.info("GFA PWI Response Status Code at {} : {}", this.imsLocationCode, responseEntity.getStatusCode());
log.info("GFA PWI Response at {} : {}", this.imsLocationCode, gfaLasServiceUtil.convertJsonToString(responseEntity.getBody()));
log.info("GFA PWI Response at {} : {}", this.imsLocationCode, getGfaLasServiceUtil().convertJsonToString(responseEntity.getBody()));
log.info("GFA PWI item status processed at {}", this.imsLocationCode);
} catch (Exception e) {
log.error(ScsbCommonConstants.REQUEST_EXCEPTION, e);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.recap.ims.connector.factory;

import org.recap.ims.connector.AbstractLASImsLocationConnector;
import org.recap.ims.connector.GFALasImsLocationConnector;
import org.recap.model.IMSConfigProperties;
import org.recap.util.PropertyUtil;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -14,25 +15,14 @@
@Component
public class LASImsLocationConnectorFactory extends BaseLASImsLocationConnectorFactory {

private final List<AbstractLASImsLocationConnector> imsLocationConnectors;
private final PropertyUtil propertyUtil;

@Autowired
public LASImsLocationConnectorFactory(List<AbstractLASImsLocationConnector> imsLocationConnectors, PropertyUtil propertyUtil) {
this.imsLocationConnectors = imsLocationConnectors;
this.propertyUtil = propertyUtil;
}
private PropertyUtil propertyUtil;

@Override
public AbstractLASImsLocationConnector getLasImsLocationConnector(String imsLocationCode) {
IMSConfigProperties imsConfigProperties = propertyUtil.getIMSConfigProperties(imsLocationCode);
AbstractLASImsLocationConnector connector = imsLocationConnectors
.stream()
.filter(service -> service.supports(imsLocationCode))
.findFirst()
.orElseThrow(IllegalArgumentException::new);
GFALasImsLocationConnector connector = new GFALasImsLocationConnector();
connector.setImsLocationCode(imsLocationCode);
connector.setImsConfigProperties(imsConfigProperties);
connector.setImsConfigProperties(propertyUtil.getIMSConfigProperties(imsLocationCode));
return connector;
}
}
3 changes: 2 additions & 1 deletion src/main/java/org/recap/ims/service/GFALasService.java
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ public ItemInformationResponse executeRetrieveOrder(ItemRequestInformation itemR
List<GFAItemStatus> gfaItemStatuses = new ArrayList<>();
gfaItemStatuses.add(gfaItemStatus001);
gfaItemStatusCheckRequest.setItemStatus(gfaItemStatuses);
log.info("Before Item Status Check - Request Type: {} Barcode: {} IMS Location: {}", itemRequestInfo.getRequestType(), gfaItemStatus001.getItemBarCode(), itemRequestInfo.getImsLocationCode());
gfaItemStatusCheckResponse = lasImsLocationConnectorFactory.getLasImsLocationConnector(itemRequestInfo.getImsLocationCode()).itemStatusCheck(gfaItemStatusCheckRequest);
if (gfaItemStatusCheckResponse != null
&& gfaItemStatusCheckResponse.getDsitem() != null
Expand All @@ -149,7 +150,7 @@ public ItemInformationResponse executeRetrieveOrder(ItemRequestInformation itemR
} else {
gfaOnlyStatus = itemStatus.toUpperCase();
}
log.info("Item status check before executing {} Order. Status received : {}", itemRequestInfo.getRequestType(), gfaOnlyStatus);
log.info("After Item Status Check, before executing - Request Type: {} Barcode: {} IMS Location: {} Status received : {}", itemRequestInfo.getRequestType(), gfaItemStatus001.getItemBarCode(), itemRequestInfo.getImsLocationCode(), gfaOnlyStatus);
// Call Retrieval Order
if (StringUtils.isBlank(itemRequestInfo.getImsLocationCode())) {
itemResponseInformation.setSuccess(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import org.mockito.Mockito;
import org.recap.BaseTestCaseUT;
import org.recap.ims.connector.AbstractLASImsLocationConnector;
import org.recap.ims.connector.factory.LASImsLocationConnectorFactory;
import org.recap.model.IMSConfigProperties;
import org.recap.util.PropertyUtil;

Expand Down Expand Up @@ -35,7 +34,7 @@ public class LASImsLocationConnectorFactoryUT extends BaseTestCaseUT {
@Test
public void getLasImsLocationConnector(){
imsLocationConnectors.add(abstractLASImsLocationConnector);
lasImsLocationConnectorFactory = new LASImsLocationConnectorFactory(imsLocationConnectors,propertyUtil);
lasImsLocationConnectorFactory = new LASImsLocationConnectorFactory();
Mockito.when(propertyUtil.getIMSConfigProperties(any())).thenReturn(imsConfigProperties);
Mockito.when(abstractLASImsLocationConnector.supports("HD")).thenReturn(true);
lasImsLocationConnectorFactory.getLasImsLocationConnector("HD");
Expand Down
3 changes: 3 additions & 0 deletions src/test/java/org/recap/ims/service/GFALasServiceUT.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
import org.json.JSONObject;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.*;
import org.mockito.junit.MockitoJUnitRunner;
import org.recap.BaseTestCaseUT;
import org.recap.ScsbCommonConstants;
import org.recap.ScsbConstants;
Expand Down Expand Up @@ -50,6 +52,7 @@
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyBoolean;

@RunWith(MockitoJUnitRunner.Silent.class)
public class GFALasServiceUT extends BaseTestCaseUT{

@InjectMocks
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
/**
* Created by hemalathas on 11/11/16.
*/
@RunWith(MockitoJUnitRunner.Silent.class)
public class ItemValidatorServiceUT extends BaseTestCaseUT {

@InjectMocks
Expand Down Expand Up @@ -146,7 +147,6 @@ public void testValidRecallAvailable() throws Exception {
itemStatusEntity.setStatusCode(ScsbConstants.ITEM_STATUS_AVAILABLE);
RequestItemEntity requestItemEntity = getRequestItemEntity();
requestItemEntity.setId(0);
ImsLocationEntity imsLocationEntity = getImsLocationEntity();
Map<String, String> frozenInstitutionPropertyMap = new HashMap<>();
frozenInstitutionPropertyMap.put(itemEntity.getInstitutionEntity().getInstitutionCode(),"FALSE");
Map<String, String> frozenInstitutionMessagesPropertyMap = new HashMap<>();
Expand Down Expand Up @@ -319,11 +319,8 @@ public void testItemValidationForRECALL(){
Mockito.when(propertyUtil.getPropertyByKeyForAllInstitutions(PropertyKeyConstants.ILS.ILS_CIRCULATION_FREEZE_MESSAGE)).thenReturn(frozenInstitutionMessagesPropertyMap);
Mockito.when(propertyUtil.getPropertyByKeyForAllInstitutions(PropertyKeyConstants.ILS.ILS_RECALL_FUNCTIONALITY_AVAILABLE)).thenReturn(frozenInstitutionMessagesPropertyMap);
Mockito.when(itemController.findByBarcodeIn(itemBarcodes.toString())).thenReturn(Arrays.asList(itemEntity));
// Mockito.when(ownerCodeDetailsRepository.findByOwnerCodeAndOwningInstitutionCode(any(),any())).thenReturn(ownerCodeEntity);
// Mockito.when(ownerCodeDetailsRepository.findByOwnerCodeAndRequestingInstitution(any(),any(),anyString())).thenReturn(Collections.EMPTY_LIST);
itemValidatorService.itemValidation(itemRequestInformation);
Mockito.when(institutionDetailsRepository.findByInstitutionCode(any())).thenReturn(getInstitutionEntity());
// Mockito.when(deliveryCodeDetailsRepository.findByDeliveryCodeAndOwningInstitutionIdAndActive(any(), any(), anyChar())).thenReturn(getDeliveryCodeEntity());
Mockito.when(imsLocationDetailsRepository.findById(any())).thenReturn(Optional.of(imsLocationEntity));
itemValidatorService.itemValidation(itemRequestInformation);
ItemRequestInformation itemRequestInformation1 = getItemRequestInformation(itemBarcodes);
Expand All @@ -337,7 +334,6 @@ public void getCheckDeliveryLocation(){
Integer institution = Integer.valueOf(1);
ItemRequestInformation itemRequestInformation = getItemRequestInformation(Arrays.asList("2456744"));
OwnerCodeEntity ownerCodeEntity = getOwnerCodeEntity();
// Mockito.when(ownerCodeDetailsRepository.findByOwnerCode(any())).thenReturn(ownerCodeEntity);
Mockito.when(deliveryCodeDetailsRepository.findByDeliveryCodeAndOwningInstitutionIdAndActive(any(), any(), anyChar())).thenReturn(getDeliveryCodeEntity());
itemValidatorService.checkDeliveryLocation(ownerCode,institution, itemRequestInformation);
itemValidatorService.checkDeliveryLocation(ownerCode,institution, itemRequestInformation);
Expand All @@ -351,7 +347,6 @@ public void getCheckDeliveryLocationForDifferentInstitution(){
itemRequestInformation.setRequestingInstitution("3");
OwnerCodeEntity ownerCodeEntity = getOwnerCodeEntity();
Mockito.when(deliveryCodeDetailsRepository.findByDeliveryCodeAndOwningInstitutionIdAndActive(any(), any(), anyChar())).thenReturn(getDeliveryCodeEntity());
// Mockito.when(ownerCodeDetailsRepository.findByOwnerCode(any())).thenReturn(ownerCodeEntity);
itemValidatorService.checkDeliveryLocation(ownerCode, institution, itemRequestInformation);
}
@Test
Expand Down

0 comments on commit 9faee86

Please sign in to comment.