Skip to content

Commit

Permalink
Fix and test issue
Browse files Browse the repository at this point in the history
  • Loading branch information
JohannesStoehr committed Jul 4, 2024
1 parent a6eade2 commit 17ad330
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,13 @@ WITH RECURSIVE transitive_closure(id) AS
Set<Long> getMatchingCompetenciesByCompetencyId(@Param("competencyId") long competencyId);

Set<CompetencyRelation> findAllByHeadCompetencyIdInAndTailCompetencyIdIn(Set<Long> headCompetencyIds, Set<Long> tailCompetencyIds);

@Transactional // ok because of delete
@Modifying
@Query("""
DELETE FROM CompetencyRelation cr
WHERE cr.headCompetency.course.id = :courseId
OR cr.tailCompetency.course.id = :courseId
""")
void deleteAllByCourseId(@Param("courseId") long courseId);
}
15 changes: 12 additions & 3 deletions src/main/java/de/tum/in/www1/artemis/service/CourseService.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,15 @@
import de.tum.in.www1.artemis.domain.ProgrammingExercise;
import de.tum.in.www1.artemis.domain.User;
import de.tum.in.www1.artemis.domain.competency.Competency;
import de.tum.in.www1.artemis.domain.competency.Prerequisite;
import de.tum.in.www1.artemis.domain.enumeration.IncludedInOverallScore;
import de.tum.in.www1.artemis.domain.enumeration.NotificationType;
import de.tum.in.www1.artemis.domain.exam.Exam;
import de.tum.in.www1.artemis.domain.exam.ExerciseGroup;
import de.tum.in.www1.artemis.domain.notification.GroupNotification;
import de.tum.in.www1.artemis.domain.plagiarism.PlagiarismCase;
import de.tum.in.www1.artemis.domain.statistics.StatisticsEntry;
import de.tum.in.www1.artemis.repository.CompetencyRelationRepository;
import de.tum.in.www1.artemis.repository.CompetencyRepository;
import de.tum.in.www1.artemis.repository.ComplaintRepository;
import de.tum.in.www1.artemis.repository.ComplaintResponseRepository;
Expand Down Expand Up @@ -109,12 +111,14 @@
@Service
public class CourseService {

private final TutorialGroupChannelManagementService tutorialGroupChannelManagementService;
private static final Logger log = LoggerFactory.getLogger(CourseService.class);

@Value("${artemis.course-archives-path}")
private Path courseArchivesDirPath;

private static final Logger log = LoggerFactory.getLogger(CourseService.class);
private final TutorialGroupChannelManagementService tutorialGroupChannelManagementService;

private final CompetencyRelationRepository competencyRelationRepository;

private final ExerciseService exerciseService;

Expand Down Expand Up @@ -202,7 +206,7 @@ public CourseService(CourseRepository courseRepository, ExerciseService exercise
TutorialGroupRepository tutorialGroupRepository, PlagiarismCaseRepository plagiarismCaseRepository, ConversationRepository conversationRepository,
LearningPathService learningPathService, Optional<IrisSettingsService> irisSettingsService, LectureRepository lectureRepository,
TutorialGroupNotificationRepository tutorialGroupNotificationRepository, TutorialGroupChannelManagementService tutorialGroupChannelManagementService,
PrerequisiteRepository prerequisiteRepository) {
PrerequisiteRepository prerequisiteRepository, CompetencyRelationRepository competencyRelationRepository) {
this.courseRepository = courseRepository;
this.exerciseService = exerciseService;
this.exerciseDeletionService = exerciseDeletionService;
Expand Down Expand Up @@ -241,6 +245,7 @@ public CourseService(CourseRepository courseRepository, ExerciseService exercise
this.tutorialGroupNotificationRepository = tutorialGroupNotificationRepository;
this.tutorialGroupChannelManagementService = tutorialGroupChannelManagementService;
this.prerequisiteRepository = prerequisiteRepository;
this.competencyRelationRepository = competencyRelationRepository;
}

/**
Expand Down Expand Up @@ -528,6 +533,10 @@ private void deleteExercisesOfCourse(Course course) {
}

private void deleteCompetenciesOfCourse(Course course) {
competencyRelationRepository.deleteAllByCourseId(course.getId());
for (Prerequisite prerequisite : course.getPrerequisites()) {
prerequisiteRepository.deleteById(prerequisite.getId());
}
for (Competency competency : course.getCompetencies()) {
competencyRepository.deleteById(competency.getId());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -506,11 +506,15 @@ void shouldReturnForbiddenForInstructorOfOtherCourse() throws Exception {

@Test
@WithMockUser(username = "admin", roles = "ADMIN")
void deleteCourseShouldAlsoDeleteCompetency() throws Exception {
void deleteCourseShouldAlsoDeleteCompetencyAndRelations() throws Exception {
Competency competency2 = createCompetency(course);
CompetencyRelation relation = createRelation(competency, competency2, RelationType.EXTENDS);

request.delete("/api/admin/courses/" + course.getId(), HttpStatus.OK);

boolean competencyExists = competencyRepository.existsById(competency.getId());
assertThat(competencyExists).isFalse();
assertThat(competencyRepository.existsById(competency.getId())).isFalse();
assertThat(competencyRepository.existsById(competency2.getId())).isFalse();
assertThat(competencyRelationRepository.existsById(relation.getId())).isFalse();
}

@Nested
Expand Down

0 comments on commit 17ad330

Please sign in to comment.