Search in sources :

Example 11 with Lecture

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

the class DatabaseUtilService method createCoursesWithExercisesAndLectures.

public List<Course> createCoursesWithExercisesAndLectures(boolean withParticipations) throws Exception {
    ZonedDateTime pastTimestamp = ZonedDateTime.now().minusDays(5);
    ZonedDateTime futureTimestamp = ZonedDateTime.now().plusDays(5);
    ZonedDateTime futureFutureTimestamp = ZonedDateTime.now().plusDays(8);
    Course course1 = ModelFactory.generateCourse(null, pastTimestamp, futureTimestamp, new HashSet<>(), "tumuser", "tutor", "editor", "instructor");
    Course course2 = ModelFactory.generateCourse(null, ZonedDateTime.now().minusDays(8), pastTimestamp, new HashSet<>(), "tumuser", "tutor", "editor", "instructor");
    ModelingExercise modelingExercise = ModelFactory.generateModelingExercise(pastTimestamp, futureTimestamp, futureFutureTimestamp, DiagramType.ClassDiagram, course1);
    modelingExercise.setGradingInstructions("some grading instructions");
    modelingExercise.setExampleSolutionModel("Example solution model");
    modelingExercise.setExampleSolutionExplanation("Example Solution");
    addGradingInstructionsToExercise(modelingExercise);
    modelingExercise.getCategories().add("Modeling");
    modelingExercise.setKnowledge(modelAssessmentKnowledgeService.createNewKnowledge());
    course1.addExercises(modelingExercise);
    TextExercise textExercise = ModelFactory.generateTextExercise(pastTimestamp, futureTimestamp, futureFutureTimestamp, course1);
    textExercise.setGradingInstructions("some grading instructions");
    textExercise.setExampleSolution("Example Solution");
    addGradingInstructionsToExercise(textExercise);
    textExercise.getCategories().add("Text");
    textExercise.setKnowledge(textAssessmentKnowledgeService.createNewKnowledge());
    course1.addExercises(textExercise);
    FileUploadExercise fileUploadExercise = ModelFactory.generateFileUploadExercise(pastTimestamp, futureTimestamp, futureFutureTimestamp, "png", course1);
    fileUploadExercise.setGradingInstructions("some grading instructions");
    fileUploadExercise.setExampleSolution("Example Solution");
    addGradingInstructionsToExercise(fileUploadExercise);
    fileUploadExercise.getCategories().add("File");
    course1.addExercises(fileUploadExercise);
    ProgrammingExercise programmingExercise = ModelFactory.generateProgrammingExercise(pastTimestamp, futureTimestamp, course1);
    programmingExercise.setGradingInstructions("some grading instructions");
    addGradingInstructionsToExercise(programmingExercise);
    programmingExercise.getCategories().add("Programming");
    course1.addExercises(programmingExercise);
    QuizExercise quizExercise = ModelFactory.generateQuizExercise(pastTimestamp, futureTimestamp, course1);
    programmingExercise.getCategories().add("Quiz");
    course1.addExercises(quizExercise);
    Lecture lecture1 = ModelFactory.generateLecture(pastTimestamp, futureFutureTimestamp, course1);
    Attachment attachment1 = ModelFactory.generateAttachment(pastTimestamp, lecture1);
    lecture1.addAttachments(attachment1);
    course1.addLectures(lecture1);
    Lecture lecture2 = ModelFactory.generateLecture(pastTimestamp, futureFutureTimestamp, course1);
    Attachment attachment2 = ModelFactory.generateAttachment(pastTimestamp, lecture2);
    lecture2.addAttachments(attachment2);
    course1.addLectures(lecture2);
    course1 = courseRepo.save(course1);
    course2 = courseRepo.save(course2);
    lectureRepo.save(lecture1);
    lectureRepo.save(lecture2);
    attachmentRepo.save(attachment1);
    attachmentRepo.save(attachment2);
    modelingExercise = exerciseRepo.save(modelingExercise);
    textExercise = exerciseRepo.save(textExercise);
    exerciseRepo.save(fileUploadExercise);
    exerciseRepo.save(programmingExercise);
    exerciseRepo.save(quizExercise);
    if (withParticipations) {
        // create 5 tutor participations and 5 example submissions and connect all of them (to test the many-to-many relationship)
        var tutorParticipations = new ArrayList<TutorParticipation>();
        for (int i = 1; i < 6; i++) {
            var tutorParticipation = new TutorParticipation().tutor(getUserByLogin("tutor" + i));
            tutorParticipationRepo.save(tutorParticipation);
            tutorParticipations.add(tutorParticipation);
        }
        for (int i = 0; i < 5; i++) {
            String validModel = FileUtils.loadFileFromResources("test-data/model-submission/model.54727.json");
            var exampleSubmission = addExampleSubmission(generateExampleSubmission(validModel, modelingExercise, true));
            exampleSubmission.assessmentExplanation("exp");
            for (var tutorParticipation : tutorParticipations) {
                exampleSubmission.addTutorParticipations(tutorParticipation);
            }
            exampleSubmissionRepo.save(exampleSubmission);
        }
        User user = (userRepo.findOneByLogin("student1")).get();
        StudentParticipation participation1 = ModelFactory.generateStudentParticipation(InitializationState.INITIALIZED, modelingExercise, user);
        StudentParticipation participation2 = ModelFactory.generateStudentParticipation(InitializationState.FINISHED, textExercise, user);
        StudentParticipation participation3 = ModelFactory.generateStudentParticipation(InitializationState.UNINITIALIZED, modelingExercise, user);
        Submission modelingSubmission1 = ModelFactory.generateModelingSubmission("model1", true);
        Submission modelingSubmission2 = ModelFactory.generateModelingSubmission("model2", true);
        Submission textSubmission = ModelFactory.generateTextSubmission("text", Language.ENGLISH, true);
        Result result1 = ModelFactory.generateResult(true, 10D);
        Result result2 = ModelFactory.generateResult(true, 12D);
        Result result3 = ModelFactory.generateResult(false, 0D);
        participation1 = studentParticipationRepo.save(participation1);
        participation2 = studentParticipationRepo.save(participation2);
        participation3 = studentParticipationRepo.save(participation3);
        submissionRepository.save(modelingSubmission1);
        submissionRepository.save(modelingSubmission2);
        submissionRepository.save(textSubmission);
        modelingSubmission1.setParticipation(participation1);
        textSubmission.setParticipation(participation2);
        modelingSubmission2.setParticipation(participation3);
        result1.setParticipation(participation1);
        result2.setParticipation(participation3);
        result3.setParticipation(participation2);
        result1 = resultRepo.save(result1);
        result2 = resultRepo.save(result2);
        result3 = resultRepo.save(result3);
        result1.setSubmission(modelingSubmission1);
        result2.setSubmission(modelingSubmission2);
        result3.setSubmission(textSubmission);
        modelingSubmission1.addResult(result1);
        modelingSubmission2.addResult(result2);
        textSubmission.addResult(result3);
        submissionRepository.save(modelingSubmission1);
        submissionRepository.save(modelingSubmission2);
        submissionRepository.save(textSubmission);
    }
    return Arrays.asList(course1, course2);
}
Also used : ModelingSubmission(de.tum.in.www1.artemis.domain.modeling.ModelingSubmission) ModelingExercise(de.tum.in.www1.artemis.domain.modeling.ModelingExercise) JsonParser.parseString(com.google.gson.JsonParser.parseString) ExerciseHint(de.tum.in.www1.artemis.domain.hestia.ExerciseHint) TextPlagiarismResult(de.tum.in.www1.artemis.domain.plagiarism.text.TextPlagiarismResult) ModelingPlagiarismResult(de.tum.in.www1.artemis.domain.plagiarism.modeling.ModelingPlagiarismResult) ZonedDateTime(java.time.ZonedDateTime)

