-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Introduce OntologyService and refactor resource creation (#…
- Loading branch information
1 parent
211caa2
commit 21b82bf
Showing
8 changed files
with
115 additions
and
95 deletions.
There are no files selected for viewing
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
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
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
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
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
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
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
38 changes: 38 additions & 0 deletions
38
webapi/src/main/scala/org/knora/webapi/slice/ontology/domain/service/OntologyService.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,38 @@ | ||
/* | ||
* Copyright © 2021 - 2024 Swiss National Data and Service Center for the Humanities and/or DaSCH Service Platform contributors. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.knora.webapi.slice.ontology.domain.service | ||
|
||
import zio.* | ||
|
||
import org.knora.webapi.messages.OntologyConstants | ||
import org.knora.webapi.slice.ontology.repo.service.OntologyCache | ||
import org.knora.webapi.slice.resourceinfo.domain.InternalIri | ||
|
||
trait OntologyService { | ||
def getProjectIriForOntologyIri(ontologyIri: InternalIri): Task[Option[String]] | ||
} | ||
|
||
final case class OntologyServiceLive(ontologyCache: OntologyCache) extends OntologyService { | ||
def getProjectIriForOntologyIri(ontologyIri: InternalIri): Task[Option[String]] = | ||
ontologyCache.getCacheData.map { cacheData => | ||
cacheData.ontologies.map { case (k, v) => k.toString() -> v } | ||
.get(ontologyIri.value) | ||
.flatMap(_.ontologyMetadata.projectIri.map(_.toString())) | ||
} | ||
} | ||
|
||
object OntologyServiceLive { | ||
def isBuiltInOntology(ontologyIri: InternalIri): Boolean = | ||
OntologyConstants.BuiltInOntologyLabels.contains(ontologyIri.value.split("/").last) | ||
|
||
def isSharedOntology(ontologyIri: InternalIri): Boolean = | ||
ontologyIri.value.split("/")(4) == "shared" | ||
|
||
def isBuiltInOrSharedOntology(ontologyIri: InternalIri): Boolean = | ||
isBuiltInOntology(ontologyIri) || isSharedOntology(ontologyIri) | ||
|
||
val layer = ZLayer.derive[OntologyServiceLive] | ||
} |