Search in sources :

Example 1 with ConcurrentUserAggregation

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

the class ActivityController method buildPortalActivity.

private PortalActivity buildPortalActivity(PortletRequest request, int timeframe) {
    PortletPreferences prefs = request.getPreferences();
    DateTime begin, end;
    final AggregationInterval interval;
    final List<PortalGroupActivity> groupActivities = new ArrayList<PortalGroupActivity>();
    switch(timeframe) {
        case NOW:
            {
                end = new DateTime();
                begin = end.minusHours(1);
                interval = AggregationInterval.FIVE_MINUTE;
                break;
            }
        case TODAY:
            {
                begin = new DateMidnight().toDateTime();
                end = begin.plusDays(1);
                interval = AggregationInterval.DAY;
                break;
            }
        case YESTERDAY:
            {
                end = new DateMidnight().toDateTime().minusSeconds(1);
                begin = end.minusDays(1);
                interval = AggregationInterval.DAY;
                break;
            }
        default:
            {
                end = new DateTime();
                begin = end.minusHours(1);
                interval = AggregationInterval.HOUR;
                break;
            }
    }
    String masterGroup = prefs.getValue(PREFERENCE_MASTER_GROUP, DEFAULT_PREFERENCE_MASTER_GROUP);
    List<String> displayGroups = Arrays.asList(prefs.getValues(PREFERENCE_DISPLAY_GROUPS, DEFAULT_PREFERENCE_DISPLAY_GROUPS));
    boolean displayOther = Boolean.valueOf(prefs.getValue(PREFERENCE_DISPLAY_OTHER, DEFAULT_PREFERENCE_DISPLAY_OTHER));
    int masterTotal = 0;
    int absTotal = 0;
    int subTotal = 0;
    switch(timeframe) {
        case NOW:
            for (AggregatedGroupMapping group : concurrentUserAggregationDao.getAggregatedGroupMappings()) {
                ConcurrentUserAggregationKey key = new ConcurrentUserAggregationKeyImpl(interval, group);
                final List<ConcurrentUserAggregation> aggregations = concurrentUserAggregationDao.getAggregations(begin, end, key);
                // NB:  We only care about the most recent entry (??)
                if (aggregations.size() != 0) {
                    final ConcurrentUserAggregation aggregation = aggregations.get(0);
                    int groupTotal = aggregation.getConcurrentUsers();
                    absTotal += aggregation.getConcurrentUsers();
                    if (group.getGroupName().equalsIgnoreCase(masterGroup)) {
                        masterTotal = groupTotal;
                    } else {
                        subTotal += groupTotal;
                    }
                    if (!group.getGroupName().equals(masterGroup)) {
                        if (displayGroups.isEmpty() || displayGroups.contains(group.getGroupName())) {
                            final PortalGroupActivity groupActivity = new PortalGroupActivity(group.getGroupName(), groupTotal);
                            groupActivities.add(groupActivity);
                        }
                    }
                }
            }
            break;
        default:
            String uniqueLoginsPref = prefs.getValue(PREFERENCE_UNIQUE_LOGINS, DEFAULT_PREFERENCE_UNIQUE_LOGINS);
            Boolean uniqueLogins = Boolean.valueOf(uniqueLoginsPref);
            for (AggregatedGroupMapping group : loginAggregationDao.getAggregatedGroupMappings()) {
                final LoginAggregationKey key = new LoginAggregationKeyImpl(interval, group);
                final List<LoginAggregation> aggregations = loginAggregationDao.getAggregations(begin, end, key);
                // NB:  We only care about the most recent entry (??)
                if (aggregations.size() != 0) {
                    final LoginAggregation aggregation = aggregations.get(0);
                    int groupTotal = getAggregationLoginCount(aggregation, uniqueLogins);
                    absTotal += groupTotal;
                    if (group.getGroupName().equalsIgnoreCase(masterGroup)) {
                        masterTotal = groupTotal;
                    } else {
                        subTotal += groupTotal;
                    }
                    if (!group.getGroupName().equals(masterGroup)) {
                        if (displayGroups.isEmpty() || displayGroups.contains(group.getGroupName())) {
                            PortalGroupActivity groupActivity = new PortalGroupActivity(group.getGroupName(), groupTotal);
                            groupActivities.add(groupActivity);
                        }
                    }
                }
            }
            break;
    }
    if (displayOther) {
        int otherTotal = masterTotal - subTotal;
        if (otherTotal > 0) {
            PortalGroupActivity otherGroup = new PortalGroupActivity("Other", otherTotal);
            groupActivities.add(otherGroup);
        }
    }
    Collections.sort(groupActivities);
    Collections.reverse(groupActivities);
    int total = masterTotal > 0 ? masterTotal : absTotal;
    final PortalActivity activity = new PortalActivity(total, groupActivities);
    return activity;
}
Also used : LoginAggregationKey(org.apereo.portal.events.aggr.login.LoginAggregationKey) ConcurrentUserAggregationKey(org.apereo.portal.events.aggr.concuser.ConcurrentUserAggregationKey) ArrayList(java.util.ArrayList) LoginAggregationKeyImpl(org.apereo.portal.events.aggr.login.LoginAggregationKeyImpl) LoginAggregation(org.apereo.portal.events.aggr.login.LoginAggregation) DateTime(org.joda.time.DateTime) ConcurrentUserAggregationKeyImpl(org.apereo.portal.events.aggr.concuser.ConcurrentUserAggregationKeyImpl) ConcurrentUserAggregation(org.apereo.portal.events.aggr.concuser.ConcurrentUserAggregation) AggregatedGroupMapping(org.apereo.portal.events.aggr.groups.AggregatedGroupMapping) DateMidnight(org.joda.time.DateMidnight) PortletPreferences(javax.portlet.PortletPreferences) AggregationInterval(org.apereo.portal.events.aggr.AggregationInterval)

Aggregations

ArrayList (java.util.ArrayList)1 PortletPreferences (javax.portlet.PortletPreferences)1 AggregationInterval (org.apereo.portal.events.aggr.AggregationInterval)1 ConcurrentUserAggregation (org.apereo.portal.events.aggr.concuser.ConcurrentUserAggregation)1 ConcurrentUserAggregationKey (org.apereo.portal.events.aggr.concuser.ConcurrentUserAggregationKey)1 ConcurrentUserAggregationKeyImpl (org.apereo.portal.events.aggr.concuser.ConcurrentUserAggregationKeyImpl)1 AggregatedGroupMapping (org.apereo.portal.events.aggr.groups.AggregatedGroupMapping)1 LoginAggregation (org.apereo.portal.events.aggr.login.LoginAggregation)1 LoginAggregationKey (org.apereo.portal.events.aggr.login.LoginAggregationKey)1 LoginAggregationKeyImpl (org.apereo.portal.events.aggr.login.LoginAggregationKeyImpl)1 DateMidnight (org.joda.time.DateMidnight)1 DateTime (org.joda.time.DateTime)1