Search in sources :

Example 81 with AxelorException

use of com.axelor.exception.AxelorException in project axelor-open-suite by axelor.

the class StockMoveServiceImpl method computeMasses.

private void computeMasses(StockMove stockMove) throws AxelorException {
    StockConfig stockConfig = stockMove.getCompany().getStockConfig();
    Unit endUnit = stockConfig != null ? stockConfig.getCustomsMassUnit() : null;
    boolean massesRequiredForStockMove = false;
    List<StockMoveLine> stockMoveLineList = stockMove.getStockMoveLineList();
    if (stockMoveLineList == null) {
        return;
    }
    UnitConversionService unitConversionService = Beans.get(UnitConversionService.class);
    for (StockMoveLine stockMoveLine : stockMoveLineList) {
        Product product = stockMoveLine.getProduct();
        boolean massesRequiredForStockMoveLine = stockMoveLineService.checkMassesRequired(stockMove, stockMoveLine);
        if (product == null || !ProductRepository.PRODUCT_TYPE_STORABLE.equals(product.getProductTypeSelect())) {
            continue;
        }
        BigDecimal netMass = stockMoveLine.getNetMass();
        if (netMass.signum() == 0) {
            Unit startUnit = product.getMassUnit();
            if (startUnit != null && endUnit != null) {
                netMass = unitConversionService.convert(startUnit, endUnit, product.getNetMass(), product.getNetMass().scale(), null);
                stockMoveLine.setNetMass(netMass);
            }
        }
        if (netMass.signum() != 0) {
            BigDecimal totalNetMass = netMass.multiply(stockMoveLine.getRealQty());
            stockMoveLine.setTotalNetMass(totalNetMass);
        } else if (massesRequiredForStockMoveLine) {
            throw new AxelorException(stockMove, TraceBackRepository.CATEGORY_NO_VALUE, I18n.get(IExceptionMessage.STOCK_MOVE_18));
        }
        if (!massesRequiredForStockMove && massesRequiredForStockMoveLine) {
            massesRequiredForStockMove = true;
        }
    }
    if (massesRequiredForStockMove && endUnit == null) {
        throw new AxelorException(stockMove, TraceBackRepository.CATEGORY_NO_VALUE, I18n.get(IExceptionMessage.STOCK_MOVE_17));
    }
}
Also used : AxelorException(com.axelor.exception.AxelorException) UnitConversionService(com.axelor.apps.base.service.UnitConversionService) StockConfig(com.axelor.apps.stock.db.StockConfig) StockMoveLine(com.axelor.apps.stock.db.StockMoveLine) Product(com.axelor.apps.base.db.Product) Unit(com.axelor.apps.base.db.Unit) BigDecimal(java.math.BigDecimal)

Example 82 with AxelorException

use of com.axelor.exception.AxelorException in project axelor-open-suite by axelor.

the class DepositSlipAccountRepository method setDepositNumber.

private void setDepositNumber(DepositSlip entity) throws AxelorException {
    SequenceService sequenceService = Beans.get(SequenceService.class);
    String depositNumber = sequenceService.getSequenceNumber(SequenceRepository.DEPOSIT_SLIP, entity.getCompany());
    if (Strings.isNullOrEmpty(depositNumber)) {
        throw new AxelorException(Sequence.class, TraceBackRepository.CATEGORY_NO_VALUE, I18n.get(IExceptionMessage.DEPOSIT_SLIP_MISSING_SEQUENCE), entity.getCompany().getName());
    }
    entity.setDepositNumber(depositNumber);
}
Also used : AxelorException(com.axelor.exception.AxelorException) SequenceService(com.axelor.apps.base.service.administration.SequenceService)

Example 83 with AxelorException

use of com.axelor.exception.AxelorException in project axelor-open-suite by axelor.

the class EbicsUtils method canonize.

