Skip to content

Commit

Permalink
added loa support and conducted refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
cameroncaci committed Dec 11, 2023
1 parent e1092d6 commit ba51b79
Show file tree
Hide file tree
Showing 11 changed files with 589 additions and 18 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</parent>
<groupId>com.milmove.trdmlambda</groupId>
<artifactId>trdm-lambda</artifactId>
<version>1.0.1.5</version>
<version>1.0.2.0</version>
<name>trdm java spring interface</name>
<description>Project for deploying a Java TRDM interfacer for TGET data.</description>
<properties>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.amazonaws.services.lambda.runtime.Context;
import com.amazonaws.services.lambda.runtime.RequestHandler;
import com.milmove.trdmlambda.milmove.handler.LinesOfAccountingHandler;
import com.milmove.trdmlambda.milmove.handler.TransportationAccountingCodesHandler;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
Expand All @@ -24,8 +25,13 @@ public String handleRequest(Object input, Context lambdaContext) {
logger.info("trdm cron job triggered, starting TAC handler and TGET flow");
TransportationAccountingCodesHandler tacHandler = context.getBean(TransportationAccountingCodesHandler.class);
tacHandler.tacCron();
logger.info("finished tac cron handler");

logger.info("starting LOA handler");
LinesOfAccountingHandler loaHandler = context.getBean(LinesOfAccountingHandler.class);
loaHandler.loaCron();
logger.info("finished loa cron handler");

logger.info("trdm cron job finished execution");
return "trdm cron job finished execution";
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,50 @@
package com.milmove.trdmlambda.milmove.handler;

import com.milmove.trdmlambda.milmove.util.Trdm;

import ch.qos.logback.classic.Logger;

import java.io.IOException;
import java.sql.SQLException;
import java.text.ParseException;

import javax.xml.datatype.DatatypeConfigurationException;
import javax.xml.datatype.XMLGregorianCalendar;

import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import com.milmove.trdmlambda.milmove.exceptions.TableRequestException;
import com.milmove.trdmlambda.milmove.model.lasttableupdate.LastTableUpdateResponse;

@Component
public class LinesOfAccountingHandler {
// TODO:
private Logger logger = (Logger) LoggerFactory.getLogger(LinesOfAccountingHandler.class);

private Trdm trdmUtil;

public LinesOfAccountingHandler(Trdm trdmUtil) {
this.trdmUtil = trdmUtil;
}

// This cron job will handle the entirety of ensuring the RDS db
// is up to date with proper TGET data.
public void loaCron()
throws SQLException, DatatypeConfigurationException, TableRequestException, IOException, ParseException {
// Gather the last update from TRDM
logger.info("getting lastTableUpdate response with physical name LN_OF_ACCT");
LastTableUpdateResponse response = trdmUtil.LastTableUpdate("LN_OF_ACCT");
logger.info("received LastTableUpdateResponse, getting our latest TGET update now");
XMLGregorianCalendar ourLastUpdate = trdmUtil.GetOurLastTGETUpdate("lines_of_accounting");
logger.info("received out latest TGET update. Comparing the 2 values to see if our TGET data is out of date");
boolean tgetOutOfDate = trdmUtil.IsTGETDataOutOfDate(ourLastUpdate, response.getLastUpdate());
if (tgetOutOfDate) {
logger.info("LOA TGET data is out of date. Starting updateTGETData flow");
trdmUtil.UpdateTGETData(ourLastUpdate, "LN_OF_ACCT", "lines_of_accounting");
logger.info("finished updating LOA TGET data");
} else {
// The data in RDS is up to date, no need to proceed
logger.info("Lines of Accounting RDS Table TGET data already up to date");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package com.milmove.trdmlambda.milmove.model;

import lombok.Data;
import java.time.LocalDateTime;
import java.util.UUID;

@Data
public class LineOfAccounting {
private UUID id; // RDS Internal
private String loaSysID;
private String loaDptID;
private String loaTnsfrDptNm;
private String loaBafID;
private String loaTrsySfxTx;
private String loaMajClmNm;
private String loaOpAgncyID;
private String loaAlltSnID;
private String loaPgmElmntID;
private String loaTskBdgtSblnTx;
private String loaDfAgncyAlctnRcpntID;
private String loaJbOrdNm;
private String loaSbaltmtRcpntID;
private String loaWkCntrRcpntNm;
private String loaMajRmbsmtSrcID;
private String loaDtlRmbsmtSrcID;
private String loaCustNm;
private String loaObjClsID;
private String loaSrvSrcID;
private String loaSpclIntrID;
private String loaBdgtAcntClsNm;
private String loaDocID;
private String loaClsRefID;
private String loaInstlAcntgActID;
private String loaLclInstlID;
private String loaFmsTrnsactnID;
private String loaDscTx;
private LocalDateTime loaBgnDt;
private LocalDateTime loaEndDt;
private String loaFnctPrsNm;
private String loaStatCd;
private String loaHistStatCd;
private String loaHsGdsCd;
private String orgGrpDfasCd;
private String loaUic;
private String loaTrnsnID;
private String loaSubAcntID;
private String loaBetCd;
private String loaFndTyFgCd;
private String loaBgtLnItmID;
private String loaScrtyCoopImplAgncCd;
private String loaScrtyCoopDsgntrCd;
private String loaScrtyCoopLnItmID;
private String loaAgncDsbrCd;
private String loaAgncAcntngCd;
private String loaFndCntrID;
private String loaCstCntrID;
private String loaPrjID;
private String loaActvtyID;
private String loaCstCd;
private String loaWrkOrdID;
private String loaFnclArID;
private String loaScrtyCoopCustCd;
private Integer loaEndFyTx;
private Integer loaBgFyTx;
private String loaBgtRstrCd;
private String loaBgtSubActCd;
private LocalDateTime createdAt; // RDS Internal
private LocalDateTime updatedAt; // RDS Internal
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import java.util.List;
import java.util.UUID;

import com.milmove.trdmlambda.milmove.model.LineOfAccounting;
import com.milmove.trdmlambda.milmove.model.TransportationAccountingCode;
import com.milmove.trdmlambda.milmove.util.SecretFetcher;

Expand Down Expand Up @@ -61,7 +62,7 @@ public Connection getConnection() throws SQLException {
public void insertTransportationAccountingCodes(List<TransportationAccountingCode> codes) throws SQLException {

String sql = "INSERT INTO transportation_accounting_codes (id, tac, tac_sys_id, loa_sys_id, tac_fy_txt, tac_fn_bl_mod_cd, org_grp_dfas_cd, tac_mvt_dsg_id, tac_ty_cd, tac_use_cd, tac_maj_clmt_id, tac_bill_act_txt, tac_cost_ctr_nm, buic, tac_hist_cd, tac_stat_cd, trnsprtn_acnt_tx, trnsprtn_acnt_bgn_dt, trnsprtn_acnt_end_dt, dd_actvty_adrs_id, tac_blld_add_frst_ln_tx, tac_blld_add_scnd_ln_tx, tac_blld_add_thrd_ln_tx, tac_blld_add_frth_ln_tx, tac_fnct_poc_nm) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";

try (Connection conn = this.getConnection(); PreparedStatement pstmt = conn.prepareStatement(sql)) {

int count = 0;
Expand Down Expand Up @@ -105,4 +106,87 @@ public void insertTransportationAccountingCodes(List<TransportationAccountingCod
}
}
}

// Batch insert 10k LOAs at a time
public void insertLinesOfAccounting(List<LineOfAccounting> loas) throws SQLException {

String sql = "INSERT INTO lines_of_accounting (id, loa_sys_id, loa_dpt_id, loa_tnsfr_dpt_nm, loa_baf_id, loa_trsy_sfx_tx, loa_maj_clm_nm, loa_op_agncy_id, loa_allt_sn_id, loa_pgm_elmnt_id, loa_tsk_bdgt_sbln_tx, loa_df_agncy_alctn_rcpnt_id, loa_jb_ord_nm, loa_sbaltmt_rcpnt_id, loa_wk_cntr_rcpnt_nm, loa_maj_rmbsmt_src_id, loa_dtl_rmbsmt_src_id, loa_cust_nm, loa_obj_cls_id, loa_srv_src_id, loa_spcl_intr_id, loa_bdgt_acnt_cls_nm, loa_doc_id, loa_cls_ref_id, loa_instl_acntg_act_id, loa_lcl_instl_id, loa_fms_trnsactn_id, loa_dsc_tx, loa_bgn_dt, loa_end_dt, loa_fnct_prs_nm, loa_stat_cd, loa_hist_stat_cd, loa_hs_gds_cd, org_grp_dfas_cd, loa_uic, loa_trnsn_id, loa_sub_acnt_id, loa_bet_cd, loa_fnd_ty_fg_cd, loa_bgt_ln_itm_id, loa_scrty_coop_impl_agnc_cd, loa_scrty_coop_dsgntr_cd, loa_scrty_coop_ln_itm_id, loa_agnc_dsbr_cd, loa_agnc_acntng_cd, loa_fnd_cntr_id, loa_cst_cntr_id, loa_prj_id, loa_actvty_id, loa_cst_cd, loa_wrk_ord_id, loa_fncl_ar_id, loa_scrty_coop_cust_cd, loa_end_fy_tx, loa_bg_fy_tx, loa_bgt_rstr_cd, loa_bgt_sub_act_cd, created_at, updated_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";

try (Connection conn = this.getConnection(); PreparedStatement pstmt = conn.prepareStatement(sql)) {

int count = 0;

for (LineOfAccounting loa : loas) {
if (loa.getId() == null) {
loa.setId(UUID.randomUUID());
}
pstmt.setObject(1, loa.getId());
pstmt.setString(2, loa.getLoaSysID());
pstmt.setString(3, loa.getLoaDptID());
pstmt.setString(4, loa.getLoaTnsfrDptNm());
pstmt.setString(5, loa.getLoaBafID());
pstmt.setString(6, loa.getLoaTrsySfxTx());
pstmt.setString(7, loa.getLoaMajClmNm());
pstmt.setString(8, loa.getLoaOpAgncyID());
pstmt.setString(9, loa.getLoaAlltSnID());
pstmt.setString(10, loa.getLoaPgmElmntID());
pstmt.setString(11, loa.getLoaTskBdgtSblnTx());
pstmt.setString(12, loa.getLoaDfAgncyAlctnRcpntID());
pstmt.setString(13, loa.getLoaJbOrdNm());
pstmt.setString(14, loa.getLoaSbaltmtRcpntID());
pstmt.setString(15, loa.getLoaWkCntrRcpntNm());
pstmt.setString(16, loa.getLoaMajRmbsmtSrcID());
pstmt.setString(17, loa.getLoaDtlRmbsmtSrcID());
pstmt.setString(18, loa.getLoaCustNm());
pstmt.setString(19, loa.getLoaObjClsID());
pstmt.setString(20, loa.getLoaSrvSrcID());
pstmt.setString(21, loa.getLoaSpclIntrID());
pstmt.setString(22, loa.getLoaBdgtAcntClsNm());
pstmt.setString(23, loa.getLoaDocID());
pstmt.setString(24, loa.getLoaClsRefID());
pstmt.setString(25, loa.getLoaInstlAcntgActID());
pstmt.setString(26, loa.getLoaLclInstlID());
pstmt.setString(27, loa.getLoaFmsTrnsactnID());
pstmt.setString(28, loa.getLoaDscTx());
pstmt.setDate(29, java.sql.Date.valueOf(loa.getLoaBgnDt().toLocalDate()));
pstmt.setDate(30, java.sql.Date.valueOf(loa.getLoaEndDt().toLocalDate()));
pstmt.setString(31, loa.getLoaFnctPrsNm());
pstmt.setString(32, loa.getLoaStatCd());
pstmt.setString(33, loa.getLoaHistStatCd());
pstmt.setString(34, loa.getLoaHsGdsCd());
pstmt.setString(35, loa.getOrgGrpDfasCd());
pstmt.setString(36, loa.getLoaUic());
pstmt.setString(37, loa.getLoaTrnsnID());
pstmt.setString(38, loa.getLoaSubAcntID());
pstmt.setString(39, loa.getLoaBetCd());
pstmt.setString(40, loa.getLoaFndTyFgCd());
pstmt.setString(41, loa.getLoaBgtLnItmID());
pstmt.setString(42, loa.getLoaScrtyCoopImplAgncCd());
pstmt.setString(43, loa.getLoaScrtyCoopDsgntrCd());
pstmt.setString(44, loa.getLoaScrtyCoopLnItmID());
pstmt.setString(45, loa.getLoaAgncDsbrCd());
pstmt.setString(46, loa.getLoaAgncAcntngCd());
pstmt.setString(47, loa.getLoaFndCntrID());
pstmt.setString(48, loa.getLoaCstCntrID());
pstmt.setString(49, loa.getLoaPrjID());
pstmt.setString(50, loa.getLoaActvtyID());
pstmt.setString(51, loa.getLoaCstCd());
pstmt.setString(52, loa.getLoaWrkOrdID());
pstmt.setString(53, loa.getLoaFnclArID());
pstmt.setString(54, loa.getLoaScrtyCoopCustCd());
pstmt.setObject(55, loa.getLoaEndFyTx());
pstmt.setObject(56, loa.getLoaBgFyTx());
pstmt.setString(57, loa.getLoaBgtRstrCd());
pstmt.setString(58, loa.getLoaBgtSubActCd());
pstmt.setTimestamp(60, java.sql.Timestamp.valueOf(loa.getUpdatedAt()));
pstmt.addBatch();

// Execute every 10000 rows or when finished with the provided LOAs
if (count++ % 10000 == 0 || count == loas.size()) {
pstmt.executeBatch();
}
}
}
}

}
Loading

0 comments on commit ba51b79

Please sign in to comment.