Skip to content

Commit

Permalink
Merge pull request #151 from SwissDataScienceCenter/model-refactoring
Browse files Browse the repository at this point in the history
Refactoring of search entity classes
  • Loading branch information
eikek authored Jun 12, 2024
2 parents d8a19a0 + 4731c91 commit ccdbbd9
Show file tree
Hide file tree
Showing 69 changed files with 701 additions and 532 deletions.
16 changes: 15 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ lazy val root = project
}
)
.aggregate(
json,
commons,
jwt,
openidKeycloak,
Expand All @@ -72,6 +73,18 @@ lazy val root = project
searchCli
)

lazy val json = project
.in(file("modules/json"))
.settings(commonSettings)
.settings(
name := "json",
// please don't add more dependencies here
libraryDependencies ++= Dependencies.borer,
description := "Utilities around working with borer"
)
.enablePlugins(AutomateHeaderPlugin)
.disablePlugins(DbTestPlugin, RevolverPlugin)

lazy val commons = project
.in(file("modules/commons"))
.settings(commonSettings)
Expand All @@ -81,7 +94,6 @@ lazy val commons = project
Dependencies.borer ++
Dependencies.catsCore ++
Dependencies.catsEffect ++
Dependencies.ducktape ++
Dependencies.fs2Core ++
Dependencies.scodecBits ++
Dependencies.scribe,
Expand All @@ -102,6 +114,7 @@ lazy val commons = project
buildInfoKeys := Seq(name, version, gitHeadCommit, gitDescribedVersion),
buildInfoPackage := "io.renku.search"
)
.dependsOn(json % "compile->compile;test->test")
.enablePlugins(AutomateHeaderPlugin, BuildInfoPlugin)
.disablePlugins(DbTestPlugin, RevolverPlugin)

Expand Down Expand Up @@ -255,6 +268,7 @@ lazy val solrClient = project
)
.dependsOn(
httpClient % "compile->compile;test->test",
json % "compile->compile;test->test",
commons % "test->test"
)

Expand Down
7 changes: 6 additions & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@
RS_CONTAINER = "rsdev";
RS_LOG_LEVEL = "3";
RS_SEARCH_HTTP_SERVER_PORT = "8080";
RS_SEARCH_HTTP_SHUTDOWN_TIMEOUT = "0ms";
RS_PROVISION_HTTP_SERVER_PORT = "8082";
RS_PROVISION_HTTP_SHUTDOWN_TIMEOUT = "0ms";
RS_METRICS_UPDATE_INTERVAL = "0s";
RS_SOLR_CREATE_CORE_CMD = "cnt-solr-create-core %s";
RS_SOLR_DELETE_CORE_CMD = "cnt-solr-delete-core %s";
Expand All @@ -94,6 +96,7 @@
NO_SOLR = "true";
NO_REDIS = "true";
DEV_CONTAINER = "rsdev-cnt";
SBT_OPTS = "-Xmx2G";

buildInputs =
commonPackages
Expand All @@ -110,7 +113,9 @@
VM_SSH_PORT = "10022";
RS_LOG_LEVEL = "3";
RS_SEARCH_HTTP_SERVER_PORT = "8080";
RS_SEARCH_HTTP_SHUTDOWN_TIMEOUT = "0ms";
RS_PROVISION_HTTP_SERVER_PORT = "8082";
RS_PROVISION_HTTP_SHUTDOWN_TIMEOUT = "0ms";
RS_METRICS_UPDATE_INTERVAL = "0s";
RS_SOLR_CREATE_CORE_CMD = "vm-solr-create-core %s";
RS_SOLR_DELETE_CORE_CMD = "vm-solr-delete-core %s";
Expand All @@ -119,8 +124,8 @@
#don't start docker container for dbTests
NO_SOLR = "true";
NO_REDIS = "true";

DEV_VM = "rsdev-vm";
SBT_OPTS = "-Xmx2G";

buildInputs =
commonPackages
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright 2024 Swiss Data Science Center (SDSC)
* A partnership between École Polytechnique Fédérale de Lausanne (EPFL) and
* Eidgenössische Technische Hochschule Zürich (ETHZ).
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.renku.search.model

import java.time.Instant

import cats.kernel.Order

import io.bullet.borer.Codec
import io.renku.json.codecs.all.given

opaque type CreationDate = Instant
object CreationDate:
def apply(v: Instant): CreationDate = v
extension (self: CreationDate) def value: Instant = self
given Codec[CreationDate] = Codec.of[Instant]
given Order[CreationDate] = Order.fromComparable[Instant]
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,16 @@
package io.renku.search.model

import io.bullet.borer.Codec
import io.github.arainko.ducktape.Transformer