/**
 * Canonizes an input with inclusive c14n without comments algorithm.
 *
 * <p>EBICS Specification 2.4.2 - 5.5.1.1.1 EBICS messages in transaction initialization:
 *
 * <p>The identification and authentication signature includes all XML elements of the EBICS
 * request whose attribute value for @authenticate is equal to “true”. The definition of the XML
 * schema “ebics_request.xsd“ guarantees that the value of the attribute @authenticate is equal to
 * “true” for precisely those elements that also need to be signed.
 *
 * <p>Thus, All the Elements with the attribute authenticate = true and their sub elements are
 * considered for the canonization process. This is performed via the {@link
 * XPathAPI#selectNodeIterator(Node, String) selectNodeIterator(Node, String)}.
 *
 * @param input the byte array XML input.
 * @return the canonized form of the given XML
 * @throws EbicsException
 */
public static byte[] canonize(byte[] input) throws AxelorException {
    DocumentBuilderFactory factory;
    DocumentBuilder builder;
    Document document;
    NodeIterator iter;
    ByteArrayOutputStream output;
    Node node;
    try {
        factory = Beans.get(XPathParse.class).getDocumentBuilderFactory();
        factory.setNamespaceAware(true);
        factory.setValidating(true);
        builder = factory.newDocumentBuilder();
        builder.setErrorHandler(new IgnoreAllErrorHandler());
        document = builder.parse(new ByteArrayInputStream(input));
        iter = XPathAPI.selectNodeIterator(document, "//*[@authenticate='true']");
        output = new ByteArrayOutputStream();
        while ((node = iter.nextNode()) != null) {
            Canonicalizer canonicalizer;
            canonicalizer = Canonicalizer.getInstance(Canonicalizer.ALGO_ID_C14N_OMIT_COMMENTS);
            output.write(canonicalizer.canonicalizeSubtree(node));
        }
        return output.toByteArray();
    } catch (Exception e) {
        throw new AxelorException(e.getCause(), TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, e.getMessage());
    }
}
Also used : NodeIterator(org.w3c.dom.traversal.NodeIterator) AxelorException(com.axelor.exception.AxelorException) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) IgnoreAllErrorHandler(org.apache.xml.security.utils.IgnoreAllErrorHandler) DocumentBuilder(javax.xml.parsers.DocumentBuilder) ByteArrayInputStream(java.io.ByteArrayInputStream) Node(org.w3c.dom.Node) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Document(org.w3c.dom.Document) Canonicalizer(org.apache.xml.security.c14n.Canonicalizer) GeneralSecurityException(java.security.GeneralSecurityException) AxelorException(com.axelor.exception.AxelorException) DataFormatException(java.util.zip.DataFormatException) IOException(java.io.IOException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException)

Example 84 with AxelorException

use of com.axelor.exception.AxelorException in project axelor-open-suite by axelor.

the class EbicsUtils method unzip.

/**
 * Uncompresses a given byte array input.
 *
 * <p>The Decompression is ensured via Universal compression algorithm (RFC 1950, RFC 1951) As
 * specified in the EBICS specification (16 Appendix: Standards and references)
 *
 * @param zip the zipped input.
 * @return the uncompressed data.
 */
public static byte[] unzip(byte[] zip) throws AxelorException {
    Inflater decompressor;
    ByteArrayOutputStream output;
    byte[] buf;
    decompressor = new Inflater();
    output = new ByteArrayOutputStream(zip.length);
    decompressor.setInput(zip);
    buf = new byte[1024];
    while (!decompressor.finished()) {
        int count;
        try {
            count = decompressor.inflate(buf);
        } catch (DataFormatException e) {
            throw new AxelorException(e.getCause(), TraceBackRepository.CATEGORY_INCONSISTENCY, e.getMessage());
        }
        output.write(buf, 0, count);
    }
    try {
        output.close();
    } catch (IOException e) {
        throw new AxelorException(e.getCause(), TraceBackRepository.CATEGORY_INCONSISTENCY, e.getMessage());
    }
    decompressor.end();
    return output.toByteArray();
}
Also used : AxelorException(com.axelor.exception.AxelorException) DataFormatException(java.util.zip.DataFormatException) Inflater(java.util.zip.Inflater) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException)

Example 85 with AxelorException

