Skip to content

Commit

Permalink
[Fix] duplicate notice (#122)
Browse files Browse the repository at this point in the history
* refactor(CommonNoticeFormatDto): Builder의 서식 지정자를 private로 변경

* fix(NoticeJdbcRepository): 빼먹은 학과 이름 추가

* feat(NoticeUpdateSupport): NoticeUpdater의 공통로직 추출

* refactor(DepartmentName): DepartmentName을 찾아오는 로직을 cache를 활용하도록 리팩토링

* fix(NoticeJdbcRepository): 학과이름 인자 추가

* refactor(CategoryName#fromStringName): String인자로 해당 Enum값을 찾아오는 로직 리패토링

* refactor: Java 17로 변경후 기존의 .collect(Collectors.toList()) 로직을 toList()로 변경한다

* feat: 더이상 사용하지 않는 에노테이션 제거

* feat: 중복된 학과 공지 제거 SQL문 추가

* refactor: 테스트에서 서식 지정자 제거

* fix: SQL문에서 테이블 중복 이름 오류 수정
  • Loading branch information
zbqmgldjfh committed Jan 21, 2024
1 parent 74aa721 commit 18e60b9
Show file tree
Hide file tree
Showing 30 changed files with 569 additions and 206 deletions.
2 changes: 1 addition & 1 deletion src/main/java/com/kustacks/kuring/admin/domain/Admin.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public List<String> getAuthorities() {
return this.adminRoles.getRoles()
.stream()
.map(AdminRole::name)
.collect(Collectors.toList());
.toList();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public void checkAuthorities(JoinPoint joinPoint) {
Secured secured = method.getAnnotation(Secured.class);
List<String> values = Arrays.stream(secured.value())
.map(String::valueOf)
.collect(Collectors.toList());
.toList();

Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
if(isRoleRoot(authentication)) {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ private void sendBaseNotification(NoticeMessageDto messageDto, Function<String,
private List<NoticeMessageDto> createNotification(List<? extends Notice> willBeNotiNotices) {
return willBeNotiNotices.stream()
.map(NoticeMessageDto::from)
.collect(Collectors.toList());
.toList();
}

private void sendNoticeMessageList(List<NoticeMessageDto> messageDtoList) throws FirebaseMessageSendException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ private String[] splitBySpace(String content) {
private List<String> noticeCategoryNameConvertEnglish(String[] splitedKeywords) {
return Arrays.stream(splitedKeywords)
.map(this::convertEnglish)
.collect(Collectors.toList());
.toList();
}

private String convertEnglish(String keyword) {
Expand Down
29 changes: 15 additions & 14 deletions src/main/java/com/kustacks/kuring/notice/domain/CategoryName.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
import lombok.Getter;

import java.util.Arrays;
import java.util.Collections;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;

import static com.kustacks.kuring.common.exception.code.ErrorCode.CAT_NOT_EXIST_CATEGORY;

Expand All @@ -20,6 +24,13 @@ public enum CategoryName {
LIBRARY("library", "lib", "도서관"),
DEPARTMENT("department", "dep", "학과");

private static final Map<String, String> NAME_MAP;

static {
NAME_MAP = Collections.unmodifiableMap(Arrays.stream(CategoryName.values())
.collect(Collectors.toMap(CategoryName::getName, CategoryName::name)));
}

private String name;
private String shortName;
private String korName;
Expand All @@ -38,23 +49,13 @@ public boolean isSameShortName(String shortName) {
return this.shortName.equals(shortName);
}

public boolean isSameKorName(String name) {
return this.korName.equals(name);
}

public static boolean containsEnumValue(String value) {
try {
Enum.valueOf(CategoryName.class, value);
return true;
} catch (IllegalArgumentException e) {
return false;
}
public boolean isSameKorName(String korName) {
return this.korName.equals(korName);
}

public static CategoryName fromStringName(String name) {
return Arrays.stream(CategoryName.values())
.filter(d -> d.isSameName(name))
.findFirst()
String findName = Optional.ofNullable(NAME_MAP.get(name))
.orElseThrow(() -> new NotFoundException(CAT_NOT_EXIST_CATEGORY));
return CategoryName.valueOf(findName);
}
}
41 changes: 28 additions & 13 deletions src/main/java/com/kustacks/kuring/notice/domain/DepartmentName.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
import lombok.Getter;

import java.util.Arrays;
import java.util.Collections;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;

import static com.kustacks.kuring.common.exception.code.ErrorCode.DEPARTMENT_NOT_FOUND;

Expand Down Expand Up @@ -85,6 +89,21 @@ public enum DepartmentName {
ELE_EDU_CENTER("elective_education_center", "sgedu", "교양교육센터"),
VOLUNTEER("volunteer_center", "kuvolunteer", "사회봉사센터");

private static final Map<String, String> NAME_MAP;
private static final Map<String, String> HOST_PREFIX_MAP;
private static final Map<String, String> KOR_NAME_MAP;

static {
NAME_MAP = Collections.unmodifiableMap(Arrays.stream(DepartmentName.values())
.collect(Collectors.toMap(DepartmentName::getName, DepartmentName::name)));

HOST_PREFIX_MAP = Collections.unmodifiableMap(Arrays.stream(DepartmentName.values())
.collect(Collectors.toMap(DepartmentName::getHostPrefix, DepartmentName::name)));

KOR_NAME_MAP = Collections.unmodifiableMap(Arrays.stream(DepartmentName.values())
.collect(Collectors.toMap(DepartmentName::getKorName, DepartmentName::name)));
}

private final String name;
private final String hostPrefix;
private final String korName;
Expand All @@ -95,25 +114,21 @@ public enum DepartmentName {
this.korName = korName;
}

public boolean isSameHostPrefix(String name) {
return this.hostPrefix.equals(name);
}

public boolean isSameKorName(String name) {
return this.korName.equals(name);
public static DepartmentName fromName(String name) {
String findName = Optional.ofNullable(NAME_MAP.get(name))
.orElseThrow(() -> new NotFoundException(DEPARTMENT_NOT_FOUND));
return DepartmentName.valueOf(findName);
}

public static DepartmentName fromHostPrefix(String hostPrefix) {
return Arrays.stream(DepartmentName.values())
.filter(d -> d.isSameHostPrefix(hostPrefix))
.findFirst()
String findHostPrefix = Optional.ofNullable(HOST_PREFIX_MAP.get(hostPrefix))
.orElseThrow(() -> new NotFoundException(DEPARTMENT_NOT_FOUND));
return DepartmentName.valueOf(findHostPrefix);
}

public static DepartmentName fromKor(String departmentName) {
return Arrays.stream(DepartmentName.values())
.filter(d -> d.isSameKorName(departmentName))
.findFirst()
public static DepartmentName fromKor(String korName) {
String findKorName = Optional.ofNullable(KOR_NAME_MAP.get(korName))
.orElseThrow(() -> new NotFoundException(DEPARTMENT_NOT_FOUND));
return DepartmentName.valueOf(findKorName);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public int getBatchSize() {

@Transactional
public void saveAllDepartmentNotices(List<DepartmentNotice> departmentNotices) {
jdbcTemplate.batchUpdate("INSERT INTO notice (article_id, category_name, important, posted_dt, subject, updated_dt, url, dtype) values (?, ?, ?, ?, ?, ?, ?, 'DepartmentNotice')",
jdbcTemplate.batchUpdate("INSERT INTO notice (article_id, category_name, important, posted_dt, subject, updated_dt, url, department_name, dtype) values (?, ?, ?, ?, ?, ?, ?, ?, 'DepartmentNotice')",
new BatchPreparedStatementSetter() {
@Override
public void setValues(PreparedStatement ps, int i) throws SQLException {
Expand All @@ -53,6 +53,7 @@ public void setValues(PreparedStatement ps, int i) throws SQLException {
ps.setString(5, departmentNotice.getSubject());
ps.setString(6, departmentNotice.getUpdatedDate());
ps.setString(7, departmentNotice.getUrl());
ps.setString(8, DepartmentName.fromName(departmentNotice.getDepartmentName()).name());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public NoticeLookupResponse searchNoticeByContent(String content) {
public List<CategoryNameDto> getSupportedCategories() {
return Stream.of(CategoryName.values())
.map(CategoryNameDto::from)
.collect(Collectors.toList());
.toList();
}

public List<DepartmentNameDto> getSupportedDepartments() {
Expand All @@ -44,6 +44,6 @@ private List<DepartmentNameDto> convertDepartmentNameDtos(List<DepartmentName> d
.filter(dn -> !dn.equals(DepartmentName.BIO_SCIENCE))
.filter(dn -> !dn.equals(DepartmentName.COMM_DESIGN))
.map(DepartmentNameDto::from)
.collect(Collectors.toList());
.toList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,12 @@ private User findUserByToken(String token) {
private List<CategoryName> convertToEnumList(List<String> categories) {
return categories.stream()
.map(CategoryName::fromStringName)
.collect(Collectors.toList());
.toList();
}

private List<DepartmentName> convertHostPrefixToEnum(List<String> departments) {
return departments.stream()
.map(DepartmentName::fromHostPrefix)
.collect(Collectors.toList());
.toList();
}
}
16 changes: 5 additions & 11 deletions src/main/java/com/kustacks/kuring/user/domain/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,12 @@
import lombok.Getter;
import lombok.NoArgsConstructor;

import javax.persistence.Column;
import javax.persistence.Embedded;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.*;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;

@Entity
@NoArgsConstructor(access = AccessLevel.PROTECTED)
Expand Down Expand Up @@ -88,25 +82,25 @@ public List<DepartmentName> getSubscribedDepartmentList() {
public List<CategoryName> filteringNewCategoryName(List<CategoryName> newCategoryNames) {
return newCategoryNames.stream()
.filter(newCategoryName -> !this.categories.contains(newCategoryName))
.collect(Collectors.toList());
.toList();
}

public List<CategoryName> filteringOldCategoryName(List<CategoryName> newCategoryNames) {
return this.categories.getCategoryNamesSet().stream().
filter(oldCategoryName -> !newCategoryNames.contains(oldCategoryName))
.collect(Collectors.toList());
.toList();
}

public List<DepartmentName> filteringNewDepartmentName(List<DepartmentName> newDepartmentNames) {
return newDepartmentNames.stream()
.filter(newDepartmentName -> !this.departments.contains(newDepartmentName))
.collect(Collectors.toList());
.toList();
}

public List<DepartmentName> filteringOldDepartmentName(List<DepartmentName> newDepartmentNames) {
return this.departments.getDepartmentNamesSet().stream()
.filter(oldDepartmentName -> !newDepartmentNames.contains(oldDepartmentName))
.collect(Collectors.toList());
.toList();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ public List<FeedbackDto> lookupFeedbacks(int page, int size) {
private List<CategoryNameDto> convertCategoryNameDtoList(List<CategoryName> categoryNamesList) {
return categoryNamesList.stream()
.map(CategoryNameDto::from)
.collect(Collectors.toList());
.toList();
}

private List<DepartmentNameDto> convertDepartmentDtoList(List<DepartmentName> departmentNames) {
return departmentNames.stream()
.map(DepartmentNameDto::from)
.collect(Collectors.toList());
.toList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,6 @@ private HttpHeaders createKuisNoticeRequestHeader(String sessionId) {
private List<CommonNoticeFormatDto> convertToCommonFormatDto(List<KuisNoticeDto> kuisNoticeDtoList) {
return kuisNoticeDtoList.stream()
.map(dto -> (CommonNoticeFormatDto) dtoConverter.convert(dto))
.collect(Collectors.toList());
.toList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ private String buildUrl(String url, int offset, int max) {
private List<CommonNoticeFormatDto> convertToCommonFormatDto(List<LibraryNoticeDto> libraryNoticeDtoList) {
return libraryNoticeDtoList.stream()
.map(dto -> (CommonNoticeFormatDto) dtoConverter.convert(dto))
.collect(Collectors.toList());
.toList();
}

private void validateResponse(int requestIndex, LibraryNoticeResponseDto libraryNoticeResponseDto) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public RowsDto parse(Document document) {
private List<String[]> extractNoticeListFromRows(Elements rows) {
return rows.stream()
.map(LatestPageNoticeHtmlParser::extractNoticeFromRow)
.collect(Collectors.toList());
.toList();
}

private static String[] extractNoticeFromRow(Element row) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public RowsDto parse(Document document) {
private List<String[]> extractNoticeListFromRows(Elements rows) {
return rows.stream()
.map(LatestPageNoticeHtmlParserTwo::extractNoticeFromRow)
.collect(Collectors.toList());
.toList();
}

private static String[] extractNoticeFromRow(Element row) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public List<CommonNoticeFormatDto> buildImportantRowList(String viewUrl) {
.fullUrl(viewUrl + row[0])
.important(true)
.build())
.collect(Collectors.toList());
.toList();
}

public List<CommonNoticeFormatDto> buildNormalRowList(String viewUrl) {
Expand All @@ -38,6 +38,6 @@ public List<CommonNoticeFormatDto> buildNormalRowList(String viewUrl) {
.fullUrl(viewUrl + row[0])
.important(false)
.build())
.collect(Collectors.toList());
.toList();
}
}
Loading

0 comments on commit 18e60b9

Please sign in to comment.