Search in sources :

Example 1 with EbicsSession

use of com.axelor.apps.bankpayment.ebics.client.EbicsSession in project axelor-open-suite by axelor.

the class EbicsService method sendSPRRequest.

/**
 * Sends the SPR order to the bank.
 *
 * @param userId the user ID
 * @param product the session product
 * @throws AxelorException
 */
@Transactional
public void sendSPRRequest(EbicsUser ebicsUser, EbicsProduct product) throws AxelorException {
    EbicsSession session = new EbicsSession(ebicsUser);
    if (product == null) {
        product = defaultProduct;
    }
    session.setProduct(product);
    KeyManagement keyManager = new KeyManagement(session);
    try {
        keyManager.lockAccess();
        ebicsUser.setStatusSelect(EbicsUserRepository.STATUS_WAITING_SENDING_SIGNATURE_CERTIFICATE);
        userService.getNextOrderId(ebicsUser);
        userRepo.save(ebicsUser);
    } catch (Exception e) {
        TraceBackService.trace(e);
        throw new AxelorException(e, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR);
    }
}
Also used : AxelorException(com.axelor.exception.AxelorException) KeyManagement(com.axelor.apps.bankpayment.ebics.client.KeyManagement) EbicsSession(com.axelor.apps.bankpayment.ebics.client.EbicsSession) InvalidKeySpecException(java.security.spec.InvalidKeySpecException) JDOMException(org.jdom.JDOMException) AxelorException(com.axelor.exception.AxelorException) IOException(java.io.IOException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) Transactional(com.google.inject.persist.Transactional)

Example 2 with EbicsSession

use of com.axelor.apps.bankpayment.ebics.client.EbicsSession in project axelor-open-suite by axelor.

the class EbicsService method sendINIRequest.

/**
 * Sends an INI request to the ebics bank server
 *
 * @param userId the user ID
 * @param product the application product
 * @throws AxelorException
 * @throws JDOMException
 * @throws IOException
 */
@Transactional
public void sendINIRequest(EbicsUser ebicsUser, EbicsProduct product) throws AxelorException {
    if (ebicsUser.getStatusSelect() != EbicsUserRepository.STATUS_WAITING_SENDING_SIGNATURE_CERTIFICATE) {
        return;
    }
    try {
        userService.getNextOrderId(ebicsUser);
        EbicsSession session = new EbicsSession(ebicsUser);
        if (product == null) {
            product = defaultProduct;
        }
        session.setProduct(product);
        KeyManagement keyManager = new KeyManagement(session);
        keyManager.sendINI();
        ebicsUser.setStatusSelect(EbicsUserRepository.STATUS_WAITING_AUTH_AND_ENCRYPT_CERTIFICATES);
        userRepo.save(ebicsUser);
    } catch (Exception e) {
        TraceBackService.trace(e);
        throw new AxelorException(e, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR);
    }
}
Also used : AxelorException(com.axelor.exception.AxelorException) KeyManagement(com.axelor.apps.bankpayment.ebics.client.KeyManagement) EbicsSession(com.axelor.apps.bankpayment.ebics.client.EbicsSession) InvalidKeySpecException(java.security.spec.InvalidKeySpecException) JDOMException(org.jdom.JDOMException) AxelorException(com.axelor.exception.AxelorException) IOException(java.io.IOException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) Transactional(com.google.inject.persist.Transactional)

Example 3 with EbicsSession

use of com.axelor.apps.bankpayment.ebics.client.EbicsSession in project axelor-open-suite by axelor.

the class EbicsService method sendFULRequest.

/**
 * Sends a file to the ebics bank sever
 *
 * @param path the file path to send
 * @param userId the user ID that sends the file.
 * @param product the application product.
 * @throws AxelorException
 */
