-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make
ValidatePriority
a trait (#4832)
- Loading branch information
1 parent
b2c5e64
commit a14152a
Showing
8 changed files
with
54 additions
and
24 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
37 changes: 37 additions & 0 deletions
37
delta/sdk/src/main/scala/ch/epfl/bluebrain/nexus/delta/sdk/resolvers/ValidatePriority.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,37 @@ | ||
package ch.epfl.bluebrain.nexus.delta.sdk.resolvers | ||
|
||
import cats.effect.IO | ||
import ch.epfl.bluebrain.nexus.delta.rdf.IriOrBNode.Iri | ||
import ch.epfl.bluebrain.nexus.delta.sdk.implicits._ | ||
import ch.epfl.bluebrain.nexus.delta.sdk.resolvers.model.Priority | ||
import ch.epfl.bluebrain.nexus.delta.sdk.resolvers.model.ResolverRejection.PriorityAlreadyExists | ||
import ch.epfl.bluebrain.nexus.delta.sourcing.Transactors | ||
import ch.epfl.bluebrain.nexus.delta.sourcing.model.ProjectRef | ||
import doobie.implicits._ | ||
|
||
trait ValidatePriority { | ||
|
||
/** Validate that a resolver with the given self & priority can be created in the provided project */ | ||
def validate(ref: ProjectRef, self: Iri, priority: Priority): IO[Unit] | ||
|
||
} | ||
|
||
object ValidatePriority { | ||
|
||
/** Provides a [[ValidatePriority]] instance that ensure there is no active resolver with the given priority */ | ||
def priorityAlreadyExists(xas: Transactors): ValidatePriority = (ref: ProjectRef, self: Iri, priority: Priority) => | ||
sql"""SELECT id FROM scoped_states | ||
WHERE type = ${Resolvers.entityType} | ||
AND org = ${ref.organization} AND project = ${ref.project} | ||
AND id != $self | ||
AND (value->'deprecated')::boolean = false | ||
AND (value->'value'->'priority')::int = ${priority.value}""" | ||
.query[Iri] | ||
.option | ||
.transact(xas.read) | ||
.flatMap { | ||
case Some(other) => IO.raiseError(PriorityAlreadyExists(ref, other, priority)) | ||
case None => IO.unit | ||
} | ||
|
||
} |
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