-
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.
Merge pull request #490 from bcgov/feature/GRAD2-2724
GRAD2-2724: task is completed.
- Loading branch information
Showing
22 changed files
with
298 additions
and
211 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
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
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
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
38 changes: 38 additions & 0 deletions
38
api/src/main/java/ca/bc/gov/educ/api/batchgraduation/reader/BaseStudentReader.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 |
---|---|---|
@@ -0,0 +1,38 @@ | ||
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.ResponseObj; | ||
import ca.bc.gov.educ.api.batchgraduation.rest.RestUtils; | ||
import org.springframework.batch.core.JobExecution; | ||
import org.springframework.batch.item.ItemReader; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.beans.factory.annotation.Value; | ||
|
||
import java.util.List; | ||
import java.util.UUID; | ||
|
||
public abstract class BaseStudentReader implements ItemReader<UUID> { | ||
|
||
@SuppressWarnings("SpringJavaInjectionPointsAutowiringInspection") | ||
@Autowired | ||
RestUtils restUtils; | ||
|
||
@Value("#{stepExecutionContext['index']}") | ||
protected Integer nxtStudentForProcessing; | ||
|
||
@Value("#{stepExecutionContext['data']}") | ||
protected List<UUID> studentList; | ||
|
||
@Value("#{stepExecutionContext['summary']}") | ||
AlgorithmSummaryDTO summaryDTO; | ||
|
||
@Value("#{stepExecution.jobExecution}") | ||
JobExecution jobExecution; | ||
|
||
protected void fetchAccessToken() { | ||
ResponseObj res = restUtils.getTokenResponseObject(); | ||
if (res != null) { | ||
summaryDTO.setAccessToken(res.getAccess_token()); | ||
} | ||
} | ||
} |
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
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
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
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
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
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
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; | ||
} | ||
} |
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
Oops, something went wrong.