Example usage for java.math BigDecimal toString

List of usage examples for java.math BigDecimal toString

Introduction

In this page you can find the example usage for java.math BigDecimal toString.

Prototype

@Override
public String toString() 

Source Link

Document

Returns the string representation of this BigDecimal , using scientific notation if an exponent is needed.

Usage

From source file:org.egov.works.contractorbill.service.ContractorBillRegisterService.java

public void validateRefundAmount(final ContractorBillRegister contractorBillRegister,
        final BindingResult resultBinder) {
    int index = 0;
    for (final EgBilldetails egBillDetail : contractorBillRegister.getRefundBillDetails()) {
        if (egBillDetail.getGlcodeid() != null && egBillDetail.getDebitamount() == null)
            resultBinder.rejectValue("refundBillDetails[" + index + "].debitamount",
                    "error.refundamount.required");
        if (egBillDetail.getDebitamount() != null && egBillDetail.getGlcodeid() == null)
            resultBinder.rejectValue("refundBillDetails[" + index + "].glcodeid",
                    "error.refundaccountcode.required");
        if (egBillDetail.getGlcodeid() != null && egBillDetail.getDebitamount() != null) {
            final CChartOfAccounts coa = chartOfAccountsHibernateDAO
                    .findById(egBillDetail.getGlcodeid().longValue(), false);
            final String amounts = getTotalDebitAndCreditAmountByAccountCode(
                    contractorBillRegister.getWorkOrderEstimate().getId(), new BigDecimal(coa.getId()),
                    contractorBillRegister.getId() != null ? contractorBillRegister.getId() : -1);
            if (!org.apache.commons.lang.StringUtils.isBlank(amounts)) {
                final String[] creditDebitAmounts = amounts.split(",");
                BigDecimal withheldAmount = BigDecimal.ZERO;
                BigDecimal refundedAmount = BigDecimal.ZERO;
                if (!creditDebitAmounts[0].equals("0"))
                    withheldAmount = new BigDecimal(creditDebitAmounts[0]);
                if (!creditDebitAmounts[1].equals("0"))
                    refundedAmount = new BigDecimal(creditDebitAmounts[1]);

                if (withheldAmount.equals("0"))
                    resultBinder.reject("error.contractorBill.nowithheldtorefund",
                            new String[] { coa.getGlcode() }, null);
                else {

                    final BigDecimal validRefundAmount = egBillDetail.getDebitamount().add(refundedAmount);
                    final BigDecimal diffAmount = validRefundAmount.subtract(withheldAmount);
                    if (validRefundAmount.compareTo(new BigDecimal(creditDebitAmounts[0])) == 1
                            && !contractorBillRegister.getWorkOrderEstimate().getEstimate()
                                    .getLineEstimateDetails().getLineEstimate().isSpillOverFlag())
                        resultBinder.reject("error.contractorBill.validate.refundAmount",
                                new String[] { coa.getGlcode(), diffAmount.toString() }, null);
                }//from  w  ww .java 2  s . c  o  m
            }
        }
        index++;
    }

}

From source file:org.nd4j.linalg.util.BigDecimalMath.java

/**
 * The natural logarithm./*w  ww  . jav  a2 s .c  o m*/
 *
 * @param x the argument.
 * @return ln(x).
 * The precision of the result is implicitly defined by the precision in the argument.
 */
