...
Migrate client members of group information
Note | ||
---|---|---|
| ||
Manually migrating client data cannot be done correctly without modifying the system date where the application is running or by somehow modifying the data directly on the database after the group has being created and activated. |
Tip | ||
---|---|---|
| ||
Build flexibility into mifos services and API to allow groups to be created and activated with an activation date in the past. |
Example of migrating client information
Code Block |
---|
package demo.migration;
import java.io.InputStream;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
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.ClientServiceFacade;
import org.mifos.application.servicefacade.GroupServiceFacade;
import org.mifos.application.servicefacade.SavingsServiceFacade;
import org.mifos.application.util.helpers.YesNoFlag;
import org.mifos.calendar.DayOfWeek;
import org.mifos.customers.client.business.NameType;
import org.mifos.customers.util.helpers.CustomerStatus;
import org.mifos.dto.domain.AddressDto;
import org.mifos.dto.domain.ApplicableAccountFeeDto;
import org.mifos.dto.domain.ClientCreationDetail;
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.domain.SavingsDetailDto;
import org.mifos.dto.screen.ClientFamilyDetailDto;
import org.mifos.dto.screen.ClientNameDetailDto;
import org.mifos.dto.screen.ClientPersonalDetailDto;
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");
ClientServiceFacade clientServiceFacade = applicationContext.getBean(ClientServiceFacade.class);
AuthenticationAuthorizationServiceFacade authenticationAuthorizationServiceFacade = applicationContext.getBean(AuthenticationAuthorizationServiceFacade.class);
System.out.println("found");
// authenticate first of all
authenticationAuthorizationServiceFacade.reloadUserDetailsForSecurityContext("mifos");
List<Short> selectedSavingProducts = new ArrayList<Short>();
String clientName = "CARMELITA DAGALLA ALCARAZ";
Short clientStatus = CustomerStatus.CLIENT_ACTIVE.getValue();
boolean trained = true;
Date trainedOn = new DateTime().withDate(2010, 11, 30).toDate();
Date mfiJoiningDate = new DateTime().withDate(2010, 12, 06).toDate();
LocalDate activationDate = new LocalDate(mfiJoiningDate);
String externalId = null;
AddressDto address = new AddressDto("48M. SANTOS ST. SANTULAN", null, null, "MALABON CITY", null, "PHILIPPINES", "1470", null);
Short formedBy = null;
Date dateOfBirth = new DateTime().withDate(1954, 5, 14).toDate();
String governmentId = null;
Short groupFlag = YesNoFlag.YES.getValue();
Integer salutation = Integer.valueOf(2001); //Mrs. see custom reference-data for salutations
String firstName = "CARMELITA";
String middleName = "DAGALLA";
String lastName = "ALCARAZ";
String secondLastName = null;
ClientNameDetailDto clientNameDetailDto = new ClientNameDetailDto(NameType.CLIENT.getValue(), salutation, firstName, middleName, lastName, secondLastName);
Integer ethinicity = Integer.valueOf(19); // no
Integer citizenship = Integer.valueOf(2006); // roman catholic
Integer handicapped = null;
Integer businessActivities = Integer.valueOf(2029); // sari sari
Integer maritalStatus = Integer.valueOf(2005); // widow
Integer educationLevel = Integer.valueOf(2018); // high school
Short numChildren = Short.valueOf("1");
Short gender = Short.valueOf("50"); // female
Short povertyStatus = null;
ClientPersonalDetailDto clientPersonalDetailDto = new ClientPersonalDetailDto(ethinicity, citizenship, handicapped,
businessActivities, maritalStatus, educationLevel, numChildren, gender, povertyStatus);
ClientNameDetailDto spouseFatherName = null;
InputStream picture = null;
List<ApplicableAccountFeeDto> feesToApply = new ArrayList<ApplicableAccountFeeDto>();
String parentGroupId = "5";
List<ClientNameDetailDto> familyNames = new ArrayList<ClientNameDetailDto>();
List<ClientFamilyDetailDto> familyDetails = new ArrayList<ClientFamilyDetailDto>();
Short loanOfficerId = null; // 2 inherit from parent
Short officeId = null; // 11 inherit from parent
ClientCreationDetail client = new ClientCreationDetail(selectedSavingProducts, clientName, clientStatus, mfiJoiningDate, externalId,
address, formedBy, dateOfBirth, governmentId, trained, trainedOn, groupFlag,
clientNameDetailDto, clientPersonalDetailDto, spouseFatherName, picture,
feesToApply, parentGroupId, familyNames, familyDetails, loanOfficerId, officeId, activationDate);
MeetingDto meeting = null; // will inherit meeting of parent group.
List<SavingsDetailDto> savings = new ArrayList<SavingsDetailDto>();
clientServiceFacade.createNewClient(client, meeting, savings);
}
}
|
Results of migrating client using API (taking into account activiation/mfiJoining date in past)
Meeting is created for every monday, weekly.
In customer table, entry for client has the following details of interest:
display name | trained | trained_date | created_date | created_by | mfijoining_date | customer_activation_date |
---|---|---|---|---|---|---|
CARMELITA DAGALLA ALCARAZ | YES | 30-11-2010 | 19-01-2011 | 1 | 06-Dec-2010 | 06-Dec-2010 |
In the customer schedule table, ten customer schedules are created starting from 06-Dec-2010 ending 14-Feb-2011.
Note | ||
---|---|---|
| ||
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 Loans using Opening Balance Approach
...