Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
larousso committed Oct 9, 2024
1 parent cb7c61c commit 5f07674
Show file tree
Hide file tree
Showing 15 changed files with 37 additions and 43 deletions.
7 changes: 4 additions & 3 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import ReleaseTransformations._
import Dependencies._scalaVersion
import ReleaseTransformations.*

name := """nio"""
organization := "fr.maif"
scalaVersion := "2.13.11"
scalaVersion := _scalaVersion

lazy val root = (project in file("."))
.aggregate(
Expand All @@ -15,7 +16,7 @@ lazy val `nio-provider` = project

inThisBuild(
List(
scalaVersion := "2.13.14",
scalaVersion := _scalaVersion,
semanticdbEnabled := true,
semanticdbVersion := scalafixSemanticdb.revision
)
Expand Down
2 changes: 1 addition & 1 deletion manual/build.sbt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name := """nio-manual"""
organization := "fr.maif"
version := "2.0.4"
scalaVersion := "2.12.4"
scalaVersion := _scalaVersion

lazy val docs = (project in file("."))
.enablePlugins(ParadoxPlugin)
Expand Down
2 changes: 1 addition & 1 deletion nio-provider/app/actor/EventActor.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ object EventActor {

class EventActor(out: ActorRef) extends Actor {

override def preStart: Unit = context.system.eventStream.subscribe(self, classOf[NioEvent])
override def preStart(): Unit = context.system.eventStream.subscribe(self, classOf[NioEvent])

override def receive: Receive = { case e: NioEvent =>
NioLogger.info(s"Event actor received a message : ${e.tYpe}")
Expand Down
2 changes: 1 addition & 1 deletion nio-provider/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ lazy val `nio-provider` = (project in file("."))
.enablePlugins(NoPublish)
.disablePlugins(BintrayPlugin)

scalaVersion := "2.13.14"
scalaVersion := _scalaVersion

resolvers ++= Seq(
Resolver.jcenterRepo,
Expand Down
4 changes: 3 additions & 1 deletion nio-server/app/db/LastConsentFactMongoDataStore.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@ import reactivemongo.api.indexes.{Index, IndexType}
import utils.BSONUtils
import utils.Result.{AppErrors, ErrorMessage}

import scala.annotation.nowarn
import scala.concurrent.{ExecutionContext, Future}
import scala.util.Failure
import scala.collection.{immutable, Seq}
import scala.collection.{Seq, immutable}

@nowarn("msg=Will be removed when provided by Play-JSON itself")
class LastConsentFactMongoDataStore(val mongoApi: ReactiveMongoApi)(implicit val executionContext: ExecutionContext)
extends MongoDataStore[ConsentFact] {

Expand Down
2 changes: 2 additions & 0 deletions nio-server/app/db/MongoOpsDataStore.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ import org.apache.pekko.stream.scaladsl.Source
import reactivemongo.api.{Cursor, ReadPreference}
import reactivemongo.api.bson.collection.BSONCollection

import scala.annotation.nowarn
import scala.concurrent.{ExecutionContext, Future}
import scala.collection.Seq

@nowarn("msg=Will be removed when provided by Play-JSON itself")
object MongoOpsDataStore {

implicit class MongoDataStore(coll: BSONCollection)(implicit executionContext: ExecutionContext) {
Expand Down
2 changes: 2 additions & 0 deletions nio-server/app/db/OrganisationMongoDataStore.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ import reactivemongo.api.indexes.Index.Default
import reactivemongo.api.indexes.{Index, IndexType}
import utils.Result.{AppErrors, ErrorMessage}

import scala.annotation.nowarn
import scala.concurrent.{ExecutionContext, Future}
import scala.collection.{Seq, immutable}

@nowarn("msg=Will be removed when provided by Play-JSON itself")
class OrganisationMongoDataStore(val mongoApi: ReactiveMongoApi)(implicit val executionContext: ExecutionContext)
extends MongoDataStore[Organisation] {

Expand Down
26 changes: 3 additions & 23 deletions nio-server/app/db/UserMongoDataStore.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ import org.apache.pekko.stream.scaladsl.Source
import models._
import play.api.libs.json.{JsValue, Json, OFormat}
import play.modules.reactivemongo.ReactiveMongoApi
import reactivemongo.api.indexes.Index.Default
import reactivemongo.api.indexes.{Index, IndexType}

import scala.concurrent.{ExecutionContext, Future}
import scala.collection.{immutable, Seq}
import scala.collection.{Seq, immutable}

class UserMongoDataStore(val mongoApi: ReactiveMongoApi)(implicit val executionContext: ExecutionContext)
extends MongoDataStore[User] {
Expand All @@ -23,7 +24,7 @@ class UserMongoDataStore(val mongoApi: ReactiveMongoApi)(implicit val executionC

override def collectionName(tenant: String) = s"$tenant-users"

override def indices = Seq(
override def indices: Seq[Default] = Seq(
Index(
key = immutable.Seq("orgKey" -> IndexType.Ascending, "userId" -> IndexType.Ascending),
name = Some("orgKey_userId"),
Expand Down Expand Up @@ -78,27 +79,6 @@ class UserMongoDataStore(val mongoApi: ReactiveMongoApi)(implicit val executionC
.documentSource()
}

def streamAllConsentFactIds(tenant: String)(implicit m: Materializer): Future[Source[JsValue, Future[State]]] =
storedCollection(tenant).map { col =>
col
.find(
Json.obj(),
Some(Json.obj("_id" -> 0, "latestConsentFactId" -> 1))
)
.cursor[JsValue]()
.documentSource()
}

def streamAllUsersConsentFacts(tenant: String)(implicit m: Materializer): Future[Source[JsValue, Future[State]]] =
storedCollection(tenant).map { users =>
users
.aggregateWith[JsValue]() { framework =>
import framework.Lookup
List(Lookup(s"$tenant-consentFacts", "latestConsentFactId", "_id", "consentFact"))
}
.documentSource()
}

def deleteUserByTenant(tenant: String): Future[Boolean] =
storedCollection(tenant).flatMap { col =>
col.drop(failIfNotFound = false)
Expand Down
4 changes: 2 additions & 2 deletions nio-server/app/models/ApiKey.scala
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ object ApiKey extends ReadableEntity[ApiKey] {
def fromXml(xml: Elem): Either[AppErrors, ApiKey] =
readXml.read(xml, Some("ApiKey")).toEither

def fromJson(json: JsValue) =
def fromJson(json: JsValue): Either[AppErrors, ApiKey] =
json.validate[ApiKey] match {
case JsSuccess(o, _) => Right(o)
case JsError(errors) => Left(AppErrors.fromJsError(errors))
Expand All @@ -143,7 +143,7 @@ object ApiKey extends ReadableEntity[ApiKey] {
}

case class ApiKeys(page: Int, pageSize: Int, count: Long, items: Seq[ApiKey]) extends ModelTransformAs {
def asJson() =
def asJson(): JsObject =
Json.obj("page" -> page, "pageSize" -> pageSize, "count" -> count, "items" -> JsArray(items.map(_.asJson())))

def asXml() = <apiKeys>
Expand Down
4 changes: 2 additions & 2 deletions nio-server/app/models/NioAccount.scala
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,10 @@ object NioAccount extends ReadableEntity[NioAccount] {
}

case class NioAccounts(page: Int, pageSize: Int, count: Long, items: Seq[NioAccount]) extends ModelTransformAs {
def asJson() =
def asJson(): JsObject =
Json.obj("page" -> page, "pageSize" -> pageSize, "count" -> count, "items" -> JsArray(items.map(_.asJson())))

def asXml() = <nioAccounts>
def asXml(): Elem = <nioAccounts>
<page>
{page}
</page>
Expand Down
8 changes: 5 additions & 3 deletions nio-server/app/models/PagedConsentFacts.scala
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
package models

import play.api.libs.json.{JsArray, Json}
import play.api.libs.json.{JsArray, JsObject, Json}

import scala.collection.Seq
import scala.xml.Elem

case class PagedConsentFacts(page: Int, pageSize: Int, count: Long, items: Seq[ConsentFact]) extends ModelTransformAs {

def asJson() =
def asJson(): JsObject =
Json.obj("page" -> page, "pageSize" -> pageSize, "count" -> count, "items" -> JsArray(items.map(_.asJson())))

def asXml() = <pagedConsentFacts>
def asXml(): Elem = <pagedConsentFacts>
<page>{page}</page>
<pageSize>{pageSize}</pageSize>
<count>{count}</count>
Expand Down
8 changes: 5 additions & 3 deletions nio-server/app/models/PagedUsers.scala
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
package models

import play.api.libs.json.{JsArray, Json}
import play.api.libs.json.{JsArray, JsObject, Json}
import libs.xml.XmlUtil.XmlCleaner

import scala.collection.Seq
import scala.xml.Elem

case class PagedUsers(page: Int, pageSize: Int, count: Long, items: Seq[User]) extends ModelTransformAs {

def asJson() =
def asJson(): JsObject =
Json.obj(
"page" -> page,
"pageSize" -> pageSize,
"count" -> count,
"items" -> JsArray(items.map(u => Json.obj("userId" -> u.userId, "orgKey" -> u.orgKey)))
)

def asXml() = <pagedUsers>
def asXml(): Elem = <pagedUsers>
<page>{page}</page>
<pageSize>{pageSize}</pageSize>
<count>{count}</count>
Expand Down
2 changes: 1 addition & 1 deletion nio-server/app/models/Permission.scala
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ object Permission {

implicit val readXmlFiniteDuration: XMLRead[FiniteDuration] = (xml: NodeSeq, path: Option[String]) =>
Try(xml.head.text)
.map { str: String =>
.map { (str: String) =>
Try (Duration(str)) match {
case Success(value: FiniteDuration) => value.valid
case Success(_) => AppErrors.error("invalid duration").invalid
Expand Down
4 changes: 2 additions & 2 deletions nio-server/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ lazy val `nio-server` = (project in file("."))
.enablePlugins(NoPublish)
.disablePlugins(BintrayPlugin)

scalaVersion := "2.13.14"
scalaVersion := Dependencies._scalaVersion

resolvers ++= Seq(
Resolver.jcenterRepo,
Expand Down Expand Up @@ -60,7 +60,7 @@ scalacOptions ++= Seq(
"-language:higherKinds",
"-language:implicitConversions",
"-language:existentials",
"-Wunused"
"-Wunused:imports" //, "-Xsource:3"
)

/// ASSEMBLY CONFIG
Expand Down
3 changes: 3 additions & 0 deletions project/Dependencies.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
object Dependencies {

val _scalaVersion = "2.13.15"

val reactiveMongoVersion = "1.1.0"
val pekko = "1.1.1"
val pekkoKafka = "1.1.0"
Expand Down

0 comments on commit 5f07674

Please sign in to comment.