Example usage for java.math BigDecimal floatValue

List of usage examples for java.math BigDecimal floatValue

Introduction

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

Prototype

@Override
public float floatValue() 

Source Link

Document

Converts this BigDecimal to a float .

Usage

From source file:org.moqui.impl.entity.EntityJavaUtil.java

public static Object convertFromString(String value, FieldInfo fi, L10nFacade l10n) {
    Object outValue;//from  w  w  w .  j av a2  s  . co  m
    boolean isEmpty = value.length() == 0;

    try {
        switch (fi.typeValue) {
        case 1:
            outValue = value;
            break;
        case 2: // outValue = java.sql.Timestamp.valueOf(value);
            if (isEmpty) {
                outValue = null;
                break;
            }
            outValue = l10n.parseTimestamp(value, null);
            if (outValue == null)
                throw new BaseException("The value [" + value + "] is not a valid date/time for field "
                        + fi.entityName + "." + fi.name);
            break;
        case 3: // outValue = java.sql.Time.valueOf(value);
            if (isEmpty) {
                outValue = null;
                break;
            }
            outValue = l10n.parseTime(value, null);
            if (outValue == null)
                throw new BaseException("The value [" + value + "] is not a valid time for field "
                        + fi.entityName + "." + fi.name);
            break;
        case 4: // outValue = java.sql.Date.valueOf(value);
            if (isEmpty) {
                outValue = null;
                break;
            }
            outValue = l10n.parseDate(value, null);
            if (outValue == null)
                throw new BaseException("The value [" + value + "] is not a valid date for field "
                        + fi.entityName + "." + fi.name);
            break;
        case 5: // outValue = Integer.valueOf(value); break
        case 6: // outValue = Long.valueOf(value); break
        case 7: // outValue = Float.valueOf(value); break
        case 8: // outValue = Double.valueOf(value); break
        case 9: // outValue = new BigDecimal(value); break
            if (isEmpty) {
                outValue = null;
                break;
            }
            BigDecimal bdVal = l10n.parseNumber(value, null);
            if (bdVal == null) {
                throw new BaseException("The value [" + value + "] is not valid for type [" + fi.javaType
                        + "] for field " + fi.entityName + "." + fi.name);
            } else {
                bdVal = bdVal.stripTrailingZeros();
                switch (fi.typeValue) {
                case 5:
                    outValue = bdVal.intValue();
                    break;
                case 6:
                    outValue = bdVal.longValue();
                    break;
                case 7:
                    outValue = bdVal.floatValue();
                    break;
                case 8:
                    outValue = bdVal.doubleValue();
                    break;
                default:
                    outValue = bdVal;
                    break;
                }
            }
            break;
        case 10:
            if (isEmpty) {
                outValue = null;
                break;
            }
            outValue = Boolean.valueOf(value);
            break;
        case 11:
            outValue = value;
            break;
        case 12:
            try {
                outValue = new SerialBlob(value.getBytes());
            } catch (SQLException e) {
                throw new BaseException("Error creating SerialBlob for value [" + value + "] for field "
                        + fi.entityName + "." + fi.name);
            }
            break;
        case 13:
            outValue = value;
            break;
        case 14:
            if (isEmpty) {
                outValue = null;
                break;
            }
            Timestamp ts = l10n.parseTimestamp(value, null);
            outValue = new java.util.Date(ts.getTime());
            break;
        // better way for Collection (15)? maybe parse comma separated, but probably doesn't make sense in the first place
        case 15:
            outValue = value;
            break;
        default:
            outValue = value;
            break;
        }
    } catch (IllegalArgumentException e) {
        throw new BaseException("The value [" + value + "] is not valid for type [" + fi.javaType
                + "] for field " + fi.entityName + "." + fi.name, e);
    }

    return outValue;
}

From source file:com.salesmanager.core.module.impl.application.prices.OneTimePriceModule.java

