Example usage for org.joda.time DateTime parse

List of usage examples for org.joda.time DateTime parse

Introduction

In this page you can find the example usage for org.joda.time DateTime parse.

Prototype

@FromString
public static DateTime parse(String str) 

Source Link

Document

Parses a DateTime from the specified string.

Usage

From source file:com.appdynamics.analytics.processor.elasticsearch.scripts.AccountConfigUpsertScript.java

private static Map<String, Object> updateAccountConfiguration(Map existingConfig,
        Map<String, Object> fieldsToUpdate)
/*     */ {//from  w  w w .java2  s. c om
    /*  66 */ Map<String, Object> result = new LinkedHashMap();
    /*     */
    /*  68 */ DateTime existingExpiryDate = null;
    /*  69 */ if (existingConfig.get("expirationDate") != null) {
        /*  70 */ existingExpiryDate = DateTime.parse(String.valueOf(existingConfig.get("expirationDate")));
        /*     */ }
    /*     */
    /*  73 */ DateTime resolvedExpiryDate = existingExpiryDate;
    /*  74 */ if (fieldsToUpdate.get("expirationDate") != null) {
        /*  75 */ resolvedExpiryDate = determineAccountExpiryDate(existingExpiryDate,
                DateTime.parse((String) fieldsToUpdate.get("expirationDate")));
        /*     */ }
    /*     */
    /*     */
    /*  79 */ result.put("expirationDate", resolvedExpiryDate);
    /*  80 */ result.put("accountName", existingConfig.get("accountName"));
    /*  81 */ result.put("accessKey", fieldsToUpdate.get("accessKey"));
    /*  82 */ result.put("eumAccountName", fieldsToUpdate.get("eumAccountName"));
    /*  83 */ result.put("licensingConfigurations",
            getMergedLicenceConfig((List) existingConfig.get("licensingConfigurations"),
                    (List) fieldsToUpdate.get("licensingConfigurations")));
    /*     */
    /*     */
    /*  86 */ return result;
    /*     */ }

