Example usage for org.joda.time LocalDate compareTo

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

Introduction

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

Prototype

public int compareTo(ReadablePartial partial) 

Source Link

Document

Compares this partial with another returning an integer indicating the order.

Usage

From source file:org.libreplan.business.workreports.daos.WorkReportDAO.java

License:Open Source License

@Override
@SuppressWarnings("unchecked")
public WorkReport getPersonalTimesheetWorkReport(Resource resource, LocalDate date,
        PersonalTimesheetsPeriodicityEnum periodicity) {

    Criteria criteria = getSession().createCriteria(WorkReport.class);
    criteria.add(Restrictions.eq(WORK_REPORT_TYPE_COLUMN, getPersonalTimesheetsWorkReportType()));
    List<WorkReport> personalTimesheets = criteria.add(Restrictions.eq("resource", resource)).list();

    LocalDate start = periodicity.getStart(date);
    LocalDate end = periodicity.getEnd(date);

    for (WorkReport workReport : personalTimesheets) {
        Set<WorkReportLine> workReportLines = workReport.getWorkReportLines();

        if (!workReportLines.isEmpty()) {
            LocalDate workReportDate = LocalDate.fromDateFields(workReportLines.iterator().next().getDate());

            if (workReportDate.compareTo(start) >= 0 && workReportDate.compareTo(end) <= 0) {
                return workReport;
            }//from  ww w.  j a v a2s.  c  o m
        }
    }

    return null;
}

From source file:org.libreplan.business.workreports.entities.WorkReport.java

License:Open Source License

@AssertTrue(message = "In personal timesheets, all timesheet lines should be in the same period")
public boolean isAllWorkReportLinesInTheSamePeriodInPersonalTimesheetConstraint() {
    if (!getWorkReportType().isPersonalTimesheetsType()) {
        return true;
    }/*  w  w  w .  j  av a 2  s.  c o  m*/

    if (workReportLines.isEmpty()) {
        return true;
    }

    LocalDate workReportDate = LocalDate.fromDateFields(workReportLines.iterator().next().getDate());

    PersonalTimesheetsPeriodicityEnum periodicity = Registry.getConfigurationDAO()
            .getConfigurationWithReadOnlyTransaction().getPersonalTimesheetsPeriodicity();

    LocalDate min = periodicity.getStart(workReportDate);
    LocalDate max = periodicity.getEnd(workReportDate);

    for (WorkReportLine line : workReportLines) {
        LocalDate date = LocalDate.fromDateFields(line.getDate());
        if ((date.compareTo(min) < 0) || (date.compareTo(max) > 0)) {
            return false;
        }
    }
    return true;
}

From source file:org.libreplan.web.calendars.BaseCalendarModel.java

License:Open Source License

@Override
public void checkAndChangeStartDate(CalendarData version, Date date) throws ValidationException {

    if (date == null) {
        if (version.equals(getBaseCalendar().getFirstCalendarData())) {
            return;
        } else {/*from www.j a  va  2 s  .c o m*/
            throw new ValidationException(_("This date cannot be empty"));
        }
    }

    LocalDate newStartDate = LocalDate.fromDateFields(date);
    CalendarData prevVersion = getBaseCalendar().getPrevious(version);
    if ((newStartDate != null) && (prevVersion != null)) {
        if (getBaseCalendar().getPrevious(prevVersion) == null) {
            return;
        }
        LocalDate prevStartDate = getBaseCalendar().getPrevious(prevVersion).getExpiringDate();
        if ((prevStartDate == null) || ((newStartDate.compareTo(prevStartDate) > 0))) {
            prevVersion.setExpiringDate(newStartDate);
            return;
        }
    }
    throw new ValidationException(_("This date can not include the whole previous work week"));
}

From source file:org.libreplan.web.calendars.BaseCalendarModel.java

License:Open Source License

@Override
public void checkChangeExpiringDate(CalendarData version, Date date) {
    Integer index = getBaseCalendar().getCalendarDataVersions().indexOf(version);

    if (date == null) {
        if (version.equals(getBaseCalendar().getLastCalendarData())) {
            return;
        } else {/*from   w ww.j a v  a  2s.co  m*/
            throw new ValidationException(_("This date cannot be empty"));
        }
    }

    LocalDate newExpiringDate = LocalDate.fromDateFields(date);
    if ((index < getBaseCalendar().getCalendarDataVersions().size() - 1)) {
        LocalDate nextExpiringDate = getBaseCalendar().getCalendarDataVersions().get(index + 1)
                .getExpiringDate();
        if ((nextExpiringDate == null) || (newExpiringDate.compareTo(nextExpiringDate) < 0)) {
            return;
        }
    }
    throw new ValidationException(_("Date cannot include the entire next work week"));
}

From source file:org.libreplan.web.limitingresources.ManualAllocationController.java

License:Open Source License

private DateAndHour getSelectedAllocationTime() {
    final Gap selectedGap = getSelectedGap();
    int index = radioAllocationDate.getSelectedIndex();

    // Earliest date
    if (index == 0) {
        return getEarliestTime(selectedGap);

        // Latest date
    } else if (index == 1) {
        return getLatestTime(selectedGap);

        // Select start date
    } else if (index == 2) {
        final LocalDate selectedDay = new LocalDate(startAllocationDate.getValue());
        if (isAppropriative()) {
            LimitingResourceQueueElement beingEdited = getBeingEditedElement();
            if (selectedDay.compareTo(new LocalDate(beingEdited.getEarliestStartDateBecauseOfGantt())) < 0) {
                throw new WrongValueException(startAllocationDate, _("Day is not valid"));
            }/*w  w w  . j  ava  2s.  c o m*/

            return new DateAndHour(selectedDay, 0);
        } else {
            DateAndHour allocationTime = getValidDayInGap(selectedDay, getSelectedGap());
            if (allocationTime == null) {
                throw new WrongValueException(startAllocationDate, _("Day is not valid"));
            }

            return allocationTime;
        }
    }

    return null;
}

From source file:org.libreplan.web.limitingresources.ManualAllocationController.java

License:Open Source License

/**
 * Checks if date is a valid day within gap.
 * A day is valid within a gap if it is included between gap.startTime and the last day from which is
 * possible to start doing an allocation (endAllocationDate).
 *
 * If date is valid, returns DateAndHour in gap associated with that date.
 *
 * @param date//  w  w  w  . j av  a2 s .  c  om
 * @param gap
 * @return {@link DateAndHour}
 */
private DateAndHour getValidDayInGap(LocalDate date, Gap gap) {
    final DateAndHour endAllocationDate = endAllocationDates.get(gap);
    final LocalDate start = gap.getStartTime().getDate();
    final LocalDate end = endAllocationDate != null ? endAllocationDate.getDate() : null;

    if (start.equals(date)) {
        return gap.getStartTime();
    }

    if (end != null && end.equals(date)) {
        return endAllocationDate;
    }

    if ((start.compareTo(date) <= 0 && (end == null || end.compareTo(date) >= 0))) {
        return new DateAndHour(date, 0);
    }

    return null;
}

From source file:org.libreplan.web.limitingresources.QueueTaskGeneratorFactory.java

License:Open Source License

private static LocalDate max(LocalDate l1, LocalDate l2) {
    return l1.compareTo(l2) < 0 ? l2 : l1;
}

From source file:org.libreplan.web.limitingresources.QueueTaskGeneratorFactory.java

License:Open Source License

private static LocalDate min(LocalDate l1, LocalDate l2) {
    return l1.compareTo(l2) < 0 ? l1 : l2;
}

From source file:org.libreplan.web.orders.AssignedHoursToOrderElementModel.java

License:Open Source License

private List<WorkReportLineDTO> groupByDate(List<WorkReportLineDTO> listWRL) {
    List<WorkReportLineDTO> groupedByDateList = new ArrayList<>();

    if (!listWRL.isEmpty()) {
        Iterator<WorkReportLineDTO> iterator = listWRL.iterator();
        WorkReportLineDTO currentWRL = iterator.next();
        groupedByDateList.add(currentWRL);

        while (iterator.hasNext()) {
            WorkReportLineDTO nextWRL = iterator.next();

            LocalDate currentDate = currentWRL.getLocalDate();
            LocalDate nextDate = nextWRL.getLocalDate();

            if ((currentWRL.getResource().getId().equals(nextWRL.getResource().getId()))
                    && (currentWRL.getTypeOfWorkHours().getId().equals(nextWRL.getTypeOfWorkHours().getId()))
                    && (currentDate.compareTo(nextDate) == 0)) {

                // Sum the number of hours to the next WorkReportLineDTO
                currentWRL.setSumEffort(currentWRL.getSumEffort().plus(nextWRL.getSumEffort()));
            } else {
                groupedByDateList.add(nextWRL);
                currentWRL = nextWRL;/*from   w  w  w  . j a v a2 s  .  c  om*/
            }
        }
    }
    return groupedByDateList;
}

From source file:org.libreplan.web.orders.ManageOrderElementAdvancesController.java

License:Open Source License

private String validateDateAdvanceMeasurement(LocalDate value, AdvanceMeasurement measurement) {
    LocalDate oldDate = measurement.getDate();
    measurement.setDate(value);/* w  w  w.  ja v  a 2 s  .  c  o m*/

    if (!manageOrderElementAdvancesModel.isDistinctValidDate(value, measurement))
        return _("Invalid date. Date must be unique for this Progress Assignment");

    if (manageOrderElementAdvancesModel.hasConsolidatedAdvances(measurement))
        measurement.setDate(oldDate);
    else {
        manageOrderElementAdvancesModel.sortListAdvanceMeasurement();
        if (manageOrderElementAdvancesModel.lessThanPreviousMeasurements())
            return _("Invalid value. Value must be greater than the value of previous progress.");
    }

    if (!isReadOnlyAdvanceMeasurements()) {

        LocalDate consolidatedUntil = manageOrderElementAdvancesModel
                .getLastConsolidatedMeasurementDate(measurement.getAdvanceAssignment());

        if (consolidatedUntil != null && consolidatedUntil.compareTo(measurement.getDate()) >= 0) {
            return _("Date is not valid, it must be later than the last progress consolidation");
        }
        if (manageOrderElementAdvancesModel.isAlreadyReportedProgressWith(value)) {
            return _("Date is not valid, it must be later than the last progress reported to the customer");
        }
    }

    return null;
}