...
Tip | ||
---|---|---|
| ||
Build flexibility into mifos services and API to allow groups to be created and activated with an activation date in the past. |
Example code for using API to migrate Group (taking into account activiation/mfiJoining date in past)
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;
}
}
|
Migrate client members of group information
...