Skip to content

Commit 01e615a

Browse files
authored
Feature/ab2d 1192 code climate (#255)
Reducing complexity and removing lines in methods to move below 35 and complexity at 10. Adding a .codeclimate.yml file to set baseline options.
1 parent d328be7 commit 01e615a

File tree

5 files changed

+223
-172
lines changed

5 files changed

+223
-172
lines changed

.codeclimate.yml

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
version: "2"
2+
checks:
3+
method-lines:
4+
config:
5+
threshold: 35
6+
method-complexity:
7+
config:
8+
threshold: 10

hpms/src/main/java/gov/cms/ab2d/hpms/processing/AttestationReportProcessor.java

+53-53
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,13 @@ public class AttestationReportProcessor implements ExcelReportProcessor {
3434
@Autowired
3535
private ContractService contractService;
3636

37-
3837
private static final String ATTESTATION_OFFSET_DATE_TIME_PATTERN = "M/d/y h:m a Z";
3938

4039
@Value
4140
private class AttestationReportData {
4241
private Contract contract;
4342
private String attestationStatus;
44-
private OffsetDateTime attestetedDateTime;
43+
private OffsetDateTime attestedDateTime;
4544
}
4645

4746
@Override
@@ -50,14 +49,14 @@ public void processReport(InputStream xlsInputStream, ExcelType excelType) throw
5049
Sheet datatypeSheet = workbook.getSheetAt(0);
5150
Iterator<Row> iterator = datatypeSheet.iterator();
5251

53-
Map<String, AttestationReportData> contractsSeenToLatestAttestationData =
54-
new HashMap<>();
52+
Map<String, AttestationReportData> contractsSeenToLatestAttestationData = new HashMap<>();
5553

5654
log.info("Beginning processing a total of {} rows", datatypeSheet.getPhysicalNumberOfRows());
5755

5856
// In this loop just gather the most recent attestation data
5957
while (iterator.hasNext()) {
6058
Row currentRow = iterator.next();
59+
6160
if (currentRow == null) {
6261
continue;
6362
}
@@ -69,59 +68,60 @@ public void processReport(InputStream xlsInputStream, ExcelType excelType) throw
6968
continue;
7069
}
7170

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);
10872
}
10973

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+
}
12277

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+
}
124101
}
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()));
125125
}
126126
}
127127
}

hpms/src/main/java/gov/cms/ab2d/hpms/processing/OrgStructureReportProcessor.java

