diff --git a/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/processor/RunCertificateRegenerationProcessor.java b/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/processor/RunCertificateRegenerationProcessor.java index f78c2dd5..95101ac8 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/processor/RunCertificateRegenerationProcessor.java +++ b/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/processor/RunCertificateRegenerationProcessor.java @@ -4,7 +4,6 @@ import ca.bc.gov.educ.api.batchgraduation.model.GraduationStudentRecordDistribution; import ca.bc.gov.educ.api.batchgraduation.model.StudentCredentialDistribution; import ca.bc.gov.educ.api.batchgraduation.rest.RestUtils; -import jakarta.validation.ValidationException; import jakarta.validation.constraints.NotNull; import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; @@ -15,7 +14,6 @@ import org.springframework.lang.Nullable; import java.io.IOException; -import java.net.UnknownServiceException; import java.util.UUID; public class RunCertificateRegenerationProcessor implements ItemProcessor { @@ -55,7 +53,7 @@ public Integer process(@NotNull StudentCredentialDistribution item) throws Excep return null; } } - LOGGER.warn("Skipped STU-ID:{} Errors:{}", item != null? item.getStudentID() : "UNKNOWN PEN#",summaryDTO.getErrors().size()); + LOGGER.warn("Skipped STU-ID:{} Errors:{}", item != null? item.getStudentID() : "UNKNOWN STUDENT",summaryDTO.getErrors().size()); return null; } diff --git a/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/reader/RegenerateCertificateReader.java b/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/reader/RegenerateCertificateReader.java index cd1ea8d5..fbc450b2 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/reader/RegenerateCertificateReader.java +++ b/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/reader/RegenerateCertificateReader.java @@ -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 { private static final Logger LOGGER = LoggerFactory.getLogger(RegenerateCertificateReader.class); + @Value("#{stepExecutionContext['index']}") + private Integer nxtCredentialForProcessing; + + @Value("#{stepExecutionContext['data']}") + List 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; } }