Search in sources :

Example 26 with ModelingSubmission

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

the class ParticipationTeamWebsocketService method updateSubmission.

/**
 * Updates a modeling or text submission
 *
 * @param participationId id of participation
 * @param submission      updated modeling text submission
 * @param principal       principal of user who wants to update the submission
 * @param topicPath       path of websocket destination topic where to send the new submission
 */
private void updateSubmission(@DestinationVariable Long participationId, @Payload Submission submission, Principal principal, String topicPath) {
    // Without this, custom jpa repository methods don't work in websocket channel.
    SecurityUtils.setAuthorizationObject();
    final StudentParticipation participation = studentParticipationRepository.findByIdElseThrow(participationId);
    // user must belong to the team who owns the participation in order to update a submission
    if (!participation.isOwnedBy(principal.getName())) {
        return;
    }
    final User user = userRepository.getUserWithGroupsAndAuthorities(principal.getName());
    final Exercise exercise = exerciseRepository.findByIdElseThrow(participation.getExercise().getId());
    if (submission instanceof ModelingSubmission && exercise instanceof ModelingExercise) {
        submission = modelingSubmissionService.save((ModelingSubmission) submission, (ModelingExercise) exercise, principal.getName());
        modelingSubmissionService.hideDetails(submission, user);
    } else if (submission instanceof TextSubmission && exercise instanceof TextExercise) {
        submission = textSubmissionService.handleTextSubmission((TextSubmission) submission, (TextExercise) exercise, principal);
        textSubmissionService.hideDetails(submission, user);
    } else {
        throw new IllegalArgumentException("Submission type '" + submission.getType() + "' not allowed.");
    }
    // update the last action date for the user and send out list of team members
    updateValue(lastActionTracker, participationId, principal.getName());
    sendOnlineTeamStudents(participationId);
    SubmissionSyncPayload payload = new SubmissionSyncPayload(submission, user);
    messagingTemplate.convertAndSend(getDestination(participationId, topicPath), payload);
}
Also used : ModelingExercise(de.tum.in.www1.artemis.domain.modeling.ModelingExercise) SubmissionSyncPayload(de.tum.in.www1.artemis.web.websocket.dto.SubmissionSyncPayload) 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)

Example 27 with ModelingSubmission

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

the class CompassService method getSuggestionResult.

/**
 * Selects the feedback suggestion for each element in submission and creates a result from them
 * Returns null if no feedback can be selected or the submission has already a manual feedback
 *
 * @param modelingSubmission the submission to select feedbacks for
 * @param modelingExercise the modeling exercise to which the submission belongs
 * @return the semi-automatic result that has the feedbacks inside
 */
public Result getSuggestionResult(ModelingSubmission modelingSubmission, ModelingExercise modelingExercise) {
    Result result = getAutomaticResultForSubmission(modelingSubmission);
    if (result != null) {
        List<Feedback> feedbacksForSuggestion = new ArrayList<>();
        ModelClusterFactory clusterBuilder = new ModelClusterFactory();
        List<UMLElement> elements = clusterBuilder.getModelElements(modelingSubmission);
        List<ModelElement> modelElements = modelElementRepository.findByModelElementIdIn(elements.stream().map(UMLElement::getJSONElementID).collect(Collectors.toList()));
        List<Long> clusterIds = modelElements.stream().map(ModelElement::getCluster).map(ModelCluster::getId).collect(Collectors.toList());
        List<ModelCluster> modelClusters = modelClusterRepository.findAllByIdInWithEagerElements(clusterIds);
        List<String> references = modelClusters.stream().flatMap(modelCluster -> modelCluster.getModelElements().stream()).map(modelElement1 -> modelElement1.getModelElementType() + ":" + modelElement1.getModelElementId()).collect(Collectors.toList());
        List<Feedback> feedbacks = feedbackRepository.findByReferenceInAndResult_Submission_Participation_Exercise(references, modelingExercise);
        for (ModelElement modelElement : modelElements) {
            if (modelElement != null) {
                ModelCluster cluster = modelClusters.get(modelClusters.indexOf(modelElement.getCluster()));
                Set<ModelElement> similarElements = cluster.getModelElements();
                List<String> similarReferences = similarElements.stream().map(element -> element.getModelElementType() + ":" + element.getModelElementId()).toList();
                List<Feedback> similarFeedbacks = feedbacks.stream().filter(feedback -> similarReferences.contains(feedback.getReference())).collect(Collectors.toList());
                Feedback suggestedFeedback = FeedbackSelector.selectFeedback(modelElement, similarFeedbacks, result);
                if (suggestedFeedback != null) {
                    feedbacksForSuggestion.add(suggestedFeedback);
                }
            }
        }
        if (feedbacksForSuggestion.isEmpty()) {
            return null;
        }
        // Note, that a result is always initialized with an empty list -> no NPE here
        result.getFeedbacks().clear();
        result.getFeedbacks().addAll(feedbacksForSuggestion);
        result.setHasFeedback(false);
        result.setAssessmentType(AssessmentType.SEMI_AUTOMATIC);
    }
    return result;
}
Also used : java.util(java.util) Feedback(de.tum.in.www1.artemis.domain.Feedback) Logger(org.slf4j.Logger) FeedbackSelector(de.tum.in.www1.artemis.service.compass.controller.FeedbackSelector) de.tum.in.www1.artemis.repository(de.tum.in.www1.artemis.repository) TimeLogUtil(de.tum.in.www1.artemis.service.util.TimeLogUtil) LoggerFactory(org.slf4j.LoggerFactory) AssessmentType(de.tum.in.www1.artemis.domain.enumeration.AssessmentType) Collectors(java.util.stream.Collectors) UMLElement(de.tum.in.www1.artemis.service.compass.umlmodel.UMLElement) Result(de.tum.in.www1.artemis.domain.Result) ModelElement(de.tum.in.www1.artemis.domain.modeling.ModelElement) ModelClusterFactory(de.tum.in.www1.artemis.service.compass.controller.ModelClusterFactory) Service(org.springframework.stereotype.Service) ModelCluster(de.tum.in.www1.artemis.domain.modeling.ModelCluster) ModelingSubmission(de.tum.in.www1.artemis.domain.modeling.ModelingSubmission) StudentParticipation(de.tum.in.www1.artemis.domain.participation.StudentParticipation) ModelingExercise(de.tum.in.www1.artemis.domain.modeling.ModelingExercise) UMLElement(de.tum.in.www1.artemis.service.compass.umlmodel.UMLElement) ModelCluster(de.tum.in.www1.artemis.domain.modeling.ModelCluster) Result(de.tum.in.www1.artemis.domain.Result) ModelClusterFactory(de.tum.in.www1.artemis.service.compass.controller.ModelClusterFactory) ModelElement(de.tum.in.www1.artemis.domain.modeling.ModelElement) Feedback(de.tum.in.www1.artemis.domain.Feedback)

