Skip to content

Commit

Permalink
Merge pull request #527 from bcgov/feature/GRAD2-2929
Browse files Browse the repository at this point in the history
GRAD2-2929: task is completed.
  • Loading branch information
infstar authored Sep 18, 2024
2 parents 2690e06 + 912aa46 commit aef7df2
Show file tree
Hide file tree
Showing 40 changed files with 1,205 additions and 1,564 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,18 @@
import org.springframework.batch.core.launch.JobLauncher;
import org.springframework.batch.core.launch.support.TaskExecutorJobLauncher;
import org.springframework.batch.core.repository.JobRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.core.task.SimpleAsyncTaskExecutor;
import org.springframework.core.task.SyncTaskExecutor;
import org.springframework.stereotype.Component;
import org.springframework.transaction.TransactionManager;

import javax.sql.DataSource;

@Configuration
@Profile("!test")
@Component
public class BatchConfig {

@Autowired
DataSource dataSource;

@Autowired
TransactionManager transactionManager;

@Bean(name = "asyncJobLauncher")
public JobLauncher asyncJobLauncher(JobRepository jobRepository) throws Exception {
TaskExecutorJobLauncher jobLauncher = new TaskExecutorJobLauncher();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.security.oauth2.client.*;
import org.springframework.security.oauth2.client.registration.ClientRegistrationRepository;
import org.springframework.security.oauth2.client.web.reactive.function.client.ServletOAuth2AuthorizedClientExchangeFilterFunction;
import org.springframework.web.reactive.function.client.ExchangeStrategies;
import org.springframework.web.reactive.function.client.WebClient;
import reactor.netty.http.client.HttpClient;
Expand All @@ -30,4 +33,35 @@ public WebClient webClient() {
.maxInMemorySize(300 * 1024 * 1024)) // 300 MB
.build()).build();
}

@Bean("batchClient")
public WebClient getBatchWebClient(OAuth2AuthorizedClientManager authorizedClientManager) {
ServletOAuth2AuthorizedClientExchangeFilterFunction filter = new ServletOAuth2AuthorizedClientExchangeFilterFunction(authorizedClientManager);
filter.setDefaultClientRegistrationId("batch-client");
return WebClient.builder()
.exchangeStrategies(ExchangeStrategies
.builder()
.codecs(codecs -> codecs
.defaultCodecs()
.maxInMemorySize(300 * 1024 * 1024)) // 300 MB
.build())
.apply(filter.oauth2Configuration())
.build();
}

