Search in sources :

Example 1 with AcademicTermDetail

use of org.apereo.portal.events.aggr.AcademicTermDetail in project uPortal by Jasig.

the class JpaEventAggregationManagementDaoTest method testAcademicTermDetails.

@Test
public void testAcademicTermDetails() throws Exception {
    this.execute(new CallableWithoutResult() {

        @Override
        protected void callWithoutResult() {
            final List<AcademicTermDetail> academicTermDetail = eventAggregationManagementDao.getAcademicTermDetails();
            assertEquals(0, academicTermDetail.size());
            List<AcademicTermDetail> academicTermDetails = new ArrayList<AcademicTermDetail>();
            academicTermDetails.add(new AcademicTermDetailImpl(new DateMidnight(2012, 1, 1), new DateMidnight(2012, 6, 1), "Spring 2012"));
            academicTermDetails.add(new AcademicTermDetailImpl(new DateMidnight(2012, 6, 1), new DateMidnight(2012, 9, 1), "Summer 2012"));
            academicTermDetails.add(new AcademicTermDetailImpl(new DateMidnight(2012, 9, 1), new DateMidnight(2013, 1, 1), "Fall 2012"));
            eventAggregationManagementDao.setAcademicTermDetails(academicTermDetails);
        }
    });
    try {
        this.executeInTransaction(new CallableWithoutResult() {

            @Override
            protected void callWithoutResult() {
                final List<AcademicTermDetail> academicTermDetail = eventAggregationManagementDao.getAcademicTermDetails();
                assertEquals(3, academicTermDetail.size());
                academicTermDetail.add(new AcademicTermDetailImpl(new DateMidnight(2012, 1, 1), new DateMidnight(2013, 6, 1), "Spring 2013"));
                try {
                    eventAggregationManagementDao.setAcademicTermDetails(academicTermDetail);
                    fail();
                } catch (IllegalArgumentException e) {
                // expected
                }
            }
        });
        fail();
    } catch (TransactionSystemException e) {
    // Expected
    }
    this.executeInTransaction(new CallableWithoutResult() {

        @Override
        protected void callWithoutResult() {
            final List<AcademicTermDetail> academicTermDetail = eventAggregationManagementDao.getAcademicTermDetails();
            assertEquals(3, academicTermDetail.size());
            academicTermDetail.get(0).setTermName("New Term");
            academicTermDetail.remove(2);
            eventAggregationManagementDao.setAcademicTermDetails(academicTermDetail);
        }
    });
    this.execute(new CallableWithoutResult() {

        @Override
        protected void callWithoutResult() {
            final List<AcademicTermDetail> academicTermDetail = eventAggregationManagementDao.getAcademicTermDetails();
            assertEquals(2, academicTermDetail.size());
        }
    });
}
Also used : DateMidnight(org.joda.time.DateMidnight) AcademicTermDetail(org.apereo.portal.events.aggr.AcademicTermDetail) ArrayList(java.util.ArrayList) List(java.util.List) TransactionSystemException(org.springframework.transaction.TransactionSystemException) CallableWithoutResult(org.apereo.portal.concurrency.CallableWithoutResult) Test(org.junit.Test) BaseAggrEventsJpaDaoTest(org.apereo.portal.test.BaseAggrEventsJpaDaoTest)

Example 2 with AcademicTermDetail

use of org.apereo.portal.events.aggr.AcademicTermDetail 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 3 with AcademicTermDetail

use of org.apereo.portal.events.aggr.AcademicTermDetail in project uPortal by Jasig.

the class EventAggregationConfigurationImporterExporter method exportData.

/*
     * (non-Javadoc)
     * @see org.apereo.portal.io.xml.IDataImporterExporter#exportData(java.lang.String)
     */
