diff --git a/build.gradle b/build.gradle index 44edc06..c1f838b 100644 --- a/build.gradle +++ b/build.gradle @@ -228,6 +228,8 @@ dependencies { implementation 'com.fasterxml.jackson.dataformat:jackson-dataformat-xml:2.13.1' implementation 'com.fasterxml.jackson.module:jackson-module-afterburner:2.13.1' implementation 'com.fasterxml.jackson.datatype:jackson-datatype-joda:2.13.1' + implementation 'com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.13.3' + // JAP LAZY loading시 객체생성 (OneToMay <--> ManyToOne) implementation 'com.fasterxml.jackson.datatype:jackson-datatype-hibernate5' //implementation 'com.fasterxml.jackson.datatype:jackson-datatype-jdk8:2.12.5' diff --git a/src/main/java/com/xit/biz/ctgy/controller/ParkingController.java b/src/main/java/com/xit/biz/ctgy/controller/ParkingController.java index 6421644..5a69ebe 100644 --- a/src/main/java/com/xit/biz/ctgy/controller/ParkingController.java +++ b/src/main/java/com/xit/biz/ctgy/controller/ParkingController.java @@ -62,7 +62,7 @@ public class ParkingController { return RestResponse.of(service.findParkings(dto, pageable)); } - @Secured(policy = SecurityPolicy.TOKEN) + //@Secured(policy = SecurityPolicy.TOKEN) @Operation(summary = "주정차 의견진술 심의 결과" , description = "주정차 의견진술 심의 결과") @Parameters({ @Parameter(in = ParameterIn.QUERY, name = "msSdate", description = "심사시작일", required = true, example = "2021-01-04"), diff --git a/src/main/java/com/xit/biz/ctgy/dto/DashboardJudgeListDto.java b/src/main/java/com/xit/biz/ctgy/dto/DashboardJudgeListDto.java index 3982a78..736636b 100644 --- a/src/main/java/com/xit/biz/ctgy/dto/DashboardJudgeListDto.java +++ b/src/main/java/com/xit/biz/ctgy/dto/DashboardJudgeListDto.java @@ -6,6 +6,7 @@ import lombok.AllArgsConstructor; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; +import org.springframework.format.annotation.DateTimeFormat; import javax.validation.constraints.Size; import java.time.LocalDate; @@ -19,6 +20,7 @@ public class DashboardJudgeListDto { @Schema(title = "심사종료일", example = "2022-03-23", description = "심사종료일") @JsonFormat(pattern="yyyy-MM-dd") + @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) private LocalDate msEdate; @Schema(title = "심사팀코드", example = " ", description = "심사팀코드") diff --git a/src/main/java/com/xit/biz/ctgy/dto/JudgeDetailDto.java b/src/main/java/com/xit/biz/ctgy/dto/JudgeDetailDto.java index e05ff92..d39216b 100644 --- a/src/main/java/com/xit/biz/ctgy/dto/JudgeDetailDto.java +++ b/src/main/java/com/xit/biz/ctgy/dto/JudgeDetailDto.java @@ -6,6 +6,7 @@ import lombok.AllArgsConstructor; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; +import org.springframework.format.annotation.DateTimeFormat; import java.time.LocalDate; @@ -33,6 +34,7 @@ public class JudgeDetailDto { @Schema(required = true, title = "심사시작일", example = " ", description = "Input Description...") @JsonFormat(pattern="yyyy-MM-dd") + @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) private LocalDate msSdate; @Schema(required = true, title = "심사시작시간", example = " ", description = "Input Description...") @@ -40,17 +42,19 @@ public class JudgeDetailDto { @Schema(required = true, title = "심사종료일", example = " ", description = "Input Description...") @JsonFormat(pattern="yyyy-MM-dd") + @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) private LocalDate msEdate; @Schema(required = true, title = "심사마감일", example = " ", description = "Input Description...") @JsonFormat(pattern="yyyy-MM-dd") + @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) private LocalDate msCdate; @Schema(required = true, title = "심사마감시간", example = " ", description = "Input Description...") private String msClosesi; @Schema(required = false, title = "단속일자", example = " ", description = "Input Description...") - @JsonFormat(pattern="yyyy-MM-dd") + //@JsonFormat(pattern="yyyy-MM-dd") private LocalDate msWdate; @Schema(required = false, title = "단속장소", example = " ", description = "Input Description...") diff --git a/src/main/java/com/xit/biz/ctgy/dto/JudgeListDto.java b/src/main/java/com/xit/biz/ctgy/dto/JudgeListDto.java index d118203..7b06c9a 100644 --- a/src/main/java/com/xit/biz/ctgy/dto/JudgeListDto.java +++ b/src/main/java/com/xit/biz/ctgy/dto/JudgeListDto.java @@ -3,6 +3,7 @@ package com.xit.biz.ctgy.dto; import com.fasterxml.jackson.annotation.JsonFormat; import io.swagger.v3.oas.annotations.media.Schema; import lombok.*; +import org.springframework.format.annotation.DateTimeFormat; import javax.validation.constraints.Size; import java.time.LocalDate; @@ -22,15 +23,18 @@ public class JudgeListDto { @Schema(title = "심사시작일", example = "2022-03-23", description = "심사시작일") @JsonFormat(pattern="yyyy-MM-dd") + @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) private LocalDate msSdate; private String msStartsi; @Schema(title = "심사종료일", example = "2022-03-23", description = "심사종료일") @JsonFormat(pattern="yyyy-MM-dd") + @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) private LocalDate msEdate; @Schema(title = "심사마감일", example = "2022-03-23", description = "심사마감일") @JsonFormat(pattern="yyyy-MM-dd") + @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) private LocalDate msCdate; private String msClosesi; @@ -58,6 +62,8 @@ public class JudgeListDto { @Schema(title = "심사자별 사유", example = " ", description = "심사자별 사유") private String msuReason; @Schema(title = "심사일", example = " ", description = "심사일") + @JsonFormat(pattern="yyyy-MM-dd") + @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) private LocalDate msuIndate; @Schema(required = true, title = "위반일자", example = " ", description = "위반일자") diff --git a/src/main/java/com/xit/biz/ctgy/dto/JudgeTargetDto.java b/src/main/java/com/xit/biz/ctgy/dto/JudgeTargetDto.java index 925c94a..4161a2a 100644 --- a/src/main/java/com/xit/biz/ctgy/dto/JudgeTargetDto.java +++ b/src/main/java/com/xit/biz/ctgy/dto/JudgeTargetDto.java @@ -6,6 +6,7 @@ import lombok.AllArgsConstructor; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; +import org.springframework.format.annotation.DateTimeFormat; import java.time.LocalDate; import java.util.List; @@ -54,6 +55,7 @@ public class JudgeTargetDto { //------------------------------------------------------------------ @Schema(title = "심사시작일", example = "2022-03-23", description = "Input Description...") @JsonFormat(pattern="yyyy-MM-dd") + @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) private LocalDate msSdate; @Schema(title = "심사시작시간", example = " ", description = "Input Description...") @@ -61,10 +63,12 @@ public class JudgeTargetDto { @Schema(title = "심사종료일", example = "2022-03-24", description = "Input Description...") @JsonFormat(pattern="yyyy-MM-dd") + @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) private LocalDate msEdate; @Schema(title = "심사마감일", example = "2022-03-25", description = "Input Description...") @JsonFormat(pattern="yyyy-MM-dd") + @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) private LocalDate msCdate; @Schema(title = "심사마감시간", example = " ", description = "Input Description...") diff --git a/src/main/java/com/xit/biz/ctgy/dto/MinSimsa680Dto.java b/src/main/java/com/xit/biz/ctgy/dto/MinSimsa680Dto.java index ea72f3e..f0186c0 100644 --- a/src/main/java/com/xit/biz/ctgy/dto/MinSimsa680Dto.java +++ b/src/main/java/com/xit/biz/ctgy/dto/MinSimsa680Dto.java @@ -6,6 +6,7 @@ import lombok.AllArgsConstructor; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; +import org.springframework.format.annotation.DateTimeFormat; import java.time.LocalDate; @@ -34,6 +35,7 @@ public class MinSimsa680Dto { @Schema(required = true, title = "심사시작일", example = " ", description = "Input Description...") @JsonFormat(pattern="yyyy-MM-dd") + @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) private LocalDate msSdate; @Schema(required = true, title = "심사시작시간", example = " ", description = "Input Description...") @@ -41,10 +43,12 @@ public class MinSimsa680Dto { @Schema(required = true, title = "심사종료일", example = " ", description = "Input Description...") @JsonFormat(pattern="yyyy-MM-dd") + @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) private LocalDate msEdate; @Schema(required = true, title = "심사마감일", example = " ", description = "Input Description...") @JsonFormat(pattern="yyyy-MM-dd") + @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) private LocalDate msCdate; @Schema(required = true, title = "심사마감시간", example = " ", description = "Input Description...") @@ -52,6 +56,7 @@ public class MinSimsa680Dto { @Schema(required = false, title = "단속일자", example = " ", description = "Input Description...") @JsonFormat(pattern="yyyy-MM-dd") + @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) private LocalDate msWdate; @Schema(required = false, title = "단속장소", example = " ", description = "Input Description...") diff --git a/src/main/java/com/xit/biz/ctgy/dto/MinUserinfoDto.java b/src/main/java/com/xit/biz/ctgy/dto/MinUserinfoDto.java index 0d62756..6cd0da4 100644 --- a/src/main/java/com/xit/biz/ctgy/dto/MinUserinfoDto.java +++ b/src/main/java/com/xit/biz/ctgy/dto/MinUserinfoDto.java @@ -1,7 +1,9 @@ package com.xit.biz.ctgy.dto; +import com.fasterxml.jackson.annotation.JsonFormat; import io.swagger.v3.oas.annotations.media.Schema; import lombok.*; +import org.springframework.format.annotation.DateTimeFormat; import java.io.Serializable; import java.time.LocalDate; @@ -40,6 +42,8 @@ public class MinUserinfoDto implements Serializable { private String team; @Schema(required = false, title = "등록일시", example = " ", description = "Input Description...") + @JsonFormat(pattern="yyyy-MM-dd") + @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) private LocalDate regdate; @Schema(required = false, title = "사용여부", example = " ", description = "Input Description...") diff --git a/src/main/java/com/xit/biz/ctgy/dto/ParkingTargetDto.java b/src/main/java/com/xit/biz/ctgy/dto/ParkingTargetDto.java index 01ef6fe..b79b0b7 100644 --- a/src/main/java/com/xit/biz/ctgy/dto/ParkingTargetDto.java +++ b/src/main/java/com/xit/biz/ctgy/dto/ParkingTargetDto.java @@ -6,6 +6,7 @@ import lombok.AllArgsConstructor; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; +import org.springframework.format.annotation.DateTimeFormat; import java.time.LocalDate; import java.util.List; @@ -52,6 +53,7 @@ public class ParkingTargetDto { @Schema(title = "심사시작일", example = "2022-03-23", description = "Input Description...") @JsonFormat(pattern="yyyy-MM-dd") + @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) private LocalDate msSdate; @Schema(title = "심사시작시간", example = " ", description = "Input Description...") @@ -59,10 +61,12 @@ public class ParkingTargetDto { @Schema(title = "심사종료일", example = "2022-03-24", description = "Input Description...") @JsonFormat(pattern="yyyy-MM-dd") + @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) private LocalDate msEdate; @Schema(title = "심사마감일", example = "2022-03-25", description = "Input Description...") @JsonFormat(pattern="yyyy-MM-dd") + @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) private LocalDate msCdate; @Schema(title = "심사마감시간", example = " ", description = "Input Description...") diff --git a/src/main/java/com/xit/core/config/support/LocalDateTimeConfiguration.java b/src/main/java/com/xit/core/config/support/LocalDateTimeConfiguration.java new file mode 100644 index 0000000..b444b9a --- /dev/null +++ b/src/main/java/com/xit/core/config/support/LocalDateTimeConfiguration.java @@ -0,0 +1,107 @@ +package com.xit.core.config.support; + +import com.fasterxml.jackson.core.JsonGenerator; +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.*; +import com.fasterxml.jackson.databind.Module; +import com.fasterxml.jackson.databind.module.SimpleModule; + +import java.time.LocalDate; +import java.time.LocalDateTime; + +import lombok.extern.slf4j.Slf4j; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Primary; +import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder; + +import java.io.IOException; +import java.time.ZonedDateTime; +import java.time.format.DateTimeFormatter; + +/** + * DTO LocalDate 필드의 아래의 선언 처리 + * @JsonFormat(pattern="yyyy-MM-dd") + * @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) + * + * Request(클라이언트 -> 서버)로 전달할 때는 @DateTimeFormat + * Responst (서버 -> 클라이언트) 로 전달할 때에는 @JsonFormat + * + */ +//@Configuration +@Slf4j +public class LocalDateTimeConfiguration { + private static final String DEFAULT_DATE_FMT = "yyyy-MM-dd"; + private static final String DEFAULT_DATE_TIME_FMT = "yyyy-MM-dd HH:mm:ss"; + + @Bean + @Primary + public ObjectMapper objectMapper(Jackson2ObjectMapperBuilder builder) { + log.info(">>>>>>>>>>> Config is starting."); + ObjectMapper objectMapper = builder.createXmlMapper(false).build(); + objectMapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false); + return objectMapper; + } + + @Bean + public Module jsonMapperJava8DateTimeModule() { + SimpleModule module = new SimpleModule(); + + module.addDeserializer(ZonedDateTime.class, new JsonDeserializer() { + @Override + public ZonedDateTime deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JsonProcessingException { + log.info(">>>>>>>>>>>>>>>>>>>>>LocalDateTimeConfiguration::addDeserializer-ZonedDateTime"); + return ZonedDateTime.parse(p.getValueAsString(), DateTimeFormatter.ISO_ZONED_DATE_TIME); + } + }); + + module.addDeserializer(LocalDateTime.class, new JsonDeserializer() { + @Override + public LocalDateTime deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JsonProcessingException { + log.info(">>>>>>>>>>>>>>>>>>>>>LocalDateTimeConfiguration::addDeserializer-LocalDateTime"); + return LocalDateTime.parse(p.getValueAsString(), DateTimeFormatter.ISO_LOCAL_DATE_TIME); + //return LocalDateTime.parse(p.getValueAsString(), DateTimeFormatter.ofPattern(DEFAULT_DATE_TIME_FMT)); + } + }); + + module.addDeserializer(LocalDate.class, new JsonDeserializer() { + @Override + public LocalDate deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JsonProcessingException { + log.info(">>>>>>>>>>>>>>>>>>>>>LocalDateTimeConfiguration::addDeserializer-LocalDate"); + //return LocalDateTime.parse(p.getValueAsString(), DateTimeFormatter.ISO_DATE_TIME); + return LocalDate.parse(p.getValueAsString(), DateTimeFormatter.ofPattern(DEFAULT_DATE_FMT)); + } + }); + + + + module.addSerializer(ZonedDateTime.class, new JsonSerializer() { + @Override + public void serialize(ZonedDateTime value, JsonGenerator gen, SerializerProvider serializers) throws IOException { + log.info(">>>>>>>>>>>>>>>>>>>>>LocalDateTimeConfiguration::addSerializer-ZonedDateTime"); + gen.writeString(DateTimeFormatter.ISO_ZONED_DATE_TIME.format(value)); + } + }); + + module.addSerializer(LocalDateTime.class, new JsonSerializer() { + @Override + public void serialize(LocalDateTime localDateTime, JsonGenerator gen, SerializerProvider serializers) throws IOException { + log.info(">>>>>>>>>>>>>>>>>>>>>LocalDateTimeConfiguration::addSerializer-LocalDateTime"); + gen.writeString(DateTimeFormatter.ISO_LOCAL_DATE_TIME.format(localDateTime)); + //gen.writeString(localDateTime.format(DateTimeFormatter.ofPattern(DEFAULT_DATE_TIME_FMT))); + } + }); + + module.addSerializer(LocalDate.class, new JsonSerializer() { + @Override + public void serialize(LocalDate localDate, JsonGenerator gen, SerializerProvider serializers) throws IOException { + log.info(">>>>>>>>>>>>>>>>>>>>>LocalDateTimeConfiguration::addSerializer-LocalDate"); + //gen.writeString(DateTimeFormatter.ISO_DATE_TIME.format(value)); + gen.writeString(localDate.format(DateTimeFormatter.ofPattern(DEFAULT_DATE_FMT))); + } + }); + + return module; + } +} \ No newline at end of file diff --git a/src/main/java/com/xit/core/exception/handling/CustomRestExceptionHandler.java b/src/main/java/com/xit/core/exception/handling/CustomRestExceptionHandler.java index d13bea6..4b8311f 100644 --- a/src/main/java/com/xit/core/exception/handling/CustomRestExceptionHandler.java +++ b/src/main/java/com/xit/core/exception/handling/CustomRestExceptionHandler.java @@ -71,6 +71,7 @@ public class CustomRestExceptionHandler extends ResponseEntityExceptionHandler { */ @SuppressWarnings("NullableProblems") @Override + //@ExceptionHandler(MethodArgumentNotValidException.class) protected ResponseEntity handleMethodArgumentNotValid( MethodArgumentNotValidException ex, HttpHeaders headers, HttpStatus status, WebRequest request) { log.error("==================== Override handleMethodArgumentNotValid throw MethodArgumentNotValidException ===================="); @@ -124,6 +125,7 @@ public class CustomRestExceptionHandler extends ResponseEntityExceptionHandler { */ @SuppressWarnings("NullableProblems") @Override + //@ExceptionHandler(HttpMessageNotReadableException.class) protected ResponseEntity handleHttpMessageNotReadable( HttpMessageNotReadableException ex, HttpHeaders headers, HttpStatus status, WebRequest request) { log.error("==================== Override handleHttpMessageNotReadable throw HttpMessageNotReadableException ===================="); @@ -215,4 +217,37 @@ public class CustomRestExceptionHandler extends ResponseEntityExceptionHandler { log.error("handleException throw Exception : {}", Checks.isEmpty(message) ? StringUtils.EMPTY : e.getClass().getCanonicalName()); return RestErrorResponse.of(HttpStatus.INTERNAL_SERVER_ERROR.toString(), message); } -} \ No newline at end of file +} + +/* + +javax.validation.constraints @NotNull + + +@ExceptionHandler(MethodArgumentNotValidException.class) + public ResponseEntity> methodArgumentValidException(MethodArgumentNotValidException e) { + return ResponseEntity.badRequest().body(extractErrorMessages(e)); + } + + private List extractErrorMessages(MethodArgumentNotValidException e) { + return e.getBindingResult() + .getAllErrors() + .stream() + .map(DefaultMessageSourceResolvable::getDefaultMessage) + .map(ExceptionDto::new) + .collect(Collectors.toList()); + } + + @ExceptionHandler(ConstraintViolationException.class) + public ResponseEntity> constraintViolationException(ConstraintViolationException e) { + return ResponseEntity.badRequest().body(extractErrorMessages(e)); + } + + private List extractErrorMessages(ConstraintViolationException e) { + return e.getConstraintViolations() + .stream() + .map(ConstraintViolation::getMessage) + .map(ExceptionDto::new) + .collect(Collectors.toList()); + } + */ \ No newline at end of file diff --git a/src/main/java/com/xit/core/util/security/ConvertUtils.java b/src/main/java/com/xit/core/util/security/ConvertUtils.java new file mode 100644 index 0000000..cb7132e --- /dev/null +++ b/src/main/java/com/xit/core/util/security/ConvertUtils.java @@ -0,0 +1,56 @@ +package com.xit.core.util.security; + +import com.xit.core.util.Checks; + +import javax.annotation.Nullable; +import javax.validation.constraints.NotNull; +import java.sql.Date; +import java.text.SimpleDateFormat; +import java.time.Instant; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.ZoneId; +import java.time.format.DateTimeFormatter; + +public class ConvertUtils { + private static final String DEFAULT_DATE_FMT = "yyyy-MM-dd"; + private static final String DEFAULT_DATE_TIME_FMT = "yyyy-MM-dd HH:mm:ss"; + + public static String getStringDateFromDate(@NotNull Date date, @Nullable String format) { + if(Checks.isNull(format)) format = "DEFAULT_DATE_FMT"; + return new SimpleDateFormat(format).format(date); + } + + public static String getStringDateTimeFromDate(@NotNull Date date, @Nullable String format) { + if(Checks.isNull(format)) format = "DEFAULT_DATE_TIME_FMT"; + return new SimpleDateFormat(format).format(date); + } + + public String getStringDateFromLocalDate(@NotNull LocalDate localDate, @Nullable String format) { + if(Checks.isNull(format)) format = "DEFAULT_DATE_FMT"; + return localDate.format(DateTimeFormatter.ofPattern(format)); + } + + public String getStringDateTimeFromLocalDate(@NotNull LocalDate localDate, @Nullable String format) { + if(Checks.isNull(format)) format = "DEFAULT_DATE_TIME_FMT"; + return localDate.format(DateTimeFormatter.ofPattern(format)); + } + + public static java.util.Date toDateFromLocalDate(LocalDate localDate){ + Instant instant = localDate.atStartOfDay(ZoneId.systemDefault()).toInstant(); + return java.util.Date.from(instant); + } + + public static java.util.Date toDateFromLocalDateTime(LocalDateTime localDateTime){ + Instant instant = localDateTime.atZone(ZoneId.systemDefault()).toInstant(); + return java.util.Date.from(instant); + } + + public static LocalDate toLocalDateFromDate(java.util.Date date){ + return LocalDate.ofInstant(date.toInstant(), ZoneId.systemDefault()); + } + + public static LocalDateTime toLocalDateTimeFromDate(java.util.Date date){ + return LocalDateTime.ofInstant(date.toInstant(), ZoneId.systemDefault()); + } +} diff --git a/src/main/resources/config/conf.yml b/src/main/resources/config/conf.yml index 23c818d..4fc092b 100644 --- a/src/main/resources/config/conf.yml +++ b/src/main/resources/config/conf.yml @@ -12,7 +12,7 @@ xit: # api response logging 여부 api: reponse: - logging: false + logging: true file: cmm: