Search in sources :

Example 1 with LectureUnit

use of de.tum.in.www1.artemis.domain.lecture.LectureUnit in project Artemis by ls1intum.

the class LectureUnitResource method updateLectureUnitsOrder.

/**
 * PUT /lectures/:lectureId/lecture-units-order
 *
 * @param lectureId           the id of the lecture for which to update the lecture unit order
 * @param orderedLectureUnits ordered lecture units
 * @return the ResponseEntity with status 200 (OK) and with body the ordered lecture units
 */
@PutMapping("/lectures/{lectureId}/lecture-units-order")
@PreAuthorize("hasRole('EDITOR')")
public ResponseEntity<List<LectureUnit>> updateLectureUnitsOrder(@PathVariable Long lectureId, @RequestBody List<LectureUnit> orderedLectureUnits) {
    log.debug("REST request to update the order of lecture units of lecture: {}", lectureId);
    Optional<Lecture> lectureOptional = lectureRepository.findByIdWithPostsAndLectureUnitsAndLearningGoals(lectureId);
    if (lectureOptional.isEmpty()) {
        throw new EntityNotFoundException("Lecture", lectureId);
    }
    Lecture lecture = lectureOptional.get();
    if (lecture.getCourse() == null) {
        return conflict();
    }
    authorizationCheckService.checkHasAtLeastRoleInCourseElseThrow(Role.EDITOR, lecture.getCourse(), null);
    // Ensure that exactly as many lecture units have been received as are currently related to the lecture
    if (orderedLectureUnits.size() != lecture.getLectureUnits().size()) {
        return conflict();
    }
    // Ensure that all received lecture units are already related to the lecture
    for (LectureUnit lectureUnit : orderedLectureUnits) {
        if (!lecture.getLectureUnits().contains(lectureUnit)) {
            return conflict();
        }
        // Set the lecture manually as it won't be included in orderedLectureUnits
        lectureUnit.setLecture(lecture);
        // keep bidirectional mapping between attachment unit and attachment
        if (lectureUnit instanceof AttachmentUnit) {
            ((AttachmentUnit) lectureUnit).getAttachment().setAttachmentUnit((AttachmentUnit) lectureUnit);
        }
    }
    lecture.setLectureUnits(orderedLectureUnits);
    Lecture persistedLecture = lectureRepository.save(lecture);
    return ResponseEntity.ok(persistedLecture.getLectureUnits());
}
Also used : Lecture(de.tum.in.www1.artemis.domain.Lecture) LectureUnit(de.tum.in.www1.artemis.domain.lecture.LectureUnit) AttachmentUnit(de.tum.in.www1.artemis.domain.lecture.AttachmentUnit) EntityNotFoundException(de.tum.in.www1.artemis.web.rest.errors.EntityNotFoundException) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 2 with LectureUnit

use of de.tum.in.www1.artemis.domain.lecture.LectureUnit in project Artemis by ls1intum.

the class LearningGoalService method calculateLearningGoalCourseProgress.

/**
 * Calculate the progress in a learning goal for a whole course
 *
 * @param useParticipantScoreTable use the participant score table instead of going through participation -> submission -> result
 * @param learningGoal             learning goal to get the progress for
 * @return progress of the course in the learning goal
 */
public CourseLearningGoalProgress calculateLearningGoalCourseProgress(LearningGoal learningGoal, boolean useParticipantScoreTable) {
    CourseLearningGoalProgress courseLearningGoalProgress = new CourseLearningGoalProgress();
    courseLearningGoalProgress.courseId = learningGoal.getCourse().getId();
    courseLearningGoalProgress.learningGoalId = learningGoal.getId();
    courseLearningGoalProgress.learningGoalTitle = learningGoal.getTitle();
    courseLearningGoalProgress.totalPointsAchievableByStudentsInLearningGoal = 0.0;
    courseLearningGoalProgress.averagePointsAchievedByStudentInLearningGoal = 0.0;
    // The progress will be calculated from a subset of the connected lecture units (currently only from released exerciseUnits)
    List<ExerciseUnit> exerciseUnitsUsableForProgressCalculation = learningGoal.getLectureUnits().parallelStream().filter(LectureUnit::isVisibleToStudents).filter(lectureUnit -> lectureUnit instanceof ExerciseUnit).map(lectureUnit -> (ExerciseUnit) lectureUnit).collect(Collectors.toList());
    Set<CourseLearningGoalProgress.CourseLectureUnitProgress> progressInLectureUnits = this.calculateExerciseUnitsProgressForCourse(exerciseUnitsUsableForProgressCalculation, useParticipantScoreTable);
    // updating learningGoalPerformance by summing up the points of the individual lecture unit progress
    courseLearningGoalProgress.totalPointsAchievableByStudentsInLearningGoal = progressInLectureUnits.stream().map(lectureUnitProgress -> lectureUnitProgress.totalPointsAchievableByStudentsInLectureUnit).reduce(0.0, Double::sum);
    courseLearningGoalProgress.averagePointsAchievedByStudentInLearningGoal = progressInLectureUnits.stream().map(lectureUnitProgress -> (lectureUnitProgress.averageScoreAchievedByStudentInLectureUnit / 100.0) * lectureUnitProgress.totalPointsAchievableByStudentsInLectureUnit).reduce(0.0, Double::sum);
    courseLearningGoalProgress.progressInLectureUnits = new ArrayList<>(progressInLectureUnits);
    return courseLearningGoalProgress;
}
Also used : java.util(java.util) TeamScore(de.tum.in.www1.artemis.domain.scores.TeamScore) de.tum.in.www1.artemis.repository(de.tum.in.www1.artemis.repository) StudentScore(de.tum.in.www1.artemis.domain.scores.StudentScore) Collectors(java.util.stream.Collectors) CourseLearningGoalProgress(de.tum.in.www1.artemis.web.rest.dto.CourseLearningGoalProgress) Stream(java.util.stream.Stream) de.tum.in.www1.artemis.domain(de.tum.in.www1.artemis.domain) LectureUnit(de.tum.in.www1.artemis.domain.lecture.LectureUnit) Service(org.springframework.stereotype.Service) ExerciseUnit(de.tum.in.www1.artemis.domain.lecture.ExerciseUnit) CourseExerciseStatisticsDTO(de.tum.in.www1.artemis.web.rest.dto.CourseExerciseStatisticsDTO) StudentParticipation(de.tum.in.www1.artemis.domain.participation.StudentParticipation) ParticipantScore(de.tum.in.www1.artemis.domain.scores.ParticipantScore) IndividualLearningGoalProgress(de.tum.in.www1.artemis.web.rest.dto.IndividualLearningGoalProgress) CourseLearningGoalProgress(de.tum.in.www1.artemis.web.rest.dto.CourseLearningGoalProgress) ExerciseUnit(de.tum.in.www1.artemis.domain.lecture.ExerciseUnit)

Example 3 with LectureUnit

use of de.tum.in.www1.artemis.domain.lecture.LectureUnit in project ArTEMiS by ls1intum.

the class LearningGoalService method calculateLearningGoalCourseProgress.

/**
 * Calculate the progress in a learning goal for a whole course
 *
 * @param useParticipantScoreTable use the participant score table instead of going through participation -> submission -> result
 * @param learningGoal             learning goal to get the progress for
 * @return progress of the course in the learning goal
 */
public CourseLearningGoalProgress calculateLearningGoalCourseProgress(LearningGoal learningGoal, boolean useParticipantScoreTable) {
    CourseLearningGoalProgress courseLearningGoalProgress = new CourseLearningGoalProgress();
    courseLearningGoalProgress.courseId = learningGoal.getCourse().getId();
    courseLearningGoalProgress.learningGoalId = learningGoal.getId();
    courseLearningGoalProgress.learningGoalTitle = learningGoal.getTitle();
    courseLearningGoalProgress.totalPointsAchievableByStudentsInLearningGoal = 0.0;
    courseLearningGoalProgress.averagePointsAchievedByStudentInLearningGoal = 0.0;
    // The progress will be calculated from a subset of the connected lecture units (currently only from released exerciseUnits)
    List<ExerciseUnit> exerciseUnitsUsableForProgressCalculation = learningGoal.getLectureUnits().parallelStream().filter(LectureUnit::isVisibleToStudents).filter(lectureUnit -> lectureUnit instanceof ExerciseUnit).map(lectureUnit -> (ExerciseUnit) lectureUnit).collect(Collectors.toList());
    Set<CourseLearningGoalProgress.CourseLectureUnitProgress> progressInLectureUnits = this.calculateExerciseUnitsProgressForCourse(exerciseUnitsUsableForProgressCalculation, useParticipantScoreTable);
    // updating learningGoalPerformance by summing up the points of the individual lecture unit progress
    courseLearningGoalProgress.totalPointsAchievableByStudentsInLearningGoal = progressInLectureUnits.stream().map(lectureUnitProgress -> lectureUnitProgress.totalPointsAchievableByStudentsInLectureUnit).reduce(0.0, Double::sum);
    courseLearningGoalProgress.averagePointsAchievedByStudentInLearningGoal = progressInLectureUnits.stream().map(lectureUnitProgress -> (lectureUnitProgress.averageScoreAchievedByStudentInLectureUnit / 100.0) * lectureUnitProgress.totalPointsAchievableByStudentsInLectureUnit).reduce(0.0, Double::sum);
    courseLearningGoalProgress.progressInLectureUnits = new ArrayList<>(progressInLectureUnits);
    return courseLearningGoalProgress;
}
Also used : java.util(java.util) TeamScore(de.tum.in.www1.artemis.domain.scores.TeamScore) de.tum.in.www1.artemis.repository(de.tum.in.www1.artemis.repository) StudentScore(de.tum.in.www1.artemis.domain.scores.StudentScore) Collectors(java.util.stream.Collectors) CourseLearningGoalProgress(de.tum.in.www1.artemis.web.rest.dto.CourseLearningGoalProgress) Stream(java.util.stream.Stream) de.tum.in.www1.artemis.domain(de.tum.in.www1.artemis.domain) LectureUnit(de.tum.in.www1.artemis.domain.lecture.LectureUnit) Service(org.springframework.stereotype.Service) ExerciseUnit(de.tum.in.www1.artemis.domain.lecture.ExerciseUnit) CourseExerciseStatisticsDTO(de.tum.in.www1.artemis.web.rest.dto.CourseExerciseStatisticsDTO) StudentParticipation(de.tum.in.www1.artemis.domain.participation.StudentParticipation) ParticipantScore(de.tum.in.www1.artemis.domain.scores.ParticipantScore) IndividualLearningGoalProgress(de.tum.in.www1.artemis.web.rest.dto.IndividualLearningGoalProgress) CourseLearningGoalProgress(de.tum.in.www1.artemis.web.rest.dto.CourseLearningGoalProgress) ExerciseUnit(de.tum.in.www1.artemis.domain.lecture.ExerciseUnit)

Example 4 with LectureUnit

use of de.tum.in.www1.artemis.domain.lecture.LectureUnit in project ArTEMiS by ls1intum.

the class LectureImportService method cloneLectureUnit.

/**
 * This helper function clones the {@code importedLectureUnit} and returns it
 *
 * @param importedLectureUnit The original lecture unit to be copied
 * @param newLecture The new lecture to which the lecture units are appended
 * @return The cloned lecture unit
 */
