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:es.ucm.fdi.tutorias.business.boundary.Emails.java

License:Open Source License

private String generarMensajeConfirmacionTutoria(Tutoria tutoria) {
    String mensaje = "<p><b>" + tutoria.getDestinatario().getUserGivenName()
            + tutoria.getDestinatario().getUserSurname() + "</b>";
    mensaje += " ha confirmado la tutora con usted, ";
    mensaje += tutoria.getEmisor().getUserGivenName() + " " + tutoria.getEmisor().getUserSurname();
    DateTimeFormatter dtfOut = DateTimeFormat.forPattern("MM/dd/yyyy hh:mm");
    mensaje += " sobre su asignatura <b>" + tutoria.getAsignatura() + "</b></p> de " + "<b>"
            + dtfOut.print(tutoria.getComienzoTutoria()) + "</b>";
    mensaje += " hasta " + "<b>" + dtfOut.print(tutoria.getFinTutoria()) + "</b></p>";
    return mensaje;
}

From source file:es.ucm.fdi.tutorias.business.boundary.Emails.java

License:Open Source License

private String generarMensajeSolicitudTutoria(Tutoria tutoria, String contextPath) {
    String mensaje = "<p> <b>" + tutoria.getEmisor().getUserGivenName() + " "
            + tutoria.getEmisor().getUserSurname() + "</b>";
    mensaje += " ha solicitado una tutora con usted, ";
    mensaje += tutoria.getDestinatario().getUserGivenName() + " " + tutoria.getDestinatario().getUserSurname();
    DateTimeFormatter dtfOut = DateTimeFormat.forPattern("MM/dd/yyyy hh:mm");
    mensaje += ", sobre su asignatura: <b>" + tutoria.getAsignatura() + "</b>, de " + "<b>"
            + dtfOut.print(tutoria.getComienzoTutoria()) + "</b>";
    mensaje += " hasta " + "<b>" + dtfOut.print(tutoria.getFinTutoria()) + "</b></p>";
    mensaje += "El motivo por el que se solicita la tutora es: <p><i>" + tutoria.getResumenDudas()
            + "</i></p>";
    mensaje += "<a bgcolor='#70bbd9' color='green' href='http://localhost:8088" + contextPath
            + Constants.URL_CONFIRMAR_TUTORIA + "?id=" + tutoria.getId() + "'>Confirmar tutora</a>";
    return mensaje;
}

From source file:es.ucm.fdi.tutorias.web.TutoriasController.java

License:Open Source License

@RequestMapping(method = RequestMethod.GET, value = Constants.URL_CONFIRMAR_TUTORIA)
public ModelAndView confirmarTutoria(@RequestParam("id") String id, HttpServletRequest request) {
    Authentication auth = SecurityContextHolder.getContext().getAuthentication();
    User usuarioLogueado = (User) auth.getPrincipal();

    Map<String, Object> model = new HashMap<>();
    logger.warn("Se quiere confirmar la tutora con id:" + id);

    Tutoria tutoria = tutoriaService.getTutoria(Long.parseLong(id));
    model.put("urlRedireccion", request.getContextPath() + Constants.URL_LISTAR_TUTORIAS);
    if (tutoria != null) {
        //Solo puede confirmar una tutora su destinatario
        boolean esDestinatario = usuarioLogueado.getId().intValue() == tutoria.getDestinatario().getId()
                .intValue();/*w w  w  . j a v a 2 s . co m*/
        if (esDestinatario) {
            tutoriaService.confirmarTutoria(id);
        }
        logger.warn("usuarioLogueado:" + usuarioLogueado.getId().intValue() + " "
                + (usuarioLogueado.getId().intValue() == tutoria.getDestinatario().getId().intValue() ? "cierto"
                        : "falso")
                + " " + tutoria.getDestinatario().getId().intValue() + ": Receptor");
        if (tutoria != null) {
            if (!tutoria.isConfirmada()) {
                logger.warn("Se ha confirmado la tutora con id:" + id);
                emailUtils.enviarEmailConfirmacionTutoria(tutoria);
                model.put("texto1", "tutoria.confirmar.confirmada");
                DateTimeFormatter dtfOut = DateTimeFormat.forPattern("MM/dd/yyyy hh:mm");
                String asignatura = tutoria.getAsignatura();
                String destinatario = tutoria.getDestinatario().getUserGivenName() + " "
                        + tutoria.getDestinatario().getUserSurname();
                String fecha = dtfOut.print(tutoria.getComienzoTutoria());
                model.put("texto", messageSource.getMessage("tutoria.confirmar.confirmada.descripcion",
                        new String[] { asignatura, destinatario, fecha }, request.getLocale()));
                return new ModelAndView("temporal", model);
            }
        }
        model.put("texto1", "tutoria.confirmar.no.confirmada");
        model.put("texto2", "tutoria.confirmar.no.confirmada.descripcion");
        return new ModelAndView("temporal", model);
    }

    model.put("texto1", "tutoria.confirmar.no.existe");
    model.put("texto2", "tutoria.confirmar.no.existe.descripcion");

    return new ModelAndView("temporal", model);
}

