Example usage for org.joda.time LocalDate isAfter

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

Introduction

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

Prototype

public boolean isAfter(ReadablePartial partial) 

Source Link

Document

Is this partial later than the specified partial.

Usage

From source file:com.helger.peppol.smpserver.ui.secure.PageSecureEndpoints.java

License:Apache License

@Override
protected void validateAndSaveInputParameters(@Nonnull final WebPageExecutionContext aWPEC,
        @Nullable final ISMPServiceInformation aSelectedObject, @Nonnull final FormErrors aFormErrors,
        @Nonnull final EWebPageFormAction eFormAction) {
    final boolean bEdit = eFormAction.isEdit();
    final Locale aDisplayLocale = aWPEC.getDisplayLocale();
    final ISMPProcess aSelectedProcess = aWPEC.getRequestScope().getCastedAttribute(ATTR_PROCESS);
    final ISMPEndpoint aSelectedEndpoint = aWPEC.getRequestScope().getCastedAttribute(ATTR_ENDPOINT);
    final ISMPServiceGroupManager aServiceGroupManager = SMPMetaManager.getServiceGroupMgr();
    final ISMPServiceInformationManager aServiceInfoMgr = SMPMetaManager.getServiceInformationMgr();
    final ISMPRedirectManager aRedirectMgr = SMPMetaManager.getRedirectMgr();
    final SMPTransportProfileManager aTransportProfileMgr = SMPMetaManager.getTransportProfileMgr();

    final String sServiceGroupID = bEdit ? aSelectedObject.getServiceGroupID()
            : aWPEC.getAttributeAsString(FIELD_SERVICE_GROUP_ID);
    ISMPServiceGroup aServiceGroup = null;

    final String sDocTypeIDScheme = bEdit ? aSelectedObject.getDocumentTypeIdentifier().getScheme()
            : aWPEC.getAttributeAsString(FIELD_DOCTYPE_ID_SCHEME);
    final String sDocTypeIDValue = bEdit ? aSelectedObject.getDocumentTypeIdentifier().getValue()
            : aWPEC.getAttributeAsString(FIELD_DOCTYPE_ID_VALUE);
    IPeppolDocumentTypeIdentifier aDocTypeID = null;
    final String sProcessIDScheme = bEdit ? aSelectedProcess.getProcessIdentifier().getScheme()
            : aWPEC.getAttributeAsString(FIELD_PROCESS_ID_SCHEME);
    final String sProcessIDValue = bEdit ? aSelectedProcess.getProcessIdentifier().getValue()
            : aWPEC.getAttributeAsString(FIELD_PROCESS_ID_VALUE);
    IPeppolProcessIdentifier aProcessID = null;

    final String sTransportProfileID = bEdit ? aSelectedEndpoint.getTransportProfile()
            : aWPEC.getAttributeAsString(FIELD_TRANSPORT_PROFILE);
    final ISMPTransportProfile aTransportProfile = aTransportProfileMgr
            .getSMPTransportProfileOfID(sTransportProfileID);
    final String sEndpointReference = aWPEC.getAttributeAsString(FIELD_ENDPOINT_REFERENCE);
    final boolean bRequireBusinessLevelSignature = aWPEC
            .getAttributeAsBoolean(FIELD_REQUIRES_BUSINESS_LEVEL_SIGNATURE);
    final String sMinimumAuthenticationLevel = aWPEC.getAttributeAsString(FIELD_MINIMUM_AUTHENTICATION_LEVEL);
    final String sNotBefore = aWPEC.getAttributeAsString(FIELD_NOT_BEFORE);
    final LocalDate aNotBeforeDate = PDTFromString.getLocalDateFromString(sNotBefore, aDisplayLocale);
    final String sNotAfter = aWPEC.getAttributeAsString(FIELD_NOT_AFTER);
    final LocalDate aNotAfterDate = PDTFromString.getLocalDateFromString(sNotAfter, aDisplayLocale);
    final String sCertificate = aWPEC.getAttributeAsString(FIELD_CERTIFICATE);
    final String sServiceDescription = aWPEC.getAttributeAsString(FIELD_SERVICE_DESCRIPTION);
    final String sTechnicalContact = aWPEC.getAttributeAsString(FIELD_TECHNICAL_CONTACT);
    final String sTechnicalInformation = aWPEC.getAttributeAsString(FIELD_TECHNICAL_INFORMATION);
    final String sExtension = aWPEC.getAttributeAsString(FIELD_EXTENSION);

    // validations
    if (StringHelper.isEmpty(sServiceGroupID))
        aFormErrors.addFieldError(FIELD_SERVICE_GROUP_ID, "A service group must be selected!");
    else {//from w w  w. j  a v  a2  s.com
        aServiceGroup = aServiceGroupManager
                .getSMPServiceGroupOfID(SimpleParticipantIdentifier.createFromURIPartOrNull(sServiceGroupID));
        if (aServiceGroup == null)
            aFormErrors.addFieldError(FIELD_SERVICE_GROUP_ID, "The provided service group does not exist!");
    }

    if (StringHelper.isEmpty(sDocTypeIDScheme))
        aFormErrors.addFieldError(FIELD_DOCTYPE_ID_SCHEME, "Document type ID scheme must not be empty!");
    else if (StringHelper.isEmpty(sDocTypeIDValue))
        aFormErrors.addFieldError(FIELD_DOCTYPE_ID_VALUE, "Document type ID value must not be empty!");
    else {
        aDocTypeID = SimpleDocumentTypeIdentifier.createFromURIPartOrNull(
                sDocTypeIDScheme + CIdentifier.URL_SCHEME_VALUE_SEPARATOR + sDocTypeIDValue);
        if (aDocTypeID == null)
            aFormErrors.addFieldError(FIELD_DOCTYPE_ID_VALUE,
                    "The provided document type ID has an invalid syntax!");
        else {
            if (aServiceGroup != null)
                if (aRedirectMgr.getSMPRedirectOfServiceGroupAndDocumentType(aServiceGroup, aDocTypeID) != null)
                    aFormErrors.addFieldError(FIELD_DOCTYPE_ID_VALUE,
                            "At least one redirect is registered for this document type. Delete the redirect before you can create an endpoint.");
        }
    }

    if (StringHelper.isEmpty(sProcessIDScheme))
        aFormErrors.addFieldError(FIELD_PROCESS_ID_SCHEME, "Process ID scheme must not be empty!");
    else if (StringHelper.isEmpty(sProcessIDValue))
        aFormErrors.addFieldError(FIELD_PROCESS_ID_SCHEME, "Process ID value must not be empty!");
    else {
        aProcessID = SimpleProcessIdentifier.createFromURIPartOrNull(
                sProcessIDScheme + CIdentifier.URL_SCHEME_VALUE_SEPARATOR + sProcessIDValue);
        if (aProcessID == null)
            aFormErrors.addFieldError(FIELD_PROCESS_ID_VALUE, "The provided process ID has an invalid syntax!");
    }

    if (StringHelper.isEmpty(sTransportProfileID))
        aFormErrors.addFieldError(FIELD_TRANSPORT_PROFILE, "Transport Profile must not be empty!");
    else if (aTransportProfile == null)
        aFormErrors.addFieldError(FIELD_TRANSPORT_PROFILE,
                "Transport Profile of type '" + sTransportProfileID + "' does not exist!");
    if (!bEdit && aServiceGroup != null && aDocTypeID != null && aProcessID != null && aTransportProfile != null
            && aServiceInfoMgr.findServiceInformation(aServiceGroup, aDocTypeID, aProcessID,
                    aTransportProfile) != null)
        aFormErrors.addFieldError(FIELD_TRANSPORT_PROFILE,
                "Another endpoint for the provided service group, document type, process and transport profile is already present.");

    if (StringHelper.isEmpty(sEndpointReference)) {
        if (false)
            aFormErrors.addFieldError(FIELD_ENDPOINT_REFERENCE, "Endpoint Reference must not be empty!");
    } else if (URLHelper.getAsURL(sEndpointReference) == null)
        aFormErrors.addFieldError(FIELD_ENDPOINT_REFERENCE, "The Endpoint Reference is not a valid URL!");

    if (aNotBeforeDate != null && aNotAfterDate != null)
        if (aNotBeforeDate.isAfter(aNotAfterDate))
            aFormErrors.addFieldError(FIELD_NOT_BEFORE, "Not Before Date must not be after Not After Date!");

    if (StringHelper.isEmpty(sCertificate))
        aFormErrors.addFieldError(FIELD_CERTIFICATE, "Certificate must not be empty!");
    else {
        X509Certificate aCert = null;
        try {
            aCert = CertificateHelper.convertStringToCertficate(sCertificate);
        } catch (final CertificateException ex) {
            // Fall through
        }
        if (aCert == null)
            aFormErrors.addFieldError(FIELD_CERTIFICATE,
                    "The provided certificate string is not a valid X509 certificate!");
    }

    if (StringHelper.isEmpty(sServiceDescription))
        aFormErrors.addFieldError(FIELD_SERVICE_DESCRIPTION, "Service Description must not be empty!");

    if (StringHelper.isEmpty(sTechnicalContact))
        aFormErrors.addFieldError(FIELD_TECHNICAL_CONTACT, "Technical Contact must not be empty!");

    if (StringHelper.hasText(sExtension)) {
        final IMicroDocument aDoc = MicroReader.readMicroXML(sExtension);
        if (aDoc == null)
            aFormErrors.addFieldError(FIELD_EXTENSION, "The extension must be XML content.");
    }

    if (aFormErrors.isEmpty()) {
        ISMPServiceInformation aServiceInfo = aServiceInfoMgr
                .getSMPServiceInformationOfServiceGroupAndDocumentType(aServiceGroup, aDocTypeID);
        if (aServiceInfo == null)
            aServiceInfo = new SMPServiceInformation(aServiceGroup, aDocTypeID, null, null);

        ISMPProcess aProcess = aServiceInfo.getProcessOfID(aProcessID);
        if (aProcess == null) {
            aProcess = new SMPProcess(aProcessID, null, null);
            aServiceInfo.addProcess((SMPProcess) aProcess);
        }

        aProcess.setEndpoint(new SMPEndpoint(sTransportProfileID, sEndpointReference,
                bRequireBusinessLevelSignature, sMinimumAuthenticationLevel,
                aNotBeforeDate == null ? null : aNotBeforeDate.toLocalDateTime(CPDT.NULL_LOCAL_TIME),
                aNotAfterDate == null ? null : aNotAfterDate.toLocalDateTime(CPDT.NULL_LOCAL_TIME),
                sCertificate, sServiceDescription, sTechnicalContact, sTechnicalInformation, sExtension));

        aServiceInfoMgr.mergeSMPServiceInformation(aServiceInfo);
        if (bEdit) {
            aWPEC.postRedirectGet(
                    new BootstrapSuccessBox().addChild("Successfully edited the endpoint for service group '"
                            + aServiceGroup.getParticpantIdentifier().getURIEncoded() + "'."));
        } else {
            aWPEC.postRedirectGet(
                    new BootstrapSuccessBox().addChild("Successfully created a new endpoint for service group '"
                            + aServiceGroup.getParticpantIdentifier().getURIEncoded() + "'."));
        }
    }
}

