Search in sources :

Example 36 with DateMidnight

use of org.joda.time.DateMidnight in project uPortal by Jasig.

the class AggregationIntervalHelperImpl method intervalsBetween.

@Override
public int intervalsBetween(AggregationInterval interval, DateTime start, DateTime end) {
    // For intervals that support native determination
    if (interval.isSupportsDetermination()) {
        return interval.determineIntervalsBetween(start, end);
    }
    if (interval == AggregationInterval.ACADEMIC_TERM) {
        // Since terms can have gaps all terms must be checked
        // Find the first term than is in the range via binary search
        final List<AcademicTermDetail> terms = getAcademicTermsAfter(start);
        // Count all the terms that are in the range, breaking the loop on the first
        // non-matching term
        int count = 0;
        for (final AcademicTermDetail academicTerm : terms) {
            final DateMidnight termStart = academicTerm.getStart();
            if (end.isAfter(termStart) && !start.isAfter(termStart)) {
                count++;
            } else if (count > 0) {
                // a term that doesn't match means no more matches will be found
                break;
            }
        }
        return count;
    }
    // Fallback for any other interval type that needs explicit iteration
    AggregationIntervalInfo nextInterval = this.getIntervalInfo(interval, start);
    int count = 0;
    while (nextInterval.getStart().isBefore(end)) {
        // Needed to make sure we don't count a partial first interval
        if (!start.isAfter(nextInterval.getStart())) {
            count++;
        }
        nextInterval = this.getIntervalInfo(interval, nextInterval.getEnd());
    }
    return count;
}
Also used : DateMidnight(org.joda.time.DateMidnight)

Example 37 with DateMidnight

use of org.joda.time.DateMidnight in project uPortal by Jasig.

the class AggregationIntervalHelperImpl method getIntervalStartDateTimesBetween.

@Override
public List<DateTime> getIntervalStartDateTimesBetween(AggregationInterval interval, DateTime start, DateTime end, int maxTimes) {
    if (interval.isSupportsDetermination()) {
        // Get the interval count for the date-time field type and verify it is in the valid
        // range.
        final int intervals = interval.determineIntervalsBetween(start, end);
        verifyIntervalCount(start, end, maxTimes, intervals);
        // Result list
        final List<DateTime> result = new ArrayList<DateTime>(intervals);
        // Check if first interval in the range
        DateTime intervalStart = interval.determineStart(start);
        if (!intervalStart.isBefore(start)) {
            result.add(intervalStart);
        }
        // Move one step forward in the range
        DateTime intervalEnd = interval.determineEnd(intervalStart);
        intervalStart = interval.determineStart(intervalEnd);
        // Step through the interval start/end values to build the full list
        while (intervalStart.isBefore(end)) {
            result.add(intervalStart);
            intervalEnd = interval.determineEnd(intervalStart);
            intervalStart = interval.determineStart(intervalEnd);
        }
        return result;
    }
    // Special handling for intervals that don't support determination
    if (interval == AggregationInterval.ACADEMIC_TERM) {
        // Since terms can have gaps all terms must be checked
        final List<AcademicTermDetail> terms = getAcademicTermsAfter(start);
        // Use all the terms that are in the range, breaking the loop on the first non-matching
        // term
        final List<DateTime> result = new ArrayList<DateTime>(terms.size());
        for (final AcademicTermDetail academicTerm : terms) {
            final DateMidnight termStart = academicTerm.getStart();
            if (end.isAfter(termStart) && !start.isAfter(termStart)) {
                result.add(start);
            } else if (!result.isEmpty()) {
                // a term that doesn't match means no more matches will be found
                break;
            }
        }
        return result;
    }
    // Fallback for any other interval type that needs explicit iteration
    AggregationIntervalInfo nextInterval = this.getIntervalInfo(interval, start);
    final List<DateTime> result = new ArrayList<DateTime>();
    while (nextInterval.getStart().isBefore(end)) {
        // Needed to make sure we don't count a partial first interval
        if (!start.isAfter(nextInterval.getStart())) {
            result.add(nextInterval.getStart());
            if (maxTimes > 0 && result.size() > maxTimes) {
                throw new IllegalArgumentException("There more than " + result.size() + " intervals between " + start + " and " + end + " which is more than the specified maximum of " + maxTimes);
            }
        }
        nextInterval = this.getIntervalInfo(interval, nextInterval.getEnd());
    }
    return result;
}
Also used : DateMidnight(org.joda.time.DateMidnight) ArrayList(java.util.ArrayList) DateTime(org.joda.time.DateTime)

Example 38 with DateMidnight

use of org.joda.time.DateMidnight in project uPortal by Jasig.

the class PortalEventDimensionPopulatorImpl method doUpdateDateDimensions.

/**
 * Populate the term/quarter data for dimensions that are missing the data
 */
