3434import javax .net .ssl .SSLSession ;
3535import javax .net .ssl .TrustManagerFactory ;
3636import javax .swing .event .EventListenerList ;
37+ import javax .transaction .Transactional ;
3738import javax .validation .Valid ;
3839import javax .validation .constraints .Min ;
3940import javax .validation .constraints .Pattern ;
4849import org .openeo .spring .bearer .ITokenService ;
4950import org .openeo .spring .bearer .TokenUtil ;
5051import org .openeo .spring .components .JobScheduler ;
52+ import org .openeo .spring .dao .BatchJobResultCollectionDAO ;
5153import org .openeo .spring .dao .BatchJobResultDAO ;
54+ import org .openeo .spring .dao .BatchJobResultFeatureDAO ;
5255import org .openeo .spring .dao .JobDAO ;
5356import org .openeo .spring .keycloak .legacy .AuthzService ;
5457import org .openeo .spring .model .BatchJobEstimate ;
@@ -159,18 +162,22 @@ public class JobsApiController implements JobsApi {
159162
160163 JobDAO jobDAO ;
161164
162- BatchJobResultDAO resultDAO ;
165+ BatchJobResultDAO <? extends BatchJobResult > resultDAO ;
163166
164167 @ 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 ;
168171 }
169-
172+ @ Autowired
173+ public void setDaoCollection (JobDAO injectedJObDAO , BatchJobResultCollectionDAO injectResultDao ) {
174+ jobDAO = injectedJObDAO ;
175+ resultDAO = injectResultDao ;
176+ }
177+
170178 @ org .springframework .beans .factory .annotation .Autowired
171179 public JobsApiController (NativeWebRequest request ) {
172180 this .request = request ;
173-
174181 }
175182
176183 @ PostConstruct
@@ -236,7 +243,9 @@ public ResponseEntity<?> createJob(@Parameter(description = "", required = true)
236243
237244 //TODO add validity check of the job using ValidationApiController
238245// UUID jobID = UUID.randomUUID();
239- // job.setId(jobID);
246+ // job.setId(jobID.toString());
247+ // job.setId("06959adcd2a447c58c74374993a3eee9"); TEST
248+ // -> Job::@Generated will generate one
240249
241250 ResponseEntity <?> response = null ;
242251 String warningMessage = null ;
@@ -668,7 +677,7 @@ public ResponseEntity<?> deleteJob(
668677 @ Pattern (regexp = "^[\\ w\\ -\\ .~]+$" ) @ Parameter (description = "Unique job identifier." , required = true ) @ PathVariable ("job_id" ) String jobId ) {
669678 Job job = jobDAO .findOne (UUID .fromString (jobId ));
670679 if (job != null ) {
671- BatchJobResult jobResult = resultDAO .findOne (UUID . fromString ( jobId ) );
680+ BatchJobResult jobResult = resultDAO .findOne (jobId );
672681 if (jobResult != null ) {
673682 log .debug ("The job result {} was detected." , jobId );
674683 File jobResults = new File (tmpDir + jobId );
@@ -681,7 +690,7 @@ public ResponseEntity<?> deleteJob(
681690 jobResults .delete ();
682691 log .debug ("All persistent files have been successfully deleted for job with id: " + jobId );
683692 }
684- resultDAO .delete (jobResult );
693+ resultDAO .deleteById (jobResult . getId () );
685694 log .debug ("The job result {} was successfully deleted." , jobId );
686695 }
687696 jobDAO .delete (job );
@@ -956,15 +965,16 @@ public ResponseEntity<?> listJobs(
956965 @ 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)" ) })
957966 @ RequestMapping (value = "/jobs/{job_id}/results" , produces = { "application/json" ,
958967 "application/geo+json" }, method = RequestMethod .GET )
968+ @ Transactional
959969 public ResponseEntity <?> listResults (
960970 @ 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 );
962972 if (result != null ) {
963- log .trace (result .toString ());
973+ log .debug (result .toString ());
964974 return new ResponseEntity <BatchJobResult >(result , HttpStatus .OK );
965975 } else {
966976 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 ));
968978 return response ;
969979 }
970980 }
@@ -1149,7 +1159,8 @@ public ResponseEntity<?> startJob(
11491159 public ResponseEntity <?> stopJob (
11501160 @ Pattern (regexp = "^[\\ w\\ -\\ .~]+$" ) @ Parameter (description = "Unique job identifier." , required = true ) @ PathVariable ("job_id" ) String jobId ) {
11511161 ThreadContext .put ("jobid" , jobId );
1152- Job job = jobDAO .findOne (UUID .fromString (jobId ));
1162+ UUID jobUUID = UUID .fromString (jobId );
1163+ Job job = jobDAO .findOne (jobUUID );
11531164 if (job != null ) {
11541165 if (job .getEngine ()==EngineTypes .WCPS ){
11551166 ResponseEntity <Error > response = ApiUtil .errorResponse (HttpStatus .NOT_IMPLEMENTED ,
@@ -1162,15 +1173,15 @@ else if(job.getEngine()==EngineTypes.ODC_DASK) {
11621173 job .setStatus (JobStates .CANCELED );
11631174 job .setUpdated (OffsetDateTime .now ());
11641175 jobDAO .update (job );
1165- this .fireJobStoppedEvent (job . getId () );
1176+ this .fireJobStoppedEvent (jobUUID );
11661177 ThreadContext .clearMap ();
11671178 return ResponseEntity .status (HttpStatus .NO_CONTENT ).build ();
11681179 }
11691180 else if (job .getStatus ()==JobStates .QUEUED ) {
11701181 job .setStatus (JobStates .CREATED );
11711182 job .setUpdated (OffsetDateTime .now ());
11721183 jobDAO .update (job );
1173- this .fireJobStoppedEvent (job . getId () );
1184+ this .fireJobStoppedEvent (jobUUID );
11741185 ThreadContext .clearMap ();
11751186 return ResponseEntity .status (HttpStatus .NO_CONTENT ).build ();
11761187 }
0 commit comments