Example of using application services outside of mifos project.
As an example, here is a maven project that uses mifos jars, creates application context so it may invoke java based application services.
Create maven java project with the following pom.xml files
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>org.mifos</groupId> <artifactId>migration-demo</artifactId> <packaging>jar</packaging> <version>1.0-SNAPSHOT</version> <name>migration-demo</name> <url>http://maven.apache.org</url> <properties> <jdk.version>1.6</jdk.version> </properties> <dependencies> <dependency> <groupId>org.mifos</groupId> <artifactId>mifos-serviceInterfaces</artifactId> <version>1.8-SNAPSHOT</version> </dependency> <dependency> <groupId>org.mifos</groupId> <artifactId>mifos-questionnaire</artifactId> <version>1.8-SNAPSHOT</version> </dependency> <dependency> <groupId>org.mifos</groupId> <artifactId>mifos-appdomain</artifactId> <version>1.8-SNAPSHOT</version> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <configuration> <debug>true</debug> <source>1.6</source> <target>1.6</target> </configuration> </plugin> </plugins> </build> </project>
Main Java class that showing simmple retrieval of Audit logs for a savings account
package demo.migration; import java.util.List; import org.mifos.application.servicefacade.SavingsServiceFacade; import org.mifos.dto.domain.AuditLogDto; import org.mifos.framework.hibernate.helper.StaticHibernateUtil; 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(); System.out.println("fetching service"); SavingsServiceFacade savingsServiceFacade = applicationContext.getBean(SavingsServiceFacade.class); System.out.println("found"); // use a savings account id that exists in your 'mifos' schema and one that has 'audit' or 'change logs' would be best List<AuditLogDto> auditlogs = savingsServiceFacade.retrieveSavingsAccountAuditLogs(Long.valueOf("16")); System.out.println("printing logs..."); for (AuditLogDto auditLogDto : auditlogs) { System.out.println(auditLogDto.getDate()); System.out.println(auditLogDto.getField()); System.out.println(auditLogDto.getUser()); } } }
Main Java class showing example of creating a Savings Product
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()); } } }