final void doUpdateDateDimensions() {
    final List<DateDimension> dateDimensions = this.dateDimensionDao.getDateDimensionsWithoutTerm();
    final List<AcademicTermDetail> academicTermDetails = this.eventAggregationManagementDao.getAcademicTermDetails();
    for (final DateDimension dateDimension : dateDimensions) {
        final DateMidnight date = dateDimension.getDate();
        final AcademicTermDetail termDetail = EventDateTimeUtils.findDateRangeSorted(date, academicTermDetails);
        if (termDetail != null) {
            dateDimension.setTerm(termDetail.getTermName());
            this.dateDimensionDao.updateDateDimension(dateDimension);
        }
    }
}
Also used : DateMidnight(org.joda.time.DateMidnight)

Example 39 with DateMidnight

use of org.joda.time.DateMidnight in project uPortal by Jasig.

the class EventAggregationConfigurationImporterExporter method importData.

@Transactional("aggrEventsTransactionManager")
@Override
public void importData(ExternalEventAggregationConfiguration data) {
    // Import interval configs
    final Set<AggregatedIntervalConfig> oldAggregatedIntervalConfigs = new HashSet<AggregatedIntervalConfig>(this.aggregationManagementDao.getAggregatedIntervalConfigs());
    for (final ExternalAggregatedIntervalConfig extAggregatedIntervalConfig : data.getAggregatedIntervalConfigs()) {
        final String aggregatorTypeName = extAggregatedIntervalConfig.getAggregatorType();
        final Class<? extends IPortalEventAggregator> aggregatorType = getAggregatorType(aggregatorTypeName);
        AggregatedIntervalConfig aggregatedIntervalConfig = this.aggregationManagementDao.getAggregatedIntervalConfig(aggregatorType);
        if (aggregatedIntervalConfig == null) {
            aggregatedIntervalConfig = this.aggregationManagementDao.createAggregatedIntervalConfig(aggregatorType);
        }
        // Remove the config from the old configs set, marking it as updated
        oldAggregatedIntervalConfigs.remove(aggregatedIntervalConfig);
        // Copy over excludes
        final Set<AggregationInterval> excluded = aggregatedIntervalConfig.getExcluded();
        excluded.clear();
        for (final ExternalAggregationInterval extInterval : extAggregatedIntervalConfig.getExcludes()) {
            excluded.add(convert(extInterval));
        }
        // Copy over includes
        final Set<AggregationInterval> included = aggregatedIntervalConfig.getIncluded();
        included.clear();
        for (final ExternalAggregationInterval extInterval : extAggregatedIntervalConfig.getIncludes()) {
            included.add(convert(extInterval));
        }
        this.aggregationManagementDao.updateAggregatedIntervalConfig(aggregatedIntervalConfig);
    }
    // Delete interval configs that were not updated
    for (final AggregatedIntervalConfig aggregatedIntervalConfig : oldAggregatedIntervalConfigs) {
        this.aggregationManagementDao.deleteAggregatedIntervalConfig(aggregatedIntervalConfig);
    }
    // Import Group configs
    final Set<AggregatedGroupConfig> oldAggregatedGroupConfigs = new HashSet<AggregatedGroupConfig>(this.aggregationManagementDao.getAggregatedGroupConfigs());
    for (final ExternalAggregatedGroupConfig extAggregatedGroupConfig : data.getAggregatedGroupConfigs()) {
        final String aggregatorTypeName = extAggregatedGroupConfig.getAggregatorType();
        final Class<? extends IPortalEventAggregator> aggregatorType = getAggregatorType(aggregatorTypeName);
        AggregatedGroupConfig aggregatedGroupConfig = this.aggregationManagementDao.getAggregatedGroupConfig(aggregatorType);
        if (aggregatedGroupConfig == null) {
            aggregatedGroupConfig = this.aggregationManagementDao.createAggregatedGroupConfig(aggregatorType);
        }
        // Remove the config from the old configs set, marking it as updated
        oldAggregatedGroupConfigs.remove(aggregatedGroupConfig);
        // Copy over excludes
        final Set<AggregatedGroupMapping> excluded = aggregatedGroupConfig.getExcluded();
        excluded.clear();
        for (final ExternalAggregatedGroupMapping extGroup : extAggregatedGroupConfig.getExcludes()) {
            excluded.add(convert(extGroup));
        }
        // Copy over includes
        final Set<AggregatedGroupMapping> included = aggregatedGroupConfig.getIncluded();
        included.clear();
        for (final ExternalAggregatedGroupMapping extGroup : extAggregatedGroupConfig.getIncludes()) {
            included.add(convert(extGroup));
        }
        this.aggregationManagementDao.updateAggregatedGroupConfig(aggregatedGroupConfig);
    }
    // Delete interval configs that were not updated
    for (final AggregatedGroupConfig aggregatedGroupConfig : oldAggregatedGroupConfigs) {
        this.aggregationManagementDao.deleteAggregatedGroupConfig(aggregatedGroupConfig);
    }
    // Set quarter details if configured or set default quarters
    final List<ExternalQuarterDetail> extQuarterDetails = data.getQuarterDetails();
    final List<QuarterDetail> quarterDetails;
    if (!extQuarterDetails.isEmpty()) {
        quarterDetails = convertQuarterDetail(extQuarterDetails);
    } else {
        quarterDetails = EventDateTimeUtils.createStandardQuarters();
    }
    this.aggregationManagementDao.setQuarterDetails(quarterDetails);
    // Set academic term if configured
    final List<AcademicTermDetail> academicTerms = Lists.transform(data.getTermDetails(), new Function<ExternalTermDetail, AcademicTermDetail>() {

        @Override
        public AcademicTermDetail apply(ExternalTermDetail externalTermDetail) {
            return new AcademicTermDetailImpl(new DateMidnight(externalTermDetail.getStart()), new DateMidnight(externalTermDetail.getEnd()), externalTermDetail.getName());
        }
    });
    this.aggregationManagementDao.setAcademicTermDetails(academicTerms);
}
Also used : AggregatedGroupConfig(org.apereo.portal.events.aggr.AggregatedGroupConfig) QuarterDetail(org.apereo.portal.events.aggr.QuarterDetail) DateMidnight(org.joda.time.DateMidnight) HashSet(java.util.HashSet) AcademicTermDetailImpl(org.apereo.portal.events.aggr.dao.jpa.AcademicTermDetailImpl) AggregatedIntervalConfig(org.apereo.portal.events.aggr.AggregatedIntervalConfig) AcademicTermDetail(org.apereo.portal.events.aggr.AcademicTermDetail) AggregatedGroupMapping(org.apereo.portal.events.aggr.groups.AggregatedGroupMapping) AggregationInterval(org.apereo.portal.events.aggr.AggregationInterval) Transactional(org.springframework.transaction.annotation.Transactional)

Example 40 with DateMidnight

use of org.joda.time.DateMidnight in project uPortal by Jasig.

the class BaseStatisticsReportController method setReportFormDateRangeAndInterval.

/**
 * Set the start/end date and the interval to have selected by default if they are not already
 * set
 */
protected final void setReportFormDateRangeAndInterval(final F report) {
    // Determine default interval based on the intervals available for this aggregation
    if (report.getInterval() == null) {
        report.setInterval(AggregationInterval.DAY);
        final Set<AggregationInterval> intervals = this.getIntervals();
        for (final AggregationInterval preferredInterval : PREFERRED_INTERVAL_ORDER) {
            if (intervals.contains(preferredInterval)) {
                report.setInterval(preferredInterval);
                break;
            }
        }
    }
    // Set the report end date as today
    final DateMidnight reportEnd;
    if (report.getEnd() == null) {
        reportEnd = new DateMidnight();
        report.setEnd(reportEnd);
    } else {
        reportEnd = report.getEnd();
    }
    // Determine the best start date based on the selected interval
    if (report.getStart() == null) {
        final DateMidnight start;
        switch(report.getInterval()) {
            case MINUTE:
                {
                    start = reportEnd.minusDays(1);
                    break;
                }
            case FIVE_MINUTE:
                {
                    start = reportEnd.minusDays(2);
                    break;
                }
            case HOUR:
                {
                    start = reportEnd.minusWeeks(1);
                    break;
                }
            case DAY:
                {
                    start = reportEnd.minusMonths(1);
                    break;
                }
            case WEEK:
                {
                    start = reportEnd.minusMonths(3);
                    break;
                }
            case MONTH:
                {
                    start = reportEnd.minusYears(1);
                    break;
                }
            case ACADEMIC_TERM:
                {
                    start = reportEnd.minusYears(2);
                    break;
                }
            case CALENDAR_QUARTER:
                {
                    start = reportEnd.minusYears(2);
                    break;
                }
            case YEAR:
                {
                    start = reportEnd.minusYears(10);
                    break;
                }
            default:
                {
                    start = reportEnd.minusWeeks(1);
                }
        }
        report.setStart(start);
    }
}
Also used : DateMidnight(org.joda.time.DateMidnight) AggregationInterval(org.apereo.portal.events.aggr.AggregationInterval)

Aggregations

DateMidnight (org.joda.time.DateMidnight)70 DateTime (org.joda.time.DateTime)33 Test (org.junit.Test)27 ArrayList (java.util.ArrayList)10 Money (org.mifos.framework.util.helpers.Money)10 Ignore (org.junit.Ignore)8 MeetingBO (org.mifos.application.meeting.business.MeetingBO)8 LocalDate (org.joda.time.LocalDate)6 SavingsScheduleEntity (org.mifos.accounts.savings.business.SavingsScheduleEntity)6 Holiday (org.mifos.application.holiday.business.Holiday)6 Date (java.util.Date)5 AccountActionDateEntity (org.mifos.accounts.business.AccountActionDateEntity)5 OfficeBO (org.mifos.customers.office.business.OfficeBO)5 HolidayBuilder (org.mifos.domain.builders.HolidayBuilder)5 AggregationInterval (org.apereo.portal.events.aggr.AggregationInterval)4 AccountFeesEntity (org.mifos.accounts.business.AccountFeesEntity)4 UserContext (org.mifos.security.util.UserContext)4 DateTimeZone (org.joda.time.DateTimeZone)3 DateTimeFormatter (org.joda.time.format.DateTimeFormatter)3 Before (org.junit.Before)3