Example usage for org.joda.time LocalDate LocalDate

List of usage examples for org.joda.time LocalDate LocalDate

Introduction

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

Prototype

public LocalDate(Object instant) 

Source Link

Document

Constructs an instance from an Object that represents a datetime.

Usage

From source file:com.gst.infrastructure.dataqueries.service.GenericDataServiceImpl.java

License:Apache License

@Override
public String generateJsonFromGenericResultsetData(final GenericResultsetData grs) {

    final StringBuffer writer = new StringBuffer();

    writer.append("[");

    final List<ResultsetColumnHeaderData> columnHeaders = grs.getColumnHeaders();

    final List<ResultsetRowData> data = grs.getData();
    List<String> row;
    Integer rSize;/*from w  ww.  j a  va  2  s  . c o  m*/
    final String doubleQuote = "\"";
    final String slashDoubleQuote = "\\\"";
    String currColType;
    String currVal;

    for (int i = 0; i < data.size(); i++) {
        writer.append("\n{");

        row = data.get(i).getRow();
        rSize = row.size();
        for (int j = 0; j < rSize; j++) {

            writer.append(doubleQuote + columnHeaders.get(j).getColumnName() + doubleQuote + ": ");
            currColType = columnHeaders.get(j).getColumnDisplayType();
            final String colType = columnHeaders.get(j).getColumnType();
            if (currColType == null && colType.equalsIgnoreCase("INT")) {
                currColType = "INTEGER";
            }
            if (currColType == null && colType.equalsIgnoreCase("VARCHAR")) {
                currColType = "VARCHAR";
            }
            if (currColType == null && colType.equalsIgnoreCase("DATE")) {
                currColType = "DATE";
            }
            currVal = row.get(j);
            if (currVal != null && currColType != null) {
                if (currColType.equals("DECIMAL") || currColType.equals("INTEGER")) {
                    writer.append(currVal);
                } else {
                    if (currColType.equals("DATE")) {
                        final LocalDate localDate = new LocalDate(currVal);
                        writer.append("[" + localDate.getYear() + ", " + localDate.getMonthOfYear() + ", "
                                + localDate.getDayOfMonth() + "]");
                    } else if (currColType.equals("DATETIME")) {
                        final LocalDateTime localDateTime = new LocalDateTime(currVal);
                        writer.append("[" + localDateTime.getYear() + ", " + localDateTime.getMonthOfYear()
                                + ", " + localDateTime.getDayOfMonth() + " " + localDateTime.getHourOfDay()
                                + ", " + localDateTime.getMinuteOfHour() + ", "
                                + localDateTime.getSecondOfMinute() + ", " + localDateTime.getMillisOfSecond()
                                + "]");
                    } else {
                        writer.append(
                                doubleQuote + replace(currVal, doubleQuote, slashDoubleQuote) + doubleQuote);
                    }
                }
            } else {
                writer.append("null");
            }
            if (j < (rSize - 1)) {
                writer.append(",\n");
            }
        }

        if (i < (data.size() - 1)) {
            writer.append("},");
        } else {
            writer.append("}");
        }
    }

    writer.append("\n]");
    return writer.toString();

}

From source file:com.gst.infrastructure.survey.service.ReadSurveyServiceImpl.java

License:Apache License

@Override
public List<ClientScoresOverview> retrieveClientSurveyScoreOverview(String surveyName, Long clientId) {

    final String sql = "SELECT  tz.id, lkh.name, lkh.code, poverty_line, tz.date, tz.score FROM " + surveyName
            + " tz" + " JOIN ppi_likelihoods_ppi lkp on lkp.ppi_name = '" + surveyName + "' AND enabled = '"
            + LikelihoodStatus.ENABLED/*from   ww w .j  a  v  a2 s.c o m*/
            + "' JOIN ppi_scores sc on score_from  <= tz.score AND score_to >=tz.score"
            + " JOIN ppi_poverty_line pvl on pvl.likelihood_ppi_id = lkp.id AND pvl.score_id = sc.id"
            + " JOIN ppi_likelihoods lkh on lkh.id = lkp.likelihood_id " + " WHERE  client_id = " + clientId;

    final SqlRowSet rs = this.jdbcTemplate.queryForRowSet(sql);

    List<ClientScoresOverview> scoresOverviews = new ArrayList<>();

    while (rs.next()) {
        scoresOverviews.add(new ClientScoresOverview(rs.getString("code"), rs.getString("name"),
                rs.getLong("score"), rs.getDouble("poverty_line"),
                new LocalDate(rs.getTimestamp("date").getTime()), rs.getLong("id"), surveyName));
    }

    return scoresOverviews;
}

From source file:com.gst.infrastructure.survey.service.ReadSurveyServiceImpl.java

License:Apache License

