diff --git a/eeos/src/main/java/com/blackcompany/eeos/program/application/util/ProgramInitializer.java b/eeos/src/main/java/com/blackcompany/eeos/program/application/util/ProgramInitializer.java deleted file mode 100644 index fbdef24b..00000000 --- a/eeos/src/main/java/com/blackcompany/eeos/program/application/util/ProgramInitializer.java +++ /dev/null @@ -1,53 +0,0 @@ -package com.blackcompany.eeos.program.application.util; - -import com.blackcompany.eeos.program.application.model.ProgramAttendMode; -import com.blackcompany.eeos.program.persistence.ProgramEntity; -import com.blackcompany.eeos.program.persistence.ProgramRepository; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.springframework.boot.ApplicationArguments; -import org.springframework.boot.ApplicationRunner; -import org.springframework.stereotype.Component; - -import java.util.List; -import java.util.stream.Collectors; - -@Component -@RequiredArgsConstructor -@Slf4j -public class ProgramInitializer implements ApplicationRunner { - - private final ProgramRepository programRepository; - private final String defaultUrl = "https://github.com/JNU-econovation/weekly_presentation/tree/2024-1/2024-1/A_team/1st"; - - @Override - public void run(ApplicationArguments args) throws Exception { - System.out.println("------------Program Initializer----------"); - List programs = getPrograms(); - - if(programs.isEmpty()) return; - - programs = programs.stream() - .map(program -> { - if(program.getGithubUrl()==null){ - return program.toBuilder().githubUrl(defaultUrl).build(); - } - return program; - }) - .map(program -> { - if(program.getAttendMode()==null){ - return program.toBuilder().attendMode(ProgramAttendMode.END).build(); - } - - return program; - }) - .collect(Collectors.toList()); - - programRepository.saveAll(programs); - System.out.println("----------------------------------------------"); - } - - private List getPrograms(){ - return programRepository.findAll(); - } -} diff --git a/eeos/src/main/java/com/blackcompany/eeos/target/application/util/PresentationInitializer.java b/eeos/src/main/java/com/blackcompany/eeos/target/application/util/PresentationInitializer.java deleted file mode 100644 index 3591e857..00000000 --- a/eeos/src/main/java/com/blackcompany/eeos/target/application/util/PresentationInitializer.java +++ /dev/null @@ -1,94 +0,0 @@ -package com.blackcompany.eeos.target.application.util; - -import com.blackcompany.eeos.program.persistence.ProgramEntity; -import com.blackcompany.eeos.program.persistence.ProgramRepository; -import com.blackcompany.eeos.target.persistence.PresentationEntity; -import com.blackcompany.eeos.target.persistence.PresentationRepository; -import com.blackcompany.eeos.team.application.exception.NotFoundTeamException; -import com.blackcompany.eeos.team.persistence.TeamEntity; -import com.blackcompany.eeos.team.persistence.TeamRepository; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.boot.ApplicationArguments; -import org.springframework.boot.ApplicationRunner; -import org.springframework.stereotype.Component; - -import java.util.Arrays; -import java.util.List; -import java.util.Set; -import java.util.stream.Collectors; - -// 기존에 저장된 Program과 Team을 매핑하는 구조 -@Component -@RequiredArgsConstructor -@Slf4j -public class PresentationInitializer implements ApplicationRunner { - - private final PresentationRepository presentationRepository; - private final ProgramRepository programRepository; - private final TeamRepository teamRepository; - - @Value("${eeos.team.list}") - private String teamList; - - @Override - public void run(ApplicationArguments args) throws Exception { - System.out.println("------------Presentation Initializer----------"); - Set programs = getPrograms().stream().map(ProgramEntity::getId).collect(Collectors.toSet()); - - if(programs.isEmpty()) return; - - Set presentations = getPresentations().stream() - .map(PresentationEntity::getProgramId) - .collect(Collectors.toSet()); - - Set target = programs.stream() - .filter(programId -> !presentations.contains(programId)) - .collect(Collectors.toSet()); - - List teams= getTeams(); - teams.forEach(team->log.info(team.getName())); - - target.forEach(targetId -> - { - Set entities = - teams.stream() - .map(TeamEntity::getId) - .map(teamId -> PresentationEntity.builder() - .teamId(teamId) - .programId(targetId) - .build()) - .collect(Collectors.toSet()); - presentationRepository.saveAll(entities); - }); - - System.out.println("----------------------------------------------"); - } - - private List getTeamList(){ - return Arrays.stream(teamList.split(",")).toList(); - } - - private List getPrograms(){ - return programRepository.findAll(); - } - - private List getTeams(){ - List teams = getTeamList(); - try { - return teamRepository.findAllTeams().stream().filter(team -> teams.contains(team.getName())).toList(); - } catch (NotFoundTeamException e){ - return createTeams(); - } - } - - private List createTeams(){ - Set teams = getTeamList().stream().map(team -> TeamEntity.builder().name(team).status(false).build()).collect(Collectors.toSet()); - return teamRepository.saveAll(teams); - } - - private List getPresentations(){ - return presentationRepository.findAll(); - } -} diff --git a/eeos/src/main/java/com/blackcompany/eeos/team/application/util/TeamInitializer.java b/eeos/src/main/java/com/blackcompany/eeos/team/application/util/TeamInitializer.java deleted file mode 100644 index f905c19e..00000000 --- a/eeos/src/main/java/com/blackcompany/eeos/team/application/util/TeamInitializer.java +++ /dev/null @@ -1,48 +0,0 @@ -package com.blackcompany.eeos.team.application.util; - -import com.blackcompany.eeos.team.persistence.TeamEntity; -import com.blackcompany.eeos.team.persistence.TeamRepository; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.boot.ApplicationArguments; -import org.springframework.boot.ApplicationRunner; -import org.springframework.stereotype.Component; - -import java.util.Arrays; -import java.util.Set; -import java.util.stream.Collectors; - - -// 기존 데이터베이스와의 데이터 정합성을 위한 클래스 -@RequiredArgsConstructor -@Slf4j -@Component -public class TeamInitializer implements ApplicationRunner { - - private final TeamRepository teamRepository; - - @Value("${eeos.team.list}") - private String teamList; - - @Override - public void run(ApplicationArguments args) throws Exception { - System.out.println("-----------Team Initializer-----------"); - Arrays.stream(teamList.split(",")).forEach(log::info); - try { - Set newTeams = Arrays.stream(teamList.split(",")) - .map(teamName -> TeamEntity.builder().name(teamName).status(false).build()) - .collect(Collectors.toSet()); - teamRepository.saveAll(newTeams); - log.info("임시 팀이 생성되었습니다."); - } catch (Exception e){ - log.error("임시 팀이 생성되지 않았습니다."); - } - System.out.println("---------------------------------------"); - - } - - private boolean isEmptyTable(){ - return teamRepository.findAllTeams().isEmpty(); - } -}