Search in sources :

Example 1 with BankNotFoundException

use of net.petafuel.styx.core.banklookup.exceptions.BankNotFoundException in project styx by petafuel.

the class SADTest method testXS2AStandardInitialisationProduction.

@ParameterizedTest
@MethodSource("BICProvider")
@DisplayName("testXS2AStandardInitialisationProduction() -> Check if PRODUCTION XS2AStandards can be created for all available BICs in SAD")
public void testXS2AStandardInitialisationProduction(String bic) throws BankNotFoundException, BankLookupFailedException {
    SAD sad = new SAD();
    Aspsp bank = PersistentSAD.getByBIC(bic);
    XS2AStandard xs2AStandard = sad.getBankByBIC(bic);
    try {
        Assertions.assertAll(() -> {
            if (bank.getProductionUrl().getCommonUrl() == null) {
                if (bank.getProductionUrl().getAisUrl() != null) {
                    Assert.assertTrue("AIS Url was specified but no Consent Service was initialized", xs2AStandard.isCSImplemented());
                    Assert.assertTrue("AIS Url was specified but no related Service was initialized", xs2AStandard.isAISImplemented());
                }
                if (bank.getProductionUrl().getPisUrl() != null) {
                    Assert.assertTrue("PIS Url was specified but no related Service was initialized", xs2AStandard.isPISImplemented());
                }
                if (bank.getProductionUrl().getPiisUrl() != null) {
                    Assert.assertTrue("PIIS Url was specified but no related Service was initialized", xs2AStandard.isPIISImplemented());
                }
            } else {
                boolean atLeastOneServiceImplemented = false;
                if ((xs2AStandard.isAISImplemented() && xs2AStandard.isCSImplemented()) || xs2AStandard.isPIISImplemented() || xs2AStandard.isPISImplemented()) {
                    atLeastOneServiceImplemented = true;
                }
                Assert.assertTrue("General Url was specified but no related Service was initialized", atLeastOneServiceImplemented);
            }
        });
    } catch (MultipleFailuresError e) {
        if (!bank.isActive()) {
            System.err.println("Test failed for bic=" + bic + " but bank is deactivated in styx: ");
            e.getFailures().forEach(throwable -> System.err.println(throwable.getMessage()));
            Assert.assertTrue(true);
        } else {
            System.err.println("Test failed for bic=" + bic + ": " + e.getMessage());
            e.getFailures().forEach(throwable -> System.err.println(throwable.getMessage()));
            Assert.fail();
        }
    }
}
Also used : Persistence(net.petafuel.styx.core.persistence.Persistence) Connection(java.sql.Connection) MultipleFailuresError(org.opentest4j.MultipleFailuresError) BankNotFoundException(net.petafuel.styx.core.banklookup.exceptions.BankNotFoundException) Aspsp(net.petafuel.styx.core.banklookup.sad.entities.Aspsp) Arguments(org.junit.jupiter.params.provider.Arguments) PreparedStatement(java.sql.PreparedStatement) DisplayName(org.junit.jupiter.api.DisplayName) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) SQLException(java.sql.SQLException) Stream(java.util.stream.Stream) ResultSet(java.sql.ResultSet) Assertions(org.junit.jupiter.api.Assertions) Tag(org.junit.jupiter.api.Tag) Assert(org.junit.Assert) Arguments.arguments(org.junit.jupiter.params.provider.Arguments.arguments) SAD(net.petafuel.styx.core.banklookup.sad.SAD) PersistentSAD(net.petafuel.styx.core.persistence.layers.PersistentSAD) BankLookupFailedException(net.petafuel.styx.core.banklookup.exceptions.BankLookupFailedException) MethodSource(org.junit.jupiter.params.provider.MethodSource) Aspsp(net.petafuel.styx.core.banklookup.sad.entities.Aspsp) SAD(net.petafuel.styx.core.banklookup.sad.SAD) PersistentSAD(net.petafuel.styx.core.persistence.layers.PersistentSAD) MultipleFailuresError(org.opentest4j.MultipleFailuresError) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource) DisplayName(org.junit.jupiter.api.DisplayName)

Example 2 with BankNotFoundException

use of net.petafuel.styx.core.banklookup.exceptions.BankNotFoundException in project styx by petafuel.

the class SADTest method testXS2AStandardInitialisationSandbox.

@ParameterizedTest
@MethodSource("BICProvider")
@DisplayName("testXS2AStandardInitialisationSandbox() -> Check if SANDBOX XS2AStandards can be created for all available BICs in SAD")
public void testXS2AStandardInitialisationSandbox(String bic) throws BankNotFoundException, BankLookupFailedException {
    SAD sad = new SAD();
    Aspsp bank = PersistentSAD.getByBIC(bic);
    XS2AStandard xs2AStandard = sad.getBankByBIC(bic, true);
    try {
        Assertions.assertAll(() -> {
            if (bank.getSandboxUrl().getCommonUrl() == null) {
                if (bank.getSandboxUrl().getAisUrl() != null) {
                    Assert.assertTrue("AIS Url was specified but no Consent Service was initialized", xs2AStandard.isCSImplemented());
                    Assert.assertTrue("AIS Url was specified but no related Service was initialized", xs2AStandard.isAISImplemented());
                }
                if (bank.getSandboxUrl().getPisUrl() != null) {
                    Assert.assertTrue("PIS Url was specified but no related Service was initialized", xs2AStandard.isPISImplemented());
                }
                if (bank.getSandboxUrl().getPiisUrl() != null) {
                    Assert.assertTrue("PIIS Url was specified but no related Service was initialized", xs2AStandard.isPIISImplemented());
                }
            } else {
                boolean atLeastOneServiceImplemented = false;
                if ((xs2AStandard.isAISImplemented() && xs2AStandard.isCSImplemented()) || xs2AStandard.isPIISImplemented() || xs2AStandard.isPISImplemented()) {
                    atLeastOneServiceImplemented = true;
                }
                Assert.assertTrue("General Url was specified but no related Service was initialized", atLeastOneServiceImplemented);
            }
        });
    } catch (MultipleFailuresError e) {
        if (!bank.isActive()) {
            System.err.println("Test failed for bic=" + bic + " but bank is deactivated in styx: ");
            e.getFailures().forEach(throwable -> System.err.println(throwable.getMessage()));
            Assert.assertTrue(true);
        } else {
            System.err.println("Test failed for bic=" + bic + ": " + e.getMessage());
            e.getFailures().forEach(throwable -> System.err.println(throwable.getMessage()));
            Assert.fail();
        }
    }
}
Also used : Persistence(net.petafuel.styx.core.persistence.Persistence) Connection(java.sql.Connection) MultipleFailuresError(org.opentest4j.MultipleFailuresError) BankNotFoundException(net.petafuel.styx.core.banklookup.exceptions.BankNotFoundException) Aspsp(net.petafuel.styx.core.banklookup.sad.entities.Aspsp) Arguments(org.junit.jupiter.params.provider.Arguments) PreparedStatement(java.sql.PreparedStatement) DisplayName(org.junit.jupiter.api.DisplayName) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) SQLException(java.sql.SQLException) Stream(java.util.stream.Stream) ResultSet(java.sql.ResultSet) Assertions(org.junit.jupiter.api.Assertions) Tag(org.junit.jupiter.api.Tag) Assert(org.junit.Assert) Arguments.arguments(org.junit.jupiter.params.provider.Arguments.arguments) SAD(net.petafuel.styx.core.banklookup.sad.SAD) PersistentSAD(net.petafuel.styx.core.persistence.layers.PersistentSAD) BankLookupFailedException(net.petafuel.styx.core.banklookup.exceptions.BankLookupFailedException) MethodSource(org.junit.jupiter.params.provider.MethodSource) Aspsp(net.petafuel.styx.core.banklookup.sad.entities.Aspsp) SAD(net.petafuel.styx.core.banklookup.sad.SAD) PersistentSAD(net.petafuel.styx.core.persistence.layers.PersistentSAD) MultipleFailuresError(org.opentest4j.MultipleFailuresError) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource) DisplayName(org.junit.jupiter.api.DisplayName)

Example 3 with BankNotFoundException

