-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #231 from ResearchCollectionsAndPreservation/stage…
…3-dev Merged stage3-dev: JIRA SCSB-784
- Loading branch information
Showing
7 changed files
with
65 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 36 additions & 15 deletions
51
src/main/java/org/recap/ils/connector/factory/ILSProtocolConnectorFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters