Search in sources :

Example 6 with EbicsSession

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

the class EbicsService method fetchFile.

private File fetchFile(OrderType orderType, EbicsUser user, EbicsProduct product, Date start, Date end, String fileFormat) throws AxelorException {
    EbicsSession session = new EbicsSession(user);
    File file = null;
    try {
        boolean test = isTest(user);
        if (test) {
            session.addSessionParam("TEST", "true");
        }
        if (fileFormat != null) {
            session.addSessionParam("FORMAT", fileFormat);
        }
        if (product == null) {
            product = defaultProduct;
        }
        session.setProduct(product);
        FileTransfer transferManager = new FileTransfer(session);
        file = File.createTempFile(user.getName(), "." + orderType.getOrderType());
        transferManager.fetchFile(orderType, start, end, new FileOutputStream(file));
        addResponseFile(user, file);
        userService.getNextOrderId(user);
    } catch (AxelorException e) {
        TraceBackService.trace(e);
        throw e;
    } catch (IOException e) {
        TraceBackService.trace(e);
        throw new AxelorException(e, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR);
    }
    return file;
}
Also used : AxelorException(com.axelor.exception.AxelorException) FileOutputStream(java.io.FileOutputStream) FileTransfer(com.axelor.apps.bankpayment.ebics.client.FileTransfer) IOException(java.io.IOException) File(java.io.File) EbicsSession(com.axelor.apps.bankpayment.ebics.client.EbicsSession)

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