Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -705,7 +705,6 @@ lazy val tests = project
fs2Aws % Test,
fs2AwsS3 % Test
),
scalacOptions ~= { options: Seq[String] => options.filterNot(Set("-Wunused:imports")) },
Test / parallelExecution := false,
Test / testOptions += Tests.Argument(TestFrameworks.ScalaTest, "-o", "-u", "target/test-reports"),
// Scalate gets errors with layering with this project so we disable it
Expand Down Expand Up @@ -782,7 +781,10 @@ lazy val compilation = {

Seq(
scalaVersion := scalaCompilerVersion,
scalacOptions ~= { options: Seq[String] => options.filterNot(Set("-Wself-implicit", "-Xlint:infer-any", "-Wnonunit-statement")) },
scalacOptions ~= { options: Seq[String] =>
options.filterNot(Set("-Wself-implicit", "-Xlint:infer-any", "-Wnonunit-statement")) ++
Seq("-Xsource:3", "-Xsource-features:case-apply-copy-access", "-Wconf:cat=scala3-migration:s")
},
javaSpecificationVersion := "21",
javacOptions ++= Seq(
"-source",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import akka.http.scaladsl.server.Route
import cats.effect.IO
import cats.syntax.all._
import ch.epfl.bluebrain.nexus.delta.config.DescriptionConfig
import ch.epfl.bluebrain.nexus.delta.kernel.dependency.ComponentDescription.ServiceDescription.UnresolvedServiceDescription
import ch.epfl.bluebrain.nexus.delta.kernel.dependency.ComponentDescription.{PluginDescription, ServiceDescription}
import ch.epfl.bluebrain.nexus.delta.kernel.dependency.{ComponentDescription, ServiceDependency}
import ch.epfl.bluebrain.nexus.delta.rdf.Vocabulary
Expand Down Expand Up @@ -61,7 +60,7 @@ class VersionRoutes(
object VersionRoutes {

private val emtyVersionBundle = VersionBundle(
UnresolvedServiceDescription("delta"),
ServiceDescription.unresolved("delta"),
List.empty,
List.empty,
Name.unsafe("unknown")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@ object ComponentDescription {
sealed trait ServiceDescription extends ComponentDescription

object ServiceDescription {
final case class ResolvedServiceDescription private (name: String, version: String) extends ServiceDescription
final case class UnresolvedServiceDescription private (name: String) extends ServiceDescription {
final case class ResolvedServiceDescription private[ServiceDescription] (name: String, version: String)
extends ServiceDescription
final case class UnresolvedServiceDescription private[ServiceDescription] (name: String)
extends ServiceDescription {
override val version: String = unknownVersion
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import io.circe.{Decoder, Encoder}
* @param value
* the string representation of the token
*/
final case class AuthToken private (value: String) extends AnyVal
final case class AuthToken(value: String) extends AnyVal

object AuthToken {

Expand All @@ -22,16 +22,6 @@ object AuthToken {
def apply(bearer: OAuth2BearerToken): AuthToken =
new AuthToken(bearer.token)

/**
* Creates an AuthToken from a string representation. No validations are performed in terms of format and
* consistency.
*
* @param value
* the string representation of the token
*/
def unsafe(value: String): AuthToken =
new AuthToken(value)

implicit val authTokenEncoder: Encoder[AuthToken] = Encoder.encodeString.contramap(_.value)
implicit val authTokenDecoder: Decoder[AuthToken] = Decoder.decodeString.map(unsafe)
implicit val authTokenDecoder: Decoder[AuthToken] = Decoder.decodeString.map(AuthToken(_))
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ object TimeRange {
/**
* Defines a time range taking place between the two instants
*/
final case class Between private (start: Instant, end: Instant) extends TimeRange
final case class Between private[TimeRange] (start: Instant, end: Instant) extends TimeRange

object Between {
def unsafe(start: Instant, end: Instant) = new Between(start, end)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class ArchiveDownloadSpec
implicit val ec: ExecutionContext = system.dispatcher

implicit private val subject: Subject = Identity.User("user", Label.unsafe("realm"))
implicit private val caller: Caller = Caller.unsafe(subject)
implicit private val caller: Caller = Caller(subject)
implicit private val baseUri: BaseUri = BaseUri("http://localhost", Label.unsafe("v1"))

implicit private val jsonKeyOrdering: JsonKeyOrdering =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ class ArchiveRoutesSpec extends BaseRouteSpec with StorageFixtures with ArchiveH
implicit override def rcr: RemoteContextResolution = RemoteContextResolutionFixture.rcr

private val subject: Subject = Identity.User("user", Label.unsafe("realm"))
implicit private val caller: Caller = Caller.unsafe(subject)
implicit private val caller: Caller = Caller(subject)
private val subjectNoFilePerms: Subject = Identity.User("nofileperms", Label.unsafe("realm"))
private val callerNoFilePerms: Caller = Caller.unsafe(subjectNoFilePerms)
private val callerNoFilePerms: Caller = Caller(subjectNoFilePerms)

private val project =
ProjectGen.project("org", "proj", base = nxv.base, mappings = ApiMappings("file" -> schemas.files))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class ArchivesSpec extends CatsEffectSpec with DoobieScalaTestFixture with Remot

private val usersRealm: Label = Label.unsafe("users")
private val bob: Subject = User("bob", usersRealm)
implicit private val caller: Caller = Caller.unsafe(bob)
implicit private val caller: Caller = Caller(bob)

private val am = ApiMappings("nxv" -> nxv.base, "Person" -> schema.Person)
private val projBase = iri"http://localhost/base/"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ final class BlazegraphClient(
client
.fromEntityTo[ResolvedServiceDescription](Get(endpoint / "status"))
.timeout(1.second)
.redeem(_ => ServiceDescription.unresolved(serviceName), _.copy(name = serviceName))
.recover(_ => ServiceDescription.unresolved(serviceName))

override def existsNamespace(namespace: String): IO[Boolean] =
client
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,17 @@ object SparqlWriteQuery {
/**
* A Drop query
*/
final case class SparqlDropQuery private (value: String, graph: Uri) extends SparqlWriteQuery
final case class SparqlDropQuery private[SparqlWriteQuery] (value: String, graph: Uri) extends SparqlWriteQuery

/**
* A Patch query
*/
final case class SparqlPatchQuery private (value: String, graph: Uri) extends SparqlWriteQuery
final case class SparqlPatchQuery private[SparqlWriteQuery] (value: String, graph: Uri) extends SparqlWriteQuery

/**
* A Replace query (drop + insert)
*/
final case class SparqlReplaceQuery private (value: String, graph: Uri) extends SparqlWriteQuery
final case class SparqlReplaceQuery private[SparqlWriteQuery] (value: String, graph: Uri) extends SparqlWriteQuery

/**
* A custom write query
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,9 @@ object CompositeView {
override def compact(
value: CompositeView
)(implicit opts: JsonLdOptions, api: JsonLdApi, rcr: RemoteContextResolution): IO[CompactedJsonLd] =
underlying.compact(value).map(c => c.copy(obj = stringToJson(c.obj)))
underlying.compact(value).map { c =>
CompactedJsonLd.unsafe(c.rootId, c.ctx, stringToJson(c.obj))
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package ch.epfl.bluebrain.nexus.delta.plugins.compositeviews.model

import cats.syntax.either._
import cats.syntax.all._
import ch.epfl.bluebrain.nexus.delta.plugins.compositeviews.model.CompositeViewProjection.idTemplating
import ch.epfl.bluebrain.nexus.delta.rdf.jsonld.decoder.JsonLdDecoder
import ch.epfl.bluebrain.nexus.delta.rdf.jsonld.decoder.JsonLdDecoderError.ParsingFailure
Expand All @@ -20,7 +20,8 @@ object TemplateSparqlConstructQuery {
if (!value.contains(idTemplating))
Left(s"Required templating '$idTemplating' in the provided SPARQL query is not found")
else
SparqlConstructQuery(value.replaceAll(quote(idTemplating), fakeIri.rdfFormat)).map(_.copy(value = value))
SparqlConstructQuery(value.replaceAll(quote(idTemplating), fakeIri.rdfFormat))
.as(SparqlConstructQuery.unsafe(value))

implicit val sparqlConstructQueryJsonLdDecoder: JsonLdDecoder[SparqlConstructQuery] =
JsonLdDecoder.stringJsonLdDecoder.andThen { case (cursor, str) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import ch.epfl.bluebrain.nexus.delta.sourcing.stream.ProjectionProgress
* @param branches
* the progress for each projection branch
*/
final case class CompositeProgress private (
final case class CompositeProgress(
sources: Map[(Iri, Run), Offset],
branches: Map[CompositeBranch, ProjectionProgress]
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import java.util.UUID

class CompositeViewFactorySuite extends NexusSuite {

implicit private val projectBase: ProjectBase = ProjectBase.unsafe(iri"http://localhost/project")
implicit private val projectBase: ProjectBase = ProjectBase(iri"http://localhost/project")
private val uuid = UUID.randomUUID()
implicit private val uuidF: UUIDF = UUIDF.fixed(uuid)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,7 @@ class ElasticSearchClient(client: HttpClient, endpoint: Uri, maxIndexPathLength:
client
.fromJsonTo[ResolvedServiceDescription](Get(endpoint).withHttpCredentials)
.timeout(1.second)
.redeem(
_ => ServiceDescription.unresolved(serviceName),
_.copy(name = serviceName)
)
.recover(_ => ServiceDescription.unresolved(serviceName))

/**
* Verifies if an index exists, recovering gracefully when the index does not exists.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,9 @@ object ElasticSearchView {
override def compact(
value: ElasticSearchView
)(implicit opts: JsonLdOptions, api: JsonLdApi, rcr: RemoteContextResolution): IO[CompactedJsonLd] =
underlying.compact(value).map(c => c.copy(obj = stringToJson(c.obj)))
underlying.compact(value).map { c =>
CompactedJsonLd.unsafe(c.rootId, c.ctx, stringToJson(c.obj))
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class MainIndexDeletionTaskSuite
def countInIndex(project: ProjectRef) =
for {
query <- task.searchByProject(project)
result <- client.search(QueryBuilder(query), Set(index.value), Query.Empty)
result <- client.search(QueryBuilder.unsafe(query), Set(index.value), Query.Empty)
} yield result.total

for {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,27 @@ package ch.epfl.bluebrain.nexus.delta.plugins.elasticsearch.routes

import akka.http.scaladsl.model.MediaRanges.`*/*`
import akka.http.scaladsl.model.headers.Accept
import akka.http.scaladsl.server.Directives._
import akka.http.scaladsl.server.Directives.*
import akka.http.scaladsl.server.Route
import ch.epfl.bluebrain.nexus.delta.kernel.search.TimeRange
import ch.epfl.bluebrain.nexus.delta.kernel.utils.UrlUtils
import ch.epfl.bluebrain.nexus.delta.plugins.elasticsearch.model.ResourcesSearchParams
import ch.epfl.bluebrain.nexus.delta.plugins.elasticsearch.model.ResourcesSearchParams.Type.{ExcludedType, IncludedType}
import ch.epfl.bluebrain.nexus.delta.rdf.Vocabulary.nxv
import ch.epfl.bluebrain.nexus.delta.rdf.jsonld.context.JsonLdContext.keywords
import ch.epfl.bluebrain.nexus.delta.kernel.circe.CirceMarshalling
import ch.epfl.bluebrain.nexus.delta.sdk.implicits._
import ch.epfl.bluebrain.nexus.delta.sdk.model._
import ch.epfl.bluebrain.nexus.delta.sdk.model.search.Sort.OrderType
import ch.epfl.bluebrain.nexus.delta.sdk.implicits.*
import ch.epfl.bluebrain.nexus.delta.sdk.model.*
import ch.epfl.bluebrain.nexus.delta.sdk.model.search.{Sort, SortList}
import ch.epfl.bluebrain.nexus.delta.sdk.projects.model.{ApiMappings, ProjectContext}
import ch.epfl.bluebrain.nexus.delta.sdk.utils.RouteHelpers
import ch.epfl.bluebrain.nexus.delta.sourcing.model.Identity.User
import ch.epfl.bluebrain.nexus.delta.sourcing.model.Tag.UserTag
import ch.epfl.bluebrain.nexus.delta.sourcing.model.{Label, ResourceRef}
import ch.epfl.bluebrain.nexus.testkit.scalatest.ce.CatsEffectSpec
import io.circe.Codec
import io.circe.generic.extras.Configuration
import io.circe.generic.extras.semiauto.deriveConfiguredCodec
import io.circe.syntax.EncoderOps
import org.scalactic.source.Position

import java.time.Instant

class ElasticSearchViewsDirectivesSpec
extends CatsEffectSpec
with RouteHelpers
with CirceMarshalling
with ElasticSearchViewsDirectives {
class ElasticSearchViewsDirectivesSpec extends CatsEffectSpec with RouteHelpers with ElasticSearchViewsDirectives {

implicit private val baseUri: BaseUri = BaseUri("http://localhost", Label.unsafe("v1"))

Expand All @@ -41,37 +31,32 @@ class ElasticSearchViewsDirectivesSpec
private val vocab = iri"http://localhost/vocab/"
implicit private val pc: ProjectContext = ProjectContext.unsafe(mappings, base, vocab, enforceSchema = false)

implicit val configuration: Configuration = Configuration.default.withDiscriminator(keywords.tpe)

implicit val timeRangeCodec: Codec[TimeRange] = deriveConfiguredCodec[TimeRange]

implicit val orderTypeCodec: Codec[OrderType] = deriveConfiguredCodec[OrderType]
implicit val sortCodec: Codec[Sort] = deriveConfiguredCodec[Sort]
implicit val sortListCodec: Codec[SortList] = deriveConfiguredCodec[SortList]

implicit val paramTypesCodec: Codec[ResourcesSearchParams.Type] = deriveConfiguredCodec[ResourcesSearchParams.Type]
implicit val paramTypeOperatorCodec: Codec[ResourcesSearchParams.TypeOperator] =
deriveConfiguredCodec[ResourcesSearchParams.TypeOperator]
implicit val paramsCodec: Codec[ResourcesSearchParams] = deriveConfiguredCodec[ResourcesSearchParams]

private val route: Route =
private def makeRoute(
expectedSortList: Option[SortList] = None,
expectedSearch: Option[ResourcesSearchParams] = None
)(implicit position: Position): Route =
get {
concat(
(pathPrefix("sort") & sortList & pathEndOrSingleSlash) { list =>
complete(list)
list shouldEqual expectedSortList.value
complete("successSortList")
},
(pathPrefix("search") & projectRef & pathEndOrSingleSlash) { _ =>
searchParameters(baseUri, pc).apply { params => complete(params.asJson) }
searchParameters(baseUri, pc).apply { params =>
params shouldEqual expectedSearch.value
complete("successSearchParams")
}
}
)
}

"A route" should {

"return the sort parameters" in {
val expected = SortList(List(Sort("deprecated"), Sort("-@id"), Sort("_createdBy")))
val route = makeRoute(expectedSortList = Some(expected))
Get("/sort?sort=+deprecated&sort=-@id&sort=_createdBy") ~> Accept(`*/*`) ~> route ~> check {
val expected = SortList(List(Sort("deprecated"), Sort("-@id"), Sort("_createdBy")))
response.as[SortList] shouldEqual expected
responseAs[String] shouldEqual "successSortList"
}
}

Expand All @@ -83,7 +68,7 @@ class ElasticSearchViewsDirectivesSpec

val createdAt = TimeRange.Before(Instant.EPOCH)
val createdAtEncoded = UrlUtils.encode(s"*..${createdAt.value}")
val updatedAt = TimeRange.Between(Instant.EPOCH, Instant.EPOCH.plusSeconds(5L))
val updatedAt = TimeRange.Between.unsafe(Instant.EPOCH, Instant.EPOCH.plusSeconds(5L))
val updatedAtEncoded = UrlUtils.encode(s"${updatedAt.start}..${updatedAt.end}")
val tag = UserTag.unsafe("mytag")

Expand Down Expand Up @@ -124,14 +109,18 @@ class ElasticSearchViewsDirectivesSpec
tag = Some(tag)
)

val route = makeRoute(expectedSearch = Some(expected))

Get(s"/search/org/project?$query") ~> Accept(`*/*`) ~> route ~> check {
response.as[ResourcesSearchParams] shouldEqual expected
responseAs[String] shouldEqual "successSearchParams"
}
}

"return empty search parameters" in {
val expected = ResourcesSearchParams()
val route = makeRoute(expectedSearch = Some(expected))
Get("/search/org/project") ~> Accept(`*/*`) ~> route ~> check {
response.as[ResourcesSearchParams] shouldEqual ResourcesSearchParams()
responseAs[String] shouldEqual "successSearchParams"
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,14 @@ object GraphAnalytics {

override def relationships(projectRef: ProjectRef): IO[AnalyticsGraph] =
for {
_ <- fetchContext.onRead(projectRef)
query <- relationshipsAggQuery(config)
stats <- client
.searchAs[AnalyticsGraph](QueryBuilder(query), index(prefix, projectRef).value, Query.Empty)
.adaptError { case e: HttpClientError =>
WrappedElasticSearchRejection(WrappedElasticSearchClientError(e))
}
_ <- fetchContext.onRead(projectRef)
query <- relationshipsAggQuery(config)
indexValue = index(prefix, projectRef).value
stats <- client
.searchAs[AnalyticsGraph](QueryBuilder.unsafe(query), indexValue, Query.Empty)
.adaptError { case e: HttpClientError =>
WrappedElasticSearchRejection(WrappedElasticSearchClientError(e))
}
} yield stats

override def properties(
Expand All @@ -67,8 +68,9 @@ object GraphAnalytics {

def search(tpe: Iri, idx: IndexLabel, query: JsonObject) = {
implicit val d: Decoder[PropertiesStatistics] = propertiesDecoderFromEsAggregations(tpe)
val queryBuilder = QueryBuilder.unsafe(query).withTotalHits(true)
client
.searchAs[PropertiesStatistics](QueryBuilder(query).withTotalHits(true), idx.value, Query.Empty)
.searchAs[PropertiesStatistics](queryBuilder, idx.value, Query.Empty)
.adaptError { case e: HttpClientError => WrappedElasticSearchRejection(WrappedElasticSearchClientError(e)) }
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import ch.epfl.bluebrain.nexus.testkit.mu.NexusSuite

class SearchConfigHookSuite extends NexusSuite with CompositeViewsFixture {

implicit private val projectBase: ProjectBase = ProjectBase.unsafe(nxv.base)
implicit private val projectBase: ProjectBase = ProjectBase(nxv.base)

private val defaults = Defaults("viewName", "viewDescription")
private val currentConfig =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ object ValidationReport {
IO.fromEither(
tmpGraph
.find { case (_, p, _) => p == predicate(sh.conforms) }
.map { case (s, _, _) => if (s.isURI) iri"${s.getURI}" else BNode(s.getBlankNodeLabel) }
.map { case (s, _, _) => if (s.isURI) iri"${s.getURI}" else BNode.unsafe(s.getBlankNodeLabel) }
.toRight(new IllegalStateException("Unable to find predicate sh:conforms in the validation report graph"))
)
graph = tmpGraph.replaceRootNode(rootNode)
Expand Down
Loading