Skip to content

Commit 5687136

Browse files
committed
code quality improvements
1 parent 4c9659f commit 5687136

2 files changed

Lines changed: 105 additions & 0 deletions

File tree

src/main/java/de/tum/cit/aet/analysis/service/EmailMappingService.java

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,12 @@ public class EmailMappingService {
4949
// Email mapping operations
5050
// ================================================================
5151

52+
/**
53+
* Returns all email mappings for the given exercise.
54+
*
55+
* @param exerciseId the exercise ID
56+
* @return list of email mapping DTOs
57+
*/
5258
public List<EmailMappingDTO> getAllMappings(Long exerciseId) {
5359
return emailMappingRepository.findAllByExerciseId(exerciseId)
5460
.stream()
@@ -58,6 +64,17 @@ public List<EmailMappingDTO> getAllMappings(Long exerciseId) {
5864
.toList();
5965
}
6066

67+
/**
68+
* Creates a new email-to-student mapping. Resolves the student ID by name,
69+
* re-assigns matching orphan chunks to the student, updates commit/line stats,
70+
* and recalculates the CQI.
71+
*
72+
* @param exerciseId the exercise ID
73+
* @param request the mapping request with git email, student info and participation ID
74+
* @return updated client response DTO
75+
* @throws IllegalArgumentException if participation not found or student ID is invalid
76+
* @throws EmailMappingConflictException if a mapping for the email already exists
77+
*/
6178
@Transactional
6279
public ClientResponseDTO createMapping(Long exerciseId, CreateEmailMappingRequestDTO request) {
6380
// 1. Find the team participation
@@ -117,6 +134,16 @@ public ClientResponseDTO createMapping(Long exerciseId, CreateEmailMappingReques
117134
return buildResponse(participation);
118135
}
119136

137+
/**
138+
* Dismisses an orphan email without assigning it to a student.
139+
* Chunks are NOT mutated; the dismissed mapping is used by clients
140+
* to filter them into a separate section.
141+
*
142+
* @param exerciseId the exercise ID
143+
* @param request the dismiss request with git email and participation ID
144+
* @return updated client response, or empty if participation not found
145+
* @throws EmailMappingConflictException if a mapping for the email already exists
146+
*/
120147
@Transactional
121148
public Optional<ClientResponseDTO> dismissEmail(Long exerciseId, DismissEmailRequestDTO request) {
122149
// 1. Normalize and check for duplicates
@@ -143,6 +170,15 @@ public Optional<ClientResponseDTO> dismissEmail(Long exerciseId, DismissEmailReq
143170
return Optional.empty();
144171
}
145172

173+
/**
174+
* Deletes an email mapping and reverts affected chunks back to external/orphan status.
175+
* Subtracts the chunk stats from the previously assigned student and recalculates CQI.
176+
*
177+
* @param exerciseId the exercise ID
178+
* @param mappingId the mapping ID to delete
179+
* @return updated client response for the last affected team, or empty if no chunks changed
180+
* @throws IllegalArgumentException if mapping not found or does not belong to the exercise
181+
*/
146182
@Transactional
147183
public Optional<ClientResponseDTO> deleteMapping(Long exerciseId, UUID mappingId) {
148184
ExerciseEmailMapping mapping = emailMappingRepository.findById(mappingId)
@@ -196,13 +232,28 @@ public Optional<ClientResponseDTO> deleteMapping(Long exerciseId, UUID mappingId
196232
// Template author operations
197233
// ================================================================
198234

235+
/**
236+
* Returns all configured template authors for the given exercise.
237+
*
238+
* @param exerciseId the exercise ID
239+
* @return list of template author DTOs
240+
*/
199241
public List<TemplateAuthorDTO> getTemplateAuthors(Long exerciseId) {
200242
return templateAuthorRepository.findByExerciseId(exerciseId)
201243
.stream()
202244
.map(ta -> new TemplateAuthorDTO(ta.getTemplateEmail(), ta.getAutoDetected()))
203245
.toList();
204246
}
205247

248+
/**
249+
* Replaces all template authors for an exercise. Chunks from removed template emails
250+
* become regular orphans if not known via students or mappings. Chunks matching new
251+
* template emails are marked as external. CQI is recalculated for all teams.
252+
*
253+
* @param exerciseId the exercise ID
254+
* @param request list of template author DTOs with emails
255+
* @return list of updated client response DTOs for all teams
256+
*/
206257
@Transactional
207258
public List<ClientResponseDTO> setTemplateAuthors(Long exerciseId, List<TemplateAuthorDTO> request) {
208259
// Collect old emails
@@ -261,6 +312,14 @@ public List<ClientResponseDTO> setTemplateAuthors(Long exerciseId, List<Template
261312
return responses;
262313
}
263314

315+
/**
316+
* Removes all template author configurations for an exercise.
317+
* Chunks from old template authors that match a known student or mapping
318+
* are unmarked as external. CQI is recalculated for all teams.
319+
*
320+
* @param exerciseId the exercise ID
321+
* @return list of updated client response DTOs, or empty if none were configured
322+
*/
264323
@Transactional
265324
public Optional<List<ClientResponseDTO>> deleteTemplateAuthors(Long exerciseId) {
266325
List<ExerciseTemplateAuthor> existing = templateAuthorRepository.findByExerciseId(exerciseId);

src/main/java/de/tum/cit/aet/analysis/web/EmailMappingResource.java

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,25 @@ public class EmailMappingResource {
3030
// Email mapping endpoints
3131
// ================================================================
3232

33+
/**
34+
* Returns all email mappings for the given exercise.
35+
*
36+
* @param exerciseId the exercise ID
37+
* @return list of email mapping DTOs
38+
*/
3339
@GetMapping
3440
public ResponseEntity<List<EmailMappingDTO>> getAllMappings(@PathVariable Long exerciseId) {
3541
log.info("GET getAllMappings for exerciseId={}", exerciseId);
3642
return ResponseEntity.ok(emailMappingService.getAllMappings(exerciseId));
3743
}
3844

45+
/**
46+
* Creates a new email mapping and recalculates CQI for the affected team.
47+
*
48+
* @param exerciseId the exercise ID
49+
* @param request the mapping request with git email, student info and participation ID
50+
* @return updated client response DTO, 409 if mapping already exists, or 400 if invalid
51+
*/
3952
@PostMapping
4053
public ResponseEntity<ClientResponseDTO> createMapping(
4154
@PathVariable Long exerciseId,
@@ -51,6 +64,13 @@ public ResponseEntity<ClientResponseDTO> createMapping(
5164
}
5265
}
5366

67+
/**
68+
* Dismisses an orphan email without assigning it to a student.
69+
*
70+
* @param exerciseId the exercise ID
71+
* @param request the dismiss request with git email and participation ID
72+
* @return updated client response DTO, 409 if already mapped, or 204 if no participation found
73+
*/
5474
@PostMapping("/dismiss")
5575
public ResponseEntity<ClientResponseDTO> dismissEmail(
5676
@PathVariable Long exerciseId,
@@ -65,6 +85,13 @@ public ResponseEntity<ClientResponseDTO> dismissEmail(
6585
}
6686
}
6787

88+
/**
89+
* Deletes an email mapping and recalculates CQI for affected teams.
90+
*
91+
* @param exerciseId the exercise ID
92+
* @param mappingId the mapping ID to delete
93+
* @return updated client response DTO, or 204 if no chunks were affected
94+
*/
6895
@DeleteMapping("/{mappingId}")
6996
public ResponseEntity<ClientResponseDTO> deleteMapping(
7097
@PathVariable Long exerciseId,
@@ -88,12 +115,25 @@ public record TemplateAuthorDTO(
88115
Boolean autoDetected) {
89116
}
90117

118+
/**
119+
* Returns all configured template authors for the given exercise.
120+
*
121+
* @param exerciseId the exercise ID
122+
* @return list of template author DTOs
123+
*/
91124
@GetMapping("/template-author")
92125
public ResponseEntity<List<TemplateAuthorDTO>> getTemplateAuthors(@PathVariable Long exerciseId) {
93126
log.info("GET getTemplateAuthors for exerciseId={}", exerciseId);
94127
return ResponseEntity.ok(emailMappingService.getTemplateAuthors(exerciseId));
95128
}
96129

130+
/**
131+
* Sets or replaces all template authors for an exercise and recalculates CQI.
132+
*
133+
* @param exerciseId the exercise ID
134+
* @param request list of template author DTOs with emails
135+
* @return list of updated client response DTOs for all teams
136+
*/
97137
@PutMapping("/template-author")
98138
public ResponseEntity<List<ClientResponseDTO>> setTemplateAuthors(
99139
@PathVariable Long exerciseId,
@@ -102,6 +142,12 @@ public ResponseEntity<List<ClientResponseDTO>> setTemplateAuthors(
102142
return ResponseEntity.ok(emailMappingService.setTemplateAuthors(exerciseId, request));
103143
}
104144

145+
/**
146+
* Removes all template author configurations for an exercise and recalculates CQI.
147+
*
148+
* @param exerciseId the exercise ID
149+
* @return list of updated client response DTOs, or 204 if none configured
150+
*/
105151
@DeleteMapping("/template-author")
106152
public ResponseEntity<List<ClientResponseDTO>> deleteTemplateAuthors(
107153
@PathVariable Long exerciseId) {

0 commit comments

Comments
 (0)