From source file:com.jjlharrison.jollyday.parser.impl.FixedWeekdayBetweenFixedParser.java

License:Apache License

/**
 * {@inheritDoc}/*www .j  a v a 2  s  .  c  om*/
 *
 * Parses the provided configuration and creates holidays for the provided
 * year.
 */
public void parse(int year, Set<Holiday> holidays, final Holidays config) {
    for (FixedWeekdayBetweenFixed fwm : config.getFixedWeekdayBetweenFixed()) {
        if (!isValid(fwm, year)) {
            continue;
        }
        LocalDate from = calendarUtil.create(year, fwm.getFrom());
        LocalDate to = calendarUtil.create(year, fwm.getTo());
        LocalDate result = null;
        for (; !from.isAfter(to);) {
            if (from.getDayOfWeek() == xmlUtil.getWeekday(fwm.getWeekday())) {
                result = from;
                break;
            }
            from = from.plusDays(1);
        }
        if (result != null) {
            HolidayType type = xmlUtil.getType(fwm.getLocalizedType());
            holidays.add(new Holiday(result, fwm.getDescriptionPropertiesKey(), type));
        }
    }
}

From source file:com.mbc.jfin.daycount.impl.calculator.AFBActualActualDaycountCalculator.java

License:Open Source License

public double calculateDaycountFraction(SchedulePeriod period) {
    int daysBetween = DateUtils.daysBetween(period.getStart(), period.getEnd());

    if (daysBetween == 0)
        return 0;

    LocalDate newD2 = period.getEnd();
    LocalDate temp = period.getEnd();

    double sum = 0.0;
    while (temp.isAfter(period.getStart())) {
        temp = newD2;/*from   ww w  .jav  a 2  s.  c o  m*/
        temp = temp.minus(Years.ONE);
        if (temp.getDayOfMonth() == 28 && temp.getMonthOfYear() == 2 && DateUtils.isLeapYear(temp)) {
            temp = temp.plus(Days.ONE);
        }
        if (temp.isAfter(period.getStart()) || temp.equals(period.getStart())) {
            sum += 1.0;
            newD2 = temp;
        }
    }

    double den = 365.0;

    if (DateUtils.isLeapYear(newD2)) {
        temp = newD2;

        temp = new LocalDate(temp.getYear(), 2, 29);

        if (newD2.isAfter(temp) && (period.getStart().isBefore(temp) || period.getStart().equals(temp)))
            den += 1.0;
    } else if (DateUtils.isLeapYear(period.getStart())) {

        temp = new LocalDate(period.getStart().getYear(), 2, 29);

        if (newD2.isAfter(temp) && (period.getStart().isBefore(temp) || period.getStart().equals(temp)))
            den += 1.0;
    }

    return sum + DateUtils.daysBetween(period.getStart(), newD2) / den;

}

