Example usage for java.time ZonedDateTime format

List of usage examples for java.time ZonedDateTime format

Introduction

In this page you can find the example usage for java.time ZonedDateTime format.

Prototype

@Override 
public String format(DateTimeFormatter formatter) 

Source Link

Document

Formats this date-time using the specified formatter.

Usage

From source file:org.cgiar.ccafs.marlo.action.summaries.InstitutionsSummaryAction.java

private TypedTableModel getMasterTableModel() {
    // Initialization of Model
    TypedTableModel model = new TypedTableModel(new String[] { "date", "center", "showDescription" },
            new Class[] { String.class, String.class, Boolean.class });
    String center = this.getLoggedCrp().getAcronym();

    ZonedDateTime timezone = ZonedDateTime.now();
    DateTimeFormatter format = DateTimeFormatter.ofPattern("yyyy-MM-d 'at' HH:mm ");
    String zone = timezone.getOffset() + "";
    if (zone.equals("Z")) {
        zone = "+0";
    }/*  ww  w  .  j av a  2s.  c  om*/
    String date = timezone.format(format) + "(GMT" + zone + ")";
    model.addRow(new Object[] { date, center, this.hasSpecificities(APConstants.CRP_REPORTS_DESCRIPTION) });
    return model;
}

From source file:org.cgiar.ccafs.marlo.action.center.summaries.ImpactSubmissionSummaryAction.java

/**
 * Get the main information of the report
 * /*from  w w  w.ja  v a2s . com*/
 * @return
 */
private TypedTableModel getMasterTableModel() {
    // Initialization of Model
    TypedTableModel model = new TypedTableModel(
            new String[] { "title", "current_date", "impact_submission", "imageUrl" },
            new Class[] { String.class, String.class, String.class, String.class });
    String title = "";
    String currentDate = "";
    String impactSubmission = "";

    // Get title composed by center-area-program
    if (researchProgram.getResearchArea() != null) {
        title += researchProgram.getResearchArea().getName() + " - ";
        if (researchProgram.getComposedName() != null) {
            title += researchProgram.getName();
        }
    }

    // Get datetime
    ZonedDateTime timezone = ZonedDateTime.now();
    DateTimeFormatter format = DateTimeFormatter.ofPattern("yyyy-MM-d 'at' HH:mm ");
    currentDate = timezone.format(format) + this.getTimeZone();

    // Get submission
    researchCycle = cycleService.getResearchCycleById(ImpactPathwayCyclesEnum.IMPACT_PATHWAY.getId());

    // Filling submission
    List<CenterSubmission> submissions = new ArrayList<>();
    for (CenterSubmission submission : researchProgram.getCenterSubmissions().stream()
            .filter(s -> s.getResearchCycle().getId() == researchCycle.getId()
                    && s.getYear() == this.getActualPhase().getYear())
            .collect(Collectors.toList())) {
        submissions.add(submission);
    }

    if (!submissions.isEmpty()) {
        if (submissions.size() > 1) {
            LOG.error("More than one submission was found, the report will retrieve the first one");
        }
        CenterSubmission fisrtSubmission = submissions.get(0);
        String submissionDate = new SimpleDateFormat("yyyy-MM-dd 'at' HH:mm")
                .format(fisrtSubmission.getDateTime());

        impactSubmission = "Submitted on " + submissionDate + " ("
                + fisrtSubmission.getResearchCycle().getName() + " cycle " + fisrtSubmission.getYear() + ")";
    } else {
        impactSubmission = "Center Submission for " + researchCycle.getName() + " cycle "
                + this.getActualPhase().getYear() + ": &lt;pending&gt;";
    }

    // Get CIAT imgage URL from repo
    String imageUrl = this.getBaseUrl() + "/global/images/centers/CIAT.png";

    model.addRow(new Object[] { title, currentDate, impactSubmission, imageUrl });
    return model;
}

From source file:org.cgiar.ccafs.marlo.action.summaries.ProjectHighlightSummaryAction.java