static public BigDecimal log(BigDecimal x) {
    /* the value is undefined if x is negative.
     */
    if (x.compareTo(BigDecimal.ZERO) < 0) {
        throw new ArithmeticException("Cannot take log of negative " + x.toString());
    } else if (x.compareTo(BigDecimal.ONE) == 0) {
        /* log 1. = 0. */
        return scalePrec(BigDecimal.ZERO, x.precision() - 1);
    } else if (Math.abs(x.doubleValue() - 1.0) <= 0.3) {
        /* The standard Taylor series around x=1, z=0, z=x-1. Abramowitz-Stegun 4.124.
         * The absolute error is err(z)/(1+z) = err(x)/x.
         */
        BigDecimal z = scalePrec(x.subtract(BigDecimal.ONE), 2);
        BigDecimal zpown = z;
        double eps = 0.5 * x.ulp().doubleValue() / Math.abs(x.doubleValue());
        BigDecimal resul = z;
        for (int k = 2;; k++) {
            zpown = multiplyRound(zpown, z);
            BigDecimal c = divideRound(zpown, k);
            if (k % 2 == 0) {
                resul = resul.subtract(c);
            } else {
                resul = resul.add(c);
            }
            if (Math.abs(c.doubleValue()) < eps) {
                break;
            }
        }
        MathContext mc = new MathContext(err2prec(resul.doubleValue(), eps));
        return resul.round(mc);
    } else {
        final double xDbl = x.doubleValue();
        final double xUlpDbl = x.ulp().doubleValue();
        /* Map log(x) = log root[r](x)^r = r*log( root[r](x)) with the aim
         * to move roor[r](x) near to 1.2 (that is, below the 0.3 appearing above), where log(1.2) is roughly 0.2.
         */
        int r = (int) (Math.log(xDbl) / 0.2);
        /* Since the actual requirement is a function of the value 0.3 appearing above,
         * we avoid the hypothetical case of endless recurrence by ensuring that r >= 2.
         */
        r = Math.max(2, r);
        /* Compute r-th root with 2 additional digits of precision
         */
        BigDecimal xhighpr = scalePrec(x, 2);
        BigDecimal resul = root(r, xhighpr);
        resul = log(resul).multiply(new BigDecimal(r));
        /* error propagation: log(x+errx) = log(x)+errx/x, so the absolute error
         * in the result equals the relative error in the input, xUlpDbl/xDbl .
         */
        MathContext mc = new MathContext(err2prec(resul.doubleValue(), xUlpDbl / xDbl));
        return resul.round(mc);
    }
}

From source file:org.apache.pig.data.BinInterSedes.java

private void writeBigDecimal(DataOutput out, BigDecimal bd) throws IOException {
    writeDatum(out, bd.toString());
}

From source file:org.nd4j.linalg.util.BigDecimalMath.java

/**
 * The inverse trigonometric sine./*from  w w  w. j  av a2 s  . co m*/
 *
 * @param x the argument.
 * @return the arcsin(x) in radians.
 */