@Override
public List<ClientScoresOverview> retrieveClientSurveyScoreOverview(Long clientId) {
    final String surveyNameSql = retrieveAllSurveyNameSQL();
    final SqlRowSet surveyNames = this.jdbcTemplate.queryForRowSet(surveyNameSql);

    ArrayList<String> sqls = new ArrayList<>();

    while (surveyNames.next()) {
        sqls.add("SELECT '" + surveyNames.getString("name")
                + "' as surveyName, tz.id, lkh.name, lkh.code, poverty_line, tz.date, tz.score FROM "
                + surveyNames.getString("name") + " tz" + " JOIN ppi_likelihoods_ppi lkp on lkp.ppi_name = '"
                + surveyNames.getString("name") + "' AND enabled = '" + LikelihoodStatus.ENABLED
                + "' JOIN ppi_scores sc on score_from  <= tz.score AND score_to >=tz.score"
                + " JOIN ppi_poverty_line pvl on pvl.likelihood_ppi_id = lkp.id AND pvl.score_id = sc.id"
                + " JOIN ppi_likelihoods lkh on lkh.id = lkp.likelihood_id " + " WHERE  client_id = "
                + clientId);//from   w w w  .  ja v  a2 s  .  co m
    }

    List<ClientScoresOverview> scoresOverviews = new ArrayList<>();

    for (String sql : sqls) {
        final SqlRowSet rs = this.jdbcTemplate.queryForRowSet(sql);

        while (rs.next()) {
            scoresOverviews.add(
                    new ClientScoresOverview(rs.getString("code"), rs.getString("name"), rs.getLong("score"),
                            rs.getDouble("poverty_line"), new LocalDate(rs.getTimestamp("date").getTime()),
                            rs.getLong("id"), rs.getString("surveyName")));
        }

    }

    return scoresOverviews;
}

From source file:com.gst.organisation.holiday.domain.Holiday.java

License:Apache License

public LocalDate getRepaymentsRescheduledToLocalDate() {
    LocalDate repaymentsRescheduledTo = null;
    if (this.repaymentsRescheduledTo != null) {
        repaymentsRescheduledTo = new LocalDate(this.repaymentsRescheduledTo);
    }//from ww  w  .  j a va2  s  .  c  om
    return repaymentsRescheduledTo;
}

From source file:com.gst.organisation.holiday.domain.Holiday.java

License:Apache License

public LocalDate getFromDateLocalDate() {
    LocalDate fromDate = null;/*  w w  w .  j a  v a  2  s.c o  m*/
    if (this.fromDate != null) {
        fromDate = new LocalDate(this.fromDate);
    }
    return fromDate;
}

From source file:com.gst.organisation.holiday.domain.Holiday.java

License:Apache License

public LocalDate getToDateLocalDate() {
    LocalDate toDate = null;/*from ww w .j  a v a  2s.c  o m*/
    if (this.toDate != null) {
        toDate = new LocalDate(this.toDate);
    }
    return toDate;
}

From source file:com.gst.portfolio.calendar.service.CalendarUtils.java

License:Apache License

private static LocalDate getNextRecurringDate(final Recur recur, final LocalDate seedDate,
        final LocalDate startDate) {
    final DateTime periodStart = new DateTime(startDate.toDate());
    final Date seed = convertToiCal4JCompatibleDate(seedDate);
    final Date nextRecDate = recur.getNextDate(seed, periodStart);
    return nextRecDate == null ? null : new LocalDate(nextRecDate);
}

From source file:com.gst.portfolio.calendar.service.CalendarUtils.java

License:Apache License

private static Collection<LocalDate> convertToLocalDateList(final DateList dates, final LocalDate seedDate,
        final PeriodFrequencyType frequencyType, boolean isSkippMeetingOnFirstDay, final Integer numberOfDays) {

    final Collection<LocalDate> recurringDates = new ArrayList<>();

    for (@SuppressWarnings("rawtypes")
    final Iterator iterator = dates.iterator(); iterator.hasNext();) {
        final Date date = (Date) iterator.next();
        recurringDates.add(adjustDate(new LocalDate(date), seedDate, frequencyType));
    }/*from  w  ww.j  a va  2 s  . c om*/

    if (isSkippMeetingOnFirstDay) {
        return skipMeetingOnFirstdayOfMonth(recurringDates, numberOfDays);
    }

    return recurringDates;
}

From source file:com.gst.portfolio.calendar.service.CalendarUtils.java

License:Apache License