use of com.axelor.exception.AxelorException in project axelor-open-suite by axelor.

the class UnsecuredRequestElement method build.

@Override
public void build() throws AxelorException {
    Header header;
    Body body;
    EmptyMutableHeaderType mutable;
    UnsecuredRequestStaticHeaderType xstatic;
    ProductElementType productType;
    OrderDetailsType orderDetails;
    DataTransfer dataTransfer;
    OrderData orderData;
    EbicsUnsecuredRequest request;
    orderDetails = EbicsXmlFactory.createOrderDetailsType("DZNNN", session.getUser().getNextOrderId(), orderType.getOrderType());
    productType = EbicsXmlFactory.creatProductElementType(Optional.ofNullable(AuthUtils.getUser()).map(User::getLanguage).orElse(null), session.getProduct().getName());
    try {
        xstatic = EbicsXmlFactory.createUnsecuredRequestStaticHeaderType(session.getBankID(), session.getUser().getEbicsPartner().getPartnerId(), session.getUser().getUserId(), productType, orderDetails, session.getUser().getSecurityMedium());
        mutable = EbicsXmlFactory.createEmptyMutableHeaderType();
        header = EbicsXmlFactory.createHeader(true, mutable, xstatic);
        orderData = EbicsXmlFactory.createOrderData(this.orderData);
        dataTransfer = EbicsXmlFactory.createDataTransfer(orderData);
        body = EbicsXmlFactory.createBody(dataTransfer);
        request = EbicsXmlFactory.createEbicsUnsecuredRequest(header, body, 1, "H003");
        document = EbicsXmlFactory.createEbicsUnsecuredRequestDocument(request);
    } catch (AxelorException e) {
        e.printStackTrace();
    }
}
Also used : AxelorException(com.axelor.exception.AxelorException) OrderDetailsType(com.axelor.apps.account.ebics.schema.h003.OrderDetailsType) Header(com.axelor.apps.account.ebics.schema.h003.EbicsUnsecuredRequestDocument.EbicsUnsecuredRequest.Header) DataTransfer(com.axelor.apps.account.ebics.schema.h003.EbicsUnsecuredRequestDocument.EbicsUnsecuredRequest.Body.DataTransfer) ProductElementType(com.axelor.apps.account.ebics.schema.h003.ProductElementType) OrderData(com.axelor.apps.account.ebics.schema.h003.EbicsUnsecuredRequestDocument.EbicsUnsecuredRequest.Body.DataTransfer.OrderData) EbicsUnsecuredRequest(com.axelor.apps.account.ebics.schema.h003.EbicsUnsecuredRequestDocument.EbicsUnsecuredRequest) Body(com.axelor.apps.account.ebics.schema.h003.EbicsUnsecuredRequestDocument.EbicsUnsecuredRequest.Body) EmptyMutableHeaderType(com.axelor.apps.account.ebics.schema.h003.EmptyMutableHeaderType) UnsecuredRequestStaticHeaderType(com.axelor.apps.account.ebics.schema.h003.UnsecuredRequestStaticHeaderType)

Aggregations

AxelorException (com.axelor.exception.AxelorException)546 Transactional (com.google.inject.persist.Transactional)126 BigDecimal (java.math.BigDecimal)118 ArrayList (java.util.ArrayList)84 IOException (java.io.IOException)73 Product (com.axelor.apps.base.db.Product)64 Company (com.axelor.apps.base.db.Company)63 LocalDate (java.time.LocalDate)58 Partner (com.axelor.apps.base.db.Partner)48 List (java.util.List)45 StockMoveLine (com.axelor.apps.stock.db.StockMoveLine)40 HashMap (java.util.HashMap)38 Invoice (com.axelor.apps.account.db.Invoice)33 StockMove (com.axelor.apps.stock.db.StockMove)32 Map (java.util.Map)31 Beans (com.axelor.inject.Beans)30 I18n (com.axelor.i18n.I18n)28 Inject (com.google.inject.Inject)28 MoveLine (com.axelor.apps.account.db.MoveLine)27 Context (com.axelor.rpc.Context)27