From source file:com.mbc.jfin.daycount.impl.calculator.ISMAActualActualDaycountCalculator.java

License:Open Source License

public double calculateDaycountFraction(SchedulePeriod schedulePeriod) {

    if (schedulePeriod.getStart().equals(schedulePeriod.getEnd()))
        return 0;

    // when the reference period is not specified, try taking
    // it equal to (d1,d2)
    LocalDate refPeriodStart = (schedulePeriod.getReferenceStart() != null ? schedulePeriod.getReferenceStart()
            : schedulePeriod.getStart());
    LocalDate refPeriodEnd = (schedulePeriod.getReferenceEnd() != null ? schedulePeriod.getReferenceEnd()
            : schedulePeriod.getEnd());//from  w  w w.j  av  a 2s .  c om

    LocalDate startCalendar = schedulePeriod.getStart();
    LocalDate endCalendar = schedulePeriod.getEnd();

    if (!(refPeriodEnd.isAfter(refPeriodStart) && refPeriodEnd.isAfter(startCalendar))) {
        throw new InvalidReferencePeriodException(schedulePeriod);
    }

    // estimate roughly the length in months of a period
    // Integer months =
    // Integer(0.5+12*Real(refPeriodEnd-refPeriodStart)/365);

    double monthsEstimate = DateUtils.daysBetween(refPeriodStart, refPeriodEnd) * (12.0d / 365.0d);
    int months = (int) Math.round(monthsEstimate);

    if (months == 0) {
        refPeriodStart = startCalendar;
        refPeriodEnd = startCalendar.plus(Years.ONE);
        months = 12;
    }

    double period = (double) months / 12.0;

    if (endCalendar.isBefore(refPeriodEnd) || endCalendar.equals(refPeriodEnd)) {
        if (startCalendar.isAfter(refPeriodStart) || startCalendar.equals(refPeriodStart)) {
            long numerator = DateUtils.daysBetween(startCalendar, endCalendar);
            long denominator = DateUtils.daysBetween(refPeriodStart, refPeriodEnd);

            return period * (double) numerator / (double) denominator;
        } else {

            LocalDate previousRef = startCalendar;

            //previousRef.add(Calendar.MONTH, months * -1);
            if (endCalendar.isAfter(refPeriodStart))
                return calculateDaycountFraction(
                        new SchedulePeriod(startCalendar, refPeriodStart, previousRef, refPeriodStart))
                        + calculateDaycountFraction(
                                new SchedulePeriod(refPeriodStart, endCalendar, refPeriodStart, refPeriodEnd));
            else
                return calculateDaycountFraction(
                        new SchedulePeriod(startCalendar, endCalendar, previousRef, refPeriodStart));
        }
    } else {
        if (!(refPeriodStart.isBefore(startCalendar) || refPeriodStart.equals(startCalendar))) {
            throw new InvalidReferencePeriodException(schedulePeriod);
        }

        // the part from d1 to refPeriodEnd
        double sum = calculateDaycountFraction(
                new SchedulePeriod(startCalendar, refPeriodEnd, refPeriodStart, refPeriodEnd));

        // the part from refPeriodEnd to d2
        // count how many regular periods are in [refPeriodEnd, d2],
        // then add the remaining time
        int i = 0;
        LocalDate newRefStart, newRefEnd;
        do {
            newRefStart = refPeriodEnd.plus(Months.months(months * i));
            newRefEnd = refPeriodEnd.plus(Months.months(months * (i + 1)));
            if (endCalendar.isBefore(newRefEnd)) {
                break;
            } else {
                sum += period;
                i++;
            }
        } while (true);
        double secondSum = calculateDaycountFraction(
                new SchedulePeriod(newRefStart, endCalendar, newRefStart, newRefEnd));

        sum += secondSum;
        return sum;
    }
}

From source file:com.mbc.jfin.schedule.impl.LongFirstStubScheduleGenerator.java

License:Open Source License

public Schedule generate(LocalDate start, LocalDate end, ReadablePeriod frequency) throws ScheduleException {
    ArrayList<SchedulePeriod> schedulePeriods = new ArrayList<SchedulePeriod>();

    LocalDate holdDate = end;

    int periodCount = 1;

    while (holdDate.isAfter(start)) {
        LocalDate nextDate = end.minus(multiplyPeriod(frequency, periodCount));

        LocalDate nextDate2 = end.minus(multiplyPeriod(frequency, periodCount + 1));

        if (nextDate2.isBefore(start)) {
            SchedulePeriod schedulePeriod = new SchedulePeriod(start, holdDate, nextDate, holdDate);

            schedulePeriods.add(0, schedulePeriod);

            holdDate = nextDate2;//from w ww. j a  va 2s  .  c  om
        } else {
            SchedulePeriod schedulePeriod = new SchedulePeriod(nextDate, holdDate);

            schedulePeriods.add(0, schedulePeriod);

            holdDate = nextDate;
        }

        periodCount++;
        if (maxPeriods > 0 && periodCount > maxPeriods) {
            throw new ScheduleTooLongException(maxPeriods);
        }
    }

    return new Schedule(schedulePeriods);
}

