Example usage for org.joda.time.format DateTimeFormatter print

List of usage examples for org.joda.time.format DateTimeFormatter print

Introduction

In this page you can find the example usage for org.joda.time.format DateTimeFormatter print.

Prototype

public String print(ReadablePartial partial) 

Source Link

Document

Prints a ReadablePartial to a new String.

Usage

From source file:org.bekwam.maven.plugin.talendroutine.TalendRoutineMojo.java

License:Apache License

public void execute() throws MojoExecutionException {

    File f = outputDir;//from   w  ww  .j a  v  a  2  s.com

    if (!f.exists()) {
        f.mkdirs();
    }

    String filename = label + "_" + version + ".properties";
    String xmiId = "_" + RandomStringUtils.randomAlphanumeric(22);
    String id = PROPERTY_ID;
    String routineId = "_" + RandomStringUtils.randomAlphanumeric(22);
    String stateId = "_" + RandomStringUtils.randomAlphanumeric(22);
    String authorId = "_" + RandomStringUtils.randomAlphanumeric(22);

    getLog().debug("generating filename=" + filename);
    getLog().debug("using xmiId=" + xmiId);
    File propertiesFile = new File(f, filename);
    File talendProjectFile = new File(f, PROJECT_FILE_NAME);

    FileWriter w = null;
    BufferedWriter bw = null;

    try {

        w = new FileWriter(propertiesFile);
        bw = new BufferedWriter(w);

        DateTime dt = new DateTime();
        DateTimeFormatter fmt = DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
        String date_s = fmt.print(dt);

        bw.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
        bw.newLine();
        bw.write(
                "<xmi:XMI xmi:version=\"2.0\" xmlns:xmi=\"http://www.omg.org/XMI\" xmlns:TalendProperties=\"http://www.talend.org/properties\">");
        bw.newLine();
        bw.write("  <TalendProperties:Property xmi:id=\"" + xmiId + "\" id=\"" + id + "\" label=\"" + label
                + "\" purpose=\"" + purpose + "\" description=\"" + description + "\" creationDate=\"" + date_s
                + "\" modificationDate=\"" + date_s + "\" version=\"" + version
                + "\" statusCode=\"PROD\" item=\"" + routineId + "\"> ");
        bw.newLine();
        bw.write("    <author href=\"../../../talend.project#" + authorId + "\"/>");
        bw.newLine();
        bw.write("  </TalendProperties:Property>");
        bw.newLine();
        bw.write("  <TalendProperties:ItemState xmi:id=\"" + stateId + "\" path=\"" + path + "\"/>");
        bw.newLine();
        bw.write("  <TalendProperties:RoutineItem xmi:id=\"" + routineId + "\" property=\"" + xmiId
                + "\" state=\"" + stateId + "\"> ");
        bw.newLine();
        bw.write("    <content href=\"" + label + "_" + version + ".item#/0\"/>");
        bw.newLine();

        Set<Artifact> artifacts = project.getDependencyArtifacts();

        for (Artifact a : artifacts) {

            if (!StringUtils.equals(a.getScope(), "test") && StringUtils.equals(a.getType(), "jar")) {

                String jarName = a.getArtifactId() + "-" + a.getVersion() + ".jar";
                //String message = a.getGroupId() + ":" + a.getArtifactId();
                String message = "Required for using this component.";

                getLog().debug("jarName=" + jarName + ", message=" + message);

                String importId = "_" + RandomStringUtils.randomAlphanumeric(22);

                bw.write("    <imports xmi:id=\"" + importId + "\" mESSAGE=\"" + message + "\" mODULE=\""
                        + jarName + "\" nAME=\"" + a.getArtifactId() + "\" rEQUIRED=\"true\" />");
                bw.newLine();
            }
        }

        bw.write("    </TalendProperties:RoutineItem>");
        bw.newLine();
        bw.write("</xmi:XMI>");
        bw.newLine();
    } catch (IOException e) {
        throw new MojoExecutionException("Error creating file " + propertiesFile, e);
    } finally {
        if (bw != null) {
            try {
                bw.close();
            } catch (IOException e) {
                getLog().warn("error closing buffered writer for file=" + filename);
            }
        }
    }

    try {
        w = new FileWriter(talendProjectFile);
        bw = new BufferedWriter(w);

        String projectId = "_" + RandomStringUtils.randomAlphanumeric(22);

        bw.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
        bw.newLine();
        bw.write(
                "<xmi:XMI xmi:version=\"2.0\" xmlns:xmi=\"http://www.omg.org/XMI\" xmlns:TalendProperties=\"http://www.talend.org/properties\">");
        bw.newLine();
        bw.write("  <TalendProperties:Project xmi:id=\"" + projectId
                + "\" label=\"TALENDPROJECT\" description=\"Project for testing new components\" language=\"java\" technicalLabel=\"TALENDPROJECT\" local=\"true\" productVersion=\"Talend Open Studio-4.2.2.r63143\" itemsRelationVersion=\"1.1\">");
        bw.newLine();
        bw.write("  </TalendProperties:Project>");
        bw.newLine();
        bw.write("  <TalendProperties:User xmi:id=\"" + authorId + "\" login=\"exportuser@talend.com\"/>");
        bw.newLine();
        bw.write("</xmi:XMI>");
        bw.newLine();

    } catch (IOException e) {
        throw new MojoExecutionException("Error creating file " + talendProjectFile, e);
    } finally {
        if (bw != null) {
            try {
                bw.close();
            } catch (IOException e) {
                getLog().warn("error closing buffered writer for file=" + filename);
            }
        }
    }

}

