Example usage for org.joda.time DateTime now

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

Introduction

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

Prototype

public static DateTime now() 

Source Link

Document

Obtains a DateTime set to the current system millisecond time using ISOChronology in the default time zone.

Usage

From source file:junkProducer.java

License:Open Source License

public static DefaultFeatureCollection simjunk(final SimpleFeatureBuilder builder) {
    final DefaultFeatureCollection featureCollection = new DefaultFeatureCollection();

    Random rng;/*from  w w w .ja  v  a 2 s .  co m*/
    rng = new Random();
    String trainCode;

    // add three features with static meta junk, and random point
    builder.add("Good");
    trainCode = "Train A";
    builder.add(trainCode);
    builder.add("");
    builder.add("unknown");
    builder.add(DateTime.now().toDate());
    double lon = -180 + 360 * rng.nextDouble();
    double lat = -90 + 180 * rng.nextDouble();
    builder.add(WKTUtils$.MODULE$.read("POINT(" + (lon) + " " + (lat) + ")"));
    SimpleFeature feature = builder.buildFeature(trainCode);
    featureCollection.add(feature);

    // add three features with static meta junk, and random point
    builder.reset();
    builder.add("Good");
    trainCode = "Train B";
    builder.add(trainCode);
    builder.add("");
    builder.add("unknown");
    builder.add(DateTime.now().toDate());
    lon = -180 + 360 * rng.nextDouble();
    lat = -90 + 180 * rng.nextDouble();
    builder.add(WKTUtils$.MODULE$.read("POINT(" + (lon) + " " + (lat) + ")"));
    SimpleFeature feature2 = builder.buildFeature(trainCode);
    featureCollection.add(feature2);

    // add three features with static meta junk, and random point
    builder.reset();
    builder.add("Good");
    trainCode = "Train C";
    builder.add(trainCode);
    builder.add("");
    builder.add("unknown");
    builder.add(DateTime.now().toDate());
    lon = -180 + 360 * rng.nextDouble();
    lat = -90 + 180 * rng.nextDouble();
    builder.add(WKTUtils$.MODULE$.read("POINT(" + (lon) + " " + (lat) + ")"));
    SimpleFeature feature3 = builder.buildFeature(trainCode);
    featureCollection.add(feature3);

    return featureCollection;
}

From source file:SOEFinalAlertBolt.java

License:Open Source License

public void execute(Tuple tuple) {

    String message = tuple.getStringByField("message");
    long timeStamp = tuple.getLongByField("timeStamp");

    LOG.info("!!Something Happened in " + nodeID);
    LOG.info("!!At : " + new DateTime(timeStamp).toString());
    LOG.info("!!Current Time : " + DateTime.now());

    try {// w  w w  . ja v a 2s  .  c  o m
        ProcessBuilder builder = new ProcessBuilder("python", PythonFILE1);
        builder.directory(new File(PythonLOCATION));
        Process process = builder.start();
        //      process.waitFor();

        //      builder = new ProcessBuilder("python", PythonFILE2);
        //      builder.directory(new File(PythonLOCATION));
        //      process = builder.start();
        //      process.waitFor();

    } catch (Exception e) {
        LOG.info("[Final Alert]\n" + e.getMessage());
    }

    _collector.ack(tuple);
}

From source file:PresignedPostPolicy.java

License:Apache License

public static void main(String[] args)
        throws IOException, NoSuchAlgorithmException, InvalidKeyException, XmlPullParserException {
    // Note: YOUR-ACCESSKEYID, YOUR-SECRETACCESSKEY and my-bucketname are
    // dummy values, please replace them with original values.
    // For Amazon S3 endpoint, region is calculated automatically
    try {/*from w  ww  . java 2  s.c  om*/
        MinioClient minioClient = new MinioClient("https://s3.amazonaws.com", "YOUR-ACCESSKEYID",
                "YOUR-SECRETACCESSKEY");

        // Create new PostPolicy object for 'my-bucketname', 'my-objectname' and 7 days expire time from now.
        PostPolicy policy = new PostPolicy("my-bucketname", "my-objectname", DateTime.now().plusDays(7));
        // 'my-objectname' should be 'image/png' content type
        policy.setContentType("image/png");
        Map<String, String> formData = minioClient.presignedPostPolicy(policy);

        // Print a curl command that can be executable with the file /tmp/userpic.png and the file will be uploaded.
        System.out.print("curl -X POST ");
        for (Map.Entry<String, String> entry : formData.entrySet()) {
            System.out.print(" -F " + entry.getKey() + "=" + entry.getValue());
        }
        System.out.println(" -F file=@/tmp/userpic.png https://play.minio.io:9000/my-bucketname");
    } catch (MinioException e) {
        System.out.println("Error occurred: " + e);
    }
}