From source file:com.mbc.jfin.schedule.impl.LongLastStubScheduleGenerator.java

License:Open Source License

public Schedule generate(LocalDate start, LocalDate end, ReadablePeriod frequency) throws ScheduleException {
    ArrayList<SchedulePeriod> schedulePeriods = new ArrayList<SchedulePeriod>();

    LocalDate holdDate = start;//  w ww  .ja  v a2s  .c  o  m

    int periodCount = 1;

    while (holdDate.isBefore(end)) {
        LocalDate nextDate = start.plus(multiplyPeriod(frequency, periodCount));

        LocalDate nextDate2 = start.plus(multiplyPeriod(frequency, periodCount + 1));

        if (nextDate2.isAfter(end)) {
            SchedulePeriod schedulePeriod = new SchedulePeriod(holdDate, end, holdDate, nextDate);

            schedulePeriods.add(schedulePeriod);

            holdDate = nextDate2;
        } else {
            SchedulePeriod schedulePeriod = new SchedulePeriod(holdDate, nextDate);

            schedulePeriods.add(schedulePeriod);

            holdDate = nextDate;
        }

        periodCount++;
        if (maxPeriods > 0 && periodCount > maxPeriods) {
            throw new ScheduleTooLongException(maxPeriods);
        }
    }

    return new Schedule(schedulePeriods);
}

