Skip to content

Commit 26a4879

Browse files
authored
Merge branch 'develop' into clean_extractors_tmpfiles
2 parents 42d97f7 + 5e2d296 commit 26a4879

File tree

8 files changed

+224
-115
lines changed

8 files changed

+224
-115
lines changed

app/api/Extractions.scala

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import play.api.libs.concurrent.Execution.Implicits._
1616
import play.api.libs.json.Json._
1717
import play.api.libs.json._
1818
import play.api.libs.ws.{Response, WS}
19+
import play.api.libs.functional.syntax._
1920
import play.api.mvc.MultipartFormData
2021
import 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
}

app/models/Extraction.scala

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@ import play.api.libs.functional.syntax._
1212
case class Extraction(
1313
id: UUID = UUID.generate,
1414
file_id: UUID,
15+
job_id: Option[UUID],
1516
extractor_id: String,
1617
status: String = "N/A",
17-
start: Option[Date],
18+
start: Date,
1819
end: Option[Date])
1920

2021
/**
@@ -169,9 +170,10 @@ case class ExtractorProcessTriggers(dataset: List[String] = List.empty,
169170
file: List[String] = List.empty,
170171
metadata: List[String] = List.empty)
171172

173+
172174
case class ExtractionGroup(
173175
firstMsgTime: String,
174176
latestMsgTime: String,
175177
latestMsg: String,
176-
allMsgs: List[Extraction]
178+
allMsgs: Map[UUID, List[Extraction]]
177179
)

app/services/ExtractionService.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ trait ExtractionService {
1616

1717
def findAll(max: Int = 100): List[Extraction]
1818

19+
def get(msgId: UUID): Option[Extraction]
20+
1921
def findById(resource: ResourceRef): List[Extraction]
2022

2123
def insert(extraction: Extraction): Option[ObjectId]

0 commit comments

Comments
 (0)