public OrderTotalSummary calculateOrderPrice(Order order, OrderTotalSummary orderSummary,
        OrderProduct orderProduct, OrderProductPrice productPrice, String currency, Locale locale) {
    // TODO Auto-generated method stub

    /**/*from  w  w  w.j ava 2 s .co m*/
     * activation price goes in the oneTime fees
     */

    BigDecimal finalPrice = null;
    // BigDecimal discountPrice=null;

    // order price this type of price needs an upfront payment
    BigDecimal otprice = orderSummary.getOneTimeSubTotal();
    if (otprice == null) {
        otprice = new BigDecimal(0);
    }

    // the final price is in the product price
    finalPrice = productPrice.getProductPriceAmount();
    int quantity = orderProduct.getProductQuantity();
    finalPrice = finalPrice.multiply(new BigDecimal(quantity));

    otprice = otprice.add(finalPrice);
    orderSummary.setOneTimeSubTotal(otprice);

    ProductPriceSpecial pps = productPrice.getSpecial();

    // Build text

    StringBuffer notes = new StringBuffer();
    notes.append(quantity).append(" x ");
    notes.append(orderProduct.getProductName());
    notes.append(" ");
    notes.append(
            CurrencyUtil.displayFormatedAmountWithCurrency(productPrice.getProductPriceAmount(), currency));
    notes.append(" ");

    notes.append(productPrice.getProductPriceName());

    BigDecimal originalPrice = orderProduct.getOriginalProductPrice();
    if (!productPrice.isDefaultPrice()) {
        originalPrice = productPrice.getProductPriceAmount();
    }

    if (pps != null) {
        if (pps.getProductPriceSpecialStartDate() != null && pps.getProductPriceSpecialEndDate() != null) {
            if (pps.getProductPriceSpecialStartDate().before(order.getDatePurchased())
                    && pps.getProductPriceSpecialEndDate().after(order.getDatePurchased())) {

                BigDecimal dPrice = new BigDecimal(ProductUtil.determinePrice(productPrice).floatValue());

                if (dPrice.floatValue() < productPrice.getProductPriceAmount().floatValue()) {

                    BigDecimal subTotal = originalPrice
                            .multiply(new BigDecimal(orderProduct.getProductQuantity()));
                    BigDecimal creditSubTotal = pps.getProductPriceSpecialAmount()
                            .multiply(new BigDecimal(orderProduct.getProductQuantity()));

                    BigDecimal credit = subTotal.subtract(creditSubTotal);

                    StringBuffer spacialNote = new StringBuffer();
                    spacialNote.append("<font color=\"red\">[");

                    spacialNote.append(productPrice.getProductPriceName());

                    // spacialNote.append(getPriceText(currency,locale));

                    spacialNote.append(" ");
                    spacialNote.append(CurrencyUtil.displayFormatedAmountWithCurrency(credit, currency));

                    spacialNote.append("]</font>");

                    if (productPrice.getProductPriceAmount().doubleValue() > pps.getProductPriceSpecialAmount()
                            .doubleValue()) {

                        OrderTotalLine line = new OrderTotalLine();
                        line.setText(spacialNote.toString());
                        line.setCost(credit);
                        line.setCostFormated(CurrencyUtil.displayFormatedAmountWithCurrency(credit, currency));
                        orderSummary.addDueNowCredits(line);

                        BigDecimal oneTimeCredit = orderProduct.getApplicableCreditOneTimeCharge();
                        oneTimeCredit = oneTimeCredit.add(credit);
                        orderProduct.setApplicableCreditOneTimeCharge(oneTimeCredit);
                    }
                }

            } else if (pps.getProductPriceSpecialDurationDays() > -1) {

                Date dt = new Date();

                int numDays = pps.getProductPriceSpecialDurationDays();
                Date purchased = order.getDatePurchased();
                Calendar c = Calendar.getInstance();
                c.setTime(dt);
                c.add(Calendar.DATE, numDays);

                BigDecimal dPrice = new BigDecimal(ProductUtil.determinePrice(productPrice).floatValue());

                if (dt.before(c.getTime())
                        && dPrice.floatValue() < productPrice.getProductPriceAmount().floatValue()) {

                    BigDecimal subTotal = originalPrice
                            .multiply(new BigDecimal(orderProduct.getProductQuantity()));
                    BigDecimal creditSubTotal = pps.getProductPriceSpecialAmount()
                            .multiply(new BigDecimal(orderProduct.getProductQuantity()));

                    BigDecimal credit = subTotal.subtract(creditSubTotal);

                    StringBuffer spacialNote = new StringBuffer();
                    spacialNote.append("<font color=\"red\">[");

                    spacialNote.append(productPrice.getProductPriceName());

                    // spacialNote.append(getPriceText(currency,locale));
                    spacialNote.append(" ");
                    spacialNote.append(CurrencyUtil.displayFormatedAmountWithCurrency(credit, currency));

                    spacialNote.append("]</font>");

                    if (productPrice.getProductPriceAmount().doubleValue() > pps.getProductPriceSpecialAmount()
                            .doubleValue()) {

                        OrderTotalLine line = new OrderTotalLine();

                        line.setText(spacialNote.toString());
                        line.setCost(credit);
                        line.setCostFormated(CurrencyUtil.displayFormatedAmountWithCurrency(credit, currency));
                        orderSummary.addDueNowCredits(line);

                        BigDecimal oneTimeCredit = orderProduct.getApplicableCreditOneTimeCharge();
                        oneTimeCredit = oneTimeCredit.add(credit);
                        orderProduct.setApplicableCreditOneTimeCharge(oneTimeCredit);

                    }

                }

            }
        }

    }

    if (!productPrice.isDefaultPrice()) {

        // add a price description
        OrderTotalLine scl = new OrderTotalLine();
        scl.setText(notes.toString());
        scl.setCost(finalPrice);
        scl.setCostFormated(CurrencyUtil.displayFormatedAmountWithCurrency(finalPrice, currency));
        orderSummary.addOtherDueNowPrice(scl);
    }

    return orderSummary;

}