@Override
public String execute() throws Exception {
    if (projectHighlightID == null
            || projectHighLightManager.getProjectHighligthById(projectHighlightID) == null
            || projectHighLightManager.getProjectHighligthById(projectHighlightID)
                    .getProjectHighlightInfo(this.getSelectedPhase()) == null) {
        LOG.error("Project Highlight " + projectHighlightID + " Not found");
        return NOT_FOUND;
    } else {//from   w  w  w .ja  va 2  s  .com
        projectHighlightInfo = projectHighLightManager.getProjectHighligthById(projectHighlightID)
                .getProjectHighlightInfo(this.getSelectedPhase());
    }
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    try {
        Resource reportResource = resourceManager.createDirectly(
                this.getClass().getResource("/pentaho/crp/ProjectHighlightPDF.prpt"), MasterReport.class);
        MasterReport masterReport = (MasterReport) reportResource.getResource();
        String center = this.getLoggedCrp().getAcronym();
        // Get datetime
        ZonedDateTime timezone = ZonedDateTime.now();
        DateTimeFormatter format = DateTimeFormatter.ofPattern("yyyy-MM-d 'at' HH:mm ");
        String zone = timezone.getOffset() + "";
        if (zone.equals("Z")) {
            zone = "+0";
        }
        String date = timezone.format(format) + "(GMT" + zone + ")";
        // Set Main_Query
        CompoundDataFactory cdf = CompoundDataFactory.normalize(masterReport.getDataFactory());
        String masterQueryName = "main";
        TableDataFactory sdf = (TableDataFactory) cdf.getDataFactoryForQuery(masterQueryName);
        TypedTableModel model = this.getMasterTableModel(center, date, String.valueOf(this.getSelectedYear()));
        sdf.addTable(masterQueryName, model);
        masterReport.setDataFactory(cdf);
        // Set i8n for pentaho
        masterReport = this.addi8nParameters(masterReport);
        // Get details band
        ItemBand masteritemBand = masterReport.getItemBand();
        // Create new empty subreport hash map
        HashMap<String, Element> hm = new HashMap<String, Element>();
        // method to get all the subreports in the prpt and store in the HashMap
        this.getAllSubreports(hm, masteritemBand);
        // Uncomment to see which Subreports are detecting the method getAllSubreports
        // System.out.println("Pentaho SubReports: " + hm);
        this.fillSubreport((SubReport) hm.get("project_highlight"), "project_highlight");
        PdfReportUtil.createPDF(masterReport, os);
        bytesPDF = os.toByteArray();
        os.close();
    } catch (Exception e) {
        LOG.error("Error generating ProjectHighlights Summary: " + e.getMessage());
        throw e;
    }
    // Calculate time of generation
    long stopTime = System.currentTimeMillis();
    stopTime = stopTime - startTime;
    LOG.info("Downloaded successfully: " + this.getFileName() + ". User: " + this.getDownloadByUser()
            + ". CRP: " + this.getLoggedCrp().getAcronym() + ". Time to generate: " + stopTime + "ms.");
    return SUCCESS;
}

From source file:org.cgiar.ccafs.marlo.action.summaries.ProjectInnovationSummaryAction.java

@Override
public String execute() throws Exception {
    if (projectInnovationID == null
            || projectInnovationManager.getProjectInnovationById(projectInnovationID) == null
            || projectInnovationManager.getProjectInnovationById(projectInnovationID)
                    .getProjectInnovationInfo(this.getSelectedPhase()) == null) {
        LOG.error("Project Innovation " + projectInnovationID + " Not found");
        return NOT_FOUND;
    } else {/*from w w w.  j  av  a2s  . c  om*/
        projectInnovationInfo = projectInnovationManager.getProjectInnovationById(projectInnovationID)
                .getProjectInnovationInfo(this.getSelectedPhase());
    }
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    try {
        Resource reportResource = resourceManager.createDirectly(
                this.getClass().getResource("/pentaho/crp/ProjectInnovationPDF.prpt"), MasterReport.class);
        MasterReport masterReport = (MasterReport) reportResource.getResource();
        String center = this.getLoggedCrp().getAcronym();
        // Get datetime
        ZonedDateTime timezone = ZonedDateTime.now();
        DateTimeFormatter format = DateTimeFormatter.ofPattern("yyyy-MM-d 'at' HH:mm ");
        String zone = timezone.getOffset() + "";
        if (zone.equals("Z")) {
            zone = "+0";
        }
        String date = timezone.format(format) + "(GMT" + zone + ")";
        // Set Main_Query
        CompoundDataFactory cdf = CompoundDataFactory.normalize(masterReport.getDataFactory());
        String masterQueryName = "main";
        TableDataFactory sdf = (TableDataFactory) cdf.getDataFactoryForQuery(masterQueryName);
        TypedTableModel model = this.getMasterTableModel(center, date, String.valueOf(this.getSelectedYear()));
        sdf.addTable(masterQueryName, model);
        masterReport.setDataFactory(cdf);
        // Set i8n for pentaho
        masterReport = this.addi8nParameters(masterReport);
        // Get details band
        ItemBand masteritemBand = masterReport.getItemBand();
        // Create new empty subreport hash map
        HashMap<String, Element> hm = new HashMap<String, Element>();
        // method to get all the subreports in the prpt and store in the HashMap
        this.getAllSubreports(hm, masteritemBand);
        // Uncomment to see which Subreports are detecting the method getAllSubreports
        // System.out.println("Pentaho SubReports: " + hm);
        this.fillSubreport((SubReport) hm.get("project_innovation"), "project_innovation");
        PdfReportUtil.createPDF(masterReport, os);
        bytesPDF = os.toByteArray();
        os.close();
    } catch (Exception e) {
        LOG.error("Error generating ProjectInnovation Summary: " + e.getMessage());
        throw e;
    }
    // Calculate time of generation
    long stopTime = System.currentTimeMillis();
    stopTime = stopTime - startTime;
    LOG.info("Downloaded successfully: " + this.getFileName() + ". User: " + this.getDownloadByUser()
            + ". CRP: " + this.getLoggedCrp().getAcronym() + ". Time to generate: " + stopTime + "ms.");
    return SUCCESS;
}

