Search in sources :

Example 46 with ModelingExercise

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

the class CompassService method build.

/**
 * Builds and saves the clusters
 * Does not build clusters if there is already a cluster for given exercise
 *
 * @param modelingExercise the exercise to build clusters for
 */
public void build(ModelingExercise modelingExercise) {
    long start = System.nanoTime();
    if (!isSupported(modelingExercise)) {
        return;
    }
    List<ModelCluster> currentClusters = modelClusterRepository.findAllByExerciseIdWithEagerElements(modelingExercise.getId());
    if (!currentClusters.isEmpty()) {
        log.info("Clusters have already been built. First delete existing clusters and then rebuild them!");
        // Do not build submissions if this process has already been done before
        return;
    }
    List<ModelingSubmission> submissions = modelingSubmissionRepository.findSubmittedByExerciseIdWithEagerResultsAndFeedback(modelingExercise.getId());
    log.info("ModelCluster: start building clusters of {} submissions for modeling exercise {}", submissions.size(), modelingExercise.getId());
    ModelClusterFactory clusterFactory = new ModelClusterFactory();
    List<ModelCluster> modelClusters = clusterFactory.buildClusters(submissions, modelingExercise);
    log.info("ModelClusterTimeLog: building clusters of {} submissions for modeling exercise {} done in {}", submissions.size(), modelingExercise.getId(), TimeLogUtil.formatDurationFrom(start));
    modelClusterRepository.saveAll(modelClusters);
    modelElementRepository.saveAll(modelClusters.stream().flatMap(modelCluster -> modelCluster.getModelElements().stream()).collect(Collectors.toList()));
    log.info("ModelClusterTimeLog: building and saving clusters of {} submissions for exercise {} done in {}", submissions.size(), modelingExercise.getId(), TimeLogUtil.formatDurationFrom(start));
}
Also used : ModelClusterFactory(de.tum.in.www1.artemis.service.compass.controller.ModelClusterFactory) ModelingSubmission(de.tum.in.www1.artemis.domain.modeling.ModelingSubmission) ModelCluster(de.tum.in.www1.artemis.domain.modeling.ModelCluster)

Example 47 with ModelingExercise

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

the class ModelingExerciseResource method exportSubmissions.

/**
 * POST modeling-exercises/:exerciseId/export-submissions : sends exercise submissions as zip
 *
 * @param exerciseId the id of the exercise to get the repos from
 * @param submissionExportOptions the options that should be used for the export
 * @return ResponseEntity with status
 */
@PostMapping("modeling-exercises/{exerciseId}/export-submissions")
@PreAuthorize("hasRole('TA')")
public ResponseEntity<Resource> exportSubmissions(@PathVariable long exerciseId, @RequestBody SubmissionExportOptionsDTO submissionExportOptions) {
    ModelingExercise modelingExercise = modelingExerciseRepository.findByIdElseThrow(exerciseId);
    authCheckService.checkHasAtLeastRoleForExerciseElseThrow(Role.TEACHING_ASSISTANT, modelingExercise, null);
    // TAs are not allowed to download all participations
    if (submissionExportOptions.isExportAllParticipants()) {
        authCheckService.checkHasAtLeastRoleInCourseElseThrow(Role.INSTRUCTOR, modelingExercise.getCourseViaExerciseGroupOrCourseMember(), null);
    }
    File zipFile = modelingSubmissionExportService.exportStudentSubmissionsElseThrow(exerciseId, submissionExportOptions);
    return ResponseUtil.ok(zipFile);
}
Also used : ModelingExercise(de.tum.in.www1.artemis.domain.modeling.ModelingExercise) File(java.io.File) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 48 with ModelingExercise

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

the class ModelingExerciseResource method updateModelingExercise.

/**
 * PUT modeling-exercises : Updates an existing modelingExercise.
 *
 * @param modelingExercise the modelingExercise to update
 * @param notificationText the text shown to students
 * @return the ResponseEntity with status 200 (OK) and with body the updated modelingExercise, or with status 400 (Bad Request) if the modelingExercise is not valid, or with
 *         status 500 (Internal Server Error) if the modelingExercise couldn't be updated
 * @throws URISyntaxException if the Location URI syntax is incorrect
 */
@PutMapping("modeling-exercises")
@PreAuthorize("hasRole('EDITOR')")
public ResponseEntity<ModelingExercise> updateModelingExercise(@RequestBody ModelingExercise modelingExercise, @RequestParam(value = "notificationText", required = false) String notificationText) throws URISyntaxException {
    log.debug("REST request to update ModelingExercise : {}", modelingExercise);
    if (modelingExercise.getId() == null) {
        return createModelingExercise(modelingExercise);
    }
    // validates general settings: points, dates
    modelingExercise.validateGeneralSettings();
    // Valid exercises have set either a course or an exerciseGroup
    modelingExercise.checkCourseAndExerciseGroupExclusivity(ENTITY_NAME);
    // Check that the user is authorized to update the exercise
    var user = userRepository.getUserWithGroupsAndAuthorities();
    // Important: use the original exercise for permission check
    final ModelingExercise modelingExerciseBeforeUpdate = modelingExerciseRepository.findByIdElseThrow(modelingExercise.getId());
    authCheckService.checkHasAtLeastRoleForExerciseElseThrow(Role.EDITOR, modelingExerciseBeforeUpdate, user);
    // Forbid changing the course the exercise belongs to.
    if (!Objects.equals(modelingExerciseBeforeUpdate.getCourseViaExerciseGroupOrCourseMember().getId(), modelingExercise.getCourseViaExerciseGroupOrCourseMember().getId())) {
        throw new ConflictException("Exercise course id does not match the stored course id", ENTITY_NAME, "cannotChangeCourseId");
    }
    // Forbid conversion between normal course exercise and exam exercise
    exerciseService.checkForConversionBetweenExamAndCourseExercise(modelingExercise, modelingExerciseBeforeUpdate, ENTITY_NAME);
    ModelingExercise updatedModelingExercise = modelingExerciseRepository.save(modelingExercise);
    exerciseService.logUpdate(modelingExercise, modelingExercise.getCourseViaExerciseGroupOrCourseMember(), user);
    exerciseService.updatePointsInRelatedParticipantScores(modelingExerciseBeforeUpdate, updatedModelingExercise);
    participationRepository.removeIndividualDueDatesIfBeforeDueDate(updatedModelingExercise, modelingExerciseBeforeUpdate.getDueDate());
    modelingExerciseService.scheduleOperations(updatedModelingExercise.getId());
    exerciseService.checkExampleSubmissions(updatedModelingExercise);
    groupNotificationService.checkAndCreateAppropriateNotificationsWhenUpdatingExercise(modelingExerciseBeforeUpdate, updatedModelingExercise, notificationText, instanceMessageSendService);
    return ResponseEntity.ok().headers(HeaderUtil.createEntityUpdateAlert(applicationName, true, ENTITY_NAME, modelingExercise.getId().toString())).body(updatedModelingExercise);
}
Also used : ConflictException(de.tum.in.www1.artemis.web.rest.errors.ConflictException) ModelingExercise(de.tum.in.www1.artemis.domain.modeling.ModelingExercise) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 49 with ModelingExercise

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

the class ModelingExerciseResource method importExercise.

/**
 * POST modeling-exercises/import: Imports an existing modeling exercise into an existing course
 *
 * This will import the whole exercise except for the participations and Dates.
 * Referenced entities will get cloned and assigned a new id.
 * Uses {@link ModelingExerciseImportService}.
 *
 * @param sourceExerciseId The ID of the original exercise which should get imported
 * @param importedExercise The new exercise containing values that should get overwritten in the imported exercise, s.a. the title or difficulty
 * @throws URISyntaxException When the URI of the response entity is invalid
 *
 * @return The imported exercise (200), a not found error (404) if the template does not exist, or a forbidden error
 *         (403) if the user is not at least an instructor in the target course.
 */
@PostMapping("modeling-exercises/import/{sourceExerciseId}")
@PreAuthorize("hasRole('EDITOR')")
public ResponseEntity<ModelingExercise> importExercise(@PathVariable long sourceExerciseId, @RequestBody ModelingExercise importedExercise) throws URISyntaxException {
    if (sourceExerciseId <= 0 || (importedExercise.getCourseViaExerciseGroupOrCourseMember() == null && importedExercise.getExerciseGroup() == null)) {
        log.debug("Either the courseId or exerciseGroupId must be set for an import");
        throw new BadRequestAlertException("Either the courseId or exerciseGroupId must be set for an import", ENTITY_NAME, "noCourseIdOrExerciseGroupId");
    }
    importedExercise.checkCourseAndExerciseGroupExclusivity("Modeling Exercise");
    final var user = userRepository.getUserWithGroupsAndAuthorities();
    final var originalModelingExercise = modelingExerciseRepository.findByIdWithExampleSubmissionsAndResultsElseThrow(sourceExerciseId);
    authCheckService.checkHasAtLeastRoleForExerciseElseThrow(Role.EDITOR, importedExercise, user);
    authCheckService.checkHasAtLeastRoleForExerciseElseThrow(Role.EDITOR, originalModelingExercise, user);
    // validates general settings: points, dates
    importedExercise.validateGeneralSettings();
    final var newModelingExercise = modelingExerciseImportService.importModelingExercise(originalModelingExercise, importedExercise);
    ModelingExercise result = modelingExerciseRepository.save(newModelingExercise);
    modelingExerciseService.scheduleOperations(result.getId());
    return ResponseEntity.created(new URI("/api/modeling-exercises/" + newModelingExercise.getId())).headers(HeaderUtil.createEntityCreationAlert(applicationName, true, ENTITY_NAME, newModelingExercise.getId().toString())).body(newModelingExercise);
}
Also used : BadRequestAlertException(de.tum.in.www1.artemis.web.rest.errors.BadRequestAlertException) ModelingExercise(de.tum.in.www1.artemis.domain.modeling.ModelingExercise) URI(java.net.URI) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 50 with ModelingExercise

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

