-
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: Create resources repo (#3269)
- Loading branch information
1 parent
11e38a8
commit 351b3e0
Showing
8 changed files
with
104 additions
and
68 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
29 changes: 0 additions & 29 deletions
29
webapi/src/main/scala/org/knora/webapi/messages/twirl/SparqlTemplateResourceToCreate.scala
This file was deleted.
Oops, something went wrong.
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
63 changes: 63 additions & 0 deletions
63
webapi/src/main/scala/org/knora/webapi/slice/resources/repo/service/ResourcesRepoLive.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,63 @@ | ||
/* | ||
* 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.resources.repo.service | ||
|
||
import zio.* | ||
|
||
import dsp.constants.SalsahGui.IRI | ||
import org.knora.webapi.messages.SmartIri | ||
import org.knora.webapi.messages.twirl.queries.sparql | ||
import org.knora.webapi.messages.v2.responder.valuemessages.UnverifiedValueV2 | ||
import org.knora.webapi.responders.v2.resources.SparqlTemplateResourceToCreate | ||
import org.knora.webapi.slice.resourceinfo.domain.InternalIri | ||
import org.knora.webapi.store.triplestore.api.TriplestoreService | ||
import org.knora.webapi.store.triplestore.api.TriplestoreService.Queries.Update | ||
|
||
/** | ||
* Represents a resource that is ready to be created and whose contents can be verified afterwards. | ||
* | ||
* @param sparqlTemplateResourceToCreate a [[SparqlTemplateResourceToCreate]] describing SPARQL for creating | ||
* the resource. | ||
* @param values the resource's values for verification. | ||
* @param hasStandoffLink `true` if the property `knora-base:hasStandoffLinkToValue` was automatically added. | ||
*/ | ||
case class ResourceReadyToCreate( | ||
sparqlTemplateResourceToCreate: SparqlTemplateResourceToCreate, | ||
values: Map[SmartIri, Seq[UnverifiedValueV2]], | ||
hasStandoffLink: Boolean, | ||
) | ||
|
||
trait ResourcesRepo { | ||
def createNewResource( | ||
dataGraphIri: InternalIri, | ||
resource: ResourceReadyToCreate, | ||
userIri: IRI, | ||
projectIri: IRI, | ||
): Task[Unit] | ||
} | ||
|
||
final case class ResourcesRepoLive(triplestore: TriplestoreService) extends ResourcesRepo { | ||
|
||
def createNewResource( | ||
dataGraphIri: InternalIri, | ||
resource: ResourceReadyToCreate, | ||
userIri: IRI, | ||
projectIri: IRI, | ||
): Task[Unit] = | ||
triplestore.query( | ||
Update( | ||
sparql.v2.txt.createNewResource( | ||
dataNamedGraph = dataGraphIri.value, | ||
resourceToCreate = resource.sparqlTemplateResourceToCreate, | ||
projectIri = projectIri, | ||
creatorIri = userIri, | ||
), | ||
), | ||
) | ||
|
||
} | ||
|
||
object ResourcesRepoLive { val layer = ZLayer.derive[ResourcesRepoLive] } |
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