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;
}
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;
}
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);
}
}
}
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);
}
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);
}
}
Aggregations