From source file:com.aptechfpt.controller.ProductReportController.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods./*from  w  w w.j a v  a2 s  .c  o  m*/
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    try {
        InitialContext context = new InitialContext();
        productFacade = (ProductFacadeLocal) context.lookup(
                "java:global/Unify-ear/Unify-ejb-1.0-SNAPSHOT/ProductFacade!com.aptechfpt.bean.ProductFacadeLocal");
    } catch (Exception e) {
        e.printStackTrace();
    }
    response.setContentType("text/html;charset=UTF-8");
    try (PrintWriter out = response.getWriter()) {

        String date = request.getParameter("daterange");
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM/dd/yyyy");
        String from = LocalDate.parse(date.split("-")[0].trim(), formatter).toString();
        String to = LocalDate.parse(date.split("-")[1].trim(), formatter).toString();
        DateTime fdate = DateTime.parse(from);
        DateTime tdate = DateTime.parse(to);
        List<Product> listproduct = productFacade.findAll();
        int tongsanpham = listproduct.size();
        int spdangban = 0, sphuyban = 0;
        for (Product p : listproduct) {
            if (p.getAvailable()) {
                spdangban++;
            } else
                sphuyban++;
        }

        List<Category> listcategory = categoryFacade.findAll();
        List<Product> listtoplike = productFacade.getTop10Like();
        List<HighSale> listtopsale = purchaseOrderDetailFacade.getTop10Buy(from, to);
        int days = Days.daysBetween(fdate, tdate).getDays();
        List<String> lname = new ArrayList();
        List<Integer> lquanity = new ArrayList();
        for (HighSale i : listtopsale) {
            lname.add(i.getProductName());
            lquanity.add(i.getQuantity());
        }
        List<HighSale> listtopcomment = commentFacade.getTop10Comment(from, to);

        HttpSession s = request.getSession();
        s.setAttribute("tongsanpham", tongsanpham);
        s.setAttribute("spdangban", spdangban);
        s.setAttribute("sphuyban", sphuyban);
        s.setAttribute("listcategory", listcategory);
        s.setAttribute("listtoplike", listtoplike);
        s.setAttribute("listtopsale", listtopsale);
        s.setAttribute("listtopcomment", listtopcomment);
        s.setAttribute("from", from);
        s.setAttribute("to", to);
        s.setAttribute("day", days);
        s.setAttribute("names", lname);
        s.setAttribute("quantity", lquanity);
        request.getRequestDispatcher("WEB-INF/admin/productreportview.jsp").forward(request, response);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.aptechfpt.controller.PurchaseReportController.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods./* ww  w. j  a va2  s. c o m*/
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    try {
        InitialContext context = new InitialContext();
        purchaseOrderFacade = (PurchaseOrderFacadeLocal) context.lookup(
                "java:global/Unify-ear/Unify-ejb-1.0-SNAPSHOT/PurchaseOrderFacade!com.aptechfpt.bean.PurchaseOrderFacadeLocal");
    } catch (Exception e) {
        e.printStackTrace();
    }
    response.setContentType("text/html;charset=UTF-8");
    try (PrintWriter out = response.getWriter()) {
        request.setCharacterEncoding("UTF-8");
        String date = request.getParameter("daterange");
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM/dd/yyyy");
        String from = LocalDate.parse(date.split("-")[0].trim(), formatter).toString();
        String to = LocalDate.parse(date.split("-")[1].trim(), formatter).toString();
        DateTime fdate = DateTime.parse(from);
        DateTime tdate = DateTime.parse(to);
        List<PurchaseOrder> list = purchaseOrderFacade.getReport(fdate, tdate);
        double doanhthu = 0, loinhuan = 0;
        int donhang = list.size();
        int hanghoa = 0, hoanthanh = 0, giaohang = 0;
        int access = 0, dress = 0, pant = 0, shirt = 0, cancel = 0;
        for (PurchaseOrder p : list) {
            if (p.getCancelInvoice()) {
                if (p.getStatus()) {
                    doanhthu += p.getSubTotal().doubleValue();
                    hoanthanh++;
                    for (PurchaseOrderDetail pod : p.getPurchaseOrderDetailCollection()) {
                        hanghoa += pod.getQuantity();
                        loinhuan += (pod.getUnitPrice().doubleValue() - pod.getCost().doubleValue())
                                * pod.getQuantity();
                        if (pod.getProductId().getSubCategoryId().getCategoryId().getName()
                                .equalsIgnoreCase("Accessory")) {
                            access += pod.getQuantity();
                        }
                        if (pod.getProductId().getSubCategoryId().getCategoryId().getName()
                                .equalsIgnoreCase("Dress")) {
                            dress += pod.getQuantity();
                        }
                        if (pod.getProductId().getSubCategoryId().getCategoryId().getName()
                                .equalsIgnoreCase("Pants")) {
                            pant += pod.getQuantity();
                        }
                        if (pod.getProductId().getSubCategoryId().getCategoryId().getName()
                                .equalsIgnoreCase("Shirt")) {
                            shirt += pod.getQuantity();
                        }
                    }
                } else {
                    giaohang++;
                }
            } else {
                cancel++;
            }

        }

        MaHoa mh = new MaHoa();
        for (PurchaseOrder p : list) {
            p.setName(mh.decrypt(p.getName()));
            p.setAddress(mh.decrypt(p.getAddress()));
            p.setPhone(mh.decrypt(p.getPhone()));

        }
        int days = Days.daysBetween(fdate, tdate).getDays();
        //            request.setAttribute("doanhthu", doanhthu);
        //            request.setAttribute("loinhuan", loinhuan);
        //            request.setAttribute("hanghoa", hanghoa);
        //            request.setAttribute("donhang", donhang);
        //            request.setAttribute("hoanthanh", hoanthanh);
        //            request.setAttribute("giaohang", giaohang);
        //
        //            request.setAttribute("acc", access);
        //            request.setAttribute("pant", pant);
        //            request.setAttribute("dress", dress);
        //            request.setAttribute("shirt", shirt);
        //            request.setAttribute("cancel", cancel);
        //            request.setAttribute("list", list);

        HttpSession session = request.getSession();
        session.setAttribute("doanhthu", doanhthu);
        session.setAttribute("loinhuan", loinhuan);
        session.setAttribute("hanghoa", hanghoa);
        session.setAttribute("donhang", donhang);
        session.setAttribute("hoanthanh", hoanthanh);
        session.setAttribute("giaohang", giaohang);

        session.setAttribute("acc", access);
        session.setAttribute("pant", pant);
        session.setAttribute("dress", dress);
        session.setAttribute("shirt", shirt);
        session.setAttribute("cancel", cancel);
        session.setAttribute("list", list);
        session.setAttribute("day", days);
        session.setAttribute("from", from);
        session.setAttribute("to", to);
        request.getRequestDispatcher("WEB-INF/admin/reportprint.jsp").forward(request, response);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.arangodb.velocypack.module.joda.internal.util.JodaTimeUtil.java

License:Apache License

public static DateTime parseDateTime(final String source) {
    return DateTime.parse(source);
}

From source file:com.arpnetworking.clusteraggregator.aggregation.StreamingAggregator.java

License:Apache License

private void processAggregationMessage(final Messages.StatisticSetRecord data) {
    final CombinedMetricData metricData = CombinedMetricData.Builder.fromStatisticSetRecord(data).build();
    //First message sets the data we know about this actor
    if (!_initialized) {
        _period = metricData.getPeriod();
        _cluster = metricData.getCluster();
        _metric = metricData.getMetricName();
        _service = metricData.getService();
        _resultBuilder = new AggregatedData.Builder().setHost(createHost()).setPeriod(_period)
                .setPopulationSize(1L).setSamples(Collections.<Quantity>emptyList())
                .setStart(DateTime.now().hourOfDay().roundFloorCopy())
                .setValue(new Quantity.Builder().setValue(0d).build());

        _initialized = true;/* w  w  w . j av a 2 s  .  com*/
        LOGGER.debug().setMessage("Initialized aggregator").addContext("actor", self()).log();
    } else if (!(_period.equals(metricData.getPeriod()) && _cluster.equals(metricData.getCluster())
            && _service.equals(metricData.getService()) && _metric.equals(metricData.getMetricName()))) {
        LOGGER.error().setMessage("Received a work item for another aggregator").addData("workItem", data)
                .addContext("actor", self()).log();
    }
    //Find the time bucket to dump this in
    final DateTime periodStart = DateTime.parse(data.getPeriodStart());
    if (_aggBuckets.size() > 0 && _aggBuckets.getFirst().getPeriodStart().isAfter(periodStart)) {
        //We got a bit of data that is too old for us to aggregate.
        LOGGER.warn().setMessage("Received a work item that is too old to aggregate")
                .addData("bucketStart", _aggBuckets.getFirst().getPeriodStart()).addData("workItem", data)
                .addContext("actor", self()).log();
    } else {
        if (_aggBuckets.size() == 0 || _aggBuckets.getLast().getPeriodStart().isBefore(periodStart)) {
            //We need to create a new bucket to hold this data.
            LOGGER.debug().setMessage("Creating new aggregation bucket for period")
                    .addData("period", periodStart).addContext("actor", self()).log();
            _aggBuckets.add(new StreamingAggregationBucket(periodStart));
        }
        final Iterator<StreamingAggregationBucket> bucketIterator = _aggBuckets.iterator();
        StreamingAggregationBucket currentBucket;
        StreamingAggregationBucket correctBucket = null;
        while (bucketIterator.hasNext()) {
            currentBucket = bucketIterator.next();
            if (currentBucket.getPeriodStart().equals(periodStart)) {
                //We found the correct bucket
                correctBucket = currentBucket;
                break;
            }
        }

        if (correctBucket == null) {
            LOGGER.error().setMessage("No bucket found to aggregate into, bug in the bucket walk")
                    .addContext("actor", self()).log();
        } else {
            LOGGER.debug().setMessage("Updating bucket").addData("bucket", correctBucket)
                    .addData("data", metricData).addContext("actor", self()).log();
            correctBucket.update(metricData);
            LOGGER.debug().setMessage("Done updating bucket").addData("bucket", correctBucket)
                    .addContext("actor", self()).log();
        }
    }
}

From source file:com.arpnetworking.clusteraggregator.client.AggClientConnection.java

License:Apache License

private Optional<AggregatedData> getAggData(final Messages.LegacyAggRecord aggRecord) {
    try {/* w w w  .ja  va  2  s.c  o  m*/
        long sampleCount = 1;
        if (aggRecord.hasRawSampleCount()) {
            sampleCount = aggRecord.getRawSampleCount();
        } else if (aggRecord.getStatisticSamplesCount() > 0) {
            sampleCount = aggRecord.getStatisticSamplesCount();
        }

        final Period period = Period.parse(aggRecord.getPeriod());
        DateTime periodStart;
        if (aggRecord.hasPeriodStart()) {
            periodStart = DateTime.parse(aggRecord.getPeriodStart());
        } else {
            periodStart = DateTime.now().withTime(DateTime.now().getHourOfDay(), 0, 0, 0);
            while (periodStart.plus(period).isBeforeNow()) {
                periodStart = periodStart.plus(period);
            }
        }

        final Optional<Statistic> statisticOptional = _statisticFactory
                .createStatistic(aggRecord.getStatistic());
        if (!statisticOptional.isPresent()) {
            _log.error(String.format("Unsupported statistic %s", aggRecord.getStatistic()));
            return Optional.absent();
        }

        return Optional.of(new AggregatedData.Builder().setHost(_hostName.get())
                .setFQDSN(new FQDSN.Builder().setCluster(_clusterName.get()).setService(aggRecord.getService())
                        .setMetric(aggRecord.getMetric()).setStatistic(statisticOptional.get()).build())
                .setPeriod(Period.parse(aggRecord.getPeriod())).setStart(periodStart)
                .setPopulationSize(sampleCount)
                .setSamples(sampleizeDoubles(aggRecord.getStatisticSamplesList(), Optional.<Unit>absent()))
                .setValue(new Quantity(aggRecord.getStatisticValue(), Optional.<Unit>absent())).build());
        // CHECKSTYLE.OFF: IllegalCatch - The legacy parsing can throw a variety of runtime exceptions
    } catch (final RuntimeException e) {
        // CHECKSTYLE.ON: IllegalCatch
        _log.error("Caught an error parsing legacy agg record", e);
        return Optional.absent();
    }
}

From source file:com.arpnetworking.clusteraggregator.client.AggClientConnection.java

License:Apache License

private Optional<AggregatedData> getAggData(final Messages.AggregationRecord aggRecord) {
    final Optional<Statistic> statisticOptional = _statisticFactory.createStatistic(aggRecord.getStatistic());
    if (!statisticOptional.isPresent()) {
        _log.error(String.format("Unsupported statistic %s", aggRecord.getStatistic()));
        return Optional.absent();
    }/*from   ww w .j a  v  a2  s  .co  m*/
    final Optional<Unit> recordUnit;
    if (Strings.isNullOrEmpty(aggRecord.getUnit())) {
        recordUnit = Optional.absent();
    } else {
        recordUnit = Optional.fromNullable(Unit.valueOf(aggRecord.getUnit()));
    }
    final Quantity quantity = new Quantity(aggRecord.getStatisticValue(), recordUnit);
    return Optional.of(new AggregatedData.Builder().setHost(_hostName.get())
            .setFQDSN(new FQDSN.Builder().setService(aggRecord.getService()).setMetric(aggRecord.getMetric())
                    .setCluster(_clusterName.get()).setStatistic(statisticOptional.get()).build())
            .setPeriod(Period.parse(aggRecord.getPeriod())).setStart(DateTime.parse(aggRecord.getPeriodStart()))
            .setPopulationSize(aggRecord.getPopulationSize())
            .setSamples(sampleizeDoubles(aggRecord.getSamplesList(), recordUnit)).setValue(quantity).build());
}

From source file:com.bbva.arq.devops.ae.mirrorgate.collectors.jira.support.JiraIssueUtils.java

License:Apache License

private <T> T parse(String s, Class<T> type) {
    if (s == null || s.equals("<null>")) {
        return null;
    } else if (type.isEnum()) {
        Class<? extends Enum> enumType = (Class<? extends Enum>) type;
        return (T) Enum.valueOf(enumType, s);
    } else if (type == Date.class) {
        return (T) DateTime.parse(s).toDate();
    } else if (type == String.class) {
        return (T) s;
    }/*ww w  .j ava 2 s .c o  m*/
    return null;
}

From source file:com.blackducksoftware.bdio.model.AbstractModel.java

License:Apache License

/**
 * Helper to coerce a value into a timestamp.
 *//*  w ww .j  a v  a2 s.  c o m*/
@Nullable
protected static DateTime valueToDateTime(@Nullable Object value) {
    String stringValue = valueToString(value);
    return stringValue != null ? DateTime.parse(stringValue) : null;
}

From source file:com.blackducksoftware.integration.hub.api.item.HubItem.java

License:Apache License

public DateTime getDateTime(final String time) {
    if (StringUtils.isBlank(time)) {
        return null;
    }/*from ww w .j  av  a2  s.com*/
    try {
        return DateTime.parse(time);
    } catch (final IllegalArgumentException e) {
        return null;
    }
}