+57-51
Original file line numberDiff line numberDiff line change
@@ -54,59 +54,65 @@ public void processReport(InputStream xlsInputStream, ExcelType excelType) throw
5454
}
5555
if (contractNumber.toUpperCase().startsWith("E") ||
5656
contractNumber.toUpperCase().startsWith("S")) {
57-
String sponsorParentName = currentRow.getCell(0).getStringCellValue();
58-
Double sponsorParentHpmsId = currentRow.getCell(1).getNumericCellValue();
59-
String sponsorName = currentRow.getCell(2).getStringCellValue();
60-
Double sponsorHpmsId = currentRow.getCell(3).getNumericCellValue();
61-
String contractName = currentRow.getCell(5).getStringCellValue();
62-
63-
Optional<Sponsor> parentSponsorOptional = sponsorService
64-
.findByHpmsIdAndParent(sponsorParentHpmsId.intValue(), null);
65-
66-
Sponsor parentSponsor;
67-
if (parentSponsorOptional.isPresent()) {
68-
parentSponsor = parentSponsorOptional.get();
69-
} else {
70-
parentSponsor = new Sponsor();
71-
parentSponsor.setHpmsId(sponsorParentHpmsId.intValue());
72-
parentSponsor.setLegalName(sponsorParentName);
73-
parentSponsor.setOrgName(sponsorParentName);
74-
sponsorService.saveSponsor(parentSponsor);
75-
}
76-
77-
Optional<Sponsor> sponsorOptional =
78-
sponsorService.findByHpmsIdAndParent(sponsorHpmsId.intValue(),
79-
parentSponsor);
80-
81-
Sponsor sponsor;
82-
if (!sponsorOptional.isPresent()) {
83-
sponsor = new Sponsor();
84-
} else {
85-
sponsor = sponsorOptional.get();
86-
}
87-
88-
log.info("Starting processing for sponsor {}", keyValue(SPONSOR_LOG, sponsorHpmsId));
89-
90-
sponsor.setHpmsId(sponsorHpmsId.intValue());
91-
sponsor.setLegalName(sponsorName);
92-
sponsor.setOrgName(sponsorName);
93-
sponsor.setParent(parentSponsor);
94-
95-
// Only add the contract if it doesn't already exist
96-
if (!sponsor.hasContract(contractNumber)) {
97-
Contract contract = new Contract();
98-
contract.setContractName(contractName);
99-
contract.setContractNumber(contractNumber);
100-
contract.setSponsor(sponsor);
101-
102-
sponsor.getContracts().add(contract);
103-
}
104-
105-
sponsorService.saveSponsor(sponsor);
106-
107-
log.info("Sponsor saved {}", keyValue(SPONSOR_LOG, sponsorHpmsId));
57+
linkSponsorWithContract(currentRow, contractNumber);
10858
}
10959
}
11060
}
11161
}
62+
63+
private void linkSponsorWithContract(Row currentRow, String contractNumber) {
64+
String sponsorParentName = currentRow.getCell(0).getStringCellValue();
65+
Double sponsorParentHpmsId = currentRow.getCell(1).getNumericCellValue();
66+
String sponsorName = currentRow.getCell(2).getStringCellValue();
67+
Double sponsorHpmsId = currentRow.getCell(3).getNumericCellValue();
68+
String contractName = currentRow.getCell(5).getStringCellValue();
69+
70+
Optional<Sponsor> parentSponsorOptional = sponsorService
71+
.findByHpmsIdAndParent(sponsorParentHpmsId.intValue(), null);
72+
73+
Sponsor parentSponsor;
74+
if (parentSponsorOptional.isPresent()) {
75+
parentSponsor = parentSponsorOptional.get();
76+
} else {
77+
parentSponsor = new Sponsor();
78+
parentSponsor.setHpmsId(sponsorParentHpmsId.intValue());
79+
parentSponsor.setLegalName(sponsorParentName);
80+
parentSponsor.setOrgName(sponsorParentName);
81+
sponsorService.saveSponsor(parentSponsor);
82+
}
83+
84+
Optional<Sponsor> sponsorOptional = sponsorService.findByHpmsIdAndParent(sponsorHpmsId.intValue(), parentSponsor);
85+
86+
Sponsor sponsor;
87+
if (!sponsorOptional.isPresent()) {
88+
sponsor = new Sponsor();
89+
} else {
90+
sponsor = sponsorOptional.get();
91+
}
92+
93+
log.info("Starting processing for sponsor {}", keyValue(SPONSOR_LOG, sponsorHpmsId));
94+
95+
sponsor.setHpmsId(sponsorHpmsId.intValue());
96+
sponsor.setLegalName(sponsorName);
97+
sponsor.setOrgName(sponsorName);
98+
sponsor.setParent(parentSponsor);
99+
100+
saveContractWithSponsor(sponsor, contractNumber, contractName, sponsorHpmsId);
101+
}
102+
103+
private void saveContractWithSponsor(Sponsor sponsor, String contractNumber, String contractName, Double sponsorHpmsId) {
104+
// Only add the contract if it doesn't already exist
105+
if (!sponsor.hasContract(contractNumber)) {
106+
Contract contract = new Contract();
107+
contract.setContractName(contractName);
108+
contract.setContractNumber(contractNumber);
109+
contract.setSponsor(sponsor);
110+
111+
sponsor.getContracts().add(contract);
112+
}
113+
114+
sponsorService.saveSponsor(sponsor);
115+
116+
log.info("Sponsor saved {}", keyValue(SPONSOR_LOG, sponsorHpmsId));
117+
}
112118
}

load-test/pom.xml

+6
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,12 @@
5353
</exclusion>
5454
</exclusions>
5555
</dependency>
56+
57+
<dependency>
58+
<groupId>org.apache.commons</groupId>
59+
<artifactId>commons-lang3</artifactId>
60+
<version>3.9</version>
61+
</dependency>
5662
</dependencies>
5763

5864
<build>

0 commit comments

Comments
 (0)