Skip to content

Commit

Permalink
refactor: Replace MessageRelay with KnoraProjectRepo in OntologyRespo…
Browse files Browse the repository at this point in the history
…nderV2 (#2920)
  • Loading branch information
seakayone committed Nov 8, 2023
1 parent 354662c commit b093357
Showing 1 changed file with 27 additions and 32 deletions.
Expand Up @@ -21,8 +21,6 @@ import org.knora.webapi.core.MessageHandler
import org.knora.webapi.core.MessageRelay
import org.knora.webapi.messages.IriConversions._
import org.knora.webapi.messages._
import org.knora.webapi.messages.admin.responder.projectsmessages.ProjectGetRequestADM
import org.knora.webapi.messages.admin.responder.projectsmessages.ProjectGetResponseADM
import org.knora.webapi.messages.admin.responder.projectsmessages.ProjectIdentifierADM._
import org.knora.webapi.messages.admin.responder.usersmessages.UserADM
import org.knora.webapi.messages.store.triplestoremessages.SmartIriLiteralV2
Expand All @@ -38,6 +36,7 @@ import org.knora.webapi.responders.IriService
import org.knora.webapi.responders.Responder
import org.knora.webapi.responders.v2.ontology.CardinalityHandler
import org.knora.webapi.responders.v2.ontology.OntologyHelpers
import org.knora.webapi.slice.admin.domain.service.KnoraProjectRepo
import org.knora.webapi.slice.ontology.domain.service.CardinalityService
import org.knora.webapi.slice.ontology.domain.service.OntologyRepo
import org.knora.webapi.slice.ontology.repo.service.OntologyCache
Expand Down Expand Up @@ -71,10 +70,10 @@ final case class OntologyResponderV2Live(
cardinalityHandler: CardinalityHandler,
cardinalityService: CardinalityService,
iriService: IriService,
messageRelay: MessageRelay,
ontologyCache: OntologyCache,
ontologyHelpers: OntologyHelpers,
ontologyRepo: OntologyRepo,
projectRepo: KnoraProjectRepo,
triplestoreService: TriplestoreService,
implicit val stringFormatter: StringFormatter
) extends OntologyResponderV2
Expand Down Expand Up @@ -526,14 +525,6 @@ final case class OntologyResponderV2Live(
ZIO.fail(ForbiddenException(msg))
}

// Get project info for the shortcode.
projectInfo <-
IriIdentifier
.fromString(projectIri.toString)
.toZIO
.mapError(e => BadRequestException(e.getMessage))
.flatMap(id => messageRelay.ask[ProjectGetResponseADM](ProjectGetRequestADM(identifier = id)))

// Check that the ontology name is valid.
validOntologyName <-
ZIO
Expand All @@ -543,10 +534,12 @@ final case class OntologyResponderV2Live(
)

// Make the internal ontology IRI.
projectId <- IriIdentifier.fromString(projectIri.toString).toZIO.mapError(e => BadRequestException(e.getMessage))
project <- projectRepo.findById(projectId).someOrFail(BadRequestException(s"Project not found: $projectIri"))
internalOntologyIri = stringFormatter.makeProjectSpecificInternalOntologyIri(
validOntologyName,
createOntologyRequest.isShared,
projectInfo.project.shortcode
project.shortcode.value
)

// Do the remaining pre-update checks and the update while holding a global ontology cache lock.
Expand Down Expand Up @@ -2957,30 +2950,32 @@ final case class OntologyResponderV2Live(

object OntologyResponderV2Live {
val layer: URLayer[
StringFormatter
with TriplestoreService
with OntologyRepo
with OntologyHelpers
with OntologyCache
with CardinalityService
AppConfig
with CardinalityHandler
with MessageRelay
with CardinalityService
with IriService
with AppConfig,
with KnoraProjectRepo
with MessageRelay
with OntologyCache
with OntologyHelpers
with OntologyRepo
with StringFormatter
with TriplestoreService,
OntologyResponderV2
] = ZLayer.fromZIO {
for {
config <- ZIO.service[AppConfig]
iriS <- ZIO.service[IriService]
mr <- ZIO.service[MessageRelay]
ch <- ZIO.service[CardinalityHandler]
cs <- ZIO.service[CardinalityService]
oc <- ZIO.service[OntologyCache]
oh <- ZIO.service[OntologyHelpers]
or <- ZIO.service[OntologyRepo]
ts <- ZIO.service[TriplestoreService]
sf <- ZIO.service[StringFormatter]
handler <- mr.subscribe(OntologyResponderV2Live(config, ch, cs, iriS, mr, oc, oh, or, ts, sf))
} yield handler
ac <- ZIO.service[AppConfig]
ch <- ZIO.service[CardinalityHandler]
cs <- ZIO.service[CardinalityService]
is <- ZIO.service[IriService]
kr <- ZIO.service[KnoraProjectRepo]
oc <- ZIO.service[OntologyCache]
oh <- ZIO.service[OntologyHelpers]
or <- ZIO.service[OntologyRepo]
sf <- ZIO.service[StringFormatter]
ts <- ZIO.service[TriplestoreService]
responder = OntologyResponderV2Live(ac, ch, cs, is, oc, oh, or, kr, ts, sf)
_ <- MessageRelay.subscribe(responder)
} yield responder
}
}

0 comments on commit b093357

Please sign in to comment.