From source file:org.cgiar.ccafs.marlo.action.center.summaries.ProjectSummaryAction.java

/**
 * Get the main information of the report
 * /*  ww w  .  j a va  2s .co  m*/
 * @return
 */
private TypedTableModel getMasterTableModel() {
    // Initialization of Model
    final TypedTableModel model = new TypedTableModel(
            new String[] { "shortTitle", "currentDate", "projectSubmission", "imageUrl" },
            new Class[] { String.class, String.class, String.class, String.class });
    // Set short title
    String shortTitle = "";
    if ((project.getName() != null) && !project.getName().isEmpty()) {
        shortTitle += project.getName() + " - ";
    }
    if ((loggedCenter.getAcronym() != null) && !loggedCenter.getAcronym().isEmpty()) {
        shortTitle += loggedCenter.getAcronym() + " - ";
    }
    shortTitle += "P" + Long.toString(projectID);

    // Set currentDate
    String currentDate = "";
    // Get datetime
    final ZonedDateTime timezone = ZonedDateTime.now();
    final DateTimeFormatter format = DateTimeFormatter.ofPattern("yyyy-MM-d 'at' HH:mm ");
    currentDate = timezone.format(format) + this.getTimeZone();

    // Set projectSubmission
    final String projectSubmission = "";

    // set CIAT imgage URL from repo

    String imageUrl = this.getBaseUrl() + "/global/images/centers/CIAT.png";

    model.addRow(new Object[] { shortTitle, currentDate, projectSubmission, imageUrl });
    return model;
}

From source file:net.jmhertlein.alphonseirc.AlphonseBot.java

private void handleDadCommand(final String target, String sender, String[] args) {
    if (args.length == 1) {
        sendMessage(target, "Usage: !dad [left|list|say]");
        return;/*from w w  w  . j  a v a2 s  .  com*/
    }

    switch (args[1]) {
    case "left":
        ZonedDateTime now = ZonedDateTime.now();
        this.dadLeaveTimes.put(LocalDate.now(), LocalTime.now());
        sendMessage(target,
                "Marked dad's leave time as now (" + now.format(DateTimeFormatter.ISO_LOCAL_TIME) + ").");
        break;
    case "list":
        int num = 3;
        if (args.length == 3) {
            try {
                num = Integer.parseInt(args[2]);
                if (num > 10)
                    num = 10;
            } catch (NumberFormatException nfe) {
                sendMessage(target, "Error parsing " + args[2] + " into int: " + nfe.getMessage());
                sendMessage(target, "Usage: !dad list (optional: number, default 3, max 10)");
                return;
            }
        }

        final int prevDays = num;
        dadLeaveTimes.keySet().stream().sorted()
                .filter(date -> date.isAfter(LocalDate.now().minusDays(prevDays)))
                .map(date -> date.format(DateTimeFormatter.ISO_LOCAL_DATE) + " || "
                        + dadLeaveTimes.get(date).format(DateTimeFormatter.ISO_LOCAL_TIME))
                .forEach(leaveTime -> sendMessage(target, leaveTime));

        break;
    case "say":
        String msg;
        switch (gen.nextInt(9)) {
        case 0:
            msg = "TYPES LOUDLY";
            break;
        case 1:
            msg = "BREATHES DEEPLY";
            break;
        case 2:
            msg = "ANGRILY TYPES AN EMAIL";
            break;
        case 3:
            msg = "BACKSPACES WITH AUTHORITY";
            break;
        case 4:
            msg = "STRETCHES WHILE EXHALING";
            break;
        case 5:
            msg = "thinks about Happy Hour";
            break;
        case 6:
            msg = "browses Yahoo! news";
            break;
        case 7:
            msg = "tells everyone to GET BACK TO WORK";
            break;
        case 8:
            msg = "ignores Lantzer standing in front of his desk";
            break;
        default:
            msg = "Someone made nextInt() go too high";
            break;
        }

        this.sendAction(target, msg);
        break;
    default:
        System.out.println("Bad switch on " + args[1]);
    }

}