From source file:org.bensteele.jirrigate.Console.java

License:Open Source License

private void printControllerStatus(String input) {
    DateTimeFormatter statusFormatter = DateTimeFormat.forPattern("dd/MM/yyyy HH:mm");
    System.out.format("%-25s%-20s%-25s%-10s%-15s%-28s\n", "Controller", "Status", "Currently Irrigating",
            "Active", "# Irrigations", "Next Irrigation Due");
    for (Controller c : irrigator.getControllers()) {
        if (input.toLowerCase().contains(c.getName().toLowerCase())) {
            System.out.format("%-25s%-20s%-25s%-10s%-15s%-28s\n", c.getName(), c.getStatus(), c.isIrrigating(),
                    c.isActive(), c.getIrrigationResults().size(),
                    statusFormatter.print(irrigator.nextIrrigationAt()));
        }//  w  ww .  j ava  2 s  .c om
    }
}

From source file:org.bensteele.jirrigate.Console.java

License:Open Source License

private void printControllerStatusAll(String input) {
    DateTimeFormatter statusFormatter = DateTimeFormat.forPattern("dd/MM/yyyy HH:mm");
    System.out.format("%-25s%-20s%-25s%-10s%-15s%-28s\n", "Controller", "Status", "Currently Irrigating",
            "Active", "# Irrigations", "Next Irrigation Due");
    for (Controller c : irrigator.getControllers()) {
        System.out.format("%-25s%-20s%-25s%-10s%-15s%-28s\n", c.getName(), c.getStatus(), c.isIrrigating(),
                c.isActive(), c.getIrrigationResults().size(),
                statusFormatter.print(irrigator.nextIrrigationAt()));
    }/*from   w ww .j av a 2s . c o  m*/
}

From source file:org.bensteele.jirrigate.Console.java

License:Open Source License

private void printWeatherStationInfo(String input) {
    DateTimeFormatter formatter = DateTimeFormat.forPattern("dd/MM/yyyy HH:mm");
    System.out.format("%-25s%-15s%-10s%-12s%-20s%-20s\n", "Station", "Type", "Active", "# Records",
            "Oldest Record", "Newest Record");
    for (WeatherStation ws : irrigator.getWeatherStations()) {
        if (input.toLowerCase().contains(ws.getName().toLowerCase())) {
            System.out.format("%-25s%-15s%-10s%-12s%-20s%-20s\n", ws.getName(), ws.getType(), ws.isActive(),
                    ws.getNumberOfRecords(), formatter.print(ws.getOldestRecordTime()),
                    formatter.print(ws.getNewestRecordTime()));
        }/*from  www  .  j a va2 s. c  o m*/
    }
}

From source file:org.bryantd.lightscameraaction.LightsCameraActionWorker.java

