Skip to content

Commit

Permalink
Merge pull request #214 from bcgov/develop/alex
Browse files Browse the repository at this point in the history
REASON OF OVERRIDE: Fixes which won't break the reviewed code, but will save a lot of time for early morning testing.
  • Loading branch information
arybakov-cgi authored Jul 25, 2023
2 parents 0dc1b9a + 36a7b01 commit 0703c18
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ public void setBirthdate(LocalDate value) {
this.birthdate = value;
}

@JsonFormat(pattern="yyyy-MM-dd HH:mm:ss")
public LocalDateTime getLastUpdateDate() {
return lastUpdateDate;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
package ca.bc.gov.educ.api.distribution.model.dto;

import ca.bc.gov.educ.api.distribution.util.GradLocalDateDeserializer;
import ca.bc.gov.educ.api.distribution.util.GradLocalDateSerializer;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import lombok.Data;

import java.time.LocalDate;
Expand All @@ -27,10 +22,7 @@ public class StudentCredentialDistribution {
private String legalMiddleNames;
private String legalLastName;
private String studentCitizenship;
@JsonDeserialize(using = GradLocalDateDeserializer.class)
@JsonSerialize(using = GradLocalDateSerializer.class)
private LocalDate programCompletionDate;
@JsonFormat(pattern="yyyy-MM-dd HH:mm:ss")
private LocalDateTime lastUpdateDate;
private String honoursStanding;
private String program;
Expand Down
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.time.LocalDate;
import java.util.Date;
import java.util.List;

@Data
Expand All @@ -24,9 +24,9 @@ public class StudentSearchRequest implements Serializable {
private List<String> programs;

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

Boolean validateInput;
String localDownload;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ public class EducDistributionApiConstants {
public static final String POST_DISTRIBUTION = "/zipandupload";
//Default Date format constants
public static final String DEFAULT_DATE_FORMAT = "yyyy-MM-dd";
public static final String SECONDARY_DATE_FORMAT = "yyyy/MM/dd";
public static final String DEFAULT_DATE_TIME_FORMAT = "yyyy-MM-dd HH:mm:ss";
public static final String SECOND_DEFAULT_DATE_FORMAT = "yyyy/MM/dd";
public static final String SECOND_DEFAULT_DATE_TIME_FORMAT = "yyyy/MM/dd HH:mm:ss";
//Grad2-1931 - mchintha
public static final String DATE_FORMAT_YYYYMMDD = "yyyyMMdd";
public static final String TMP_DIR = "/tmp";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ public static String parsingDateForCertificate(String sessionDate) {
String actualSessionDate = sessionDate + "/01";
String sDates = null;
try {
Date temp = parseDate(actualSessionDate, EducDistributionApiConstants.SECONDARY_DATE_FORMAT);
Date temp = parseDate(actualSessionDate, EducDistributionApiConstants.SECOND_DEFAULT_DATE_FORMAT);
sDates = formatDate(temp, EducDistributionApiConstants.DEFAULT_DATE_FORMAT);
} catch (ParseException pe) {
logger.error(ERROR,pe.getMessage());
Expand All @@ -190,7 +190,7 @@ public static Date parsingTraxDate(String sessionDate) {
String actualSessionDate = sessionDate + "/01";
Date sDate = null;
try {
Date temp = EducDistributionApiUtils.parseDate(actualSessionDate, EducDistributionApiConstants.SECONDARY_DATE_FORMAT);
Date temp = EducDistributionApiUtils.parseDate(actualSessionDate, EducDistributionApiConstants.SECOND_DEFAULT_DATE_FORMAT);
String sDates = EducDistributionApiUtils.formatDate(temp, EducDistributionApiConstants.DEFAULT_DATE_FORMAT);
sDate = EducDistributionApiUtils.parseDate(sDates, EducDistributionApiConstants.DEFAULT_DATE_FORMAT);
} catch (ParseException pe) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;

import static ca.bc.gov.educ.api.distribution.util.EducDistributionApiConstants.SECOND_DEFAULT_DATE_FORMAT;

public class GradLocalDateDeserializer extends StdDeserializer<LocalDate> {

public GradLocalDateDeserializer() {
Expand All @@ -30,7 +32,7 @@ public LocalDate deserialize(JsonParser jsonParser, DeserializationContext deser
dateAsString = dateAsString + "/01";
}
if(slashCount > 0) {
formatter = DateTimeFormatter.ofPattern("yyyy/MM/dd");
formatter = DateTimeFormatter.ofPattern(SECOND_DEFAULT_DATE_FORMAT);
}
return LocalDate.parse(dateAsString, formatter);
} else if(jsonParser.hasToken(JsonToken.VALUE_NUMBER_INT)) {
Expand All @@ -39,7 +41,7 @@ public LocalDate deserialize(JsonParser jsonParser, DeserializationContext deser
} else if(StringUtils.isNotBlank(dateAsString) && dateAsString.length() == 10 && dateAsString.contains("-")) {
return LocalDate.parse(dateAsString, formatter);
} else if(StringUtils.isNotBlank(dateAsString) && dateAsString.length() == 10 && dateAsString.contains("/")) {
formatter = DateTimeFormatter.ofPattern("yyyy/MM/dd");
formatter = DateTimeFormatter.ofPattern(SECOND_DEFAULT_DATE_FORMAT);
return LocalDate.parse(dateAsString, formatter);
} else if(StringUtils.isNotBlank(dateAsString)) {
return LocalDate.parse(dateAsString, formatter);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;

import static ca.bc.gov.educ.api.distribution.util.EducDistributionApiConstants.*;

public class GradLocalDateTimeDeserializer extends StdDeserializer<LocalDateTime> {

public GradLocalDateTimeDeserializer() {
Expand All @@ -31,31 +33,25 @@ public LocalDateTime deserialize(JsonParser jsonParser, DeserializationContext d
dateAsString = dateAsString + "/01";
}
if(slashCount > 0) {
formatter = DateTimeFormatter.ofPattern("yyyy/MM/dd");
formatter = DateTimeFormatter.ofPattern(SECOND_DEFAULT_DATE_FORMAT);
}
return LocalDateTime.parse(dateAsString, formatter);
} else if(jsonParser.hasToken(JsonToken.VALUE_NUMBER_INT)) {
long timestamp = jsonParser.getValueAsLong();
return LocalDateTime.ofInstant(Instant.ofEpochMilli(timestamp), ZoneId.systemDefault());
} else if(StringUtils.isNotBlank(dateAsString) && dateAsString.length() == 10 && dateAsString.contains("-")) {
formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
formatter = DateTimeFormatter.ofPattern(DEFAULT_DATE_FORMAT);
LocalDate localDate = LocalDate.parse(dateAsString, formatter);
return localDate.atStartOfDay();
} else if(StringUtils.isNotBlank(dateAsString) && dateAsString.length() == 10 && dateAsString.contains("/")) {
formatter = DateTimeFormatter.ofPattern("yyyy/MM/dd");
formatter = DateTimeFormatter.ofPattern(SECOND_DEFAULT_DATE_FORMAT);
LocalDate localDate = LocalDate.parse(dateAsString, formatter);
return localDate.atStartOfDay();
} else if(StringUtils.isNotBlank(dateAsString) && dateAsString.length() > 10 && dateAsString.contains("/") && dateAsString.contains(" ")) {
formatter = DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm:ss");
formatter = DateTimeFormatter.ofPattern(SECOND_DEFAULT_DATE_TIME_FORMAT);
return LocalDateTime.parse(dateAsString, formatter);
} else if(StringUtils.isNotBlank(dateAsString) && dateAsString.length() > 10 && dateAsString.contains("-") && dateAsString.contains(" ")) {
formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
return LocalDateTime.parse(dateAsString, formatter);
} else if(StringUtils.isNotBlank(dateAsString) && dateAsString.length() > 10 && dateAsString.contains("/") && dateAsString.contains("T")) {
formatter = DateTimeFormatter.ofPattern("yyyy/MM/ddTHH:mm:ss.000+00:00");
return LocalDateTime.parse(dateAsString, formatter);
} else if(StringUtils.isNotBlank(dateAsString) && dateAsString.length() > 10 && dateAsString.contains("-") && dateAsString.contains("T")) {
formatter = DateTimeFormatter.ISO_OFFSET_DATE_TIME;
formatter = DateTimeFormatter.ofPattern(DEFAULT_DATE_TIME_FORMAT);
return LocalDateTime.parse(dateAsString, formatter);
} else if(StringUtils.isNotBlank(dateAsString)) {
return LocalDateTime.parse(dateAsString, formatter);
Expand Down

0 comments on commit 0703c18

Please sign in to comment.