34
34
import javax .net .ssl .SSLSession ;
35
35
import javax .net .ssl .TrustManagerFactory ;
36
36
import javax .swing .event .EventListenerList ;
37
+ import javax .transaction .Transactional ;
37
38
import javax .validation .Valid ;
38
39
import javax .validation .constraints .Min ;
39
40
import javax .validation .constraints .Pattern ;
48
49
import org .openeo .spring .bearer .ITokenService ;
49
50
import org .openeo .spring .bearer .TokenUtil ;
50
51
import org .openeo .spring .components .JobScheduler ;
52
+ import org .openeo .spring .dao .BatchJobResultCollectionDAO ;
51
53
import org .openeo .spring .dao .BatchJobResultDAO ;
54
+ import org .openeo .spring .dao .BatchJobResultFeatureDAO ;
52
55
import org .openeo .spring .dao .JobDAO ;
53
56
import org .openeo .spring .keycloak .legacy .AuthzService ;
54
57
import org .openeo .spring .model .BatchJobEstimate ;
@@ -159,18 +162,22 @@ public class JobsApiController implements JobsApi {
159
162
160
163
JobDAO jobDAO ;
161
164
162
- BatchJobResultDAO resultDAO ;
165
+ BatchJobResultDAO <? extends BatchJobResult > resultDAO ;
163
166
164
167
@ Autowired
165
- public void setDao (JobDAO injectedJObDAO , BatchJobResultDAO injectResultDao ) {
166
- jobDAO = injectedJObDAO ;
167
- resultDAO = injectResultDao ;
168
+ public void setDaoFeature (JobDAO injectedJObDAO , BatchJobResultFeatureDAO injectResultDao ) {
169
+ jobDAO = injectedJObDAO ;
170
+ resultDAO = injectResultDao ;
168
171
}
169
-
172
+ @ Autowired
173
+ public void setDaoCollection (JobDAO injectedJObDAO , BatchJobResultCollectionDAO injectResultDao ) {
174
+ jobDAO = injectedJObDAO ;
175
+ resultDAO = injectResultDao ;
176
+ }
177
+
170
178
@ org .springframework .beans .factory .annotation .Autowired
171
179
public JobsApiController (NativeWebRequest request ) {
172
180
this .request = request ;
173
-
174
181
}
175
182
176
183
@ PostConstruct
@@ -236,7 +243,9 @@ public ResponseEntity<?> createJob(@Parameter(description = "", required = true)
236
243
237
244
//TODO add validity check of the job using ValidationApiController
238
245
// UUID jobID = UUID.randomUUID();
239
- // job.setId(jobID);
246
+ // job.setId(jobID.toString());
247
+ // job.setId("06959adcd2a447c58c74374993a3eee9"); TEST
248
+ // -> Job::@Generated will generate one
240
249
241
250
ResponseEntity <?> response = null ;
242
251
String warningMessage = null ;
@@ -668,7 +677,7 @@ public ResponseEntity<?> deleteJob(
668
677
@ Pattern (regexp = "^[\\ w\\ -\\ .~]+$" ) @ Parameter (description = "Unique job identifier." , required = true ) @ PathVariable ("job_id" ) String jobId ) {
669
678
Job job = jobDAO .findOne (UUID .fromString (jobId ));
670
679
if (job != null ) {
671
- BatchJobResult jobResult = resultDAO .findOne (UUID . fromString ( jobId ) );
680
+ BatchJobResult jobResult = resultDAO .findOne (jobId );
672
681
if (jobResult != null ) {
673
682
log .debug ("The job result {} was detected." , jobId );
674
683
File jobResults = new File (tmpDir + jobId );
@@ -681,7 +690,7 @@ public ResponseEntity<?> deleteJob(
681
690
jobResults .delete ();
682
691
log .debug ("All persistent files have been successfully deleted for job with id: " + jobId );
683
692
}
684
- resultDAO .delete (jobResult );
693
+ resultDAO .deleteById (jobResult . getId () );
685
694
log .debug ("The job result {} was successfully deleted." , jobId );
686
695
}
687
696
jobDAO .delete (job );
@@ -956,15 +965,16 @@ public ResponseEntity<?> listJobs(
956
965
@ ApiResponse (responseCode = "500" , description = "The request can't be fulfilled due to an error at the back-end. The error is never the client’s fault and therefore it is reasonable for the client to retry the exact same request that triggered this response. The response body SHOULD contain a JSON error object. MUST be any HTTP status code specified in [RFC 7231](https://tools.ietf.org/html/rfc7231#section-6.6). See also: * [Error Handling](#section/API-Principles/Error-Handling) in the API in general. * [Common Error Codes](errors.json)" ) })
957
966
@ RequestMapping (value = "/jobs/{job_id}/results" , produces = { "application/json" ,
958
967
"application/geo+json" }, method = RequestMethod .GET )
968
+ @ Transactional
959
969
public ResponseEntity <?> listResults (
960
970
@ Pattern (regexp = "^[\\ w\\ -\\ .~]+$" ) @ Parameter (description = "Unique job identifier." , required = true ) @ PathVariable ("job_id" ) String jobId ) {
961
- BatchJobResult result = resultDAO .findOne (UUID . fromString ( jobId ) );
971
+ BatchJobResult result = resultDAO .findOne (jobId );
962
972
if (result != null ) {
963
- log .trace (result .toString ());
973
+ log .debug (result .toString ());
964
974
return new ResponseEntity <BatchJobResult >(result , HttpStatus .OK );
965
975
} else {
966
976
ResponseEntity <Error > response = ApiUtil .errorResponse (HttpStatus .BAD_REQUEST ,
967
- String .format ("The requested job %s could not be found." , jobId ));
977
+ String .format ("The result for job %s could not be found." , jobId ));
968
978
return response ;
969
979
}
970
980
}
@@ -1149,7 +1159,8 @@ public ResponseEntity<?> startJob(
1149
1159
public ResponseEntity <?> stopJob (
1150
1160
@ Pattern (regexp = "^[\\ w\\ -\\ .~]+$" ) @ Parameter (description = "Unique job identifier." , required = true ) @ PathVariable ("job_id" ) String jobId ) {
1151
1161
ThreadContext .put ("jobid" , jobId );
1152
- Job job = jobDAO .findOne (UUID .fromString (jobId ));
1162
+ UUID jobUUID = UUID .fromString (jobId );
1163
+ Job job = jobDAO .findOne (jobUUID );
1153
1164
if (job != null ) {
1154
1165
if (job .getEngine ()==EngineTypes .WCPS ){
1155
1166
ResponseEntity <Error > response = ApiUtil .errorResponse (HttpStatus .NOT_IMPLEMENTED ,
@@ -1162,15 +1173,15 @@ else if(job.getEngine()==EngineTypes.ODC_DASK) {
1162
1173
job .setStatus (JobStates .CANCELED );
1163
1174
job .setUpdated (OffsetDateTime .now ());
1164
1175
jobDAO .update (job );
1165
- this .fireJobStoppedEvent (job . getId () );
1176
+ this .fireJobStoppedEvent (jobUUID );
1166
1177
ThreadContext .clearMap ();
1167
1178
return ResponseEntity .status (HttpStatus .NO_CONTENT ).build ();
1168
1179
}
1169
1180
else if (job .getStatus ()==JobStates .QUEUED ) {
1170
1181
job .setStatus (JobStates .CREATED );
1171
1182
job .setUpdated (OffsetDateTime .now ());
1172
1183
jobDAO .update (job );
1173
- this .fireJobStoppedEvent (job . getId () );
1184
+ this .fireJobStoppedEvent (jobUUID );
1174
1185
ThreadContext .clearMap ();
1175
1186
return ResponseEntity .status (HttpStatus .NO_CONTENT ).build ();
1176
1187
}
0 commit comments