static public BigDecimal asin(final BigDecimal x) {
    if (x.compareTo(BigDecimal.ONE) > 0 || x.compareTo(BigDecimal.ONE.negate()) < 0) {
        throw new ArithmeticException("Out of range argument " + x.toString() + " of asin");

    } else if (x.compareTo(BigDecimal.ZERO) == 0) {
        return BigDecimal.ZERO;
    } else if (x.compareTo(BigDecimal.ONE) == 0) {
        /* arcsin(1) = pi/2
         */
        double errpi = Math.sqrt(x.ulp().doubleValue());
        MathContext mc = new MathContext(err2prec(3.14159, errpi));

        return pi(mc).divide(new BigDecimal(2));

    } else if (x.compareTo(BigDecimal.ZERO) < 0) {
        return asin(x.negate()).negate();

    } else if (x.doubleValue() > 0.7) {
        final BigDecimal xCompl = BigDecimal.ONE.subtract(x);
        final double xDbl = x.doubleValue();
        final double xUlpDbl = x.ulp().doubleValue() / 2.;
        final double eps = xUlpDbl / 2. / Math.sqrt(1. - Math.pow(xDbl, 2.));

        final BigDecimal xhighpr = scalePrec(xCompl, 3);
        final BigDecimal xhighprV = divideRound(xhighpr, 4);
        BigDecimal resul = BigDecimal.ONE;
        /* x^(2i+1) */
        BigDecimal xpowi = BigDecimal.ONE;
        /* i factorial */
        BigInteger ifacN = BigInteger.ONE;
        BigInteger ifacD = BigInteger.ONE;

        for (int i = 1;; i++) {
            ifacN = ifacN.multiply(new BigInteger("" + (2 * i - 1)));
            ifacD = ifacD.multiply(new BigInteger("" + i));

            if (i == 1) {
                xpowi = xhighprV;
            } else {
                xpowi = multiplyRound(xpowi, xhighprV);
            }
            BigDecimal c = divideRound(multiplyRound(xpowi, ifacN),
                    ifacD.multiply(new BigInteger("" + (2 * i + 1))));
            resul = resul.add(c);
            /* series started 1+x/12+... which yields an estimate of the sums error
             */

            if (Math.abs(c.doubleValue()) < xUlpDbl / 120.) {
                break;
            }

        }
        /* sqrt(2*z)*(1+...)
         */
        xpowi = sqrt(xhighpr.multiply(new BigDecimal(2)));
        resul = multiplyRound(xpowi, resul);
        MathContext mc = new MathContext(resul.precision());
        BigDecimal pihalf = pi(mc).divide(new BigDecimal(2));
        mc = new MathContext(err2prec(resul.doubleValue(), eps));

        return pihalf.subtract(resul, mc);

    } else {
        /* absolute error in the result is err(x)/sqrt(1-x^2) to lowest order
         */
        final double xDbl = x.doubleValue();
        final double xUlpDbl = x.ulp().doubleValue() / 2.;
        final double eps = xUlpDbl / 2. / Math.sqrt(1. - Math.pow(xDbl, 2.));
        final BigDecimal xhighpr = scalePrec(x, 2);
        final BigDecimal xhighprSq = multiplyRound(xhighpr, xhighpr);
        BigDecimal resul = xhighpr.plus();
        /* x^(2i+1) */
        BigDecimal xpowi = xhighpr;
        /* i factorial */
        BigInteger ifacN = BigInteger.ONE;
        BigInteger ifacD = BigInteger.ONE;

        for (int i = 1;; i++) {
            ifacN = ifacN.multiply(new BigInteger("" + (2 * i - 1)));
            ifacD = ifacD.multiply(new BigInteger("" + (2 * i)));
            xpowi = multiplyRound(xpowi, xhighprSq);
            BigDecimal c = divideRound(multiplyRound(xpowi, ifacN),
                    ifacD.multiply(new BigInteger("" + (2 * i + 1))));
            resul = resul.add(c);

            if (Math.abs(c.doubleValue()) < 0.1 * eps) {
                break;
            }

        }
        MathContext mc = new MathContext(err2prec(resul.doubleValue(), eps));

        return resul.round(mc);

    }
}

From source file:org.openbravo.erpCommon.ad_forms.Fact.java

/**
 * Create Source Line for Suspense Balancing. Only if Suspense Balancing is enabled and not a
 * multi-currency document (double check as otherwise the rule should not have fired) If not
 * balanced create balancing entry in currency of the document
 * /*from w ww .  j ava2  s . co m*/
 * @return FactLine
 */
