Search in sources :

Example 1 with EbicsPartner

use of com.axelor.apps.bankpayment.db.EbicsPartner in project axelor-open-suite by axelor.

the class EbicsPartnerServiceImpl method checkBankDetailsMissingCurrency.

public void checkBankDetailsMissingCurrency(EbicsPartner ebicsPartner) throws AxelorException {
    List<com.axelor.apps.bankpayment.db.EbicsPartnerService> ebicsPartnerServiceSet = ebicsPartner.getBoEbicsPartnerServiceList();
    if (ebicsPartnerServiceSet == null) {
        return;
    }
    boolean allowOrderCurrDiffFromBankDetails = false;
    for (com.axelor.apps.bankpayment.db.EbicsPartnerService ebicsPartnerService : ebicsPartnerServiceSet) {
        allowOrderCurrDiffFromBankDetails = ebicsPartnerService.getBankOrderFileFormat().getAllowOrderCurrDiffFromBankDetails();
        if (allowOrderCurrDiffFromBankDetails) {
            break;
        }
    }
    if (!allowOrderCurrDiffFromBankDetails) {
        return;
    }
    Set<BankDetails> bankDetailsSet = ebicsPartner.getBankDetailsSet();
    if (bankDetailsSet == null) {
        return;
    }
    List<String> bankDetailsWithoutCurrency = new ArrayList<>();
    for (BankDetails bankDetails : bankDetailsSet) {
        if (bankDetails.getCurrency() == null) {
            bankDetailsWithoutCurrency.add(bankDetails.getFullName());
        }
    }
    if (!bankDetailsWithoutCurrency.isEmpty()) {
        Function<String, String> addLi = s -> "<li>".concat(s).concat("</li>");
        throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, String.format(I18n.get(IExceptionMessage.EBICS_PARTNER_BANK_DETAILS_WARNING), "<ul>" + Joiner.on("").join(Iterables.transform(bankDetailsWithoutCurrency, addLi)) + "<ul>"), ebicsPartner);
    }
}
Also used : EbicsUser(com.axelor.apps.bankpayment.db.EbicsUser) Iterables(com.google.common.collect.Iterables) BankStatementFileFormat(com.axelor.apps.bankpayment.db.BankStatementFileFormat) Date(java.util.Date) Inject(com.google.inject.Inject) LocalDateTime(java.time.LocalDateTime) Transactional(com.google.inject.persist.Transactional) ArrayList(java.util.ArrayList) BankStatementRepository(com.axelor.apps.bankpayment.db.repo.BankStatementRepository) Lists(com.google.common.collect.Lists) AxelorException(com.axelor.exception.AxelorException) I18n(com.axelor.i18n.I18n) IExceptionMessage(com.axelor.apps.bankpayment.exception.IExceptionMessage) DateTool(com.axelor.apps.tool.date.DateTool) Function(com.google.common.base.Function) TraceBackRepository(com.axelor.exception.db.repo.TraceBackRepository) EbicsPartner(com.axelor.apps.bankpayment.db.EbicsPartner) Collection(java.util.Collection) TraceBackService(com.axelor.exception.service.TraceBackService) Set(java.util.Set) IOException(java.io.IOException) File(java.io.File) EbicsPartnerRepository(com.axelor.apps.bankpayment.db.repo.EbicsPartnerRepository) List(java.util.List) Beans(com.axelor.inject.Beans) BankStatement(com.axelor.apps.bankpayment.db.BankStatement) LocalDate(java.time.LocalDate) BankStatementCreateService(com.axelor.apps.bankpayment.service.bankstatement.BankStatementCreateService) BankDetails(com.axelor.apps.base.db.BankDetails) Joiner(com.google.common.base.Joiner) AxelorException(com.axelor.exception.AxelorException) BankDetails(com.axelor.apps.base.db.BankDetails) ArrayList(java.util.ArrayList)

Example 2 with EbicsPartner

