implement jpa for likelihood write operation, set default value for registered table category, add likelihood table sql
This commit is contained in:
@@ -1 +1 @@
|
||||
ALTER TABLE `x_registered_table` ADD `category` INT NOT NULL ;
|
||||
ALTER TABLE `x_registered_table` ADD `category` INT NOT NULL DEFAULT(100);
|
||||
@@ -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 ;
|
||||
+112
@@ -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<HashMap> 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<HashMap> loanSchedule) {
|
||||
System.out.println("--------------------VERIFYING THE PRINCIPAL DUES,INTEREST DUE AND DUE DATE--------------------------");
|
||||
|
||||
assertEquals("Checking for Due Date for 1st Month", new ArrayList<Integer>(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<Integer>(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<Integer>(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<Integer>(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"));
|
||||
}
|
||||
}
|
||||
-1
@@ -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);
|
||||
}
|
||||
-23
@@ -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
|
||||
|
||||
+1
-1
@@ -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){
|
||||
|
||||
-13
@@ -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<ClientScoresOverview> scores = this.readSurveyService.retrieveClientSurveyScoreOverview(clientId);
|
||||
//
|
||||
// return this.toApiJsonClientScoreOverviewSerializer.serialize(scores);
|
||||
// }
|
||||
|
||||
@GET
|
||||
@Path("{surveyName}/{clientId}/{entryId}")
|
||||
|
||||
+5
@@ -65,4 +65,9 @@ public final class Likelihood extends AbstractPersistable<Long> {
|
||||
public Long getId() {
|
||||
return super.getId();
|
||||
}
|
||||
|
||||
public void disable()
|
||||
{
|
||||
this.enabled = LikelihoodStatus.DISABLED;
|
||||
}
|
||||
}
|
||||
|
||||
+5
-3
@@ -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<Likelihood, Long>, JpaSpecificationExecutor<Likelihood> {
|
||||
|
||||
@Query("FROM Likelihood WHERE ppi_name =:ppiName AND id !=:id")
|
||||
List<Likelihood> findByPpiNameAndLikeliHoodId(@Param("ppiName") String ppiName,@Param("id") Long likeliHoodId);
|
||||
|
||||
}
|
||||
|
||||
+8
-10
@@ -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<Likelihood> likelihoods = this.repository.findByPpiNameAndLikeliHoodId(likelihood.getPpiName(),likelihood.getId());
|
||||
|
||||
for(Likelihood aLikelihood:likelihoods)
|
||||
{
|
||||
aLikelihood.disable();
|
||||
}
|
||||
this.repository.save(likelihoods);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user