From source file:org.hoteia.qalingo.core.solr.service.ProductMarketingSolrService.java

public void addOrUpdateProductMarketing(final ProductMarketing productMarketing,
        final List<ProductSku> productSkus, final List<CatalogCategoryVirtual> catalogCategories,
        final MarketArea marketArea, final Retailer retailer) throws SolrServerException, IOException {
    if (productMarketing.getId() == null) {
        throw new IllegalArgumentException("Id  cannot be blank or null.");
    }//w  ww.  j  ava  2  s  .co m
    if (logger.isDebugEnabled()) {
        logger.debug("Indexing productMarketing " + productMarketing.getId() + " : "
                + productMarketing.getCode() + " : " + productMarketing.getName());
    }

    ProductMarketingSolr productMarketingSolr = new ProductMarketingSolr();
    productMarketingSolr.setId(productMarketing.getId());
    productMarketingSolr.setCode(productMarketing.getCode());
    productMarketingSolr.setName(productMarketing.getName());
    productMarketingSolr.setDescription(productMarketing.getDescription());

    productMarketingSolr.setEnabledB2B(productMarketing.isEnabledB2B());
    productMarketingSolr.setEnabledB2C(productMarketing.isEnabledB2C());

    productMarketingSolr.setSalableB2B(productMarketing.isSalableB2B());
    productMarketingSolr.setSalableB2C(productMarketing.isSalableB2C());

    if (productMarketing.getProductBrand() != null
            && Hibernate.isInitialized(productMarketing.getProductBrand())) {
        productMarketingSolr.setProductBrandCode(productMarketing.getProductBrand().getCode());
        productMarketingSolr.setProductBrandName(productMarketing.getProductBrand().getName());
    }

    CatalogCategoryVirtual defaultVirtualCatalogCategory = productService
            .getDefaultVirtualCatalogCategory(productMarketing, catalogCategories, true);

    if (defaultVirtualCatalogCategory != null) {
        productMarketingSolr.setDefaultCategoryCode(defaultVirtualCatalogCategory.getCode());
    }

    if (catalogCategories != null) {
        for (CatalogCategoryVirtual catalogCategoryVirtual : catalogCategories) {
            String catalogCode = catalogCategoryVirtual.getCatalog().getCode();
            productMarketingSolr.addCatalogCode(catalogCode);
            String catalogCategoryCode = catalogCode + "_" + catalogCategoryVirtual.getCode();
            productMarketingSolr.addCatalogCategory(catalogCategoryCode);
        }
    }

    if (productSkus != null) {
        // REGROUP SKU OPTION
        Map<String, String> skuOptionDefinitionsCodes = new HashMap<String, String>();
        for (ProductSku productSku : productSkus) {
            if (productSku.getOptionRels() != null && Hibernate.isInitialized(productSku.getOptionRels())) {
                for (ProductSkuOptionRel productSkuOptionRel : productSku.getOptionRels()) {
                    if (productSkuOptionRel.getProductSkuOptionDefinition() != null
                            && Hibernate.isInitialized(productSkuOptionRel.getProductSkuOptionDefinition())) {
                        skuOptionDefinitionsCodes.put(
                                productSkuOptionRel.getProductSkuOptionDefinition().getCode(),
                                productSkuOptionRel.getProductSkuOptionDefinition().getCode());
                    }
                }
            }
        }
        for (Iterator<String> iterator = skuOptionDefinitionsCodes.keySet().iterator(); iterator.hasNext();) {
            String skuOptionDefinitionCode = (String) iterator.next();
            productMarketingSolr.addOptionDefinition(skuOptionDefinitionCode);
        }

        // REGROUP TAGS
        Map<String, String> tagCodes = new HashMap<String, String>();
        for (ProductSku productSku : productSkus) {
            if (productSku.getTagRels() != null && Hibernate.isInitialized(productSku.getTagRels())) {
                for (ProductSkuTagRel tagRel : productSku.getTagRels()) {
                    if (tagRel.getProductSkuTag() != null
                            && Hibernate.isInitialized(tagRel.getProductSkuTag())) {
                        tagCodes.put(tagRel.getProductSkuTag().getCode(), tagRel.getProductSkuTag().getCode());
                    }
                }
            }
        }
        for (Iterator<String> iterator = tagCodes.keySet().iterator(); iterator.hasNext();) {
            String tagCode = (String) iterator.next();
            productMarketingSolr.addTag(tagCode);
        }
    }

    if (marketArea != null && retailer != null) {
        if (productMarketing.getDefaultProductSku() != null) {
            ProductSkuPrice productSkuPrice = productMarketing.getDefaultProductSku()
                    .getBestPrice(marketArea.getId());
            if (productSkuPrice != null) {
                BigDecimal salePrice = productSkuPrice.getSalePrice();
                productMarketingSolr.setPrice(salePrice.floatValue());
            }
        }
    }

    productMarketingSolrServer.addBean(productMarketingSolr);
    productMarketingSolrServer.commit();
}

From source file:org.openhab.binding.yamahareceiver.handler.YamahaBridgeHandler.java

/**
 * Calls createCommunicationObject if the host name is configured correctly.
 *//*  w w w .  j av  a2  s  . c om*/
@Override
public void initialize() {
    // Read the configuration for the relative volume change factor.
    BigDecimal relativeVolumeChangeFactorBD = (BigDecimal) thing.getConfiguration()
            .get(YamahaReceiverBindingConstants.CONFIG_RELVOLUMECHANGE);
    if (relativeVolumeChangeFactorBD != null) {
        relativeVolumeChangeFactor = relativeVolumeChangeFactorBD.floatValue();
    }

    String host = (String) thing.getConfiguration().get(YamahaReceiverBindingConstants.CONFIG_HOST_NAME);
    BigDecimal port = (BigDecimal) thing.getConfiguration()
            .get(YamahaReceiverBindingConstants.CONFIG_HOST_PORT);

    if (StringUtils.isEmpty(host) || port == null) {
        updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, "Hostname or port not set!");
        return;
    }

    zoneDiscoveryService = new ZoneDiscoveryService(bundleContext);

    updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_PENDING, "Waiting for data");
    ProtocolFactory.createConnection(host + ":" + String.valueOf(port.intValue()), this);
}