From source file:eu.itesla_project.online.tools.ListForecastErrorsAnalysisTool.java

License:Mozilla Public License

@Override
public void run(CommandLine line) throws Exception {
    ForecastErrorsAnalysisConfig config = ForecastErrorsAnalysisConfig.load();
    ForecastErrorsDataStorage feDataStorage = config.getForecastErrorsDataStorageFactoryClass().newInstance()
            .create();//  w  w w. jav a  2 s  .  com
    List<ForecastErrorsAnalysisDetails> analysisList = feDataStorage.listAnalysis();
    DateTimeFormatter formatter = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss");
    Table table = new Table(5, BorderStyle.CLASSIC_WIDE);
    table.addCell("ID", new CellStyle(CellStyle.HorizontalAlign.center));
    table.addCell("Date", new CellStyle(CellStyle.HorizontalAlign.center));
    table.addCell("Errors Models", new CellStyle(CellStyle.HorizontalAlign.center));
    table.addCell("Statistics", new CellStyle(CellStyle.HorizontalAlign.center));
    table.addCell("Parameters", new CellStyle(CellStyle.HorizontalAlign.center));
    for (ForecastErrorsAnalysisDetails analysis : analysisList) {
        ArrayList<TimeHorizon> mergedList = new ArrayList<TimeHorizon>(analysis.getForecastErrorsDataList());
        mergedList.removeAll(analysis.getForecastErrorsStatisticsList());
        mergedList.addAll(analysis.getForecastErrorsStatisticsList());
        for (TimeHorizon timeHorizon : mergedList) {
            table.addCell(analysis.getAnalysisId());
            table.addCell(formatter.print(analysis.getAnalysisDate()));
            if (analysis.getForecastErrorsDataList().contains(timeHorizon))
                table.addCell(timeHorizon.getName());
            else
                table.addCell("-");
            if (analysis.getForecastErrorsStatisticsList().contains(timeHorizon))
                table.addCell(timeHorizon.getName());
            else
                table.addCell("-");
            ForecastErrorsAnalyzerParameters parameters = feDataStorage.getParameters(analysis.getAnalysisId(),
                    timeHorizon);
            if (parameters != null) {
                //table.addCell(parameters.toString().substring(32));
                String value = parameters.toString().substring(32);
                while (value.length() > COLUMN_LENGTH) {
                    table.addCell(value.substring(0, COLUMN_LENGTH),
                            new CellStyle(CellStyle.HorizontalAlign.left));
                    table.addCell(" ", new CellStyle(CellStyle.HorizontalAlign.left));
                    table.addCell(" ", new CellStyle(CellStyle.HorizontalAlign.left));
                    table.addCell(" ", new CellStyle(CellStyle.HorizontalAlign.left));
                    table.addCell(" ", new CellStyle(CellStyle.HorizontalAlign.left));
                    value = value.substring(COLUMN_LENGTH);
                }
                table.addCell(value, new CellStyle(CellStyle.HorizontalAlign.left));
            } else
                table.addCell("-");
        }
    }
    System.out.println(table.render());
}

From source file:eu.itesla_project.online.tools.ListOnlineWorkflowsTool.java

License:Mozilla Public License

