Skip to content

Commit

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

Merged stage3-dev:  JIRA SCSB-784
  • Loading branch information
srinduri04 authored Oct 5, 2021
2 parents 9faee86 + 7240739 commit 4fabaf0
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@
import org.recap.repository.jpa.ItemDetailsRepository;
import org.recap.util.PropertyUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.context.annotation.Scope;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Service;
Expand All @@ -73,6 +75,7 @@
@Service
@Slf4j
@RefreshScope
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class NCIPProtocolConnector extends AbstractProtocolConnector {

private String ncipRequest = "NCIP2 request sent: ";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import org.recap.model.request.ItemRequestInformation;
import org.recap.ils.protocol.rest.processor.RestProtocolJobResponsePollingProcessor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.http.*;
import org.springframework.stereotype.Service;
import org.springframework.web.client.HttpClientErrorException;
Expand All @@ -27,6 +29,7 @@

@Service
@Slf4j
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class RestProtocolConnector extends AbstractProtocolConnector {

@Autowired
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
import org.recap.model.ILSConfigProperties;
import org.recap.model.request.ItemRequestInformation;
import org.recap.model.response.*;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;

import java.text.ParseException;
Expand All @@ -23,6 +25,7 @@

@Service
@Slf4j
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class SIPProtocolConnector extends AbstractProtocolConnector {

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,36 +1,57 @@
package org.recap.ils.connector.factory;

import lombok.extern.slf4j.Slf4j;
import org.recap.ScsbConstants;
import org.recap.ils.connector.AbstractProtocolConnector;
import org.recap.ils.connector.NCIPProtocolConnector;
import org.recap.ils.connector.RestProtocolConnector;
import org.recap.ils.connector.SIPProtocolConnector;
import org.recap.model.ILSConfigProperties;
import org.recap.util.PropertyUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.HashMap;
import java.util.Map;

@Slf4j
@Component
public class ILSProtocolConnectorFactory extends BaseILSProtocolConnectorFactory {

private final List<AbstractProtocolConnector> protocolConnectors;
private final PropertyUtil propertyUtil;
@Autowired
private PropertyUtil propertyUtil;

@Autowired
public ILSProtocolConnectorFactory(List<AbstractProtocolConnector> protocolConnectors, PropertyUtil propertyUtil) {
this.protocolConnectors = protocolConnectors;
this.propertyUtil = propertyUtil;
}
private ApplicationContext applicationContext;

private static final Map<String, AbstractProtocolConnector> protocolConnectorsMap = new HashMap<>();

public AbstractProtocolConnector getIlsProtocolConnector(String institution) {
AbstractProtocolConnector connector = null;
ILSConfigProperties ilsConfigProperties = propertyUtil.getILSConfigProperties(institution);
String protocol = ilsConfigProperties.getProtocol();
AbstractProtocolConnector connector = protocolConnectors
.stream()
.filter(service -> service.supports(protocol))
.findFirst()
.orElseThrow(IllegalArgumentException::new);
connector.setInstitution(institution);
connector.setIlsConfigProperties(ilsConfigProperties);
if (protocolConnectorsMap.containsKey(institution)) {
connector = protocolConnectorsMap.get(institution);
if (connector != null){
connector.setInstitution(institution);
connector.setIlsConfigProperties(ilsConfigProperties);
}
} else {
if (ScsbConstants.SIP2_PROTOCOL.equalsIgnoreCase(protocol)) {
connector = applicationContext.getBean(SIPProtocolConnector.class);
} else if (ScsbConstants.REST_PROTOCOL.equalsIgnoreCase(protocol)) {
connector = applicationContext.getBean(RestProtocolConnector.class);
} else if (ScsbConstants.NCIP_PROTOCOL.equalsIgnoreCase(protocol)) {
connector = applicationContext.getBean(NCIPProtocolConnector.class);
}
if (connector != null){
connector.setInstitution(institution);
connector.setIlsConfigProperties(ilsConfigProperties);
protocolConnectorsMap.put(institution, connector);
}
}
return connector;
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,10 @@

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;
import org.springframework.stereotype.Component;

import java.util.List;

/**
* Created by rajeshbabuk on 20/Jan/2021
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public void getIlsProtocolConnector(){
String institution = "PUL";
ILSConfigProperties ilsConfigProperties = new ILSConfigProperties();
ilsConfigProperties.setProtocol("NCIP");
ILSProtocolConnectorFactory ilsProtocolConnectorFactory = new ILSProtocolConnectorFactory(Arrays.asList(abstractProtocolConnector),propertyUtil);
ILSProtocolConnectorFactory ilsProtocolConnectorFactory = new ILSProtocolConnectorFactory();
Mockito.when(propertyUtil.getILSConfigProperties(any())).thenReturn(ilsConfigProperties);
Mockito.when(abstractProtocolConnector.supports("NCIP")).thenReturn(true);
AbstractProtocolConnector abstractProtocolConnector = ilsProtocolConnectorFactory.getIlsProtocolConnector(institution);
Expand Down
23 changes: 19 additions & 4 deletions src/test/java/org/recap/request/service/ItemRequestServiceUT.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
import org.apache.camel.support.DefaultExchange;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.Spy;
import org.mockito.junit.MockitoJUnitRunner;
import org.recap.BaseTestCaseUT;
import org.recap.PropertyKeyConstants;
import org.recap.ScsbCommonConstants;
Expand Down Expand Up @@ -56,7 +58,7 @@

import static org.junit.Assert.assertNotNull;
import static org.mockito.ArgumentMatchers.*;

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


Expand Down Expand Up @@ -100,10 +102,10 @@ public class ItemRequestServiceUT extends BaseTestCaseUT {

@Mock
private RequestItemDetailsRepository mockedRequestItemDetailsRepository;

@Mock
private InstitutionDetailsRepository institutionDetailsRepository;

@Mock
private DeliveryCodeDetailsRepository deliveryCodeDetailsRepository;

Expand Down Expand Up @@ -194,7 +196,7 @@ public void testRequestItem() throws Exception {
Mockito.when(deliveryCodeTranslationDetailsRepository.findByRequestingInstitutionandImsLocation(any(),any(), any())).thenReturn(deliveryCodeTranslationEntity);
Mockito.when(mockedRequestItemController.holdItem(any(), any())).thenReturn(itemHoldResponse);
Mockito.when(mockedItemDetailsRepository.findByBarcodeIn(any())).thenReturn(Arrays.asList(itemEntity));
// Mockito.when(mockedOwnerCodeDetailsRepository.findByOwnerCode(itemRequestInfo.getDeliveryLocation())).thenReturn(ownerCodeEntity);
// Mockito.when(mockedOwnerCodeDetailsRepository.findByOwnerCode(itemRequestInfo.getDeliveryLocation())).thenReturn(ownerCodeEntity);
Mockito.when(mockedItemStatusDetailsRepository.findByStatusCode(ScsbCommonConstants.NOT_AVAILABLE)).thenReturn(itemStatusEntity);
Mockito.when(mockedItemDetailsRepository.findById(itemEntity.getId())).thenReturn(Optional.of(itemEntity));
Mockito.doNothing().when(mockedItemRequestDBService).updateItemAvailabilityStatus(Arrays.asList(itemEntity), itemRequestInfo.getUsername());
Expand Down Expand Up @@ -829,6 +831,17 @@ public void testUpdateRecapRequestItem() throws Exception {
public void setRequestItemEntity() {
ItemRequestInformation itemRequestInformation = getItemRequestInformation();
RequestItemEntity requestItemEntity = createRequestItem();
Mockito.when(mockedCommonUtil.checkIfImsItemStatusIsRequestableNotRetrievable(any(), any())).thenReturn(Boolean.TRUE);
Mockito.when(mockedGfaLasService.callGfaItemStatus(requestItemEntity.getItemEntity().getBarcode())).thenReturn("Available");
Mockito.when(mockedRequestItemStatusDetailsRepository.findByRequestStatusCode(ScsbConstants.LAS_REFILE_REQUEST_PLACED)).thenReturn(createRequestItem().getRequestStatusEntity());
ReflectionTestUtils.invokeMethod(mockedItemRequestService, "setRequestItemEntity", itemRequestInformation, requestItemEntity);
}

@Test
public void setRequestItemEntityException() {
ItemRequestInformation itemRequestInformation = getItemRequestInformation();
RequestItemEntity requestItemEntity = createRequestItem();
Mockito.when(mockedCommonUtil.checkIfImsItemStatusIsRequestableNotRetrievable(any(), any())).thenReturn(Boolean.TRUE);
Mockito.when(mockedGfaLasService.callGfaItemStatus(requestItemEntity.getItemEntity().getBarcode())).thenReturn("Available");
Mockito.when(mockedRequestItemStatusDetailsRepository.findByRequestStatusCode(ScsbConstants.LAS_REFILE_REQUEST_PLACED)).thenThrow(new NullPointerException());
ReflectionTestUtils.invokeMethod(mockedItemRequestService, "setRequestItemEntity", itemRequestInformation, requestItemEntity);
Expand Down Expand Up @@ -1401,6 +1414,7 @@ public void replaceRequestsToLASQueueForRequestIdsForEDDException() {
Mockito.when(mockedItemValidatorService.itemValidation(any())).thenReturn(responseEntity1);
Mockito.when(mockedRequestItemDetailsRepository.findByIdsAndStatusCodes(requestIds, Collections.singletonList(ScsbConstants.REQUEST_STATUS_EXCEPTION))).thenReturn(Arrays.asList(requestItemEntity));
Mockito.when(mockedGfaLasService.callGfaItemStatus(any())).thenReturn("OUT");
Mockito.when(mockedCommonUtil.checkIfImsItemStatusIsRequestableNotRetrievable(any(),any())).thenReturn(Boolean.TRUE);
Mockito.when(mockedRequestItemDetailsRepository.save(any())).thenReturn(requestItemEntity);
Mockito.when(mockedRequestItemStatusDetailsRepository.findByRequestStatusCode(ScsbConstants.LAS_REFILE_REQUEST_PLACED)).thenReturn(requestItemEntity.getRequestStatusEntity());
Map<String, String> result1 = mockedItemRequestService.replaceRequestsToLASQueue(replaceRequest);
Expand Down Expand Up @@ -1793,6 +1807,7 @@ public RequestItemEntity createRequestItem() {
requestTypeEntity.setRequestTypeDesc("Recallhold");

RequestStatusEntity requestStatusEntity = new RequestStatusEntity();
requestStatusEntity.setId(1);
requestStatusEntity.setRequestStatusCode("REFILE");
requestStatusEntity.setRequestStatusDescription("REFILE");

Expand Down

0 comments on commit 4fabaf0

Please sign in to comment.