From source file:org.openhab.binding.yamahareceiver.handler.YamahaBridgeHandler.java

/**
 * We handle the update ourself to avoid a costly dispose/initialize
 *///from ww  w.  java2 s.  com
@Override
public void handleConfigurationUpdate(Map<String, Object> configurationParameters) {
    if (!isInitialized()) {
        super.handleConfigurationUpdate(configurationParameters);
        return;
    }

    validateConfigurationParameters(configurationParameters);

    // can be overridden by subclasses
    Configuration configuration = editConfiguration();
    for (Entry<String, Object> configurationParmeter : configurationParameters.entrySet()) {
        configuration.put(configurationParmeter.getKey(), configurationParmeter.getValue());
    }

    updateConfiguration(configuration);

    // Check if host configuration has changed
    String hostConfig = (String) thing.getConfiguration().get(YamahaReceiverBindingConstants.CONFIG_HOST_NAME);
    if (hostConfig != null) {
        connection.setHost(hostConfig);
    }

    // Check if refresh configuration has changed
    BigDecimal intervalConfig = (BigDecimal) thing.getConfiguration()
            .get(YamahaReceiverBindingConstants.CONFIG_REFRESH);
    if (intervalConfig != null && intervalConfig.intValue() != refrehInterval) {
        setupRefreshTimer(intervalConfig.intValue());
    }

    // Read the configuration for the relative volume change factor.
    BigDecimal relativeVolumeChangeFactorBD = (BigDecimal) thing.getConfiguration()
            .get(YamahaReceiverBindingConstants.CONFIG_RELVOLUMECHANGE);
    if (relativeVolumeChangeFactorBD != null) {
        relativeVolumeChangeFactor = relativeVolumeChangeFactorBD.floatValue();
    } else {
        relativeVolumeChangeFactor = 0.5f;
    }
}

From source file:com.norconex.collector.http.db.impl.derby.DerbyCrawlURLDatabase.java

private CrawlURL toCrawlURL(ResultSet rs) throws SQLException {
    if (rs == null) {
        return null;
    }/*  www . j  a  v a2s  . c o m*/
    int colCount = rs.getMetaData().getColumnCount();
    CrawlURL crawlURL = new CrawlURL(rs.getString("url"), rs.getInt("depth"));
    if (colCount > COLCOUNT_SITEMAP) {
        crawlURL.setSitemapChangeFreq(rs.getString("smChangeFreq"));
        BigDecimal bigP = rs.getBigDecimal("smPriority");
        if (bigP != null) {
            crawlURL.setSitemapPriority(bigP.floatValue());
        }
        BigDecimal bigLM = rs.getBigDecimal("smLastMod");
        if (bigLM != null) {
            crawlURL.setSitemapLastMod(bigLM.longValue());
        }
        if (colCount > COLCOUNT_ALL) {
            crawlURL.setDocChecksum(rs.getString("docchecksum"));
            crawlURL.setHeadChecksum(rs.getString("headchecksum"));
            crawlURL.setStatus(CrawlStatus.valueOf(rs.getString("status")));
        }
    }
    return crawlURL;
}

From source file:fixio.fixprotocol.fields.FieldFactoryTest.java

@Test
public void testValueOfQty() throws Exception {
    BigDecimal value = BigDecimal.valueOf(new Random().nextInt()).movePointLeft(5);

    FloatField field = FieldFactory.valueOf(FieldType.OrderQty.tag(), value.toPlainString().getBytes(US_ASCII));

    assertEquals("tagnum", FieldType.OrderQty.tag(), field.getTagNum());
    assertEquals("value", value.doubleValue(), field.getValue().doubleValue(), 0.0);
    assertEquals("value", value.floatValue(), field.floatValue(), 0.0);
}