From source file:AdminLogCreator.java

public void processForExecutions(String testName, File logDir)
        throws SAXException, ParserConfigurationException, IOException {
    setTestName(testName);/*  w  w w  .  j  a v a 2 s .c  o m*/
    String[] rootDirs = logDir.list();
    if (null != rootDirs && 0 < rootDirs.length) {
        Arrays.sort(rootDirs);
        for (int i = 0; i < rootDirs.length; i++) {
            String[] dirs = new File(logDir, rootDirs[i]).list();
            if (null != dirs && 0 < dirs.length) {
                Arrays.sort(dirs);
                for (int j = 0; j < dirs.length; j++) {
                    if (new File(new File(new File(logDir, rootDirs[i]), dirs[j]), "session.xml").exists()) {
                        File sessionFile = new File(new File(new File(logDir, rootDirs[i]), dirs[j]),
                                "session.xml");
                        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
                        dbf.setNamespaceAware(true);
                        DocumentBuilder db = dbf.newDocumentBuilder();
                        Document doc = db.parse(sessionFile);
                        Element session = (Element) (doc.getElementsByTagName("session").item(0));
                        if ((session.getAttribute("sourcesId")).contains(testName)) {
                            Path file = sessionFile.toPath();
                            BasicFileAttributes attr = Files.readAttributes(file, BasicFileAttributes.class);
                            DateTime fileCreationTime = new DateTime(attr.creationTime().toString());
                            DateTime currentTime = DateTime.now();
                            int countDay = Days.daysBetween(fileCreationTime, currentTime).getDays();
                            if (countDay <= 30) {
                                setCountLastMonth();
                                setCountLast3Month();
                                setCountLastYear();
                                setCountAllTime();
                            } else if (countDay > 30 && countDay <= 90) {
                                setCountLast3Month();
                                setCountLastYear();
                                setCountAllTime();
                            } else if (countDay > 90 && countDay <= 365) {
                                setCountLastYear();
                                setCountAllTime();
                            } else {
                                setCountAllTime();
                            }
                        }
                    }
                }
            }
        }
    }
}

From source file:AdminLogCreator.java

public void processForUsers(String testName, File logDir)
        throws SAXException, ParserConfigurationException, IOException {
    setTestName(testName);//w  w w  .  j  a va  2  s  .  c  o m
    String[] rootDirs = logDir.list();
    if (null != rootDirs && 0 < rootDirs.length) {
        Arrays.sort(rootDirs);
        for (int i = 0; i < rootDirs.length; i++) {
            innercountLastMonth = 0;
            innercountLast3Month = 0;
            innercountLastYear = 0;
            innercountAllTime = 0;
            String[] dirs = new File(logDir, rootDirs[i]).list();
            if (null != dirs && 0 < dirs.length) {
                Arrays.sort(dirs);
                for (int j = 0; j < dirs.length; j++) {
                    if (new File(new File(new File(logDir, rootDirs[i]), dirs[j]), "session.xml").exists()) {
                        File sessionFile = new File(new File(new File(logDir, rootDirs[i]), dirs[j]),
                                "session.xml");
                        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
                        dbf.setNamespaceAware(true);
                        DocumentBuilder db = dbf.newDocumentBuilder();
                        Document doc = db.parse(sessionFile);
                        Element session = (Element) (doc.getElementsByTagName("session").item(0));
                        if ((session.getAttribute("sourcesId")).contains(testName)) {
                            Path file = sessionFile.toPath();
                            BasicFileAttributes attr = Files.readAttributes(file, BasicFileAttributes.class);
                            DateTime fileCreationTime = new DateTime(attr.creationTime().toString());
                            DateTime currentTime = DateTime.now();
                            int countDay = Days.daysBetween(fileCreationTime, currentTime).getDays();
                            if (countDay <= 30) {
                                innercountLastMonth = 1;
                            } else if (countDay > 30 && countDay <= 90) {
                                innercountLast3Month = 1;
                            } else if (countDay > 90 && countDay <= 365) {
                                innercountLastYear = 1;
                            } else {
                                innercountAllTime = 1;
                            }
                        }
                    }
                }
            }
            if (innercountLastMonth == 1) {
                setCountLastMonth();
                setCountLast3Month();
                setCountLastYear();
                setCountAllTime();
            } else if (innercountLast3Month == 1) {
                setCountLast3Month();
                setCountLastYear();
                setCountAllTime();
            } else if (innercountLastYear == 1) {
                setCountLastYear();
                setCountAllTime();
            } else if (innercountAllTime == 1) {
                setCountAllTime();
            }
        }
    }
}

