@@ -127,36 +127,6 @@ class Extractions @Inject()(
127127 }
128128 }
129129
130- /**
131- *
132- * Given a file id (UUID), submit this file for extraction
133- */
134- def submitExtraction (id : UUID ) = PermissionAction (Permission .ViewFile , Some (ResourceRef (ResourceRef .file, id)))(parse.json) { implicit request =>
135- if (UUID .isValid(id.stringify)) {
136- files.get(id) match {
137- case Some (file) => {
138- // FIXME dataset not available?
139- routing.fileCreated(file, None , Utils .baseUrl(request).toString, request.apiKey) match {
140- case Some (jobId) => {
141- Ok (Json .obj(" status" -> " OK" , " job_id" -> jobId))
142- }
143- case None => {
144- val message = " No jobId found for Extraction"
145- Logger .error(message)
146- InternalServerError (toJson(Map (" status" -> " KO" , " message" -> message)))
147- }
148- }
149- }
150- case None => {
151- Logger .error(" Could not retrieve file that was just saved." )
152- InternalServerError (" Error uploading file" )
153- }
154- } // file match
155- } else {
156- BadRequest (" Not valid id" )
157- }
158- }
159-
160130 /**
161131 * For a given file id, checks for the status of all extractors processing that file.
162132 * REST endpoint GET /api/extractions/:id/status
@@ -404,24 +374,24 @@ class Extractions @Inject()(
404374 Ok (jarr)
405375 }
406376
407- def listExtractors (categories : List [String ]) = AuthenticatedAction { implicit request =>
408- Ok (Json .toJson(extractors.listExtractorsInfo(categories)))
377+ def listExtractors (categories : List [String ], space : Option [UUID ]) = AuthenticatedAction { implicit request =>
378+ val userid = request.user.map(u => Some (u.id)).getOrElse(None )
379+ Ok (Json .toJson(extractors.listExtractorsInfo(categories, userid)))
409380 }
410381
411- def getExtractorInfo (extractorName : String ) = AuthenticatedAction { implicit request =>
412- extractors.getExtractorInfo(extractorName) match {
382+ def getExtractorInfo (extractorName : String , extractor_key : Option [ String ] ) = AuthenticatedAction { implicit request =>
383+ extractors.getExtractorInfo(extractorName, extractor_key, request.user ) match {
413384 case Some (info) => Ok (Json .toJson(info))
414385 case None => NotFound (Json .obj(" status" -> " KO" , " message" -> " Extractor info not found" ))
415386 }
416387 }
417388
418- def deleteExtractor (extractorName : String ) = ServerAdminAction { implicit request =>
419- extractors.deleteExtractor(extractorName)
389+ def deleteExtractor (extractorName : String , extractor_key : Option [ String ] ) = ServerAdminAction { implicit request =>
390+ extractors.deleteExtractor(extractorName, extractor_key )
420391 Ok (toJson(Map (" status" -> " success" )))
421392 }
422393
423- def addExtractorInfo () = AuthenticatedAction (parse.json) { implicit request =>
424-
394+ def addExtractorInfo (extractor_key : Option [String ], user : Option [String ]) = AuthenticatedAction (parse.json) { implicit request =>
425395 // If repository is of type object, change it into an array.
426396 // This is for backward compatibility with requests from existing extractors.
427397 var requestJson = request.body \ " repository" match {
@@ -438,34 +408,66 @@ class Extractions @Inject()(
438408 BadRequest (Json .obj(" status" -> " KO" , " message" -> JsError .toFlatJson(errors)))
439409 },
440410 info => {
441- extractors.updateExtractorInfo(info) match {
442- case Some (u) => {
443- // Create/assign any default labels for this extractor
444- u.defaultLabels.foreach(labelStr => {
445- val segments = labelStr.split(" /" )
446- val (labelName, labelCategory) = if (segments.length > 1 ) {
447- (segments(1 ), segments(0 ))
448- } else {
449- (segments(0 ), " Other" )
411+ // Check private extractor flags
412+ val submissionInfo : Option [ExtractorInfo ] = extractor_key match {
413+ case Some (ek) => {
414+ user match {
415+ case None => {
416+ Logger .error(" Extractors with a private key must also specify a user email." )
417+ None
450418 }
451- extractors.getExtractorsLabel(labelName) match {
452- case None => {
453- // Label does not exist - create and assign it
454- val createdLabel = extractors.createExtractorsLabel(labelName, Some (labelCategory), List [String ](u.name))
455- }
456- case Some (lbl) => {
457- // Label already exists, assign it
458- if (! lbl.extractors.contains(u.name)) {
459- val label = ExtractorsLabel (lbl.id, lbl.name, lbl.category, lbl.extractors ++ List [String ](u.name))
460- val updatedLabel = extractors.updateExtractorsLabel(label)
419+ case Some (userEmail) => {
420+ userservice.findByEmail(userEmail) match {
421+ case Some (u) => {
422+ val perms = List (new ResourceRef (' user , u.id))
423+ Some (info.copy(unique_key= Some (ek), permissions= perms))
424+ }
425+ case None => {
426+ Logger .error(" No user found with email " + userEmail)
427+ None
461428 }
462429 }
463430 }
464- })
431+ }
432+ }
433+ case None => Some (info)
434+ }
435+
436+ // TODO: Check user permissions if the extractor_key has already been registered
437+
438+ submissionInfo match {
439+ case None => BadRequest (" Extractors with a private key must also specify a non-anonymous user." )
440+ case Some (subInfo) => {
441+ extractors.updateExtractorInfo(subInfo) match {
442+ case Some (u) => {
443+ // Create/assign any default labels for this extractor
444+ u.defaultLabels.foreach(labelStr => {
445+ val segments = labelStr.split(" /" )
446+ val (labelName, labelCategory) = if (segments.length > 1 ) {
447+ (segments(1 ), segments(0 ))
448+ } else {
449+ (segments(0 ), " Other" )
450+ }
451+ extractors.getExtractorsLabel(labelName) match {
452+ case None => {
453+ // Label does not exist - create and assign it
454+ val createdLabel = extractors.createExtractorsLabel(labelName, Some (labelCategory), List [String ](u.name))
455+ }
456+ case Some (lbl) => {
457+ // Label already exists, assign it
458+ if (! lbl.extractors.contains(u.name)) {
459+ val label = ExtractorsLabel (lbl.id, lbl.name, lbl.category, lbl.extractors ++ List [String ](u.name))
460+ val updatedLabel = extractors.updateExtractorsLabel(label)
461+ }
462+ }
463+ }
464+ })
465465
466- Ok (Json .obj(" status" -> " OK" , " message" -> (" Extractor info updated. ID = " + u.id)))
466+ Ok (Json .obj(" status" -> " OK" , " message" -> (" Extractor info updated. ID = " + u.id)))
467+ }
468+ case None => BadRequest (Json .obj(" status" -> " KO" , " message" -> " Error updating extractor info" ))
469+ }
467470 }
468- case None => BadRequest (Json .obj(" status" -> " KO" , " message" -> " Error updating extractor info" ))
469471 }
470472 }
471473 )
@@ -518,11 +520,14 @@ class Extractions @Inject()(
518520 }
519521 // if extractor_id is not specified default to execution of all extractors matching mime type
520522 (request.body \ " extractor" ).asOpt[String ] match {
521- case Some (extractorId) =>
523+ case Some (extractorId) => {
524+ val extractorKey = (request.body \ " extractor" ).asOpt[String ]
525+ extractors.getExtractorInfo(extractorId, extractorKey, request.user)
522526 val job_id = routing.submitFileManually(new UUID (originalId), file, Utils .baseUrl(request), extractorId, extra,
523527 datasetId, newFlags, request.apiKey, request.user)
524528 sink.logSubmitFileToExtractorEvent(file, extractorId, request.user)
525529 Ok (Json .obj(" status" -> " OK" , " job_id" -> job_id))
530+ }
526531 case None => {
527532 routing.fileCreated(file, None , Utils .baseUrl(request).toString, request.apiKey) match {
528533 case Some (job_id) => {
0 commit comments