use of net.petafuel.styx.core.xs2a.exceptions.SADException in project styx by petafuel.
the class SAD method getBankByBIC.
/**
* Returns a fully initialized XS2AStandard including instances of the service
* classes if available/implemented for bank standard
* If there is no entry found for the bic, a BankNotFoundException is thrown
*
* @param bic The bic which should be searched for in SAD
* @param isSandbox Should the service classes be initialized using the xs2a
* sandbox environment or production environment of the bank
* @return returns a XS2AStandard object which should contain fully initialized
* service objects for all service types if applicable/implemented
* @throws BankNotFoundException the bic was not found in the SAD Database
* @throws BankLookupFailedException there was an error initializing a service
* which is necessary for
*/
public XS2AStandard getBankByBIC(String bic, boolean isSandbox) throws BankLookupFailedException, BankNotFoundException {
this.bic = bic;
// Read aspsp data from SAD database into Aspsp.class model
Aspsp aspsp = PersistentSAD.getByBIC(bic);
if (aspsp == null) {
LOG.error("The requested bank for bic={} is not avaiable in SAD {}", bic, SAD_BANK_NOT_FOUND);
throw new BankNotFoundException("The requested aspsp for bic " + bic + " is not available in SAD");
}
XS2AStandard xs2AStandard = new XS2AStandard();
// parse the implementer options into the implementerOptions List of the aspsp
// object
parseImplementerOptions(aspsp);
xs2AStandard.setAspsp(aspsp);
String standardClassName = aspsp.getConfig().getStandard().getName();
String standardPackage = standardClassName.toLowerCase();
Version version = new Version(aspsp.getConfig().getStandard().getVersion());
String interfaceVersion = ".v" + version.getMajor() + "_" + version.getMinor();
// build a full qualified class name without service type suffix
xs2aClassPrefix = SERVICES_PACKAGE_PATH + standardPackage + interfaceVersion + "." + standardClassName;
// Check if requesting sandbox or production urls
if (isSandbox) {
LOG.warn("SAD is using sandbox environment bic={}", bic);
mapASPSPUrlSetup(aspsp.getSandboxUrl());
} else {
mapASPSPUrlSetup(aspsp.getProductionUrl());
}
// HttpSigner will be used in all following service initialisations and is
// therefore initialized first
// Signer might be null if the target standard does not require or did not
// implement the class in its package
Class<?> httpSignerClazz = getServiceClass(xs2aClassPrefix + XS2AServices.HTTP_SIGNER.getValue());
try {
IXS2AHttpSigner httpSignerInstance = null;
if (httpSignerClazz != null && shouldSign(xs2AStandard)) {
httpSignerInstance = (IXS2AHttpSigner) httpSignerClazz.getConstructor().newInstance();
}
// initializing all service classes per service type and setting them into the
// xs2aStandard
CSInterface csServiceInstance = (CSInterface) reflectServiceInstance(httpSignerInstance, XS2AServices.CS);
xs2AStandard.setCs(csServiceInstance);
AISInterface aisServiceInstance = (AISInterface) reflectServiceInstance(httpSignerInstance, XS2AServices.AIS);
xs2AStandard.setAis(aisServiceInstance);
PISInterface pisServiceInstance = (PISInterface) reflectServiceInstance(httpSignerInstance, XS2AServices.PIS);
xs2AStandard.setPis(pisServiceInstance);
PIISInterface piisServiceInstance = (PIISInterface) reflectServiceInstance(httpSignerInstance, XS2AServices.PIIS);
xs2AStandard.setPiis(piisServiceInstance);
Class<?> requestClassProviderClazz = getServiceClass(xs2aClassPrefix + XS2AServices.REQUEST_CLASS_PROVIDER.getValue());
if (requestClassProviderClazz == null) {
throw new SADException("RequestClassProvider was not found for the requested XS2A Standard but is required");
}
XS2ARequestClassProvider requestClassProviderInstance;
requestClassProviderInstance = (XS2ARequestClassProvider) requestClassProviderClazz.getConstructor().newInstance();
xs2AStandard.setRequestClassProvider(requestClassProviderInstance);
} catch (InstantiationException | IllegalAccessException e) {
LOG.error("Error initialising service class through SAD: {}", e.getMessage(), e);
throw new BankLookupFailedException(e.getMessage(), e);
} catch (InvocationTargetException e) {
LOG.error("Error calling service class constructor through SAD: {}", e.getMessage(), e);
throw new BankLookupFailedException(e.getMessage(), e);
} catch (NoSuchMethodException e) {
LOG.error("The service class has no matching constructor for initialisation through SAD: {}", e.getMessage(), e);
throw new BankLookupFailedException(e.getMessage(), e);
}
return xs2AStandard;
}
Aggregations