private LectureUnit cloneLectureUnit(final LectureUnit importedLectureUnit, final Lecture newLecture) {
    log.debug("Creating a new LectureUnit from lecture unit {}", importedLectureUnit);
    if (importedLectureUnit instanceof TextUnit) {
        TextUnit textUnit = new TextUnit();
        textUnit.setName(importedLectureUnit.getName());
        textUnit.setReleaseDate(importedLectureUnit.getReleaseDate());
        textUnit.setContent(((TextUnit) importedLectureUnit).getContent());
        return textUnit;
    } else if (importedLectureUnit instanceof VideoUnit) {
        VideoUnit videoUnit = new VideoUnit();
        videoUnit.setName(importedLectureUnit.getName());
        videoUnit.setReleaseDate(importedLectureUnit.getReleaseDate());
        videoUnit.setDescription(((VideoUnit) importedLectureUnit).getDescription());
        videoUnit.setSource(((VideoUnit) importedLectureUnit).getSource());
        return videoUnit;
    } else if (importedLectureUnit instanceof AttachmentUnit) {
        // Create and save the attachment unit, then the attachment itself, as the id is needed for file handling
        AttachmentUnit attachmentUnit = new AttachmentUnit();
        attachmentUnit.setDescription(((AttachmentUnit) importedLectureUnit).getDescription());
        attachmentUnit.setLecture(newLecture);
        lectureUnitRepository.save(attachmentUnit);
        Attachment attachment = cloneAttachment(((AttachmentUnit) importedLectureUnit).getAttachment());
        attachment.setAttachmentUnit(attachmentUnit);
        attachmentRepository.save(attachment);
        attachmentUnit.setAttachment(attachment);
        return attachmentUnit;
    } else if (importedLectureUnit instanceof ExerciseUnit) {
        // We have a dedicated exercise import system, so this is left out for now
        return null;
    }
    return null;
}
Also used : Attachment(de.tum.in.www1.artemis.domain.Attachment)

Example 5 with LectureUnit

use of de.tum.in.www1.artemis.domain.lecture.LectureUnit in project ArTEMiS by ls1intum.

the class LectureUnitService method disconnectLectureUnitAndLearningGoal.

/**
 * Remove connection between lecture unit and learning goal in the database
 *
 * @param lectureUnit  Lecture unit connected to learning goal
 * @param learningGoal Learning goal connected to lecture unit
 */
public void disconnectLectureUnitAndLearningGoal(LectureUnit lectureUnit, LearningGoal learningGoal) {
    Optional<LearningGoal> learningGoalFromDbOptional = learningGoalRepository.findByIdWithLectureUnitsBidirectional(learningGoal.getId());
    if (learningGoalFromDbOptional.isPresent()) {
        LearningGoal learningGoalFromDb = learningGoalFromDbOptional.get();
        learningGoalFromDb.removeLectureUnit(lectureUnit);
        learningGoalRepository.save(learningGoalFromDb);
    }
}
Also used : LearningGoal(de.tum.in.www1.artemis.domain.LearningGoal)

Aggregations

LectureUnit (de.tum.in.www1.artemis.domain.lecture.LectureUnit)38 ExerciseUnit (de.tum.in.www1.artemis.domain.lecture.ExerciseUnit)14 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)12 Course (de.tum.in.www1.artemis.domain.Course)10 LearningGoal (de.tum.in.www1.artemis.domain.LearningGoal)10 Lecture (de.tum.in.www1.artemis.domain.Lecture)10 Test (org.junit.jupiter.api.Test)10 WithMockUser (org.springframework.security.test.context.support.WithMockUser)10 AttachmentUnit (de.tum.in.www1.artemis.domain.lecture.AttachmentUnit)8 TextUnit (de.tum.in.www1.artemis.domain.lecture.TextUnit)8 EntityNotFoundException (de.tum.in.www1.artemis.web.rest.errors.EntityNotFoundException)8 Attachment (de.tum.in.www1.artemis.domain.Attachment)6 CourseLearningGoalProgress (de.tum.in.www1.artemis.web.rest.dto.CourseLearningGoalProgress)6 IndividualLearningGoalProgress (de.tum.in.www1.artemis.web.rest.dto.IndividualLearningGoalProgress)6 ConflictException (de.tum.in.www1.artemis.web.rest.errors.ConflictException)6 java.util (java.util)6 Collectors (java.util.stream.Collectors)6 Transactional (org.springframework.transaction.annotation.Transactional)6 de.tum.in.www1.artemis.domain (de.tum.in.www1.artemis.domain)4 User (de.tum.in.www1.artemis.domain.User)4