List of usage examples for java.math BigDecimal ROUND_HALF_UP
int ROUND_HALF_UP
To view the source code for java.math BigDecimal ROUND_HALF_UP.
Click Source Link
From source file:com.selfsoft.business.service.impl.TbBusinessBalanceServiceImpl.java
public List<TbBusinessBalance> findTbBusinessBalanceToGroup(TbBusinessBalance tbBusinessBalance) { String sql = "select new TbBusinessBalance(max(tbBusinessBalance.id),tbBusinessBalance.balanceCode,max(tbBusinessBalance.bananceDate),sum(tbBusinessBalance.balanceTotalAll),sum(tbBusinessBalance.shouldPayAmount),sum(tbBusinessBalance.workingHourTotalAll),sum(tbBusinessBalance.fixPartTotalAll),sum(tbBusinessBalance.solePartTotalAll)) from TbBusinessBalance tbBusinessBalance WHERE 1=1"; String sqlConditionSelect = "select tbBusinessBalance from TbBusinessBalance tbBusinessBalance where 1=1"; String sqlCondition = ""; String sqlGroup = " group by tbBusinessBalance.balanceCode"; if (null != tbBusinessBalance) { if (null != tbBusinessBalance.getId()) { /*/*from www . j ava 2 s . co m*/ * sqlCondition +=" and tbBusinessBalance.id = " + * tbBusinessBalance.getId(); */ TbBusinessBalance t = this.findById(tbBusinessBalance.getId()); tbBusinessBalance.setBalanceCode(t.getBalanceCode()); } if (null != tbBusinessBalance.getBalanceCode() && !"".equals(tbBusinessBalance.getBalanceCode())) { sqlCondition += " and tbBusinessBalance.balanceCode like '%" + tbBusinessBalance.getBalanceCode() + "%'"; } if (null != tbBusinessBalance.getEntrustCode() && !"".equals(tbBusinessBalance.getEntrustCode())) { sqlCondition += " and tbBusinessBalance.tbFixEntrust.entrustCode like '%" + tbBusinessBalance.getEntrustCode() + "%'"; } if (null != tbBusinessBalance.getBananceDateStart()) { sqlCondition += " and tbBusinessBalance.bananceDate>='" + CommonMethod.parseDateToString(tbBusinessBalance.getBananceDateStart(), "yyyy-MM-dd") + "'"; } if (null != tbBusinessBalance.getBananceDateEnd()) { sqlCondition += " and tbBusinessBalance.bananceDate<='" + CommonMethod.parseDateToString( CommonMethod.addDate(tbBusinessBalance.getBananceDateEnd(), 1), "yyyy-MM-dd") + "'"; } if (null != tbBusinessBalance.getTmUser()) { if (null != tbBusinessBalance.getTmUser().getId()) { sqlCondition += " and tbBusinessBalance.tmUser.id=" + tbBusinessBalance.getTmUser().getId(); } } if (null != tbBusinessBalance.getUserId()) { sqlCondition += " and tbBusinessBalance.tbFixEntrust.tmUser.id =" + tbBusinessBalance.getUserId() + ""; } if (null != tbBusinessBalance.getLicenseCode() && !"".equals(tbBusinessBalance.getLicenseCode())) { sqlCondition += " and tbBusinessBalance.tbFixEntrust.tbCarInfo.licenseCode like '%" + tbBusinessBalance.getLicenseCode() + "%'"; } if (null != tbBusinessBalance.getChassisCode() && !"".equals(tbBusinessBalance.getChassisCode())) { sqlCondition += " and tbBusinessBalance.tbFixEntrust.tbCarInfo.chassisCode like '%" + tbBusinessBalance.getChassisCode() + "%'"; } if (null != tbBusinessBalance.getCustomerName() && !"".equals(tbBusinessBalance.getCustomerName())) { sqlCondition += " and tbBusinessBalance.tbFixEntrust.tbCustomer.customerName = '" + tbBusinessBalance.getCustomerName() + "'"; } if (null != tbBusinessBalance.getCustomerCode() && !"".equals(tbBusinessBalance.getCustomerCode())) { sqlCondition += " and tbBusinessBalance.tbFixEntrust.tbCustomer.customerCode = '" + tbBusinessBalance.getCustomerCode() + "'"; } if (null != tbBusinessBalance.getTelephone() && !"".equals(tbBusinessBalance.getTelephone())) { sqlCondition += " and tbBusinessBalance.tbFixEntrust.tbCustomer.telephone = '" + tbBusinessBalance.getTelephone() + "'"; } if (null != tbBusinessBalance.getTmModelTypeId()) { sqlCondition += " and tbBusinessBalance.tbFixEntrust.tbCarInfo.tmCarModelType.id =" + tbBusinessBalance.getTmModelTypeId(); } if (null != tbBusinessBalance.getPayPattern()) { sqlCondition += " and tbBusinessBalance.payPattern = '" + tbBusinessBalance.getPayPattern() + "'"; } if (null != tbBusinessBalance.getTmFixTypeId()) { sqlCondition += " and tbBusinessBalance.tbFixEntrust.tmFixType.id =" + tbBusinessBalance.getTmFixTypeId() + ""; } } List<TbBusinessBalance> listCondition = tbBusinessBalanceDao.findBySQL(sqlConditionSelect + sqlCondition, null); List<TbBusinessBalance> list = tbBusinessBalanceDao.findBySQL(sql + sqlGroup, null); List<TbBusinessBalance> listReturn = new ArrayList<TbBusinessBalance>(); BigDecimal pjCostAll = new BigDecimal("0.00"); if (null != listCondition && listCondition.size() > 0 && null != list && list.size() > 0) { for (int i = list.size() - 1; i >= 0; i--) { TbBusinessBalance ti = list.get(i); for (int j = listCondition.size() - 1; j >= 0; j--) { TbBusinessBalance tj = listCondition.get(j); if (ti.getId().equals(tj.getId())) { ti.setPayPattern(tj.getPayPattern()); ti.setTbFixEntrust(tj.getTbFixEntrust()); ti.setTmStockOut(tj.getTmStockOut()); ti.setOldPartDeal(tj.getOldPartDeal()); ti.setRemark(tj.getRemark()); ti.setTmUser(tj.getTmUser()); TbCustomer tbCustomer = null; if (null != ti.getTbFixEntrust()) { tbCustomer = ti.getTbFixEntrust().getTbCarInfo().getTbCustomer(); ti.setLicenseCode(ti.getTbFixEntrust().getTbCarInfo().getLicenseCode()); Double pjCost = statisticsStockInOutService .sumStockDetailByEntrustId(ti.getTbFixEntrust().getId()); ti.setPjCost(new BigDecimal(pjCost).divide(new BigDecimal("1.00"), 2, BigDecimal.ROUND_HALF_UP)); pjCostAll = pjCostAll.add(new BigDecimal(pjCost)).divide(new BigDecimal("1.00"), 2, BigDecimal.ROUND_HALF_UP); ti.setPjCostAll(pjCostAll); BigDecimal djCost = tbFixEntrustCostService .sumTbFixEntrustCostByTbFixEntrustId(ti.getTbFixEntrust().getId()); ti.setDjCost(djCost.divide(new BigDecimal("1.00"), 2, BigDecimal.ROUND_HALF_UP)); ti.setUserRealNameServer(ti.getTbFixEntrust().getTmUser().getUserRealName()); } else { tbCustomer = tbCustomerService.findById(ti.getTmStockOut().getCustomerBill()); Double pjCost = tmStockOutService.sumSingleSellByBanalceCode(ti.getBalanceCode()); ti.setPjCost(new BigDecimal(pjCost).divide(new BigDecimal("1.00"), 2, BigDecimal.ROUND_HALF_UP)); pjCostAll = pjCostAll.add(new BigDecimal(pjCost)).divide(new BigDecimal("1.00"), 2, BigDecimal.ROUND_HALF_UP); ti.setPjCostAll(pjCostAll); } ti.setTbCustomer(tbCustomer); ti.setXlgsfFavourAmount(this.calcItemFavourAmount(ti, "XLGSF")); ti.setXlclfFavourAmount(this.calcItemFavourAmount(ti, "XLCLF")); ti.setXsjeFavourAmount(this.calcItemFavourAmount(ti, "XSJE")); String bananceDateStart_s = CommonMethod.parseDateToString(ti.getBananceDate(), "yyyy-MM-dd HH:ss:mm"); ti.setBananceDateStart_s(bananceDateStart_s); // if (ti.getOweAmount() > 0D) { BigDecimal d = new BigDecimal("0.00"); List<TbReceiveFree> tbReceiveFreeList = tbReceiveFreeService .findByBalanceId(ti.getId()); /** * ???? */ if (null != tbReceiveFreeList && tbReceiveFreeList.size() > 0) { for (TbReceiveFree tf : tbReceiveFreeList) { if (Constants.AMOUNTS.equals(tf.getAmountType())) { d = d.add(new BigDecimal(tf.getFeeAmount())); ti.setFreeAmount(tf.getFeeAmount()); } } } } listReturn.add(ti); break; } } } } return listReturn; }
From source file:tasly.greathealth.erp.order.services.impl.DefaultOrderUpdateService.java
private BigDecimal double2BigDecimal(final double refundAmount) { final BigDecimal decimal = new BigDecimal(Double.toString(refundAmount)); decimal.setScale(3, BigDecimal.ROUND_HALF_UP); if (decimal.precision() > 18) { erpOrderLog.warn(UO_LogHead + "Message: " + "refundAmount" + ": " + refundAmount + "," + decimal.precision() + ",?" + "(15,3)" + "."); erpOrderLog.warn(UO_LogHead + "Message:" + "refundAmount" + ",?????ECC."); }/*from w ww . ja v a 2 s.c o m*/ return decimal; }
From source file:com.exilant.eGov.src.common.EGovernCommon.java
public BigDecimal getAccountBalance(final String recDate, final String bankAccountId) throws TaskFailedException { BigDecimal opeAvailable = BigDecimal.ZERO; BigDecimal totalAvailable = BigDecimal.ZERO; Query pst = null;//from ww w . j a v a 2 s. com List<Object[]> resultset = null; List<Object[]> resultset1 = null; try { final String str = "SELECT case when sum(openingDebitBalance) is null then 0 else sum(openingDebitBalance) end - case when sum(openingCreditBalance) is null then 0 else sum(openingCreditBalance) end AS \"openingBalance\" " + " FROM transactionSummary WHERE financialYearId=( SELECT id FROM financialYear WHERE startingDate <=? " + " AND endingDate >=? ) AND glCodeId =(select glcodeid from bankaccount where id=? )"; if (LOGGER.isDebugEnabled()) LOGGER.debug("getAccountBalance(EGovernCommon.java): " + str); pst = persistenceService.getSession().createSQLQuery(str); SimpleDateFormat dtSlashFormat = new SimpleDateFormat("dd/MMM/yyyy"); Date reconDate = dtSlashFormat.parse(recDate); java.sql.Date sDate = new java.sql.Date(reconDate.getTime()); pst.setDate(0, sDate); pst.setDate(1, sDate); pst.setInteger(2, Integer.valueOf(bankAccountId)); List list = pst.list(); if (list == null || list.size() == 0) if (LOGGER.isDebugEnabled()) LOGGER.debug("Else resultset in getAccountBalance..."); if (list != null || list.size() > 0) { opeAvailable = new BigDecimal(list.get(0).toString()); } /* for (final Object[] element : resultset) { if(element[0]!=null) opeAvailable = new BigDecimal(element[0].toString()); }*/ if (LOGGER.isDebugEnabled()) LOGGER.debug("opening balance " + opeAvailable); final String str1 = "SELECT (case when sum(gl.debitAmount) is null then 0 else sum(gl.debitAmount) end - case when sum(gl.creditAmount) is null then 0 else sum(gl.creditAmount) end ) + " + opeAvailable + " as \"totalAmount\" FROM generalLedger gl, voucherHeader vh WHERE vh.id = gl.voucherHeaderId and gl.glCodeid = (select glcodeid from bankaccount where id=?) AND " + " vh.voucherDate >=( SELECT startingDate FROM financialYear WHERE startingDate <= ? AND endingDate >= ?) AND vh.voucherDate <= ? and vh.status!=4"; if (LOGGER.isDebugEnabled()) LOGGER.debug("Curr Yr Bal: " + str1); pst = persistenceService.getSession().createSQLQuery(str1); pst.setInteger(0, Integer.valueOf(bankAccountId)); pst.setDate(1, reconDate); pst.setDate(2, reconDate); pst.setDate(3, reconDate); List list2 = pst.list(); if (list2 != null) totalAvailable = new BigDecimal(list2.get(0).toString()); if (LOGGER.isDebugEnabled()) LOGGER.debug("total balance " + totalAvailable); if (resultset1 == null || resultset1.size() == 0) if (LOGGER.isDebugEnabled()) LOGGER.debug("Else resultset in getAccountBalance..."); totalAvailable = totalAvailable.setScale(2, BigDecimal.ROUND_HALF_UP); if (LOGGER.isDebugEnabled()) LOGGER.debug("total balance before return " + totalAvailable); return totalAvailable; } catch (final Exception e) { LOGGER.error(e.getMessage(), e); throw taskExc; } }
From source file:org.egov.ptis.service.dashboard.SurveyDashboardService.java
private Map<String, List<Map<String, BigDecimal>>> getApprovedTaxes(SearchResponse approvedResponse) { Terms approvedAggr = approvedResponse.getAggregations().get(AGGREGATIONWISE); Map<String, List<Map<String, BigDecimal>>> totalMap = new ConcurrentHashMap<>(); for (Bucket appBucket : approvedAggr.getBuckets()) { List<Map<String, BigDecimal>> list = new ArrayList<>(); Map<String, BigDecimal> approvedSystemMap = new ConcurrentHashMap<>(); Map<String, BigDecimal> approvedTotalMap = new ConcurrentHashMap<>(); Sum approvedSystemSumAggr = appBucket.getAggregations().get("approvedSystemTotal"); BigDecimal totalApprovedSysTax = BigDecimal.valueOf(approvedSystemSumAggr.getValue()).setScale(0, BigDecimal.ROUND_HALF_UP); Sum totalApprovedAggr = appBucket.getAggregations().get("approvedTotal"); BigDecimal totalApprovedTax = BigDecimal.valueOf(totalApprovedAggr.getValue()).setScale(0, BigDecimal.ROUND_HALF_UP); approvedSystemMap.put("approvedSystemTax", totalApprovedSysTax); approvedTotalMap.put("totalApprovedTax", totalApprovedTax); list.add(approvedSystemMap);//from ww w . j a v a2 s. c o m list.add(approvedTotalMap); totalMap.put(appBucket.getKeyAsString(), list); } return totalMap; }
From source file:org.gradoop.flink.datagen.transactions.foodbroker.config.FoodBrokerConfig.java
/** * Calculates and returns BigDecimal value of the loaded key. * * @param influencingMasterDataQuality list of influencing master data quality * @param node the transactional data node * @param key the key to load from/*from w w w . j av a 2s. c o m*/ * @param higherIsBetterDefault default value to define that a higher value is better or not * @return BigDecimal value */ public BigDecimal getDecimalVariationConfigurationValue(List<Float> influencingMasterDataQuality, String node, String key, boolean higherIsBetterDefault) { Float baseValue = 0.0f; Float value; Boolean higherIsBetter = getHigherIsBetter(node, key, higherIsBetterDefault); Float influence = getInfluence(node, key, null); // load the value to start with try { baseValue = (float) getTransactionalNodes().getJSONObject(node).getDouble(key); } catch (JSONException e) { e.printStackTrace(); } // get the result value based on the loaded one value = getValue(influencingMasterDataQuality, higherIsBetter, influence, baseValue); // round and return the value return BigDecimal.valueOf(value).setScale(2, BigDecimal.ROUND_HALF_UP); }
From source file:com.salesmanager.core.util.ProductUtil.java
public static BigDecimal determinePriceWithAttributes(Product product, Collection attributes, Locale locale, String currency) {//from www .j a va2 s .co m int decimalPlace = 2; Map currenciesmap = RefCache.getCurrenciesListWithCodes(); Currency c = (Currency) currenciesmap.get(currency); // prices BigDecimal bdprodprice = product.getProductPrice(); BigDecimal bddiscountprice = null; // discount price Special special = product.getSpecial(); Date dt = new Date(); java.util.Date spdate = null; java.util.Date spenddate = null; if (special != null) { spdate = special.getSpecialDateAvailable(); spenddate = special.getExpiresDate(); if (spdate.before(new Date(dt.getTime())) && spenddate.after(new Date(dt.getTime()))) { bddiscountprice = special.getSpecialNewProductPrice(); } } // all other prices Set prices = product.getPrices(); if (prices != null) { Iterator pit = prices.iterator(); while (pit.hasNext()) { ProductPrice pprice = (ProductPrice) pit.next(); pprice.setLocale(locale); if (pprice.isDefaultPrice()) {// overwrites default price bddiscountprice = null; spdate = null; spenddate = null; bdprodprice = pprice.getProductPriceAmount(); ProductPriceSpecial ppspecial = pprice.getSpecial(); if (ppspecial != null) { if (ppspecial.getProductPriceSpecialStartDate() != null && ppspecial.getProductPriceSpecialEndDate() != null && ppspecial.getProductPriceSpecialStartDate().before(new Date(dt.getTime())) && ppspecial.getProductPriceSpecialEndDate().after(new Date(dt.getTime()))) { bddiscountprice = ppspecial.getProductPriceSpecialAmount(); } else if (ppspecial.getProductPriceSpecialDurationDays() > -1) { bddiscountprice = ppspecial.getProductPriceSpecialAmount(); } } break; } } } double fprodprice = 0; ; if (bdprodprice != null) { fprodprice = bdprodprice.setScale(decimalPlace, BigDecimal.ROUND_HALF_UP).doubleValue(); } // determine any properties prices BigDecimal attributesPrice = null; if (attributes != null) { Iterator i = attributes.iterator(); while (i.hasNext()) { ProductAttribute attr = (ProductAttribute) i.next(); if (!attr.isAttributeDisplayOnly() && attr.getOptionValuePrice().longValue() > 0) { if (attributesPrice == null) { attributesPrice = new BigDecimal(0); } attributesPrice = attributesPrice.add(attr.getOptionValuePrice()); } } } if (bddiscountprice != null) { if (attributesPrice != null) { bddiscountprice = bddiscountprice.add(attributesPrice); } return bddiscountprice; } else { if (attributesPrice != null) { bdprodprice = bdprodprice.add(attributesPrice); } return bdprodprice; } }
From source file:org.egov.wtms.web.controller.application.MeterReadingController.java
private BigDecimal calculateDamagedMeterAverageDemand(final List<Installment> installmentList, final WaterConnectionDetails waterConnectionDetails) { BigDecimal totalAmount = BigDecimal.ZERO; int count = 0; Set<EgDemandDetails> demandDtlSet = null; BigDecimal meterDemandAmount = BigDecimal.ZERO; final EgDemand demand = waterTaxUtils.getCurrentDemand(waterConnectionDetails).getDemand(); if (demand != null) demandDtlSet = demand.getEgDemandDetails(); for (final Installment installment : installmentList) for (final EgDemandDetails demandDetail : demandDtlSet) if (demandDetail.getEgDemandReason().getEgInstallmentMaster().equals(installment)) { count++;//from w ww .j a v a 2 s .c om meterDemandAmount = meterDemandAmount.add(demandDetail.getAmount()); } if (count != 0) totalAmount = meterDemandAmount.divide(BigDecimal.valueOf(count), 0, BigDecimal.ROUND_HALF_UP); return totalAmount; }
From source file:org.egov.ptis.service.dashboard.SurveyDashboardService.java
private Map<String, List<BigDecimal>> getTaxDetails(SearchResponse taxesResponse) { Terms taxAggr = taxesResponse.getAggregations().get(AGGREGATIONWISE); Map<String, List<BigDecimal>> taxMap = new ConcurrentHashMap<>(); Sum gisTotalAgg;// w w w .j a v a 2 s . c o m Sum systemTotalAgg; Sum applicationTotalAgg; BigDecimal gisTotalTax; BigDecimal systemTotalTax; BigDecimal applicationTotalTax; for (Bucket taxBucket : taxAggr.getBuckets()) { List<BigDecimal> taxList = new ArrayList<>(); gisTotalAgg = taxBucket.getAggregations().get("gisTotal"); gisTotalTax = BigDecimal.valueOf(gisTotalAgg.getValue()).setScale(0, BigDecimal.ROUND_HALF_UP); systemTotalAgg = taxBucket.getAggregations().get("systemTotal"); systemTotalTax = BigDecimal.valueOf(systemTotalAgg.getValue()).setScale(0, BigDecimal.ROUND_HALF_UP); applicationTotalAgg = taxBucket.getAggregations().get(APPLICATION_TAX); applicationTotalTax = BigDecimal.valueOf(applicationTotalAgg.getValue()).setScale(0, BigDecimal.ROUND_HALF_UP); taxList.add(gisTotalTax); taxList.add(systemTotalTax); taxList.add(applicationTotalTax); taxMap.put(taxBucket.getKeyAsString(), taxList); } return taxMap; }
From source file:org.egov.services.voucher.VoucherService.java
public Map<String, Object> getVoucherInfo(final Long voucherId) { if (LOGGER.isDebugEnabled()) LOGGER.debug("VoucherService | getVoucherDetails | Start"); final Map<String, Object> voucherMap = new HashMap<>(); final CVoucherHeader voucherHeader = (CVoucherHeader) persistenceService .find("from CVoucherHeader where id=?", voucherId); voucherMap.put(Constants.VOUCHERHEADER, voucherHeader); final List<CGeneralLedger> glList = voucherHibDAO.getGLInfo(voucherHeader.getId()); if (LOGGER.isDebugEnabled()) LOGGER.debug("total number of general ledger entry " + glList.size()); final List<VoucherDetails> billDetailslist = new ArrayList<>(); final List<VoucherDetails> subLedgerlist = new ArrayList<>(); VoucherDetails voucherDetail;/*from ww w. ja v a 2 s.c o m*/ VoucherDetails subLedgerDetail; BigDecimal crAmount; BigDecimal drAmount; try { for (final CGeneralLedger generalLedger : glList) { voucherDetail = new VoucherDetails(); if (null != generalLedger.getFunctionId()) { voucherDetail.setFunctionIdDetail(Long.valueOf(generalLedger.getFunctionId().toString())); voucherDetail.setFunctionDetail(functionDAO .getFunctionById(Long.valueOf(generalLedger.getFunctionId().toString())).getName()); } voucherDetail.setGlcodeIdDetail(generalLedger.getGlcodeId().getId()); voucherDetail.setGlcodeDetail(generalLedger.getGlcodeId().getGlcode()); voucherDetail.setAccounthead(coaDAO.findById(generalLedger.getGlcodeId().getId(), false).getName()); drAmount = new BigDecimal(generalLedger.getDebitAmount()); crAmount = new BigDecimal(generalLedger.getCreditAmount()); voucherDetail.setDebitAmountDetail(drAmount.setScale(2, BigDecimal.ROUND_HALF_UP)); voucherDetail.setCreditAmountDetail(crAmount.setScale(2, BigDecimal.ROUND_HALF_UP)); billDetailslist.add(voucherDetail); final List<CGeneralLedgerDetail> gledgerDetailList = voucherHibDAO .getGeneralledgerdetail(generalLedger.getId()); for (final CGeneralLedgerDetail gledgerDetail : gledgerDetailList) { if (chartOfAccountDetailService.getByGlcodeIdAndDetailTypeId( generalLedger.getGlcodeId().getId(), gledgerDetail.getDetailTypeId().getId().intValue()) != null) { subLedgerDetail = new VoucherDetails(); subLedgerDetail.setAmount(gledgerDetail.getAmount().setScale(2)); subLedgerDetail.setGlcode(coaDAO.findById(generalLedger.getGlcodeId().getId(), false)); subLedgerDetail.setSubledgerCode(generalLedger.getGlcodeId().getGlcode()); final Accountdetailtype accountdetailtype = voucherHibDAO .getAccountDetailById(gledgerDetail.getDetailTypeId().getId()); subLedgerDetail.setDetailType(accountdetailtype); subLedgerDetail.setDetailTypeName(accountdetailtype.getName()); final EntityType entity = voucherHibDAO.getEntityInfo(gledgerDetail.getDetailKeyId(), accountdetailtype.getId()); subLedgerDetail.setDetailCode(entity.getCode()); subLedgerDetail.setDetailKeyId(gledgerDetail.getDetailKeyId()); subLedgerDetail.setDetailKey(entity.getName()); subLedgerDetail.setFunctionDetail( generalLedger.getFunctionId() != null ? generalLedger.getFunctionId().toString() : "0"); subLedgerlist.add(subLedgerDetail); } } } } catch (final HibernateException e) { LOGGER.error("Exception occured in VoucherSerive |getVoucherInfo " + e); } catch (final Exception e) { LOGGER.error("Exception occured in VoucherSerive |getVoucherInfo " + e); } voucherMap.put(Constants.GLDEATILLIST, billDetailslist); /** * create empty sub ledger row */ if (subLedgerlist.isEmpty()) subLedgerlist.add(new VoucherDetails()); voucherMap.put("subLedgerDetail", subLedgerlist); return voucherMap; }
From source file:org.kalypso.kalypsomodel1d2d.sim.ProcessResultTelemacOperation.java
private IStatus readTelemacResults() { final SerafinReader convTelemac = new SerafinReader(); final FileObject inputFile = getOrUnzipResult(m_inputFile, m_outputDir); if (inputFile == null) { return new Status(IStatus.ERROR, PluginUtilities.id(KalypsoModel1D2DPlugin.getDefault()), "error - no result file found!"); }//from ww w.j a v a 2 s .com try { convTelemac.setFile(new File(inputFile.getURL().toURI())); convTelemac.doReadAll(); } catch (URISyntaxException | IOException e1) { e1.printStackTrace(); final String msg = "error while reading telemac results file"; return new Status(IStatus.ERROR, PluginUtilities.id(KalypsoModel1D2DPlugin.getDefault()), msg, e1); } // Map<String, Map<String, List<Double>>> mapResults = convTelemac.doRead(); for (Date stepDate : m_stepDates) { // stepDate = findStepDate( file ); // m_geoLog.formatLog( IStatus.INFO, CODE_RUNNING_FINE, Messages.getString( "org.kalypso.kalypsomodel1d2d.sim.ResultManager.14" ), inputFile.getURL().toString() ); //$NON-NLS-1$ final String outDirName = NodeResultHelper.createOutDirName(stepDate); final File resultOutputDir = new File(m_outputDir, outDirName); resultOutputDir.mkdirs(); KalypsoModel1D2DDebug.SIMULATIONRESULT.printf("%s", //$NON-NLS-1$ Messages.getString("org.kalypso.kalypsomodel1d2d.sim.ProcessResultsJob.16")); //$NON-NLS-1$ final Runtime runtime = Runtime.getRuntime(); runtime.gc(); final TimeLogger logger = new TimeLogger( Messages.getString("org.kalypso.kalypsomodel1d2d.sim.ProcessResultsJob.17")); //$NON-NLS-1$ final File gmlZipResultFile = new File(resultOutputDir, "results.gz"); //$NON-NLS-1$ IStepResultMeta stepResultMeta = m_unitResultMeta.addStepResult(); try { /* GMLWorkspace fr Ergebnisse anlegen */ final GMLWorkspace resultWorkspace = FeatureFactory.createGMLWorkspace(INodeResultCollection.QNAME, gmlZipResultFile.toURI().toURL(), null); final URL lsObsUrl = LengthSectionHandler2d.class .getResource("resources/lengthSectionTemplate.gml"); //$NON-NLS-1$ final String componentID = IWspmDictionaryConstants.LS_COMPONENT_STATION; final LengthSectionHandler1d lsHandler = new LengthSectionHandler1d(componentID, lsObsUrl); /* .2d Datei lesen und GML fllen */ final String crs = KalypsoDeegreePlugin.getDefault().getCoordinateSystem(); final MultiTriangleEater multiEater = new MultiTriangleEater(); if (m_boolDoFullEvaluate) { for (final ResultType parameter : m_parameters) { /* GML(s) */ if (parameter == ResultType.TERRAIN && !ResultMeta1d2dHelper.containsTerrain(stepResultMeta)) { /* create TIN-Dir for FEM terrain model */ // TODO: obscure, why go outside our output dir... TODO: refaktor it! final String calcUnitPath = resultOutputDir.getParent(); final File modelPath = new File(calcUnitPath, "model"); //$NON-NLS-1$ if (!modelPath.exists()) { modelPath.mkdirs(); final File modelTinPath = new File(modelPath, "Tin"); //$NON-NLS-1$ modelTinPath.mkdirs(); final File tinResultFile = new File(modelTinPath, "tin.gz"); //$NON-NLS-1$ final ITriangleEater gmlTriangleEater = NodeResultHelper .createTinEater(tinResultFile, parameter, crs); multiEater.addEater(gmlTriangleEater); } } else { /* create TIN-Dir for results */ final File tinPath = new File(resultOutputDir, "Tin"); //$NON-NLS-1$ tinPath.mkdirs(); final File tinZipResultFile = new File(tinPath, "tin.gz"); //$NON-NLS-1$ final ITriangleEater tinEater = NodeResultHelper.createTinEater(tinZipResultFile, parameter, crs); multiEater.addEater(tinEater); } } } final NodeResultsHandler handler = new NodeResultsHandler(resultWorkspace, multiEater, m_flowModel, m_controlModel, m_discModel, resultMinMaxCatcher, lsHandler, m_mapResults); convTelemac.setModelElementHandler(handler); logger.takeInterimTime(); logger.printCurrentInterim(Messages .getString("org.kalypso.kalypsomodel1d2d.sim.ProcessResultsJob.54", m_inputFile.getName())); //$NON-NLS-1$ System.out.println(stepDate); int iStep = resolveStepNr(stepDate); convTelemac.feedHandler(iStep); logger.takeInterimTime(); logger.printCurrentInterim( Messages.getString("org.kalypso.kalypsomodel1d2d.sim.ProcessResultsJob.56")); //$NON-NLS-1$ if (m_boolDoFullEvaluate) { convTelemac.feedHandlerWithTriangles(); } // finish MultiEater and engage serializer KalypsoModel1D2DDebug.SIMULATIONRESULT.printf("%s", //$NON-NLS-1$ Messages.getString("org.kalypso.kalypsomodel1d2d.sim.ProcessResultsJob.58")); //$NON-NLS-1$ multiEater.finished(); KalypsoModel1D2DDebug.SIMULATIONRESULT.printf("%s", //$NON-NLS-1$ Messages.getString("org.kalypso.kalypsomodel1d2d.sim.ProcessResultsJob.60")); //$NON-NLS-1$ /* Node-GML in Datei schreiben */ GmlSerializer.serializeWorkspace(gmlZipResultFile, resultWorkspace, "UTF-8"); //$NON-NLS-1$UTF-8 /* LengthSection in Datei schreiben */ final ICalculationUnit1D[] calcUnits = lsHandler.getCalcUnits(); for (final ICalculationUnit1D calcUnit : calcUnits) { final File lsObsFile = new File(resultOutputDir, "lengthSection_" + calcUnit.getId() + ".gml"); //$NON-NLS-1$ //$NON-NLS-2$ final IObservation<TupleResult> lsObs = lsHandler.getObservation(calcUnit); final GMLWorkspace lsObsWorkspace = lsHandler.getWorkspace(calcUnit); if (lsObs.getResult().size() > 0) { ObservationFeatureFactory.toFeature(lsObs, lsObsWorkspace.getRootFeature()); GmlSerializer.serializeWorkspace(lsObsFile, lsObsWorkspace, "UTF-8"); //$NON-NLS-1$ /* length section entry in result db */ // TODO: use station range for min max... ResultMeta1d2dHelper.addDocument(stepResultMeta, Messages.getString("org.kalypso.kalypsomodel1d2d.sim.ProcessResultsJob.65") //$NON-NLS-1$ + calcUnit.getName(), Messages.getString("org.kalypso.kalypsomodel1d2d.sim.ProcessResultsJob.66"), //$NON-NLS-1$ IDocumentResultMeta.DOCUMENTTYPE.lengthSection, new Path(lsObsFile.getName()), Status.OK_STATUS, new BigDecimal(0), new BigDecimal(0)); } } logger.takeInterimTime(); logger.printCurrentInterim( Messages.getString("org.kalypso.kalypsomodel1d2d.sim.ProcessResultsJob.67")); //$NON-NLS-1$ BigDecimal min; BigDecimal max; if (m_boolDoFullEvaluate) { for (final ResultType parameter : m_parameters) { /* GML(s) */ /* result db */ switch (parameter) { case TERRAIN: if (stepResultMeta != null && !ResultMeta1d2dHelper.containsTerrain(stepResultMeta)) { /* check if there exists already an entry for terrainTin */ final ICalcUnitResultMeta calcUnitResult = (ICalcUnitResultMeta) stepResultMeta .getOwner(); min = new BigDecimal(resultMinMaxCatcher.getMinTerrain()).setScale(3, BigDecimal.ROUND_HALF_UP); max = new BigDecimal(resultMinMaxCatcher.getMaxTerrain()).setScale(3, BigDecimal.ROUND_HALF_UP); ResultMeta1d2dHelper.addDocument(calcUnitResult, Messages.getString("org.kalypso.kalypsomodel1d2d.sim.ProcessResultsJob.68"), //$NON-NLS-1$ Messages.getString("org.kalypso.kalypsomodel1d2d.sim.ProcessResultsJob.69"), //$NON-NLS-1$ IDocumentResultMeta.DOCUMENTTYPE.tinTerrain, new Path("model/Tin/tin_TERRAIN.gz"), Status.OK_STATUS, min, max); //$NON-NLS-1$ } break; case DEPTH: // TODO: Handle minimum at infinity min = new BigDecimal(resultMinMaxCatcher.getMinDepth()).setScale(3, BigDecimal.ROUND_HALF_UP); max = new BigDecimal(resultMinMaxCatcher.getMaxDepth()).setScale(3, BigDecimal.ROUND_HALF_UP); ResultMeta1d2dHelper.addDocument(stepResultMeta, Messages.getString("org.kalypso.kalypsomodel1d2d.sim.ProcessResultsJob.71"), //$NON-NLS-1$ Messages.getString("org.kalypso.kalypsomodel1d2d.sim.ProcessResultsJob.1"), //$NON-NLS-1$ IDocumentResultMeta.DOCUMENTTYPE.tinDepth, new Path("Tin/tin_DEPTH.gz"), //$NON-NLS-1$ Status.OK_STATUS, min, max); break; case VELOCITY: min = new BigDecimal(resultMinMaxCatcher.getMinVelocityAbs()).setScale(3, BigDecimal.ROUND_HALF_UP); max = new BigDecimal(resultMinMaxCatcher.getMaxVelocityAbs()).setScale(3, BigDecimal.ROUND_HALF_UP); ResultMeta1d2dHelper.addDocument(stepResultMeta, Messages.getString("org.kalypso.kalypsomodel1d2d.sim.ProcessResultsJob.74"), //$NON-NLS-1$ Messages.getString("org.kalypso.kalypsomodel1d2d.sim.ProcessResultsJob.75"), //$NON-NLS-1$ IDocumentResultMeta.DOCUMENTTYPE.tinVelo, new Path("Tin/tin_VELOCITY.gz"), //$NON-NLS-1$ Status.OK_STATUS, min, max); break; case VELOCITY_X: min = new BigDecimal(resultMinMaxCatcher.getMinVelocityAbs()).setScale(3, BigDecimal.ROUND_HALF_UP); max = new BigDecimal(resultMinMaxCatcher.getMaxVelocityAbs()).setScale(3, BigDecimal.ROUND_HALF_UP); ResultMeta1d2dHelper.addDocument(stepResultMeta, Messages.getString("org.kalypso.kalypsomodel1d2d.sim.ProcessResultsJob.77"), //$NON-NLS-1$ Messages.getString("org.kalypso.kalypsomodel1d2d.sim.ProcessResultsJob.78"), //$NON-NLS-1$ IDocumentResultMeta.DOCUMENTTYPE.tinVelo, new Path("Tin/tin_VELOCITY_X.gz"), //$NON-NLS-1$ Status.OK_STATUS, min, max); break; case VELOCITY_Y: min = new BigDecimal(resultMinMaxCatcher.getMinVelocityAbs()).setScale(3, BigDecimal.ROUND_HALF_UP); max = new BigDecimal(resultMinMaxCatcher.getMaxVelocityAbs()).setScale(3, BigDecimal.ROUND_HALF_UP); ResultMeta1d2dHelper.addDocument(stepResultMeta, Messages.getString("org.kalypso.kalypsomodel1d2d.sim.ProcessResultsJob.80"), //$NON-NLS-1$ Messages.getString("org.kalypso.kalypsomodel1d2d.sim.ProcessResultsJob.81"), //$NON-NLS-1$ IDocumentResultMeta.DOCUMENTTYPE.tinVelo, new Path("Tin/tin_VELOCITY_Y.gz"), //$NON-NLS-1$ Status.OK_STATUS, min, max); break; case WATERLEVEL: min = new BigDecimal(resultMinMaxCatcher.getMinWaterlevel()).setScale(3, BigDecimal.ROUND_HALF_UP); max = new BigDecimal(resultMinMaxCatcher.getMaxWaterlevel()).setScale(3, BigDecimal.ROUND_HALF_UP); ResultMeta1d2dHelper.addDocument(stepResultMeta, Messages.getString("org.kalypso.kalypsomodel1d2d.sim.ProcessResultsJob.83"), //$NON-NLS-1$ Messages.getString("org.kalypso.kalypsomodel1d2d.sim.ProcessResultsJob.84"), //$NON-NLS-1$ IDocumentResultMeta.DOCUMENTTYPE.tinWsp, new Path("Tin/tin_WATERLEVEL.gz"), //$NON-NLS-1$ Status.OK_STATUS, min, max); break; case SHEARSTRESS: min = new BigDecimal(resultMinMaxCatcher.getMinShearStress()).setScale(3, BigDecimal.ROUND_HALF_UP); max = new BigDecimal(resultMinMaxCatcher.getMaxShearStress()).setScale(3, BigDecimal.ROUND_HALF_UP); ResultMeta1d2dHelper.addDocument(stepResultMeta, Messages.getString("org.kalypso.kalypsomodel1d2d.sim.ProcessResultsJob.86"), //$NON-NLS-1$ Messages.getString("org.kalypso.kalypsomodel1d2d.sim.ProcessResultsJob.87"), //$NON-NLS-1$ IDocumentResultMeta.DOCUMENTTYPE.tinShearStress, new Path("Tin/tin_SHEARSTRESS.gz"), Status.OK_STATUS, min, max); //$NON-NLS-1$ break; default: throw new UnsupportedOperationException(); } } } // we will set all min max results to the node results meta also ResultMeta1d2dHelper.addDocument(stepResultMeta, Messages.getString("org.kalypso.kalypsomodel1d2d.sim.ProcessResultsJob.89"), //$NON-NLS-1$ Messages.getString("org.kalypso.kalypsomodel1d2d.sim.ProcessResultsJob.90"), //$NON-NLS-1$ IDocumentResultMeta.DOCUMENTTYPE.nodes, new Path("results.gz"), Status.OK_STATUS, //$NON-NLS-1$ resultMinMaxCatcher); // TODO: maybe check if time and stepTime are equal? if (stepResultMeta != null) ResultMeta1d2dHelper.addToResultDB(stepResultMeta, stepDate, resultOutputDir); // return gmlZipResultFile; } // catch( CoreException | IOException | GmlSerializeException | GMLSchemaException e ) catch (Exception e) { e.printStackTrace(); final String msg = "error while reading telemac results"; return new Status(IStatus.ERROR, PluginUtilities.id(KalypsoModel1D2DPlugin.getDefault()), msg, e); } finally { // IOUtils.closeQuietly( is ); logger.takeInterimTime(); logger.printCurrentInterim( Messages.getString("org.kalypso.kalypsomodel1d2d.sim.ProcessResultsJob.92")); //$NON-NLS-1$ runtime.gc(); } } return Status.OK_STATUS; }