@@ -16,6 +16,7 @@ import play.api.libs.concurrent.Execution.Implicits._
1616import play .api .libs .json .Json ._
1717import play .api .libs .json ._
1818import play .api .libs .ws .{Response , WS }
19+ import play .api .libs .functional .syntax ._
1920import play .api .mvc .MultipartFormData
2021import services ._
2122
@@ -129,29 +130,31 @@ class Extractions @Inject()(
129130 }
130131
131132 /**
132- * *
133- * For DTS service use case: suppose a user posts a file to the extractions API, no extractors and its corresponding queues in the Rabbitmq are available. Now she checks the status
134- * for extractors, i.e., if any new extractor has subscribed to the Rabbitmq. If yes, she may again wants to submit the file for extraction again. Since she has already uploaded
135- * it, this time will just uses the file id to submit the request again.
136- * This API takes file id and notifies the user that the request has been sent for processing.
137- * This may change depending on our our design on DTS extraction service.
138133 *
134+ * Given a file id (UUID), submit this file for extraction
139135 */
140136 def submitExtraction (id : UUID ) = PermissionAction (Permission .ViewFile , Some (ResourceRef (ResourceRef .file, id)))(parse.json) { implicit request =>
141137 current.plugin[RabbitmqPlugin ] match {
142138 case Some (plugin) => {
143139 if (UUID .isValid(id.stringify)) {
144140 files.get(id) match {
145141 case Some (file) => {
146- current.plugin[RabbitmqPlugin ].foreach {
147- // FIXME dataset not available?
148- _.fileCreated(file, None , Utils .baseUrl(request), request.apiKey)
142+ // FIXME dataset not available?
143+ plugin.fileCreated(file, None , Utils .baseUrl(request), request.apiKey) match {
144+ case Some (jobId) => {
145+ Ok (Json .obj(" status" -> " OK" , " job_id" -> jobId))
146+ }
147+ case None => {
148+ val message = " No jobId found for Extraction"
149+ Logger .error(message)
150+ InternalServerError (toJson(Map (" status" -> " KO" , " message" -> message)))
151+ }
149152 }
150- Ok (" Sent for Extraction. check the status" )
151153 }
152- case None =>
154+ case None => {
153155 Logger .error(" Could not retrieve file that was just saved." )
154156 InternalServerError (" Error uploading file" )
157+ }
155158 } // file match
156159 } // if Object id
157160 else {
@@ -529,12 +532,20 @@ class Extractions @Inject()(
529532 // if extractor_id is not specified default to execution of all extractors matching mime type
530533 val key = (request.body \ " extractor" ).asOpt[String ] match {
531534 case Some (extractorId) =>
532- p.submitFileManually(new UUID (originalId), file, Utils .baseUrl(request), extractorId, extra,
535+ val job_id = p.submitFileManually(new UUID (originalId), file, Utils .baseUrl(request), extractorId, extra,
533536 datasetId, newFlags, request.apiKey, request.user)
537+ Ok (Json .obj(" status" -> " OK" , " job_id" -> job_id))
534538 case None =>
535- p.fileCreated(file, None , Utils .baseUrl(request), request.apiKey)
539+ p.fileCreated(file, None , Utils .baseUrl(request), request.apiKey) match {
540+ case Some (job_id) => {
541+ Ok (Json .obj(" status" -> " OK" , " job_id" -> job_id))
542+ }
543+ }
536544 }
537- Ok (Json .obj(" status" -> " OK" ))
545+
546+ val message = " No jobId found for Extraction on fileid=" + file_id.stringify
547+ Logger .error(message)
548+ InternalServerError (toJson(Map (" status" -> " KO" , " msg" -> message)))
538549 } else {
539550 Conflict (toJson(Map (" status" -> " error" , " msg" -> " File is not ready. Please wait and try again." )))
540551 }
@@ -570,8 +581,8 @@ class Extractions @Inject()(
570581 " parameters" -> parameters.toString,
571582 " action" -> " manual-submission" )
572583
573- p.submitDatasetManually(host, key, extra, ds_id, " " , request.apiKey, request.user)
574- Ok (Json .obj(" status" -> " OK" ))
584+ val job_id = p.submitDatasetManually(host, key, extra, ds_id, " " , request.apiKey, request.user)
585+ Ok (Json .obj(" status" -> " OK" , " job_id " -> job_id ))
575586 }
576587 case None =>
577588 BadRequest (toJson(Map (" request" -> " Dataset not found" )))
@@ -597,9 +608,10 @@ class Extractions @Inject()(
597608 // check that the file is ready for processing
598609 if (file.status.equals(models.FileStatus .PROCESSED .toString)) {
599610 (request.body \ " extractor" ).asOpt[String ] match {
600- case Some (extractorId) =>
611+ case Some (extractorId) => {
601612 p.cancelPendingSubmission(file_id, extractorId, msg_id)
602- Ok (Json .obj(" status" -> " OK" ))
613+ Ok (Json .obj(" status" -> " OK" ))
614+ }
603615 case None =>
604616 BadRequest (toJson(Map (" request" -> " extractor field not found" )))
605617 }
@@ -623,9 +635,10 @@ class Extractions @Inject()(
623635 datasets.get(ds_id) match {
624636 case Some (ds) => {
625637 (request.body \ " extractor" ).asOpt[String ] match {
626- case Some (extractorId) =>
638+ case Some (extractorId) => {
627639 p.cancelPendingSubmission(ds_id, extractorId, msg_id)
628640 Ok (Json .obj(" status" -> " OK" ))
641+ }
629642 case None => BadRequest (toJson(Map (" request" -> " extractor field not found" )))
630643 }
631644 }
0 commit comments