From source file:iarnrodProducer.java

License:Open Source License

public static DefaultFeatureCollection parseXML(final SimpleFeatureBuilder builder) {

    // sft schema = "trainStatus:String,trainCode:String,publicMessage:String,direction:String,dtg:Date,*geom:Point:srid=4326"
    final DefaultFeatureCollection featureCollection = new DefaultFeatureCollection();

    try {//from  ww  w  .ja v  a  2 s.  c o m
        SAXParserFactory factory = SAXParserFactory.newInstance();
        SAXParser saxParser = factory.newSAXParser();

        DefaultHandler handler = new DefaultHandler() {

            StringBuilder textContent = new StringBuilder();
            String tagName;
            double lat;
            double lon;
            String trainCode;

            public void startElement(String uri, String localName, String qName, Attributes attributes)
                    throws SAXException {
                tagName = qName;
                textContent.setLength(0);
            }

            public void endElement(String uri, String localName, String qName) throws SAXException {
                tagName = qName;
                String text = textContent.toString();

                if (tagName == TRAIN_LAT) {
                    lat = Double.parseDouble(text);
                } else if (tagName == TRAIN_LON) {
                    lon = Double.parseDouble(text);
                } else if (tagName == TRAIN_STATUS) {
                    builder.add(text);
                } else if (tagName == TRAIN_CODE) {
                    trainCode = text; // use this as feature ID
                    builder.add(text);
                } else if (tagName == PUBLIC_MESSAGE) {
                    builder.add(text);
                } else if (tagName == DIRECTION) {
                    builder.add(text); // add direction
                    // this is the last field, so finish up
                    builder.add(DateTime.now().toDate());
                    builder.add(WKTUtils$.MODULE$.read("POINT(" + (lon) + " " + (lat) + ")"));
                    SimpleFeature feature = builder.buildFeature(trainCode);
                    featureCollection.add(feature);
                }

            }

            public void characters(char ch[], int start, int length) throws SAXException {
                textContent.append(ch, start, length);
            }

            public void startDocument() throws SAXException {
                // System.out.println("document started");
            }

            public void endDocument() throws SAXException {
                // System.out.println("document ended");
            }
        }; //handler

        saxParser.parse(API_PATH, handler);
        return featureCollection;

    } catch (Exception e) {
        System.out.println("Parsing exception: " + e);
        System.out.println("exception");
        return null;
    }
}

From source file:$.LogController.java

License:Apache License

@RequestMapping("/")
    public String getLogSearch(@RequestParam(value = "fromDate", required = false) DateTime fromDate,
            @RequestParam MultiValueMap<String, String> params, Model model) throws UnsupportedEncodingException {
        if (fromDate != null) {
            params.remove("fromDate");
            // remove empty values:
            for (List<String> valueList : params.values()) {
                ListIterator<String> values = valueList.listIterator();
                while (values.hasNext()) {
                    if (!StringUtils.hasText(values.next())) {
                        values.remove();
                    }/* ww  w  .  jav a 2  s . c om*/
                }
            }
            model.mergeAttributes(params);
            return "redirect:"
                    + UriUtils.encodePath(LogParserConstants.LOGBACK_ISO8601_FORMAT.print(fromDate), "UTF-8");
        }

        model.addAttribute("fromDate", LogParserConstants.LOGBACK_ISO8601_FORMAT.print(
                DateTime.now().minusHours(2).withMinuteOfHour(0).withSecondOfMinute(0).withMillisOfSecond(0)));

        LogParserConfig logParserConfig = new LogParserConfig();
        logParserConfig.setGroupBy(LogParserConstants.DEFAULT_GROUP_BY_PROPERTY);
        logParserConfig.setGroupLimit(LogParserConstants.DEFAULT_GROUP_SIZE);
        model.addAttribute("config", logParserConfig);

        return "logSearch";
    }

