Skip to content

Commit 362c49b

Browse files
authored
KFSPTS-33582 Implement Part 3 of Sprintax 1042-S handling (#1705)
1 parent 5955bf6 commit 362c49b

File tree

80 files changed

+2929
-475
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

80 files changed

+2929
-475
lines changed

src/main/java/edu/cornell/kfs/sys/util/CuSqlQueryPlatformAwareDaoBaseJdbc.java

+38
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22

33
import java.text.MessageFormat;
44
import java.util.List;
5+
import java.util.function.Function;
56
import java.util.stream.Collectors;
67

78
import org.apache.logging.log4j.LogManager;
89
import org.apache.logging.log4j.Logger;
910
import org.kuali.kfs.core.framework.persistence.jdbc.dao.PlatformAwareDaoBaseJdbc;
11+
import org.springframework.jdbc.core.ResultSetExtractor;
1012
import org.springframework.jdbc.core.RowMapper;
1113
import org.springframework.jdbc.core.SqlParameterValue;
1214

@@ -48,6 +50,42 @@ protected int executeUpdate(final CuSqlQuery sqlQuery, boolean logSQLOnError) {
4850
}
4951
}
5052

53+
protected <T> T queryForResults(final CuSqlQuery sqlQuery, ResultSetExtractor<T> resultSetExtractor) {
54+
return queryForResults(sqlQuery, resultSetExtractor, true);
55+
}
56+
57+
protected <T> T queryForResults(final CuSqlQuery sqlQuery, ResultSetExtractor<T> resultSetExtractor,
58+
boolean logSQLOnError) {
59+
return queryForResults(sqlQuery, resultSetExtractor,
60+
CuSqlQueryPreparedStatementCreatorAndSetter::forReadOnlyResults, logSQLOnError);
61+
}
62+
63+
protected <T> T queryForUpdatableResults(final CuSqlQuery sqlQuery, ResultSetExtractor<T> resultSetExtractor) {
64+
return queryForUpdatableResults(sqlQuery, resultSetExtractor, true);
65+
}
66+
67+
protected <T> T queryForUpdatableResults(final CuSqlQuery sqlQuery, ResultSetExtractor<T> resultSetExtractor,
68+
boolean logSQLOnError) {
69+
return queryForResults(sqlQuery, resultSetExtractor,
70+
CuSqlQueryPreparedStatementCreatorAndSetter::forUpdatableResults, logSQLOnError);
71+
}
72+
73+
protected <T> T queryForResults(final CuSqlQuery sqlQuery, final ResultSetExtractor<T> resultSetExtractor,
74+
final Function<CuSqlQuery, CuSqlQueryPreparedStatementCreatorAndSetter> statementHandlerFactory,
75+
final boolean logSQLOnError) {
76+
try {
77+
final CuSqlQueryPreparedStatementCreatorAndSetter statementHandler =
78+
statementHandlerFactory.apply(sqlQuery);
79+
return getJdbcTemplate().query(statementHandler, statementHandler, resultSetExtractor);
80+
} catch (RuntimeException e) {
81+
if (logSQLOnError || LOG.isDebugEnabled()) {
82+
logSQL(sqlQuery);
83+
}
84+
LOG.error("queryForResults, Unexpected error encountered while running query!", e);
85+
throw e;
86+
}
87+
}
88+
5189
protected void logSQL(CuSqlQuery sqlQuery) {
5290
LOG.info("logSQL, queryString: " + sqlQuery.getQueryString());
5391
LOG.info("logSQL, parameters: " + buildParametersMessage(sqlQuery));
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package edu.cornell.kfs.sys.util;
2+
3+
import java.sql.Connection;
4+
import java.sql.PreparedStatement;
5+
import java.sql.ResultSet;
6+
import java.sql.SQLException;
7+
8+
import org.springframework.jdbc.core.ArgumentTypePreparedStatementSetter;
9+
import org.springframework.jdbc.core.PreparedStatementCreator;
10+
import org.springframework.jdbc.core.SqlProvider;
11+
12+
/**
13+
* Convenience CuSqlQuery-to-JDBC-query class that can be used as both a PreparedStatementCreator
14+
* and a PreparedStatementSetter by a JdbcTemplate. Furthermore, it also allows specifying the desired
15+
* type and concurrency for the generated ResultSet.
16+
*/
17+
public class CuSqlQueryPreparedStatementCreatorAndSetter extends ArgumentTypePreparedStatementSetter
18+
implements PreparedStatementCreator, SqlProvider {
19+
20+
private final CuSqlQuery query;
21+
private final int resultSetType;
22+
private final int resultSetConcurrency;
23+
24+
public CuSqlQueryPreparedStatementCreatorAndSetter(final CuSqlQuery query, final int resultSetType,
25+
final int resultSetConcurrency) {
26+
super(query.getParameterValuesArray(), query.getParameterTypesArray());
27+
this.query = query;
28+
this.resultSetType = resultSetType;
29+
this.resultSetConcurrency = resultSetConcurrency;
30+
}
31+
32+
public static CuSqlQueryPreparedStatementCreatorAndSetter forReadOnlyResults(final CuSqlQuery query) {
33+
return new CuSqlQueryPreparedStatementCreatorAndSetter(
34+
query, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
35+
}
36+
37+
public static CuSqlQueryPreparedStatementCreatorAndSetter forUpdatableResults(final CuSqlQuery query) {
38+
return new CuSqlQueryPreparedStatementCreatorAndSetter(
39+
query, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE);
40+
}
41+
42+
@Override
43+
public String getSql() {
44+
return query.getQueryString();
45+
}
46+
47+
@Override
48+
public PreparedStatement createPreparedStatement(final Connection con) throws SQLException {
49+
return con.prepareStatement(getSql(), resultSetType, resultSetConcurrency);
50+
}
51+
52+
}

src/main/java/edu/cornell/kfs/tax/batch/CUTaxBatchConstants.java

+16-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,16 @@ public enum Tax1099FilerAddressField {
7171

7272
public enum TaxOutputFieldType {
7373
STATIC,
74-
DERIVED;
74+
STRING,
75+
NORMALIZED_STRING,
76+
SENSITIVE_STRING,
77+
INTEGER,
78+
BOOLEAN,
79+
DATE,
80+
AMOUNT,
81+
NEGATED_AMOUNT,
82+
PERCENT,
83+
PLAIN_DECIMAL;
7584
}
7685

7786
/**
@@ -523,6 +532,12 @@ private DerivedFieldNames() {
523532
}
524533
}
525534

535+
public static final class TaxFileSections {
536+
public static final String SPRINTAX_BIOGRAPHIC_ROW_1042S = "Sprintax_Bio_Row_1042S";
537+
public static final String SPRINTAX_PAYMENT_ROW_1042S = "Sprintax_Payment_Row_1042S";
538+
public static final String PLAIN_TRANSACTION_DETAIL_ROW = "Plain_Transaction_Detail_Row";
539+
}
540+
526541

527542

528543
private CUTaxBatchConstants() {

src/main/java/edu/cornell/kfs/tax/batch/TaxBatchConfig.java

+29-6
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,16 @@
22

33
import org.apache.commons.lang3.Validate;
44

5+
import edu.cornell.kfs.tax.util.TaxUtils;
6+
57
public final class TaxBatchConfig {
68

9+
public enum Mode {
10+
CREATE_TAX_FILES,
11+
CREATE_TRANSACTION_LIST_FILE;
12+
}
13+
14+
private final Mode mode;
715
private final String taxType;
816
private final int reportYear;
917
private final java.util.Date processingStartDate;
@@ -12,15 +20,30 @@ public final class TaxBatchConfig {
1220

1321
public TaxBatchConfig(final String taxType, final int reportYear,
1422
final java.util.Date processingStartDate, final java.sql.Date startDate, final java.sql.Date endDate) {
23+
this(Mode.CREATE_TAX_FILES, taxType, reportYear, processingStartDate, startDate, endDate);
24+
}
25+
26+
public TaxBatchConfig(final Mode mode, final String taxType, final int reportYear,
27+
final java.util.Date processingStartDate, final java.sql.Date startDate, final java.sql.Date endDate) {
28+
Validate.notNull(mode, "mode cannot be null");
1529
Validate.notBlank(taxType, "taxType cannot be blank");
1630
Validate.notNull(processingStartDate, "processingStartDate cannot be null");
1731
Validate.notNull(startDate, "startDate cannot be null");
1832
Validate.notNull(endDate, "endDate cannot be null");
33+
this.mode = mode;
1934
this.taxType = taxType;
2035
this.reportYear = reportYear;
21-
this.processingStartDate = processingStartDate;
22-
this.startDate = startDate;
23-
this.endDate = endDate;
36+
this.processingStartDate = TaxUtils.copyDate(processingStartDate);
37+
this.startDate = TaxUtils.copyDate(startDate);
38+
this.endDate = TaxUtils.copyDate(endDate);
39+
}
40+
41+
public TaxBatchConfig withMode(final Mode newMode) {
42+
return new TaxBatchConfig(newMode, taxType, reportYear, processingStartDate, startDate, endDate);
43+
}
44+
45+
public Mode getMode() {
46+
return mode;
2447
}
2548

2649
public String getTaxType() {
@@ -32,15 +55,15 @@ public int getReportYear() {
3255
}
3356

3457
public java.util.Date getProcessingStartDate() {
35-
return new java.util.Date(processingStartDate.getTime());
58+
return TaxUtils.copyDate(processingStartDate);
3659
}
3760

3861
public java.sql.Date getStartDate() {
39-
return new java.sql.Date(startDate.getTime());
62+
return TaxUtils.copyDate(startDate);
4063
}
4164

4265
public java.sql.Date getEndDate() {
43-
return new java.sql.Date(endDate.getTime());
66+
return TaxUtils.copyDate(endDate);
4467
}
4568

4669
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package edu.cornell.kfs.tax.batch;
2+
3+
/**
4+
* This object will be fully implemented by one of the follow-up Sprintax user stories.
5+
*/
6+
public class TaxStatistics {
7+
8+
}

src/main/java/edu/cornell/kfs/tax/batch/dataaccess/TaxDtoFieldEnum.java

+8
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,14 @@ default String getFieldName() {
1515
return name();
1616
}
1717

18+
default boolean needsExplicitAlias() {
19+
return false;
20+
}
21+
22+
default boolean needsEncryptedStorage() {
23+
return false;
24+
}
25+
1826
Class<? extends BusinessObject> getMappedBusinessObjectClass();
1927

2028
}

src/main/java/edu/cornell/kfs/tax/batch/dataaccess/TaxDtoRowMapper.java

+5-4
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,16 @@
88
*
99
* The "T" type represents the DTO type that will be extracted from the ResultSet.
1010
*
11-
* The "U" type represents the DTO type that will be used for updating the ResultSet (if supported);
12-
* it can be the same as the "T" type if desired.
11+
* A DTO type other than the "T" type may be used when calling the updateStringFieldsOnCurrentRow() method,
12+
* as long as the DTO fields being accessed have the same names as those on the "T" DTO.
1313
*/
14-
public interface TaxDtoRowMapper<T, U> {
14+
public interface TaxDtoRowMapper<T> {
1515

1616
boolean moveToNextRow() throws SQLException;
1717

1818
T readCurrentRow() throws SQLException;
1919

20-
void prepareCurrentRowForUpdate(final U dtoContainingUpdates) throws SQLException;
20+
void updateStringFieldsOnCurrentRow(final Object dtoContainingUpdates,
21+
final TaxDtoFieldEnum... fieldsToUpdate) throws SQLException;
2122

2223
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package edu.cornell.kfs.tax.batch.dataaccess;
2+
3+
import edu.cornell.kfs.tax.batch.TaxBatchConfig;
4+
import edu.cornell.kfs.tax.batch.TaxStatistics;
5+
import edu.cornell.kfs.tax.businessobject.TransactionDetail;
6+
7+
@FunctionalInterface
8+
public interface TransactionDetailHandler {
9+
10+
TaxStatistics performProcessing(final TaxBatchConfig config,
11+
final TaxDtoRowMapper<TransactionDetail> rowMapper) throws Exception;
12+
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package edu.cornell.kfs.tax.batch.dataaccess;
2+
3+
import java.util.List;
4+
5+
import edu.cornell.kfs.tax.batch.TaxBatchConfig;
6+
import edu.cornell.kfs.tax.batch.TaxStatistics;
7+
import edu.cornell.kfs.tax.batch.dto.NoteLite;
8+
import edu.cornell.kfs.tax.batch.dto.VendorAddressLite;
9+
import edu.cornell.kfs.tax.batch.dto.VendorQueryResults;
10+
11+
public interface TransactionDetailProcessorDao {
12+
13+
TaxStatistics processTransactionDetails(final TaxBatchConfig config,
14+
final TransactionDetailHandler handler);
15+
16+
VendorQueryResults getVendor(final Integer vendorHeaderId, final Integer vendorDetailId);
17+
18+
VendorAddressLite getHighestPriorityUSVendorAddress(final Integer vendorHeaderId,
19+
final Integer vendorDetailId);
20+
21+
VendorAddressLite getHighestPriorityForeignVendorAddress(final Integer vendorHeaderId,
22+
final Integer vendorDetailId);
23+
24+
List<NoteLite> getNotesByDocumentNumber(final String documentNumber);
25+
26+
}

src/main/java/edu/cornell/kfs/tax/batch/dataaccess/impl/NoteLiteMapper.java

-26
This file was deleted.

src/main/java/edu/cornell/kfs/tax/batch/dataaccess/impl/ReadOnlyTaxDtoRowMapperBase.java

-28
This file was deleted.

0 commit comments

Comments
 (0)