object groups:
opaque type Description = String
object Description:
def apply(v: String): Description = v
def from(v: Option[String]): Option[Description] =
v.flatMap {
_.trim match {
case "" => Option.empty[Description]
case o => Option(o)
}
opaque type Description = String
object Description:
def apply(v: String): Description = v
def from(v: Option[String]): Option[Description] =
v.flatMap {
_.trim match {
case "" => Option.empty[Description]
case o => Option(o)
}
extension (self: Description) def value: String = self
given Transformer[String, Description] = apply
given Codec[Description] = Codec.of[String]
}
extension (self: Description) def value: String = self
given Codec[Description] = Codec.of[String]
27 changes: 27 additions & 0 deletions modules/commons/src/main/scala/io/renku/search/model/Email.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright 2024 Swiss Data Science Center (SDSC)
* A partnership between École Polytechnique Fédérale de Lausanne (EPFL) and
* Eidgenössische Technische Hochschule Zürich (ETHZ).
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.renku.search.model

import io.bullet.borer.Codec

opaque type Email = String
object Email:
def apply(v: String): Email = v
extension (self: Email) def value: String = self
given Codec[Email] = Codec.bimap[String, Email](_.value, Email.apply)
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright 2024 Swiss Data Science Center (SDSC)
* A partnership between École Polytechnique Fédérale de Lausanne (EPFL) and
* Eidgenössische Technische Hochschule Zürich (ETHZ).
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.renku.search.model

import io.bullet.borer.Codec

opaque type FirstName = String
object FirstName:
def apply(v: String): FirstName = v
extension (self: FirstName) def value: String = self
given Codec[FirstName] = Codec.bimap[String, FirstName](_.value, FirstName.apply)
2 changes: 0 additions & 2 deletions modules/commons/src/main/scala/io/renku/search/model/Id.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,10 @@ package io.renku.search.model
import cats.Show

import io.bullet.borer.Codec
import io.github.arainko.ducktape.Transformer

opaque type Id = String
object Id:
def apply(v: String): Id = v
extension (self: Id) def value: String = self
given Transformer[String, Id] = apply
given Codec[Id] = Codec.of[String]
given Show[Id] = Show.show(_.value)
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright 2024 Swiss Data Science Center (SDSC)
* A partnership between École Polytechnique Fédérale de Lausanne (EPFL) and
* Eidgenössische Technische Hochschule Zürich (ETHZ).
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.renku.search.model

import io.bullet.borer.Codec

opaque type LastName = String
object LastName:
def apply(v: String): LastName = v
extension (self: LastName) def value: String = self
given Codec[LastName] = Codec.bimap[String, LastName](_.value, LastName.apply)
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,9 @@
package io.renku.search.model

import io.bullet.borer.Codec
import io.github.arainko.ducktape.Transformer

opaque type Name = String
object Name:
def apply(v: String): Name = v
extension (self: Name) def value: String = self
given Transformer[String, Name] = apply
given Codec[Name] = Codec.of[String]
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright 2024 Swiss Data Science Center (SDSC)
* A partnership between École Polytechnique Fédérale de Lausanne (EPFL) and
* Eidgenössische Technische Hochschule Zürich (ETHZ).
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.renku.search.model

import cats.kernel.Order

import io.bullet.borer.Codec

opaque type Repository = String
object Repository:
def apply(v: String): Repository = v
extension (self: Repository) def value: String = self
given Codec[Repository] = Codec.of[String]
given Order[Repository] = Order.fromComparable[String]
30 changes: 30 additions & 0 deletions modules/commons/src/main/scala/io/renku/search/model/Slug.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright 2024 Swiss Data Science Center (SDSC)
* A partnership between École Polytechnique Fédérale de Lausanne (EPFL) and
* Eidgenössische Technische Hochschule Zürich (ETHZ).
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.renku.search.model

import cats.kernel.Order

import io.bullet.borer.Codec

opaque type Slug = String
object Slug:
def apply(v: String): Slug = v
extension (self: Slug) def value: String = self
given Codec[Slug] = Codec.of[String]
given Order[Slug] = Order.fromComparable[String]
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright 2024 Swiss Data Science Center (SDSC)
* A partnership between École Polytechnique Fédérale de Lausanne (EPFL) and
* Eidgenössische Technische Hochschule Zürich (ETHZ).
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.renku.search.model

import io.bullet.borer.Codec

opaque type Username = String
object Username:
def apply(v: String): Username = v
extension (self: Username) def value: String = self
given Codec[Username] = Codec.bimap[String, Username](_.value, Username.apply)
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright 2024 Swiss Data Science Center (SDSC)
* A partnership between École Polytechnique Fédérale de Lausanne (EPFL) and
* Eidgenössische Technische Hochschule Zürich (ETHZ).
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.renku.search.model

import cats.kernel.Order

import io.bullet.borer.derivation.MapBasedCodecs.*
import io.bullet.borer.{Decoder, Encoder}

enum Visibility:
lazy val name: String = productPrefix.toLowerCase
case Public, Private

object Visibility:
given Order[Visibility] = Order.by(_.ordinal)
given Encoder[Visibility] = Encoder.forString.contramap(_.name)
given Decoder[Visibility] = Decoder.forString.mapEither(Visibility.fromString)

def fromString(v: String): Either[String, Visibility] =
Visibility.values
.find(_.name.equalsIgnoreCase(v))
.toRight(s"Invalid visibility: $v")

def unsafeFromString(v: String): Visibility =
fromString(v).fold(sys.error, identity)
Loading

0 comments on commit ccdbbd9

Please sign in to comment.