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