public FactLine balanceSource(ConnectionProvider conn) {
    if (!m_acctSchema.isSuspenseBalancing() || m_doc.MultiCurrency)
        return null;
    if (m_lines.size() == 0) {
        log4jFact.error("balanceSouce failed.");
        return null;
    }
    FactLine fl = (FactLine) m_lines.get(0);
    BigDecimal diff = getSourceBalance();
    log4jFact.debug("balanceSource = " + diff);
    // new line
    FactLine line = new FactLine(m_doc.AD_Table_ID, m_doc.Record_ID, "", fl.m_Fact_Acct_Group_ID, fl.m_SeqNo,
            fl.m_DocBaseType);// antes
    // "0".
    line.setDocumentInfo(m_doc, null);
    line.setJournalInfo(m_doc.GL_Category_ID);
    line.setPostingType(m_postingType);
    // Amount
    if (diff.compareTo(ZERO) < 0) // negative balance => DR
        line.setAmtSource(m_doc.C_Currency_ID, diff.abs().toString(), ZERO.toString());
    else
        // positive balance => CR
        line.setAmtSource(m_doc.C_Currency_ID, ZERO.toString(), diff.toString());
    // Convert
    line.convert(m_acctSchema.getC_Currency_ID(), m_doc.DateAcct, m_acctSchema.getCurrencyRateType(), conn);
    line.setAccount(m_acctSchema, m_acctSchema.getSuspenseBalancing_Acct());
    //
    log4jFact.debug("balanceSource - ");
    log4jFact.debug("****************** fact - balancesource -  m_lines.size() - " + m_lines.size());
    m_lines.add(line);
    return line;
}

From source file:org.egov.wtms.application.service.ConnectionDemandService.java

@Transactional
public void createMeteredDemandDetails(EgDemand demandObj, WaterConnectionDetails waterConnectionDetails,
        BigDecimal billAmount, Installment installment) {
    Boolean demandDetailExists = false;
    for (EgDemandDetails demandDetails : demandObj.getEgDemandDetails())
        if (demandDetails.getEgDemandReason().getEgInstallmentMaster().equals(installment)) {
            demandDetailExists = true;// w  ww .  j  av a  2  s .  c o  m
            break;
        }
    if (!demandDetailExists) {
        Set<EgDemandDetails> dmdDetailSet = new HashSet<>();
        dmdDetailSet.add(createDemandDetails(Double.parseDouble(billAmount.toString()),
                METERED_CHARGES_REASON_CODE, installment));
        demandObj.setBaseDemand(demandObj.getBaseDemand().add(billAmount));
        demandObj.setEgInstallmentMaster(installment);
        demandObj.getEgDemandDetails().addAll(dmdDetailSet);
        demandObj.setModifiedDate(new Date());
        final WaterDemandConnection waterDemandConnection = waterDemandConnectionService
                .findByWaterConnectionDetailsAndDemand(waterConnectionDetails, demandObj);
        if (demandObj.getId() != null && waterDemandConnection == null) {
            final WaterDemandConnection waterdemandConnection = new WaterDemandConnection();
            waterdemandConnection.setDemand(demandObj);
            waterdemandConnection.setWaterConnectionDetails(waterConnectionDetails);
            waterConnectionDetails.addWaterDemandConnection(waterdemandConnection);
            waterDemandConnectionService.createWaterDemandConnection(waterdemandConnection);
        }
    }
}

From source file:it.govpay.web.rs.dars.monitoraggio.versamenti.PagamentiHandler.java

