Example usage for org.joda.time LocalDate toString

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

Introduction

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

Prototype

@ToString
public String toString() 

Source Link

Document

Output the date time in ISO8601 format (yyyy-MM-dd).

Usage

From source file:com.axelor.apps.project.service.ProjectPlanningService.java

License:Open Source License

public void getTasksForUser(ActionRequest request, ActionResponse response) {
    List<Map<String, String>> dataList = new ArrayList<Map<String, String>>();
    try {/*from  w ww.j a  va 2s  .  c  o  m*/
        LocalDate todayDate = Beans.get(GeneralService.class).getTodayDate();
        List<ProjectPlanningLine> linesList = Beans.get(ProjectPlanningLineRepository.class).all()
                .filter("self.user.id = ?1 AND self.year >= ?2 AND self.week >= ?3",
                        AuthUtils.getUser().getId(), todayDate.getYear(), todayDate.getWeekOfWeekyear())
                .fetch();

        for (ProjectPlanningLine line : linesList) {
            if (line.getMonday().compareTo(BigDecimal.ZERO) != 0) {
                LocalDate date = new LocalDate().withYear(line.getYear()).withWeekOfWeekyear(line.getWeek())
                        .withDayOfWeek(DateTimeConstants.MONDAY);
                if (date.isAfter(todayDate) || date.isEqual(todayDate)) {
                    Map<String, String> map = new HashMap<String, String>();
                    map.put("taskId", line.getProjectTask().getId().toString());
                    map.put("name", line.getProjectTask().getFullName());
                    if (line.getProjectTask().getProject() != null) {
                        map.put("projectName", line.getProjectTask().getProject().getFullName());
                    } else {
                        map.put("projectName", "");
                    }
                    map.put("date", date.toString());
                    map.put("duration", line.getMonday().toString());
                    dataList.add(map);
                }
            }
            if (line.getTuesday().compareTo(BigDecimal.ZERO) != 0) {
                LocalDate date = new LocalDate().withYear(line.getYear()).withWeekOfWeekyear(line.getWeek())
                        .withDayOfWeek(DateTimeConstants.TUESDAY);
                if (date.isAfter(todayDate) || date.isEqual(todayDate)) {
                    Map<String, String> map = new HashMap<String, String>();
                    map.put("taskId", line.getProjectTask().getId().toString());
                    map.put("name", line.getProjectTask().getFullName());
                    if (line.getProjectTask().getProject() != null) {
                        map.put("projectName", line.getProjectTask().getProject().getFullName());
                    } else {
                        map.put("projectName", "");
                    }
                    map.put("date", date.toString());
                    map.put("duration", line.getTuesday().toString());
                    dataList.add(map);
                }
            }
            if (line.getWednesday().compareTo(BigDecimal.ZERO) != 0) {
                LocalDate date = new LocalDate().withYear(line.getYear()).withWeekOfWeekyear(line.getWeek())
                        .withDayOfWeek(DateTimeConstants.WEDNESDAY);
                if (date.isAfter(todayDate) || date.isEqual(todayDate)) {
                    Map<String, String> map = new HashMap<String, String>();
                    map.put("taskId", line.getProjectTask().getId().toString());
                    map.put("name", line.getProjectTask().getFullName());
                    if (line.getProjectTask().getProject() != null) {
                        map.put("projectName", line.getProjectTask().getProject().getFullName());
                    } else {
                        map.put("projectName", "");
                    }
                    map.put("date", date.toString());
                    map.put("duration", line.getWednesday().toString());
                    dataList.add(map);
                }
            }
            if (line.getThursday().compareTo(BigDecimal.ZERO) != 0) {
                LocalDate date = new LocalDate().withYear(line.getYear()).withWeekOfWeekyear(line.getWeek())
                        .withDayOfWeek(DateTimeConstants.THURSDAY);
                if (date.isAfter(todayDate) || date.isEqual(todayDate)) {
                    Map<String, String> map = new HashMap<String, String>();
                    map.put("taskId", line.getProjectTask().getId().toString());
                    map.put("name", line.getProjectTask().getFullName());
                    if (line.getProjectTask().getProject() != null) {
                        map.put("projectName", line.getProjectTask().getProject().getFullName());
                    } else {
                        map.put("projectName", "");
                    }
                    map.put("date", date.toString());
                    map.put("duration", line.getThursday().toString());
                    dataList.add(map);
                }
            }
            if (line.getFriday().compareTo(BigDecimal.ZERO) != 0) {
                LocalDate date = new LocalDate().withYear(line.getYear()).withWeekOfWeekyear(line.getWeek())
                        .withDayOfWeek(DateTimeConstants.FRIDAY);
                if (date.isAfter(todayDate) || date.isEqual(todayDate)) {
                    Map<String, String> map = new HashMap<String, String>();
                    map.put("taskId", line.getProjectTask().getId().toString());
                    map.put("name", line.getProjectTask().getFullName());
                    if (line.getProjectTask().getProject() != null) {
                        map.put("projectName", line.getProjectTask().getProject().getFullName());
                    } else {
                        map.put("projectName", "");
                    }
                    map.put("date", date.toString());
                    map.put("duration", line.getFriday().toString());
                    dataList.add(map);
                }
            }
            if (line.getSaturday().compareTo(BigDecimal.ZERO) != 0) {
                LocalDate date = new LocalDate().withYear(line.getYear()).withWeekOfWeekyear(line.getWeek())
                        .withDayOfWeek(DateTimeConstants.SATURDAY);
                if (date.isAfter(todayDate) || date.isEqual(todayDate)) {
                    Map<String, String> map = new HashMap<String, String>();
                    map.put("taskId", line.getProjectTask().getId().toString());
                    map.put("name", line.getProjectTask().getFullName());
                    if (line.getProjectTask().getProject() != null) {
                        map.put("projectName", line.getProjectTask().getProject().getFullName());
                    } else {
                        map.put("projectName", "");
                    }
                    map.put("date", date.toString());
                    map.put("duration", line.getSaturday().toString());
                    dataList.add(map);
                }
            }
            if (line.getSunday().compareTo(BigDecimal.ZERO) != 0) {
                LocalDate date = new LocalDate().withYear(line.getYear()).withWeekOfWeekyear(line.getWeek())
                        .withDayOfWeek(DateTimeConstants.SUNDAY);
                if (date.isAfter(todayDate) || date.isEqual(todayDate)) {
                    Map<String, String> map = new HashMap<String, String>();
                    map.put("taskId", line.getProjectTask().getId().toString());
                    map.put("name", line.getProjectTask().getFullName());
                    if (line.getProjectTask().getProject() != null) {
                        map.put("projectName", line.getProjectTask().getProject().getFullName());
                    } else {
                        map.put("projectName", "");
                    }
                    map.put("date", date.toString());
                    map.put("duration", line.getSunday().toString());
                    dataList.add(map);
                }
            }
        }
        response.setData(dataList);
    } catch (Exception e) {
        response.setStatus(-1);
        response.setError(e.getMessage());
    }
}

