Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Replace MessageRelay with KnoraProjectRepo in OntologyResponderV2 #2920

Merged
merged 3 commits into from Nov 8, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -21,8 +21,6 @@
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.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 @@
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 @@
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 @@
)

// 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"))

Check warning on line 538 in webapi/src/main/scala/org/knora/webapi/responders/v2/OntologyResponderV2.scala

View check run for this annotation

Codecov / codecov/patch

webapi/src/main/scala/org/knora/webapi/responders/v2/OntologyResponderV2.scala#L537-L538

Added lines #L537 - L538 were not covered by tests
internalOntologyIri = stringFormatter.makeProjectSpecificInternalOntologyIri(
validOntologyName,
createOntologyRequest.isShared,
projectInfo.project.shortcode
project.shortcode.value

Check warning on line 542 in webapi/src/main/scala/org/knora/webapi/responders/v2/OntologyResponderV2.scala

View check run for this annotation

Codecov / codecov/patch

webapi/src/main/scala/org/knora/webapi/responders/v2/OntologyResponderV2.scala#L542

Added line #L542 was not covered by tests
)

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

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

Check warning on line 2979 in webapi/src/main/scala/org/knora/webapi/responders/v2/OntologyResponderV2.scala

View check run for this annotation

Codecov / codecov/patch

webapi/src/main/scala/org/knora/webapi/responders/v2/OntologyResponderV2.scala#L2967-L2979

Added lines #L2967 - L2979 were not covered by tests
}
}