From source file:com.mbc.jfin.schedule.impl.NoStubScheduleGenerator.java

License:Open Source License

public Schedule generate(LocalDate start, LocalDate end, ReadablePeriod frequency) throws ScheduleException {
    ArrayList<SchedulePeriod> schedulePeriods = new ArrayList<SchedulePeriod>();

    LocalDate holdDate = start;//from   w w  w  .  j  av  a2  s .  c o  m

    int periodCount = 1;

    while (holdDate.isBefore(end)) {
        LocalDate nextDate = start.plus(multiplyPeriod(frequency, periodCount));

        if (nextDate.isAfter(end)) {
            throw new ScheduleWontFitException(start, end, frequency);
        }

        SchedulePeriod schedulePeriod = new SchedulePeriod(holdDate, nextDate);

        schedulePeriods.add(schedulePeriod);

        holdDate = nextDate;
        periodCount++;
        if (maxPeriods > 0 && periodCount > maxPeriods) {
            throw new ScheduleTooLongException(maxPeriods);
        }
    }

    return new Schedule(schedulePeriods);
}

From source file:com.mbc.jfin.schedule.impl.ShortFirstStubScheduleGenerator.java

License:Open Source License

public Schedule generate(LocalDate start, LocalDate end, ReadablePeriod frequency) throws ScheduleException {
    ArrayList<SchedulePeriod> schedulePeriods = new ArrayList<SchedulePeriod>();

    LocalDate holdDate = end;

    int periodCount = 1;

    while (holdDate.isAfter(start)) {
        LocalDate nextDate = end.minus(multiplyPeriod(frequency, periodCount));

        LocalDate notionalStartDate = null;
        LocalDate notionalEndDate = null;

        if (nextDate.isBefore(start)) {
            notionalStartDate = nextDate;
            notionalEndDate = holdDate;//from  www.  jav  a2  s .  c o m
            nextDate = start;
        }

        SchedulePeriod schedulePeriod = new SchedulePeriod(nextDate, holdDate, notionalStartDate,
                notionalEndDate);

        schedulePeriods.add(0, schedulePeriod);

        holdDate = nextDate;
        periodCount++;
        if (maxPeriods > 0 && periodCount > maxPeriods) {
            throw new ScheduleTooLongException(maxPeriods);
        }
    }

    return new Schedule(schedulePeriods);
}

From source file:com.mbc.jfin.schedule.impl.ShortLastStubScheduleGenerator.java

License:Open Source License

public Schedule generate(LocalDate start, LocalDate end, ReadablePeriod frequency) throws ScheduleException {
    ArrayList<SchedulePeriod> schedulePeriods = new ArrayList<SchedulePeriod>();

    LocalDate holdDate = start;/*  w ww  .ja  v a 2s.com*/

    int periodCount = 1;

    while (holdDate.isBefore(end)) {
        LocalDate nextDate = start.plus(multiplyPeriod(frequency, periodCount));

        LocalDate notionalStartDate = null;
        LocalDate notionalEndDate = null;

        if (nextDate.isAfter(end)) {
            notionalStartDate = holdDate;
            notionalEndDate = nextDate;
            nextDate = end;
        }

        SchedulePeriod schedulePeriod = new SchedulePeriod(holdDate, nextDate, notionalStartDate,
                notionalEndDate);

        schedulePeriods.add(schedulePeriod);

        holdDate = nextDate;
        periodCount++;
        if (maxPeriods > 0 && periodCount > maxPeriods) {
            throw new ScheduleTooLongException(maxPeriods);
        }
    }

    return new Schedule(schedulePeriods);
}

From source file:com.mycollab.core.utils.DateTimeUtils.java

License:Open Source License

public static LocalDate min(LocalDate... values) {
    LocalDate minVal = values[0];
    for (int i = 1; i < values.length; i++) {
        if (minVal.isAfter(values[i])) {
            minVal = values[i];//ww w  .  j a v  a  2  s .c  o  m
        }
    }
    return minVal;
}