-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GAWB-849: ga4gh api for agora. (#218)
* ga4gh APIs
- Loading branch information
Showing
11 changed files
with
1,300 additions
and
131 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
86 changes: 86 additions & 0 deletions
86
src/main/scala/org/broadinstitute/dsde/agora/server/ga4gh/Ga4ghQueryHandler.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
package org.broadinstitute.dsde.agora.server.ga4gh | ||
|
||
import akka.pattern.pipe | ||
import org.broadinstitute.dsde.agora.server.dataaccess.permissions.{AccessControl, PermissionsDataSource} | ||
import org.broadinstitute.dsde.agora.server.exceptions.ValidationException | ||
import org.broadinstitute.dsde.agora.server.ga4gh.Ga4ghServiceMessages._ | ||
import org.broadinstitute.dsde.agora.server.ga4gh.Models._ | ||
import org.broadinstitute.dsde.agora.server.model.{AgoraEntity, AgoraEntityType} | ||
import org.broadinstitute.dsde.agora.server.webservice.PerRequest.{PerRequestMessage, RequestComplete} | ||
import org.broadinstitute.dsde.agora.server.webservice.handlers.QueryHandler | ||
import spray.httpx.SprayJsonSupport._ | ||
import spray.json.DefaultJsonProtocol._ | ||
import spray.routing.RequestContext | ||
|
||
import scala.concurrent.{ExecutionContext, Future} | ||
|
||
class Ga4ghQueryHandler(dataSource: PermissionsDataSource, override implicit val ec: ExecutionContext) | ||
extends QueryHandler(dataSource, ec) { | ||
|
||
override def receive: akka.actor.Actor.Receive = { | ||
case QueryPublicSingle(requestContext: RequestContext, entity: AgoraEntity) => | ||
queryPublicSingle(requestContext, entity) pipeTo context.parent | ||
|
||
case QueryPublicSinglePayload(requestContext: RequestContext, entity: AgoraEntity, descriptorType: ToolDescriptorType.DescriptorType) => | ||
queryPublicSinglePayload(requestContext, entity, descriptorType) pipeTo context.parent | ||
|
||
case QueryPublic(requestContext: RequestContext, agoraSearch: AgoraEntity) => | ||
queryPublic(requestContext, agoraSearch) pipeTo context.parent | ||
|
||
case QueryPublicTool(requestContext: RequestContext, agoraSearch: AgoraEntity) => | ||
queryPublicTool(requestContext, agoraSearch) pipeTo context.parent | ||
|
||
case QueryPublicTools(requestContext: RequestContext) => | ||
queryPublicTools(requestContext) pipeTo context.parent | ||
|
||
|
||
} | ||
|
||
def queryPublicSingle(requestContext: RequestContext, entity: AgoraEntity): Future[PerRequestMessage] = { | ||
val entityTypes = Seq(entity.entityType.getOrElse(throw ValidationException("need an entity type"))) | ||
agoraBusiness.findSingle(entity, entityTypes, AccessControl.publicUser) map { foundEntity => | ||
RequestComplete(ToolVersion(foundEntity)) | ||
} | ||
} | ||
|
||
def queryPublicSinglePayload(requestContext: RequestContext, entity: AgoraEntity, descriptorType: ToolDescriptorType.DescriptorType): Future[PerRequestMessage] = { | ||
val entityTypes = Seq(entity.entityType.getOrElse(throw ValidationException("need an entity type"))) | ||
agoraBusiness.findSingle(entity, entityTypes, AccessControl.publicUser) map { foundEntity => | ||
descriptorType match { | ||
case ToolDescriptorType.WDL => | ||
// the url we return here is known to be incorrect in FireCloud (GAWB-1741). | ||
// we return it anyway because it still provides some information, even if it | ||
// requires manual user intervention to work. | ||
val result = ToolDescriptor(foundEntity.url.getOrElse(""), | ||
foundEntity.payload.getOrElse(""), | ||
ToolDescriptorType.WDL) | ||
RequestComplete(result) | ||
case ToolDescriptorType.PLAIN_WDL => | ||
RequestComplete(foundEntity.payload.getOrElse("")) | ||
} | ||
} | ||
} | ||
|
||
def queryPublic(requestContext: RequestContext, | ||
agoraSearch: AgoraEntity): Future[PerRequestMessage] = { | ||
agoraBusiness.find(agoraSearch, None, Seq(AgoraEntityType.Workflow), AccessControl.publicUser) map { entities => | ||
val toolVersions = entities map ToolVersion.apply | ||
RequestComplete(toolVersions) | ||
} | ||
} | ||
|
||
def queryPublicTool(requestContext: RequestContext, | ||
agoraSearch: AgoraEntity): Future[PerRequestMessage] = { | ||
agoraBusiness.find(agoraSearch, None, Seq(AgoraEntityType.Workflow), AccessControl.publicUser) map { entities => | ||
RequestComplete(Tool(entities)) | ||
} | ||
} | ||
|
||
def queryPublicTools(requestContext: RequestContext): Future[PerRequestMessage] = { | ||
agoraBusiness.find(AgoraEntity(), None, Seq(AgoraEntityType.Workflow), AccessControl.publicUser) map { allentities => | ||
val groupedSnapshots = allentities.groupBy( ae => (ae.namespace,ae.name)) | ||
val tools:Seq[Tool] = (groupedSnapshots.values map { entities => Tool(entities )}).toSeq | ||
RequestComplete(tools.sortBy(_.id)) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
src/main/scala/org/broadinstitute/dsde/agora/server/ga4gh/Ga4ghServiceMessages.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package org.broadinstitute.dsde.agora.server.ga4gh | ||
|
||
import org.broadinstitute.dsde.agora.server.ga4gh.Models.ToolDescriptorType.DescriptorType | ||
import org.broadinstitute.dsde.agora.server.model.AgoraEntity | ||
import spray.routing.RequestContext | ||
|
||
object Ga4ghServiceMessages { | ||
|
||
case class QueryPublicSingle(requestContext: RequestContext, | ||
entity: AgoraEntity) | ||
|
||
case class QueryPublicSinglePayload(requestContext: RequestContext, | ||
entity: AgoraEntity, | ||
descriptorType: DescriptorType) | ||
|
||
case class QueryPublic(requestContext: RequestContext, | ||
agoraSearch: AgoraEntity) | ||
|
||
case class QueryPublicTool(requestContext: RequestContext, | ||
agoraSearch: AgoraEntity) | ||
|
||
case class QueryPublicTools(requestContext: RequestContext) | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.