From source file:org.cgiar.ccafs.marlo.action.summaries.ProjectHighlightsSummaryAction.java

@Override
public String execute() throws Exception {
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    try {/*  www  . jav  a  2 s.co m*/
        Resource reportResource;
        if (this.getSelectedFormat().equals(APConstants.SUMMARY_FORMAT_EXCEL)) {
            reportResource = resourceManager.createDirectly(
                    this.getClass().getResource("/pentaho/crp/ProjectHighlightsExcel.prpt"),
                    MasterReport.class);
        } else {
            reportResource = resourceManager.createDirectly(
                    this.getClass().getResource("/pentaho/crp/ProjectHighlightsPDF.prpt"), MasterReport.class);
        }

        MasterReport masterReport = (MasterReport) reportResource.getResource();
        String center = this.getLoggedCrp().getAcronym();
        // Get datetime
        ZonedDateTime timezone = ZonedDateTime.now();
        DateTimeFormatter format = DateTimeFormatter.ofPattern("yyyy-MM-d 'at' HH:mm ");
        String zone = timezone.getOffset() + "";
        if (zone.equals("Z")) {
            zone = "+0";
        }
        String date = timezone.format(format) + "(GMT" + zone + ")";
        // Set Main_Query
        CompoundDataFactory cdf = CompoundDataFactory.normalize(masterReport.getDataFactory());
        String masterQueryName = "main";
        TableDataFactory sdf = (TableDataFactory) cdf.getDataFactoryForQuery(masterQueryName);
        TypedTableModel model = this.getMasterTableModel(center, date, String.valueOf(this.getSelectedYear()));
        sdf.addTable(masterQueryName, model);
        masterReport.setDataFactory(cdf);
        // Set i8n for pentaho
        masterReport = this.addi8nParameters(masterReport);
        // Get details band
        ItemBand masteritemBand = masterReport.getItemBand();
        // Create new empty subreport hash map
        HashMap<String, Element> hm = new HashMap<String, Element>();
        // method to get all the subreports in the prpt and store in the HashMap
        this.getAllSubreports(hm, masteritemBand);
        // Uncomment to see which Subreports are detecting the method getAllSubreports
        // System.out.println("Pentaho SubReports: " + hm);
        this.fillSubreport((SubReport) hm.get("project_highlight"), "project_highlight");
        if (this.getSelectedFormat().equals(APConstants.SUMMARY_FORMAT_EXCEL)) {
            ExcelReportUtil.createXLSX(masterReport, os);
            bytesXLSX = os.toByteArray();
        } else {
            PdfReportUtil.createPDF(masterReport, os);
            bytesPDF = os.toByteArray();
        }
        os.close();
    } catch (Exception e) {
        LOG.error("Error generating ProjectHighlights" + this.getSelectedFormat() + ": " + e.getMessage());
        throw e;
    }
    // Calculate time of generation
    long stopTime = System.currentTimeMillis();
    stopTime = stopTime - startTime;
    LOG.info("Downloaded successfully: " + this.getFileName() + ". User: "
            + this.getCurrentUser().getComposedCompleteName() + ". CRP: " + this.getLoggedCrp().getAcronym()
            + ". Time to generate: " + stopTime + "ms.");
    return SUCCESS;
}