...
Code Block |
---|
package demo.migration; import java.math.BigDecimal; import java.util.List; import org.joda.time.DateTime; import org.mifos.accounts.productdefinition.util.helpers.ApplicableTo; import org.mifos.accounts.productdefinition.util.helpers.InterestCalcType; import org.mifos.accounts.productdefinition.util.helpers.SavingsType; import org.mifos.application.admin.servicefacade.AdminServiceFacade; import org.mifos.application.master.business.MifosCurrency; import org.mifos.application.master.util.helpers.PaymentTypes; import org.mifos.application.meeting.util.helpers.RecurrenceType; import org.mifos.application.servicefacade.SavingsServiceFacade; import org.mifos.dto.domain.AuditLogDto; import org.mifos.dto.domain.PrdOfferingDto; import org.mifos.dto.domain.ProductDetailsDto; import org.mifos.dto.domain.SavingsProductDto; 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 MigrationDemo { 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"); SavingsServiceFacade savingsServiceFacade = applicationContext.getBean(SavingsServiceFacade.class); AuthenticationAuthorizationServiceFacade authenticationAuthorizationServiceFacade = applicationContext.getBean(AuthenticationAuthorizationServiceFacade.class); System.out.println("found"); String name = "testSavingsProductFacade3"; String shortName = "spf3"; String description = ""; Integer category = Integer.valueOf(1); // Other DateTime startDate = new DateTime(); DateTime endDate = null; Integer applicableFor = ApplicableTo.CLIENTS.getValue().intValue(); ProductDetailsDto productDetailsDto = new ProductDetailsDto(name, shortName, description, category, startDate, endDate, applicableFor); boolean jointSavingsAccount = false; Integer groupSavingsType = null; Integer depositType = SavingsType.VOLUNTARY.getValue().intValue(); Double amountForDeposit = Double.valueOf("50.0"); Double maxWithdrawal = Double.valueOf("40.0"); BigDecimal interestRate = BigDecimal.valueOf(Double.valueOf("15.0")); Integer interestCalculationType = InterestCalcType.AVERAGE_BALANCE.getValue().intValue(); Integer interestCalculationFrequency = Integer.valueOf(1); Integer interestCalculationFrequencyPeriod = RecurrenceType.WEEKLY.getValue().intValue(); Integer interestPostingMonthlyFrequency = Integer.valueOf(3); BigDecimal minBalanceForInterestCalculation = BigDecimal.valueOf(Double.valueOf("2500.0")); Integer depositGlCode = Integer.valueOf(11); Integer interestGlCode = Integer.valueOf(12); SavingsProductDto savingsProduct = new SavingsProductDto(productDetailsDto, jointSavingsAccount, depositType, groupSavingsType, amountForDeposit, maxWithdrawal, interestRate, interestCalculationType, interestCalculationFrequency, interestCalculationFrequencyPeriod, interestPostingMonthlyFrequency, minBalanceForInterestCalculation, depositGlCode, interestGlCode); // authenticate first of all authenticationAuthorizationServiceFacade.reloadUserDetailsForSecurityContext("mifos"); // validation to do: // 1. does currency exist? PrdOfferingDto product = adminServiceFacade.createSavingsProduct(savingsProduct); List<ProductDisplayDto> allSavingsProducts = adminServiceFacade.retrieveSavingsProducts(); for (ProductDisplayDto productDisplayDto : allSavingsProducts) { System.out.println("savings product: " + productDisplayDto.getPrdOfferingName()); } } } |