Example 28 with ModelingSubmission

use of de.tum.in.www1.artemis.domain.modeling.ModelingSubmission 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 29 with ModelingSubmission

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

Example 30 with ModelingSubmission

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

the class ModelingSubmissionIntegrationTest method saveExercise_beforeDueDate.

@Test
@WithMockUser(username = "student3", roles = "USER")
public void saveExercise_beforeDueDate() throws Exception {
    ModelingSubmission storedSubmission = request.postWithResponseBody("/api/exercises/" + classExercise.getId() + "/modeling-submissions", unsubmittedSubmission, ModelingSubmission.class, HttpStatus.OK);
    assertThat(storedSubmission.isSubmitted()).isTrue();
}
Also used : ModelingSubmission(de.tum.in.www1.artemis.domain.modeling.ModelingSubmission) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.jupiter.api.Test)

Aggregations

ModelingSubmission (de.tum.in.www1.artemis.domain.modeling.ModelingSubmission)160 Test (org.junit.jupiter.api.Test)108 WithMockUser (org.springframework.security.test.context.support.WithMockUser)106 ModelingExercise (de.tum.in.www1.artemis.domain.modeling.ModelingExercise)36 StudentParticipation (de.tum.in.www1.artemis.domain.participation.StudentParticipation)22 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)20 AbstractSpringIntegrationBambooBitbucketJiraTest (de.tum.in.www1.artemis.AbstractSpringIntegrationBambooBitbucketJiraTest)16 ModelingPlagiarismResult (de.tum.in.www1.artemis.domain.plagiarism.modeling.ModelingPlagiarismResult)16 TextPlagiarismResult (de.tum.in.www1.artemis.domain.plagiarism.text.TextPlagiarismResult)12 JsonParser.parseString (com.google.gson.JsonParser.parseString)8 ModelCluster (de.tum.in.www1.artemis.domain.modeling.ModelCluster)8 ModelingSubmission (de.tum.in.www1.artemis.domain.ModelingSubmission)6 Result (de.tum.in.www1.artemis.domain.Result)6 ModelElement (de.tum.in.www1.artemis.domain.modeling.ModelElement)6 ModelClusterFactory (de.tum.in.www1.artemis.service.compass.controller.ModelClusterFactory)6 StudentExam (de.tum.in.www1.artemis.domain.exam.StudentExam)4 ExerciseHint (de.tum.in.www1.artemis.domain.hestia.ExerciseHint)4 Participation (de.tum.in.www1.artemis.domain.participation.Participation)4 PlagiarismComparison (de.tum.in.www1.artemis.domain.plagiarism.PlagiarismComparison)4 PlagiarismSubmission (de.tum.in.www1.artemis.domain.plagiarism.PlagiarismSubmission)4