Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GRAD2-2325: option is added into EDW snapshot batch. #440

Merged
merged 2 commits into from
Oct 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.math.NumberUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.batch.core.JobExecution;
Expand Down Expand Up @@ -775,44 +774,11 @@ public ResponseEntity<BatchJobResponse> launchUserReqCertRegenJob(@RequestBody C
}
}

@GetMapping(EducGradBatchGraduationApiConstants.EXECUTE_EDW_SNAPSHOT_BATCH_JOB)
@PreAuthorize(PermissionsConstants.RUN_GRAD_ALGORITHM)
@Operation(summary = "Run EDW Snapshot Job", description = "Run EDW Snapshot Job", tags = { "EDW Snapshot" })
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "OK"),@ApiResponse(responseCode = "500", description = "Internal Server Error")})
public ResponseEntity<BatchJobResponse> launchEdwSnapshotJob(@PathVariable String gradYear) {
logger.debug("launchEdwSnapshotJob");
BatchJobResponse response = new BatchJobResponse();
JobParametersBuilder builder = new JobParametersBuilder();
builder.addLong(TIME, System.currentTimeMillis()).toJobParameters();
builder.addString(RUN_BY, ThreadLocalStateUtil.getCurrentUser());
builder.addString(JOB_TRIGGER, MANUAL);
builder.addString(JOB_TYPE, EDW_SNAPSHOT);

SnapshotRequest snapshotRequest = new SnapshotRequest();
snapshotRequest.setGradYear(StringUtils.isNotBlank(gradYear) && NumberUtils.isCreatable(gradYear)? Integer.parseInt(gradYear) : Year.now().getValue());
response.setJobType(EDW_SNAPSHOT);
response.setTriggerBy(MANUAL);
response.setStartTime(LocalDateTime.now());
response.setStatus(BatchStatusEnum.STARTED.name());

try {
String searchData = jsonTransformer.marshall(snapshotRequest);
builder.addString(SEARCH_REQUEST, searchData);
JobExecution jobExecution = asyncJobLauncher.run(jobRegistry.getJob(EDW_SNAPSHOT_BATCH_JOB), builder.toJobParameters());
response.setBatchId(jobExecution.getId());
return ResponseEntity.ok(response);
} catch (JobExecutionAlreadyRunningException | JobRestartException | JobInstanceAlreadyCompleteException
| JobParametersInvalidException | NoSuchJobException | IllegalArgumentException e) {
response.setException(e.getLocalizedMessage());
return ResponseEntity.status(500).body(response);
}
}