@Override
protected Integer doInBackground() throws Exception {
    final DateTimeFormatter dtf = DateTimeFormat.forPattern("yyyy-MM-dd '-' HH:mm:ss.SSSS");
    String fileName;//from ww w  .  j  a v  a 2  s . co m
    while (imageJobScheduleIterator_.hasNext()) {
        LightsCameraActionWorker.failIfInterrupted();
        DateTime nextScheduledEvent = (DateTime) imageJobScheduleIterator_.next();
        process(Arrays.asList(Utilities
                .timeStamp("Next snapshot scheduled for " + dtf.print(nextScheduledEvent)).toString()));
        if (nextScheduledEvent.isAfterNow()) {
            waitUntil(nextScheduledEvent);
            process(Arrays.asList(Utilities.timeStamp("Begining scheduled image acquisition.").toString()));

            Boolean okToExecuteJob = true;
            if (requireRunningSchedule_) {
                process(Arrays.asList(Utilities.timeStamp("Checking lights for running schedule:").toString()));
                try {
                    okToExecuteJob = lights_.issueCommands(Arrays.asList(LightsTask.GETSCHEDULERUNNING), null,
                            null);
                } catch (InterruptedException e) {
                    throw (e);
                } catch (Exception e) {
                    okToExecuteJob = false;
                    process(Arrays.asList(Utilities.timeStamp("Error: " + e.getMessage()).toString()));
                    process(Arrays.asList(Utilities.timeStamp("Error type: " + e.getCause()).toString()));
                    process(Arrays.asList(
                            Utilities.timeStamp("Could not issue lights command. Skipping this scheduled job.")
                                    .toString()));
                }
                if (okToExecuteJob) {
                    process(Arrays.asList(
                            Utilities.timeStamp("Schedule is running on lights, proceeding.").toString()));
                } else {
                    process(Arrays.asList(Utilities
                            .timeStamp("Schedule is not running on lights! Skipping job.").toString()));
                    okToExecuteJob = false;
                }
            }

            if (okToExecuteJob) {
                boolean success = true;
                fileName = nextScheduledEvent.toLocalDateTime().toString().replace(':', '-');
                process(Arrays.asList(Utilities.timeStamp("Executing image acquisition routine.").toString()));

                lights_.issueCommands(Arrays.asList(LightsTask.SCHEDULESTOP, LightsTask.SETWL), null,
                        setWLCommand_);
                DateTime takeImageEvent = DateTime.now().plusMillis(lightsToImageDelayMS_);
                waitUntil(takeImageEvent);

                try {
                    success = camera_.snapImage(fileName);
                    failIfInterrupted();
                } catch (Exception e) {
                    process(Arrays
                            .asList(Utilities.timeStamp("Error snapping image: " + e.getMessage()).toString()));
                    process(Arrays.asList(
                            Utilities.timeStamp("Could not issue camera command. Skipping this scheduled job.")
                                    .toString()));
                }
                if (success) {
                    process(Arrays.asList(Utilities.timeStamp("Successfully acquired image.").toString()));
                } else {
                    process(Arrays
                            .asList(Utilities.timeStamp("Something went wrong with this job.").toString()));
                }

                lights_.issueCommands(Arrays.asList(LightsTask.SCHEDULESTART), null, null);
            }
        } else {
            process(Arrays.asList(Utilities.timeStamp("Scheduled job is in the past. Skipping.").toString()));
            System.out.println("event skipped");
        }
    }
    process(Arrays.asList(Utilities.timeStamp("Done processing full schedule.").toString()));
    return 0;
}

From source file:org.codehaus.httpcache4j.HeaderUtils.java

License:Open Source License

public static Header toHttpDate(String headerName, DateTime time) {
    DateTimeFormatter formatter = DateTimeFormat.forPattern(PATTERN_RFC1123).withZone(DateTimeZone.forID("UTC"))
            .withLocale(Locale.US);
    return new Header(headerName, formatter.print(time));
}

From source file:org.codelibs.elasticsearch.common.xcontent.XContentBuilder.java

License:Apache License

public XContentBuilder value(ReadableInstant value, DateTimeFormatter formatter) throws IOException {
    if (value == null) {
        return nullValue();
    }/* w w  w .j  av a 2s.com*/
    ensureFormatterNotNull(formatter);
    return value(formatter.print(value));
}

From source file:org.codelibs.elasticsearch.common.xcontent.XContentBuilder.java

License:Apache License

XContentBuilder value(DateTimeFormatter formatter, long value) throws IOException {
    ensureFormatterNotNull(formatter);/*w ww  . ja  va  2s .  com*/
    return value(formatter.print(value));
}

From source file:org.codice.ddf.opensearch.source.OpenSearchParserImpl.java

License:Open Source License

@Override
public void populateTemporal(WebClient client, TemporalFilter temporal, List<String> parameters) {
    if (temporal == null) {
        return;//from  ww w  .  j a  v a  2s. c o  m
    }

    DateTimeFormatter fmt = ISODateTimeFormat.dateTime();
    long startLng = (temporal.getStartDate() != null) ? temporal.getStartDate().getTime() : 0;
    final String start = fmt.print(startLng);
    long endLng = (temporal.getEndDate() != null) ? temporal.getEndDate().getTime()
            : System.currentTimeMillis();
    final String end = fmt.print(endLng);

    checkAndReplace(client, start, OpenSearchConstants.DATE_START, parameters);
    checkAndReplace(client, end, OpenSearchConstants.DATE_END, parameters);
}

From source file:org.codice.ddf.spatial.ogc.wfs.v2_0_0.catalog.source.WfsFilterDelegate.java

License:Open Source License

private String convertDateToIso8601Format(DateTime inputDate) {
    DateTimeFormatter dtf = ISODateTimeFormat.dateTimeNoMillis().withZone(DateTimeZone.UTC);
    return dtf.print(inputDate).toString();
}