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);
}
}
use of de.tum.in.www1.artemis.domain.modeling.ModelingExercise in project Artemis by ls1intum.
the class ModelingExerciseResource method getModelingExercisesForCourse.
/**
* GET /courses/:courseId/exercises : get all the exercises.
*
* @param courseId the id of the course
* @return the ResponseEntity with status 200 (OK) and the list of modelingExercises in body
*/
@GetMapping(value = "/courses/{courseId}/modeling-exercises")
@PreAuthorize("hasRole('TA')")
public ResponseEntity<List<ModelingExercise>> getModelingExercisesForCourse(@PathVariable Long courseId) {
log.debug("REST request to get all ModelingExercises for the course with id : {}", courseId);
Course course = courseRepository.findByIdElseThrow(courseId);
authCheckService.checkHasAtLeastRoleInCourseElseThrow(Role.TEACHING_ASSISTANT, course, null);
List<ModelingExercise> exercises = modelingExerciseRepository.findByCourseIdWithCategories(courseId);
for (Exercise exercise : exercises) {
// not required in the returned json body
exercise.setStudentParticipations(null);
exercise.setCourse(null);
}
return ResponseEntity.ok().body(exercises);
}
use of de.tum.in.www1.artemis.domain.modeling.ModelingExercise in project Artemis by ls1intum.
the class ModelingExerciseResource method checkPlagiarism.
/**
* GET modeling-exercises/{exerciseId}/check-plagiarism
* <p>
* Start the automated plagiarism detection for the given exercise and return its result.
*
* @param exerciseId for which all submission should be checked
* @param similarityThreshold ignore comparisons whose similarity is below this threshold (%)
* @param minimumScore consider only submissions whose score is greater or equal to this
* value
* @param minimumSize consider only submissions whose size is greater or equal to this
* value
* @return the ResponseEntity with status 200 (OK) and the list of at most 500 pair-wise submissions with a similarity above the given threshold (e.g. 50%).
*/
@GetMapping("modeling-exercises/{exerciseId}/check-plagiarism")
@FeatureToggle(Feature.PlagiarismChecks)
@PreAuthorize("hasRole('INSTRUCTOR')")
public ResponseEntity<ModelingPlagiarismResult> checkPlagiarism(@PathVariable long exerciseId, @RequestParam float similarityThreshold, @RequestParam int minimumScore, @RequestParam int minimumSize) {
var modelingExercise = modelingExerciseRepository.findByIdWithStudentParticipationsSubmissionsResultsElseThrow(exerciseId);
authCheckService.checkHasAtLeastRoleForExerciseElseThrow(Role.INSTRUCTOR, modelingExercise, null);
long start = System.nanoTime();
log.info("Start modelingPlagiarismDetectionService.checkPlagiarism for exercise {}", exerciseId);
ModelingPlagiarismResult result = modelingPlagiarismDetectionService.checkPlagiarism(modelingExercise, similarityThreshold / 100, minimumSize, minimumScore);
log.info("Finished modelingPlagiarismDetectionService.checkPlagiarism call for {} comparisons in {}", result.getComparisons().size(), TimeLogUtil.formatDurationFrom(start));
// TODO: limit the amount temporarily because of database issues
result.sortAndLimit(100);
log.info("Limited number of comparisons to {} to avoid performance issues when saving to database", result.getComparisons().size());
start = System.nanoTime();
plagiarismResultRepository.savePlagiarismResultAndRemovePrevious(result);
log.info("Finished plagiarismResultRepository.savePlagiarismResultAndRemovePrevious call in {}", TimeLogUtil.formatDurationFrom(start));
for (var comparison : result.getComparisons()) {
comparison.setPlagiarismResult(null);
}
return ResponseEntity.ok(result);
}
use of de.tum.in.www1.artemis.domain.modeling.ModelingExercise in project Artemis by ls1intum.
the class ModelingExerciseResource method createModelingExercise.
// TODO: most of these calls should be done in the context of a course
/**
* POST modeling-exercises : Create a new modelingExercise.
*
* @param modelingExercise the modelingExercise to create
* @return the ResponseEntity with status 201 (Created) and with body the new modelingExercise, or with status 400 (Bad Request) if the modelingExercise has already an ID
* @throws URISyntaxException if the Location URI syntax is incorrect
*/
// TODO: we should add courses/{courseId} here
@PostMapping("modeling-exercises")
@PreAuthorize("hasRole('EDITOR')")
public ResponseEntity<ModelingExercise> createModelingExercise(@RequestBody ModelingExercise modelingExercise) throws URISyntaxException {
log.debug("REST request to save ModelingExercise : {}", modelingExercise);
if (modelingExercise.getId() != null) {
throw new BadRequestAlertException("A new modeling exercise cannot already have an ID", ENTITY_NAME, "idexists");
}
if (modelingExercise.getTitle() == null) {
throw new BadRequestAlertException("A new modeling exercise needs a title", ENTITY_NAME, "missingtitle");
}
// validates general settings: points, dates
modelingExercise.validateGeneralSettings();
// Valid exercises have set either a course or an exerciseGroup
modelingExercise.checkCourseAndExerciseGroupExclusivity(ENTITY_NAME);
// Retrieve the course over the exerciseGroup or the given courseId
Course course = courseService.retrieveCourseOverExerciseGroupOrCourseId(modelingExercise);
// Check that the user is authorized to create the exercise
authCheckService.checkHasAtLeastRoleInCourseElseThrow(Role.EDITOR, course, null);
// if exercise is created from scratch we create new knowledge instance
modelingExercise.setKnowledge(modelAssessmentKnowledgeService.createNewKnowledge());
ModelingExercise result = modelingExerciseRepository.save(modelingExercise);
modelingExerciseService.scheduleOperations(result.getId());
groupNotificationService.checkNotificationsForNewExercise(modelingExercise, instanceMessageSendService);
return ResponseEntity.created(new URI("/api/modeling-exercises/" + result.getId())).headers(HeaderUtil.createEntityCreationAlert(applicationName, true, ENTITY_NAME, result.getId().toString())).body(result);
}
use of de.tum.in.www1.artemis.domain.modeling.ModelingExercise in project Artemis by ls1intum.
the class ModelingExerciseResource method getPlagiarismResult.
/**
* GET modeling-exercises/{exerciseId}/plagiarism-result
* <p>
* Return the latest plagiarism result or null, if no plagiarism was detected for this exercise yet.
*
* @param exerciseId ID of the modeling exercise for which the plagiarism result should be
* returned
* @return The ResponseEntity with status 200 (Ok) or with status 400 (Bad Request) if the
* parameters are invalid
*/
@GetMapping("modeling-exercises/{exerciseId}/plagiarism-result")
@PreAuthorize("hasRole('EDITOR')")
public ResponseEntity<ModelingPlagiarismResult> getPlagiarismResult(@PathVariable long exerciseId) {
log.debug("REST request to get the latest plagiarism result for the modeling exercise with id: {}", exerciseId);
ModelingExercise modelingExercise = modelingExerciseRepository.findByIdWithStudentParticipationsSubmissionsResultsElseThrow(exerciseId);
authCheckService.checkHasAtLeastRoleForExerciseElseThrow(Role.EDITOR, modelingExercise, null);
var plagiarismResult = plagiarismResultRepository.findFirstByExerciseIdOrderByLastModifiedDateDescOrNull(modelingExercise.getId());
if (plagiarismResult != null) {
for (var comparison : plagiarismResult.getComparisons()) {
comparison.setPlagiarismResult(null);
comparison.getSubmissionA().setPlagiarismComparison(null);
comparison.getSubmissionB().setPlagiarismComparison(null);
}
}
return ResponseEntity.ok((ModelingPlagiarismResult) plagiarismResult);
}
Aggregations