use of net.petafuel.styx.core.banklookup.exceptions.BankNotFoundException 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;
}
Also used : XS2ARequestClassProvider(net.petafuel.styx.core.xs2a.factory.XS2ARequestClassProvider) XS2AStandard(net.petafuel.styx.core.banklookup.XS2AStandard) AISInterface(net.petafuel.styx.core.xs2a.contracts.AISInterface) PISInterface(net.petafuel.styx.core.xs2a.contracts.PISInterface) InvocationTargetException(java.lang.reflect.InvocationTargetException) IXS2AHttpSigner(net.petafuel.styx.core.xs2a.contracts.IXS2AHttpSigner) Aspsp(net.petafuel.styx.core.banklookup.sad.entities.Aspsp) SADException(net.petafuel.styx.core.xs2a.exceptions.SADException) Version(net.petafuel.styx.core.xs2a.utils.Version) BankLookupFailedException(net.petafuel.styx.core.banklookup.exceptions.BankLookupFailedException) CSInterface(net.petafuel.styx.core.xs2a.contracts.CSInterface) BankNotFoundException(net.petafuel.styx.core.banklookup.exceptions.BankNotFoundException) PIISInterface(net.petafuel.styx.core.xs2a.contracts.PIISInterface)

Example 4 with BankNotFoundException

use of net.petafuel.styx.core.banklookup.exceptions.BankNotFoundException in project styx by petafuel.

the class SADInitialisationFilter method filter.

@Override
public void filter(ContainerRequestContext containerRequestContext) throws IOException {
    if (containerRequestContext.getProperty(BICFilter.class.getName()) == null) {
        LOG.info("XS2AStandard was not initialized as there was no BICFilter in place for the requested Resource");
        return;
    }
    String bic = (String) containerRequestContext.getProperty(BICFilter.class.getName());
    XS2AStandard xs2AStandard;
    try {
        xs2AStandard = new SAD().getBankByBIC(bic, WebServer.isSandbox());
        if (Boolean.FALSE.equals(xs2AStandard.getAspsp().isActive())) {
            throw new StyxException(new ResponseEntity("ASPSP with bic=" + xs2AStandard.getAspsp().getBic() + " is inactive", ResponseConstant.SAD_ASPSP_INACTIVE, ResponseCategory.ERROR, ResponseOrigin.STYX));
        }
        LOG.info("XS2AStandard successfully initialized. bic={}, aspspName={}, aspspId={}, aspspGroup={}, aspspGroupId={}, standard={}, standardVersion={}, ais={}, cs={}, pis={}, piis={}, availableOptions={}", xs2AStandard.getAspsp().getBic(), xs2AStandard.getAspsp().getName(), xs2AStandard.getAspsp().getId(), xs2AStandard.getAspsp().getAspspGroup().getName(), xs2AStandard.getAspsp().getAspspGroup().getId(), xs2AStandard.getAspsp().getConfig().getStandard().getName(), xs2AStandard.getAspsp().getConfig().getStandard().getVersion(), xs2AStandard.getAis(), xs2AStandard.getCs(), xs2AStandard.getPis(), xs2AStandard.getPiis(), xs2AStandard.getAspsp().getConfig().getImplementerOptions() != null ? xs2AStandard.getAspsp().getConfig().getImplementerOptions().size() : 0);
    } catch (BankNotFoundException bicNotFound) {
        throw new StyxException(new ResponseEntity(bicNotFound.getMessage(), ResponseConstant.SAD_ASPSP_NOT_FOUND, ResponseCategory.ERROR, ResponseOrigin.STYX));
    } catch (BankLookupFailedException internalSADError) {
        throw new StyxException(new ResponseEntity("SAD was unable to initialize required Services", ResponseConstant.INTERNAL_SERVER_ERROR, ResponseCategory.ERROR, ResponseOrigin.STYX), internalSADError);
    }
    containerRequestContext.setProperty(XS2AStandard.class.getName(), xs2AStandard);
}
Also used : XS2AStandard(net.petafuel.styx.core.banklookup.XS2AStandard) ResponseEntity(net.petafuel.styx.api.exception.ResponseEntity) SAD(net.petafuel.styx.core.banklookup.sad.SAD) BankLookupFailedException(net.petafuel.styx.core.banklookup.exceptions.BankLookupFailedException) StyxException(net.petafuel.styx.api.exception.StyxException) BankNotFoundException(net.petafuel.styx.core.banklookup.exceptions.BankNotFoundException)

