Advertisement
Guest User

Untitled

a guest
Mar 15th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.43 KB | None | 0 0
  1. new class
  2.  
  3. package gov.bsp.lcmis.internal.utilities;
  4.  
  5. import java.math.BigDecimal;
  6. import java.util.ArrayList;
  7. import java.util.Date;
  8. import java.util.List;
  9.  
  10. import org.slf4j.Logger;
  11. import org.slf4j.LoggerFactory;
  12.  
  13. import gov.bsp.lcmis.internal.domain.Rate;
  14. import gov.bsp.lcmis.internal.report.domain.ComputedRvcReportItem;
  15. import gov.bsp.lcmis.internal.report.domain.ElReleaseValue;
  16. import gov.bsp.lcmis.internal.report.domain.ValueTerm;
  17.  
  18. public class ElRvcReportItemProcessor {
  19.  
  20. private static final Logger log = LoggerFactory.getLogger(ElRvcReportItemProcessor.class);
  21.  
  22. // private ValuetermGeneratorFactory valuetermGeneratorFactory;
  23.  
  24. public List<ComputedRvcReportItem> fuseDateAndRate(ElReleaseValue erv) {
  25. if (log.isDebugEnabled()) {
  26. log.debug("MCI >> fuseDateAndRate");
  27. }
  28. List<ComputedRvcReportItem> computedRvcReportList = new ArrayList<>();
  29. setValueTerms();
  30. setRates();
  31. try {
  32. ComputedRvcReportItem item = null;
  33. for(ValueTerm term : valueTerms) {
  34. log.info(new StringBuilder("from date: ").append(term.getFromDate()).append(" | to date: ").append(term.getToDate()).toString());
  35. Date threshold = null;
  36. for(Rate rate : rates) {
  37. item = new ComputedRvcReportItem();
  38. item.setValueTerm(term);
  39. if((rate.getFromDate().compareTo(term.getFromDate())==0) || rate.getFromDate().before(term.getFromDate())) {
  40. if(threshold!=null) {
  41. if(rate.getFromDate().after(threshold)) {
  42. threshold = rate.getFromDate();
  43. item.setRepricingRate(rate.getRate());
  44. }
  45. } else {
  46. threshold = rate.getFromDate();
  47. item.setRepricingRate(rate.getRate());
  48. }
  49. }
  50. }
  51. computedRvcReportList.add(item);
  52. }
  53. } catch(Exception e) {
  54. log.error(new StringBuilder("Error found. ").append(e).toString());
  55. }
  56. if (log.isDebugEnabled()) {
  57. log.debug("MCO >> fuseDateAndRate");
  58. }
  59. return computedRvcReportList;
  60. }
  61.  
  62. private DateConverter conv = new DateConverter();
  63.  
  64. private List<ValueTerm> valueTerms;
  65.  
  66. private void setValueTerms() {
  67. valueTerms = new ArrayList<>();
  68. ValueTerm term = new ValueTerm();
  69. term.setFromDate(conv.convertStringToDate("01/02/2015"));
  70. term.setToDate(conv.convertStringToDate("04/02/2015"));
  71. // term.setNumberOfDays(50);
  72. valueTerms.add(term);
  73.  
  74. term = new ValueTerm();
  75. term.setFromDate(conv.convertStringToDate("04/07/2015"));
  76. term.setToDate(conv.convertStringToDate("07/16/2015"));
  77. // term.setNumberOfDays(56);
  78. valueTerms.add(term);
  79.  
  80. term = new ValueTerm();
  81. term.setFromDate(conv.convertStringToDate("07/16/2015"));
  82. term.setToDate(conv.convertStringToDate("10/28/2015"));
  83. // term.setNumberOfDays(70);
  84. valueTerms.add(term);
  85.  
  86. term = new ValueTerm();
  87. term.setFromDate(conv.convertStringToDate("10/28/2015"));
  88. term.setToDate(conv.convertStringToDate("12/22/2015"));
  89. // term.setNumberOfDays(85);
  90. valueTerms.add(term);
  91.  
  92. term = new ValueTerm();
  93. term.setFromDate(conv.convertStringToDate("12/22/2015"));
  94. term.setToDate(conv.convertStringToDate("04/02/2016"));
  95. // term.setNumberOfDays(59);
  96. valueTerms.add(term);
  97.  
  98. term = new ValueTerm();
  99. term.setFromDate(conv.convertStringToDate("04/07/2016"));
  100. term.setToDate(conv.convertStringToDate("07/16/2016"));
  101. // term.setNumberOfDays(22);
  102. valueTerms.add(term);
  103.  
  104. term = new ValueTerm();
  105. term.setFromDate(conv.convertStringToDate("10/28/2016"));
  106. term.setToDate(conv.convertStringToDate("12/22/2016"));
  107. // term.setNumberOfDays(21);
  108. valueTerms.add(term);
  109.  
  110. // term = new ValueTerm();
  111. // term.setFromDate(conv.convertStringToDate("01/02/2016"));
  112. // term.setToDate(conv.convertStringToDate("01/02/2016"));
  113. // term.setNumberOfDays(26);
  114. // valueTerms.add(term);
  115.  
  116. }
  117.  
  118. private List<Rate> rates;
  119.  
  120. private void setRates() {
  121. rates = new ArrayList<>();
  122. Rate rate = new Rate();
  123. rate.setFromDate(conv.convertStringToDate("12/02/2014"));
  124. rate.setRate(new BigDecimal("0.314"));
  125. rates.add(rate);
  126.  
  127. rate = new Rate();
  128. rate.setFromDate(conv.convertStringToDate("02/28/2015"));
  129. rate.setRate(new BigDecimal("0.34"));
  130. rates.add(rate);
  131.  
  132. rate = new Rate();
  133. rate.setFromDate(conv.convertStringToDate("04/28/2015"));
  134. rate.setRate(new BigDecimal("0.38"));
  135. rates.add(rate);
  136.  
  137. rate = new Rate();
  138. rate.setFromDate(conv.convertStringToDate("06/28/2015"));
  139. rate.setRate(new BigDecimal("0.42"));
  140. rates.add(rate);
  141.  
  142. rate = new Rate();
  143. rate.setFromDate(conv.convertStringToDate("08/28/2015"));
  144. rate.setRate(new BigDecimal("0.51"));
  145. rates.add(rate);
  146.  
  147. rate = new Rate();
  148. rate.setFromDate(conv.convertStringToDate("10/28/2015"));
  149. rate.setRate(new BigDecimal("0.24"));
  150. rates.add(rate);
  151.  
  152. rate = new Rate();
  153. rate.setFromDate(conv.convertStringToDate("12/28/2015"));
  154. rate.setRate(new BigDecimal("0.19"));
  155. rates.add(rate);
  156.  
  157. rate = new Rate();
  158. rate.setFromDate(conv.convertStringToDate("02/28/2016"));
  159. rate.setRate(new BigDecimal("0.34"));
  160. rates.add(rate);
  161.  
  162. rate = new Rate();
  163. rate.setFromDate(conv.convertStringToDate("05/28/2016"));
  164. rate.setRate(new BigDecimal("0.33"));
  165. rates.add(rate);
  166.  
  167. rate = new Rate();
  168. rate.setFromDate(conv.convertStringToDate("08/28/2016"));
  169. rate.setRate(new BigDecimal("0.317"));
  170. rates.add(rate);
  171.  
  172. rate = new Rate();
  173. rate.setFromDate(conv.convertStringToDate("09/28/2016"));
  174. rate.setRate(new BigDecimal("0.714"));
  175. rates.add(rate);
  176.  
  177. }
  178. }
  179.  
  180. ---------------------------------------------------------------------------------------------------------------------------------------
  181.  
  182.  
  183. package gov.bsp.lcmis.internal.report.domain;
  184.  
  185. import java.math.BigDecimal;
  186. import java.util.List;
  187.  
  188. import gov.bsp.lcmis.internal.domain.Rate;
  189. import gov.bsp.lcmis.internal.utilities.ElRvcReportItemProcessor;
  190.  
  191. public class ElReleaseValue extends ReleaseValue {
  192.  
  193. private ElRvcReportItemProcessor elRvcReportItemProcessor;
  194.  
  195. private List<ComputedRvcReportItem> computedRvcReportItems;
  196.  
  197. private BigDecimal totalAccIntRec;
  198.  
  199. private BigDecimal totalIntInc;
  200.  
  201. private BigDecimal totalLiqDmgs;
  202.  
  203. private BigDecimal totalComputedRvWithLd;
  204.  
  205. private BigDecimal totalComputedRvWithoutLd;
  206.  
  207. private List<Rate> rates;
  208.  
  209. public List<ComputedRvcReportItem> getComputedRvcReportItems() {
  210. computedRvcReportItems = elRvcReportItemProcessor.fuseDateAndRate(this);
  211. System.out.print("computedRvcReportItems is null? ");
  212. System.out.println(computedRvcReportItems==null);
  213. // System.out.print("computedRvcReportItems is empty?");
  214. // System.out.println(computedRvcReportItems.isEmpty());
  215. setGrandTotal();
  216. return computedRvcReportItems;
  217. }
  218.  
  219. // public void setComputedRvcReportItems(List<ComputedRvcReportItem> computedRvcReportItems) {
  220. // this.computedRvcReportItems = computedRvcReportItems;
  221. // }
  222.  
  223. private void setGrandTotal() {
  224. this.totalAccIntRec = BigDecimal.ZERO;
  225. this.totalIntInc = BigDecimal.ZERO;
  226. this.totalLiqDmgs = BigDecimal.ZERO;
  227.  
  228. for (ComputedRvcReportItem item : this.computedRvcReportItems) {
  229. // this.totalAccIntRec = totalAccIntRec.add(item.getAir() == null || item.getAir().trim().isEmpty() ?
  230. // BigDecimal.ZERO : new BigDecimal(item.getAir()));
  231. // this.totalIntInc = totalIntInc.add(item.getInterestIncome() == null || item.getInterestIncome().trim().isEmpty() ?
  232. // BigDecimal.ZERO : new BigDecimal(item.getInterestIncome()));
  233. // this.totalLiqDmgs = totalLiqDmgs.add(item.getLiquidatedDamages() == null || item.getLiquidatedDamages().trim().isEmpty() ?
  234. // BigDecimal.ZERO : new BigDecimal(item.getLiquidatedDamages()));
  235. this.totalAccIntRec = totalAccIntRec.add(item.getAir() == null ? BigDecimal.ZERO : item.getAir());
  236. this.totalIntInc = totalIntInc.add(item.getInterestIncome() == null ? BigDecimal.ZERO : item.getInterestIncome());
  237. this.totalLiqDmgs =
  238. totalLiqDmgs.add(item.getLiquidatedDamages() == null ? BigDecimal.ZERO : item.getLiquidatedDamages());
  239.  
  240. }
  241.  
  242. this.totalComputedRvWithLd = getBasis().getOutstandingPrincipal().add(totalAccIntRec).add(totalIntInc).add(totalLiqDmgs);
  243. this.totalComputedRvWithoutLd = getBasis().getOutstandingPrincipal().add(totalAccIntRec).add(totalIntInc);
  244. }
  245.  
  246. public BigDecimal getTotalAccIntRec() {
  247. return totalAccIntRec;
  248. }
  249.  
  250. public void setTotalAccIntRec(BigDecimal totalAccIntRec) {
  251. this.totalAccIntRec = totalAccIntRec;
  252. }
  253.  
  254. public BigDecimal getTotalIntInc() {
  255. return totalIntInc;
  256. }
  257.  
  258. public void setTotalIntInc(BigDecimal totalIntInc) {
  259. this.totalIntInc = totalIntInc;
  260. }
  261.  
  262. public BigDecimal getTotalLiqDmgs() {
  263. return totalLiqDmgs;
  264. }
  265.  
  266. public void setTotalLiqDmgs(BigDecimal totalLiqDmgs) {
  267. this.totalLiqDmgs = totalLiqDmgs;
  268. }
  269.  
  270. public BigDecimal getTotalComputedRvWithLd() {
  271. return totalComputedRvWithLd;
  272. }
  273.  
  274. public BigDecimal getTotalComputedRvWithoutLd() {
  275. return totalComputedRvWithoutLd;
  276. }
  277.  
  278. public List<Rate> getRates() {
  279. return rates;
  280. }
  281.  
  282. public void setRates(List<Rate> rates) {
  283. this.rates = rates;
  284. }
  285.  
  286. public void setElRvcReportItemProcessor(ElRvcReportItemProcessor elRvcReportItemProcessor) {
  287. this.elRvcReportItemProcessor = elRvcReportItemProcessor;
  288. }
  289.  
  290. }
  291. ---------------------------------------------------------------------------------------------------------------------------------------
  292.  
  293. package gov.bsp.lcmis.internal.test;
  294.  
  295. import javax.naming.NamingException;
  296.  
  297. import org.junit.BeforeClass;
  298. import org.junit.Test;
  299. import org.junit.runner.RunWith;
  300. import org.slf4j.Logger;
  301. import org.slf4j.LoggerFactory;
  302. import org.springframework.context.ApplicationContext;
  303. import org.springframework.context.ApplicationContextAware;
  304. import org.springframework.jdbc.datasource.DriverManagerDataSource;
  305. import org.springframework.mock.jndi.SimpleNamingContextBuilder;
  306. import org.springframework.test.context.ActiveProfiles;
  307. import org.springframework.test.context.ContextConfiguration;
  308. import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
  309. import org.springframework.test.context.web.WebAppConfiguration;
  310.  
  311. import com.ibm.icu.impl.Assert;
  312.  
  313. import gov.bsp.lcmis.internal.fsm.dao.SearchRepoImpl;
  314. import gov.bsp.lcmis.internal.fsm.repo.RetrieveRvcAutocompleteResultByBankNameRepo;
  315. import gov.bsp.lcmis.internal.report.domain.ComputedRvcReportItem;
  316. import gov.bsp.lcmis.internal.report.domain.ElReleaseValue;
  317. import gov.bsp.lcmis.internal.utilities.DateConverter;
  318.  
  319.  
  320. @RunWith(SpringJUnit4ClassRunner.class)
  321. @WebAppConfiguration
  322. @ContextConfiguration(value = "file:src/main/webapp/WEB-INF/dispatcher-servlet.xml")
  323. @ActiveProfiles("test")
  324. public class ReusableUnitTest implements ApplicationContextAware {
  325.  
  326. private ApplicationContext applicationContext;
  327.  
  328. private static Logger logger = LoggerFactory.getLogger(ReusableUnitTest.class);
  329.  
  330. /**
  331. * SET THE DATABASE CREDS and URL
  332. */
  333. private static String url = "jdbc:db2://localhost:50000/mydb2";
  334.  
  335. private static String username = "db2admin";
  336.  
  337. private static String password = "password123";
  338.  
  339. /**
  340. * Note to Architect : please setup an environment dependent datasource
  341. * to remove the need for commenting and uncommenting the @Test method.
  342. */
  343. @BeforeClass
  344. public static void setupClass() {
  345. //create the datasource
  346. DriverManagerDataSource datasource = new DriverManagerDataSource(url, username, password);
  347. datasource.setDriverClassName("com.ibm.db2.jcc.DB2Driver");
  348.  
  349. //bind to a jndi string
  350. SimpleNamingContextBuilder builder = new SimpleNamingContextBuilder();
  351. builder.bind("lcmisbsp", datasource);
  352. builder.bind("${lcmissequencebsp.jndi.name}", datasource);
  353. builder.bind("${cfas.jndi.name}", datasource);
  354. builder.bind("${ops.jndi.name}", datasource);
  355.  
  356. try {
  357. builder.activate();
  358. } catch (IllegalStateException | NamingException e) {
  359. logger.error("Error setting up test class, ", e);
  360. }
  361. }
  362.  
  363. @Test
  364. public void test() {
  365. try {
  366. ElReleaseValue erv = applicationContext.getBean("elReleaseValue", ElReleaseValue.class);
  367. Assert.assrt(erv != null);
  368.  
  369. // DateConverter conv = applicationContext.getBean("dateConverter", DateConverter.class);
  370. // Assert.assrt(conv != null);
  371.  
  372. // System.out.println(conv.convertStringToDate("01/02/2016"));
  373.  
  374. for(ComputedRvcReportItem item : erv.getComputedRvcReportItems()) {
  375. System.out.println("accrued interest income: " + item.getAir());
  376. System.out.println("interest income: " + item.getInterestIncome());
  377. System.out.println("liquidated damages: " + item.getLiquidatedDamages());
  378. System.out.println("computation rate: " + item.getComputationRate());
  379. System.out.println("from date: " + item.getValueTerm().getFromDate() + " | to date: " + item.getValueTerm().getToDate());
  380. }
  381.  
  382. } catch (Exception e) {
  383. logger.error("Error found. ", e);
  384. }
  385. }
  386.  
  387. public void setApplicationContext(ApplicationContext applicationContext) {
  388. this.applicationContext = applicationContext;
  389. }
  390. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement