use of org.joda.time.DateMidnight in project head by mifos.
the class GroupTransferServiceIntegrationTest method transferingGroupToCenterWithDifferentMeetingDayOfWeekCausesFutureSchedulesToBeRegeneratedForGroup.
@Ignore
@Test
public void transferingGroupToCenterWithDifferentMeetingDayOfWeekCausesFutureSchedulesToBeRegeneratedForGroup() throws Exception {
// setup
OfficeBO branchOffice = anExistingBranchOffice(new OfficeBuilder().withGlobalOfficeNum("xxxx-003").withName("builder-branch-office1").withShortName("bf1").withSearchId("1.1.1.1."));
OfficeBO branchOffice2 = new OfficeBuilder().withParentOffice(branchOffice.getParentOffice()).branchOffice().withGlobalOfficeNum("xxxx-004").withName("builder-branch-office2").withShortName("bf1").withSearchId("1.1.1.2.").build();
IntegrationTestObjectMother.createOffice(branchOffice2);
DateTime todaySixWeeksAgo = new DateMidnight().toDateTime().minusWeeks(6);
MeetingBO weeklyMeeting = aWeeklyMeeting().withLocation("weeklyMeeting-sixWeeksAgo").startingFrom(todaySixWeeksAgo.toDate()).build();
IntegrationTestObjectMother.saveMeeting(weeklyMeeting);
CenterBuilder centerWithWeeklyMeeting = anActiveCenter().withName("center-with-no-children").with(weeklyMeeting).with(branchOffice).withActivationDate(todaySixWeeksAgo).withLoanOfficer(anExistingLoanOfficer());
CenterBO centerWithNoChildren = anExistingActiveCenter(centerWithWeeklyMeeting);
DateTime tomorrowTwoWeeksAgo = new DateMidnight().toDateTime().minusWeeks(2).plusDays(1);
MeetingBO differentWeeklyMeeting = aWeeklyMeeting().withLocation("weeklyMeeting-tomorrow-twoWeeksAgo").withStartDate(tomorrowTwoWeeksAgo.minusWeeks(1)).build();
IntegrationTestObjectMother.saveMeeting(differentWeeklyMeeting);
CenterBuilder centerInDifferentBranchWithDifferentMeeting = centerWithWeeklyMeeting.withName("center-with-group").with(branchOffice2).with(differentWeeklyMeeting).withActivationDate(tomorrowTwoWeeksAgo);
GroupBO groupForTransfer = anExistingGroupUnderCenterInDifferentBranchAs(centerInDifferentBranchWithDifferentMeeting);
// pre-verification
assertThat(groupForTransfer.getStatus().isGroupActive(), is(true));
TestUtils.assertThatAllCustomerSchedulesOccuringAfterCurrentInstallmentPeriodFallOnDayOfWeek(groupForTransfer, WeekDay.getJodaWeekDay(tomorrowTwoWeeksAgo.getDayOfWeek()));
// exercise test
customerService.transferGroupTo(groupForTransfer, centerWithNoChildren);
// verification
groupForTransfer = customerDao.findGroupBySystemId(groupForTransfer.getGlobalCustNum());
assertThat(groupForTransfer.getStatus().isGroupActive(), is(false));
TestUtils.assertThatAllCustomerSchedulesOccuringBeforeOrOnCurrentInstallmentPeriodRemainUnchanged(groupForTransfer, WeekDay.getJodaWeekDay(tomorrowTwoWeeksAgo.getDayOfWeek()));
//TO-FIX TestUtils.assertThatAllCustomerSchedulesOccuringAfterCurrentInstallmentPeriodFallOnDayOfWeek(groupForTransfer, WeekDay.getJodaWeekDay(todaySixWeeksAgo.getDayOfWeek()));
}
use of org.joda.time.DateMidnight in project head by mifos.
the class DateUtilsTest method xtestGetLocaleDate.
// test that getLocaleDate is parsing various localized date strings into
// java.sql.Date objects in our localization setting
@Ignore
public void xtestGetLocaleDate() throws Exception {
Locale savedLocale = Localization.getInstance().getConfiguredLocale();
long expectedDate = new DateMidnight(2005, 03, 4).getMillis();
DateUtils.refreshInternalLocale();
Assert.assertEquals(expectedDate, DateUtils.getLocaleDate(Locale.GERMANY, "04.03.2005").getTime());
DateUtils.refreshInternalLocale();
Assert.assertEquals(expectedDate, DateUtils.getLocaleDate(Locale.US, "03/04/2005").getTime());
DateUtils.refreshInternalLocale();
Assert.assertEquals(expectedDate, DateUtils.getLocaleDate(Locale.UK, "04/03/2005").getTime());
checkException(Locale.US, "04.03.2005");
DateUtils.refreshInternalLocale();
DateUtils.refreshInternalLocale();
}
use of org.joda.time.DateMidnight in project head by mifos.
the class DateUtilsTest method testGetDateFromBrowser.
public void testGetDateFromBrowser() throws Exception {
// test that day and month order is correct
long expectedDate = new DateMidnight(2005, 03, 04).getMillis();
java.sql.Date result = DateUtils.getDateAsSentFromBrowser("04/03/2005");
Assert.assertEquals(expectedDate, result.getTime());
expectedDate = new DateMidnight(2005, 04, 03).getMillis();
result = DateUtils.getDateAsSentFromBrowser("3/4/2005");
Assert.assertEquals(expectedDate, result.getTime());
// test non-lenient day/month parsing (must be in the normal range, i.e.
// 1-12 for months)
String badDate = "3/15/2006";
try {
result = DateUtils.getDateAsSentFromBrowser(badDate);
Assert.fail();
} catch (InvalidDateException e) {
Assert.assertEquals(badDate, e.getDateString());
}
// test acceptance of two-digit years
expectedDate = new DateMidnight(2005, 5, 5).getMillis();
result = DateUtils.getDateAsSentFromBrowser("5/5/05");
Assert.assertEquals(expectedDate, result.getTime());
}
use of org.joda.time.DateMidnight in project head by mifos.
the class DateUtilsTest method testParseBrowserDateFields.
public void testParseBrowserDateFields() throws Exception {
long expectedDate = new DateMidnight(2005, 03, 04).getMillis();
java.sql.Date result = DateUtils.parseBrowserDateFields("2005", "3", "4");
Assert.assertEquals(expectedDate, result.getTime());
result = DateUtils.parseBrowserDateFields("05", "03", "04");
Assert.assertEquals(expectedDate, result.getTime());
expectedDate = new DateMidnight(2005, 03, 20).getMillis();
result = DateUtils.parseBrowserDateFields("05", "03", "20");
Assert.assertEquals(expectedDate, result.getTime());
try {
DateUtils.parseBrowserDateFields("2005", "20", "1");
Assert.fail("didn't parse month correctly");
} catch (InvalidDateException e) {
Assert.assertEquals(e.getDateString(), "1/20/2005");
}
}
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;
}
Aggregations