Example 5 with BankNotFoundException

use of net.petafuel.styx.core.banklookup.exceptions.BankNotFoundException in project styx by petafuel.

the class ASPSPProcessor method process.

/**
 * @param bic - BIC provided by the client
 * @return ASPSPResponse | null
 */
public static ASPSPResponse process(String bic) {
    try {
        Aspsp aspsp = getAspspByBic(bic);
        if (Objects.nonNull(aspsp)) {
            ASPSPResponse aspspResponse = new ASPSPResponse();
            Map<String, ImplementerOption> implementerOptions = aspsp.getConfig().getImplementerOptions();
            SupportedServicesPIS supportedServicesPIS = processSupportedServicesPis(implementerOptions);
            SupportedServicesAIS supportedServicesAIS = processSupportedServicesAis(implementerOptions);
            SupportedServicesCOF supportedServicesCOF = processSupportedServicesCof();
            SupportedServices supportedServices = new SupportedServices(supportedServicesPIS, supportedServicesAIS, supportedServicesCOF);
            aspspResponse.setName(aspsp.getName());
            aspspResponse.setActive(aspsp.isActive());
            aspspResponse.setScaApproaches(processScaApproaches(implementerOptions));
            aspspResponse.setSupportedServices(supportedServices);
            aspspResponse.setPrestepRequired(processPrestepRequired(implementerOptions));
            aspspResponse.setMulticurrencyAccountsSupported(proccessMulticurrencyAccountsSupported(implementerOptions));
            return aspspResponse;
        } else {
            return null;
        }
    } catch (BankNotFoundException | BankLookupFailedException bankNotFoundException) {
        LOG.error("Bank not found for bic={} in SAD", bic);
        return null;
    }
}
Also used : Aspsp(net.petafuel.styx.core.banklookup.sad.entities.Aspsp) ASPSPResponse(net.petafuel.styx.api.v1.sad.entity.ASPSPResponse) SupportedServicesAIS(net.petafuel.styx.api.v1.sad.entity.SupportedServicesAIS) SupportedServicesPIS(net.petafuel.styx.api.v1.sad.entity.SupportedServicesPIS) SupportedServicesCOF(net.petafuel.styx.api.v1.sad.entity.SupportedServicesCOF) SupportedServices(net.petafuel.styx.api.v1.sad.entity.SupportedServices) BankLookupFailedException(net.petafuel.styx.core.banklookup.exceptions.BankLookupFailedException) ImplementerOption(net.petafuel.styx.core.banklookup.sad.entities.ImplementerOption) BankNotFoundException(net.petafuel.styx.core.banklookup.exceptions.BankNotFoundException)

Aggregations

BankLookupFailedException (net.petafuel.styx.core.banklookup.exceptions.BankLookupFailedException)6 BankNotFoundException (net.petafuel.styx.core.banklookup.exceptions.BankNotFoundException)6 SAD (net.petafuel.styx.core.banklookup.sad.SAD)4 Aspsp (net.petafuel.styx.core.banklookup.sad.entities.Aspsp)4 XS2AStandard (net.petafuel.styx.core.banklookup.XS2AStandard)3 Connection (java.sql.Connection)2 PreparedStatement (java.sql.PreparedStatement)2 ResultSet (java.sql.ResultSet)2 SQLException (java.sql.SQLException)2 Stream (java.util.stream.Stream)2 Persistence (net.petafuel.styx.core.persistence.Persistence)2 PersistentSAD (net.petafuel.styx.core.persistence.layers.PersistentSAD)2 Assert (org.junit.Assert)2 Assertions (org.junit.jupiter.api.Assertions)2 DisplayName (org.junit.jupiter.api.DisplayName)2 Tag (org.junit.jupiter.api.Tag)2 Test (org.junit.jupiter.api.Test)2 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)2 Arguments (org.junit.jupiter.params.provider.Arguments)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1