diff --git a/webapi/src/main/scala/org/knora/webapi/messages/util/search/QueryTraverser.scala b/webapi/src/main/scala/org/knora/webapi/messages/util/search/QueryTraverser.scala index ea3b66ed8e..731619d18b 100644 --- a/webapi/src/main/scala/org/knora/webapi/messages/util/search/QueryTraverser.scala +++ b/webapi/src/main/scala/org/knora/webapi/messages/util/search/QueryTraverser.scala @@ -216,37 +216,41 @@ object QueryTraverser { * @param appActor a reference to the appActor to retrieve a [[ProjectADM]] by a shortcode. * @return a sequence of ontology IRIs which relate to the input RDF entity. */ - private def resolveEntity(entity: Entity, map: Map[SmartIri, SmartIri], appActor: ActorRef): Seq[SmartIri] = + private def resolveEntity(entity: Entity, map: Map[SmartIri, SmartIri], appActor: ActorRef)(implicit + ec: ExecutionContext + ): Future[Seq[SmartIri]] = entity match { case IriRef(iri, _) => { val internal = iri.toOntologySchema(InternalSchema) val maybeOntoIri = map.get(internal) maybeOntoIri match { // if the map contains an ontology IRI corresponding to the entity IRI, then this can be returned - case Some(iri) => Seq(iri) + case Some(iri) => Future(Seq(iri)) case None => { // if the map doesn't contain a corresponding ontology IRI, then the entity IRI points to a resource or value // in that case, all ontologies of the project, to which the entity belongs, should be returned. val shortcode = internal.getProjectCode shortcode match { - case None => Seq.empty - case _ => { + case None => Future(Seq.empty) + case Some(_) => { // find the project with the shortcode - val projectFuture = appActor - .ask(ProjectGetADM(ProjectIdentifierADM(maybeShortcode = shortcode))) - .mapTo[Option[ProjectADM]] - val projectMaybe = Await.result(projectFuture, 1.second) - projectMaybe match { - case None => Seq.empty - // return all ontologies of the project - case Some(project) => project.ontologies.map(_.toSmartIri) - } + + for { + projectMaybe <- appActor + .ask(ProjectGetADM(ProjectIdentifierADM(maybeShortcode = shortcode))) + .mapTo[Option[ProjectADM]] + projectOntologies = projectMaybe match { + case None => Seq.empty + // return all ontologies of the project + case Some(project) => project.ontologies.map(_.toSmartIri) + } + } yield projectOntologies } } } } } - case _ => Seq.empty + case _ => Future(Seq.empty) } /** @@ -286,9 +290,11 @@ object QueryTraverser { // from the cache, get the map from entity to the ontology where the entity is defined entityMap = ontoCache.entityDefinedInOntology // resolve all entities from the WHERE clause to the ontology where they are defined - relevantOntologies = entities.flatMap(resolveEntity(_, entityMap, storeManager)).toSet + relevantOntologies <- + Future.sequence(entities.map(resolveEntity(_, entityMap, storeManager)(executionContext))) + relevantOntologiesSet = relevantOntologies.flatten.toSet relevantOntologiesMaybe = - relevantOntologies match { + relevantOntologiesSet match { case Nil => None // if nothing was found, then None should be returned case ontologies => // if only knora-base was found, then None should be returned too diff --git a/webapi/src/main/scala/org/knora/webapi/responders/admin/ProjectsResponderADM.scala b/webapi/src/main/scala/org/knora/webapi/responders/admin/ProjectsResponderADM.scala index e7a786e75b..ab04303a98 100644 --- a/webapi/src/main/scala/org/knora/webapi/responders/admin/ProjectsResponderADM.scala +++ b/webapi/src/main/scala/org/knora/webapi/responders/admin/ProjectsResponderADM.scala @@ -208,16 +208,14 @@ class ProjectsResponderADM(responderData: ResponderData) extends Responder(respo * * @param identifier the IRI, shortname, or shortcode of the project. * @param skipCache if `true`, doesn't check the cache and tries to retrieve the project directly from the triplestore - * @return information about the project as a [[ProjectInfoV1]]. + * @return information about the project as an optional [[ProjectADM]]. */ - private def getSingleProjectADM( + def getSingleProjectADM( identifier: ProjectIdentifierADM, skipCache: Boolean = false ): Future[Option[ProjectADM]] = tracedFuture("admin-get-project") { - // log.debug("getSingleProjectADM - projectIRI: {}", projectIri) - log.debug( s"getSingleProjectADM - id: {}, skipCache: {}", identifier.value, @@ -251,16 +249,14 @@ class ProjectsResponderADM(responderData: ResponderData) extends Responder(respo * as a [[ProjectGetResponseADM]]. * * @param identifier the IRI, shortname, or shortcode of the project. - * * @param requestingUser the user making the request. - * @return information about the project as a [[ProjectInfoResponseV1]]. + * @return information about the project as a [[ProjectGetResponseADM]]. * @throws NotFoundException when no project for the given IRI can be found */ private def getSingleProjectADMRequest( identifier: ProjectIdentifierADM, requestingUser: UserADM ): Future[ProjectGetResponseADM] = - // log.debug("getSingleProjectADMRequest - maybeIri: {}, maybeShortname: {}, maybeShortcode: {}", maybeIri, maybeShortname, maybeShortcode) for { maybeProject: Option[ProjectADM] <- getSingleProjectADM( identifier = identifier