From 6de7a6e7e551e9e4f47d81bb1339bb918f5450f6 Mon Sep 17 00:00:00 2001 From: wonseok2877 Date: Sat, 10 Feb 2024 10:57:57 +0900 Subject: [PATCH 1/4] =?UTF-8?q?refactor:=20=ED=98=84=EC=9E=AC=20=ED=95=99?= =?UTF-8?q?=EA=B8=B0=20magic=20literal=20=EC=83=81=EC=88=98=ED=99=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/usw/suwiki/domain/lecture/service/LectureService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/usw/suwiki/domain/lecture/service/LectureService.java b/src/main/java/usw/suwiki/domain/lecture/service/LectureService.java index f20ce8ca..c81d2c69 100644 --- a/src/main/java/usw/suwiki/domain/lecture/service/LectureService.java +++ b/src/main/java/usw/suwiki/domain/lecture/service/LectureService.java @@ -139,7 +139,7 @@ private static List convertJSONArrayToVOList(JSONArray jsonArray) @Transactional(propagation = Propagation.MANDATORY) public void bulkApplyJsonLectureList(List jsonLectureVOList) { List currentSemeterLectureScheduleList = lectureRepository - .findAllLectureSchedulesByLectureSemesterContains("2024-1"); + .findAllLectureSchedulesByLectureSemesterContains(currentSemester); List deletedLectureScheduleList = resolveDeletedLectureScheduleList( jsonLectureVOList, From 3e0b1eda8059b49f901bc303f90c7ce0a0a71c0f Mon Sep 17 00:00:00 2001 From: wonseok2877 Date: Sat, 10 Feb 2024 12:48:38 +0900 Subject: [PATCH 2/4] =?UTF-8?q?hotfix:=20=EA=B0=95=EC=9D=98=20=EB=8D=B0?= =?UTF-8?q?=EC=9D=B4=ED=84=B0=20=EC=A0=81=EC=9E=AC=EC=8B=9C=20place=5Fsche?= =?UTF-8?q?dule=20null=20=EB=8D=B0=EC=9D=B4=ED=84=B0=20=EC=A0=80=EC=9E=A5?= =?UTF-8?q?=20=EB=AC=B8=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/lecture/service/LectureService.java | 18 ++++++++++-------- .../global/util/loadjson/JSONLectureVO.java | 8 ++++++-- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/main/java/usw/suwiki/domain/lecture/service/LectureService.java b/src/main/java/usw/suwiki/domain/lecture/service/LectureService.java index c81d2c69..c8980f0f 100644 --- a/src/main/java/usw/suwiki/domain/lecture/service/LectureService.java +++ b/src/main/java/usw/suwiki/domain/lecture/service/LectureService.java @@ -166,11 +166,7 @@ private void applyJsonLecture( boolean isThereNewSchedule = lecture.getScheduleList().stream() .noneMatch(jsonLectureVO::isLectureAndPlaceScheduleEqual); if (isThereNewSchedule) { - LectureSchedule schedule = LectureSchedule.builder() - .lecture(lecture) - .placeSchedule(jsonLectureVO.getPlaceSchedule()) - .build(); - lectureScheduleRepository.save(schedule); + saveOnlyValidLectureSchedule(jsonLectureVO, lecture); } deletedLectureScheduleList.stream() @@ -178,12 +174,18 @@ private void applyJsonLecture( .forEach(lecture::removeSchedule); } else { Lecture newLecture = jsonLectureVO.toEntity(); - LectureSchedule.builder() + saveOnlyValidLectureSchedule(jsonLectureVO, newLecture); + lectureRepository.save(newLecture); + } + } + + private void saveOnlyValidLectureSchedule(JSONLectureVO jsonLectureVO, Lecture newLecture) { + if (jsonLectureVO.isPlaceScheduleValid()) { + LectureSchedule schedule = LectureSchedule.builder() .lecture(newLecture) .placeSchedule(jsonLectureVO.getPlaceSchedule()) .build(); - - lectureRepository.save(newLecture); + lectureScheduleRepository.save(schedule); } } diff --git a/src/main/java/usw/suwiki/global/util/loadjson/JSONLectureVO.java b/src/main/java/usw/suwiki/global/util/loadjson/JSONLectureVO.java index 5c308b9f..d93fa12f 100644 --- a/src/main/java/usw/suwiki/global/util/loadjson/JSONLectureVO.java +++ b/src/main/java/usw/suwiki/global/util/loadjson/JSONLectureVO.java @@ -53,8 +53,6 @@ public Lecture toEntity() { .capprType(capprType) .build(); - // TODO fix: LectureSchedule 생성. 이 메서드 말고 밖에서 만들어야 할듯 - return Lecture.builder() .name(lectureName) .type(lectureType) @@ -65,6 +63,12 @@ public Lecture toEntity() { .build(); } + + + public boolean isPlaceScheduleValid() { + return !(placeSchedule.equals("null") || placeSchedule.isEmpty()); + } + public boolean isLectureAndPlaceScheduleEqual(LectureSchedule lectureSchedule) { return lectureSchedule.getPlaceSchedule().contains(placeSchedule) && lectureSchedule.getLecture().getName().equals(lectureName) From f6beace634b2d902e591394819a869e163ac1f9d Mon Sep 17 00:00:00 2001 From: wonseok2877 Date: Sat, 10 Feb 2024 12:48:49 +0900 Subject: [PATCH 3/4] =?UTF-8?q?hotfix:=20=EA=B0=95=EC=9D=98=20=EC=8B=9C?= =?UTF-8?q?=EA=B0=84=ED=91=9C=20=EC=A1=B0=ED=9A=8C=EC=8B=9C=20place=20?= =?UTF-8?q?=EB=AF=B8=EC=A0=95=EB=90=9C=20=EB=8D=B0=EC=9D=B4=ED=84=B0=20?= =?UTF-8?q?=EC=B2=98=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lecture/util/LectureStringConverter.java | 30 +++++++------------ 1 file changed, 11 insertions(+), 19 deletions(-) diff --git a/src/main/java/usw/suwiki/domain/lecture/util/LectureStringConverter.java b/src/main/java/usw/suwiki/domain/lecture/util/LectureStringConverter.java index 1b4d9ccd..55dff2bd 100644 --- a/src/main/java/usw/suwiki/domain/lecture/util/LectureStringConverter.java +++ b/src/main/java/usw/suwiki/domain/lecture/util/LectureStringConverter.java @@ -3,40 +3,24 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import java.util.Objects; -import java.util.regex.Pattern; import usw.suwiki.domain.timetable.entity.TimetableCellSchedule; import usw.suwiki.domain.timetable.entity.TimetableDay; -// TODO refactor: TimetableCellSchedule 의존성 제거. 해당 클래스는 스트링 변환 작업만 책임지도록 public final class LectureStringConverter { - /* - 변환에 필요한 최소한의 스트링 형식입니다. https://regexr.com/7q2nv - pass : "강의실107-1(수6,7,8)" "강의실 B215(화5,6,7 수5,6,7)" - fail : "(월1,2)" "강의실(1,2)" "강의실 월1,2" "강의실107(요일아님6,7,8)" - */ - private static final String PLACE_SCHEDULE_REGEX = "^([\\s가-힣A-Za-z\\d-]+\\([월화수목금토일]\\d+(?:,\\d+)*.*?\\))+$"; + private static final String LOCATION_IF_BLANK = "미정"; /** - * @param scheduleChunk 강의 장소 및 시간 원본 lecture.place_schedule + * @param scheduleChunk 강의 장소 및 시간 원본 lecture_schedule.place_schedule * @implNote place_schedule을 TimetableCellSchedule 객체 리스트로 변환 */ public static List convertScheduleChunkIntoTimetableCellScheduleList(String scheduleChunk) { List scheduleList = new ArrayList<>(); - // TODO refactor: "null" -> null. 데이터 파싱 로직 변경 필요 - if (Objects.equals(scheduleChunk, "null") - || Objects.isNull(scheduleChunk) - || !Pattern.matches(PLACE_SCHEDULE_REGEX, scheduleChunk) - ) { - return scheduleList; - } - List locationAndDaysChunkList = splitScheduleChunkIntoLocationAndDaysChunkList(scheduleChunk); for (String locationAndDaysChunk : locationAndDaysChunkList) { - String location = extractLocationFromLocationAndDaysChunk(locationAndDaysChunk); + String location = resolveLocationFromLocationAndDaysChunk(locationAndDaysChunk); String DaysChunk = extractDaysChunkFromLocationAndDaysElementChunk(locationAndDaysChunk); for (String dayAndPeriodsChunk : splitDaysChunkIntoDayAndPeriodsChunkList(DaysChunk)) { @@ -68,6 +52,14 @@ private static List splitScheduleChunkIntoLocationAndDaysChunkList(Strin return Arrays.asList(chunk.split(",(?![^()]*\\))")); } + private static String resolveLocationFromLocationAndDaysChunk(String chunk) { + String locationLiteral = extractLocationFromLocationAndDaysChunk(chunk); + if (locationLiteral.isBlank()) { + return LOCATION_IF_BLANK; + } + return locationLiteral; + } + private static String extractLocationFromLocationAndDaysChunk(String chunk) { // e.g. "IT103(월1,2, 화1,2)" -> "IT103" return chunk.split("\\(")[0]; From 8e576e300f9a5be4644cbd25ff6bfdbe78b5cb8d Mon Sep 17 00:00:00 2001 From: wonseok2877 Date: Sat, 10 Feb 2024 12:49:07 +0900 Subject: [PATCH 4/4] =?UTF-8?q?docs:=20TODO=20=EB=8D=B0=EC=9D=B4=ED=84=B0?= =?UTF-8?q?=20=EC=A0=81=EC=9E=AC=EC=8B=9C=20regex=20=EA=B2=80=EC=82=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../suwiki/global/util/loadjson/USWTermResolver.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/main/java/usw/suwiki/global/util/loadjson/USWTermResolver.java b/src/main/java/usw/suwiki/global/util/loadjson/USWTermResolver.java index 1d2e7bb1..c7a2efa8 100644 --- a/src/main/java/usw/suwiki/global/util/loadjson/USWTermResolver.java +++ b/src/main/java/usw/suwiki/global/util/loadjson/USWTermResolver.java @@ -4,6 +4,16 @@ public final class USWTermResolver { private static final String[] KEYWORDS_TO_REMOVE = {"재수강", "비대면수업", "대면수업", "혼합수업"}; + + // TODO refactor: REGEX 검사 + // 변환에 필요한 최소한의 스트링 형식입니다. + // 해당 형식에 맞지 않는다면 수원대측에서 형식을 바꾼 것이므로 더 이상 호환되지 않기 때문에 예외를 발생시키고 적재를 중단해야 합니다. + // https://regexr.com/7rq1g + // pass : "강의실107-1(수6,7,8)" "강의실 B215(화5,6,7 수5,6,7)" + // pass : "(월1,2)" -> "미정(월1,2)" + // fail : "강의실(1,2)" "강의실 월1,2" "강의실107(요일아님6,7,8)" "요일없음(1,2)" "강의실103(화5,6),강의실103" +// private static final String PLACE_SCHEDULE_REGEX = "^([\\s가-힣A-Za-z\\d-]+\\([월화수목금토일]\\d+(?:,\\d+)*.*?\\))+$"; + private static final String ESTABLISHED_YEAR = "subjtEstbYear"; private static final String ESTABLISHED_SEMESTER = "subjtEstbSmrCd"; private static final String PLACE_SCHEDULE = "timtSmryCn";