@@ -34,14 +34,13 @@ public class AttestationReportProcessor implements ExcelReportProcessor {
34
34
@ Autowired
35
35
private ContractService contractService ;
36
36
37
-
38
37
private static final String ATTESTATION_OFFSET_DATE_TIME_PATTERN = "M/d/y h:m a Z" ;
39
38
40
39
@ Value
41
40
private class AttestationReportData {
42
41
private Contract contract ;
43
42
private String attestationStatus ;
44
- private OffsetDateTime attestetedDateTime ;
43
+ private OffsetDateTime attestedDateTime ;
45
44
}
46
45
47
46
@ Override
@@ -50,14 +49,14 @@ public void processReport(InputStream xlsInputStream, ExcelType excelType) throw
50
49
Sheet datatypeSheet = workbook .getSheetAt (0 );
51
50
Iterator <Row > iterator = datatypeSheet .iterator ();
52
51
53
- Map <String , AttestationReportData > contractsSeenToLatestAttestationData =
54
- new HashMap <>();
52
+ Map <String , AttestationReportData > contractsSeenToLatestAttestationData = new HashMap <>();
55
53
56
54
log .info ("Beginning processing a total of {} rows" , datatypeSheet .getPhysicalNumberOfRows ());
57
55
58
56
// In this loop just gather the most recent attestation data
59
57
while (iterator .hasNext ()) {
60
58
Row currentRow = iterator .next ();
59
+
61
60
if (currentRow == null ) {
62
61
continue ;
63
62
}
@@ -69,59 +68,60 @@ public void processReport(InputStream xlsInputStream, ExcelType excelType) throw
69
68
continue ;
70
69
}
71
70
72
- Optional <Contract > contractOptional =
73
- contractService .getContractByContractNumber (contractNumber );
74
- if (contractOptional .isPresent ()) {
75
- Contract contract = contractOptional .get ();
76
-
77
- String attestetedDateTimeCell = currentRow .getCell (6 ).getStringCellValue ();
78
- // Set to Eastern time since that's where HPMS is
79
- String offset = DateUtil .getESTOffset ();
80
- OffsetDateTime offsetDateTime =
81
- OffsetDateTime .parse (attestetedDateTimeCell + " " + offset ,
82
- DateTimeFormatter
83
- .ofPattern (ATTESTATION_OFFSET_DATE_TIME_PATTERN ));
84
- String attestationStatus = currentRow .getCell (2 ).getStringCellValue ();
85
-
86
- if (!contractsSeenToLatestAttestationData .containsKey (contractNumber )) {
87
- contractsSeenToLatestAttestationData .put (contractNumber ,
88
- new AttestationReportData (contract , attestationStatus ,
89
- offsetDateTime ));
90
- } else {
91
- AttestationReportData latestData =
92
- contractsSeenToLatestAttestationData .get (contractNumber );
93
- // Overwrite if we have a later date, we only care about the latest
94
- if (offsetDateTime .isAfter (latestData .getAttestetedDateTime ())) {
95
- contractsSeenToLatestAttestationData .put (contractNumber ,
96
- new AttestationReportData (contract , attestationStatus ,
97
- offsetDateTime ));
98
- }
99
- }
100
- } else {
101
- log .error (
102
- "Contract ID {} was not found in the database during contract report " +
103
- "processing" ,
104
- contractNumber );
105
- throw new ReportProcessingException ("Contract ID " + contractNumber +
106
- " was not found in the database during contract report processing" );
107
- }
71
+ processRow (currentRow , contractsSeenToLatestAttestationData , contractNumber );
108
72
}
109
73
110
- for (Map .Entry <String , AttestationReportData > entry :
111
- contractsSeenToLatestAttestationData
112
- .entrySet ()) {
113
- AttestationReportData attestationReportData = entry .getValue ();
114
- var contract = attestationReportData .getContract ();
115
-
116
- String attestationStatus = attestationReportData .getAttestationStatus ();
117
- OffsetDateTime offsetDateTime = attestationStatus .toUpperCase ()
118
- .equals (AttestationStatus .ATTESTED .getValue ().toUpperCase ()) ?
119
- attestationReportData .getAttestetedDateTime () : null ;
120
- contract .setAttestedOn (offsetDateTime );
121
- contractService .updateContract (contract );
74
+ updateContract (contractsSeenToLatestAttestationData );
75
+ }
76
+ }
122
77
123
- log .info ("Updated contract {}" , keyValue (CONTRACT_LOG , contract .getContractName ()));
78
+ private void processRow (Row currentRow , Map <String , AttestationReportData > contractsSeenToLatestAttestationData ,
79
+ String contractNumber ) {
80
+ Optional <Contract > contractOptional = contractService .getContractByContractNumber (contractNumber );
81
+ if (contractOptional .isPresent ()) {
82
+ Contract contract = contractOptional .get ();
83
+
84
+ String attestetedDateTimeCell = currentRow .getCell (6 ).getStringCellValue ();
85
+ // Set to Eastern time since that's where HPMS is
86
+ String offset = DateUtil .getESTOffset ();
87
+ OffsetDateTime offsetDateTime = OffsetDateTime .parse (attestetedDateTimeCell + " " + offset ,
88
+ DateTimeFormatter .ofPattern (ATTESTATION_OFFSET_DATE_TIME_PATTERN ));
89
+ String attestationStatus = currentRow .getCell (2 ).getStringCellValue ();
90
+
91
+ if (!contractsSeenToLatestAttestationData .containsKey (contractNumber )) {
92
+ contractsSeenToLatestAttestationData .put (contractNumber ,
93
+ new AttestationReportData (contract , attestationStatus , offsetDateTime ));
94
+ } else {
95
+ AttestationReportData latestData = contractsSeenToLatestAttestationData .get (contractNumber );
96
+ // Overwrite if we have a later date, we only care about the latest
97
+ if (offsetDateTime .isAfter (latestData .getAttestedDateTime ())) {
98
+ contractsSeenToLatestAttestationData .put (contractNumber ,
99
+ new AttestationReportData (contract , attestationStatus , offsetDateTime ));
100
+ }
124
101
}
102
+ } else {
103
+ log .error ("Contract ID {} was not found in the database during contract report " + "processing" ,
104
+ contractNumber );
105
+ throw new ReportProcessingException ("Contract ID " + contractNumber +
106
+ " was not found in the database during contract report processing" );
107
+ }
108
+ }
109
+
110
+ private void updateContract (Map <String , AttestationReportData > contractsSeenToLatestAttestationData ) {
111
+ for (Map .Entry <String , AttestationReportData > entry :
112
+ contractsSeenToLatestAttestationData
113
+ .entrySet ()) {
114
+ AttestationReportData attestationReportData = entry .getValue ();
115
+ var contract = attestationReportData .getContract ();
116
+
117
+ String attestationStatus = attestationReportData .getAttestationStatus ();
118
+ OffsetDateTime offsetDateTime = attestationStatus .toUpperCase ()
119
+ .equals (AttestationStatus .ATTESTED .getValue ().toUpperCase ()) ?
120
+ attestationReportData .getAttestedDateTime () : null ;
121
+ contract .setAttestedOn (offsetDateTime );
122
+ contractService .updateContract (contract );
123
+
124
+ log .info ("Updated contract {}" , keyValue (CONTRACT_LOG , contract .getContractName ()));
125
125
}
126
126
}
127
127
}
0 commit comments