use of org.joda.time.DateMidnight 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;
}
use of org.joda.time.DateMidnight 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);
}
use of org.joda.time.DateMidnight in project uPortal by Jasig.
the class EventDateTimeUtilsTest method testFindAcademicTerms.
@Test
public void testFindAcademicTerms() {
final AcademicTermDetailImpl spring2012 = new AcademicTermDetailImpl(new DateMidnight(2012, 1, 1), new DateMidnight(2012, 6, 1), "Spring 2012");
final AcademicTermDetailImpl summer2012 = new AcademicTermDetailImpl(new DateMidnight(2012, 6, 1), new DateMidnight(2012, 9, 1), "Summer 2012");
final AcademicTermDetailImpl fall2012 = new AcademicTermDetailImpl(new DateMidnight(2012, 9, 1), new DateMidnight(2013, 1, 1), "Fall 2012");
List<AcademicTermDetailImpl> terms = Arrays.asList(spring2012, summer2012, fall2012);
AcademicTermDetailImpl result;
Collections.sort(terms);
result = EventDateTimeUtils.findDateRangeSorted(new DateMidnight(2011, 3, 1), terms);
assertNull(result);
result = EventDateTimeUtils.findDateRangeSorted(new DateMidnight(2012, 3, 1), terms);
assertEquals(spring2012, result);
result = EventDateTimeUtils.findDateRangeSorted(new DateMidnight(2012, 7, 1), terms);
assertEquals(summer2012, result);
result = EventDateTimeUtils.findDateRangeSorted(new DateMidnight(2012, 12, 31), terms);
assertEquals(fall2012, result);
}
use of org.joda.time.DateMidnight in project uPortal by Jasig.
the class JpaDateTimeDimensionDaoTest method testGetMinMaxDateDimension.
@Test
public void testGetMinMaxDateDimension() {
this.execute(new CallableWithoutResult() {
@Override
protected void callWithoutResult() {
final DateDimension newestDateDimension = dateDimensionDao.getNewestDateDimension();
assertNull(newestDateDimension);
}
});
this.execute(new CallableWithoutResult() {
@Override
protected void callWithoutResult() {
final List<DateDimension> dateDimensions = dateDimensionDao.getDateDimensions();
assertEquals(Collections.EMPTY_LIST, dateDimensions);
}
});
this.executeInTransaction(new CallableWithoutResult() {
@Override
protected void callWithoutResult() {
DateMidnight date = new DateMidnight(2012, 1, 1);
for (int i = 0; i < 7; i++) {
dateDimensionDao.createDateDimension(date, 0, null);
date = date.plusDays(1);
}
}
});
this.execute(new CallableWithoutResult() {
@Override
protected void callWithoutResult() {
DateMidnight date = new DateMidnight(2012, 1, 1);
final DateDimension dateDimension = dateDimensionDao.getDateDimensionByDate(date);
assertNotNull(dateDimension);
}
});
this.execute(new CallableWithoutResult() {
@Override
protected void callWithoutResult() {
final List<DateDimension> dateDimensions = dateDimensionDao.getDateDimensions();
assertEquals(7, dateDimensions.size());
}
});
this.execute(new CallableWithoutResult() {
@Override
protected void callWithoutResult() {
final DateMidnight start = new DateMidnight(2012, 1, 2);
final DateMidnight end = new DateMidnight(2012, 1, 6);
final List<DateDimension> dateDimensions = dateDimensionDao.getDateDimensionsBetween(start, end);
assertEquals(4, dateDimensions.size());
}
});
this.execute(new CallableWithoutResult() {
@Override
protected void callWithoutResult() {
final DateDimension oldestDateDimension = dateDimensionDao.getOldestDateDimension();
assertEquals(2012, oldestDateDimension.getYear());
assertEquals(1, oldestDateDimension.getMonth());
assertEquals(1, oldestDateDimension.getDay());
}
});
this.execute(new CallableWithoutResult() {
@Override
protected void callWithoutResult() {
final DateDimension newestDateDimension = dateDimensionDao.getNewestDateDimension();
assertEquals(2012, newestDateDimension.getYear());
assertEquals(1, newestDateDimension.getMonth());
assertEquals(7, newestDateDimension.getDay());
}
});
}
use of org.joda.time.DateMidnight in project uPortal by Jasig.
the class DateDimensionImpl method getDate.
@Override
public DateMidnight getDate() {
DateMidnight dm = this.dateMidnight;
if (dm == null) {
dm = this.date.toDateMidnight();
this.dateMidnight = dm;
}
return dm;
}
Aggregations