From source file:com.axelor.csv.script.UpdateAll.java

License:Open Source License

@Transactional
public Object updatePeriod(Object bean, Map<String, Object> values) {
    try {//from  w  ww  .  ja  va 2  s.  co m
        assert bean instanceof Company;
        Company company = (Company) bean;
        List<? extends Period> periods = periodRepo.all().filter("self.company.id = ?1", company.getId())
                .fetch();
        if (periods == null || periods.isEmpty()) {
            for (Year year : yearRepo.all()
                    .filter("self.company.id = ?1 AND self.typeSelect = 1", company.getId()).fetch()) {
                for (Integer month : Arrays.asList(new Integer[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 })) {
                    Period period = new Period();
                    LocalDate dt = new LocalDate(year.getFromDate().getYear(), month, 1);
                    period.setToDate(dt.dayOfMonth().withMaximumValue());
                    period.setFromDate(dt.dayOfMonth().withMinimumValue());
                    period.setYear(year);
                    period.setStatusSelect(PeriodRepository.STATUS_OPENED);
                    period.setCompany(company);
                    period.setCode(dt.toString().split("-")[1] + "/" + year.getCode().split("_")[0] + "_"
                            + company.getName());
                    period.setName(dt.toString().split("-")[1] + '/' + year.getName());
                    periodRepo.save(period);
                }
            }
        }

        return company;
    } catch (Exception e) {
        e.printStackTrace();
    }
    return bean;
}

