11/* Licensed under EPL-2.0 2024. */
22package edu .kit .kastel .sdq .artemis4j .grading ;
33
4- import java .nio .file .Path ;
5- import java .time .ZonedDateTime ;
6- import java .util .Objects ;
7- import java .util .Optional ;
8-
94import edu .kit .kastel .sdq .artemis4j .ArtemisClientException ;
105import edu .kit .kastel .sdq .artemis4j .ArtemisNetworkException ;
11- import edu .kit .kastel .sdq .artemis4j .client .AssessmentType ;
126import edu .kit .kastel .sdq .artemis4j .client .ProgrammingSubmissionDTO ;
137import edu .kit .kastel .sdq .artemis4j .client .ResultDTO ;
148import edu .kit .kastel .sdq .artemis4j .grading .metajson .AnnotationMappingException ;
159import edu .kit .kastel .sdq .artemis4j .grading .penalty .GradingConfig ;
1610
11+ import java .nio .file .Path ;
12+ import java .time .ZonedDateTime ;
13+ import java .util .Objects ;
14+ import java .util .Optional ;
15+
1716/**
1817 * A student's programming submission. A submission essentially consists of the
1918 * URL of a student's Git repository, along with a commit hash. We do not model
2221public class ProgrammingSubmission extends ArtemisConnectionHolder {
2322 private final ProgrammingSubmissionDTO dto ;
2423
25- private final CorrectionRound correctionRound ;
2624 private final User student ;
2725 private final ProgrammingExercise exercise ;
2826
2927 public ProgrammingSubmission (
30- ProgrammingSubmissionDTO dto , ProgrammingExercise exercise , CorrectionRound correctionRound ) {
28+ ProgrammingSubmissionDTO dto , ProgrammingExercise exercise ) {
3129 super (exercise );
3230
3331 this .dto = dto ;
@@ -40,8 +38,6 @@ public ProgrammingSubmission(
4038 } else {
4139 this .student = null ;
4240 }
43-
44- this .correctionRound = correctionRound ;
4541 }
4642
4743 public long getId () {
@@ -79,10 +75,6 @@ public ProgrammingExercise getExercise() {
7975 return exercise ;
8076 }
8177
82- public CorrectionRound getCorrectionRound () {
83- return this .correctionRound ;
84- }
85-
8678 public ZonedDateTime getSubmissionDate () {
8779 return this .dto .submissionDate ();
8880 }
@@ -95,17 +87,6 @@ public Optional<ResultDTO> getLatestResult() {
9587 }
9688 }
9789
98- /**
99- * Get the assessor of this assessment.
100- * <p>
101- * This is the user who has locked the submission.
102- *
103- * @return the assessor or empty if the submission has not been assessed
104- */
105- public Optional <User > getAssessor () {
106- return this .getRelevantResult ().map (ResultDTO ::assessor ).map (User ::new );
107- }
108-
10990 /**
11091 * Clones the submission, including the test repository, into the given path,
11192 * and checks out the submitted commit. This method uses the user's VCS access token, potentially creating a new one.
@@ -131,7 +112,9 @@ public ClonedProgrammingSubmission cloneViaSSHInto(Path target) throws ArtemisCl
131112 }
132113
133114 /**
134- * Tries to lock this submission. Locking is reentrant.
115+ * Prefer the methods on PackedAssessment!
116+ * <p>
117+ * Tries to lock this submission for a given correction round. Locking is reentrant.
135118 *
136119 * @return An empty optional if a *different* user has already locked the
137120 * submission, otherwise the assessment
@@ -144,46 +127,21 @@ public ClonedProgrammingSubmission cloneViaSSHInto(Path target) throws ArtemisCl
144127 * corresponding student (i.e.
145128 * participation)
146129 */
147- public Optional <Assessment > tryLock (GradingConfig gradingConfig )
130+ public Optional <Assessment > tryLock (GradingConfig gradingConfig , CorrectionRound correctionRound )
148131 throws AnnotationMappingException , ArtemisNetworkException , MoreRecentSubmissionException {
149- return this .exercise .tryLockSubmission (this .getId (), this . getCorrectionRound () , gradingConfig );
132+ return this .exercise .tryLockSubmission (this .getId (), correctionRound , gradingConfig );
150133 }
151134
152- public boolean isSubmitted () {
153- var result = this .getRelevantResult ();
154- if (result .isEmpty () || result .get ().completionDate () == null ) {
155- return false ;
156- }
157-
158- var assessmentType = result .get ().assessmentType ();
159- return assessmentType == AssessmentType .MANUAL || assessmentType == AssessmentType .SEMI_AUTOMATIC ;
135+ public boolean isBuildFailed () {
136+ return this .dto .buildFailed ();
160137 }
161138
162139 /**
163- * Opens the assessment for this submission.
164- * <p>
165- * If the submission has not been assessed by you, you might not be able to
166- * change the assessment.
167- *
168- * @param config the config for the exercise
169- * @return the assessment if there are results for this submission
170- * @throws AnnotationMappingException If the annotations that were already
171- * present could not be mapped given the
172- * gradingConfig
140+ * Be VERY careful with the dto's results, since their number may differ depending on the source of the dto.
141+ * @return the corresponding dto
173142 */
174- public Optional <Assessment > openAssessment (GradingConfig config )
175- throws AnnotationMappingException , ArtemisNetworkException {
176- ResultDTO resultDTO = this .getRelevantResult ().orElse (null );
177-
178- if (resultDTO != null ) {
179- return Optional .of (new Assessment (resultDTO , config , this , this .correctionRound ));
180- }
181-
182- return Optional .empty ();
183- }
184-
185- public boolean isBuildFailed () {
186- return this .dto .buildFailed ();
143+ public ProgrammingSubmissionDTO getDTO () {
144+ return this .dto ;
187145 }
188146
189147 @ Override
@@ -198,30 +156,4 @@ public boolean equals(Object o) {
198156 public int hashCode () {
199157 return Objects .hashCode (this .getId ());
200158 }
201-
202- /**
203- * Returns the relevant result for this submission.
204- * <p>
205- * The difference between this method and {@link #getLatestResult()} is that
206- * when a submission has multiple results from different correction rounds, this
207- * method will return the result for the current correction round. If you want the
208- * latest result regardless of the correction round, use {@link #getLatestResult()}.
209- *
210- * @return the relevant result, if present
211- */
212- public Optional <ResultDTO > getRelevantResult () {
213- var results = this .dto .nonAutomaticResults ();
214-
215- if (results .isEmpty ()) {
216- return Optional .empty ();
217- } else if (results .size () == 1 ) {
218- // We only have one result, so the submission has
219- // probably been created for a specific correction round,
220- // or we only have one correction round
221- return Optional .of (results .get (0 ));
222- } else {
223- // More than one result, so probably multiple correction rounds
224- return Optional .of (results .get (this .correctionRound .toArtemis ()));
225- }
226- }
227159}
0 commit comments