use of de.tum.in.www1.artemis.domain.ProgrammingSubmission in project ArTEMiS by ls1intum.
the class DatabaseUtilService method generateTestRunForInstructor.
public StudentExam generateTestRunForInstructor(Exam exam, User instructor, List<Exercise> exercises) {
var testRun = ModelFactory.generateExamTestRun(exam);
testRun.setUser(instructor);
examRepository.findWithExerciseGroupsAndExercisesById(exam.getId()).get();
for (final var exercise : exercises) {
testRun.addExercise(exercise);
assertThat(exercise.isExamExercise()).isTrue();
Submission submission;
if (exercise instanceof ModelingExercise) {
submission = addModelingSubmission((ModelingExercise) exercise, ModelFactory.generateModelingSubmission("", false), instructor.getLogin());
} else if (exercise instanceof TextExercise) {
submission = saveTextSubmission((TextExercise) exercise, ModelFactory.generateTextSubmission("", null, false), instructor.getLogin());
} else {
submission = new ProgrammingSubmission().submitted(true);
addProgrammingSubmission((ProgrammingExercise) exercise, (ProgrammingSubmission) submission, instructor.getLogin());
submission = submissionRepository.save(submission);
}
var studentParticipation = (StudentParticipation) submission.getParticipation();
studentParticipation.setTestRun(true);
studentParticipationRepo.save(studentParticipation);
}
return testRun;
}
use of de.tum.in.www1.artemis.domain.ProgrammingSubmission in project ArTEMiS by ls1intum.
the class DatabaseUtilService method addProgrammingSubmissionWithResult.
/**
* Add a submission with a result to the given programming exercise. The submission will be assigned to the corresponding participation of the given login (if exists or create a new participation).
* The method will make sure that all necessary entities are connected.
*
* @param exercise for which to create the submission/participation/result combination.
* @param submission to use for adding to the exercise/participation/result.
* @param login of the user to identify the corresponding student participation.
*/
public void addProgrammingSubmissionWithResult(ProgrammingExercise exercise, ProgrammingSubmission submission, String login) {
StudentParticipation participation = addStudentParticipationForProgrammingExercise(exercise, login);
submission = programmingSubmissionRepo.save(submission);
Result result = resultRepo.save(new Result().participation(participation));
participation.addSubmission(submission);
submission.setParticipation(participation);
submission.addResult(result);
submission = programmingSubmissionRepo.save(submission);
result.setSubmission(submission);
result = resultRepo.save(result);
participation.addResult(result);
studentParticipationRepo.save(participation);
}
use of de.tum.in.www1.artemis.domain.ProgrammingSubmission in project ArTEMiS by ls1intum.
the class ProgrammingSubmissionResultSimulationService method createSubmission.
/**
* This method creates a new submission for the provided user
* @param exerciseId the exerciseId of the exercise for which a submission should be created
* This functionality is only for testing purposes (noVersionControlAndContinuousIntegrationAvailable)
* @return the newly created and stored submission
*/
public ProgrammingSubmission createSubmission(Long exerciseId) {
User user = userRepository.getUserWithGroupsAndAuthorities();
Participant participant = user;
ProgrammingExerciseStudentParticipation programmingExerciseStudentParticipation;
ProgrammingExercise programmingExercise = programmingExerciseRepository.findByIdWithStudentParticipationsAndLegalSubmissionsElseThrow(exerciseId);
Optional<StudentParticipation> optionalStudentParticipation = participationService.findOneByExerciseAndStudentLoginWithEagerSubmissionsAnyState(programmingExercise, user.getLogin());
if (optionalStudentParticipation.isEmpty()) {
programmingExerciseStudentParticipation = createParticipation(programmingExercise, participant, user);
} else {
programmingExerciseStudentParticipation = (ProgrammingExerciseStudentParticipation) optionalStudentParticipation.get();
}
ProgrammingSubmission programmingSubmission = new ProgrammingSubmission();
programmingSubmission.setCommitHash(VCSSimulationUtils.simulateCommitHash());
programmingSubmission.setSubmitted(true);
programmingSubmission.setSubmissionDate(ZonedDateTime.now());
programmingSubmission.setType(SubmissionType.MANUAL);
programmingExerciseStudentParticipation.addSubmission(programmingSubmission);
programmingSubmissionRepository.save(programmingSubmission);
return programmingSubmission;
}
use of de.tum.in.www1.artemis.domain.ProgrammingSubmission in project ArTEMiS by ls1intum.
the class JenkinsService method getLatestBuildLogs.
@Override
public List<BuildLogEntry> getLatestBuildLogs(ProgrammingSubmission programmingSubmission) {
ProgrammingExerciseParticipation programmingExerciseParticipation = (ProgrammingExerciseParticipation) programmingSubmission.getParticipation();
String projectKey = programmingExerciseParticipation.getProgrammingExercise().getProjectKey();
String buildPlanId = programmingExerciseParticipation.getBuildPlanId();
ProgrammingLanguage programmingLanguage = programmingExerciseParticipation.getProgrammingExercise().getProgrammingLanguage();
try {
final var build = jenkinsJobService.getJobInFolder(projectKey, buildPlanId).getLastBuild();
List<BuildLogEntry> buildLogEntries;
// Attempt to parse pipeline logs
final String pipelineLogs = build.details().getConsoleOutputText();
if (pipelineLogs != null && pipelineLogs.contains("[Pipeline] Start of Pipeline")) {
buildLogEntries = JenkinsBuildLogParseUtils.parseBuildLogsFromJenkinsLogs(List.of(pipelineLogs.split("\n")));
} else {
// Fallback to legacy logs
final var logHtml = Jsoup.parse(build.details().getConsoleOutputHtml()).body();
buildLogEntries = JenkinsBuildLogParseUtils.parseLogsLegacy(logHtml);
}
// Filter and save build logs
buildLogEntries = filterUnnecessaryLogs(buildLogEntries, programmingLanguage);
buildLogEntries = buildLogService.saveBuildLogs(buildLogEntries, programmingSubmission);
programmingSubmission.setBuildLogEntries(buildLogEntries);
programmingSubmissionRepository.save(programmingSubmission);
return buildLogEntries;
} catch (IOException e) {
log.error(e.getMessage(), e);
throw new JenkinsException(e.getMessage(), e);
}
}
use of de.tum.in.www1.artemis.domain.ProgrammingSubmission 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);
}
}
Aggregations