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));
}
}
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);
}
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());
}
}
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();
}
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();
}
}
Aggregations