Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- new class
- package gov.bsp.lcmis.internal.utilities;
- import java.math.BigDecimal;
- import java.util.ArrayList;
- import java.util.Date;
- import java.util.List;
- import org.slf4j.Logger;
- import org.slf4j.LoggerFactory;
- import gov.bsp.lcmis.internal.domain.Rate;
- import gov.bsp.lcmis.internal.report.domain.ComputedRvcReportItem;
- import gov.bsp.lcmis.internal.report.domain.ElReleaseValue;
- import gov.bsp.lcmis.internal.report.domain.ValueTerm;
- public class ElRvcReportItemProcessor {
- private static final Logger log = LoggerFactory.getLogger(ElRvcReportItemProcessor.class);
- // private ValuetermGeneratorFactory valuetermGeneratorFactory;
- public List<ComputedRvcReportItem> fuseDateAndRate(ElReleaseValue erv) {
- if (log.isDebugEnabled()) {
- log.debug("MCI >> fuseDateAndRate");
- }
- List<ComputedRvcReportItem> computedRvcReportList = new ArrayList<>();
- setValueTerms();
- setRates();
- try {
- ComputedRvcReportItem item = null;
- for(ValueTerm term : valueTerms) {
- log.info(new StringBuilder("from date: ").append(term.getFromDate()).append(" | to date: ").append(term.getToDate()).toString());
- Date threshold = null;
- for(Rate rate : rates) {
- item = new ComputedRvcReportItem();
- item.setValueTerm(term);
- if((rate.getFromDate().compareTo(term.getFromDate())==0) || rate.getFromDate().before(term.getFromDate())) {
- if(threshold!=null) {
- if(rate.getFromDate().after(threshold)) {
- threshold = rate.getFromDate();
- item.setRepricingRate(rate.getRate());
- }
- } else {
- threshold = rate.getFromDate();
- item.setRepricingRate(rate.getRate());
- }
- }
- }
- computedRvcReportList.add(item);
- }
- } catch(Exception e) {
- log.error(new StringBuilder("Error found. ").append(e).toString());
- }
- if (log.isDebugEnabled()) {
- log.debug("MCO >> fuseDateAndRate");
- }
- return computedRvcReportList;
- }
- private DateConverter conv = new DateConverter();
- private List<ValueTerm> valueTerms;
- private void setValueTerms() {
- valueTerms = new ArrayList<>();
- ValueTerm term = new ValueTerm();
- term.setFromDate(conv.convertStringToDate("01/02/2015"));
- term.setToDate(conv.convertStringToDate("04/02/2015"));
- // term.setNumberOfDays(50);
- valueTerms.add(term);
- term = new ValueTerm();
- term.setFromDate(conv.convertStringToDate("04/07/2015"));
- term.setToDate(conv.convertStringToDate("07/16/2015"));
- // term.setNumberOfDays(56);
- valueTerms.add(term);
- term = new ValueTerm();
- term.setFromDate(conv.convertStringToDate("07/16/2015"));
- term.setToDate(conv.convertStringToDate("10/28/2015"));
- // term.setNumberOfDays(70);
- valueTerms.add(term);
- term = new ValueTerm();
- term.setFromDate(conv.convertStringToDate("10/28/2015"));
- term.setToDate(conv.convertStringToDate("12/22/2015"));
- // term.setNumberOfDays(85);
- valueTerms.add(term);
- term = new ValueTerm();
- term.setFromDate(conv.convertStringToDate("12/22/2015"));
- term.setToDate(conv.convertStringToDate("04/02/2016"));
- // term.setNumberOfDays(59);
- valueTerms.add(term);
- term = new ValueTerm();
- term.setFromDate(conv.convertStringToDate("04/07/2016"));
- term.setToDate(conv.convertStringToDate("07/16/2016"));
- // term.setNumberOfDays(22);
- valueTerms.add(term);
- term = new ValueTerm();
- term.setFromDate(conv.convertStringToDate("10/28/2016"));
- term.setToDate(conv.convertStringToDate("12/22/2016"));
- // term.setNumberOfDays(21);
- valueTerms.add(term);
- // term = new ValueTerm();
- // term.setFromDate(conv.convertStringToDate("01/02/2016"));
- // term.setToDate(conv.convertStringToDate("01/02/2016"));
- // term.setNumberOfDays(26);
- // valueTerms.add(term);
- }
- private List<Rate> rates;
- private void setRates() {
- rates = new ArrayList<>();
- Rate rate = new Rate();
- rate.setFromDate(conv.convertStringToDate("12/02/2014"));
- rate.setRate(new BigDecimal("0.314"));
- rates.add(rate);
- rate = new Rate();
- rate.setFromDate(conv.convertStringToDate("02/28/2015"));
- rate.setRate(new BigDecimal("0.34"));
- rates.add(rate);
- rate = new Rate();
- rate.setFromDate(conv.convertStringToDate("04/28/2015"));
- rate.setRate(new BigDecimal("0.38"));
- rates.add(rate);
- rate = new Rate();
- rate.setFromDate(conv.convertStringToDate("06/28/2015"));
- rate.setRate(new BigDecimal("0.42"));
- rates.add(rate);
- rate = new Rate();
- rate.setFromDate(conv.convertStringToDate("08/28/2015"));
- rate.setRate(new BigDecimal("0.51"));
- rates.add(rate);
- rate = new Rate();
- rate.setFromDate(conv.convertStringToDate("10/28/2015"));
- rate.setRate(new BigDecimal("0.24"));
- rates.add(rate);
- rate = new Rate();
- rate.setFromDate(conv.convertStringToDate("12/28/2015"));
- rate.setRate(new BigDecimal("0.19"));
- rates.add(rate);
- rate = new Rate();
- rate.setFromDate(conv.convertStringToDate("02/28/2016"));
- rate.setRate(new BigDecimal("0.34"));
- rates.add(rate);
- rate = new Rate();
- rate.setFromDate(conv.convertStringToDate("05/28/2016"));
- rate.setRate(new BigDecimal("0.33"));
- rates.add(rate);
- rate = new Rate();
- rate.setFromDate(conv.convertStringToDate("08/28/2016"));
- rate.setRate(new BigDecimal("0.317"));
- rates.add(rate);
- rate = new Rate();
- rate.setFromDate(conv.convertStringToDate("09/28/2016"));
- rate.setRate(new BigDecimal("0.714"));
- rates.add(rate);
- }
- }
- ---------------------------------------------------------------------------------------------------------------------------------------
- package gov.bsp.lcmis.internal.report.domain;
- import java.math.BigDecimal;
- import java.util.List;
- import gov.bsp.lcmis.internal.domain.Rate;
- import gov.bsp.lcmis.internal.utilities.ElRvcReportItemProcessor;
- public class ElReleaseValue extends ReleaseValue {
- private ElRvcReportItemProcessor elRvcReportItemProcessor;
- private List<ComputedRvcReportItem> computedRvcReportItems;
- private BigDecimal totalAccIntRec;
- private BigDecimal totalIntInc;
- private BigDecimal totalLiqDmgs;
- private BigDecimal totalComputedRvWithLd;
- private BigDecimal totalComputedRvWithoutLd;
- private List<Rate> rates;
- public List<ComputedRvcReportItem> getComputedRvcReportItems() {
- computedRvcReportItems = elRvcReportItemProcessor.fuseDateAndRate(this);
- System.out.print("computedRvcReportItems is null? ");
- System.out.println(computedRvcReportItems==null);
- // System.out.print("computedRvcReportItems is empty?");
- // System.out.println(computedRvcReportItems.isEmpty());
- setGrandTotal();
- return computedRvcReportItems;
- }
- // public void setComputedRvcReportItems(List<ComputedRvcReportItem> computedRvcReportItems) {
- // this.computedRvcReportItems = computedRvcReportItems;
- // }
- private void setGrandTotal() {
- this.totalAccIntRec = BigDecimal.ZERO;
- this.totalIntInc = BigDecimal.ZERO;
- this.totalLiqDmgs = BigDecimal.ZERO;
- for (ComputedRvcReportItem item : this.computedRvcReportItems) {
- // this.totalAccIntRec = totalAccIntRec.add(item.getAir() == null || item.getAir().trim().isEmpty() ?
- // BigDecimal.ZERO : new BigDecimal(item.getAir()));
- // this.totalIntInc = totalIntInc.add(item.getInterestIncome() == null || item.getInterestIncome().trim().isEmpty() ?
- // BigDecimal.ZERO : new BigDecimal(item.getInterestIncome()));
- // this.totalLiqDmgs = totalLiqDmgs.add(item.getLiquidatedDamages() == null || item.getLiquidatedDamages().trim().isEmpty() ?
- // BigDecimal.ZERO : new BigDecimal(item.getLiquidatedDamages()));
- this.totalAccIntRec = totalAccIntRec.add(item.getAir() == null ? BigDecimal.ZERO : item.getAir());
- this.totalIntInc = totalIntInc.add(item.getInterestIncome() == null ? BigDecimal.ZERO : item.getInterestIncome());
- this.totalLiqDmgs =
- totalLiqDmgs.add(item.getLiquidatedDamages() == null ? BigDecimal.ZERO : item.getLiquidatedDamages());
- }
- this.totalComputedRvWithLd = getBasis().getOutstandingPrincipal().add(totalAccIntRec).add(totalIntInc).add(totalLiqDmgs);
- this.totalComputedRvWithoutLd = getBasis().getOutstandingPrincipal().add(totalAccIntRec).add(totalIntInc);
- }
- public BigDecimal getTotalAccIntRec() {
- return totalAccIntRec;
- }
- public void setTotalAccIntRec(BigDecimal totalAccIntRec) {
- this.totalAccIntRec = totalAccIntRec;
- }
- public BigDecimal getTotalIntInc() {
- return totalIntInc;
- }
- public void setTotalIntInc(BigDecimal totalIntInc) {
- this.totalIntInc = totalIntInc;
- }
- public BigDecimal getTotalLiqDmgs() {
- return totalLiqDmgs;
- }
- public void setTotalLiqDmgs(BigDecimal totalLiqDmgs) {
- this.totalLiqDmgs = totalLiqDmgs;
- }
- public BigDecimal getTotalComputedRvWithLd() {
- return totalComputedRvWithLd;
- }
- public BigDecimal getTotalComputedRvWithoutLd() {
- return totalComputedRvWithoutLd;
- }
- public List<Rate> getRates() {
- return rates;
- }
- public void setRates(List<Rate> rates) {
- this.rates = rates;
- }
- public void setElRvcReportItemProcessor(ElRvcReportItemProcessor elRvcReportItemProcessor) {
- this.elRvcReportItemProcessor = elRvcReportItemProcessor;
- }
- }
- ---------------------------------------------------------------------------------------------------------------------------------------
- package gov.bsp.lcmis.internal.test;
- import javax.naming.NamingException;
- import org.junit.BeforeClass;
- import org.junit.Test;
- import org.junit.runner.RunWith;
- import org.slf4j.Logger;
- import org.slf4j.LoggerFactory;
- import org.springframework.context.ApplicationContext;
- import org.springframework.context.ApplicationContextAware;
- import org.springframework.jdbc.datasource.DriverManagerDataSource;
- import org.springframework.mock.jndi.SimpleNamingContextBuilder;
- import org.springframework.test.context.ActiveProfiles;
- import org.springframework.test.context.ContextConfiguration;
- import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
- import org.springframework.test.context.web.WebAppConfiguration;
- import com.ibm.icu.impl.Assert;
- import gov.bsp.lcmis.internal.fsm.dao.SearchRepoImpl;
- import gov.bsp.lcmis.internal.fsm.repo.RetrieveRvcAutocompleteResultByBankNameRepo;
- import gov.bsp.lcmis.internal.report.domain.ComputedRvcReportItem;
- import gov.bsp.lcmis.internal.report.domain.ElReleaseValue;
- import gov.bsp.lcmis.internal.utilities.DateConverter;
- @RunWith(SpringJUnit4ClassRunner.class)
- @WebAppConfiguration
- @ContextConfiguration(value = "file:src/main/webapp/WEB-INF/dispatcher-servlet.xml")
- @ActiveProfiles("test")
- public class ReusableUnitTest implements ApplicationContextAware {
- private ApplicationContext applicationContext;
- private static Logger logger = LoggerFactory.getLogger(ReusableUnitTest.class);
- /**
- * SET THE DATABASE CREDS and URL
- */
- private static String url = "jdbc:db2://localhost:50000/mydb2";
- private static String username = "db2admin";
- private static String password = "password123";
- /**
- * Note to Architect : please setup an environment dependent datasource
- * to remove the need for commenting and uncommenting the @Test method.
- */
- @BeforeClass
- public static void setupClass() {
- //create the datasource
- DriverManagerDataSource datasource = new DriverManagerDataSource(url, username, password);
- datasource.setDriverClassName("com.ibm.db2.jcc.DB2Driver");
- //bind to a jndi string
- SimpleNamingContextBuilder builder = new SimpleNamingContextBuilder();
- builder.bind("lcmisbsp", datasource);
- builder.bind("${lcmissequencebsp.jndi.name}", datasource);
- builder.bind("${cfas.jndi.name}", datasource);
- builder.bind("${ops.jndi.name}", datasource);
- try {
- builder.activate();
- } catch (IllegalStateException | NamingException e) {
- logger.error("Error setting up test class, ", e);
- }
- }
- @Test
- public void test() {
- try {
- ElReleaseValue erv = applicationContext.getBean("elReleaseValue", ElReleaseValue.class);
- Assert.assrt(erv != null);
- // DateConverter conv = applicationContext.getBean("dateConverter", DateConverter.class);
- // Assert.assrt(conv != null);
- // System.out.println(conv.convertStringToDate("01/02/2016"));
- for(ComputedRvcReportItem item : erv.getComputedRvcReportItems()) {
- System.out.println("accrued interest income: " + item.getAir());
- System.out.println("interest income: " + item.getInterestIncome());
- System.out.println("liquidated damages: " + item.getLiquidatedDamages());
- System.out.println("computation rate: " + item.getComputationRate());
- System.out.println("from date: " + item.getValueTerm().getFromDate() + " | to date: " + item.getValueTerm().getToDate());
- }
- } catch (Exception e) {
- logger.error("Error found. ", e);
- }
- }
- public void setApplicationContext(ApplicationContext applicationContext) {
- this.applicationContext = applicationContext;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement