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 linking attachment units to competencies #9739

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 @@ -3,6 +3,7 @@
import static de.tum.cit.aet.artemis.core.config.Constants.PROFILE_CORE;

import java.util.List;
import java.util.Optional;

import jakarta.validation.constraints.NotNull;

Expand Down Expand Up @@ -62,5 +63,9 @@ default List<AttachmentUnit> findAllByLectureIdAndAttachmentTypeElseThrow(Long l
LEFT JOIN FETCH cl.competency
WHERE attachmentUnit.id = :attachmentUnitId
""")
AttachmentUnit findOneWithSlidesAndCompetencies(@Param("attachmentUnitId") long attachmentUnitId);
Optional<AttachmentUnit> findWithSlidesAndCompetenciesById(@Param("attachmentUnitId") long attachmentUnitId);

default AttachmentUnit findWithSlidesAndCompetenciesByIdElseThrow(long attachmentUnitId) {
return getValueElseThrow(findWithSlidesAndCompetenciesById(attachmentUnitId), attachmentUnitId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ public AttachmentUnit updateAttachmentUnit(AttachmentUnit existingAttachmentUnit
existingAttachmentUnit.setDescription(updateUnit.getDescription());
existingAttachmentUnit.setName(updateUnit.getName());
existingAttachmentUnit.setReleaseDate(updateUnit.getReleaseDate());
existingAttachmentUnit.setCompetencyLinks(updateUnit.getCompetencyLinks());

AttachmentUnit savedAttachmentUnit = lectureUnitService.saveWithCompetencyLinks(existingAttachmentUnit, attachmentUnitRepository::saveAndFlush);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public AttachmentUnitResource(AttachmentUnitRepository attachmentUnitRepository,
@EnforceAtLeastEditor
public ResponseEntity<AttachmentUnit> getAttachmentUnit(@PathVariable Long attachmentUnitId, @PathVariable Long lectureId) {
log.debug("REST request to get AttachmentUnit : {}", attachmentUnitId);
AttachmentUnit attachmentUnit = attachmentUnitRepository.findByIdElseThrow(attachmentUnitId);
AttachmentUnit attachmentUnit = attachmentUnitRepository.findWithSlidesAndCompetenciesByIdElseThrow(attachmentUnitId);
checkAttachmentUnitCourseAndLecture(attachmentUnit, lectureId);
authorizationCheckService.checkHasAtLeastRoleInCourseElseThrow(Role.EDITOR, attachmentUnit.getLecture().getCourse(), null);

Expand All @@ -125,7 +125,7 @@ public ResponseEntity<AttachmentUnit> updateAttachmentUnit(@PathVariable Long le
@RequestPart Attachment attachment, @RequestPart(required = false) MultipartFile file, @RequestParam(defaultValue = "false") boolean keepFilename,
@RequestParam(value = "notificationText", required = false) String notificationText) {
log.debug("REST request to update an attachment unit : {}", attachmentUnit);
AttachmentUnit existingAttachmentUnit = attachmentUnitRepository.findOneWithSlidesAndCompetencies(attachmentUnitId);
AttachmentUnit existingAttachmentUnit = attachmentUnitRepository.findWithSlidesAndCompetenciesByIdElseThrow(attachmentUnitId);
checkAttachmentUnitCourseAndLecture(existingAttachmentUnit, lectureId);
authorizationCheckService.checkHasAtLeastRoleInCourseElseThrow(Role.EDITOR, existingAttachmentUnit.getLecture().getCourse(), null);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ void updateAttachmentUnit_asInstructor_shouldUpdateAttachmentUnit() throws Excep
attachment = attachmentRepository.findById(attachment.getId()).orElseThrow();
assertThat(attachmentUnit2.getAttachment()).isEqualTo(attachment);
assertThat(attachment.getAttachmentUnit()).isEqualTo(attachmentUnit2);
assertThat(attachmentUnit1.getCompetencyLinks()).anyMatch(link -> link.getCompetency().getId().equals(competency.getId()));
verify(competencyProgressService, timeout(1000).times(1)).updateProgressForUpdatedLearningObjectAsync(eq(attachmentUnit), eq(Optional.of(attachmentUnit)));
}

Expand Down Expand Up @@ -334,6 +335,7 @@ void getAttachmentUnit_correctId_shouldReturnAttachmentUnit() throws Exception {
this.attachment.setAttachmentUnit(this.attachmentUnit);
this.attachment = attachmentRepository.save(attachment);
this.attachmentUnit = this.attachmentUnitRepository.save(this.attachmentUnit);
competencyUtilService.linkLectureUnitToCompetency(competency, attachmentUnit);

// 1. check the database call directly
this.attachmentUnit = this.attachmentUnitRepository.findByIdElseThrow(this.attachmentUnit.getId());
Expand All @@ -342,6 +344,7 @@ void getAttachmentUnit_correctId_shouldReturnAttachmentUnit() throws Exception {
// 2. check the REST call
this.attachmentUnit = request.get("/api/lectures/" + lecture1.getId() + "/attachment-units/" + this.attachmentUnit.getId(), HttpStatus.OK, AttachmentUnit.class);
assertThat(this.attachmentUnit.getAttachment()).isEqualTo(this.attachment);
assertThat(this.attachmentUnit.getCompetencyLinks()).anyMatch(link -> link.getCompetency().getId().equals(competency.getId()));
}

@Test
Expand Down
Loading