From 9dfd5aac644126161696226a57e811cf4bcf02e8 Mon Sep 17 00:00:00 2001 From: GODrums Date: Mon, 21 Oct 2024 01:57:43 +0200 Subject: [PATCH] Create Team entity --- .../www1/hephaestus/codereview/team/Team.java | 51 +++++++++++++++++++ .../codereview/team/TeamRepository.java | 11 ++++ .../codereview/team/TeamService.java | 23 +++++++++ .../www1/hephaestus/codereview/user/User.java | 11 ++++ .../scheduler/GitHubDataSyncService.java | 11 ++-- 5 files changed, 103 insertions(+), 4 deletions(-) create mode 100644 server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/team/Team.java create mode 100644 server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/team/TeamRepository.java create mode 100644 server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/team/TeamService.java diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/team/Team.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/team/Team.java new file mode 100644 index 00000000..01b6a6a3 --- /dev/null +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/team/Team.java @@ -0,0 +1,51 @@ +package de.tum.in.www1.hephaestus.codereview.team; + +import jakarta.persistence.Table; + +import java.util.HashSet; +import java.util.Set; + +import org.springframework.lang.NonNull; + +import de.tum.in.www1.hephaestus.codereview.user.User; +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.FetchType; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.JoinTable; +import jakarta.persistence.ManyToMany; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.ToString; + +@Entity +@Table(name = "team") +@Getter +@Setter +@NoArgsConstructor +@ToString(callSuper = true) +public class Team { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @Column + private String name; + + @NonNull + private String color; + + @ManyToMany(fetch = FetchType.EAGER) + @JoinTable(name = "TEAM_MEMBERS", joinColumns = @JoinColumn(name = "team_id", referencedColumnName = "id"), inverseJoinColumns = @JoinColumn(name = "user_id", referencedColumnName = "id")) + @ToString.Exclude + private Set members = new HashSet<>(); + + public void addMember(User user) { + members.add(user); + user.addTeam(this); + } +} diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/team/TeamRepository.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/team/TeamRepository.java new file mode 100644 index 00000000..7ea5aac6 --- /dev/null +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/team/TeamRepository.java @@ -0,0 +1,11 @@ +package de.tum.in.www1.hephaestus.codereview.team; + +import java.util.Optional; + +import org.springframework.data.jpa.repository.JpaRepository; + +public interface TeamRepository extends JpaRepository { + + Optional findByName(String name); + +} diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/team/TeamService.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/team/TeamService.java new file mode 100644 index 00000000..721c63ef --- /dev/null +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/team/TeamService.java @@ -0,0 +1,23 @@ +package de.tum.in.www1.hephaestus.codereview.team; + +import java.util.Optional; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Service; + +@Service +public class TeamService { + private static final Logger logger = LoggerFactory.getLogger(TeamService.class); + + private final TeamRepository teamRepository; + + public TeamService(TeamRepository teamRepository) { + this.teamRepository = teamRepository; + } + + public Optional getTeam(String name) { + logger.info("Getting team with name: " + name); + return teamRepository.findByName(name); + } +} diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/user/User.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/user/User.java index 8c84ec51..ee452536 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/user/User.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/user/User.java @@ -12,9 +12,12 @@ import de.tum.in.www1.hephaestus.codereview.comment.review.PullRequestReviewComment; import de.tum.in.www1.hephaestus.codereview.pullrequest.PullRequest; import de.tum.in.www1.hephaestus.codereview.pullrequest.review.PullRequestReview; +import de.tum.in.www1.hephaestus.codereview.team.Team; import jakarta.persistence.CascadeType; import jakarta.persistence.Column; import jakarta.persistence.Entity; +import jakarta.persistence.FetchType; +import jakarta.persistence.ManyToMany; import jakarta.persistence.OneToMany; import lombok.Getter; import lombok.NoArgsConstructor; @@ -63,6 +66,10 @@ public class User extends BaseGitServiceEntity { @NonNull private UserType type; + @ManyToMany(fetch = FetchType.EAGER, mappedBy = "members") + @ToString.Exclude + private Set teams = new HashSet<>(); + @OneToMany(cascade = CascadeType.ALL, mappedBy = "author") private Set pullRequests = new HashSet<>(); @@ -90,4 +97,8 @@ public void addPullRequest(PullRequest pullRequest) { public void addReview(PullRequestReview review) { reviews.add(review); } + + public void addTeam(Team team) { + teams.add(team); + } } diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/scheduler/GitHubDataSyncService.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/scheduler/GitHubDataSyncService.java index 3b2cd3f1..87145489 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/scheduler/GitHubDataSyncService.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/scheduler/GitHubDataSyncService.java @@ -31,6 +31,7 @@ import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; +import de.tum.in.www1.hephaestus.admin.AdminService; import de.tum.in.www1.hephaestus.codereview.comment.IssueComment; import de.tum.in.www1.hephaestus.codereview.comment.IssueCommentConverter; import de.tum.in.www1.hephaestus.codereview.comment.IssueCommentRepository; @@ -59,9 +60,6 @@ public class GitHubDataSyncService { @Value("${github.authToken:null}") private String ghAuthToken; - @Value("${monitoring.repositories}") - private String[] repositoriesToMonitor; - @Value("${monitoring.timeframe}") private int timeframe; private OffsetDateTime cutOffTime; @@ -75,6 +73,9 @@ public class GitHubDataSyncService { private final PullRequestReviewCommentRepository reviewCommentRepository; private final UserRepository userRepository; + @Autowired + private AdminService adminService; + @Autowired private RepositoryConverter repositoryConverter; @Autowired @@ -109,6 +110,8 @@ public void syncData() { logger.error("Aborted GitHub data sync due to error during initialization of GitHub client."); return; } + + Set repositoriesToMonitor = adminService.getAdminConfig().getRepositoriesToMonitor(); int successfullySyncedRepositories = 0; for (String repositoryName : repositoriesToMonitor) { try { @@ -121,7 +124,7 @@ public void syncData() { } } logger.info("GitHub data sync completed for " + successfullySyncedRepositories + "/" - + repositoriesToMonitor.length + " repositories for the last " + timeframe + " day(s)."); + + repositoriesToMonitor.size() + " repositories for the last " + timeframe + " day(s)."); } private boolean initGithubClient() {