private void sendFULRequest(EbicsUser transportUser, EbicsUser signatoryUser, EbicsProduct product, File file, String format, File signature) throws AxelorException {
    EbicsSession session = new EbicsSession(transportUser, signatoryUser);
    boolean test = isTest(transportUser);
    if (test) {
        session.addSessionParam("TEST", "true");
    }
    if (file == null) {
        throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, "File is required to send FUL request");
    }
    EbicsPartner ebicsPartner = transportUser.getEbicsPartner();
    if (ebicsPartner.getEbicsTypeSelect() == EbicsPartnerRepository.EBICS_TYPE_TS) {
        if (signature == null) {
            throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, "Signature file is required to send FUL request");
        }
        if (signatoryUser == null) {
            throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, "Signatory user is required to send FUL request");
        }
    }
    session.addSessionParam("EBCDIC", "false");
    session.addSessionParam("FORMAT", format);
    if (product == null) {
        product = defaultProduct;
    }
    session.setProduct(product);
    FileTransfer transferManager = new FileTransfer(session);
    try {
        if (ebicsPartner.getEbicsTypeSelect() == EbicsPartnerRepository.EBICS_TYPE_TS) {
            transferManager.sendFile(IOUtils.getFileContent(file.getAbsolutePath()), OrderType.FUL, IOUtils.getFileContent(signature.getAbsolutePath()));
        } else {
            transferManager.sendFile(IOUtils.getFileContent(file.getAbsolutePath()), OrderType.FUL, null);
        }
        userService.getNextOrderId(transportUser);
    } catch (IOException | AxelorException e) {
        TraceBackService.trace(e);
        throw new AxelorException(e, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR);
    }
    try {
        if (ebicsPartner.getUsePSR()) {
            sendFDLRequest(transportUser, product, null, null, ebicsPartner.getpSRBankStatementFileFormat().getStatementFileFormatSelect());
        }
    } catch (AxelorException e) {
        TraceBackService.trace(e);
    }
}
Also used : AxelorException(com.axelor.exception.AxelorException) FileTransfer(com.axelor.apps.bankpayment.ebics.client.FileTransfer) IOException(java.io.IOException) EbicsPartner(com.axelor.apps.bankpayment.db.EbicsPartner) EbicsSession(com.axelor.apps.bankpayment.ebics.client.EbicsSession)

Example 4 with EbicsSession

use of com.axelor.apps.bankpayment.ebics.client.EbicsSession in project axelor-open-suite by axelor.

the class EbicsService method sendHPBRequest.

/**
 * Sends a HPB request to the ebics server.
 *
 * @param userId the user ID.
 * @param product the application product.
 * @throws AxelorException
 */
@Transactional
public X509Certificate[] sendHPBRequest(EbicsUser user, EbicsProduct product) throws AxelorException {
    EbicsSession session = new EbicsSession(user);
    if (product == null) {
        product = defaultProduct;
    }
    session.setProduct(product);
    KeyManagement keyManager = new KeyManagement(session);
    try {
        return keyManager.sendHPB();
    } catch (Exception e) {
        TraceBackService.trace(e);
        throw new AxelorException(e, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR);
    }
}
Also used : AxelorException(com.axelor.exception.AxelorException) KeyManagement(com.axelor.apps.bankpayment.ebics.client.KeyManagement) EbicsSession(com.axelor.apps.bankpayment.ebics.client.EbicsSession) InvalidKeySpecException(java.security.spec.InvalidKeySpecException) JDOMException(org.jdom.JDOMException) AxelorException(com.axelor.exception.AxelorException) IOException(java.io.IOException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) Transactional(com.google.inject.persist.Transactional)

Example 5 with EbicsSession

use of com.axelor.apps.bankpayment.ebics.client.EbicsSession in project axelor-open-suite by axelor.

the class EbicsService method sendHIARequest.

/**
 * Sends a HIA request to the ebics server.
 *
 * @param userId the user ID.
 * @param product the application product.
 * @throws AxelorException
 */
@Transactional
public void sendHIARequest(EbicsUser ebicsUser, EbicsProduct product) throws AxelorException {
    if (ebicsUser.getStatusSelect() != EbicsUserRepository.STATUS_WAITING_AUTH_AND_ENCRYPT_CERTIFICATES) {
        return;
    }
    userService.getNextOrderId(ebicsUser);
    EbicsSession session = new EbicsSession(ebicsUser);
    if (product == null) {
        product = defaultProduct;
    }
    session.setProduct(product);
    KeyManagement keyManager = new KeyManagement(session);
    try {
        keyManager.sendHIA();
        ebicsUser.setStatusSelect(EbicsUserRepository.STATUS_ACTIVE_CONNECTION);
        userRepo.save(ebicsUser);
    } catch (IOException | AxelorException | JDOMException e) {
        TraceBackService.trace(e);
        throw new AxelorException(e, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR);
    }
}
Also used : AxelorException(com.axelor.exception.AxelorException) KeyManagement(com.axelor.apps.bankpayment.ebics.client.KeyManagement) IOException(java.io.IOException) JDOMException(org.jdom.JDOMException) EbicsSession(com.axelor.apps.bankpayment.ebics.client.EbicsSession) Transactional(com.google.inject.persist.Transactional)

Aggregations

EbicsSession (com.axelor.apps.bankpayment.ebics.client.EbicsSession)6 AxelorException (com.axelor.exception.AxelorException)6 IOException (java.io.IOException)6 KeyManagement (com.axelor.apps.bankpayment.ebics.client.KeyManagement)4 Transactional (com.google.inject.persist.Transactional)4 JDOMException (org.jdom.JDOMException)4 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)3 InvalidKeySpecException (java.security.spec.InvalidKeySpecException)3 FileTransfer (com.axelor.apps.bankpayment.ebics.client.FileTransfer)2 EbicsPartner (com.axelor.apps.bankpayment.db.EbicsPartner)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1