@Override
public ExternalEventAggregationConfiguration exportData(String id) {
    final ExternalEventAggregationConfiguration externalData = new ExternalEventAggregationConfiguration();
    // Copy interval configs
    final List<ExternalAggregatedIntervalConfig> aggregatedIntervalConfigs = externalData.getAggregatedIntervalConfigs();
    for (final AggregatedIntervalConfig aggregatedIntervalConfig : this.aggregationManagementDao.getAggregatedIntervalConfigs()) {
        final ExternalAggregatedIntervalConfig externalIntervalConfig = new ExternalAggregatedIntervalConfig();
        externalIntervalConfig.setAggregatorType(aggregatedIntervalConfig.getAggregatorType().getName());
        final List<ExternalAggregationInterval> extIncludes = externalIntervalConfig.getIncludes();
        for (final AggregationInterval interval : aggregatedIntervalConfig.getIncluded()) {
            extIncludes.add(convert(interval));
        }
        Collections.sort(extIncludes, EnumNameComparator.INSTANCE);
        final List<ExternalAggregationInterval> extExcludes = externalIntervalConfig.getExcludes();
        for (final AggregationInterval interval : aggregatedIntervalConfig.getExcluded()) {
            extExcludes.add(convert(interval));
        }
        Collections.sort(extExcludes, EnumNameComparator.INSTANCE);
        aggregatedIntervalConfigs.add(externalIntervalConfig);
    }
    Collections.sort(aggregatedIntervalConfigs, ExternalAggregatedDimensionConfigComparator.INSTANCE);
    // Copy group configs
    final List<ExternalAggregatedGroupConfig> aggregatedGroupConfigs = externalData.getAggregatedGroupConfigs();
    for (final AggregatedGroupConfig aggregatedGroupConfig : this.aggregationManagementDao.getAggregatedGroupConfigs()) {
        final ExternalAggregatedGroupConfig externalGroupConfig = new ExternalAggregatedGroupConfig();
        externalGroupConfig.setAggregatorType(aggregatedGroupConfig.getAggregatorType().getName());
        final List<ExternalAggregatedGroupMapping> extIncludes = externalGroupConfig.getIncludes();
        for (final AggregatedGroupMapping Group : aggregatedGroupConfig.getIncluded()) {
            extIncludes.add(convert(Group));
        }
        Collections.sort(extIncludes, ExternalAggregatedGroupMappingComparator.INSTANCE);
        final List<ExternalAggregatedGroupMapping> extExcludes = externalGroupConfig.getExcludes();
        for (final AggregatedGroupMapping Group : aggregatedGroupConfig.getExcluded()) {
            extExcludes.add(convert(Group));
        }
        Collections.sort(extExcludes, ExternalAggregatedGroupMappingComparator.INSTANCE);
        aggregatedGroupConfigs.add(externalGroupConfig);
    }
    Collections.sort(aggregatedGroupConfigs, ExternalAggregatedDimensionConfigComparator.INSTANCE);
    // Copy term details
    final List<ExternalTermDetail> externalTermDetails = externalData.getTermDetails();
    for (final AcademicTermDetail academicTermDetail : this.aggregationManagementDao.getAcademicTermDetails()) {
        final ExternalTermDetail externalTermDetail = new ExternalTermDetail();
        externalTermDetail.setName(academicTermDetail.getTermName());
        externalTermDetail.setStart(academicTermDetail.getStart().toGregorianCalendar());
        externalTermDetail.setEnd(academicTermDetail.getEnd().toGregorianCalendar());
        externalTermDetails.add(externalTermDetail);
    }
    Collections.sort(externalTermDetails, ExternalTermDetailComparator.INSTANCE);
    // Copy quarter details
    final List<ExternalQuarterDetail> quarterDetails = externalData.getQuarterDetails();
    for (final QuarterDetail quarterDetail : this.aggregationManagementDao.getQuartersDetails()) {
        final ExternalQuarterDetail externalQuarterDetail = new ExternalQuarterDetail();
        externalQuarterDetail.setId(quarterDetail.getQuarterId());
        externalQuarterDetail.setStart(quarterDetail.getStart().toString());
        externalQuarterDetail.setEnd(quarterDetail.getEnd().toString());
        quarterDetails.add(externalQuarterDetail);
    }
    Collections.sort(quarterDetails, ExternalQuarterDetailComparator.INSTANCE);
    return externalData;
}
Also used : AggregatedIntervalConfig(org.apereo.portal.events.aggr.AggregatedIntervalConfig) AggregatedGroupConfig(org.apereo.portal.events.aggr.AggregatedGroupConfig) AcademicTermDetail(org.apereo.portal.events.aggr.AcademicTermDetail) QuarterDetail(org.apereo.portal.events.aggr.QuarterDetail) AggregatedGroupMapping(org.apereo.portal.events.aggr.groups.AggregatedGroupMapping) AggregationInterval(org.apereo.portal.events.aggr.AggregationInterval)

