diff --git a/mifosng-db/migrations/core_db/V148__x_registered_table_category.sql b/mifosng-db/migrations/core_db/V148__x_registered_table_category.sql index 88903f444..dcbac2150 100644 --- a/mifosng-db/migrations/core_db/V148__x_registered_table_category.sql +++ b/mifosng-db/migrations/core_db/V148__x_registered_table_category.sql @@ -1 +1 @@ -ALTER TABLE `x_registered_table` ADD `category` INT NOT NULL ; \ No newline at end of file +ALTER TABLE `x_registered_table` ADD `category` INT NOT NULL DEFAULT(100); \ No newline at end of file diff --git a/mifosng-db/migrations/core_db/V150_2__likelihood_table.sql b/mifosng-db/migrations/core_db/V150_2__likelihood_table.sql new file mode 100644 index 000000000..493e985c9 --- /dev/null +++ b/mifosng-db/migrations/core_db/V150_2__likelihood_table.sql @@ -0,0 +1,89 @@ +-- +--CREATE TABLE IF NOT EXISTS `ppi_scores` ( +-- `id` int(11) NOT NULL AUTO_INCREMENT, +-- `score_from` int(11) NOT NULL, +-- `score_to` int(11) NOT NULL, +-- PRIMARY KEY (`id`) +--) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ; +-- +-- +--INSERT INTO `ppi_scores` ( `score_from`, `score_to`) +--VALUES +-- (0, 4); +-- +-- INSERT INTO `ppi_scores` ( `score_from`, `score_to`) +--VALUES +-- (5, 9); +-- INSERT INTO `ppi_scores` ( `score_from`, `score_to`) +--VALUES +-- (10, 14); +-- INSERT INTO `ppi_scores` ( `score_from`, `score_to`) +--VALUES +-- (15, 19); +-- INSERT INTO `ppi_scores` ( `score_from`, `score_to`) +--VALUES +-- (20, 24); +-- INSERT INTO `ppi_scores` ( `score_from`, `score_to`) +--VALUES +-- (25,29 ); +-- INSERT INTO `ppi_scores` ( `score_from`, `score_to`) +--VALUES +-- (30, 34); +-- INSERT INTO `ppi_scores` ( `score_from`, `score_to`) +--VALUES +-- (35, 39); +-- INSERT INTO `ppi_scores` ( `score_from`, `score_to`) +--VALUES +-- (40, 44); +-- INSERT INTO `ppi_scores` ( `score_from`, `score_to`) +--VALUES +-- (45, 49); +-- INSERT INTO `ppi_scores` ( `score_from`, `score_to`) +--VALUES +-- (50, 54); +-- INSERT INTO `ppi_scores` ( `score_from`, `score_to`) +--VALUES +-- (55, 59); +-- INSERT INTO `ppi_scores` ( `score_from`, `score_to`) +--VALUES +-- (60,64); +-- INSERT INTO `ppi_scores` ( `score_from`, `score_to`) +--VALUES +-- (65, 69); +-- INSERT INTO `ppi_scores` ( `score_from`, `score_to`) +--VALUES +-- (70, 74); +-- INSERT INTO `ppi_scores` ( `score_from`, `score_to`) +--VALUES +-- (75, 79); +-- INSERT INTO `ppi_scores` ( `score_from`, `score_to`) +--VALUES +-- (80,84); +-- INSERT INTO `ppi_scores` ( `score_from`, `score_to`) +--VALUES +-- (85, 89); +-- INSERT INTO `ppi_scores` ( `score_from`, `score_to`) +--VALUES +-- (90, 94); +-- INSERT INTO `ppi_scores` ( `score_from`, `score_to`) +--VALUES +-- (95, 100); +-- +-- -- likelihood table +-- +-- CREATE TABLE IF NOT EXISTS `ppi_likelihoods` ( +-- `id` bigint(20) NOT NULL AUTO_INCREMENT, +-- `code` varchar(100) NOT NULL, +-- `name` varchar(250) NOT NULL, +-- PRIMARY KEY (`id`) +--) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ; +-- +-- +-- +-- CREATE TABLE IF NOT EXISTS `ppi_likelihoods_ppi` ( +-- `id` bigint(20) NOT NULL AUTO_INCREMENT, +-- `likelihood_id` bigint(20) NOT NULL, +-- `ppi_name` varchar(250) NOT NULL, +-- `enabled` int(11) NOT NULL DEFAULT '100', +-- PRIMARY KEY (`id`) +--) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ; \ No newline at end of file diff --git a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/SurveyIntegrationTest.java b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/SurveyIntegrationTest.java new file mode 100644 index 000000000..f813b2dd4 --- /dev/null +++ b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/SurveyIntegrationTest.java @@ -0,0 +1,112 @@ +package org.mifosplatform.integrationtests; + +import com.jayway.restassured.builder.RequestSpecBuilder; +import com.jayway.restassured.builder.ResponseSpecBuilder; +import com.jayway.restassured.http.ContentType; +import com.jayway.restassured.specification.RequestSpecification; +import com.jayway.restassured.specification.ResponseSpecification; +import org.junit.Before; +import org.junit.Test; +import org.mifosplatform.integrationtests.common.ClientHelper; +import org.mifosplatform.integrationtests.common.Utils; +import org.mifosplatform.integrationtests.common.loans.LoanApplicationTestBuilder; +import org.mifosplatform.integrationtests.common.loans.LoanProductTestBuilder; +import org.mifosplatform.integrationtests.common.loans.LoanTransactionHelper; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; + +import static org.junit.Assert.assertEquals; + +/** + * Client Loan Integration Test for checking Loan Application Repayment + * Schedule. + */ +@SuppressWarnings({ "rawtypes", "unchecked" }) +public class SurveyIntegrationTest { + + private ResponseSpecification responseSpec; + private RequestSpecification requestSpec; + private LoanTransactionHelper loanTransactionHelper; + + @Before + public void setup() { + Utils.initializeRESTAssured(); + this.requestSpec = new RequestSpecBuilder().setContentType(ContentType.JSON).build(); + this.requestSpec.header("Authorization", "Basic " + Utils.loginIntoServerAndGetBase64EncodedAuthenticationKey()); + this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200).build(); + } + + @Test + public void checkClientLoanCreateAndDisburseFlow() { + this.loanTransactionHelper = new LoanTransactionHelper(this.requestSpec, this.responseSpec); + + final Integer clientID = ClientHelper.createClient(this.requestSpec, this.responseSpec); + ClientHelper.verifyClientCreatedOnServer(this.requestSpec, this.responseSpec, clientID); + final Integer loanProductID = createLoanProduct(); + final Integer loanID = applyForLoanApplication(clientID, loanProductID); + final ArrayList loanSchedule = this.loanTransactionHelper.getLoanRepaymentSchedule(this.requestSpec, this.responseSpec, + loanID); + verifyLoanRepaymentSchedule(loanSchedule); + + } + + private Integer createLoanProduct() { + System.out.println("------------------------------CREATING NEW LOAN PRODUCT ---------------------------------------"); + final String loanProductJSON = new LoanProductTestBuilder() // + .withPrincipal("12,000.00") // + .withNumberOfRepayments("4") // + .withRepaymentAfterEvery("1") // + .withRepaymentTypeAsMonth() // + .withinterestRatePerPeriod("1") // + .withInterestRateFrequencyTypeAsMonths() // + .withAmortizationTypeAsEqualInstallments() // + .withInterestTypeAsDecliningBalance() // + .build(); + return this.loanTransactionHelper.getLoanProductId(loanProductJSON); + } + + private Integer applyForLoanApplication(final Integer clientID, final Integer loanProductID) { + System.out.println("--------------------------------APPLYING FOR LOAN APPLICATION--------------------------------"); + final String loanApplicationJSON = new LoanApplicationTestBuilder() // + .withPrincipal("12,000.00") // + .withLoanTermFrequency("4") // + .withLoanTermFrequencyAsMonths() // + .withNumberOfRepayments("4") // + .withRepaymentEveryAfter("1") // + .withRepaymentFrequencyTypeAsMonths() // + .withInterestRatePerPeriod("2") // + .withAmortizationTypeAsEqualInstallments() // + .withInterestTypeAsDecliningBalance() // + .withInterestCalculationPeriodTypeSameAsRepaymentPeriod() // + .withExpectedDisbursementDate("20 September 2011") // + .withSubmittedOnDate("20 September 2011") // + .build(clientID.toString(), loanProductID.toString()); + return this.loanTransactionHelper.getLoanId(loanApplicationJSON); + } + + private void verifyLoanRepaymentSchedule(final ArrayList loanSchedule) { + System.out.println("--------------------VERIFYING THE PRINCIPAL DUES,INTEREST DUE AND DUE DATE--------------------------"); + + assertEquals("Checking for Due Date for 1st Month", new ArrayList(Arrays.asList(2011, 10, 20)), + loanSchedule.get(1).get("dueDate")); + assertEquals("Checking for Principal Due for 1st Month", new Float("2911.49"), loanSchedule.get(1).get("principalOriginalDue")); + assertEquals("Checking for Interest Due for 1st Month", new Float("240.00"), loanSchedule.get(1).get("interestOriginalDue")); + + assertEquals("Checking for Due Date for 2nd Month", new ArrayList(Arrays.asList(2011, 11, 20)), + loanSchedule.get(2).get("dueDate")); + assertEquals("Checking for Principal Due for 2nd Month", new Float("2969.71"), loanSchedule.get(2).get("principalDue")); + assertEquals("Checking for Interest Due for 2nd Month", new Float("181.77"), loanSchedule.get(2).get("interestOriginalDue")); + + assertEquals("Checking for Due Date for 3rd Month", new ArrayList(Arrays.asList(2011, 12, 20)), + loanSchedule.get(3).get("dueDate")); + assertEquals("Checking for Principal Due for 3rd Month", new Float("3029.1"), loanSchedule.get(3).get("principalDue")); + assertEquals("Checking for Interest Due for 3rd Month", new Float("122.38"), loanSchedule.get(3).get("interestOriginalDue")); + + assertEquals("Checking for Due Date for 4th Month", new ArrayList(Arrays.asList(2012, 1, 20)), + loanSchedule.get(4).get("dueDate")); + assertEquals("Checking for Principal Due for 4th Month", new Float("3089.7"), loanSchedule.get(4).get("principalDue")); + assertEquals("Checking for Interest Due for 4th Month", new Float("61.79"), loanSchedule.get(4).get("interestOriginalDue")); + } +} \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/configuration/service/GlobalConfigurationWritePlatformService.java b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/configuration/service/GlobalConfigurationWritePlatformService.java index fea85b3dd..95fa15d0a 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/configuration/service/GlobalConfigurationWritePlatformService.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/configuration/service/GlobalConfigurationWritePlatformService.java @@ -11,6 +11,5 @@ import org.mifosplatform.infrastructure.core.data.CommandProcessingResult; public interface GlobalConfigurationWritePlatformService { CommandProcessingResult update(Long configId, JsonCommand command); - CommandProcessingResult update(String name, JsonCommand command); void addSurveyConfig(String name); } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/configuration/service/GlobalConfigurationWritePlatformServiceJpaRepositoryImpl.java b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/configuration/service/GlobalConfigurationWritePlatformServiceJpaRepositoryImpl.java index ad64270de..ca3e6b950 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/configuration/service/GlobalConfigurationWritePlatformServiceJpaRepositoryImpl.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/configuration/service/GlobalConfigurationWritePlatformServiceJpaRepositoryImpl.java @@ -66,29 +66,6 @@ public class GlobalConfigurationWritePlatformServiceJpaRepositoryImpl implements } - @Transactional - @Override - public CommandProcessingResult update(final String name, final JsonCommand command) { - - this.context.authenticatedUser(); - - try { - this.globalConfigurationDataValidator.validateForUpdate(command); - - final GlobalConfigurationProperty configItemForUpdate = this.repository.findOneByNameWithNotFoundDetection(name); - - if (configItemForUpdate.updateTo(true)) { - this.repository.save(configItemForUpdate); - } - - return new CommandProcessingResultBuilder().withCommandId(command.commandId()).withEntityId(configItemForUpdate.getId()).build(); - - } catch (final DataIntegrityViolationException dve) { - handleDataIntegrityIssues(dve); - return CommandProcessingResult.empty(); - } - - } @Transactional @Override diff --git a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/survey/api/LikelihoodApiResource.java b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/survey/api/LikelihoodApiResource.java index 00ebd9f2f..8f887b205 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/survey/api/LikelihoodApiResource.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/survey/api/LikelihoodApiResource.java @@ -75,7 +75,7 @@ public class LikelihoodApiResource { } @PUT - @Path("{likelihoodId}") + @Path("{ppiName}/{likelihoodId}") @Consumes({ MediaType.APPLICATION_JSON }) @Produces({ MediaType.APPLICATION_JSON }) public String update(@PathParam("likelihoodId") final Long likelihoodId, final String apiRequestBodyAsJson){ diff --git a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/survey/api/SurveyApiResource.java b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/survey/api/SurveyApiResource.java index 9c86440e1..c75c5eb48 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/survey/api/SurveyApiResource.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/survey/api/SurveyApiResource.java @@ -126,19 +126,6 @@ public class SurveyApiResource { return this.toApiJsonClientScoreOverviewSerializer.serialize(scores); } -// @GET -// @Path("{clientId}") -// @Consumes({ MediaType.APPLICATION_JSON }) -// @Produces({ MediaType.APPLICATION_JSON }) -// public String getAllClientSurveyOverview( @PathParam("clientId") final Long clientId) { -// -// -// this.context.authenticatedUser().validateHasReadPermission(SurveyApiConstants.SURVEY_RESOURCE_NAME); -// -// List scores = this.readSurveyService.retrieveClientSurveyScoreOverview(clientId); -// -// return this.toApiJsonClientScoreOverviewSerializer.serialize(scores); -// } @GET @Path("{surveyName}/{clientId}/{entryId}") diff --git a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/survey/domain/Likelihood.java b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/survey/domain/Likelihood.java index 0eeb646ce..f1ddb4969 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/survey/domain/Likelihood.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/survey/domain/Likelihood.java @@ -65,4 +65,9 @@ public final class Likelihood extends AbstractPersistable { public Long getId() { return super.getId(); } + + public void disable() + { + this.enabled = LikelihoodStatus.DISABLED; + } } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/survey/domain/LikelihoodRepository.java b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/survey/domain/LikelihoodRepository.java index ac0dd02fa..2e252a851 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/survey/domain/LikelihoodRepository.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/survey/domain/LikelihoodRepository.java @@ -3,13 +3,15 @@ package org.mifosplatform.infrastructure.survey.domain; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaSpecificationExecutor; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; import java.util.List; -/** - * Created by Cieyou on 3/12/14. - */ + public interface LikelihoodRepository extends JpaRepository, JpaSpecificationExecutor { + @Query("FROM Likelihood WHERE ppi_name =:ppiName AND id !=:id") + List findByPpiNameAndLikeliHoodId(@Param("ppiName") String ppiName,@Param("id") Long likeliHoodId); } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/survey/service/WriteLikelihoodServiceImpl.java b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/survey/service/WriteLikelihoodServiceImpl.java index a41fa8404..113eaff11 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/survey/service/WriteLikelihoodServiceImpl.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/survey/service/WriteLikelihoodServiceImpl.java @@ -20,6 +20,7 @@ import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.stereotype.Service; import javax.sql.DataSource; +import java.util.List; /** * Created by Cieyou on 3/12/14. @@ -60,21 +61,18 @@ public class WriteLikelihoodServiceImpl implements WriteLikelihoodService{ final Likelihood likelihood = this.repository.findOne(likelihoodId); - - String disableLikelihoodSql = "update ppi_likelihoods_ppi set enabled = "+ LikelihoodStatus.DISABLED - + " WHERE ppi_likelihoods_ppi.id IN " - + " ( SELECT t.id FROM ( SELECT * FROM ppi_likelihoods_ppi ) as t " + - " WHERE t.ppi_name = '" + likelihood.getPpiName() - + "' AND t.id !=" +likelihood.getId()+ " ) "; - - if (!likelihood.update(command).isEmpty()) { this.repository.save(likelihood); if(likelihood.isActivateCommand(command)) { - // disable the other likelihood - jdbcTemplate.execute(disableLikelihoodSql); + List likelihoods = this.repository.findByPpiNameAndLikeliHoodId(likelihood.getPpiName(),likelihood.getId()); + + for(Likelihood aLikelihood:likelihoods) + { + aLikelihood.disable(); + } + this.repository.save(likelihoods); } }