Skip to content

Commit

Permalink
Allow resolvers with same priority as deprecated resolver (#4805)
Browse files Browse the repository at this point in the history
  • Loading branch information
olivergrabinski authored Mar 28, 2024
1 parent 6534494 commit 32f30d6
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,12 @@ object ResolversImpl {
uuidF: UUIDF
): Resolvers = {
def priorityAlreadyExists(ref: ProjectRef, self: Iri, priority: Priority): IO[Unit] = {
sql"SELECT id FROM scoped_states WHERE type = ${Resolvers.entityType} AND org = ${ref.organization} AND project = ${ref.project} AND id != $self AND (value->'value'->'priority')::int = ${priority.value} "
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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import ch.epfl.bluebrain.nexus.delta.kernel.utils.UUIDF
import ch.epfl.bluebrain.nexus.delta.rdf.Vocabulary.{contexts, nxv, schema}
import ch.epfl.bluebrain.nexus.delta.rdf.jsonld.api.{JsonLdApi, JsonLdJavaApi}
import ch.epfl.bluebrain.nexus.delta.rdf.jsonld.context.RemoteContextResolution
import ch.epfl.bluebrain.nexus.delta.sdk.ConfigFixtures
import ch.epfl.bluebrain.nexus.delta.sdk.generators.ProjectGen
import ch.epfl.bluebrain.nexus.delta.sdk.generators.ResolverGen.{resolverResourceFor, sourceFrom, sourceWithoutId}
import ch.epfl.bluebrain.nexus.delta.sdk.identities.model.Caller
Expand All @@ -24,6 +23,7 @@ import ch.epfl.bluebrain.nexus.delta.sdk.resolvers.model.ResolverRejection.{Inco
import ch.epfl.bluebrain.nexus.delta.sdk.resolvers.model.ResolverValue.{CrossProjectValue, InProjectValue}
import ch.epfl.bluebrain.nexus.delta.sdk.resolvers.model._
import ch.epfl.bluebrain.nexus.delta.sdk.resources.Resources
import ch.epfl.bluebrain.nexus.delta.sdk.{ConfigFixtures, ResolverResource}
import ch.epfl.bluebrain.nexus.delta.sourcing.EntityDependencyStore
import ch.epfl.bluebrain.nexus.delta.sourcing.model.EntityDependency.DependsOn
import ch.epfl.bluebrain.nexus.delta.sourcing.model.Identity.{Authenticated, Group, User}
Expand Down Expand Up @@ -620,6 +620,22 @@ class ResolversImplSpec extends CatsEffectSpec with DoobieScalaTestFixture with
}

}

"validating priority" should {
"allow creating a resolver with the same priority as a deprecated resolver" in {
givenADeprecatedInProjectResolver(666) { resolver =>
resolvers.create(nxv + genString(), resolver.value.project, InProjectValue(resolver.value.priority))
}
}
}

def givenADeprecatedInProjectResolver(priority: Int)(test: ResolverResource => IO[ResolverResource]) = {
val id = nxv + genString()
val resolverValue = InProjectValue(Priority.unsafe(priority))
resolvers.create(id, projectRef, resolverValue).accepted
val deprecatedResolver = resolvers.deprecate(id, projectRef, 1).accepted
test(deprecatedResolver).accepted
}
}

}

0 comments on commit 32f30d6

Please sign in to comment.