From source file:com.einzig.ipst2.activities.MainActivity.java

License:Open Source License

public void openList(LocalDate dateForList, String listType) {
    Intent intent = new Intent(MainActivity.this, PSListActivity.class);
    String stringForLog = "";
    if (dateForList != null)
        stringForLog = dateForList.toString();
    Logger.i("MainActivity", "Starting list activity with " + listType + " type " + stringForLog + "");
    intent.putExtra(PORTAL_LIST_KEY_TYPE, listType);
    intent.putExtra(PORTAL_LIST_KEY_RANGE, stringForLog);
    startActivityForResult(intent, EDIT_ACTIVITY_CODE);
}

From source file:com.einzig.ipst2.parse.GetMailTask.java

License:Open Source License

/**
 * Get SearchTerm to find relevant emails
 *
 * @param lastParseDate Date of previous parse for ReceivedDateTerm
 * @param anySource     boolean that decides if the email search terms 'from' are included.
 * @return Search term that will find all portal submission emails
 *///  w w w .  ja v  a 2  s.c  om
private SearchTerm getSearchTerm(LocalDate lastParseDate, boolean anySource) {
    SearchTerm portalTerm = new SubjectTerm("ingress portal");
    SearchTerm reviewTerm = new SubjectTerm("portal review");
    SearchTerm submissionTerm = new SubjectTerm("portal submission");
    SearchTerm submittedTerm = new SubjectTerm("portal submitted");
    SearchTerm subjectTerm = new OrTerm(
            new SearchTerm[] { portalTerm, reviewTerm, submissionTerm, submittedTerm });
    ReceivedDateTerm minDateTerm = new ReceivedDateTerm(ComparisonTerm.GT, lastParseDate.toDate());
    SearchTerm invalidTerm = new NotTerm(new SubjectTerm("invalid"));
    SearchTerm editTerm = new NotTerm(new SubjectTerm("edit"));
    SearchTerm editsTerm = new NotTerm(new SubjectTerm("edits"));
    SearchTerm photoTerm = new NotTerm(new SubjectTerm("photo"));
    SearchTerm superOpsTerm = new FromStringTerm("super-ops@google.com");
    SearchTerm iSupportTerm1 = new FromStringTerm("ingress-support@google.com");
    SearchTerm iSupportTerm2 = new FromStringTerm("ingress-support@nianticlabs.com");
    Logger.d("Last Parse Date: " + lastParseDate.toString());
    SearchTerm fromTerm = new OrTerm(new SearchTerm[] { superOpsTerm, iSupportTerm1, iSupportTerm2 });
    if (anySource)
        return new AndTerm(
                new SearchTerm[] { subjectTerm, minDateTerm, invalidTerm, editTerm, editsTerm, photoTerm });
    else
        return new AndTerm(new SearchTerm[] { subjectTerm, minDateTerm, invalidTerm, editTerm, editsTerm,
                photoTerm, fromTerm });
}

From source file:com.excilys.sugadroid.services.impl.ksoap2.AppointmentServicesKsoap2Impl.java

License:Open Source License