public static String getRRuleReadable(final LocalDate startDate, final String recurringRule) {

    String humanReadable = "";

    RRule rrule;//from w  w  w .ja  v  a2 s  .c  o m
    Recur recur = null;
    try {
        rrule = new RRule(recurringRule);
        rrule.validate();
        recur = rrule.getRecur();
    } catch (final ValidationException e) {
        throw new PlatformDataIntegrityException("error.msg.invalid.recurring.rule",
                "The Recurring Rule value: " + recurringRule + " is not valid.", "recurrence", recurringRule);
    } catch (final ParseException e) {
        throw new PlatformDataIntegrityException("error.msg.recurring.rule.parsing.error",
                "Error in pasring the Recurring Rule value: " + recurringRule, "recurrence", recurringRule);
    }

    if (recur == null) {
        return humanReadable;
    }

    if (recur.getFrequency().equals(Recur.DAILY)) {
        if (recur.getInterval() == 1) {
            humanReadable = "Daily";
        } else {
            humanReadable = "Every " + recur.getInterval() + " days";
        }
    } else if (recur.getFrequency().equals(Recur.WEEKLY)) {
        if (recur.getInterval() == 1 || recur.getInterval() == -1) {
            humanReadable = "Weekly";
        } else {
            humanReadable = "Every " + recur.getInterval() + " weeks";
        }

        humanReadable += " on ";
        final WeekDayList weekDayList = recur.getDayList();

        for (@SuppressWarnings("rawtypes")
        final Iterator iterator = weekDayList.iterator(); iterator.hasNext();) {
            final WeekDay weekDay = (WeekDay) iterator.next();
            humanReadable += DayNameEnum.from(weekDay.getDay()).getCode();
        }

    } else if (recur.getFrequency().equals(Recur.MONTHLY)) {
        NumberList nthDays = recur.getSetPosList();
        Integer nthDay = null;
        if (!nthDays.isEmpty())
            nthDay = (Integer) nthDays.get(0);
        NumberList monthDays = recur.getMonthDayList();
        Integer monthDay = null;
        if (!monthDays.isEmpty())
            monthDay = (Integer) monthDays.get(0);
        WeekDayList weekdays = recur.getDayList();
        WeekDay weekDay = null;
        if (!weekdays.isEmpty())
            weekDay = (WeekDay) weekdays.get(0);
        if (nthDay != null && weekDay != null) {
            NthDayType nthDayType = NthDayType.fromInt(nthDay);
            NthDayNameEnum nthDayName = NthDayNameEnum.from(nthDayType.toString());
            DayNameEnum weekdayType = DayNameEnum.from(weekDay.getDay());
            if (recur.getInterval() == 1 || recur.getInterval() == -1) {
                humanReadable = "Monthly on " + nthDayName.getCode().toLowerCase() + " "
                        + weekdayType.getCode().toLowerCase();
            } else {
                humanReadable = "Every " + recur.getInterval() + " months on "
                        + nthDayName.getCode().toLowerCase() + " " + weekdayType.getCode().toLowerCase();
            }
        } else if (monthDay != null) {
            if (monthDay == -1) {
                if (recur.getInterval() == 1 || recur.getInterval() == -1) {
                    humanReadable = "Monthly on last day";
                } else {
                    humanReadable = "Every " + recur.getInterval() + " months on last day";
                }
            } else {
                if (recur.getInterval() == 1 || recur.getInterval() == -1) {
                    humanReadable = "Monthly on day " + monthDay;
                } else {
                    humanReadable = "Every " + recur.getInterval() + " months on day " + monthDay;
                }
            }
        } else {
            if (recur.getInterval() == 1 || recur.getInterval() == -1) {
                humanReadable = "Monthly on day " + startDate.getDayOfMonth();
            } else {
                humanReadable = "Every " + recur.getInterval() + " months on day " + startDate.getDayOfMonth();
            }
        }
    } else if (recur.getFrequency().equals(Recur.YEARLY)) {
        if (recur.getInterval() == 1) {
            humanReadable = "Annually on " + startDate.toString("MMM") + " " + startDate.getDayOfMonth();
        } else {
            humanReadable = "Every " + recur.getInterval() + " years on " + startDate.toString("MMM") + " "
                    + startDate.getDayOfMonth();
        }
    }

    if (recur.getCount() > 0) {
        if (recur.getCount() == 1) {
            humanReadable = "Once";
        }
        humanReadable += ", " + recur.getCount() + " times";
    }

    final Date endDate = recur.getUntil();
    final LocalDate date = new LocalDate(endDate);
    final DateTimeFormatter fmt = DateTimeFormat.forPattern("dd MMMM YY");
    final String formattedDate = date.toString(fmt);
    if (endDate != null) {
        humanReadable += ", until " + formattedDate;
    }

    return humanReadable;
}

From source file:com.gst.portfolio.client.domain.Client.java

License:Apache License

public LocalDate getSubmittedOnDate() {
    return (LocalDate) ObjectUtils.defaultIfNull(new LocalDate(this.submittedOnDate), null);
}