Skip to content

Commit

Permalink
Merge pull request #80 from uswLectureEvaluation/hotfix/lecture_sched…
Browse files Browse the repository at this point in the history
…ule_place_obmission

hotfix: 강의 시간표상 시간 미정된 강의들에 대한 누락 문제
  • Loading branch information
wonslee authored Feb 10, 2024
2 parents 4b46553 + 8e576e3 commit 7728096
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ private static List<JSONLectureVO> convertJSONArrayToVOList(JSONArray jsonArray)
@Transactional(propagation = Propagation.MANDATORY)
public void bulkApplyJsonLectureList(List<JSONLectureVO> jsonLectureVOList) {
List<LectureSchedule> currentSemeterLectureScheduleList = lectureRepository
.findAllLectureSchedulesByLectureSemesterContains("2024-1");
.findAllLectureSchedulesByLectureSemesterContains(currentSemester);

List<LectureSchedule> deletedLectureScheduleList = resolveDeletedLectureScheduleList(
jsonLectureVOList,
Expand All @@ -166,24 +166,26 @@ 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()
.filter(it -> it.getLecture().getId().equals(lecture.getId()))
.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);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<TimetableCellSchedule> convertScheduleChunkIntoTimetableCellScheduleList(String scheduleChunk) {
List<TimetableCellSchedule> scheduleList = new ArrayList<>();

// TODO refactor: "null" -> null. 데이터 파싱 로직 변경 필요
if (Objects.equals(scheduleChunk, "null")
|| Objects.isNull(scheduleChunk)
|| !Pattern.matches(PLACE_SCHEDULE_REGEX, scheduleChunk)
) {
return scheduleList;
}

List<String> locationAndDaysChunkList = splitScheduleChunkIntoLocationAndDaysChunkList(scheduleChunk);

for (String locationAndDaysChunk : locationAndDaysChunkList) {
String location = extractLocationFromLocationAndDaysChunk(locationAndDaysChunk);
String location = resolveLocationFromLocationAndDaysChunk(locationAndDaysChunk);

String DaysChunk = extractDaysChunkFromLocationAndDaysElementChunk(locationAndDaysChunk);
for (String dayAndPeriodsChunk : splitDaysChunkIntoDayAndPeriodsChunkList(DaysChunk)) {
Expand Down Expand Up @@ -68,6 +52,14 @@ private static List<String> 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];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@ public Lecture toEntity() {
.capprType(capprType)
.build();

// TODO fix: LectureSchedule 생성. 이 메서드 말고 밖에서 만들어야 할듯

return Lecture.builder()
.name(lectureName)
.type(lectureType)
Expand All @@ -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)
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/usw/suwiki/global/util/loadjson/USWTermResolver.java
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down

0 comments on commit 7728096

Please sign in to comment.