@Override
public void run(CommandLine line) throws Exception {
    OnlineConfig config = OnlineConfig.load();
    OnlineDb onlinedb = config.getOnlineDbFactoryClass().newInstance().create();
    List<OnlineWorkflowDetails> workflows = null;
    if (line.hasOption("basecase")) {
        DateTime basecaseDate = DateTime.parse(line.getOptionValue("basecase"));
        workflows = onlinedb.listWorkflows(basecaseDate);
    } else if (line.hasOption("basecases-interval")) {
        Interval basecasesInterval = Interval.parse(line.getOptionValue("basecases-interval"));
        workflows = onlinedb.listWorkflows(basecasesInterval);
    } else if (line.hasOption("workflow")) {
        String workflowId = line.getOptionValue("workflow");
        OnlineWorkflowDetails workflowDetails = onlinedb.getWorkflowDetails(workflowId);
        workflows = new ArrayList<OnlineWorkflowDetails>();
        if (workflowDetails != null)
            workflows.add(workflowDetails);
    } else//  w  ww .  ja v a  2 s  . c  o m
        workflows = onlinedb.listWorkflows();
    boolean printParameters = line.hasOption("parameters");
    DateTimeFormatter formatter = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss");
    Table table = new Table(2, BorderStyle.CLASSIC_WIDE);
    if (printParameters)
        table = new Table(3, BorderStyle.CLASSIC_WIDE);
    List<Map<String, String>> jsonData = new ArrayList<Map<String, String>>();
    table.addCell("ID", new CellStyle(CellStyle.HorizontalAlign.center));
    table.addCell("Date", new CellStyle(CellStyle.HorizontalAlign.center));
    if (printParameters)
        table.addCell("Parameters", new CellStyle(CellStyle.HorizontalAlign.center));
    for (OnlineWorkflowDetails workflow : workflows) {
        Map<String, String> wfJsonData = new HashMap<String, String>();
        table.addCell(workflow.getWorkflowId());
        wfJsonData.put("id", workflow.getWorkflowId());
        table.addCell(formatter.print(workflow.getWorkflowDate()));
        wfJsonData.put("date", formatter.print(workflow.getWorkflowDate()));
        if (printParameters) {
            OnlineWorkflowParameters parameters = onlinedb.getWorkflowParameters(workflow.getWorkflowId());
            if (parameters != null) {
                table.addCell("Basecase = " + parameters.getBaseCaseDate().toString());
                wfJsonData.put(OnlineWorkflowCommand.BASE_CASE, parameters.getBaseCaseDate().toString());
                table.addCell(" ");
                table.addCell(" ");
                table.addCell("Time Horizon = " + parameters.getTimeHorizon().getName());
                wfJsonData.put(OnlineWorkflowCommand.TIME_HORIZON, parameters.getTimeHorizon().getName());
                table.addCell(" ");
                table.addCell(" ");
                table.addCell("FE Analysis Id = " + parameters.getFeAnalysisId());
                wfJsonData.put(OnlineWorkflowCommand.FEANALYSIS_ID, parameters.getFeAnalysisId());
                table.addCell(" ");
                table.addCell(" ");
                table.addCell("Offline Workflow Id = " + parameters.getOfflineWorkflowId());
                wfJsonData.put(OnlineWorkflowCommand.WORKFLOW_ID, parameters.getOfflineWorkflowId());
                table.addCell(" ");
                table.addCell(" ");
                table.addCell("Historical Interval = " + parameters.getHistoInterval().toString());
                wfJsonData.put(OnlineWorkflowCommand.HISTODB_INTERVAL,
                        parameters.getHistoInterval().toString());
                table.addCell(" ");
                table.addCell(" ");
                table.addCell("States = " + Integer.toString(parameters.getStates()));
                wfJsonData.put(OnlineWorkflowCommand.STATES, Integer.toString(parameters.getStates()));
                table.addCell(" ");
                table.addCell(" ");
                table.addCell(
                        "Rules Purity Threshold = " + Double.toString(parameters.getRulesPurityThreshold()));
                wfJsonData.put(OnlineWorkflowCommand.RULES_PURITY,
                        Double.toString(parameters.getRulesPurityThreshold()));
                table.addCell(" ");
                table.addCell(" ");
                table.addCell("Store States = " + Boolean.toString(parameters.storeStates()));
                wfJsonData.put(OnlineWorkflowCommand.STORE_STATES, Boolean.toString(parameters.storeStates()));
                table.addCell(" ");
                table.addCell(" ");
                table.addCell("Analyse Basecase = " + Boolean.toString(parameters.analyseBasecase()));
                wfJsonData.put(OnlineWorkflowCommand.ANALYSE_BASECASE,
                        Boolean.toString(parameters.analyseBasecase()));
                table.addCell(" ");
                table.addCell(" ");
                table.addCell("Validation = " + Boolean.toString(parameters.validation()));
                wfJsonData.put(OnlineWorkflowCommand.VALIDATION, Boolean.toString(parameters.validation()));
                table.addCell(" ");
                table.addCell(" ");
                String securityRulesString = parameters.getSecurityIndexes() == null ? "ALL"
                        : parameters.getSecurityIndexes().toString();
                table.addCell("Security Rules = " + securityRulesString);
                wfJsonData.put(OnlineWorkflowCommand.SECURITY_INDEXES, securityRulesString);
                table.addCell(" ");
                table.addCell(" ");
                table.addCell("Case Type = " + parameters.getCaseType());
                wfJsonData.put(OnlineWorkflowCommand.CASE_TYPE, parameters.getCaseType().name());
                table.addCell(" ");
                table.addCell(" ");
                table.addCell("Countries = " + parameters.getCountries().toString());
                wfJsonData.put(OnlineWorkflowCommand.COUNTRIES, parameters.getCountries().toString());
                table.addCell(" ");
                table.addCell(" ");
                table.addCell("Limits Reduction = " + Float.toString(parameters.getLimitReduction()));
                wfJsonData.put(OnlineWorkflowCommand.LIMIT_REDUCTION,
                        Float.toString(parameters.getLimitReduction()));
                table.addCell(" ");
                table.addCell(" ");
                table.addCell(
                        "Handle Violations in N = " + Boolean.toString(parameters.isHandleViolationsInN()));
                wfJsonData.put(OnlineWorkflowCommand.HANDLE_VIOLATION_IN_N,
                        Boolean.toString(parameters.isHandleViolationsInN()));
                table.addCell(" ");
                table.addCell(" ");
                table.addCell("Constrain Margin = " + Float.toString(parameters.getConstraintMargin()));
                wfJsonData.put(OnlineWorkflowCommand.CONSTRAINT_MARGIN,
                        Float.toString(parameters.getConstraintMargin()));
                if (parameters.getCaseFile() != null) {
                    table.addCell(" ");
                    table.addCell(" ");
                    table.addCell("Case file = " + parameters.getCaseFile());
                    wfJsonData.put(OnlineWorkflowCommand.CASE_FILE, parameters.getCaseFile());
                }
            } else {
                table.addCell("-");
            }
        }
        jsonData.add(wfJsonData);
    }
    if (line.hasOption("json")) {
        Path jsonFile = Paths.get(line.getOptionValue("json"));
        try (FileWriter jsonFileWriter = new FileWriter(jsonFile.toFile())) {
            //JSONSerializer.toJSON(jsonData).write(jsonFileWriter);
            jsonFileWriter.write(JSONSerializer.toJSON(jsonData).toString(3));
        }
    } else
        System.out.println(table.render());

    onlinedb.close();
}

From source file:femr.util.calculations.dateUtils.java

License:Open Source License

public static String getCurrentDateTimeString() {
    DateTimeFormatter dateFormat = DateTimeFormat.forPattern("yyyy/mm/dd HH:mm:ss");
    LocalDateTime localDateTime = new LocalDateTime();
    dateFormat.print(localDateTime);
    String dt = localDateTime.toString();
    return dt;/*from   ww  w.ja  v a2s . co  m*/
}

From source file:fi.johannes.kata.ocr.utils.TimeUtils.java

License:Open Source License

public static String getCurrentDate() {
    DateTime dt = new DateTime();
    DateTimeFormatter fmt = DateTimeFormat.forPattern("d.M.YYYY");
    return fmt.print(dt);
}

From source file:fr.acxio.tools.agia.io.ChronoFileSystemResourceFactory.java

License:Apache License

public Resource getResource() throws ResourceCreationException {
    FileSystemResource aFileSystemResource = null;
    try {//from  w  ww .  j a v a  2 s . c o m
        DateTimeFormatter aFormatter = DateTimeFormat.forPattern(dateFormat);
        StringBuilder aFilename = new StringBuilder();
        aFilename.append(prefix).append(aFormatter.print(new Instant())).append(suffix);
        aFileSystemResource = new FileSystemResource(aFilename.toString());
    } catch (Exception e) {
        throw new ResourceCreationException(e);
    }
    return aFileSystemResource;
}

