Skip to content

Commit

Permalink
Merge pull request #474 from bcgov/develop/alex-GRAD2-2570
Browse files Browse the repository at this point in the history
GRAD2-2570
  • Loading branch information
arybakov-cgi authored Apr 12, 2024
2 parents c870ce2 + d38ea0a commit ce3063b
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 37 deletions.
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
package ca.bc.gov.educ.api.batchgraduation.model;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.stereotype.Component;

import java.io.Serializable;
import java.util.List;

@Data
@Component
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class CertificateRegenerationRequest implements Serializable {
private List<String> pens;
public class CertificateRegenerationRequest extends StudentSearchRequest {
private String runMode; // "Y" or "N"

public boolean runForAll () {
return (getPens() == null || getPens().isEmpty()) &&
(getDistricts() == null || getDistricts().isEmpty()) &&
(getSchoolOfRecords() == null || getSchoolOfRecords().isEmpty()) &&
(getSchoolCategoryCodes() == null || getSchoolCategoryCodes().isEmpty()) &&
(getStudentIDs() == null || getStudentIDs().isEmpty());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import org.springframework.stereotype.Component;

import java.io.Serializable;
import java.util.Date;
import java.time.LocalDate;
import java.util.List;
import java.util.UUID;

Expand All @@ -29,9 +29,9 @@ public class StudentSearchRequest implements Serializable {
private Address address;

@JsonFormat(pattern = "yyyy-MM-dd")
Date gradDateFrom;
LocalDate gradDateFrom;
@JsonFormat(pattern = "yyyy-MM-dd")
Date gradDateTo;
LocalDate gradDateTo;

Boolean validateInput;
String localDownload;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

import ca.bc.gov.educ.api.batchgraduation.model.*;
import ca.bc.gov.educ.api.batchgraduation.service.ParallelDataFetch;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.commons.lang3.StringUtils;
import ca.bc.gov.educ.api.batchgraduation.util.JsonTransformer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.batch.core.JobExecution;
Expand All @@ -29,6 +27,9 @@ public class RegenerateCertificatePartitioner extends BasePartitioner {
@Autowired
ParallelDataFetch parallelDataFetch;

@Autowired
JsonTransformer jsonTransformer;

@Override
public Map<String, ExecutionContext> partition(int gridSize) {
ResponseObj res = restUtils.getTokenResponseObject();
Expand All @@ -39,14 +40,15 @@ public Map<String, ExecutionContext> partition(int gridSize) {
List<StudentCredentialDistribution> credentialList = new ArrayList<>();
JobParameters jobParameters = context.getJobParameters();
String searchRequest = jobParameters.getString(SEARCH_REQUEST);
if (StringUtils.isBlank(searchRequest)) {
CertificateRegenerationRequest certificateRegenerationRequest = (CertificateRegenerationRequest)jsonTransformer.unmarshall(searchRequest, CertificateRegenerationRequest.class);
if (certificateRegenerationRequest.runForAll()) {
Mono<DistributionDataParallelDTO> parallelDTOMono = parallelDataFetch.fetchDistributionRequiredData();
DistributionDataParallelDTO parallelDTO = parallelDTOMono.block();
if(parallelDTO != null) {
credentialList.addAll(parallelDTO.certificateList());
}
} else {
credentialList.addAll(getStudentsForUserReqRun(searchRequest, accessToken));
credentialList.addAll(getStudentsForUserReqRun(certificateRegenerationRequest, accessToken));
}

Set<UUID> studentSet = new HashSet<>();
Expand Down Expand Up @@ -82,30 +84,12 @@ public Map<String, ExecutionContext> partition(int gridSize) {
return new HashMap<>();
}

private List<StudentCredentialDistribution> getStudentsForDistRun(String accessToken) {
List<StudentCredentialDistribution> credentialList = new ArrayList<>();
Mono<DistributionDataParallelDTO> parallelDTOMono = parallelDataFetch.fetchDistributionRequiredData();
DistributionDataParallelDTO parallelDTO = parallelDTOMono.block();
if(parallelDTO != null) {
credentialList.addAll(parallelDTO.certificateList());
}
return credentialList;
}

// retrieve students based on the search criteria requested by user
private List<StudentCredentialDistribution> getStudentsForUserReqRun(String searchRequest, String accessToken) {
CertificateRegenerationRequest certRegenReq = null;
try {
certRegenReq = new ObjectMapper().readValue(searchRequest, CertificateRegenerationRequest.class);
} catch (JsonProcessingException e) {
e.printStackTrace();
}
if (certRegenReq != null && "Y".equalsIgnoreCase(certRegenReq.getRunMode())) {
StudentSearchRequest req = new StudentSearchRequest();
req.setPens(certRegenReq.getPens());
return restUtils.getStudentsForUserReqDisRun("OC", req);
private List<StudentCredentialDistribution> getStudentsForUserReqRun(CertificateRegenerationRequest certificateRegenerationRequest, String accessToken) {
if(certificateRegenerationRequest != null && "Y".equalsIgnoreCase(certificateRegenerationRequest.getRunMode())) {
return restUtils.getStudentsForUserReqDisRun("OC", certificateRegenerationRequest);
} else {
return getStudentsForDistRun(accessToken);
return new ArrayList<>();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public UUID read() throws Exception {
nextStudent = studentList.get(nxtStudentForProcessing);
LOGGER.info("StudID:{} - {} of {}", nextStudent, nxtStudentForProcessing + 1, summaryDTO.getReadCount());
nxtStudentForProcessing++;
summaryDTO.setProcessedCount(nxtStudentForProcessing);
} else {
aggregate("regenCertSummaryDTO");
}
Expand Down

0 comments on commit ce3063b

Please sign in to comment.