-
Notifications
You must be signed in to change notification settings - Fork 295
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
Development
: Add simple repository service
#9871
base: develop
Are you sure you want to change the base?
Changes from all commits
2907c17
3195bd6
7d4693e
755c449
b2e8134
479c405
1c62cdb
98a226e
1e1b3c9
4f6db42
3a1cd24
b80b453
b22daac
61f0e05
ca07539
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package de.tum.cit.aet.artemis.atlas.repository.simple; | ||
|
||
import static de.tum.cit.aet.artemis.core.config.Constants.PROFILE_CORE; | ||
|
||
import org.springframework.context.annotation.Profile; | ||
import org.springframework.stereotype.Service; | ||
|
||
import de.tum.cit.aet.artemis.atlas.domain.competency.Competency; | ||
import de.tum.cit.aet.artemis.atlas.repository.CompetencyRepository; | ||
import de.tum.cit.aet.artemis.core.repository.base.AbstractSimpleService; | ||
|
||
@Profile(PROFILE_CORE) | ||
@Service | ||
public class CompetencySimpleService extends AbstractSimpleService<Competency> { | ||
|
||
private final static String ENTITY_NAME = "Competency"; | ||
|
||
private final CompetencyRepository competencyRepository; | ||
|
||
public CompetencySimpleService(CompetencyRepository competencyRepository) { | ||
this.competencyRepository = competencyRepository; | ||
} | ||
|
||
public Competency findByIdWithLectureUnitsAndExercisesElseThrow(long competencyId) { | ||
return getValueElseThrow(competencyRepository.findByIdWithLectureUnitsAndExercises(competencyId), ENTITY_NAME); | ||
} | ||
|
||
public Competency findByIdWithLectureUnitsElseThrow(long competencyId) { | ||
return getValueElseThrow(competencyRepository.findByIdWithLectureUnitsAndExercises(competencyId), ENTITY_NAME); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package de.tum.cit.aet.artemis.atlas.repository.simple; | ||
|
||
import static de.tum.cit.aet.artemis.core.config.Constants.PROFILE_CORE; | ||
|
||
import java.util.Set; | ||
|
||
import org.springframework.context.annotation.Profile; | ||
import org.springframework.stereotype.Service; | ||
|
||
import de.tum.cit.aet.artemis.atlas.domain.LearningObject; | ||
import de.tum.cit.aet.artemis.atlas.domain.competency.CourseCompetency; | ||
import de.tum.cit.aet.artemis.atlas.repository.CourseCompetencyRepository; | ||
import de.tum.cit.aet.artemis.core.repository.base.AbstractSimpleService; | ||
import de.tum.cit.aet.artemis.exercise.domain.Exercise; | ||
import de.tum.cit.aet.artemis.lecture.domain.LectureUnit; | ||
|
||
@Profile(PROFILE_CORE) | ||
@Service | ||
public class CourseCompetencySimpleService extends AbstractSimpleService<CourseCompetency> { | ||
|
||
private static final String ENTITY_NAME = "CourseCompetency"; | ||
|
||
private final CourseCompetencyRepository courseCompetencyRepository; | ||
|
||
public CourseCompetencySimpleService(CourseCompetencyRepository courseCompetencyRepository) { | ||
this.courseCompetencyRepository = courseCompetencyRepository; | ||
} | ||
|
||
public CourseCompetency findByIdWithExercisesAndLectureUnitsAndLecturesElseThrow(long id) { | ||
return getValueElseThrow(courseCompetencyRepository.findByIdWithExercisesAndLectureUnitsAndLectures(id), ENTITY_NAME); | ||
} | ||
|
||
public CourseCompetency findByIdWithExercisesAndLectureUnitsElseThrow(long competencyId) { | ||
return getValueElseThrow(courseCompetencyRepository.findByIdWithExercisesAndLectureUnits(competencyId), ENTITY_NAME); | ||
} | ||
|
||
public CourseCompetency findByIdWithExercisesAndLectureUnitsBidirectionalElseThrow(long competencyId) { | ||
return getValueElseThrow(courseCompetencyRepository.findByIdWithExercisesAndLectureUnitsBidirectional(competencyId), ENTITY_NAME); | ||
} | ||
|
||
/** | ||
* Finds the set of ids of course competencies that are linked to a given learning object | ||
* | ||
* @param learningObject the learning object to find the course competencies for | ||
* @return the set of ids of course competencies linked to the learning object | ||
*/ | ||
public Set<Long> findAllIdsByLearningObject(LearningObject learningObject) { | ||
return switch (learningObject) { | ||
case LectureUnit lectureUnit -> courseCompetencyRepository.findAllIdsByLectureUnit(lectureUnit); | ||
case Exercise exercise -> courseCompetencyRepository.findAllIdsByExercise(exercise); | ||
default -> throw new IllegalArgumentException("Unknown LearningObject type: " + learningObject.getClass()); | ||
}; | ||
} | ||
|
||
public CourseCompetency findByIdWithExercisesElseThrow(long competencyId) { | ||
return getValueElseThrow(courseCompetencyRepository.findByIdWithExercises(competencyId), ENTITY_NAME); | ||
} | ||
|
||
public CourseCompetency findByIdWithLectureUnitsAndExercisesElseThrow(long competencyId) { | ||
return getValueElseThrow(courseCompetencyRepository.findByIdWithLectureUnitsAndExercises(competencyId), ENTITY_NAME); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -22,6 +22,8 @@ | |||||
import de.tum.cit.aet.artemis.atlas.repository.CompetencyRepository; | ||||||
import de.tum.cit.aet.artemis.atlas.repository.CourseCompetencyRepository; | ||||||
import de.tum.cit.aet.artemis.atlas.repository.StandardizedCompetencyRepository; | ||||||
import de.tum.cit.aet.artemis.atlas.repository.simple.CompetencySimpleService; | ||||||
import de.tum.cit.aet.artemis.atlas.repository.simple.CourseCompetencySimpleService; | ||||||
import de.tum.cit.aet.artemis.atlas.service.LearningObjectImportService; | ||||||
import de.tum.cit.aet.artemis.atlas.service.learningpath.LearningPathService; | ||||||
import de.tum.cit.aet.artemis.core.domain.Course; | ||||||
|
@@ -42,17 +44,21 @@ public class CompetencyService extends CourseCompetencyService { | |||||
|
||||||
private final CompetencyRepository competencyRepository; | ||||||
|
||||||
private final CompetencySimpleService competencySimpleRepository; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Rename field to match its type The field is of type - private final CompetencySimpleService competencySimpleRepository;
+ private final CompetencySimpleService competencySimpleService; 📝 Committable suggestion
Suggested change
|
||||||
|
||||||
private final CompetencyExerciseLinkRepository competencyExerciseLinkRepository; | ||||||
|
||||||
public CompetencyService(CompetencyRepository competencyRepository, AuthorizationCheckService authCheckService, CompetencyRelationRepository competencyRelationRepository, | ||||||
LearningPathService learningPathService, CompetencyProgressService competencyProgressService, LectureUnitService lectureUnitService, | ||||||
CompetencyProgressRepository competencyProgressRepository, LectureUnitCompletionRepository lectureUnitCompletionRepository, | ||||||
CourseCompetencySimpleService courseCompetencySimpleRepository, LearningPathService learningPathService, CompetencyProgressService competencyProgressService, | ||||||
LectureUnitService lectureUnitService, CompetencyProgressRepository competencyProgressRepository, LectureUnitCompletionRepository lectureUnitCompletionRepository, | ||||||
StandardizedCompetencyRepository standardizedCompetencyRepository, CourseCompetencyRepository courseCompetencyRepository, ExerciseService exerciseService, | ||||||
LearningObjectImportService learningObjectImportService, CompetencyLectureUnitLinkRepository competencyLectureUnitLinkRepository, CourseRepository courseRepository, | ||||||
CompetencyExerciseLinkRepository competencyExerciseLinkRepository) { | ||||||
super(competencyProgressRepository, courseCompetencyRepository, competencyRelationRepository, competencyProgressService, exerciseService, lectureUnitService, | ||||||
learningPathService, authCheckService, standardizedCompetencyRepository, lectureUnitCompletionRepository, learningObjectImportService, courseRepository); | ||||||
CompetencySimpleService competencySimpleRepository, CompetencyExerciseLinkRepository competencyExerciseLinkRepository) { | ||||||
super(competencyProgressRepository, courseCompetencyRepository, courseCompetencySimpleRepository, competencyRelationRepository, competencyProgressService, exerciseService, | ||||||
lectureUnitService, learningPathService, authCheckService, standardizedCompetencyRepository, lectureUnitCompletionRepository, learningObjectImportService, | ||||||
courseRepository); | ||||||
this.competencyRepository = competencyRepository; | ||||||
this.competencySimpleRepository = competencySimpleRepository; | ||||||
this.competencyExerciseLinkRepository = competencyExerciseLinkRepository; | ||||||
} | ||||||
|
||||||
|
@@ -100,7 +106,7 @@ public List<Competency> createCompetencies(List<Competency> competencies, Course | |||||
* @return The found competency | ||||||
*/ | ||||||
public Competency findCompetencyWithExercisesAndLectureUnitsAndProgressForUser(Long competencyId, Long userId) { | ||||||
Competency competency = competencyRepository.findByIdWithLectureUnitsAndExercisesElseThrow(competencyId); | ||||||
Competency competency = competencySimpleRepository.findByIdWithLectureUnitsAndExercisesElseThrow(competencyId); | ||||||
return findProgressAndLectureUnitCompletionsForUser(competency, userId); | ||||||
} | ||||||
|
||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Potential
NullPointerException
iflearningObject
is nullThe method
findAllIdsByLearningObject
does not check iflearningObject
isnull
. Passing anull
value will result in aNullPointerException
at runtime.Consider adding a null check at the beginning of the method:
📝 Committable suggestion