From source file:$.LogParserConfig.java

License:Apache License

public LogParserConfig() {
        setFromDate(DateTime.now());
        setLimit(LogParserConstants.MAX_RESULT_LIMIT);
        setFilter(Collections.<String, String>emptyMap());
        setGroupBy(Collections.<String>emptySet());
        setGroupLimit(null);/*from  www .j  a v a2s  . com*/
        setMsg(null);
    }

From source file:$.RequestResponseController.java

License:Apache License

@RequestMapping(value = "/search", method = { RequestMethod.GET, RequestMethod.POST })
    public String searchRequests(@RequestParam(value = "fromDate", required = false) DateTime fromDate,
            @RequestParam(value = "toDate", required = false) DateTime toDate,
            @RequestParam(value = "uri", required = false) String uri,
            @RequestParam(value = "content", required = false) String content,
            @ModelAttribute("model") ModelMap model) {

        if (fromDate != null && toDate != null) {
            List<Request> requestList = requestResponseService.findByCriteria(fromDate.toDate(), toDate.toDate(),
                    uri, content);//from   w ww.j  av  a  2s  . c  om

            model.addAttribute("fromDate", LogParserConstants.LOGBACK_ISO8601_FORMAT.print(fromDate));
            model.addAttribute("toDate", LogParserConstants.LOGBACK_ISO8601_FORMAT.print(toDate));

            if (!requestList.isEmpty()) {
                model.addAttribute("requestList", requestList);
            } else {
                model.addAttribute("emptyList", Boolean.TRUE);
            }
        } else {

            model.addAttribute("fromDate", LogParserConstants.LOGBACK_ISO8601_FORMAT.print(
                    DateTime.now().minusHours(1).withMinuteOfHour(0).withSecondOfMinute(0).withMillisOfSecond(0)));
            model.addAttribute("toDate", LogParserConstants.LOGBACK_ISO8601_FORMAT
                    .print(DateTime.now().withSecondOfMinute(0).withMillisOfSecond(0)));
        }

        model.addAttribute("uri", uri);
        model.addAttribute("content", content);

        return "reqRespSearch";
    }

From source file:access.deploy.Leaser.java

License:Apache License

/**
 * Renews the existing Deployment. This Deployment must exist in the Deployments collection.
 * /*from w  w  w.  j av a  2  s  . c o m*/
 * @param deployment
 *            The deployment to renew.
 * @param durationDays
 *            The number of days to renew the lease by.
 * @return The Lease for this Deployment
 */
public Lease renewDeploymentLease(Deployment deployment, Integer durationDays) {
    Lease lease = accessor.getDeploymentLease(deployment);
    // If the lease has been reaped by the database, then create a new
    // Lease.
    if (lease == null) {
        lease = createDeploymentLease(deployment, durationDays);
    } else {
        DateTime expirationDate = new DateTime(lease.getExpiresOn());
        if (expirationDate.isBeforeNow()) {
            // If the Lease has expired, then the Lease will be extended for
            // the default Lease period.
            Integer updatedDurationDays = ((durationDays != null) && (durationDays.intValue() > 0))
                    ? durationDays
                    : DEFAULT_LEASE_PERIOD_DAYS;
            accessor.updateLeaseExpirationDate(lease.getLeaseId(),
                    DateTime.now().plusDays(updatedDurationDays.intValue()).toString());
            pzLogger.log(
                    String.format("Updating Deployment Lease for Deployment %s on host %s for %s",
                            deployment.getDeploymentId(), deployment.getHost(), deployment.getDataId()),
                    Severity.INFORMATIONAL,
                    new AuditElement(ACCESS, "renewDeploymentLease", deployment.getDeploymentId()));
        } else {
            // If the Lease has not expired, then the Lease will not be
            // extended. It will simply be reused.
        }
    }

    return lease;
}