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

Develop/alex grad2 2283 #511

Merged
merged 3 commits into from
Aug 13, 2024
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
@@ -1,15 +1,13 @@
package ca.bc.gov.educ.api.batchgraduation.listener;

import ca.bc.gov.educ.api.batchgraduation.model.DistributionSummaryDTO;
import ca.bc.gov.educ.api.batchgraduation.service.GradBatchHistoryService;
import ca.bc.gov.educ.api.batchgraduation.util.DateUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.batch.core.BatchStatus;
import org.springframework.batch.core.JobExecution;
import org.springframework.batch.core.JobParameters;
import org.springframework.batch.item.ExecutionContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Date;
Expand All @@ -20,9 +18,6 @@
public class ArchiveSchoolReportsCompletionNotificationListener extends BaseDistributionRunCompletionNotificationListener {

private static final Logger LOGGER = LoggerFactory.getLogger(ArchiveSchoolReportsCompletionNotificationListener.class);

@Autowired
private GradBatchHistoryService gradBatchHistoryService;

@Override
public void afterJob(JobExecution jobExecution) {
Expand All @@ -49,6 +44,8 @@ public void afterJob(JobExecution jobExecution) {
LOGGER.info(" --------------------------------------------------------------------------------------");
LOGGER.info("Errors:{}", summaryDTO.getErrors().size());

updateUserSchedulingJobs(jobParameters);

String jobParametersDTO = buildJobParametersDTO(jobType, studentSearchRequest, null, null);
// save batch job & error history
processBatchJobHistory(summaryDTO, jobExecutionId, status, jobTrigger, jobType, startTime, endTime, jobParametersDTO);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
package ca.bc.gov.educ.api.batchgraduation.listener;

import ca.bc.gov.educ.api.batchgraduation.model.DistributionSummaryDTO;
import ca.bc.gov.educ.api.batchgraduation.service.GradBatchHistoryService;
import ca.bc.gov.educ.api.batchgraduation.util.DateUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.batch.core.BatchStatus;
import org.springframework.batch.core.JobExecution;
import org.springframework.batch.core.JobParameters;
import org.springframework.batch.item.ExecutionContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Date;
Expand All @@ -20,9 +18,6 @@
public class ArchiveStudentsCompletionNotificationListener extends BaseDistributionRunCompletionNotificationListener {

private static final Logger LOGGER = LoggerFactory.getLogger(ArchiveStudentsCompletionNotificationListener.class);

@Autowired
private GradBatchHistoryService gradBatchHistoryService;

@Override
public void afterJob(JobExecution jobExecution) {
Expand All @@ -49,6 +44,8 @@ public void afterJob(JobExecution jobExecution) {
LOGGER.info(" --------------------------------------------------------------------------------------");
LOGGER.info("Errors:{}", summaryDTO.getErrors().size());

updateUserSchedulingJobs(jobParameters);

String jobParametersDTO = buildJobParametersDTO(jobType, studentSearchRequest, null, null);
// save batch job & error history
processBatchJobHistory(summaryDTO, jobExecutionId, status, jobTrigger, jobType, startTime, endTime, jobParametersDTO);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import ca.bc.gov.educ.api.batchgraduation.rest.RestUtils;
import ca.bc.gov.educ.api.batchgraduation.service.DistributionService;
import ca.bc.gov.educ.api.batchgraduation.service.GradBatchHistoryService;
import ca.bc.gov.educ.api.batchgraduation.service.TaskSchedulingService;
import ca.bc.gov.educ.api.batchgraduation.util.DateUtils;
import ca.bc.gov.educ.api.batchgraduation.util.GradSorter;
import ca.bc.gov.educ.api.batchgraduation.util.JsonTransformer;
Expand All @@ -13,12 +14,15 @@
import org.slf4j.LoggerFactory;
import org.springframework.batch.core.JobExecution;
import org.springframework.batch.core.JobExecutionListener;
import org.springframework.batch.core.JobParameters;
import org.springframework.beans.factory.annotation.Autowired;

import java.time.ZoneId;
import java.util.Date;
import java.util.List;

import static ca.bc.gov.educ.api.batchgraduation.util.EducGradBatchGraduationApiConstants.USER_SCHEDULED;

public abstract class BaseDistributionRunCompletionNotificationListener implements JobExecutionListener {

private static final Logger LOGGER = LoggerFactory.getLogger(BaseDistributionRunCompletionNotificationListener.class);
Expand All @@ -32,6 +36,9 @@ public abstract class BaseDistributionRunCompletionNotificationListener implemen
@Autowired
DistributionService distributionService;

@Autowired
private TaskSchedulingService taskSchedulingService;

@Autowired
RestUtils restUtils;

Expand Down Expand Up @@ -140,4 +147,11 @@ void filterStudentCredentialDistribution(List<StudentCredentialDistribution> cre
long getElapsedTimeMillis(JobExecution jobExecution) {
return new Date().getTime() - jobExecution.getStartTime().atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
}

void updateUserSchedulingJobs(JobParameters jobParameters) {
String userScheduledId = jobParameters.getString(USER_SCHEDULED);
if (userScheduledId != null) {
taskSchedulingService.updateUserScheduledJobs(userScheduledId);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ protected void handleSummary(JobExecution jobExecution, String summaryDtoName, b
}

if (isSpecialRun) {
String userScheduledId = jobParameters.getString("userScheduled");
String userScheduledId = jobParameters.getString(USER_SCHEDULED);
if (userScheduledId != null) {
taskSchedulingService.updateUserScheduledJobs(userScheduledId);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package ca.bc.gov.educ.api.batchgraduation.listener;

import ca.bc.gov.educ.api.batchgraduation.model.*;
import ca.bc.gov.educ.api.batchgraduation.service.TaskSchedulingService;
import ca.bc.gov.educ.api.batchgraduation.util.DateUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
Expand All @@ -28,9 +27,6 @@ public class UserReqBlankDistributionRunCompletionNotificationListener extends B
private static final String LOG_SEPARATION = "=======================================================================================";
private static final String LOG_SEPARATION_SINGLE = " --------------------------------------------------------------------------------------";

@Autowired
private TaskSchedulingService taskSchedulingService;

@Autowired
SupportListener supportListener;

Expand All @@ -53,10 +49,7 @@ public void afterJob(JobExecution jobExecution) {
String localDownLoad = jobParameters.getString("LocalDownload");
String properName = jobParameters.getString("properName");
String studentSearchRequest = jobParameters.getString(SEARCH_REQUEST, "{}");
String userScheduledId = jobParameters.getString("userScheduled");
if(userScheduledId != null) {
taskSchedulingService.updateUserScheduledJobs(userScheduledId);
}
updateUserSchedulingJobs(jobParameters);
BlankDistributionSummaryDTO summaryDTO = (BlankDistributionSummaryDTO) jobContext.get("blankDistributionSummaryDTO");
if(summaryDTO == null) {
summaryDTO = new BlankDistributionSummaryDTO();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
import ca.bc.gov.educ.api.batchgraduation.model.*;
import ca.bc.gov.educ.api.batchgraduation.rest.RestUtils;
import ca.bc.gov.educ.api.batchgraduation.service.GraduationReportService;
import ca.bc.gov.educ.api.batchgraduation.service.ParallelDataFetch;
import ca.bc.gov.educ.api.batchgraduation.service.TaskSchedulingService;
import ca.bc.gov.educ.api.batchgraduation.util.DateUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
Expand All @@ -30,17 +28,13 @@ public class UserReqDistributionRunCompletionNotificationListener extends BaseDi
private static final String LOG_SEPARATION = "=======================================================================================";
private static final String LOG_SEPARATION_SINGLE = " --------------------------------------------------------------------------------------";

@Autowired
TaskSchedulingService taskSchedulingService;
@Autowired
GraduationReportService graduationReportService;
@Autowired
RestUtils restUtils;
@Autowired
SupportListener supportListener;

ParallelDataFetch parallelDataFetch;

@Override
public void afterJob(JobExecution jobExecution) {
if (jobExecution.getStatus() == BatchStatus.COMPLETED) {
Expand All @@ -60,10 +54,7 @@ public void afterJob(JobExecution jobExecution) {
String credentialType = jobParameters.getString("credentialType");
String properName = jobParameters.getString("properName");
String studentSearchRequest = jobParameters.getString(SEARCH_REQUEST, "{}");
String userScheduledId = jobParameters.getString("userScheduled");
if(userScheduledId != null) {
taskSchedulingService.updateUserScheduledJobs(userScheduledId);
}
updateUserSchedulingJobs(jobParameters);

DistributionSummaryDTO summaryDTO = (DistributionSummaryDTO)jobContext.get("distributionSummaryDTO");
if(summaryDTO == null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package ca.bc.gov.educ.api.batchgraduation.listener;

import ca.bc.gov.educ.api.batchgraduation.model.*;
import ca.bc.gov.educ.api.batchgraduation.service.TaskSchedulingService;
import ca.bc.gov.educ.api.batchgraduation.util.DateUtils;
import ca.bc.gov.educ.api.batchgraduation.util.EducGradBatchGraduationApiConstants;
import org.apache.commons.lang3.StringUtils;
Expand All @@ -25,12 +24,10 @@ public class UserReqPsiDistributionRunCompletionNotificationListener extends Bas
private static final String LOG_SEPARATION = "=======================================================================================";
private static final String LOG_SEPARATION_SINGLE = " --------------------------------------------------------------------------------------";

private TaskSchedulingService taskSchedulingService;
private SupportListener supportListener;

@Autowired
public UserReqPsiDistributionRunCompletionNotificationListener(TaskSchedulingService taskSchedulingService, SupportListener supportListener) {
this.taskSchedulingService = taskSchedulingService;
public UserReqPsiDistributionRunCompletionNotificationListener(SupportListener supportListener) {
this.supportListener = supportListener;
}

Expand All @@ -51,10 +48,7 @@ public void afterJob(JobExecution jobExecution) {
String transmissionType = jobParameters.getString(EducGradBatchGraduationApiConstants.TRANSMISSION_TYPE);
String studentSearchRequest = jobParameters.getString(EducGradBatchGraduationApiConstants.SEARCH_REQUEST, "{}");

String userScheduledId = jobParameters.getString(EducGradBatchGraduationApiConstants.USER_SCHEDULED);
if(userScheduledId != null) {
taskSchedulingService.updateUserScheduledJobs(userScheduledId);
}
updateUserSchedulingJobs(jobParameters);

PsiDistributionSummaryDTO summaryDTO = (PsiDistributionSummaryDTO)jobContext.get("psiDistributionSummaryDTO");
if(summaryDTO == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.util.UUID;

import static ca.bc.gov.educ.api.batchgraduation.util.EducGradBatchGraduationApiConstants.SEARCH_REQUEST;
import static ca.bc.gov.educ.api.batchgraduation.util.EducGradBatchGraduationApiConstants.USER_SCHEDULED;

@Service
public class TaskDefinition implements Runnable {
Expand Down Expand Up @@ -71,7 +72,7 @@ public void run() {
builder.addString(TRANMISSION_TYPE,task.getTransmissionType());
}
if(task.getJobIdReference() != null) {
builder.addString("userScheduled",task.getJobIdReference().toString());
builder.addString(USER_SCHEDULED,task.getJobIdReference().toString());
if (!isTaskRunnable(task.getJobIdReference())) {
LOGGER.error("{} should be QUEUED status for the given jobId, {}", task.getJobName(), task.getJobIdReference());
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,12 @@
import org.springframework.web.reactive.function.client.WebClient;

import java.time.LocalDateTime;
import java.util.*;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

import static ca.bc.gov.educ.api.batchgraduation.util.EducGradBatchGraduationApiConstants.SEARCH_REQUEST;
import static ca.bc.gov.educ.api.batchgraduation.util.EducGradBatchGraduationApiConstants.USER_SCHEDULED;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.MockitoAnnotations.openMocks;

Expand Down Expand Up @@ -122,7 +125,7 @@ public void testAfterJob_witherror() throws JobInstanceAlreadyCompleteException,
builder.addLong(TIME, System.currentTimeMillis()).toJobParameters();
builder.addString(JOB_TRIGGER, "MANUAL");
builder.addString(JOB_TYPE, "TVRRUN");
builder.addString("userScheduled", UUID.randomUUID().toString());
builder.addString(USER_SCHEDULED, UUID.randomUUID().toString());

JobExecution jobExecution = new JobExecution(121L);
jobExecution.setStatus(BatchStatus.COMPLETED);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import java.util.List;
import java.util.UUID;

import static ca.bc.gov.educ.api.batchgraduation.util.EducGradBatchGraduationApiConstants.USER_SCHEDULED;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.MockitoAnnotations.openMocks;

Expand Down Expand Up @@ -90,7 +91,7 @@ public void testAfterJob() throws JobInstanceAlreadyCompleteException, JobExecut
builder.addString(JOB_TRIGGER, "MANUAL");
builder.addString(JOB_TYPE, "TVRRUN");
builder.addString("credentialType","OT");
builder.addString("userScheduled", UUID.randomUUID().toString());
builder.addString(USER_SCHEDULED, UUID.randomUUID().toString());

JobExecution jobExecution = new JobExecution(new JobInstance(121L,"UserReqDistributionBatchJob"), 121L, builder.toJobParameters());
jobExecution.setStatus(BatchStatus.COMPLETED);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import java.util.UUID;
import java.util.function.Consumer;

import static ca.bc.gov.educ.api.batchgraduation.util.EducGradBatchGraduationApiConstants.USER_SCHEDULED;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.when;
Expand Down Expand Up @@ -91,7 +92,7 @@ public void testAfterJob() throws JobInstanceAlreadyCompleteException, JobExecut
builder.addString(JOB_TRIGGER, "MANUAL");
builder.addString(JOB_TYPE, "TVRRUN");
builder.addString("credentialType","OT");
builder.addString("userScheduled", UUID.randomUUID().toString());
builder.addString(USER_SCHEDULED, UUID.randomUUID().toString());

JobExecution jobExecution = new JobExecution(new JobInstance(121L,"UserReqDistributionBatchJob"), 121L, builder.toJobParameters());
jobExecution.setStatus(BatchStatus.COMPLETED);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import java.util.List;
import java.util.UUID;

import static ca.bc.gov.educ.api.batchgraduation.util.EducGradBatchGraduationApiConstants.USER_SCHEDULED;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.MockitoAnnotations.openMocks;

Expand Down Expand Up @@ -89,7 +90,7 @@ public void testAfterJob() throws JobInstanceAlreadyCompleteException, JobExecut
builder.addString(JOB_TRIGGER, "MANUAL");
builder.addString(JOB_TYPE, "PSIRUN");
builder.addString("transmissionType","FTP");
builder.addString("userScheduled", UUID.randomUUID().toString());
builder.addString(USER_SCHEDULED, UUID.randomUUID().toString());

JobExecution jobExecution = new JobExecution(new JobInstance(121L,"psiDistributionBatchJob"), 121L, builder.toJobParameters());
jobExecution.setStatus(BatchStatus.COMPLETED);
Expand Down
Loading