@Override
public List<IAppointmentBean> getDayAppointments(LocalDate day) throws ServiceException {

    Log.d(TAG, "getDayAppointments called, date: " + day.toString());

    checkLoggedIn();//ww  w.  j  a  v  a2  s  .  c  o m

    boolean version4_5 = sessionBean.isVersion4_5();

    SoapObject request = newEntryListRequest();

    request.addProperty("module_name", "Meetings");

    String query;

    query = "meetings.id = meetings_users.meeting_id AND meetings_users.user_id='" + sessionBean.getUserId()
            + "' AND ";

    if (version4_5) {
        query += "meetings.date_start='" + day.toString("yyyy-MM-dd") + "'";
    } else {
        query += "meetings.date_start>='" + day.toString("yyyy-MM-dd") + "' AND meetings.date_start<'"
                + day.plusDays(1).toString("yyyy-MM-dd") + "'";
    }

    request.addProperty("query", query);

    if (version4_5) {
        request.addProperty("order_by", "meetings.time_start asc");
    } else {
        request.addProperty("order_by", "meetings.date_start asc");
    }

    request.addProperty("offset", "0");

    List<String> t = new Vector<String>();

    t.add("id");
    t.add("name");

    request.addProperty("select_fields", t);
    request.addProperty("max_results", "100");
    request.addProperty("deleted", "0");

    List<IAppointmentBean> appointments = new ArrayList<IAppointmentBean>();

    if (version4_5) {
        appointments.addAll(getEntryList(request, AppointmentBeanV4_5.class));
    } else {
        appointments.addAll(getEntryList(request, AppointmentBeanV5.class));
    }

    return appointments;
}

From source file:com.excilys.sugadroid.services.impl.ksoap2.AppointmentServicesKsoap2Impl.java

License:Open Source License

@Override
public Map<LocalDate, List<IAppointmentBean>> getAppointmentsInInterval(LocalDate start, LocalDate end)
        throws ServiceException {
    Log.d(TAG, "getAppointmentsInInterval called, days " + start.toString() + " " + end.toString());

    checkLoggedIn();//from   w w  w.jav a 2 s  .c  o  m

    if (start.compareTo(end) > 0) {
        throw new ServiceException("start day should be before or equal to end day");
    }

    boolean version4_5 = sessionBean.isVersion4_5();

    StringBuilder sb = new StringBuilder("meetings_users.meeting_id=meetings.id AND meetings_users.user_id='")
            .append(sessionBean.getUserId()).append("' AND ");

    if (version4_5) {
        sb.append("meetings.date_start>='").append(start.toString("yyyy-MM-dd"))
                .append("' AND meetings.date_start<'").append(end.plusDays(1).toString("yyyy-MM-dd"))
                .append("'");
    } else {
        sb.append("meetings.date_start>='").append(start.toString("yyyy-MM-dd"))
                .append("' AND meetings.date_start<='").append(end.toString("yyyy-MM-dd")).append("'");
    }

    String query = sb.toString();

    SoapObject request = newEntryListRequest();

    request.addProperty("module_name", "Meetings");
    request.addProperty("query", query);
    if (version4_5) {
        request.addProperty("order_by", "meetings.date_start asc, meetings.time_start asc");
    } else {
        request.addProperty("order_by", "meetings.date_start asc");
    }

    request.addProperty("offset", "0");

    List<String> t = new Vector<String>();

    t.add("id");
    t.add("name");
    t.add("date_start");
    if (version4_5) {
        t.add("time_start");
    }

    request.addProperty("select_fields", t);
    request.addProperty("max_results", "1000");
    request.addProperty("deleted", "0");

    List<IAppointmentBean> appointments = new ArrayList<IAppointmentBean>();

    if (version4_5) {
        appointments.addAll(getEntryList(request, AppointmentBeanV4_5.class));
    } else {
        appointments.addAll(getEntryList(request, AppointmentBeanV5.class));
    }

    Map<LocalDate, List<IAppointmentBean>> appointmentsInInterval = new HashMap<LocalDate, List<IAppointmentBean>>();

    appointmentsInInterval.put(start, new ArrayList<IAppointmentBean>());

    LocalDate day = start;

    while (!day.equals(end)) {
        day = day.plusDays(1);
        appointmentsInInterval.put(day, new ArrayList<IAppointmentBean>());
    }

    for (IAppointmentBean appointment : appointments) {
        appointmentsInInterval.get(appointment.getDayStart()).add(appointment);
    }

    return appointmentsInInterval;
}

