Skip to content

Commit

Permalink
chore: Remove @accessible macro from some places (#3181)
Browse files Browse the repository at this point in the history
  • Loading branch information
seakayone authored Apr 10, 2024
1 parent 73fc75f commit 28a085b
Show file tree
Hide file tree
Showing 22 changed files with 125 additions and 181 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ object LayersTest {
AppRouter.layer,
AssetPermissionsResponder.layer,
AuthenticatorLive.layer,
AuthorizationRestServiceLive.layer,
AuthorizationRestService.layer,
BaseEndpoints.layer,
CacheService.layer,
CacheServiceRequestMessageHandlerLive.layer,
Expand Down Expand Up @@ -142,7 +142,7 @@ object LayersTest {
PredicateRepositoryLive.layer,
ProjectExportServiceLive.layer,
ProjectExportStorageServiceLive.layer,
ProjectImportServiceLive.layer,
ProjectImportService.layer,
QueryTraverser.layer,
RepositoryUpdater.layer,
ResourceInfoLayers.live,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import org.knora.webapi.util.ZioScalaTestUtil.assertFailsWithA

class SearchResponderV2Spec extends CoreSpec {

private val iriConverter = ZIO.serviceWithZIO[IriConverter]
private implicit val stringFormatter: StringFormatter = StringFormatter.getGeneralInstance
override lazy val rdfDataObjects: List[RdfDataObject] = List(
RdfDataObject(
Expand Down Expand Up @@ -225,8 +226,7 @@ class SearchResponderV2Spec extends CoreSpec {
"perform a search by label for incunabula:book that contain 'Narrenschiff'" in {
val actual = UnsafeZioRun.runOrThrow {
for {
limitToResourceClass <- IriConverter
.asSmartIri("http://www.knora.org/ontology/0803/incunabula#book")
limitToResourceClass <- iriConverter(_.asSmartIri("http://www.knora.org/ontology/0803/incunabula#book"))
.mapAttempt(_.toOntologySchema(ApiV2Complex))
.map(Some(_))
result <- searchResourcesByLabelV2(
Expand All @@ -246,8 +246,7 @@ class SearchResponderV2Spec extends CoreSpec {
"perform a search by label for incunabula:book that contain 'Das Narrenschiff'" in {
val actual = UnsafeZioRun.runOrThrow {
for {
limitToResourceClass <- IriConverter
.asSmartIri("http://www.knora.org/ontology/0803/incunabula#book")
limitToResourceClass <- iriConverter(_.asSmartIri("http://www.knora.org/ontology/0803/incunabula#book"))
.mapAttempt(_.toOntologySchema(ApiV2Complex))
.map(Some(_))
result <- searchResourcesByLabelV2(
Expand All @@ -268,8 +267,7 @@ class SearchResponderV2Spec extends CoreSpec {

val actual = UnsafeZioRun.runOrThrow {
for {
limitToResourceClass <- IriConverter
.asSmartIri("http://www.knora.org/ontology/0803/incunabula#book")
limitToResourceClass <- iriConverter(_.asSmartIri("http://www.knora.org/ontology/0803/incunabula#book"))
.mapAttempt(_.toOntologySchema(ApiV2Complex))
.map(Some(_))
result <- searchResourcesByLabelCountV2(
Expand All @@ -288,8 +286,7 @@ class SearchResponderV2Spec extends CoreSpec {

val actual = UnsafeZioRun.runOrThrow {
for {
limitToResourceClass <- IriConverter
.asSmartIri("http://www.knora.org/ontology/0803/incunabula#book")
limitToResourceClass <- iriConverter(_.asSmartIri("http://www.knora.org/ontology/0803/incunabula#book"))
.mapAttempt(_.toOntologySchema(ApiV2Complex))
.map(Some(_))
result <- searchResourcesByLabelCountV2(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ import org.knora.webapi.testcontainers.FusekiTestContainer

object ProjectImportServiceIT extends ZIOSpecDefault {

private val repositoryName = "knora-test"
private val projectImportService = ZIO.serviceWithZIO[ProjectImportService]
private val repositoryName = "knora-test"

private val storageServiceLayer: Layer[IOException, ProjectExportStorageServiceLive] = ZLayer.fromZIO {
for {
Expand All @@ -28,7 +29,7 @@ object ProjectImportServiceIT extends ZIOSpecDefault {
}

private val importServiceTestLayer
: URLayer[FusekiTestContainer with ProjectExportStorageService, ProjectImportServiceLive] = ZLayer.fromZIO {
: URLayer[FusekiTestContainer with ProjectExportStorageService, ProjectImportService] = ZLayer.fromZIO {
(for {
exportStorageService <- ZIO.service[ProjectExportStorageService]
container <- ZIO.service[FusekiTestContainer]
Expand All @@ -49,7 +50,7 @@ object ProjectImportServiceIT extends ZIOSpecDefault {
),
profileQueries = false,
)
} yield ProjectImportServiceLive(config, exportStorageService, dspIngestClient))
} yield ProjectImportService(config, exportStorageService, dspIngestClient))
.provideSomeLayer[FusekiTestContainer with ProjectExportStorageService](DspIngestClientITMock.layer)
}

Expand All @@ -70,9 +71,9 @@ object ProjectImportServiceIT extends ZIOSpecDefault {
_ <- FusekiTestContainer.initializeWithDataset(repositoryName)

filePath <- FileTestUtil.createTempTextFileScoped(trigContent, ".trig")
_ <- ProjectImportService.importTrigFile(filePath)
nrResultsInNamedGraph <- ProjectImportService
.querySelect(
_ <- projectImportService(_.importTrigFile(filePath))
nrResultsInNamedGraph <- projectImportService(
_.querySelect(
"""
|SELECT ?subject ?predicate ?object
|FROM NAMED <http://example.org/graph>
Expand All @@ -82,17 +83,19 @@ object ProjectImportServiceIT extends ZIOSpecDefault {
| }
|}
|""".stripMargin,
)
),
)
.map(_.rewindable.size())
nrResultsInDefaultGraph <- ProjectImportService
.querySelect(
nrResultsInDefaultGraph <- projectImportService(
_.querySelect(
"""
|SELECT ?subject ?predicate ?object
|WHERE {
| ?subject ?predicate ?object.
|}
|""".stripMargin,
)
),
)
.map(_.rewindable.size())
_ <- ZIO.logDebug("loaded")
} yield assertTrue(nrResultsInNamedGraph == 1, nrResultsInDefaultGraph == 1)
Expand Down
4 changes: 2 additions & 2 deletions webapi/src/main/scala/org/knora/webapi/core/LayersLive.scala
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ object LayersLive {
AppRouter.layer,
AssetPermissionsResponder.layer,
AuthenticatorLive.layer,
AuthorizationRestServiceLive.layer,
AuthorizationRestService.layer,
BaseEndpoints.layer,
CacheService.layer,
CacheServiceRequestMessageHandlerLive.layer,
Expand Down Expand Up @@ -132,7 +132,7 @@ object LayersLive {
PredicateRepositoryLive.layer,
ProjectExportServiceLive.layer,
ProjectExportStorageServiceLive.layer,
ProjectImportServiceLive.layer,
ProjectImportService.layer,
QueryTraverser.layer,
RepositoryUpdater.layer,
ResourceInfoLayers.live,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
package org.knora.webapi.core

import zio._
import zio.macros.accessible

import org.knora.webapi.messages.ResponderRequest

Expand All @@ -28,7 +27,6 @@ trait RelayedMessage extends ResponderRequest
* However, with the current architecture there are some circular dependencies between the responders and
* the router such that breaking these up is a task for after the ZIO migration.
*/
@accessible
trait MessageRelay {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -777,8 +777,8 @@ case class JsonLDObject(value: Map[String, JsonLDValue]) extends JsonLDValue {
def getRequiredTypeAsKnoraApiV2ComplexTypeIri: ZIO[IriConverter, String, SmartIri] =
ZIO.fromEither(getString(JsonLDKeywords.TYPE)).flatMap {
case Some(str) =>
IriConverter
.asSmartIri(str)
ZIO
.serviceWithZIO[IriConverter](_.asSmartIri(str))
.mapError(_.getMessage)
.filterOrFail(iri => iri.isKnoraEntityIri && iri.isApiV2ComplexSchema)(
s"Invalid Knora API v2 complex type IRI: $str",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -957,7 +957,7 @@ object UpdateResourceMetadataRequestV2 {
obj: JsonLDObject,
): ZIO[IriConverter, BadRequestException, Option[Instant]] = {
val getTimeStamp = for {
tsDataType <- IriConverter.asSmartIri(Xsd.DateTimeStamp).orDie
tsDataType <- ZIO.serviceWithZIO[IriConverter](_.asSmartIri(Xsd.DateTimeStamp)).orDie
tsString <- obj.getDataTypeValueInObject(key, tsDataType)
tsDate <- ZIO.foreach(tsString)(tsStr =>
ZIO
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1747,7 +1747,9 @@ object TextValueContentV2 {
maybeMappingResponse <-
getIriFromObject(jsonLdObject, TextValueHasMapping).flatMap(mappingIriOption =>
ZIO.foreach(mappingIriOption) { mappingIri =>
MessageRelay.ask[GetMappingResponseV2](GetMappingRequestV2(mappingIri, requestingUser))
ZIO.serviceWithZIO[MessageRelay](
_.ask[GetMappingResponseV2](GetMappingRequestV2(mappingIri, requestingUser)),
)
},
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2984,7 +2984,7 @@ object OntologyResponderV2Live {
ts <- ZIO.service[TriplestoreService]
cache <- ZIO.service[CacheService]
responder = OntologyResponderV2Live(ac, ch, cs, is, oc, oh, or, kr, ts, cache, sf)
_ <- MessageRelay.subscribe(responder)
_ <- ZIO.serviceWithZIO[MessageRelay](_.subscribe(responder))
} yield responder
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ object RouteUtilADM {
request: KnoraRequestADM,
): ZIO[StringFormatter & MessageRelay, Throwable, HttpResponse] =
for {
knoraResponse <- MessageRelay.ask[KnoraResponseADM](request)
knoraResponse <- ZIO.serviceWithZIO[MessageRelay](_.ask[KnoraResponseADM](request))
knoraResponseExternal <- transformResponseIntoExternalFormat(knoraResponse)
} yield HttpResponse(
OK,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ object RouteUtilV2 {
val maybeProjectIriStr =
requestContext.request.headers.find(_.lowercaseName == xKnoraAcceptProject).map(_.value())
ZIO.foreach(maybeProjectIriStr)(iri =>
IriConverter
.asSmartIri(iri)
ZIO
.serviceWithZIO[IriConverter](_.asSmartIri(iri))
.orElseFail(BadRequestException(s"Invalid project IRI: $iri in request header $xKnoraAcceptSchemaHeader")),
)
}
Expand All @@ -136,7 +136,7 @@ object RouteUtilV2 {
targetSchemaTask: ZIO[R, Throwable, OntologySchema] = ZIO.succeed(ApiV2Complex),
schemaOptionsOption: ZIO[R, Throwable, Option[Set[Rendering]]] = ZIO.none,
)(implicit runtime: Runtime[R & MessageRelay & AppConfig]): Future[RouteResult] = {
val responseZio = requestZio.flatMap(request => MessageRelay.ask[KnoraResponseV2](request))
val responseZio = requestZio.flatMap(request => ZIO.serviceWithZIO[MessageRelay](_.ask[KnoraResponseV2](request)))
completeResponse(responseZio, requestContext, targetSchemaTask, schemaOptionsOption)
}

Expand Down Expand Up @@ -191,7 +191,7 @@ object RouteUtilV2 {
UnsafeZioRun.runToFuture {
for {
requestMessage <- requestTask
teiResponse <- MessageRelay.ask[ResourceTEIGetResponseV2](requestMessage)
teiResponse <- ZIO.serviceWithZIO[MessageRelay](_.ask[ResourceTEIGetResponseV2](requestMessage))
contentType = MediaTypes.`application/xml`.toContentType(HttpCharsets.`UTF-8`)
response = HttpResponse(StatusCodes.OK, entity = HttpEntity(contentType, teiResponse.toXML))
completed <- ZIO.fromFuture(_ => requestContext.complete(response))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -509,9 +509,11 @@ final case class OntologiesRouteV2()(
.validate(validatedGuiAttributes, validatedGuiElement)
.flatMap(values => GuiObject.make(values._1, values._2))

ontologyIri <- IriConverter.asSmartIri(inputOntology.ontologyMetadata.ontologyIri.toString)
ontologyIri <-
ZIO.serviceWithZIO[IriConverter](_.asSmartIri(inputOntology.ontologyMetadata.ontologyIri.toString))
lastModificationDate = Validation.succeed(propertyUpdateInfo.lastModificationDate)
propertyIri <- IriConverter.asSmartIri(propertyInfoContent.propertyIri.toString)
propertyIri <- ZIO
.serviceWithZIO[IriConverter](_.asSmartIri(propertyInfoContent.propertyIri.toString))
subClassConstraintSmartIri <-
RouteUtilZ.toSmartIri(OntologyConstants.KnoraBase.SubjectClassConstraint, "Should not happen")
subjectType <-
Expand All @@ -520,9 +522,9 @@ final case class OntologiesRouteV2()(
case Some(value) =>
value.objects.head match {
case objectType: SmartIriLiteralV2 =>
IriConverter
.asSmartIri(
objectType.value.toOntologySchema(InternalSchema).toString,
ZIO
.serviceWithZIO[IriConverter](
_.asSmartIri(objectType.value.toOntologySchema(InternalSchema).toString),
)
.map(Some(_))
case other =>
Expand All @@ -538,7 +540,10 @@ final case class OntologiesRouteV2()(
case Some(value) =>
value.objects.head match {
case objectType: SmartIriLiteralV2 =>
IriConverter.asSmartIri(objectType.value.toOntologySchema(InternalSchema).toString)
ZIO
.serviceWithZIO[IriConverter](
_.asSmartIri(objectType.value.toOntologySchema(InternalSchema).toString),
)
case other =>
ZIO.fail(ValidationException(s"Unexpected object type for $other"))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,22 +140,24 @@ final case class ResourcesRouteV2(appConfig: AppConfig)(
.fromOption(params.get("resourceClass"))
.orElseFail(BadRequestException(s"This route requires the parameter 'resourceClass'"))
.flatMap(iri =>
IriConverter.asSmartIri(iri).orElseFail(BadRequestException(s"Invalid resource class IRI: $iri")),
ZIO
.serviceWithZIO[IriConverter](_.asSmartIri(iri))
.orElseFail(BadRequestException(s"Invalid resource class IRI: $iri")),
)
.filterOrElseWith(it => it.isKnoraApiV2EntityIri && it.isApiV2ComplexSchema)(it =>
ZIO.fail(BadRequestException(s"Invalid resource class IRI: $it")),
)
.flatMap(IriConverter.asInternalSmartIri)
.flatMap(it => ZIO.serviceWithZIO[IriConverter](_.asInternalSmartIri(it)))

val getOrderByProperty: ZIO[IriConverter, Throwable, Option[SmartIri]] =
ZIO.foreach(params.get("orderByProperty")) { orderByPropertyStr =>
IriConverter
.asSmartIri(orderByPropertyStr)
ZIO
.serviceWithZIO[IriConverter](_.asSmartIri(orderByPropertyStr))
.orElseFail(BadRequestException(s"Invalid property IRI: $orderByPropertyStr"))
.filterOrFail(iri => iri.isKnoraApiV2EntityIri && iri.isApiV2ComplexSchema)(
BadRequestException(s"Invalid property IRI: $orderByPropertyStr"),
)
.flatMap(IriConverter.asInternalSmartIri)
.flatMap(it => ZIO.serviceWithZIO[IriConverter](_.asInternalSmartIri(it)))
}

val getPage = ZIO
Expand Down Expand Up @@ -346,8 +348,8 @@ final case class ResourcesRouteV2(appConfig: AppConfig)(
val getExcludeProperty: ZIO[IriConverter, BadRequestException, Option[SmartIri]] = params
.get(ExcludeProperty)
.map(propIriStr =>
IriConverter
.asSmartIri(propIriStr)
ZIO
.serviceWithZIO[IriConverter](_.asSmartIri(propIriStr))
.mapBoth(_ => BadRequestException(s"Invalid property IRI: <$propIriStr>"), Some(_)),
)
.getOrElse(ZIO.none)
Expand Down Expand Up @@ -415,8 +417,8 @@ final case class ResourcesRouteV2(appConfig: AppConfig)(
.fromOption(params.get(Text_Property))
.orElseFail(BadRequestException(s"param $Text_Property not set"))
.flatMap { textPropIriStr =>
IriConverter
.asSmartIri(textPropIriStr)
ZIO
.serviceWithZIO[IriConverter](_.asSmartIri(textPropIriStr))
.orElseFail(BadRequestException(s"Invalid property IRI: <$textPropIriStr>"))
.filterOrFail(_.isKnoraApiV2EntityIri)(
BadRequestException(s"<$textPropIriStr> is not a valid knora-api property IRI"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -288,18 +288,12 @@ final case class ProjectRestService(
exportInfo <- projectExportService.exportProject(project).logError
} yield exportInfo

def importProject(
shortcode: Shortcode,
user: User,
): Task[ProjectImportResponse] = for {
def importProject(shortcode: Shortcode, user: User): Task[ProjectImportResponse] = for {
_ <- auth.ensureSystemAdmin(user)
path <-
projectImportService
.importProject(shortcode, user)
.flatMap {
case Some(export) => export.toAbsolutePath.map(_.toString)
case None => ZIO.fail(NotFoundException(s"Project export for ${shortcode.value} not found."))
}
path <- projectImportService.importProject(shortcode).flatMap {
case Some(export) => export.toAbsolutePath.map(_.toString)
case None => ZIO.fail(NotFoundException(s"Project export for ${shortcode.value} not found."))
}
} yield ProjectImportResponse(path)

def listExports(user: User): Task[Chunk[ProjectExportInfoResponse]] = for {
Expand Down
Loading

0 comments on commit 28a085b

Please sign in to comment.