Skip to content

Commit 4921821

Browse files
add comments
1 parent 5c62c63 commit 4921821

File tree

7 files changed

+70
-34
lines changed

7 files changed

+70
-34
lines changed

src/main/java/de/tum/cit/aet/dataProcessing/service/RequestService.java

Lines changed: 40 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package de.tum.cit.aet.dataProcessing.service;
22

3+
import de.tum.cit.aet.analysis.dto.AuthorContributionDTO;
34
import de.tum.cit.aet.analysis.service.AnalysisService;
45
import de.tum.cit.aet.core.dto.ArtemisCredentials;
56
import de.tum.cit.aet.repositoryProcessing.domain.*;
@@ -36,6 +37,22 @@ public RequestService(RepositoryFetchingService repositoryFetchingService, Analy
3637
this.studentRepository = studentRepository;
3738
}
3839

40+
/**
41+
* Fetches, analyzes, and saves repository data using the provided Artemis credentials.
42+
*
43+
* @param credentials The Artemis credentials
44+
*/
45+
public void fetchAnalyzeAndSaveRepositories(ArtemisCredentials credentials) {
46+
// Fetch and clone repositories
47+
List<TeamRepositoryDTO> repositories = fetchAndCloneRepositories(credentials);
48+
49+
// Analyze contributions
50+
Map<Long, AuthorContributionDTO> contributionData = getContributionData(repositories);
51+
52+
// Save results to the database
53+
saveResults(repositories, contributionData);
54+
}
55+
3956
/**
4057
* Fetches and clones all repositories from Artemis using dynamic credentials.
4158
*
@@ -53,42 +70,25 @@ public List<TeamRepositoryDTO> fetchAndCloneRepositories(ArtemisCredentials cred
5370
* @param repositories List of TeamRepositoryDTO to be analyzed
5471
* @return Map of Participant ID to an array of contribution metrics (e.g., lines added, lines deleted)
5572
*/
56-
public Map<Long, int[]> getContributionData(List<TeamRepositoryDTO> repositories) {
73+
public Map<Long, AuthorContributionDTO> getContributionData(List<TeamRepositoryDTO> repositories) {
5774
return analysisService.analyzeContributions(repositories);
5875
}
5976

60-
/**
61-
* Fetches, analyzes, and saves repository data using the provided Artemis credentials.
62-
*
63-
* @param credentials The Artemis credentials
64-
*/
65-
public void fetchAnalyzeAndSaveRepositories(ArtemisCredentials credentials) {
66-
// Fetch and clone repositories
67-
List<TeamRepositoryDTO> repositories = fetchAndCloneRepositories(credentials);
68-
69-
// Analyze contributions
70-
Map<Long, int[]> contributionData = getContributionData(repositories);
71-
for (int[] lines : contributionData.values()) {
72-
log.info("Contribution Data - Added Lines: {}, Deleted Lines: {}", lines[0], lines[1]);
73-
}
74-
75-
// Save results to the database
76-
saveResults(repositories, contributionData);
77-
}
78-
7977
/**
8078
* Saves the fetched repository information into the database.
8179
*
8280
* @param repositories List of TeamRepositoryDTO to be saved
8381
* @param contributionData Map of Participant ID to an array of contribution metrics (e.g., lines added, lines deleted)
8482
*/
85-
public void saveResults(List<TeamRepositoryDTO> repositories, Map<Long, int[]> contributionData) {
83+
public void saveResults(List<TeamRepositoryDTO> repositories, Map<Long, AuthorContributionDTO> contributionData) {
84+
// Clear existing data in database tables. We assume a full refresh of all data is intended, effectively treating the run as idempotent
8685
teamRepositoryRepository.deleteAll();
8786
studentRepository.deleteAll();
8887
teamParticipationRepository.deleteAll();
8988
tutorRepository.deleteAll();
9089

9190
for (TeamRepositoryDTO repo : repositories) {
91+
// Save tutor
9292
ParticipantDTO tut = repo.participation().team().owner();
9393
Tutor tutor = null;
9494
if (tut == null) {
@@ -98,25 +98,35 @@ public void saveResults(List<TeamRepositoryDTO> repositories, Map<Long, int[]> c
9898
tutorRepository.save(tutor);
9999
}
100100

101+
// Save team participation
101102
ParticipationDTO participation = repo.participation();
102103
TeamDTO team = participation.team();
103104
TeamParticipation teamParticipation = new TeamParticipation(participation.id(), team.id(), tutor, team.name(), team.shortName(), participation.repositoryUri(), participation.submissionCount());
104105
teamParticipationRepository.save(teamParticipation);
105106

107+
// Save students with contributions
106108
List<Student> students = new ArrayList<>();
107109
for (ParticipantDTO student : repo.participation().team().students()) {
108-
int[] lines = contributionData.get(student.id());
109-
if (lines == null) {
110-
lines = new int[]{0, 0, 0};
110+
AuthorContributionDTO contributionDTO = contributionData.get(student.id());
111+
112+
// Handle the case where a student made no contributions (e.g., if they were registered but never committed)
113+
if (contributionDTO == null) {
114+
contributionDTO = new AuthorContributionDTO(0, 0, 0);
111115
}
112-
students.add(new Student(student.id(), student.login(), student.name(), student.email(), teamParticipation, lines[2], lines[0], lines[1], lines[0] + lines[1]));
116+
117+
students.add(new Student(student.id(), student.login(), student.name(), student.email(), teamParticipation,
118+
contributionDTO.commitCount(), contributionDTO.linesAdded(), contributionDTO.linesDeleted(),
119+
contributionDTO.linesAdded() + contributionDTO.linesDeleted()));
113120
}
114121
studentRepository.saveAll(students);
115122

123+
// Save team repository
116124
TeamRepository teamRepo = new TeamRepository(teamParticipation, null, repo.localPath(), repo.isCloned(), repo.error());
117125

126+
// Process VCS logs
118127
List<VCSLog> vcsLogs = repo.vcsLogs().stream().map(log -> new VCSLog(teamRepo, log.commitHash(), log.email())).toList();
119128

129+
// Save the TeamRepository (through cascade, VCSLogs will also be saved)
120130
teamRepo.setVcsLogs(vcsLogs);
121131
teamRepositoryRepository.save(teamRepo);
122132

@@ -125,17 +135,17 @@ public void saveResults(List<TeamRepositoryDTO> repositories, Map<Long, int[]> c
125135
}
126136

127137
/**
128-
* Extracts all saved repository and contribution data from the database.
138+
* Retrieves all stored repository data from the database and assembles it into ClientResponseDTOs.
129139
*
130-
* @return A list of ClientResponseDTOs containing all aggregated team and student data.
140+
* @return List of ClientResponseDTO containing the assembled data
131141
*/
132142
public List<ClientResponseDTO> getAllRepositoryData() {
133143
log.info("RequestService: Initiating data extraction from database");
134144

135-
// 1. Fetch all TeamParticipation records
145+
// Fetch all TeamParticipation records
136146
List<TeamParticipation> participations = teamParticipationRepository.findAll();
137147

138-
// 2. Map and assemble the data into ClientResponseDTOs
148+
// Map and assemble the data into ClientResponseDTOs
139149
List<ClientResponseDTO> responseDTOs = participations.stream()
140150
.map(participation -> {
141151
List<Student> students = studentRepository.findAllByTeam(participation);
@@ -161,7 +171,7 @@ public List<ClientResponseDTO> getAllRepositoryData() {
161171
})
162172
.toList();
163173

164-
log.info("RequestService: Extracted {} team participation records.", responseDTOs.size());
174+
log.info("RequestService: Extracted {} team participation records from the database.", responseDTOs.size());
165175
return responseDTOs;
166176
}
167177
}

src/main/java/de/tum/cit/aet/dataProcessing/web/RequestResource.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ public ResponseEntity<List<ClientResponseDTO>> fetchData(
5656
}
5757

5858
requestService.fetchAnalyzeAndSaveRepositories(credentials);
59-
log.info("Successfully fetched, analyzed, and saved repository data");
6059
List<ClientResponseDTO> clientResponseDTOS = requestService.getAllRepositoryData();
6160
return ResponseEntity.ok(clientResponseDTOS);
6261
}

src/main/java/de/tum/cit/aet/repositoryProcessing/domain/Student.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public class Student {
3737
@Column(name = "lines_added")
3838
private Integer linesAdded;
3939

40-
@Column(name = "lines_deleted")
40+
@Column(name = "lines_deleted")
4141
private Integer linesDeleted;
4242

4343
@Column(name = "lines_changed")

src/main/java/de/tum/cit/aet/repositoryProcessing/dto/ClientResponseDTO.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,16 @@
44

55
import java.util.List;
66

7+
/**
8+
* DTO representing the response sent to clients.
9+
*
10+
* @param tutor The name of the tutor associated with the team.
11+
* @param teamId The unique identifier of the team.
12+
* @param teamName The full name of the team.
13+
* @param shortName The short name or abbreviation of the team.
14+
* @param submissionCount The number of submissions made by the team.
15+
* @param students A list of StudentAnalysisDTO representing individual student analyses within the team.
16+
*/
717
@JsonInclude(JsonInclude.Include.NON_NULL)
818
public record ClientResponseDTO(
919
String tutor,

src/main/java/de/tum/cit/aet/repositoryProcessing/dto/StudentAnalysisDTO.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,21 @@
22

33
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
44

5+
/**
6+
* DTO representing the analysis of a student's contributions which will be sent to the client
7+
*
8+
* @param name The name of the student.
9+
* @param commitCount The number of commits made by the student.
10+
* @param linesAdded The number of lines added by the student.
11+
* @param linesDeleted The number of lines deleted by the student.
12+
* @param linesChanged The total number of lines changed by the student.
13+
*/
514
@JsonIgnoreProperties(ignoreUnknown = true)
615
public record StudentAnalysisDTO(
716
String name,
817
Integer commitCount,
918
Integer linesAdded,
1019
Integer linesDeleted,
1120
Integer linesChanged
12-
){
21+
) {
1322
}

src/main/java/de/tum/cit/aet/repositoryProcessing/dto/VCSLogDTO.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22

33
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
44

5+
/**
6+
* DTO for a VCS Log entry.
7+
*
8+
* @param email The email of the committer.
9+
* @param repositoryActionType The type of action performed in the repository.
10+
* @param commitHash The hash of the commit.
11+
*/
512
@JsonIgnoreProperties(ignoreUnknown = true)
613
public record VCSLogDTO(
714
String email,

src/main/java/de/tum/cit/aet/repositoryProcessing/service/ArtemisClientService.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ public String getVcsAccessToken(String serverUrl, String jwtToken, Long particip
189189
* @param serverUrl The Artemis server URL
190190
* @param jwtToken The JWT token for authentication
191191
* @param participationId The ID of the participation
192-
* @return List of VCS log DTOs filtered for WRITE actions
192+
* @return List of VCS log DTOs filtered for commits
193193
*/
194194
public List<VCSLogDTO> fetchVCSAccessLog(String serverUrl, String jwtToken, Long participationId) {
195195
log.info("Fetching VCS access log for participation ID: {}", participationId);
@@ -208,6 +208,7 @@ public List<VCSLogDTO> fetchVCSAccessLog(String serverUrl, String jwtToken, Long
208208
.body(new ParameterizedTypeReference<>() {
209209
});
210210

211+
// Filter the fetched logs to only include "WRITE" actions, indicating a commit
211212
if (vcsLogs != null) {
212213
vcsLogs = vcsLogs.stream()
213214
.filter(entry -> "WRITE".equals(entry.repositoryActionType()))

0 commit comments

Comments
 (0)