the class ComplaintResource method filterOutUselessDataFromComplaint.

private void filterOutUselessDataFromComplaint(Complaint complaint) {
    if (complaint.getResult() == null) {
        return;
    }
    StudentParticipation originalParticipation = (StudentParticipation) complaint.getResult().getParticipation();
    if (originalParticipation != null && originalParticipation.getExercise() != null) {
        Exercise exerciseWithOnlyTitle = originalParticipation.getExercise();
        if (exerciseWithOnlyTitle instanceof TextExercise) {
            exerciseWithOnlyTitle = new TextExercise();
        } else if (exerciseWithOnlyTitle instanceof ModelingExercise) {
            exerciseWithOnlyTitle = new ModelingExercise();
        } else if (exerciseWithOnlyTitle instanceof FileUploadExercise) {
            exerciseWithOnlyTitle = new FileUploadExercise();
        } else if (exerciseWithOnlyTitle instanceof ProgrammingExercise) {
            exerciseWithOnlyTitle = new ProgrammingExercise();
        }
        exerciseWithOnlyTitle.setTitle(originalParticipation.getExercise().getTitle());
        exerciseWithOnlyTitle.setId(originalParticipation.getExercise().getId());
        originalParticipation.setExercise(exerciseWithOnlyTitle);
    }
    Submission originalSubmission = complaint.getResult().getSubmission();
    if (originalSubmission != null) {
        Submission submissionWithOnlyId;
        if (originalSubmission instanceof TextSubmission) {
            submissionWithOnlyId = new TextSubmission();
        } else if (originalSubmission instanceof ModelingSubmission) {
            submissionWithOnlyId = new ModelingSubmission();
        } else if (originalSubmission instanceof FileUploadSubmission) {
            submissionWithOnlyId = new FileUploadSubmission();
        } else if (originalSubmission instanceof ProgrammingSubmission) {
            submissionWithOnlyId = new ProgrammingSubmission();
        } else {
            return;
        }
        submissionWithOnlyId.setId(originalSubmission.getId());
        complaint.getResult().setSubmission(submissionWithOnlyId);
    }
}
Also used : ModelingExercise(de.tum.in.www1.artemis.domain.modeling.ModelingExercise) ModelingSubmission(de.tum.in.www1.artemis.domain.modeling.ModelingSubmission) ModelingSubmission(de.tum.in.www1.artemis.domain.modeling.ModelingSubmission) ModelingExercise(de.tum.in.www1.artemis.domain.modeling.ModelingExercise) StudentParticipation(de.tum.in.www1.artemis.domain.participation.StudentParticipation)

Aggregations

ModelingExercise (de.tum.in.www1.artemis.domain.modeling.ModelingExercise)196 WithMockUser (org.springframework.security.test.context.support.WithMockUser)132 Test (org.junit.jupiter.api.Test)126 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)96 ModelingSubmission (de.tum.in.www1.artemis.domain.modeling.ModelingSubmission)72 ModelingPlagiarismResult (de.tum.in.www1.artemis.domain.plagiarism.modeling.ModelingPlagiarismResult)28 ExerciseGroup (de.tum.in.www1.artemis.domain.exam.ExerciseGroup)26 StudentParticipation (de.tum.in.www1.artemis.domain.participation.StudentParticipation)20 AbstractSpringIntegrationBambooBitbucketJiraTest (de.tum.in.www1.artemis.AbstractSpringIntegrationBambooBitbucketJiraTest)16 TextPlagiarismResult (de.tum.in.www1.artemis.domain.plagiarism.text.TextPlagiarismResult)16 BeforeEach (org.junit.jupiter.api.BeforeEach)16 Course (de.tum.in.www1.artemis.domain.Course)14 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)14 ZonedDateTime (java.time.ZonedDateTime)12 Exam (de.tum.in.www1.artemis.domain.exam.Exam)10 QuizExercise (de.tum.in.www1.artemis.domain.quiz.QuizExercise)10 TeamAssignmentPayload (de.tum.in.www1.artemis.web.websocket.dto.TeamAssignmentPayload)9 JsonParser.parseString (com.google.gson.JsonParser.parseString)8 StudentExam (de.tum.in.www1.artemis.domain.exam.StudentExam)8 ModelCluster (de.tum.in.www1.artemis.domain.modeling.ModelCluster)8