1
1
/* Licensed under EPL-2.0 2024. */
2
2
package edu .kit .kastel .sdq .artemis4j .grading ;
3
3
4
- import java .nio .file .Path ;
5
- import java .time .ZonedDateTime ;
6
- import java .util .Objects ;
7
- import java .util .Optional ;
8
-
9
4
import edu .kit .kastel .sdq .artemis4j .ArtemisClientException ;
10
5
import edu .kit .kastel .sdq .artemis4j .ArtemisNetworkException ;
11
- import edu .kit .kastel .sdq .artemis4j .client .AssessmentType ;
12
6
import edu .kit .kastel .sdq .artemis4j .client .ProgrammingSubmissionDTO ;
13
7
import edu .kit .kastel .sdq .artemis4j .client .ResultDTO ;
14
8
import edu .kit .kastel .sdq .artemis4j .grading .metajson .AnnotationMappingException ;
15
9
import edu .kit .kastel .sdq .artemis4j .grading .penalty .GradingConfig ;
16
10
11
+ import java .nio .file .Path ;
12
+ import java .time .ZonedDateTime ;
13
+ import java .util .Objects ;
14
+ import java .util .Optional ;
15
+
17
16
/**
18
17
* A student's programming submission. A submission essentially consists of the
19
18
* URL of a student's Git repository, along with a commit hash. We do not model
22
21
public class ProgrammingSubmission extends ArtemisConnectionHolder {
23
22
private final ProgrammingSubmissionDTO dto ;
24
23
25
- private final CorrectionRound correctionRound ;
26
24
private final User student ;
27
25
private final ProgrammingExercise exercise ;
28
26
29
27
public ProgrammingSubmission (
30
- ProgrammingSubmissionDTO dto , ProgrammingExercise exercise , CorrectionRound correctionRound ) {
28
+ ProgrammingSubmissionDTO dto , ProgrammingExercise exercise ) {
31
29
super (exercise );
32
30
33
31
this .dto = dto ;
@@ -40,8 +38,6 @@ public ProgrammingSubmission(
40
38
} else {
41
39
this .student = null ;
42
40
}
43
-
44
- this .correctionRound = correctionRound ;
45
41
}
46
42
47
43
public long getId () {
@@ -79,10 +75,6 @@ public ProgrammingExercise getExercise() {
79
75
return exercise ;
80
76
}
81
77
82
- public CorrectionRound getCorrectionRound () {
83
- return this .correctionRound ;
84
- }
85
-
86
78
public ZonedDateTime getSubmissionDate () {
87
79
return this .dto .submissionDate ();
88
80
}
@@ -95,17 +87,6 @@ public Optional<ResultDTO> getLatestResult() {
95
87
}
96
88
}
97
89
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
-
109
90
/**
110
91
* Clones the submission, including the test repository, into the given path,
111
92
* 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
131
112
}
132
113
133
114
/**
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.
135
118
*
136
119
* @return An empty optional if a *different* user has already locked the
137
120
* submission, otherwise the assessment
@@ -144,46 +127,21 @@ public ClonedProgrammingSubmission cloneViaSSHInto(Path target) throws ArtemisCl
144
127
* corresponding student (i.e.
145
128
* participation)
146
129
*/
147
- public Optional <Assessment > tryLock (GradingConfig gradingConfig )
130
+ public Optional <Assessment > tryLock (GradingConfig gradingConfig , CorrectionRound correctionRound )
148
131
throws AnnotationMappingException , ArtemisNetworkException , MoreRecentSubmissionException {
149
- return this .exercise .tryLockSubmission (this .getId (), this . getCorrectionRound () , gradingConfig );
132
+ return this .exercise .tryLockSubmission (this .getId (), correctionRound , gradingConfig );
150
133
}
151
134
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 ();
160
137
}
161
138
162
139
/**
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
173
142
*/
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 ;
187
145
}
188
146
189
147
@ Override
@@ -198,30 +156,4 @@ public boolean equals(Object o) {
198
156
public int hashCode () {
199
157
return Objects .hashCode (this .getId ());
200
158
}
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
- }
227
159
}
0 commit comments