Example 12 with Lecture

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

the class DatabaseUtilService method createPostsWithAnswerPostsWithinCourse.

public List<Post> createPostsWithAnswerPostsWithinCourse() {
    List<Post> posts = createPostsWithinCourse();
    // add answer for one post in each context (lecture, exercise, course-wide)
    Post lecturePost = posts.stream().filter(coursePost -> coursePost.getLecture() != null).findFirst().orElseThrow();
    lecturePost.setAnswers(createBasicAnswers(lecturePost));
    postRepository.save(lecturePost);
    Post exercisePost = posts.stream().filter(coursePost -> coursePost.getExercise() != null).findFirst().orElseThrow();
    exercisePost.setAnswers(createBasicAnswers(exercisePost));
    postRepository.save(exercisePost);
    Post courseWidePost = posts.stream().filter(coursePost -> coursePost.getCourseWideContext() != null).findFirst().orElseThrow();
    courseWidePost.setAnswers(createBasicAnswers(courseWidePost));
    postRepository.save(courseWidePost);
    return posts;
}
Also used : AnswerPost(de.tum.in.www1.artemis.domain.metis.AnswerPost) Post(de.tum.in.www1.artemis.domain.metis.Post)

Example 13 with Lecture

use of de.tum.in.www1.artemis.domain.Lecture 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 14 with Lecture