From source file:fixio.fixprotocol.fields.FieldFactoryTest.java

@Test
public void testValueOfPrice() throws Exception {
    BigDecimal value = BigDecimal.valueOf(new Random().nextInt()).movePointLeft(5);

    FloatField field = FieldFactory.valueOf(FieldType.MktBidPx.tag(), value.toPlainString().getBytes(US_ASCII));

    assertEquals("tagnum", FieldType.MktBidPx.tag(), field.getTagNum());
    assertEquals("value", value.doubleValue(), field.getValue().doubleValue(), 0.0);
    assertEquals("value", value.floatValue(), field.floatValue(), 0.0);
}

From source file:org.sofun.core.kup.policy.KupSettledLifeCyclePolicyManager.java

/**
 * Kup life cycle management./*from w  w w.j  ava 2 s .  com*/
 * 
 * @throws Exception
 */
@Schedule(minute = "*/5", hour = "*", persistent = false)
public void check() throws Exception {

    if (!available) {
        return;
    } else {
        available = false;
    }

    try {

        log.debug("Checking Kups and apply policy...");

        //
        // Deal with Settled Kups
        //

        final byte[] settledStatus = new byte[1];
        settledStatus[0] = KupStatus.SETTLED;
        String[] types = new String[] { KupType.GAMBLING_FR };

        ListIterator<Kup> kupsIter = kups.getKupsByStatus(settledStatus, types).listIterator();
        while (kupsIter.hasNext()) {

            Kup kup = kupsIter.next();
            // Ensure no changes have been made by another transaction in
            // the mean time.
            em.refresh(kup);
            if (kup.getStatus() != KupStatus.SETTLED) {
                continue;
            }

            Map<Integer, Float> repartition = kups.getWinningsRepartitionRulesFor(kup);
            final int numberOfWinners = repartition.size();

            if (kup.getParticipants().size() < numberOfWinners) {
                kups.cancelKup(kup);
                log.info("Kup with id=" + String.valueOf(kup.getId())
                        + " has been cancelled because participants are " + "below the amount of winners.");
                continue;
            }

            KupRankingTable table = kup.getRankingTable();
            List<MemberRankingTableEntry> entries = new ArrayList<MemberRankingTableEntry>(table.getEntries());
            entries = entries.subList(0, numberOfWinners);

            // Cancel if winnings < bet for one of the winners.
            boolean cancelled = false;
            for (int i = 0; i < numberOfWinners - 1; i++) {

                final float jackpot = kup.getEffectiveJackpot();
                final float amount = jackpot * repartition.get(i + 1) / 100;

                if (kup.getStake() > amount) {
                    cancelled = true;
                    break;
                }

            }

            if (!cancelled) {

                // Credit winners.

                final Date now = new Date();

                final float jackpot = kup.getEffectiveJackpot();
                if (kup.getJackpot() < kup.getGuaranteedPrice()) {
                    final float house = kup.getGuaranteedPrice() - kup.getJackpot();
                    final BigDecimal houseAmount = new BigDecimal(house);
                    houseAmount.setScale(2, BigDecimal.ROUND_HALF_UP);
                    SofunTransaction txn = new SofunTransactionImpl(kup, now, houseAmount.floatValue(),
                            kup.getStakeCurrency(), SofunTransactionType.TXN_GUARANTEED_PRICE,
                            SofunTransactionType.TXN_GUARANTEED_PRICE);
                    txn.setDebit(true);
                    em.persist(txn);
                    log.info("SOFUN TXN for kup w/ uuid=" + txn.getKup().getId() + " type=" + txn.getType()
                            + " amount=" + houseAmount.floatValue());
                } else {
                    final float rake = kup.getRakeAmount();
                    if (rake > 0) {
                        final BigDecimal rakeAmount = new BigDecimal(rake);
                        rakeAmount.setScale(2, BigDecimal.ROUND_HALF_UP);
                        SofunTransaction txn = new SofunTransactionImpl(kup, now, rakeAmount.floatValue(),
                                kup.getStakeCurrency(), SofunTransactionType.TXN_RACK,
                                SofunTransactionType.TXN_RACK);
                        txn.setCredit(true);
                        em.persist(txn);
                        log.info("SOFUN TXN for kup w/ uuid=" + txn.getKup().getId() + " type=" + txn.getType()
                                + " amount=" + rakeAmount.floatValue());
                    }
                }

                int i = 0;
                for (MemberRankingTableEntry entry : entries) {

                    final float amount = jackpot * repartition.get(i + 1) / 100;
                    Member member = entry.getMember();

                    // Round down (inferior cent) as specified in rules.
                    BigDecimal wiredAmount = new BigDecimal(amount);
                    wiredAmount = wiredAmount.setScale(2, BigDecimal.ROUND_HALF_DOWN);

                    MemberTransaction txn = new MemberTransactionImpl(now, wiredAmount.floatValue(),
                            kup.getStakeCurrency(), MemberTransactionType.BET_CREDIT);
                    txn.setLabel(MemberTransactionType.BET_CREDIT);
                    txn.setCredit(true);
                    txn.setStatusCode("00000");
                    txn.setStatus(MemberTransactionStatus.INTERNAL);
                    txn.setMemberCreditBefore(member.getMemberCredit().getCredit());
                    txn.setMemberCreditAfter(member.getMemberCredit().getCredit() + wiredAmount.floatValue());
                    member.addTransaction(txn);
                    txn.setMember(member);

                    log.info("Member with email=" + member.getEmail() + " finished " + String.valueOf(i + 1)
                            + " out of " + kup.getParticipants().size() + " in kup w/ uuid=" + kup.getId()
                            + " txn of type=" + txn.getType() + " with amount of: " + wiredAmount.floatValue());

                    // Record
                    KupMemberBet bet = new KupMemberBetImpl(member, kup, txn);
                    bet.setEffectiveDate(now);
                    em.persist(bet);

                    entry.setWinnings(wiredAmount.floatValue());

                    i++;
                }

                log.info(
                        "Kup with id=" + String.valueOf(kup.getId()) + " has now status=" + KupStatus.PAID_OUT);
                kup.setStatus(KupStatus.PAID_OUT);
            } else {
                kups.cancelKup(kup);
                log.info("Kup with id=" + String.valueOf(kup.getId())
                        + " has been cancelled because the winnings are "
                        + "below the stake for some of the winners.");

            }

        }
    } catch (Throwable t) {
        log.error(t.getMessage());
        t.printStackTrace();
    } finally {
        available = true;
    }

    // Cancel status in exceptional situations will be handled manually per
    // administrator request.
    // @see KupeService.cancelKup()

}

From source file:com.monarchapis.driver.authentication.AuthenticatorV1Impl.java

/**
 * Prepares an authentication request and sends it to the Service API.
 * Response headers are added the API response.
 * /*from   w  w  w . jav  a2 s .co  m*/
 * @param requestWeight
 *            The request weight to count in rate limiting
 * @return the authentication response.
 */
private AuthenticationResponse processAuthentication(BigDecimal requestWeight) {
    ApiRequest apiRequest = ApiRequest.getCurrent();
    HttpServletResponse httpResponse = HttpResponseHolder.getCurrent();

    AuthenticationRequest authRequest = prepareAuthenticationRequest(apiRequest);
    authRequest.setRequestWeight(Optional.of(requestWeight.floatValue()));

    SecurityResource security = serviceApi.getSecurityResource();
    long begin = System.currentTimeMillis();
    AuthenticationResponse authResponse = security.authenticateRequest(authRequest);
    long duration = System.currentTimeMillis() - begin;
    logger.debug("authentication took {}ms", duration);

    if (authResponse.getResponseHeaders() != null) {
        for (HttpHeader header : authResponse.getResponseHeaders()) {
            httpResponse.addHeader(header.getName(), header.getValue());
        }
    }

    return authResponse;
}