Skip to content

Commit

Permalink
🎨 Code cleanup and fixed application.conf (#8)
Browse files Browse the repository at this point in the history
* 🚚 move test module

* 🎨 code cleanup

* Update build.sbt

* 🔧 Re-add purified conf file
  • Loading branch information
ff137 authored Feb 8, 2024
1 parent c79d732 commit 8c7c8ab
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 34 deletions.
11 changes: 8 additions & 3 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ lazy val circeVersion = "0.14.2"
lazy val http4sVersion = "0.23.25"
lazy val http4sBlazeVersion = "0.23.16"
lazy val logbackVersion = "1.4.14"
lazy val munitVersion = "1.0.0-M11"
lazy val munitCEVersion = "2.0.0-M4"
lazy val pureconfigVersion = "0.17.5"
lazy val scalaTestVersion = "3.2.18"
lazy val slf4jVersion = "2.0.12"
Expand All @@ -45,6 +47,7 @@ lazy val commonSettings = Seq(
"releases" at "https://oss.sonatype.org/content/repositories/releases"
),
libraryDependencies ++= Seq(
"xyz.didx" %% "castanet" % castanetVersion,
"org.typelevel" %% "cats-effect" % catsEffectVersion,
"io.circe" %% "circe-core" % circeVersion,
"io.circe" %% "circe-parser" % circeVersion,
Expand All @@ -54,7 +57,6 @@ lazy val commonSettings = Seq(
"com.softwaremill.sttp.client3" %% "core" % sttpVersion,
"com.softwaremill.sttp.client3" %% "circe" % sttpVersion,
"com.softwaremill.sttp.client3" %% "async-http-client-backend-cats" % sttpVersion,
"xyz.didx" %% "castanet" % castanetVersion,
"com.softwaremill.sttp.tapir" %% "tapir-http4s-server" % tapirVersion,
"com.softwaremill.sttp.tapir" %% "tapir-json-circe" % tapirVersion,
"com.softwaremill.sttp.tapir" %% "tapir-swagger-ui-bundle" % tapirVersion,
Expand All @@ -65,6 +67,7 @@ lazy val commonSettings = Seq(
"org.http4s" %% "http4s-ember-server" % http4sVersion,
"org.slf4j" % "slf4j-nop" % slf4jVersion
) ++ Seq(
"xyz.didx" %% "castanet" % castanetVersion % Test,
"org.scalatest" %% "scalatest" % scalaTestVersion % Test,
"org.typelevel" %% "cats-effect" % catsEffectVersion % Test,
"io.circe" %% "circe-core" % circeVersion % Test,
Expand All @@ -75,7 +78,6 @@ lazy val commonSettings = Seq(
"com.softwaremill.sttp.client3" %% "circe" % sttpVersion % Test,
"com.softwaremill.sttp.client3" %% "core" % sttpVersion % Test,
"com.softwaremill.sttp.client3" %% "async-http-client-backend-cats" % sttpVersion % Test,
"xyz.didx" %% "castanet" % castanetVersion % Test,
"com.softwaremill.sttp.tapir" %% "tapir-http4s-server" % tapirVersion % Test,
"com.softwaremill.sttp.tapir" %% "tapir-json-circe" % tapirVersion % Test,
"com.softwaremill.sttp.tapir" %% "tapir-sttp-stub-server" % tapirVersion % Test,
Expand All @@ -85,7 +87,10 @@ lazy val commonSettings = Seq(
"org.http4s" %% "http4s-blaze-server" % http4sBlazeVersion % Test,
"org.http4s" %% "http4s-dsl" % http4sVersion % Test,
"org.http4s" %% "http4s-ember-server" % http4sVersion % Test,
"org.slf4j" % "slf4j-nop" % slf4jVersion % Test
"org.slf4j" % "slf4j-nop" % slf4jVersion % Test,
"org.scalameta" %% "munit" % munitVersion % Test,
"org.scalameta" %% "munit-scalacheck" % munitVersion % Test,
"org.typelevel" %% "munit-cats-effect" % munitCEVersion % Test
)
)
lazy val scalafixSettings = Seq(semanticdbEnabled := true)
14 changes: 14 additions & 0 deletions src/main/resources/application.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
purchase-proto {
places = ["start", "shopping-cart", "payment", "delivery", "end"]
transitions = ["order", "checkout", "deliver","done"]

start = { place = "start", weight = 2, initial-params = ["did","location"]}
end = "end"
weights = [
{start = "start", transition = "order", end = "shopping-cart", action = "create-order", action-params = ["order-date", "order-id", "order-name", "order-description", "order-amount"]},
{start = "shopping-cart", transition = "order", end = "shopping-cart", action = "create-order", action-params = ["order-date", "order-id", "order-name", "order-description", "order-amount", "checkout"]},
{start = "shopping-cart", transition = "checkout", end = "payment", action = "pay-order", action-params = ["order-id", "order-description", "order-amount"]},
{start = "payment", transition = "deliver", end = "delivery", action = "receive-order", action-params = ["order-id", "location"]},
{start = "delivery", transition = "done", end = "end", action = "complete-order", action-params = ["order-id", "order-amount"]},
]
}
26 changes: 6 additions & 20 deletions src/main/scala/xyz/didx/ConfigManager.scala
Original file line number Diff line number Diff line change
@@ -1,30 +1,18 @@
package xyz.didx

import cats.effect.IO
import cats.effect._
import cats.effect.*
import cats.effect.kernel.Sync
import cats.implicits._
import cats.implicits.*
import org.typelevel.log4cats.Logger
import org.typelevel.log4cats.slf4j.Slf4jLogger
import pureconfig.*
import pureconfig.generic.derivation.default.*

object ConfigManager {
given Logger[IO] = Slf4jLogger.getLogger[IO]
def info[F[_]: Sync: Logger](value: String) =
for
_ <- Logger[F].info("Logging at start of passForEasierUse")
something <- Sync[F].delay(println("I could do anything"))
// .onError{case e => Logger[F].error(e)("Something Went Wrong in passForEasierUse")}
_ <- Logger[F].info(s"$value")
yield something

// println(s"Main: $value")
// logger.info(s"$value"

def err[T](value: T)(using logger: Logger[IO]): IO[Unit] =
println(s"Main: $value")
logger.error(s"$value")
given Logger[IO] = Slf4jLogger.getLogger[IO]
def info[T](value: T): IO[Unit] = Logger[IO].info(s"$value")
def err[T](value: T): IO[Unit] = Logger[IO].error(s"$value")

case class WeightConf(
start: String,
Expand Down Expand Up @@ -71,11 +59,9 @@ object ConfigManager {
|""".stripMargin

def protocolConf(interfaceName: String): ProtocolConf =
// ConfigSource.default.at(s"$interfaceName-proto").load[ProtocolConf] match
ConfigSource.file("src/main/resources/application.conf").at(s"$interfaceName-proto").load[ProtocolConf] match

case Left(error) =>
err(s"Error: $error")
err(s"$error")
ProtocolConf(List(), List(), StartConf("", 0, List()), "", List())
case Right(conf) => conf

Expand Down
13 changes: 4 additions & 9 deletions src/main/scala/xyz/didx/PetriCompiler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import org.http4s.server.Router
import sttp.client3.HttpURLConnectionBackend
import sttp.client3.SttpBackend
import sttp.model.*
import sttp.tapir._
import sttp.tapir.generic.auto._
import sttp.tapir.json.circe._
import sttp.tapir.*
import sttp.tapir.generic.auto.*
import sttp.tapir.json.circe.*
import sttp.tapir.server.http4s.Http4sServerInterpreter
import sttp.tapir.swagger.bundle.SwaggerInterpreter
import xyz.didx.ConfigManager.ProtocolConf
Expand All @@ -32,9 +32,6 @@ import scala.collection.immutable.ListSet
case class PetriCompiler[F[_]](interfaceName: String)(using
logger: org.log4s.Logger
):

val x = this.getClass()

val protocolConf: ProtocolConf = ConfigManager.protocolConf(interfaceName)

val pl1: ListSet[String] =
Expand All @@ -47,8 +44,7 @@ case class PetriCompiler[F[_]](interfaceName: String)(using
val colourMap: Map[Colour, String] = paramList.zipWithIndex.map { case (k, v) =>
(Colour.fromOrdinal(v), k)
}.toMap
val paramMap: Map[String, Colour] =
colourMap.map(_.swap) // (m => m._2 -> m._1)
val paramMap: Map[String, Colour] = colourMap.map(_.swap)
val paramValues = colourMap.map((k, v) => k -> "")

val places: Map[String, Place] = protocolConf.places.map { p =>
Expand All @@ -70,7 +66,6 @@ case class PetriCompiler[F[_]](interfaceName: String)(using
.flatMap(w => w.actionParams)
p -> capacity
}.toMap
// println(s"places -> $places")

val transitions: Map[String, Transition] = protocolConf.transitions
.map(t => t -> Transition(t, CastanetService(), RPC(t, "", "")))
Expand Down
1 change: 0 additions & 1 deletion src/main/scala/xyz/didx/PetriRunner.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import scala.concurrent.ExecutionContext
*/

object PetriRunner extends IOApp:
// given logger[F[_]: Sync]: Logger[F] = Slf4jLogger.getLogger[F]
given logger: org.log4s.Logger = org.log4s.getLogger
given ec: ExecutionContext =
scala.concurrent.ExecutionContext.Implicits.global
Expand Down
1 change: 0 additions & 1 deletion src/main/scala/xyz/didx/StateManager.scala
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import cats.effect.kernel.Ref

import java.util.UUID
import scala.collection.immutable.HashMap
//import didcomm.DIDTypes.*

trait State
case class Context(id: String)
Expand Down
File renamed without changes.

0 comments on commit 8c7c8ab

Please sign in to comment.