From source file:com.excilys.sugadroid.util.EagerLoadingCalendar.java

License:Open Source License

public List<IAppointmentBean> getDayAppointments(LocalDate day) throws DayNotLoadedException {

    if (!isDayLoaded(day)) {
        throw new DayNotLoadedException("This day has not been loaded yet: " + day.toString());
    }/*from w  w w.j  av  a 2  s.co m*/

    List<IAppointmentBean> dayAppointments = daysAppointments.get(day);

    // Fixing missing values
    if (dayAppointments == null) {
        Log.i(TAG, "This day does not exist yet, created: " + day.toString());

        dayAppointments = new ArrayList<IAppointmentBean>();
        daysAppointments.put(day, dayAppointments);
    }

    return dayAppointments;
}

From source file:com.gst.infrastructure.campaigns.sms.service.SmsCampaignWritePlatformServiceJpaImpl.java

License:Apache License

private void updateTriggerDates(Long campaignId) {
    final SmsCampaign smsCampaign = this.smsCampaignRepository.findOne(campaignId);
    if (smsCampaign == null) {
        throw new SmsCampaignNotFound(campaignId);
    }//from  w w  w .j  av  a  2  s.c  o m
    LocalDateTime nextTriggerDate = smsCampaign.getNextTriggerDate();
    smsCampaign.setLastTriggerDate(nextTriggerDate.toDate());
    // calculate new trigger date and insert into next trigger date

    /**
     * next run time has to be in the future if not calculate a new future
     * date
     */
    LocalDate nextRuntime = CalendarUtils.getNextRecurringDate(smsCampaign.getRecurrence(),
            smsCampaign.getNextTriggerDate().toLocalDate(), nextTriggerDate.toLocalDate());
    if (nextRuntime.isBefore(DateUtils.getLocalDateOfTenant())) { // means
                                                                  // next
                                                                  // run
                                                                  // time is
                                                                  // in the
                                                                  // past
                                                                  // calculate
                                                                  // a new
                                                                  // future
                                                                  // date
        nextRuntime = CalendarUtils.getNextRecurringDate(smsCampaign.getRecurrence(),
                smsCampaign.getNextTriggerDate().toLocalDate(), DateUtils.getLocalDateOfTenant());
    }
    final LocalDateTime getTime = smsCampaign.getRecurrenceStartDateTime();
    final String dateString = nextRuntime.toString() + " " + getTime.getHourOfDay() + ":"
            + getTime.getMinuteOfHour() + ":" + getTime.getSecondOfMinute();
    final DateTimeFormatter simpleDateFormat = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss");
    final LocalDateTime newTriggerDateWithTime = LocalDateTime.parse(dateString, simpleDateFormat);

    smsCampaign.setNextTriggerDate(newTriggerDateWithTime.toDate());
    this.smsCampaignRepository.saveAndFlush(smsCampaign);
}

From source file:com.gst.infrastructure.campaigns.sms.service.SmsCampaignWritePlatformServiceJpaImpl.java

License:Apache License