use of com.axelor.apps.bankpayment.db.EbicsPartner 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 3 with EbicsPartner

use of com.axelor.apps.bankpayment.db.EbicsPartner in project axelor-open-suite by axelor.

the class EbicsUserImport method importEbicsUser.

public Object importEbicsUser(Object bean, Map<String, Object> context) {
    assert bean instanceof EbicsUser;
    EbicsUser user = (EbicsUser) bean;
    updateCertificate(user.getA005Certificate());
    updateCertificate(user.getE002Certificate());
    updateCertificate(user.getX002Certificate());
    EbicsPartner partner = user.getEbicsPartner();
    if (partner != null) {
        EbicsBank ebicsBank = partner.getEbicsBank();
        if (ebicsBank.getVersion() == 0) {
            for (EbicsCertificate cert : ebicsBank.getEbicsCertificateList()) {
                updateCertificate(cert);
            }
            Bank bank = ebicsBank.getBank();
            if (bank.getVersion() == 0) {
                bankService.computeFullName(bank);
                bankService.splitBic(bank);
            }
        }
    }
    return user;
}
Also used : EbicsCertificate(com.axelor.apps.bankpayment.db.EbicsCertificate) EbicsBank(com.axelor.apps.bankpayment.db.EbicsBank) Bank(com.axelor.apps.base.db.Bank) EbicsUser(com.axelor.apps.bankpayment.db.EbicsUser) EbicsPartner(com.axelor.apps.bankpayment.db.EbicsPartner) EbicsBank(com.axelor.apps.bankpayment.db.EbicsBank)

Example 4 with EbicsPartner

use of com.axelor.apps.bankpayment.db.EbicsPartner in project axelor-open-suite by axelor.

the class UInitializationRequestElement method buildInitialization.