@PostMapping(EducGradBatchGraduationApiConstants.EXECUTE_EDW_SNAPSHOT_BATCH_JOB)
@PreAuthorize(PermissionsConstants.RUN_GRAD_ALGORITHM)
@Operation(summary = "Run User Req EDW Snapshot Job", description = "Run User Req EDW Snapshot Job", tags = { "EDW Snapshot" })
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "OK"),@ApiResponse(responseCode = "500", description = "Internal Server Error")})
public ResponseEntity<BatchJobResponse> launchUserReqEdwSnapshotJob(@RequestBody SnapshotRequest snapshotRequest) {
public ResponseEntity<BatchJobResponse> launchEdwSnapshotJob(@RequestBody SnapshotRequest snapshotRequest) {
logger.debug("launchUserReqEdwSnapshotJob");
BatchJobResponse response = new BatchJobResponse();
JobParametersBuilder builder = new JobParametersBuilder();
Expand All @@ -823,6 +789,9 @@ public ResponseEntity<BatchJobResponse> launchUserReqEdwSnapshotJob(@RequestBody
if (snapshotRequest != null && snapshotRequest.getGradYear() == null) {
snapshotRequest.setGradYear(Year.now().getValue());
}
if (snapshotRequest != null && StringUtils.isBlank(snapshotRequest.getOption())) {
snapshotRequest.setOption("L");
}
response.setJobType(EDW_SNAPSHOT);
response.setTriggerBy(MANUAL);
response.setStartTime(LocalDateTime.now());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@
@NoArgsConstructor
public class EdwSnapshotSchoolSummaryDTO extends BaseSummaryDTO {
private Integer gradYear;
private String option; // A = All current students, L = All grad students + nongrad students(12, AD)
private List<SnapshotResponse> globalList = new ArrayList<>();
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@
@NoArgsConstructor
public class SnapshotRequest {
private Integer gradYear;
private String option; // A = All current students, L = All grad students + nongrad students(12, AD)
private List<String> schoolOfRecords;
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ public class SnapshotResponse {
private BigDecimal gpa;
private String honourFlag;
private String schoolOfRecord;
private String studentGrade;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import ca.bc.gov.educ.api.batchgraduation.model.EdwSnapshotSchoolSummaryDTO;
import ca.bc.gov.educ.api.batchgraduation.model.SnapshotResponse;
import ca.bc.gov.educ.api.batchgraduation.rest.RestUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.tuple.Pair;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -11,6 +12,7 @@
import org.springframework.beans.factory.annotation.Value;

import java.util.List;
import java.util.stream.Collectors;

public class EDWSnapshotSchoolProcessor implements ItemProcessor<String, List<Pair<String, List<SnapshotResponse>>>> {

Expand All @@ -30,6 +32,11 @@ public List<Pair<String, List<SnapshotResponse>>> process(String mincode) throws
summaryDTO.setBatchId(batchId);
LOGGER.debug("Processing partitionData for School: {} ", mincode);
List<SnapshotResponse> edwStudents = restUtils.getEDWSnapshotStudents(summaryDTO.getGradYear(), mincode, summaryDTO.getAccessToken());
if ("L".equals(summaryDTO.getOption())) {
List<SnapshotResponse> list = edwStudents.stream().filter(s -> StringUtils.isNotBlank(s.getGraduatedDate()) ||
("12".equals(s.getStudentGrade()) || "AD".equals(s.getStudentGrade()))).toList();
return List.of(Pair.of(mincode, list));
}
return List.of(Pair.of(mincode, edwStudents));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public Map<String, ExecutionContext> partition(int gridSize) {
ExecutionContext executionContext = new ExecutionContext();
EdwSnapshotSchoolSummaryDTO summaryDTO = new EdwSnapshotSchoolSummaryDTO();
summaryDTO.setGradYear(req.getGradYear());
summaryDTO.setOption(req.getOption());
List<String> data = partitions.get(i);
executionContext.put("data", data);
summaryDTO.setReadCount(data.size());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class EducGradBatchGraduationApiConstants {
public static final String EXECUTE_SUPP_DIS_RUN_BATCH_JOB = "/executesuppdisrunbatchjob";
public static final String EXECUTE_YEARLY_NON_GRAD_DIS_RUN_BATCH_JOB = "/executenongraddisrunbatchjob";
public static final String EXECUTE_CERT_REGEN_BATCH_JOB = "/executecertregenbatchjob";
public static final String EXECUTE_EDW_SNAPSHOT_BATCH_JOB = "/executeedwsnapshotbatchjob/{gradYear}";
public static final String EXECUTE_EDW_SNAPSHOT_BATCH_JOB = "/executeedwsnapshotbatchjob";

// Special Run
public static final String EXECUTE_SPECIALIZED_RUNS = "/specialrun";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -579,30 +579,12 @@ public void testLaunchEDWSnapshotJob() {
builder.addString(JOB_TRIGGER, MANUAL);
builder.addString(JOB_TYPE, EDWSNAPSHOTRUN);

try {
org.mockito.Mockito.when(asyncJobLauncher.run(jobRegistry.getJob(EDWSNAPSHOTRUN), builder.toJobParameters())).thenReturn(new JobExecution(210L));
jobLauncherController.launchEdwSnapshotJob("2023");
} catch (Exception e) {
exceptionIsThrown = true;
}

assertThat(builder).isNotNull();
}

@Test
public void testLaunchUserReqEDWSnapshotJob() {
boolean exceptionIsThrown = false;
JobParametersBuilder builder = new JobParametersBuilder();
builder.addLong(TIME, System.currentTimeMillis()).toJobParameters();
builder.addString(JOB_TRIGGER, MANUAL);
builder.addString(JOB_TYPE, EDWSNAPSHOTRUN);

SnapshotRequest req = new SnapshotRequest();
req.setGradYear(Integer.parseInt("2023"));

try {
org.mockito.Mockito.when(asyncJobLauncher.run(jobRegistry.getJob(EDWSNAPSHOTRUN), builder.toJobParameters())).thenReturn(new JobExecution(210L));
jobLauncherController.launchUserReqEdwSnapshotJob(req);
jobLauncherController.launchEdwSnapshotJob(req);
} catch (Exception e) {
exceptionIsThrown = true;
}
Expand Down
Loading