@Bean
public OAuth2AuthorizedClientManager authorizedClientManager(
ClientRegistrationRepository clientRegistrationRepository,
OAuth2AuthorizedClientService clientService) {

OAuth2AuthorizedClientProvider authorizedClientProvider =
OAuth2AuthorizedClientProviderBuilder.builder()
.clientCredentials()
.build();
AuthorizedClientServiceOAuth2AuthorizedClientManager authorizedClientManager =
new AuthorizedClientServiceOAuth2AuthorizedClientManager(clientRegistrationRepository, clientService);
authorizedClientManager.setAuthorizedClientProvider(authorizedClientProvider);

return authorizedClientManager;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -183,10 +183,9 @@ public ResponseEntity<BatchJobResponse> launchTvrRunJob() {
@PreAuthorize(PermissionsConstants.LOAD_STUDENT_IDS)
@Operation(summary = "Load Students to GRAD", description = "Load Students to GRAD", tags = { "Student" })
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "OK"),@ApiResponse(responseCode = "500", description = "Internal Server Error")})
public ResponseEntity<String> loadStudentIDs(@RequestBody List<LoadStudentData> loadStudentData,
@RequestHeader(name="Authorization") String accessToken) {
public ResponseEntity<String> loadStudentIDs(@RequestBody List<LoadStudentData> loadStudentData) {
logger.debug("Inside loadStudentIDs");
Integer recordsAdded = restUtils.getStudentByPenFromStudentAPI(loadStudentData, accessToken.replace(BEARER, ""));
Integer recordsAdded = restUtils.getStudentByPenFromStudentAPI(loadStudentData);
if(recordsAdded != null)
return ResponseEntity.ok("Record Added Successfully");
return ResponseEntity.status(500).body("Student Record Could not be added");
Expand All @@ -210,10 +209,9 @@ public ResponseEntity<GradDashboard> loadDashboard() {
@Operation(summary = "Load Error students in batch runs", description = "Load Error students in batch runs", tags = { "Dashboard" })
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "OK"),@ApiResponse(responseCode = "204", description = "No Content")})
public ResponseEntity<ErrorDashBoard> loadError(@PathVariable Long batchId, @RequestParam(name = "pageNumber", defaultValue = "0") Integer pageNumber,
@RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
@RequestHeader(name="Authorization") String accessToken) {
@RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize) {
logger.debug("Inside loadError");
ErrorDashBoard dash = gradDashboardService.getErrorInfo(batchId,pageNumber,pageSize,accessToken.replace(BEARER, ""));
ErrorDashBoard dash = gradDashboardService.getErrorInfo(batchId,pageNumber,pageSize);
if(dash == null) {
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ protected void handleSummary(JobExecution jobExecution, String summaryDtoName, b

ResponseObj obj = restUtils.getTokenResponseObject();
if (!isSpecialRun) {
updateBackStudentFlagForErroredStudents(summaryDTO.getErrors(), jobType, obj.getAccess_token());
updateBackStudentFlagForErroredStudents(summaryDTO.getErrors(), jobType);
}
processSchoolList(jobExecutionId, jobType);
}
Expand All @@ -110,11 +110,11 @@ private void processBatchJobHistory(AlgorithmSummaryDTO summaryDTO, Long jobExec
gradBatchHistoryService.saveGradAlgorithmJobHistory(ent);
}

private void updateBackStudentFlagForErroredStudents(Map<UUID, ProcessError> errors, String jobType, String accessToken) {
private void updateBackStudentFlagForErroredStudents(Map<UUID, ProcessError> errors, String jobType) {
List<UUID> erroredStudentIDs = new ArrayList<>(errors.keySet());
if (!erroredStudentIDs.isEmpty()) {
LOGGER.info(" Update Student Flags: [{}] for {} errored students ----------------------------", jobType, erroredStudentIDs.size());
String result = restUtils.updateStudentFlagReadyForBatch(erroredStudentIDs, jobType, accessToken);
String result = restUtils.updateStudentFlagReadyForBatch(erroredStudentIDs, jobType);
LOGGER.info(" Update Student Flags completed {} ----------------------------", result);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,12 @@ private void processGradStudentRecordJobHistory(JobExecution jobExecution) {

JobParameters jobParameters = jobExecution.getJobParameters();
Long batchId = jobExecution.getId();
String accessToken = restUtils.fetchAccessToken();
String userName = jobParameters.getString(RUN_BY);

String searchRequest = jobParameters.getString(SEARCH_REQUEST, "{}");
StudentSearchRequest req = (StudentSearchRequest)jsonTransformer.unmarshall(searchRequest, StudentSearchRequest.class);

restUtils.updateStudentGradRecordHistory(List.of(), batchId, accessToken, userName, StringUtils.upperCase(req.getActivityCode()));
restUtils.updateStudentGradRecordHistory(List.of(), batchId, userName, StringUtils.upperCase(req.getActivityCode()));
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
@JsonSerialize
public class AlgorithmSummaryDTO extends BaseSummaryDTO {

// List<UUID> successfulStudentIDs = new ArrayList<>();
private Map<UUID,ProcessError> errors = new HashMap<>();

public void updateError(UUID studentID,String errMsg, String errorDesc) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,7 @@ private List<StudentCredentialDistribution> getStudentsForUserReqRun(Certificate

private UUID getStudentIDByPen(String pen) {
try {
String accessToken = restUtils.fetchAccessToken();
return restUtils.getStudentIDByPen(pen, accessToken);
return restUtils.getStudentIDByPen(pen);
} catch (Exception e) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ public class RegenerateCertificateReader extends BaseReader implements ItemReade

@Override
public StudentCredentialDistribution read() throws Exception {
fetchAccessToken();
summaryDTO.setReadCount(credentialList.size());

StudentCredentialDistribution nextCredential = null;
Expand Down
Loading

0 comments on commit aef7df2

Please sign in to comment.