@Override
public Map<String, Voce<String>> getVoci(Pagamento entry, BasicBD bd) throws ConsoleException {
    Map<String, Voce<String>> valori = new HashMap<String, Voce<String>>();
    Date dataPagamento = entry.getDataPagamento();
    String statoPagamento = Utils.getInstance(this.getLanguage())
            .getMessageFromResourceBundle(this.nomeServizio + ".statoPagamento.ok");
    BigDecimal importo = entry.getImportoPagato() != null ? entry.getImportoPagato() : BigDecimal.ZERO;
    String statoPagamentoLabel = Utils.getInstance(this.getLanguage()).getMessageWithParamsFromResourceBundle(
            this.nomeServizio + ".label.sottotitolo.ok", this.sdf.format(dataPagamento));

    valori.put(/*from w  w  w.jav  a 2  s  .c o  m*/
            Utils.getInstance(this.getLanguage())
                    .getMessageFromResourceBundle(this.nomeServizio + ".statoPagamento.id"),
            new Voce<String>(statoPagamentoLabel, statoPagamento));

    valori.put(
            Utils.getInstance(this.getLanguage())
                    .getMessageFromResourceBundle(this.nomeServizio + ".importoPagato.id"),
            new Voce<String>(Utils.getInstance(this.getLanguage()).getMessageFromResourceBundle(
                    this.nomeServizio + ".importoPagato.label"), importo.toString() + ""));

    if (dataPagamento != null) {
        valori.put(
                Utils.getInstance(this.getLanguage())
                        .getMessageFromResourceBundle(this.nomeServizio + ".dataPagamento.id"),
                new Voce<String>(Utils.getInstance(this.getLanguage()).getMessageFromResourceBundle(
                        this.nomeServizio + ".dataPagamento.label"), this.sdf.format(dataPagamento)));
    }

    if (entry.getIur() != null) {
        valori.put(
                Utils.getInstance(this.getLanguage())
                        .getMessageFromResourceBundle(this.nomeServizio + ".iur.id"),
                new Voce<String>(Utils.getInstance(this.getLanguage())
                        .getMessageFromResourceBundle(this.nomeServizio + ".iur.label"), entry.getIur()));
    }

    try {
        SingoloVersamento singoloVersamento = entry.getSingoloVersamento(bd);
        if (singoloVersamento != null) {
            valori.put(
                    Utils.getInstance(this.getLanguage())
                            .getMessageFromResourceBundle(this.nomeServizio + ".codSingoloVersamentoEnte.id"),
                    new Voce<String>(
                            Utils.getInstance(this.getLanguage()).getMessageFromResourceBundle(
                                    this.nomeServizio + ".codSingoloVersamentoEnte.label"),
                            singoloVersamento.getCodSingoloVersamentoEnte()));
        }
    } catch (ServiceException e) {
        throw new ConsoleException(e);
    }
    return valori;
}

From source file:org.yes.cart.web.page.component.cart.ShoppingCartPaymentVerificationView.java

/**
 * Construct payment form verification view, that
 * shows deliveries, items in deliveries and prices.
 *
 * @param id         component id//from   w  ww  . ja  v a  2 s  . c o m
 * @param orderGuid  order guid
 */
