Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adaptive learning: Fix course deletion when competency relations exist #8969

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
17 changes: 10 additions & 7 deletions src/main/java/de/tum/in/www1/artemis/service/CourseService.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,14 @@
import de.tum.in.www1.artemis.domain.Lecture;
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.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 +109,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 +204,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 +243,7 @@ public CourseService(CourseRepository courseRepository, ExerciseService exercise
this.tutorialGroupNotificationRepository = tutorialGroupNotificationRepository;
this.tutorialGroupChannelManagementService = tutorialGroupChannelManagementService;
this.prerequisiteRepository = prerequisiteRepository;
this.competencyRelationRepository = competencyRelationRepository;
}

/**
Expand Down Expand Up @@ -528,9 +531,9 @@ private void deleteExercisesOfCourse(Course course) {
}

private void deleteCompetenciesOfCourse(Course course) {
for (Competency competency : course.getCompetencies()) {
competencyRepository.deleteById(competency.getId());
}
competencyRelationRepository.deleteAllByCourseId(course.getId());
prerequisiteRepository.deleteAll(course.getPrerequisites());
competencyRepository.deleteAll(course.getCompetencies());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import de.tum.in.www1.artemis.domain.competency.CompetencyRelation;
import de.tum.in.www1.artemis.domain.competency.CompetencyTaxonomy;
import de.tum.in.www1.artemis.domain.competency.CourseCompetency;
import de.tum.in.www1.artemis.domain.competency.Prerequisite;
import de.tum.in.www1.artemis.domain.competency.RelationType;
import de.tum.in.www1.artemis.domain.enumeration.DifficultyLevel;
import de.tum.in.www1.artemis.domain.enumeration.ExerciseMode;
Expand Down Expand Up @@ -506,11 +507,17 @@ 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);
Prerequisite prerequisite = prerequisiteUtilService.createPrerequisite(course);

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();
assertThat(prerequisiteRepository.existsById(prerequisite.getId())).isFalse();
}

@Nested
Expand Down
Loading