Search in sources :

Example 56 with DateMidnight

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()));
}
Also used : OfficeBuilder(org.mifos.domain.builders.OfficeBuilder) OfficeBO(org.mifos.customers.office.business.OfficeBO) DateMidnight(org.joda.time.DateMidnight) MeetingBO(org.mifos.application.meeting.business.MeetingBO) CenterBuilder(org.mifos.domain.builders.CenterBuilder) CenterBO(org.mifos.customers.center.business.CenterBO) GroupBO(org.mifos.customers.group.business.GroupBO) DateTime(org.joda.time.DateTime) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 57 with DateMidnight

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();
}
Also used : Locale(java.util.Locale) DateMidnight(org.joda.time.DateMidnight) Ignore(org.junit.Ignore)

Example 58 with DateMidnight

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());
}
Also used : DateMidnight(org.joda.time.DateMidnight) InvalidDateException(org.mifos.application.admin.servicefacade.InvalidDateException)

Example 59 with DateMidnight

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");
    }
}
Also used : DateMidnight(org.joda.time.DateMidnight) InvalidDateException(org.mifos.application.admin.servicefacade.InvalidDateException)

Example 60 with DateMidnight

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;
}
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

DateMidnight (org.joda.time.DateMidnight)70 DateTime (org.joda.time.DateTime)33 Test (org.junit.Test)27 ArrayList (java.util.ArrayList)10 Money (org.mifos.framework.util.helpers.Money)10 Ignore (org.junit.Ignore)8 MeetingBO (org.mifos.application.meeting.business.MeetingBO)8 LocalDate (org.joda.time.LocalDate)6 SavingsScheduleEntity (org.mifos.accounts.savings.business.SavingsScheduleEntity)6 Holiday (org.mifos.application.holiday.business.Holiday)6 Date (java.util.Date)5 AccountActionDateEntity (org.mifos.accounts.business.AccountActionDateEntity)5 OfficeBO (org.mifos.customers.office.business.OfficeBO)5 HolidayBuilder (org.mifos.domain.builders.HolidayBuilder)5 AggregationInterval (org.apereo.portal.events.aggr.AggregationInterval)4 AccountFeesEntity (org.mifos.accounts.business.AccountFeesEntity)4 UserContext (org.mifos.security.util.UserContext)4 DateTimeZone (org.joda.time.DateTimeZone)3 DateTimeFormatter (org.joda.time.format.DateTimeFormatter)3 Before (org.junit.Before)3