public ShoppingCartPaymentVerificationView(final String id, final String orderGuid,
        final boolean enableProductLinks) {
    super(id);

    final CustomerOrder customerOrder = checkoutServiceFacade.findByGuid(orderGuid);
    final Total grandTotal = checkoutServiceFacade.getOrderTotal(customerOrder);

    final String selectedLocale = getLocale().getLanguage();
    final Set<String> allPromos = checkoutServiceFacade.getOrderPromoCodes(customerOrder);
    for (final CustomerOrderDelivery delivery : customerOrder.getDelivery()) {
        allPromos.addAll(checkoutServiceFacade.getOrderShippingPromoCodes(delivery));
    }
    for (final CustomerOrderDet orderDet : customerOrder.getOrderDetail()) {
        allPromos.addAll(checkoutServiceFacade.getOrderItemPromoCodes(orderDet));
    }

    final String deliveryAddress = customerOrder.getShippingAddress();
    final String billingAddress = customerOrder.getBillingAddress();

    final Pair<String, String> imageSize = categoryServiceFacade.getThumbnailSizeConfig(0L,
            ShopCodeContext.getShopId());

    add(new ListView<CustomerOrderDelivery>(DELIVERY_LIST,
            new ArrayList<CustomerOrderDelivery>(customerOrder.getDelivery())) {

        @Override
        protected void populateItem(ListItem<CustomerOrderDelivery> customerOrderDeliveryListItem) {

            final CustomerOrderDelivery delivery = customerOrderDeliveryListItem.getModelObject();
            final CarrierSla sla = delivery.getCarrierSla();

            final String slaName = getI18NSupport().getFailoverModel(sla.getDisplayName(), sla.getName())
                    .getValue(selectedLocale);

            final List<CustomerOrderDeliveryDet> deliveryDet = new ArrayList<CustomerOrderDeliveryDet>(
                    delivery.getDetail());

            final Total total = checkoutServiceFacade.getOrderDeliveryTotal(customerOrder, delivery);

            customerOrderDeliveryListItem.add(new Label(DELIVERY_CODE, delivery.getDeliveryNum())).add(

                    new ListView<CustomerOrderDeliveryDet>(ITEM_LIST, deliveryDet) {

                        @Override
                        protected void populateItem(
                                ListItem<CustomerOrderDeliveryDet> customerOrderDeliveryDetListItem) {

                            final CustomerOrderDeliveryDet det = customerOrderDeliveryDetListItem
                                    .getModelObject();

                            final ProductSkuDecorator productSkuDecorator = getDecoratorFacade().decorate(
                                    productServiceFacade.getProductSkuBySkuCode(det.getProductSkuCode()),
                                    getWicketUtil().getHttpServletRequest().getContextPath(), true);

                            final String width = imageSize.getFirst();
                            final String height = imageSize.getSecond();

                            final String lang = getLocale().getLanguage();
                            final String defaultImageRelativePath = productSkuDecorator.getDefaultImage(width,
                                    height, lang);

                            final BigDecimal itemTotal = det.getPrice().multiply(det.getQty())
                                    .setScale(Constants.DEFAULT_SCALE, BigDecimal.ROUND_HALF_UP);

                            final LinksSupport links = getWicketSupportFacade().links();

                            customerOrderDeliveryDetListItem
                                    .add(links.newProductSkuLink(ITEM_NAME_LINK, productSkuDecorator.getId())
                                            .add(new Label(ITEM_NAME_LINK_NAME,
                                                    productSkuDecorator.getName(selectedLocale)))
                                            .setVisible(enableProductLinks))
                                    .add(new Label(ITEM_NAME, productSkuDecorator.getName(selectedLocale))
                                            .setVisible(!enableProductLinks))
                                    .add(new Label(ITEM_CODE, det.getProductSkuCode()))
                                    .add(new Label(ITEM_PRICE, det.getPrice().toString()))
                                    .add(new Label(ITEM_QTY, det.getQty().toString()))
                                    .add(new Label(ITEM_TOTAL, itemTotal.toString()))
                                    .add(new ContextImage(DEFAULT_IMAGE, defaultImageRelativePath).add(
                                            new AttributeModifier(BaseComponent.HTML_WIDTH, width),
                                            new AttributeModifier(BaseComponent.HTML_HEIGHT, height)));

                        }
                    }

            ).add(new Label(DELIVERY_SUB_TOTAL, total.getSubTotal().toString()))
                    .add(new Label(DELIVERY_SUB_TOTAL_TAX, total.getSubTotalTax().toString()))
                    .add(new Label(DELIVERY_SUB_TOTAL_AMOUNT, total.getSubTotalAmount().toString()))
                    .add(new Label(DELIVERY_COST, total.getDeliveryCost().toString()))
                    .add(new Label(DELIVERY_COST_TAX, total.getDeliveryTax().toString()))
                    .add(new Label(DELIVERY_COST_AMOUNT, total.getDeliveryCostAmount().toString()))
                    .add(new Label(DELIVERY_METHOD, slaName)).add(new Label(DELIVERY_ADDRESS, deliveryAddress));
        }
    });

    add(new Label(DELIVERY_GRAND_TOTAL, grandTotal.getTotal().toString()));
    add(new Label(BILLING_ADDRESS, billingAddress));
    add(new Label(DELIVERY_GRAND_TAX, grandTotal.getTotalTax().toString()));
    add(new PriceView(DELIVERY_GRAND_AMOUNT,
            new Pair<BigDecimal, BigDecimal>(grandTotal.getListTotalAmount(), grandTotal.getTotalAmount()),
            customerOrder.getCurrency(), StringUtils.join(allPromos, ", "), true, true));

}

