Search in sources :

Example 1 with AcademicTermDetailImpl

use of org.apereo.portal.events.aggr.dao.jpa.AcademicTermDetailImpl 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>() {

        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 2 with AcademicTermDetailImpl

use of org.apereo.portal.events.aggr.dao.jpa.AcademicTermDetailImpl in project uPortal by Jasig.

the class AggregationIntervalHelperImpl method getAcademicTermsAfter.

/**
     * Return a sorted list of AcademicTermDetail objects where the the first element of the list
     * where the first element is the first term that starts after the specified start DateTime.
     */
protected List<AcademicTermDetail> getAcademicTermsAfter(DateTime start) {
    final List<AcademicTermDetail> terms = this.eventAggregationManagementDao.getAcademicTermDetails();
    final int index = Collections.binarySearch(terms, new AcademicTermDetailImpl(start.toDateMidnight(), start.plusDays(1).toDateMidnight(), ""));
    if (index > 0) {
        return terms.subList(index, terms.size());
    } else if (index < 0) {
        return terms.subList(-(index + 1), terms.size());
    }
    return terms;
}
Also used : AcademicTermDetailImpl(org.apereo.portal.events.aggr.dao.jpa.AcademicTermDetailImpl)

Example 3 with AcademicTermDetailImpl

use of org.apereo.portal.events.aggr.dao.jpa.AcademicTermDetailImpl in project uPortal by Jasig.

the class AggregationIntervalHelperImplTest method setUp.

@Before
public void setUp() {
    when(eventAggregationManagementDao.getQuartersDetails()).thenReturn(EventDateTimeUtils.createStandardQuarters());
    final List<AcademicTermDetail> terms = ImmutableList.<AcademicTermDetail>of(new AcademicTermDetailImpl(new DateMidnight(2012, 1, 12), new DateMidnight(2012, 4, 1), "spring 2"), new AcademicTermDetailImpl(new DateMidnight(2012, 4, 1), new DateMidnight(2012, 7, 1), "summer 2"), new AcademicTermDetailImpl(new DateMidnight(2012, 7, 1), new DateMidnight(2012, 12, 15), "fall 2"), new AcademicTermDetailImpl(new DateMidnight(2012, 12, 15), new DateMidnight(2013, 1, 14), "winter 2"), new AcademicTermDetailImpl(new DateMidnight(2015, 12, 15), new DateMidnight(2016, 1, 14), "winter 5"));
    when(eventAggregationManagementDao.getAcademicTermDetails()).thenReturn(terms);
}
Also used : AcademicTermDetailImpl(org.apereo.portal.events.aggr.dao.jpa.AcademicTermDetailImpl) DateMidnight(org.joda.time.DateMidnight) Before(org.junit.Before)

Aggregations

AcademicTermDetailImpl (org.apereo.portal.events.aggr.dao.jpa.AcademicTermDetailImpl)3 DateMidnight (org.joda.time.DateMidnight)2 HashSet (java.util.HashSet)1 AcademicTermDetail (org.apereo.portal.events.aggr.AcademicTermDetail)1 AggregatedGroupConfig (org.apereo.portal.events.aggr.AggregatedGroupConfig)1 AggregatedIntervalConfig (org.apereo.portal.events.aggr.AggregatedIntervalConfig)1 AggregationInterval (org.apereo.portal.events.aggr.AggregationInterval)1 QuarterDetail (org.apereo.portal.events.aggr.QuarterDetail)1 AggregatedGroupMapping (org.apereo.portal.events.aggr.groups.AggregatedGroupMapping)1 Before (org.junit.Before)1 Transactional (org.springframework.transaction.annotation.Transactional)1