use of de.tum.in.www1.artemis.domain.Lecture 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)

Example 15 with Lecture

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

the class FileIntegrationTest method uploadAttachmentUnit.

private AttachmentUnit uploadAttachmentUnit(MockMultipartFile file, Long lectureId, HttpStatus expectedStatus) throws Exception {
    Lecture lecture = lectureRepo.findByIdWithPostsAndLectureUnitsAndLearningGoals(lectureId).get();
    AttachmentUnit attachmentUnit = database.createAttachmentUnit(false);
    // upload file
    JsonNode response = request.postWithMultipartFile("/api/fileUpload?keepFileName=true", file.getOriginalFilename(), "file", file, JsonNode.class, expectedStatus);
    if (expectedStatus != HttpStatus.CREATED) {
        return null;
    }
    String responsePath = response.get("path").asText();
    // move file from temp folder to correct folder
    var targetFolder = Path.of(FilePathService.getAttachmentUnitFilePath(), String.valueOf(attachmentUnit.getId())).toString();
    fileService.manageFilesForUpdatedFilePath(null, responsePath, targetFolder, lecture.getId(), true);
    var attachmentPath = targetFolder + "/" + file.getOriginalFilename();
    attachmentUnit.getAttachment().setLink(attachmentPath);
    attachmentRepo.save(attachmentUnit.getAttachment());
    return attachmentUnit;
}
Also used : AttachmentUnit(de.tum.in.www1.artemis.domain.lecture.AttachmentUnit) JsonNode(com.fasterxml.jackson.databind.JsonNode)

Aggregations

PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)50 Lecture (de.tum.in.www1.artemis.domain.Lecture)42 LectureUnit (de.tum.in.www1.artemis.domain.lecture.LectureUnit)34 WithMockUser (org.springframework.security.test.context.support.WithMockUser)32 Post (de.tum.in.www1.artemis.domain.metis.Post)31 Test (org.junit.jupiter.api.Test)30 ConflictException (de.tum.in.www1.artemis.web.rest.errors.ConflictException)28 ExerciseUnit (de.tum.in.www1.artemis.domain.lecture.ExerciseUnit)22 Course (de.tum.in.www1.artemis.domain.Course)20 TextUnit (de.tum.in.www1.artemis.domain.lecture.TextUnit)18 BadRequestAlertException (de.tum.in.www1.artemis.web.rest.errors.BadRequestAlertException)18 AbstractSpringIntegrationBambooBitbucketJiraTest (de.tum.in.www1.artemis.AbstractSpringIntegrationBambooBitbucketJiraTest)16 AttachmentUnit (de.tum.in.www1.artemis.domain.lecture.AttachmentUnit)16 URI (java.net.URI)14 User (de.tum.in.www1.artemis.domain.User)13 BadRequestException (javax.ws.rs.BadRequestException)12 BeforeEach (org.junit.jupiter.api.BeforeEach)12 LearningGoal (de.tum.in.www1.artemis.domain.LearningGoal)10 AnswerPost (de.tum.in.www1.artemis.domain.metis.AnswerPost)10 EntityNotFoundException (de.tum.in.www1.artemis.web.rest.errors.EntityNotFoundException)10