From source file:net.sourceforge.fenixedu.domain.credits.util.DepartmentCreditsPoolBean.java

@Atomic
public void editUnitCredits() {
    BigDecimal newAssignedCredits = BigDecimal.ZERO;
    for (DepartmentExecutionCourse departmentExecutionCourse : otherDepartmentSharedExecutionCourses) {
        BigDecimal newExecutionCourseCLE = departmentExecutionCourse.getDepartmentEffectiveLoad()
                .multiply(departmentExecutionCourse.getUnitCreditValue());
        newAssignedCredits = newAssignedCredits.add(newExecutionCourseCLE);
    }//  w w  w .j a va 2s .  c o m

    for (DepartmentExecutionCourse departmentExecutionCourse : departmentSharedExecutionCourses) {
        newAssignedCredits = setExecutionCourseUnitCredit(departmentExecutionCourse,
                getCanEditSharedUnitCredits(), newAssignedCredits, true);
    }
    for (DepartmentExecutionCourse departmentExecutionCourse : departmentExecutionCourses) {
        newAssignedCredits = setExecutionCourseUnitCredit(departmentExecutionCourse, getCanEditUnitCredits(),
                newAssignedCredits, false);
    }
    if (newAssignedCredits.compareTo(getDepartmentCreditsPool().getCreditsPool()) > 0) {
        throw new DomainException("label.excededDepartmentCreditsPool",
                getDepartmentCreditsPool().getCreditsPool().toString(), newAssignedCredits.toString());
    }
    setValues();
}

From source file:net.shopxx.plugin.abcPayment.AbcPaymentController.java

@RequestMapping(value = "/update", method = RequestMethod.POST)
public String update(String paymentName, String merchantId, MultipartFile keyFile, String keyPassword,
        PaymentPlugin.FeeType feeType, BigDecimal fee, String logo, String description,
        @RequestParam(defaultValue = "false") Boolean isEnabled, Integer order,
        RedirectAttributes redirectAttributes) {
    PluginConfig pluginConfig = abcPaymentPlugin.getPluginConfig();
    Map<String, String> attributes = new HashMap<String, String>();
    attributes.put(PaymentPlugin.PAYMENT_NAME_ATTRIBUTE_NAME, paymentName);
    attributes.put("merchantId", merchantId);
    if (keyFile != null && !keyFile.isEmpty()) {
        InputStream inputStream = null;
        try {//from w  w  w  . j  a  va 2  s.  c o m
            inputStream = keyFile.getInputStream();
            PrivateKey privateKey = (PrivateKey) RSAUtils.getKey("PKCS12", inputStream, keyPassword);
            attributes.put("key", RSAUtils.getKeyString(privateKey));
        } catch (IOException e) {
            throw new RuntimeException(e.getMessage(), e);
        } catch (RuntimeException e) {
            addFlashMessage(redirectAttributes, Message.warn("admin.plugin.abcPayment.keyInvalid"));
            return "redirect:setting.jhtml";
        } finally {
            IOUtils.closeQuietly(inputStream);
        }
    } else {
        attributes.put("key", pluginConfig.getAttribute("key"));
    }
    attributes.put(PaymentPlugin.FEE_TYPE_ATTRIBUTE_NAME, feeType.toString());
    attributes.put(PaymentPlugin.FEE_ATTRIBUTE_NAME, fee.toString());
    attributes.put(PaymentPlugin.LOGO_ATTRIBUTE_NAME, logo);
    attributes.put(PaymentPlugin.DESCRIPTION_ATTRIBUTE_NAME, description);
    pluginConfig.setAttributes(attributes);
    pluginConfig.setIsEnabled(isEnabled);
    pluginConfig.setOrder(order);
    pluginConfigService.update(pluginConfig);
    addFlashMessage(redirectAttributes, SUCCESS_MESSAGE);
    return "redirect:/admin/payment_plugin/list.jhtml";
}