@Override
public void buildInitialization() throws AxelorException {
    EbicsRequest request;
    Header header;
    Body body;
    MutableHeaderType mutable;
    StaticHeaderType xstatic;
    Product product;
    BankPubKeyDigests bankPubKeyDigests;
    Authentication authentication;
    Encryption encryption;
    DataTransferRequestType dataTransfer;
    DataEncryptionInfo dataEncryptionInfo;
    SignatureData signatureData;
    EncryptionPubKeyDigest encryptionPubKeyDigest;
    StaticHeaderOrderDetailsType orderDetails;
    FULOrderParamsType fULOrderParams;
    OrderType orderType;
    FileFormatType fileFormat;
    List<Parameter> parameters;
    EbicsUser ebicsUser = session.getUser();
    EbicsPartner ebicsPartner = ebicsUser.getEbicsPartner();
    if (ebicsPartner.getEbicsTypeSelect() == EbicsPartnerRepository.EBICS_TYPE_TS) {
        EbicsUser signatoryUser = session.getSignatoryUser();
        userSignature = new UserSignature(signatoryUser, generateName("UserSignature"), "A005", userData, userSignatureData);
    } else {
        userSignature = new UserSignature(ebicsUser, generateName("UserSignature"), "A005", userData, null);
    }
    userSignature.build();
    log.debug("user signature pretty print : {}", userSignature.toString());
    userSignature.validate();
    log.debug("user signature pretty print : {}", userSignature.toString());
    splitter.readInput(true, keySpec);
    mutable = EbicsXmlFactory.createMutableHeaderType("Initialisation", null);
    product = EbicsXmlFactory.createProduct(session.getProduct().getLanguage(), session.getProduct().getName());
    authentication = EbicsXmlFactory.createAuthentication("X002", "http://www.w3.org/2001/04/xmlenc#sha256", decodeHex(KeyUtil.getKeyDigest(session.getBankX002Key())));
    encryption = EbicsXmlFactory.createEncryption("E002", "http://www.w3.org/2001/04/xmlenc#sha256", decodeHex(KeyUtil.getKeyDigest(session.getBankE002Key())));
    bankPubKeyDigests = EbicsXmlFactory.createBankPubKeyDigests(authentication, encryption);
    orderType = EbicsXmlFactory.createOrderType(type.getOrderType());
    fileFormat = EbicsXmlFactory.createFileFormatType(Locale.FRANCE.getCountry(), session.getSessionParam("FORMAT"));
    fULOrderParams = EbicsXmlFactory.createFULOrderParamsType(fileFormat);
    parameters = new ArrayList<Parameter>();
    if (Boolean.valueOf(session.getSessionParam("TEST")).booleanValue()) {
        Parameter parameter;
        Value value;
        value = EbicsXmlFactory.createValue("String", "TRUE");
        parameter = EbicsXmlFactory.createParameter("TEST", value);
        parameters.add(parameter);
    }
    if (Boolean.valueOf(session.getSessionParam("EBCDIC")).booleanValue()) {
        Parameter parameter;
        Value value;
        value = EbicsXmlFactory.createValue("String", "TRUE");
        parameter = EbicsXmlFactory.createParameter("EBCDIC", value);
        parameters.add(parameter);
    }
    if (parameters.size() > 0) {
        fULOrderParams.setParameterArray(parameters.toArray(new Parameter[parameters.size()]));
    }
    OrderAttribute orderAttribute = new OrderAttribute(type, ebicsPartner.getEbicsTypeSelect());
    orderAttribute.build();
    orderDetails = EbicsXmlFactory.createStaticHeaderOrderDetailsType(ebicsUser.getNextOrderId(), orderAttribute.getOrderAttributes(), orderType, fULOrderParams);
    xstatic = EbicsXmlFactory.createStaticHeaderType(session.getBankID(), nonce, splitter.getSegmentNumber(), ebicsPartner.getPartnerId(), product, ebicsUser.getSecurityMedium(), ebicsUser.getUserId(), Calendar.getInstance(), orderDetails, bankPubKeyDigests);
    header = EbicsXmlFactory.createEbicsRequestHeader(true, mutable, xstatic);
    encryptionPubKeyDigest = EbicsXmlFactory.createEncryptionPubKeyDigest("E002", "http://www.w3.org/2001/04/xmlenc#sha256", decodeHex(KeyUtil.getKeyDigest(session.getBankE002Key())));
    System.out.println("signature ----------------------------------------------------------------------------");
    System.out.println(userSignature.toString());
    // USE PREVALIDATION
    // PreValidation preValidation = PreValidation.Factory.newInstance();
    // preValidation.setAuthenticate(true);
    // DataDigestType dataDigest = DataDigestType.Factory.newInstance();
    // dataDigest.setSignatureVersion("A005");
    // dataDigest.setStringValue("XXXXXXX);
    // preValidation.setDataDigestArray(new DataDigestType[] {dataDigest});
    signatureData = EbicsXmlFactory.createSignatureData(true, EbicsUtils.encrypt(EbicsUtils.zip(userSignature.prettyPrint()), keySpec));
    dataEncryptionInfo = EbicsXmlFactory.createDataEncryptionInfo(true, encryptionPubKeyDigest, generateTransactionKey());
    dataTransfer = EbicsXmlFactory.createDataTransferRequestType(dataEncryptionInfo, signatureData);
    // USE PREVALIDATION
    // body = EbicsXmlFactory.createEbicsRequestBody(dataTransfer, preValidation);
    body = EbicsXmlFactory.createEbicsRequestBody(dataTransfer);
    request = EbicsXmlFactory.createEbicsRequest(1, "H003", header, body);
    document = EbicsXmlFactory.createEbicsRequestDocument(request);
    ByteArrayOutputStream bout = new ByteArrayOutputStream();
    try {
        this.save(bout);
    } catch (JDOMException e) {
        // TODO Bloc catch généré automatiquement
        e.printStackTrace();
    }
    System.out.println("Requete signature ----------------------------------------------------------------------------");
    System.out.println(bout.toString());
}
Also used : EbicsRequest(com.axelor.apps.account.ebics.schema.h003.EbicsRequestDocument.EbicsRequest) DataTransferRequestType(com.axelor.apps.account.ebics.schema.h003.DataTransferRequestType) Product(com.axelor.apps.account.ebics.schema.h003.StaticHeaderType.Product) StaticHeaderOrderDetailsType(com.axelor.apps.account.ebics.schema.h003.StaticHeaderOrderDetailsType) StaticHeaderType(com.axelor.apps.account.ebics.schema.h003.StaticHeaderType) Encryption(com.axelor.apps.account.ebics.schema.h003.StaticHeaderType.BankPubKeyDigests.Encryption) DataEncryptionInfo(com.axelor.apps.account.ebics.schema.h003.DataTransferRequestType.DataEncryptionInfo) EbicsPartner(com.axelor.apps.bankpayment.db.EbicsPartner) OrderType(com.axelor.apps.account.ebics.schema.h003.StaticHeaderOrderDetailsType.OrderType) OrderAttribute(com.axelor.apps.bankpayment.ebics.client.OrderAttribute) Body(com.axelor.apps.account.ebics.schema.h003.EbicsRequestDocument.EbicsRequest.Body) EncryptionPubKeyDigest(com.axelor.apps.account.ebics.schema.h003.DataEncryptionInfoType.EncryptionPubKeyDigest) FileFormatType(com.axelor.apps.account.ebics.schema.h003.FileFormatType) EbicsUser(com.axelor.apps.bankpayment.db.EbicsUser) ByteArrayOutputStream(java.io.ByteArrayOutputStream) JDOMException(org.jdom.JDOMException) BankPubKeyDigests(com.axelor.apps.account.ebics.schema.h003.StaticHeaderType.BankPubKeyDigests) MutableHeaderType(com.axelor.apps.account.ebics.schema.h003.MutableHeaderType) SignatureData(com.axelor.apps.account.ebics.schema.h003.DataTransferRequestType.SignatureData) Header(com.axelor.apps.account.ebics.schema.h003.EbicsRequestDocument.EbicsRequest.Header) Authentication(com.axelor.apps.account.ebics.schema.h003.StaticHeaderType.BankPubKeyDigests.Authentication) Value(com.axelor.apps.account.ebics.schema.h003.ParameterDocument.Parameter.Value) Parameter(com.axelor.apps.account.ebics.schema.h003.ParameterDocument.Parameter) FULOrderParamsType(com.axelor.apps.account.ebics.schema.h003.FULOrderParamsType)