@Transactional
@Override/* www.j a va 2 s  . com*/
public CommandProcessingResult activateSmsCampaign(Long campaignId, JsonCommand command) {
    final AppUser currentUser = this.context.authenticatedUser();

    this.smsCampaignValidator.validateActivation(command.json());

    final SmsCampaign smsCampaign = this.smsCampaignRepository.findOne(campaignId);

    if (smsCampaign == null) {
        throw new SmsCampaignNotFound(campaignId);
    }

    final Locale locale = command.extractLocale();
    final DateTimeFormatter fmt = DateTimeFormat.forPattern(command.dateFormat()).withLocale(locale);
    final LocalDate activationDate = command.localDateValueOfParameterNamed("activationDate");

    smsCampaign.activate(currentUser, fmt, activationDate);

    this.smsCampaignRepository.saveAndFlush(smsCampaign);

    if (smsCampaign.isDirect()) {
        insertDirectCampaignIntoSmsOutboundTable(smsCampaign);
    } else if (smsCampaign.isSchedule()) {

        /**
         * if recurrence start date is in the future calculate next trigger
         * date if not use recurrence start date us next trigger date when
         * activating
         */
        LocalDate nextTriggerDate = null;
        if (smsCampaign.getRecurrenceStartDateTime().isBefore(tenantDateTime())) {
            nextTriggerDate = CalendarUtils.getNextRecurringDate(smsCampaign.getRecurrence(),
                    smsCampaign.getRecurrenceStartDate(), DateUtils.getLocalDateOfTenant());
        } else {
            nextTriggerDate = smsCampaign.getRecurrenceStartDate();
        }
        // to get time of tenant
        final LocalDateTime getTime = smsCampaign.getRecurrenceStartDateTime();

        final String dateString = nextTriggerDate.toString() + " " + getTime.getHourOfDay() + ":"
                + getTime.getMinuteOfHour() + ":" + getTime.getSecondOfMinute();
        final DateTimeFormatter simpleDateFormat = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss");
        final LocalDateTime nextTriggerDateWithTime = LocalDateTime.parse(dateString, simpleDateFormat);

        smsCampaign.setNextTriggerDate(nextTriggerDateWithTime.toDate());
        this.smsCampaignRepository.saveAndFlush(smsCampaign);
    }

    /*
     * if campaign is direct insert campaign message into sms outbound table
     * else if its a schedule create a job process for it
     */
    return new CommandProcessingResultBuilder() //
            .withCommandId(command.commandId()) //
            .withEntityId(smsCampaign.getId()) //
            .build();
}

From source file:com.gst.infrastructure.campaigns.sms.service.SmsCampaignWritePlatformServiceJpaImpl.java

License:Apache License

@Transactional
@Override//ww w. j a v  a  2 s. c o  m
public CommandProcessingResult reactivateSmsCampaign(final Long campaignId, JsonCommand command) {

    this.smsCampaignValidator.validateActivation(command.json());

    final AppUser currentUser = this.context.authenticatedUser();

    final SmsCampaign smsCampaign = this.smsCampaignRepository.findOne(campaignId);

    if (smsCampaign == null) {
        throw new SmsCampaignNotFound(campaignId);
    }

    final Locale locale = command.extractLocale();
    final DateTimeFormatter fmt = DateTimeFormat.forPattern(command.dateFormat()).withLocale(locale);
    final LocalDate reactivationDate = command.localDateValueOfParameterNamed("activationDate");
    smsCampaign.reactivate(currentUser, fmt, reactivationDate);
    if (smsCampaign.isDirect()) {
        insertDirectCampaignIntoSmsOutboundTable(smsCampaign);
    } else if (smsCampaign.isSchedule()) {

        /**
         * if recurrence start date is in the future calculate next trigger
         * date if not use recurrence start date us next trigger date when
         * activating
         */
        LocalDate nextTriggerDate = null;
        if (smsCampaign.getRecurrenceStartDateTime().isBefore(tenantDateTime())) {
            nextTriggerDate = CalendarUtils.getNextRecurringDate(smsCampaign.getRecurrence(),
                    smsCampaign.getRecurrenceStartDate(), DateUtils.getLocalDateOfTenant());
        } else {
            nextTriggerDate = smsCampaign.getRecurrenceStartDate();
        }
        // to get time of tenant
        final LocalDateTime getTime = smsCampaign.getRecurrenceStartDateTime();

        final String dateString = nextTriggerDate.toString() + " " + getTime.getHourOfDay() + ":"
                + getTime.getMinuteOfHour() + ":" + getTime.getSecondOfMinute();
        final DateTimeFormatter simpleDateFormat = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss");
        final LocalDateTime nextTriggerDateWithTime = LocalDateTime.parse(dateString, simpleDateFormat);

        smsCampaign.setNextTriggerDate(nextTriggerDateWithTime.toDate());
    }
    this.smsCampaignRepository.saveAndFlush(smsCampaign);

    return new CommandProcessingResultBuilder() //
            .withEntityId(smsCampaign.getId()) //
            .build();

}