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

Development: Add simple repository service #9871

Closed
wants to merge 20 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
2907c17
Add abstract simple repository service
ole-ve Nov 26, 2024
3195bd6
Move default methods from CompetencyRepository to CompetencySimpleRep…
ole-ve Nov 26, 2024
7d4693e
Add JavaDoc for AbstractSimpleRepositoryService
ole-ve Nov 26, 2024
755c449
Rename AbstractSimpleRepositoryService to AbstractSimpleRepository
ole-ve Nov 26, 2024
b2e8134
Move default methods from CourseCompetencyRepository to CourseCompete…
ole-ve Nov 26, 2024
479c405
Annotate SimpleRepository with profile
ole-ve Nov 26, 2024
1c62cdb
Fix missing autowiring
ole-ve Nov 26, 2024
98a226e
Adjust AbstractModuleServiceArchitectureTest to allow simple reposito…
ole-ve Nov 26, 2024
1e1b3c9
Rename SimpleRepository to SimpleService and use generics
ole-ve Nov 28, 2024
4f6db42
Move atlas SimpleServices to subpackage
ole-ve Nov 28, 2024
3a1cd24
Adapt service arch tests to consider SimpleServices
ole-ve Nov 28, 2024
b80b453
Add arch test to enforce that repositories have no default methods
ole-ve Nov 28, 2024
b22daac
Disable enforceNoDefaultMethodsInRepository for now
ole-ve Nov 28, 2024
61f0e05
Add arch test to enforce single autowired candidate
ole-ve Nov 28, 2024
ca07539
Merge branch 'develop' into chore/add-simple-repository-service
ole-ve Nov 28, 2024
4da414e
fix field naming of SimpleService
ole-ve Dec 17, 2024
bbadbe6
use abstract getEntityName in AbstractSimpleService
ole-ve Dec 17, 2024
d31c49a
fmt
ole-ve Dec 17, 2024
4f050e0
change AbstractSimpleService from abstract class to interface
ole-ve Dec 17, 2024
902a7ed
change test for ensuring single autowire in SimpleServices to allow f…
ole-ve Dec 17, 2024
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 @@ -56,14 +56,6 @@ public interface CompetencyRepository extends ArtemisJpaRepository<Competency, L
""")
Optional<Competency> findByIdWithLectureUnitsAndExercises(@Param("competencyId") long competencyId);

default Competency findByIdWithLectureUnitsAndExercisesElseThrow(long competencyId) {
return getValueElseThrow(findByIdWithLectureUnitsAndExercises(competencyId), competencyId);
}

default Competency findByIdWithLectureUnitsElseThrow(long competencyId) {
return getValueElseThrow(findByIdWithLectureUnits(competencyId), competencyId);
}

long countByCourse(Course course);

List<Competency> findByCourseIdOrderById(long courseId);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package de.tum.cit.aet.artemis.atlas.repository;

import org.springframework.stereotype.Service;

import de.tum.cit.aet.artemis.atlas.domain.competency.Competency;
import de.tum.cit.aet.artemis.core.repository.base.AbstractSimpleRepositoryService;

@Service
public class CompetencySimpleRepository extends AbstractSimpleRepositoryService {

private final static String ENTITY_NAME = "Competency";

private final CompetencyRepository competencyRepository;

public CompetencySimpleRepository(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
Expand Up @@ -20,6 +20,7 @@
import de.tum.cit.aet.artemis.atlas.repository.CompetencyProgressRepository;
import de.tum.cit.aet.artemis.atlas.repository.CompetencyRelationRepository;
import de.tum.cit.aet.artemis.atlas.repository.CompetencyRepository;
import de.tum.cit.aet.artemis.atlas.repository.CompetencySimpleRepository;
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.service.LearningObjectImportService;
Expand All @@ -42,17 +43,20 @@ public class CompetencyService extends CourseCompetencyService {

private final CompetencyRepository competencyRepository;

private final CompetencySimpleRepository competencySimpleRepository;

private final CompetencyExerciseLinkRepository competencyExerciseLinkRepository;

public CompetencyService(CompetencyRepository competencyRepository, AuthorizationCheckService authCheckService, CompetencyRelationRepository competencyRelationRepository,
LearningPathService learningPathService, CompetencyProgressService competencyProgressService, LectureUnitService lectureUnitService,
CompetencyProgressRepository competencyProgressRepository, LectureUnitCompletionRepository lectureUnitCompletionRepository,
StandardizedCompetencyRepository standardizedCompetencyRepository, CourseCompetencyRepository courseCompetencyRepository, ExerciseService exerciseService,
LearningObjectImportService learningObjectImportService, CompetencyLectureUnitLinkRepository competencyLectureUnitLinkRepository, CourseRepository courseRepository,
CompetencyExerciseLinkRepository competencyExerciseLinkRepository) {
CompetencySimpleRepository competencySimpleRepository, CompetencyExerciseLinkRepository competencyExerciseLinkRepository) {
super(competencyProgressRepository, courseCompetencyRepository, competencyRelationRepository, competencyProgressService, exerciseService, lectureUnitService,
learningPathService, authCheckService, standardizedCompetencyRepository, lectureUnitCompletionRepository, learningObjectImportService, courseRepository);
this.competencyRepository = competencyRepository;
this.competencySimpleRepository = competencySimpleRepository;
this.competencyExerciseLinkRepository = competencyExerciseLinkRepository;
}

Expand Down Expand Up @@ -100,7 +104,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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import de.tum.cit.aet.artemis.atlas.dto.CompetencyImportResponseDTO;
import de.tum.cit.aet.artemis.atlas.dto.CompetencyWithTailRelationDTO;
import de.tum.cit.aet.artemis.atlas.repository.CompetencyRepository;
import de.tum.cit.aet.artemis.atlas.repository.CompetencySimpleRepository;
import de.tum.cit.aet.artemis.atlas.repository.CourseCompetencyRepository;
import de.tum.cit.aet.artemis.atlas.service.competency.CompetencyService;
import de.tum.cit.aet.artemis.atlas.service.competency.CourseCompetencyService;
Expand Down Expand Up @@ -64,19 +65,22 @@ public class CompetencyResource {

private final CompetencyRepository competencyRepository;

private final CompetencySimpleRepository competencySimpleRepository;

private final CompetencyService competencyService;

private final CourseCompetencyRepository courseCompetencyRepository;

private final CourseCompetencyService courseCompetencyService;

public CompetencyResource(CourseRepository courseRepository, AuthorizationCheckService authorizationCheckService, UserRepository userRepository,
CompetencyRepository competencyRepository, CompetencyService competencyService, CourseCompetencyRepository courseCompetencyRepository,
CourseCompetencyService courseCompetencyService) {
CompetencyRepository competencyRepository, CompetencySimpleRepository competencySimpleRepository, CompetencyService competencyService,
CourseCompetencyRepository courseCompetencyRepository, CourseCompetencyService courseCompetencyService) {
this.courseRepository = courseRepository;
this.authorizationCheckService = authorizationCheckService;
this.userRepository = userRepository;
this.competencyRepository = competencyRepository;
this.competencySimpleRepository = competencySimpleRepository;
this.competencyService = competencyService;
this.courseCompetencyRepository = courseCompetencyRepository;
this.courseCompetencyService = courseCompetencyService;
Expand Down Expand Up @@ -293,7 +297,7 @@ public ResponseEntity<Competency> updateCompetency(@PathVariable long courseId,
checkCompetencyAttributesForUpdate(competency);

var course = courseRepository.findByIdElseThrow(courseId);
var existingCompetency = competencyRepository.findByIdWithLectureUnitsElseThrow(competency.getId());
var existingCompetency = competencySimpleRepository.findByIdWithLectureUnitsElseThrow(competency.getId());
checkCourseForCompetency(course, existingCompetency);

var persistedCompetency = competencyService.updateCourseCompetency(existingCompetency, competency);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package de.tum.cit.aet.artemis.core.repository.base;

import java.util.Optional;

import de.tum.cit.aet.artemis.core.exception.EntityNotFoundException;

public abstract class AbstractSimpleRepositoryService {

protected <U> U getValueElseThrow(Optional<U> optional, String entityName) {
return optional.orElseThrow(() -> new EntityNotFoundException(entityName));
}
}
Loading