Search in sources :

Example 1 with AggregatedGroupMapping

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

the class JpaBaseAggregationDao method getAggregations.

@Override
public final List<T> getAggregations(DateTime start, DateTime end, Set<K> keys, AggregatedGroupMapping... aggregatedGroupMappings) {
    if (!start.isBefore(end)) {
        throw new IllegalArgumentException("Start must be before End: " + start + " - " + end);
    }
    final LocalDate startDate = start.toLocalDate();
    final LocalDate endDate = end.toLocalDate();
    final TypedQuery<T> query = this.createQuery(findAggregationsByDateRangeQuery);
    query.setParameter(this.startDate, startDate);
    query.setParameter(this.startTime, start.toLocalTime());
    query.setParameter(this.endDate, endDate);
    query.setParameter(this.endTime, end.toLocalTime());
    query.setParameter(this.endPlusOneDate, endDate.plusDays(1));
    // Get the first key to use for the interval
    K key = keys.iterator().next();
    query.setParameter(this.intervalParameter, key.getInterval());
    this.bindAggregationSpecificKeyParameters(query, keys);
    final Set<AggregatedGroupMapping> groups = collectAllGroupsFromParams(keys, aggregatedGroupMappings);
    query.setParameter(this.aggregatedGroupsParameter, groups);
    return query.getResultList();
}
Also used : AggregatedGroupMapping(org.apereo.portal.events.aggr.groups.AggregatedGroupMapping) LocalDate(org.joda.time.LocalDate)

Example 2 with AggregatedGroupMapping

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

the class BaseIntervalAwarePortalEventAggregator method aggregateEvent.

@AggrEventsTransactional
@Override
public final void aggregateEvent(E e, EventSession eventSession, EventAggregationContext eventAggregationContext, Map<AggregationInterval, AggregationIntervalInfo> currentIntervals) {
    final BaseAggregationPrivateDao<T, K> aggregationDao = this.getAggregationDao();
    for (Map.Entry<AggregationInterval, AggregationIntervalInfo> intervalInfoEntry : currentIntervals.entrySet()) {
        final AggregationIntervalInfo intervalInfo = intervalInfoEntry.getValue();
        // Map used to cache aggregations locally after loading
        Map<K, T> aggregationsCache = eventAggregationContext.getAttribute(this.aggregationsCacheKey);
        if (aggregationsCache == null) {
            aggregationsCache = new HashMap<K, T>();
            eventAggregationContext.setAttribute(this.aggregationsCacheKey, aggregationsCache);
        }
        // Groups this event is for
        final Set<AggregatedGroupMapping> groupMappings = eventSession.getGroupMappings();
        // For each group get/create then update the aggregation
        for (final AggregatedGroupMapping groupMapping : groupMappings) {
            final K key = this.createAggregationKey(e, eventAggregationContext, intervalInfo, groupMapping);
            // Load the aggregation, try from the cache first
            T aggregation = aggregationsCache.get(key);
            if (aggregation == null) {
                // Then try loading from the db
                aggregation = aggregationDao.getAggregation(key);
                if (aggregation == null) {
                    // Finally create the aggregation
                    aggregation = aggregationDao.createAggregation(key);
                }
                // Store the loaded/created aggregation in the local cache
                aggregationsCache.put(key, aggregation);
            }
            // Update the aggregation with the event
            updateAggregation(e, eventAggregationContext, intervalInfo, aggregation);
        }
    }
}
Also used : AggregatedGroupMapping(org.apereo.portal.events.aggr.groups.AggregatedGroupMapping) Map(java.util.Map) HashMap(java.util.HashMap) AggrEventsTransactional(org.apereo.portal.jpa.BaseAggrEventsJpaDao.AggrEventsTransactional)

Example 3 with AggregatedGroupMapping

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

the class JpaLoginAggregationDao method createAggregationInstance.

@Override
protected LoginAggregationImpl createAggregationInstance(LoginAggregationKey key) {
    final TimeDimension timeDimension = key.getTimeDimension();
    final DateDimension dateDimension = key.getDateDimension();
    final AggregationInterval interval = key.getInterval();
    final AggregatedGroupMapping aggregatedGroup = key.getAggregatedGroup();
    return new LoginAggregationImpl(timeDimension, dateDimension, interval, aggregatedGroup);
}
Also used : AggregatedGroupMapping(org.apereo.portal.events.aggr.groups.AggregatedGroupMapping) TimeDimension(org.apereo.portal.events.aggr.TimeDimension) DateDimension(org.apereo.portal.events.aggr.DateDimension) AggregationInterval(org.apereo.portal.events.aggr.AggregationInterval)

Example 4 with AggregatedGroupMapping

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

the class JpaSearchRequestAggregationDao method getAggregations.

@Override
public final List<SearchRequestAggregationImpl> getAggregations(DateTime start, DateTime end, AggregationInterval interval, AggregatedGroupMapping aggregatedGroupMapping, AggregatedGroupMapping... aggregatedGroupMappings) {
    if (!start.isBefore(end)) {
        throw new IllegalArgumentException("Start must be before End: " + start + " - " + end);
    }
    final LocalDate startDate = start.toLocalDate();
    final LocalDate endDate = end.toLocalDate();
    final TypedQuery<SearchRequestAggregationImpl> query = this.createQuery(this.findAllSearchRequestAggregationsByDateRangeQuery);
    query.setParameter(this.startDate, startDate);
    query.setParameter(this.startTime, start.toLocalTime());
    query.setParameter(this.endDate, endDate);
    query.setParameter(this.endTime, end.toLocalTime());
    query.setParameter(this.endPlusOneDate, endDate.plusDays(1));
    query.setParameter(this.intervalParameter, interval);
    final Set<AggregatedGroupMapping> groups = ImmutableSet.<AggregatedGroupMapping>builder().add(aggregatedGroupMapping).add(aggregatedGroupMappings).build();
    query.setParameter(this.aggregatedGroupsParameter, groups);
    return query.getResultList();
}
Also used : AggregatedGroupMapping(org.apereo.portal.events.aggr.groups.AggregatedGroupMapping) LocalDate(org.joda.time.LocalDate)

Example 5 with AggregatedGroupMapping

use of org.apereo.portal.events.aggr.groups.AggregatedGroupMapping 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)

Aggregations

AggregatedGroupMapping (org.apereo.portal.events.aggr.groups.AggregatedGroupMapping)26 AggregationInterval (org.apereo.portal.events.aggr.AggregationInterval)10 IEntityGroup (org.apereo.portal.groups.IEntityGroup)8 DateTime (org.joda.time.DateTime)8 DateDimension (org.apereo.portal.events.aggr.DateDimension)6 TimeDimension (org.apereo.portal.events.aggr.TimeDimension)6 CompositeName (javax.naming.CompositeName)5 CallableWithoutResult (org.apereo.portal.concurrency.CallableWithoutResult)5 AggregatedPortletMapping (org.apereo.portal.events.aggr.portlets.AggregatedPortletMapping)5 BaseAggrEventsJpaDaoTest (org.apereo.portal.test.BaseAggrEventsJpaDaoTest)5 Test (org.junit.Test)5 HashMap (java.util.HashMap)4 Random (java.util.Random)4 TreeMap (java.util.TreeMap)4 ArrayList (java.util.ArrayList)3 SortedSet (java.util.SortedSet)3 TreeSet (java.util.TreeSet)3 MutableInt (org.apache.commons.lang.mutable.MutableInt)3 MutableObject (org.apache.commons.lang.mutable.MutableObject)3 FunctionWithoutResult (org.apereo.portal.concurrency.FunctionWithoutResult)3