Skip to content

Commit

Permalink
Fix LocalDate issues
Browse files Browse the repository at this point in the history
  • Loading branch information
arybakov-cgi committed Sep 6, 2023
1 parent 38f64d4 commit 90e5fd9
Show file tree
Hide file tree
Showing 25 changed files with 112 additions and 101 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

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

import static ca.bc.gov.educ.api.batchgraduation.util.EducGradBatchGraduationApiConstants.SEARCH_REQUEST;
Expand Down Expand Up @@ -124,7 +124,7 @@ public ResponseEntity<BatchJobResponse> launchRegGradJob() {
builder.addString(JOB_TYPE, REGALG);
response.setJobType(REGALG);
response.setTriggerBy(MANUAL);
response.setStartTime(new Date(System.currentTimeMillis()));
response.setStartTime(LocalDateTime.now());
response.setStatus(BatchStatusEnum.STARTED.name());

try {
Expand Down Expand Up @@ -153,7 +153,7 @@ public ResponseEntity<BatchJobResponse> launchTvrRunJob() {
builder.addString(JOB_TYPE, TVRRUN);
response.setJobType(TVRRUN);
response.setTriggerBy(MANUAL);
response.setStartTime(new Date(System.currentTimeMillis()));
response.setStartTime(LocalDateTime.now());
response.setStatus(BatchStatusEnum.STARTED.name());

try {
Expand Down Expand Up @@ -222,7 +222,7 @@ public ResponseEntity<BatchJobResponse> launchRegGradSpecialJob(@RequestBody Stu
builder.addString(JOB_TYPE, REGALG);
response.setJobType(REGALG);
response.setTriggerBy(MANUAL);
response.setStartTime(new Date(System.currentTimeMillis()));
response.setStartTime(LocalDateTime.now());
response.setStatus(BatchStatusEnum.STARTED.name());
validateInput(response, studentSearchRequest);
if(response.getException() != null) {
Expand Down Expand Up @@ -280,7 +280,7 @@ public ResponseEntity<BatchJobResponse> launchTvrRunSpecialJob(@RequestBody Stud
builder.addString(JOB_TYPE, TVRRUN);
response.setJobType(TVRRUN);
response.setTriggerBy(MANUAL);
response.setStartTime(new Date(System.currentTimeMillis()));
response.setStartTime(LocalDateTime.now());
response.setStatus(BatchStatusEnum.STARTED.name());
validateInput(response, studentSearchRequest);
if(response.getException() != null) {
Expand Down Expand Up @@ -313,7 +313,7 @@ public ResponseEntity<BatchJobResponse> launchRerunAll(@PathVariable Long batchI
builder.addString(JOB_TYPE, entity.getJobType());
response.setJobType(entity.getJobType());
response.setTriggerBy(entity.getTriggerBy());
response.setStartTime(new Date(System.currentTimeMillis()));
response.setStartTime(LocalDateTime.now());
response.setStatus(BatchStatusEnum.STARTED.name());

try {
Expand Down Expand Up @@ -369,7 +369,7 @@ public ResponseEntity<BatchJobResponse> launchRerunFailed(@PathVariable Long bat
builder.addString(JOB_TYPE, entity.getJobType());
response.setJobType(entity.getJobType());
response.setTriggerBy(entity.getTriggerBy());
response.setStartTime(new Date(System.currentTimeMillis()));
response.setStartTime(LocalDateTime.now());
response.setStatus(BatchStatusEnum.STARTED.name());

try {
Expand Down Expand Up @@ -706,7 +706,7 @@ public ResponseEntity<BatchJobResponse> launchCertRegenJob() {
builder.addString(SEARCH_REQUEST, "");
response.setJobType(CERT_REGEN);
response.setTriggerBy(MANUAL);
response.setStartTime(new Date(System.currentTimeMillis()));
response.setStartTime(LocalDateTime.now());
response.setStatus(BatchStatusEnum.STARTED.name());

try {
Expand Down Expand Up @@ -734,7 +734,7 @@ public ResponseEntity<BatchJobResponse> launchUserReqCertRegenJob(@RequestBody C
builder.addString(JOB_TYPE, CERT_REGEN);
response.setJobType(CERT_REGEN);
response.setTriggerBy(MANUAL);
response.setStartTime(new Date(System.currentTimeMillis()));
response.setStartTime(LocalDateTime.now());
response.setStatus(BatchStatusEnum.STARTED.name());

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import org.apache.commons.lang3.StringUtils;
import org.springframework.format.annotation.DateTimeFormat;

import java.util.Date;
import java.time.LocalDateTime;

@Data
@MappedSuperclass
Expand All @@ -18,7 +18,7 @@ public class BaseEntity {
@Column(name = "CREATE_DATE", columnDefinition="datetime",nullable = false)
@Temporal(TemporalType.TIMESTAMP)
@DateTimeFormat(pattern = "yyyy-mm-dd hh:mm:ss")
private Date createDate;
private LocalDateTime createDate;


@Column(name = "UPDATE_USER", nullable = false)
Expand All @@ -27,7 +27,7 @@ public class BaseEntity {
@Column(name = "UPDATE_DATE", columnDefinition="datetime")
@Temporal(TemporalType.TIMESTAMP)
@DateTimeFormat(pattern = "yyyy-mm-dd hh:mm:ss")
private Date updateDate;
private LocalDateTime updateDate;

@PrePersist
protected void onCreate() {
Expand All @@ -43,14 +43,14 @@ protected void onCreate() {
this.updateUser = EducGradBatchGraduationApiConstants.DEFAULT_UPDATED_BY;
}
}
this.createDate = new Date(System.currentTimeMillis());
this.updateDate = new Date(System.currentTimeMillis());
this.createDate = LocalDateTime.now();
this.updateDate = LocalDateTime.now();

}

@PreUpdate
protected void onPersist() {
this.updateDate = new Date();
this.updateDate = LocalDateTime.now();
if (StringUtils.isBlank(updateUser)) {
this.updateUser = ThreadLocalStateUtil.getCurrentUser();
if (StringUtils.isBlank(updateUser)) {
Expand All @@ -64,7 +64,7 @@ protected void onPersist() {
}
}
if (this.createDate == null) {
this.createDate = new Date();
this.createDate = LocalDateTime.now();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import lombok.EqualsAndHashCode;
import org.hibernate.annotations.GenericGenerator;

import java.util.Date;
import java.time.LocalDateTime;
import java.util.UUID;

@Data
Expand All @@ -28,11 +28,11 @@ public class BatchGradAlgorithmJobHistoryEntity extends BaseEntity {

@Column(name = "START_TIME", nullable = true)
@Temporal(TemporalType.TIMESTAMP)
private Date startTime;
private LocalDateTime startTime;

@Column(name = "END_TIME", nullable = true)
@Temporal(TemporalType.TIMESTAMP)
private Date endTime;
private LocalDateTime endTime;

@Column(name = "EXPECTED_STUDENTS_PROCESSED", nullable = true)
private Long expectedStudentsProcessed;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import lombok.EqualsAndHashCode;

import java.time.Instant;
import java.util.Date;
import java.time.LocalDateTime;

@Data
@Entity
Expand All @@ -22,15 +22,15 @@ public class BatchJobExecutionEntity {

@Column(name = "CREATE_TIME", nullable = true)
@Temporal(TemporalType.TIMESTAMP)
private Date createTime;
private LocalDateTime createTime;

@Column(name = "START_TIME", nullable = true)
@Temporal(TemporalType.TIMESTAMP)
private Date startTime;
private LocalDateTime startTime;

@Column(name = "END_TIME", nullable = true)
@Temporal(TemporalType.TIMESTAMP)
private Date endTime;
private LocalDateTime endTime;

@Column(name = "STATUS", nullable = true)
private String status;
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.util.DateUtils;
import ca.bc.gov.educ.api.batchgraduation.util.GradSorter;
import ca.bc.gov.educ.api.batchgraduation.util.JsonTransformer;
import org.apache.commons.lang3.StringUtils;
Expand Down Expand Up @@ -44,8 +45,8 @@ protected void processBatchJobHistory(BaseDistributionSummaryDTO summaryDTO, Lon
ent.setExpectedStudentsProcessed(expectedStudents);
ent.setFailedStudentsProcessed(failedRecords);
ent.setJobExecutionId(jobExecutionId);
ent.setStartTime(startTime);
ent.setEndTime(endTime);
ent.setStartTime(DateUtils.toLocalDateTime(startTime));
ent.setEndTime(DateUtils.toLocalDateTime(endTime));
ent.setStatus(status);
ent.setTriggerBy(jobTrigger);
ent.setJobType(jobType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ private void processBatchJobHistory(AlgorithmSummaryDTO summaryDTO, Long jobExec
ent.setExpectedStudentsProcessed(expectedStudents);
ent.setFailedStudentsProcessed(failedRecords != null? failedRecords.intValue() : 0);
ent.setJobExecutionId(jobExecutionId);
ent.setStartTime(startTime);
ent.setEndTime(endTime);
ent.setStartTime(DateUtils.toLocalDateTime(startTime));
ent.setEndTime(DateUtils.toLocalDateTime(endTime));
ent.setStatus(status);
ent.setTriggerBy(jobTrigger);
ent.setJobType(jobType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ private void saveBatchJobHistory(AlgorithmSummaryDTO summaryDTO, Long jobExecuti
if (ent != null) {
ent.setActualStudentsProcessed(summaryDTO.getProcessedCount());
ent.setFailedStudentsProcessed((int) summaryDTO.getErroredCount());
ent.setEndTime(endTime);
ent.setEndTime(DateUtils.toLocalDateTime(endTime));
ent.setStatus(status);

gradBatchHistoryService.saveGradAlgorithmJobHistory(ent);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import lombok.EqualsAndHashCode;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.time.LocalDateTime;
import java.util.UUID;

@Data
Expand All @@ -14,8 +14,8 @@ public class BatchGradAlgorithmJobHistory extends BaseModel{

private UUID id;
private Integer jobExecutionId;
private Date startTime;
private Date endTime;
private LocalDateTime startTime;
private LocalDateTime endTime;
private String expectedStudentsProcessed;
private String actualStudentsProcessed;
private String failedStudentsProcessed;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@
import lombok.EqualsAndHashCode;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.time.LocalDateTime;

@Data
@EqualsAndHashCode(callSuper = false)
@Component
public class BatchJobExecution {

private Long jobExecutionId;
private Date createTime;
private Date startTime;
private Date endTime;
private LocalDateTime createTime;
private LocalDateTime startTime;
private LocalDateTime endTime;
private String status;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

import lombok.Data;

import java.util.Date;
import java.time.LocalDateTime;

@Data
public class BatchJobResponse {
private Long batchId;
private Date startTime;
private LocalDateTime startTime;
private String status;
private String jobType;
private String triggerBy;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ protected BatchGradAlgorithmJobHistoryEntity createBatchJobHistory() {
ent.setExpectedStudentsProcessed(0L);
ent.setFailedStudentsProcessed(0);
ent.setJobExecutionId(jobExecutionId);
ent.setStartTime(startTime);
ent.setStartTime(DateUtils.toLocalDateTime(startTime));
ent.setStatus(status);
ent.setTriggerBy(jobTrigger);
ent.setJobType(jobType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.time.LocalDateTime;
import java.util.List;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -75,7 +75,7 @@ public void saveStudentCredentialDistribution(Long batchId, String jobType, Stud
public void updateDistributionBatchJobStatus(Long batchId, int failedCount, String status) {
log.debug("updateDistributionBatchJobStatus - retrieve the batch job history: batchId = {}", batchId);
BatchGradAlgorithmJobHistoryEntity jobHistory = gradBatchHistoryService.getGradAlgorithmJobHistory(batchId);
jobHistory.setEndTime(new Date(System.currentTimeMillis()));
jobHistory.setEndTime(LocalDateTime.now());
jobHistory.setStatus(status);
jobHistory.setActualStudentsProcessed(jobHistory.getExpectedStudentsProcessed() - failedCount);
log.debug("updateDistributionBatchJobStatus - save the batch job history: batchId = {}, status = {}. actual processed count = {}", batchId, status, jobHistory.getActualStudentsProcessed());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
package ca.bc.gov.educ.api.batchgraduation.service;

import java.util.*;
import java.util.stream.Collectors;

import ca.bc.gov.educ.api.batchgraduation.entity.*;
import ca.bc.gov.educ.api.batchgraduation.model.*;
import ca.bc.gov.educ.api.batchgraduation.repository.*;
import ca.bc.gov.educ.api.batchgraduation.repository.BatchGradAlgorithmJobHistoryRepository;
import ca.bc.gov.educ.api.batchgraduation.repository.BatchGradAlgorithmStudentRepository;
import ca.bc.gov.educ.api.batchgraduation.repository.BatchJobExecutionRepository;
import ca.bc.gov.educ.api.batchgraduation.repository.BatchProcessingRepository;
import ca.bc.gov.educ.api.batchgraduation.rest.RestUtils;
import ca.bc.gov.educ.api.batchgraduation.transformer.BatchGradAlgorithmJobHistoryTransformer;
import ca.bc.gov.educ.api.batchgraduation.transformer.BatchProcessingTransformer;
import org.apache.commons.lang3.time.DateUtils;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import ca.bc.gov.educ.api.batchgraduation.transformer.BatchGradAlgorithmJobHistoryTransformer;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDateTime;
import java.util.*;
import java.util.stream.Collectors;

@Service
public class GradDashboardService extends GradService {

Expand Down Expand Up @@ -54,9 +57,9 @@ public GradDashboard getDashboardInfo() {
gradDash.setLastActualStudentsProcessed(info.getActualStudentsProcessed());
gradDash.setLastExpectedStudentsProcessed(info.getExpectedStudentsProcessed());
gradDash.setLastFailedStudentsProcessed(info.getFailedStudentsProcessed());
gradDash.setLastJobendTime(info.getEndTime());
gradDash.setLastJobendTime(ca.bc.gov.educ.api.batchgraduation.util.DateUtils.toDate(info.getEndTime()));
gradDash.setLastJobExecutionId(info.getJobExecutionId());
gradDash.setLastJobstartTime(info.getStartTime());
gradDash.setLastJobstartTime(ca.bc.gov.educ.api.batchgraduation.util.DateUtils.toDate(info.getStartTime()));
gradDash.setLastStatus(info.getStatus());
gradDash.setTotalBatchRuns(infoDetailsList.size());
gradDash.setBatchInfoList(infoDetailsList);
Expand Down Expand Up @@ -148,9 +151,9 @@ public BatchGradAlgorithmJobHistory handleDeadJob(BatchGradAlgorithmJobHistory b
Integer jobExecutionId = batchJobHistory.getJobExecutionId();

Date now = new Date(System.currentTimeMillis());
Date deadline = DateUtils.addDays(now, -3);
LocalDateTime deadline = ca.bc.gov.educ.api.batchgraduation.util.DateUtils.toLocalDateTime(DateUtils.addDays(now, -3));

if (batchJobHistory.getStartTime().before(deadline)) {
if (batchJobHistory.getStartTime().isBefore(deadline)) {
Optional<BatchJobExecutionEntity> optional = batchJobExecutionRepository.findById(jobExecutionId.longValue());
if (optional.isPresent()) {
BatchJobExecutionEntity batchJobExecution = optional.get();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;

import java.util.Date;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -44,10 +44,10 @@ public abstract class BaseYearEndWriter {
JobParameters jobParameters;

@Value("#{stepExecution.jobExecution.startTime}")
Date startTime;
LocalDateTime startTime;

@Value("#{stepExecution.jobExecution.endTime}")
Date endTime;
LocalDateTime endTime;

protected void processGlobalList(List<StudentCredentialDistribution> cList, Long batchId, Map<String, DistributionPrintRequest> mapDist, String activityCode, String accessToken) {
List<String> uniqueSchoolList = cList.stream().map(StudentCredentialDistribution::getSchoolOfRecord).distinct().collect(Collectors.toList());
Expand Down
1 change: 1 addition & 0 deletions api/src/main/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ spring:
jackson:
deserialization:
fail-on-unknown-properties: false
date-format: com.fasterxml.jackson.databind.util.ISO8601DateFormat
#Keycloak/OAuth properties
security:
user:
Expand Down
Loading

0 comments on commit 90e5fd9

Please sign in to comment.