Skip to content
Open
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
2 changes: 2 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Scala Steward: Reformat with scalafmt 3.8.6
c8276942b5ee0d998aac15034433e7305e0c0313
2 changes: 1 addition & 1 deletion .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version = "3.8.3"
version = "3.8.6"
runner.dialect = scala213source3
maxColumn = 120
align.preset = most
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,37 +12,39 @@ 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 morphir.examples.booksandrecords

import com.fasterxml.jackson.annotation.{JsonAutoDetect, JsonProperty, JsonSubTypes, JsonTypeInfo}
import com.fasterxml.jackson.annotation.{ JsonAutoDetect, JsonProperty, JsonSubTypes, JsonTypeInfo }
import org.springframework.context.annotation.Bean;


object API {
type DealId = String
type DealId = String
type ProductId = String
type Price = Float
type Quantity = Int

type Price = Float
type Quantity = Int

// Commands
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type")
@JsonSubTypes(Array
(
new JsonSubTypes.Type(value = classOf[OpenDeal], name = "openDeal"),
new JsonSubTypes.Type(value = classOf[CloseDeal], name = "closeDeal")
))
@JsonSubTypes(
Array(
new JsonSubTypes.Type(value = classOf[OpenDeal], name = "openDeal"),
new JsonSubTypes.Type(value = classOf[CloseDeal], name = "closeDeal")
)
)
sealed trait DealCmd

@Bean
case class CloseDeal(@JsonProperty("dealId") dealId: DealId) extends DealCmd


@Bean
case class OpenDeal(@JsonProperty("dealId") dealId: DealId, @JsonProperty("productId") productId: ProductId, @JsonProperty("price") price: Price, @JsonProperty("quantity") quantity: Quantity) extends DealCmd
case class OpenDeal(
@JsonProperty("dealId") dealId: DealId,
@JsonProperty("productId") productId: ProductId,
@JsonProperty("price") price: Price,
@JsonProperty("quantity") quantity: Quantity
) extends DealCmd

// Events
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type")
Expand All @@ -57,16 +59,17 @@ object API {
case object InvalidQuantity extends RejectReason

@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type")
@JsonSubTypes(Array
(
new JsonSubTypes.Type(value = classOf[DealClosed], name = "dealClosed"),
new JsonSubTypes.Type(value = classOf[DealOpened], name = "dealOpened"),
new JsonSubTypes.Type(value = classOf[CommandRejected], name = "CommandRejected")
))
@JsonSubTypes(
Array(
new JsonSubTypes.Type(value = classOf[DealClosed], name = "dealClosed"),
new JsonSubTypes.Type(value = classOf[DealOpened], name = "dealOpened"),
new JsonSubTypes.Type(value = classOf[CommandRejected], name = "CommandRejected")
)
)
@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.ANY)
sealed trait DealEvent

case class DealOpened( id: DealId, productId: ProductId, price: Price, quantity: Quantity) extends DealEvent
case class DealOpened(id: DealId, productId: ProductId, price: Price, quantity: Quantity) extends DealEvent

case class DealClosed(dealId: DealId) extends DealEvent

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,43 +12,37 @@ 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 morphir.examples.booksandrecords

import morphir.examples.booksandrecords.API._
import morphir.examples.booksandrecords.model.State.Deal
import morphir.examples.booksandrecords.repository.DealRepository


object Logic {
def openDeal(command: OpenDeal, dealRepository: DealRepository) : DealEvent = {
val dealOptional = dealRepository.findById(command.dealId)

if (dealOptional.isPresent) {
new CommandRejected(command.dealId, DuplicateDeal, "Duplicated")
}
else if (command.price < 0) {
new CommandRejected(command.dealId, InvalidPrice, "Wrong Price")
}
else if (command.quantity < 0) {
new CommandRejected(command.dealId, InvalidQuantity, "Wrong Quantity")
}
else {
val deal = new Deal(command.dealId, command.productId, command.price, command.quantity)
dealRepository.save(deal)
new DealOpened(command.dealId, command.productId, command.price, command.quantity)
}
def openDeal(command: OpenDeal, dealRepository: DealRepository): DealEvent = {
val dealOptional = dealRepository.findById(command.dealId)

if (dealOptional.isPresent) {
new CommandRejected(command.dealId, DuplicateDeal, "Duplicated")
} else if (command.price < 0) {
new CommandRejected(command.dealId, InvalidPrice, "Wrong Price")
} else if (command.quantity < 0) {
new CommandRejected(command.dealId, InvalidQuantity, "Wrong Quantity")
} else {
val deal = new Deal(command.dealId, command.productId, command.price, command.quantity)
dealRepository.save(deal)
new DealOpened(command.dealId, command.productId, command.price, command.quantity)
}
}

def closeDeal(command: CloseDeal, dealRepository: DealRepository) : DealEvent = {
val dealOptional = dealRepository.findById(command.dealId)
def closeDeal(command: CloseDeal, dealRepository: DealRepository): DealEvent = {
val dealOptional = dealRepository.findById(command.dealId)

if (dealOptional.isPresent) {
dealRepository.deleteById(command.dealId)
new DealClosed(command.dealId)
}
else new CommandRejected(command.dealId, DealNotFound, "Deal Not Found")
}
}
if (dealOptional.isPresent) {
dealRepository.deleteById(command.dealId)
new DealClosed(command.dealId)
} else new CommandRejected(command.dealId, DealNotFound, "Deal Not Found")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,19 @@ 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 morphir.examples.booksandrecords.model;

import org.springframework.data.annotation.Id
import morphir.examples.booksandrecords.API._

object State {
case class Deal (
@Id
id : DealId,
productId : ProductId,
price : Price,
quantity : Quantity
)
}
case class Deal(
@Id
id: DealId,
productId: ProductId,
price: Price,
quantity: Quantity
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ 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 morphir.examples.booksandrecords.serviceImpl

Expand All @@ -31,4 +30,4 @@ import org.springframework.stereotype.Service
override def logic(dealCmd: API.DealCmd) =
processCmd(dealCmd, dealRepository)

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,18 @@ 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 morphir.examples.booksandrecords.processor

import morphir.examples.booksandrecords.API.{CloseDeal, DealCmd, DealEvent, OpenDeal}
import morphir.examples.booksandrecords.API.{ CloseDeal, DealCmd, DealEvent, OpenDeal }
import morphir.examples.booksandrecords.Logic._
import morphir.examples.booksandrecords.repository.DealRepository

object CmdProcessor {
def processCmd(cmd: DealCmd, dealRepository: DealRepository): DealEvent = {
def processCmd(cmd: DealCmd, dealRepository: DealRepository): DealEvent =
cmd match {
case cmd: OpenDeal => openDeal(cmd, dealRepository)
case cmd: OpenDeal => openDeal(cmd, dealRepository)
case cmd: CloseDeal => closeDeal(cmd, dealRepository)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,12 @@ 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 morphir.examples.booksandrecords.service

import morphir.examples.booksandrecords.API.{DealCmd, DealEvent}
import morphir.examples.booksandrecords.API.{ DealCmd, DealEvent }

trait ServiceStatefulApp {
def logic(dealCmd: DealCmd): DealEvent
}
}
6 changes: 3 additions & 3 deletions mill-build/build.mill.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package build
package build
import mill._, scalalib._

object `package` extends MillBuildRootModule {
Expand Down Expand Up @@ -30,8 +30,8 @@ object `package` extends MillBuildRootModule {
}
}

val forcedVersions = Seq(
val forcedVersions = Seq(
("com.google.guava", "guava", "32.0.1-jre"),
("org.yaml","snakeyaml","1.33")
("org.yaml", "snakeyaml", "1.33")
)
}
2 changes: 1 addition & 1 deletion mill-build/src/millbuild/CommonCoursierModule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@ trait CommonCoursierModule extends CoursierModule {
("com.google.protobuf", "protobuf-java", "3.21.2"),
("com.google.guava", "guava", "32.0.1-jre"),
("org.jsoup", "jsoup", "1.15.3"),
("org.yaml","snakeyaml","1.33")
("org.yaml", "snakeyaml", "1.33")
)
}
2 changes: 1 addition & 1 deletion mill-build/src/millbuild/MyBuild.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ object MyBuild extends ExternalModule {
BuildSettings.load()
}

def devMode = T.input { T.env.getOrElse("MORPHIR_SCALA_DEV_MODE", false) == "true" }
def devMode = T.input(T.env.getOrElse("MORPHIR_SCALA_DEV_MODE", false) == "true")

def showBuildSettings() = T.command {
val settings = buildSettings()
Expand Down
2 changes: 1 addition & 1 deletion mill-build/src/millbuild/crossplatform/CrossPlatform.scala
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ trait CrossPlatform extends Module with DynamicModule { self =>
def childPlatformModules: Seq[PlatformModule] =
millModuleDirectChildren.collect { case (m: PlatformModule @unchecked) => m }

def targetPlatforms: T[Seq[Platform]] = T { childPlatformModules.map(_.platform) }
def targetPlatforms: T[Seq[Platform]] = T(childPlatformModules.map(_.platform))

/// Try and resolve to an actual platform specific module if it exists (not expecting multiple but in theory it is possible)
def childPlatformModules(platform: Platform): Seq[PlatformModule] =
Expand Down
17 changes: 10 additions & 7 deletions mill-build/src/millbuild/crossplatform/Platform.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package millbuild.crossplatform

import upickle.default.{ReadWriter => RW, macroRW}
import upickle.default.{ ReadWriter => RW, macroRW }

sealed trait Platform extends Ordered[Platform] { self =>
val isJS: Boolean = self == Platform.JS
Expand All @@ -10,14 +10,17 @@ sealed trait Platform extends Ordered[Platform] { self =>
def name: String
def compare(that: Platform): Int = self.name.compare(that.name)

def suffixes: Seq[String] = Seq(self.name) ++ pairs.map {
case (a, b) => a + "-" + b
def suffixes: Seq[String] = Seq(self.name) ++ pairs.map { case (a, b) =>
a + "-" + b
}
final def pairs: Seq[(String, String)] =
Platform.all.filter(_ != self).map { p =>
if (self < p) (self.name, p.name)
else (p.name, self.name)
}.toSeq
Platform.all
.filter(_ != self)
.map { p =>
if (self < p) (self.name, p.name)
else (p.name, self.name)
}
.toSeq

override def toString = name
}
Expand Down
2 changes: 1 addition & 1 deletion mill-build/src/millbuild/deps.scala
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ object Deps {
}

case object `47Deg` {
val memeid4s = ivy"com.47deg::memeid4s:${Versions.`memeid4s`}"
val memeid4s = ivy"com.47deg::memeid4s:${Versions.`memeid4s`}"
}

case object geirsson {
Expand Down
22 changes: 12 additions & 10 deletions mill-build/src/millbuild/settings/BuildSettings.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package millbuild.settings
import zio.{ConfigProvider, Unsafe, Runtime}
import zio.{ ConfigProvider, Unsafe, Runtime }
import zio.config._
import zio.config.magnolia.deriveConfig
import zio.config.typesafe._
Expand All @@ -8,11 +8,11 @@ import com.typesafe.config.ConfigFactory
import zio.Config

final case class BuildSettings(
jvm: JvmBuildSettings = JvmBuildSettings(),
js: ScalaJsBuildSettings = ScalaJsBuildSettings(),
native: ScalaNativeBuildSettings = ScalaNativeBuildSettings(),
mill: MillSettings = MillSettings(),
scala: ScalaSettings = ScalaSettings()
jvm: JvmBuildSettings = JvmBuildSettings(),
js: ScalaJsBuildSettings = ScalaJsBuildSettings(),
native: ScalaNativeBuildSettings = ScalaNativeBuildSettings(),
mill: MillSettings = MillSettings(),
scala: ScalaSettings = ScalaSettings()
)

object BuildSettings {
Expand All @@ -31,15 +31,17 @@ object BuildSettings {
lazy val propertiesFileConfigProvider: ConfigProvider =
ConfigProvider.propsProvider.nested("morphir.build")

// .fromPropertiesFile((os.pwd / "build.user.properties").toIO)
// .fromPropertiesFile((os.pwd / "build.user.properties").toIO)

lazy val buildUserYamlFileConfigProvider =
ConfigProvider.fromYamlPath((os.pwd / "build.user.yaml").wrapped)

def load(): BuildSettings = Unsafe.unsafe { implicit u =>
Runtime.default.unsafe.run(
loadSettings()
).getOrThrowFiberFailure()
Runtime.default.unsafe
.run(
loadSettings()
)
.getOrThrowFiberFailure()
}

def loadSettings() =
Expand Down
2 changes: 1 addition & 1 deletion morphir/sdk/json/src/morphir/sdk/basics/Codec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@ object Codec {
/* Encoder / Decoder for Unit Type */
implicit val encodeUnit: Encoder[Unit] = _ => io.circe.Json.obj()

implicit val decodeUnit: Decoder[Unit] = (_: io.circe.HCursor) => Right({})
implicit val decodeUnit: Decoder[Unit] = (_: io.circe.HCursor) => Right {}

}
2 changes: 1 addition & 1 deletion project/modules/crossplatform.sc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import upickle.default.{ReadWriter => RW, macroRW}
import upickle.default.{ ReadWriter => RW, macroRW }

sealed trait Platform {
def name: String
Expand Down