From source file:fr.rjoakim.android.jonetouch.dialog.ChoiceRestoreDataMyDialog.java

License:Apache License

private String formatStringWithTime(String value) {
    DateTimeFormatter DATE_FORMAT = DateTimeFormat.forPattern("HH:mm:s:SSS");
    return DATE_FORMAT.print(DateTime.now()) + " : " + value;
}

From source file:gluu.scim2.client.util.UserSerializer.java

License:MIT License

@Override
public void serialize(User user, JsonGenerator jsonGenerator, SerializerProvider serializerProvider)
        throws IOException {

    System.out.println(" IN UserSerializer.serialize()... ");

    try {/*from w w  w.  j ava 2  s  .c  o m*/

        jsonGenerator.writeStartObject();

        ObjectMapper mapper = new ObjectMapper();
        mapper.disable(SerializationConfig.Feature.FAIL_ON_EMPTY_BEANS);

        JsonNode rootNode = mapper.convertValue(user, JsonNode.class);

        Iterator<Map.Entry<String, JsonNode>> iterator = rootNode.getFields();
        while (iterator.hasNext()) {

            Map.Entry<String, JsonNode> rootNodeEntry = iterator.next();

            jsonGenerator.writeFieldName(rootNodeEntry.getKey());

            if (rootNodeEntry.getKey().equals(Constants.USER_EXT_SCHEMA_ID)) {

                Extension extension = user.getExtension(rootNodeEntry.getKey());

                Map<String, Object> list = new HashMap<String, Object>();
                for (Map.Entry<String, Extension.Field> extEntry : extension.getFields().entrySet()) {

                    if (extEntry.getValue().isMultiValued()) {

                        if (extEntry.getValue().getType().equals(ExtensionFieldType.STRING)) {

                            List<String> stringList = Arrays
                                    .asList(mapper.readValue(extEntry.getValue().getValue(), String[].class));
                            list.put(extEntry.getKey(), stringList);

                        } else if (extEntry.getValue().getType().equals(ExtensionFieldType.DATE_TIME)) {

                            List<Date> dateList = Arrays
                                    .asList(mapper.readValue(extEntry.getValue().getValue(), Date[].class));
                            List<String> stringList = new ArrayList<String>();
                            DateTimeFormatter dateTimeFormatter = ISODateTimeFormat.dateTime().withZoneUTC();
                            for (Date date : dateList) {
                                String dateString = dateTimeFormatter.print(date.getTime());
                                stringList.add(dateString);
                            }
                            list.put(extEntry.getKey(), stringList);

                        } else if (extEntry.getValue().getType().equals(ExtensionFieldType.DECIMAL)) {

                            List<BigDecimal> numberList = Arrays.asList(
                                    mapper.readValue(extEntry.getValue().getValue(), BigDecimal[].class));
                            list.put(extEntry.getKey(), numberList);
                        }

                    } else {
                        list.put(extEntry.getKey(), extEntry.getValue().getValue());
                    }
                }

                jsonGenerator.writeObject(list);

            } else {

                jsonGenerator.writeObject(rootNodeEntry.getValue());
            }
        }

        jsonGenerator.writeEndObject();

        System.out.println(" LEAVING UserSerializer.serialize()... ");

    } catch (Exception e) {
        e.printStackTrace();
        throw new IOException("Unexpected processing error; please check the input parameters.");
    }
}