Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
package demo.migration;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

import org.joda.time.DateTime;
import org.joda.time.LocalDate;
import org.mifos.application.admin.servicefacade.AdminServiceFacade;
import org.mifos.application.admin.servicefacade.OfficeServiceFacade;
import org.mifos.application.admin.servicefacade.PersonnelServiceFacade;
import org.mifos.application.master.business.MifosCurrency;
import org.mifos.application.meeting.util.helpers.MeetingType;
import org.mifos.application.meeting.util.helpers.RecurrenceType;
import org.mifos.application.servicefacade.GroupServiceFacade;
import org.mifos.application.servicefacade.SavingsServiceFacade;
import org.mifos.calendar.DayOfWeek;
import org.mifos.customers.util.helpers.CustomerStatus;
import org.mifos.dto.domain.AddressDto;
import org.mifos.dto.domain.ApplicableAccountFeeDto;
import org.mifos.dto.domain.GroupCreationDetail;
import org.mifos.dto.domain.MeetingDetailsDto;
import org.mifos.dto.domain.MeetingDto;
import org.mifos.dto.domain.MeetingRecurrenceDto;
import org.mifos.dto.domain.MeetingTypeDto;
import org.mifos.dto.screen.ProductDisplayDto;
import org.mifos.framework.hibernate.helper.StaticHibernateUtil;
import org.mifos.framework.util.helpers.Money;
import org.mifos.security.AuthenticationAuthorizationServiceFacade;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class KMBIMigrationDemo {

	public static void main(String[] args) {

		System.setProperty("mifos.mode", "main");
		
		String[] configLocations = new String[2];
		configLocations[0] = "classpath:/org/mifos/config/resources/applicationContext.xml";
		configLocations[1] = "classpath:META-INF/spring/QuestionnaireContext.xml";
		
		// NOTE: Questionaire is coupled with applicationContext due to
		// QuestionaireMigration effort.
		ApplicationContext applicationContext = new ClassPathXmlApplicationContext(configLocations);

		// NOTE: need to ensure hibernateUtil is initialised
		StaticHibernateUtil.initialize();
		
		// NOTE: need to set default currency
		final MifosCurrency RUPEE = new MifosCurrency((short) 2, "RUPEE", BigDecimal.valueOf(1.0), "INR");
		Money.setDefaultCurrency(RUPEE);
		
		System.out.println("fetching service");
		GroupServiceFacade groupServiceFacade = applicationContext.getBean(GroupServiceFacade.class);
		AuthenticationAuthorizationServiceFacade authenticationAuthorizationServiceFacade = applicationContext.getBean(AuthenticationAuthorizationServiceFacade.class);
		System.out.println("found");
		
		// authenticate first of all
		authenticationAuthorizationServiceFacade.reloadUserDetailsForSecurityContext("mifos");
	
		String displayName =  "VAL B-211";
		Short loanOfficerId = Short.valueOf("2"); // hardcoded id of ALDRIN HONDANTE
		Short officeId = Short.valueOf("11"); // hardcoded office id of Valenzuela
		Short customerStatus = CustomerStatus.GROUP_ACTIVE.getValue();
		boolean trained = true;
		DateTime trainedOn = new DateTime().withDate(2010, 11, 30);
		DateTime mfiJoiningDate = new DateTime().withDate(2010, 12, 06);
		DateTime activationDate = new DateTime().withDate(2010, 12, 06);
		
		GroupCreationDetail groupCreationDetail = createGroupDto(displayName,
				loanOfficerId, officeId, customerStatus, trained, trainedOn,
				mfiJoiningDate, activationDate);
		
		LocalDate meetingStartDate = new LocalDate(new DateTime().withDate(2010, 12, 06));
		Integer dayOfWeek = DayOfWeek.monday();
		Integer recurrenceTypeId = RecurrenceType.WEEKLY.getValue().intValue();
		Integer every = Integer.valueOf(1);
		
		MeetingDto meeting = createMeetingDto(meetingStartDate, dayOfWeek,
				recurrenceTypeId, every);
		
		// create group (
		groupServiceFacade.createNewGroup(groupCreationDetail, meeting);
	}

	private static MeetingDto createMeetingDto(LocalDate meetingStartDate,
			Integer dayOfWeek, Integer recurrenceTypeId, Integer every) {
		String meetingPlace = "SANTULAN MALABON CITY";
		MeetingTypeDto meetingType = new MeetingTypeDto(MeetingType.CUSTOMER_MEETING.getValue().intValue(), "group meeting", "some description of meeting");
		String recurrenceName = "weekly";
		Integer dayNumber = Integer.valueOf(0);
		Integer weekOfMonth = null;
		
		MeetingRecurrenceDto recurrenceDetails = new MeetingRecurrenceDto(dayNumber, weekOfMonth, dayOfWeek);
		MeetingDetailsDto meetingDetailsDto = new MeetingDetailsDto(recurrenceTypeId, recurrenceName, every, recurrenceDetails);
		MeetingDto meeting = new MeetingDto(meetingStartDate, meetingPlace, meetingType, meetingDetailsDto);
		return meeting;
	}

	private static GroupCreationDetail createGroupDto(String displayName,
			Short loanOfficerId, Short officeId, Short customerStatus,
			boolean trained, DateTime trainedOn, DateTime mfiJoiningDate,
			DateTime activationDate) {
		String externalId = null;
		AddressDto addressDto = null;
		List<ApplicableAccountFeeDto> feesToApply = new ArrayList<ApplicableAccountFeeDto>();
		String parentSystemId = null;
		
		GroupCreationDetail groupCreationDetail = new GroupCreationDetail(displayName, externalId, addressDto,

				loanOfficerId, feesToApply, customerStatus, 
				trained, trainedOn, parentSystemId, officeId, 
				mfiJoiningDate, activationDate);
		return groupCreationDetail;
	}
}

Results of migrating group using API (taking into account activiation/mfiJoining date in past)

Meeting is created for every monday, weekly.

In customer table, entry for group has the following details of interest:

display name

trained

trained_date

created_date

created_by

mfijoining_date

customer_activation_date

VAL B-211

YES

30-11-2010

19-01-2011

1

06-12-20101

06-12-20101

In the customer schedule table, ten customer schedules are created starting from 06-12-20101 ending 14-02-2011.

Note
titleBe Careful

At present, only ten customer schedules are created when customer is activated and each night a batch job checks to see if more should be added. If the activation date is further than 10 of meeting periods away from today then there won't be a customer schedule existing for a meeting that should occur today or in the future until a batch job runs after midnight. So we should also check to see if customer activation date is in past and if so, create customer schedules from that date up to todays date, and then also create the 10 extra customer schedules for future meeting dates.

Migrate client members of group information

...