-
Notifications
You must be signed in to change notification settings - Fork 18
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: Introduce OntologyService and refactor resource creation #3255
Merged
Merged
Changes from 11 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
b8b5080
create ontology service
BalduinLandolt 071c071
refactor resource creation
BalduinLandolt 10a02e3
fix test layers
BalduinLandolt 896e537
fmt
BalduinLandolt 966c0aa
Merge branch 'main' into wip/refactor-resource-creation
BalduinLandolt ff59b1e
use internal iri
BalduinLandolt e8280a1
Merge branch 'main' into wip/refactor-resource-creation
BalduinLandolt 9e1e8dd
Merge branch 'main' into wip/refactor-resource-creation
BalduinLandolt 803415a
fix
BalduinLandolt 34dfb66
tidy up
BalduinLandolt 72086ea
Merge branch 'main' into wip/refactor-resource-creation
BalduinLandolt 01c1a14
revert
BalduinLandolt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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] | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this precise? It's always going to be an instance of Option first, ApiV2Schema second. It's never a good idea to use isInstanceOf, it's not type safe, as you see here. If you're interested in the subtype, add WithAsIs and use
.contains(_.is[ApiV2Schema])
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
right... that's actually not at all correct, I completely ignored the option. That may be the reason why suddenly all the tests fail.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reverted the change which fixed the tests.
I don't think I want to spend anymore time on this PR, so I leave WithAsIs for another time.