-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Committed the missing files and cleaned up unused import.
Committed the missing files and cleaned up unused import.
- Loading branch information
Showing
2 changed files
with
20 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 19 additions & 23 deletions
42
api/src/main/java/ca/bc/gov/educ/api/batchgraduation/reader/RegenerateCertificateReader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,37 @@ | ||
package ca.bc.gov.educ.api.batchgraduation.reader; | ||
|
||
import ca.bc.gov.educ.api.batchgraduation.model.AlgorithmSummaryDTO; | ||
import ca.bc.gov.educ.api.batchgraduation.model.StudentCredentialDistribution; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.batch.item.ItemReader; | ||
import org.springframework.beans.factory.annotation.Value; | ||
|
||
import java.util.UUID; | ||
import java.util.List; | ||
|
||
public class RegenerateCertificateReader extends BaseReader { | ||
public class RegenerateCertificateReader extends BaseReader implements ItemReader<StudentCredentialDistribution> { | ||
|
||
private static final Logger LOGGER = LoggerFactory.getLogger(RegenerateCertificateReader.class); | ||
|
||
@Value("#{stepExecutionContext['index']}") | ||
private Integer nxtCredentialForProcessing; | ||
|
||
@Value("#{stepExecutionContext['data']}") | ||
List<StudentCredentialDistribution> credentialList; | ||
|
||
@Override | ||
public UUID read() throws Exception { | ||
public StudentCredentialDistribution read() throws Exception { | ||
fetchAccessToken(); | ||
summaryDTO.setReadCount(studentList.size()); | ||
summaryDTO.setReadCount(credentialList.size()); | ||
|
||
UUID nextStudent = null; | ||
StudentCredentialDistribution nextCredential = null; | ||
|
||
if (nxtStudentForProcessing < studentList.size()) { | ||
nextStudent = studentList.get(nxtStudentForProcessing); | ||
LOGGER.info("StudID:{} - {} of {}", nextStudent, nxtStudentForProcessing + 1, summaryDTO.getReadCount()); | ||
nxtStudentForProcessing++; | ||
if (nxtCredentialForProcessing < credentialList.size()) { | ||
nextCredential = credentialList.get(nxtCredentialForProcessing); | ||
LOGGER.info("StudID:{} - {} of {}", nextCredential, nxtCredentialForProcessing + 1, summaryDTO.getReadCount()); | ||
nxtCredentialForProcessing++; | ||
} else { | ||
aggregate("regenCertSummaryDTO"); | ||
} | ||
return nextStudent; | ||
} | ||
|
||
public void aggregate(String summaryContextName) { | ||
AlgorithmSummaryDTO totalSummaryDTO = (AlgorithmSummaryDTO)jobExecution.getExecutionContext().get(summaryContextName); | ||
if (totalSummaryDTO == null) { | ||
totalSummaryDTO = new AlgorithmSummaryDTO(); | ||
jobExecution.getExecutionContext().put(summaryContextName, totalSummaryDTO); | ||
} | ||
totalSummaryDTO.setBatchId(summaryDTO.getBatchId()); | ||
totalSummaryDTO.setReadCount(totalSummaryDTO.getReadCount() + summaryDTO.getReadCount()); | ||
totalSummaryDTO.setProcessedCount(totalSummaryDTO.getProcessedCount() + summaryDTO.getProcessedCount()); | ||
totalSummaryDTO.getErrors().putAll(summaryDTO.getErrors()); | ||
return nextCredential; | ||
} | ||
} |