Example 4 with AcademicTermDetail

use of org.apereo.portal.events.aggr.AcademicTermDetail in project uPortal by Jasig.

the class JpaEventAggregationManagementDao method setAcademicTermDetails.

@Override
@AggrEventsTransactional
public void setAcademicTermDetails(List<AcademicTermDetail> newAcademicTermDetails) {
    newAcademicTermDetails = EventDateTimeUtils.validateAcademicTerms(newAcademicTermDetails);
    final TypedQuery<AcademicTermDetailImpl> query = this.createCachedQuery(this.findAllAcademicTermDetailsQuery);
    final Set<AcademicTermDetailImpl> existingAcademicTermDetails = new HashSet<AcademicTermDetailImpl>(query.getResultList());
    for (final Iterator<AcademicTermDetail> newAcademicTermDetailsItr = newAcademicTermDetails.iterator(); newAcademicTermDetailsItr.hasNext(); ) {
        final AcademicTermDetail academicTermDetail = newAcademicTermDetailsItr.next();
        // If ATD exists in both new and existing remove it from both
        if (existingAcademicTermDetails.remove(academicTermDetail)) {
            newAcademicTermDetailsItr.remove();
        }
    }
    final EntityManager entityManager = this.getEntityManager();
    // Delete all existing ATDs that were not in the new list
    for (final AcademicTermDetailImpl existingAcademicTermDetail : existingAcademicTermDetails) {
        entityManager.remove(existingAcademicTermDetail);
    }
    entityManager.flush();
    // Add all new ATDs that were not in the existing set
    for (final AcademicTermDetail newAcademicTermDetail : newAcademicTermDetails) {
        entityManager.persist(newAcademicTermDetail);
    }
}
Also used : EntityManager(javax.persistence.EntityManager) OpenEntityManager(org.apereo.portal.jpa.OpenEntityManager) AcademicTermDetail(org.apereo.portal.events.aggr.AcademicTermDetail) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Aggregations

AcademicTermDetail (org.apereo.portal.events.aggr.AcademicTermDetail)4 HashSet (java.util.HashSet)2 AggregatedGroupConfig (org.apereo.portal.events.aggr.AggregatedGroupConfig)2 AggregatedIntervalConfig (org.apereo.portal.events.aggr.AggregatedIntervalConfig)2 AggregationInterval (org.apereo.portal.events.aggr.AggregationInterval)2 QuarterDetail (org.apereo.portal.events.aggr.QuarterDetail)2 AggregatedGroupMapping (org.apereo.portal.events.aggr.groups.AggregatedGroupMapping)2 DateMidnight (org.joda.time.DateMidnight)2 ArrayList (java.util.ArrayList)1 LinkedHashSet (java.util.LinkedHashSet)1 List (java.util.List)1 EntityManager (javax.persistence.EntityManager)1 CallableWithoutResult (org.apereo.portal.concurrency.CallableWithoutResult)1 AcademicTermDetailImpl (org.apereo.portal.events.aggr.dao.jpa.AcademicTermDetailImpl)1 OpenEntityManager (org.apereo.portal.jpa.OpenEntityManager)1 BaseAggrEventsJpaDaoTest (org.apereo.portal.test.BaseAggrEventsJpaDaoTest)1 Test (org.junit.Test)1 TransactionSystemException (org.springframework.transaction.TransactionSystemException)1 Transactional (org.springframework.transaction.annotation.Transactional)1