Search in sources :

Example 1 with FileTransfer

use of com.axelor.apps.bankpayment.ebics.client.FileTransfer 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 2 with FileTransfer

use of com.axelor.apps.bankpayment.ebics.client.FileTransfer 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)2 FileTransfer (com.axelor.apps.bankpayment.ebics.client.FileTransfer)2 AxelorException (com.axelor.exception.AxelorException)2 IOException (java.io.IOException)2 EbicsPartner (com.axelor.apps.bankpayment.db.EbicsPartner)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1