Example 5 with EbicsPartner

use of com.axelor.apps.bankpayment.db.EbicsPartner in project axelor-open-suite by axelor.

the class NoPubKeyDigestsRequestElement method build.

@Override
public void build() throws AxelorException {
    EbicsNoPubKeyDigestsRequest request;
    Body body;
    Header header;
    EmptyMutableHeaderType mutable;
    NoPubKeyDigestsRequestStaticHeaderType xstatic;
    ProductElementType product;
    OrderDetailsType orderDetails;
    EbicsUser ebicsUser = session.getUser();
    EbicsPartner ebicsPartner = ebicsUser.getEbicsPartner();
    OrderAttribute orderAttribute = new OrderAttribute(OrderType.HPB, ebicsPartner.getEbicsTypeSelect());
    orderAttribute.build();
    product = EbicsXmlFactory.creatProductElementType(session.getProduct().getLanguage(), session.getProduct().getName());
    orderDetails = EbicsXmlFactory.createOrderDetailsType(orderAttribute.getOrderAttributes(), null, OrderType.HPB.getOrderType());
    xstatic = EbicsXmlFactory.createNoPubKeyDigestsRequestStaticHeaderType(session.getBankID(), EbicsUtils.generateNonce(), Calendar.getInstance(), ebicsPartner.getPartnerId(), ebicsUser.getUserId(), product, orderDetails, ebicsUser.getSecurityMedium());
    mutable = EbicsXmlFactory.createEmptyMutableHeaderType();
    header = EbicsXmlFactory.createDigestsRequestHeader(true, mutable, xstatic);
    body = EbicsXmlFactory.createDigestsRequestBody();
    request = EbicsXmlFactory.createEbicsNoPubKeyDigestsRequest(1, "H003", header, body);
    document = EbicsXmlFactory.createEbicsNoPubKeyDigestsRequestDocument(request);
}
Also used : OrderDetailsType(com.axelor.apps.account.ebics.schema.h003.OrderDetailsType) Header(com.axelor.apps.account.ebics.schema.h003.EbicsNoPubKeyDigestsRequestDocument.EbicsNoPubKeyDigestsRequest.Header) EbicsNoPubKeyDigestsRequest(com.axelor.apps.account.ebics.schema.h003.EbicsNoPubKeyDigestsRequestDocument.EbicsNoPubKeyDigestsRequest) EbicsUser(com.axelor.apps.bankpayment.db.EbicsUser) OrderAttribute(com.axelor.apps.bankpayment.ebics.client.OrderAttribute) ProductElementType(com.axelor.apps.account.ebics.schema.h003.ProductElementType) EbicsPartner(com.axelor.apps.bankpayment.db.EbicsPartner) Body(com.axelor.apps.account.ebics.schema.h003.EbicsNoPubKeyDigestsRequestDocument.EbicsNoPubKeyDigestsRequest.Body) NoPubKeyDigestsRequestStaticHeaderType(com.axelor.apps.account.ebics.schema.h003.NoPubKeyDigestsRequestStaticHeaderType) EmptyMutableHeaderType(com.axelor.apps.account.ebics.schema.h003.EmptyMutableHeaderType)

Aggregations

EbicsPartner (com.axelor.apps.bankpayment.db.EbicsPartner)13 EbicsUser (com.axelor.apps.bankpayment.db.EbicsUser)7 OrderAttribute (com.axelor.apps.bankpayment.ebics.client.OrderAttribute)4 EbicsRequest (com.axelor.apps.account.ebics.schema.h003.EbicsRequestDocument.EbicsRequest)3 Body (com.axelor.apps.account.ebics.schema.h003.EbicsRequestDocument.EbicsRequest.Body)3 Header (com.axelor.apps.account.ebics.schema.h003.EbicsRequestDocument.EbicsRequest.Header)3 MutableHeaderType (com.axelor.apps.account.ebics.schema.h003.MutableHeaderType)3 StaticHeaderOrderDetailsType (com.axelor.apps.account.ebics.schema.h003.StaticHeaderOrderDetailsType)3 OrderType (com.axelor.apps.account.ebics.schema.h003.StaticHeaderOrderDetailsType.OrderType)3 StaticHeaderType (com.axelor.apps.account.ebics.schema.h003.StaticHeaderType)3 BankPubKeyDigests (com.axelor.apps.account.ebics.schema.h003.StaticHeaderType.BankPubKeyDigests)3 Authentication (com.axelor.apps.account.ebics.schema.h003.StaticHeaderType.BankPubKeyDigests.Authentication)3 Encryption (com.axelor.apps.account.ebics.schema.h003.StaticHeaderType.BankPubKeyDigests.Encryption)3 Product (com.axelor.apps.account.ebics.schema.h003.StaticHeaderType.Product)3 BankStatement (com.axelor.apps.bankpayment.db.BankStatement)3 AxelorException (com.axelor.exception.AxelorException)3 EncryptionPubKeyDigest (com.axelor.apps.account.ebics.schema.h003.DataEncryptionInfoType.EncryptionPubKeyDigest)2 DataTransferRequestType (com.axelor.apps.account.ebics.schema.h003.DataTransferRequestType)2 DataEncryptionInfo (com.axelor.apps.account.ebics.schema.h003.DataTransferRequestType.DataEncryptionInfo)2 SignatureData (com.axelor.apps.account.ebics.schema.h003.DataTransferRequestType.SignatureData)2