Skip to content

Commit

Permalink
Upgrade scala 3
Browse files Browse the repository at this point in the history
  • Loading branch information
larousso committed Oct 11, 2024
1 parent 57e584d commit bf0d1fa
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 29 deletions.
35 changes: 17 additions & 18 deletions nio-server/app/models/ConsentFact.scala
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
package models

import cats.data.Validated._
import cats.implicits._
import cats.data.Validated.*
import cats.implicits.*
import controllers.ReadableEntity
import libs.xml.XMLRead
import libs.xml.XmlUtil.XmlCleaner
import libs.xml.implicits._
import libs.xml.syntax._
import play.api.libs.functional.syntax._
import play.api.libs.json.Reads._
import play.api.libs.json._
import libs.xml.implicits.*
import libs.xml.syntax.*
import play.api.libs.functional.syntax.*
import play.api.libs.json.Reads.*
import play.api.libs.json.*
import reactivemongo.api.bson.BSONObjectID
import utils.DateUtils
import utils.Result.AppErrors
import utils.Result.AppErrors._
import utils.Result.AppErrors.*
import utils.json.JsResultOps

import java.time.{Clock, LocalDateTime}
import scala.xml.{Elem, NodeSeq}
import scala.xml.{Elem, NodeBuffer, NodeSeq}
import scala.collection.Seq

case class Metadata(key: String, value: String)
Expand Down Expand Up @@ -64,7 +64,7 @@ case class Consent(key: String, label: String, checked: Boolean, expiredAt: Opti
<checked>
{checked}
</checked>
{expiredAt.map(l => <expiredAt>{l.format(DateUtils.utcDateFormatter)}</expiredAt>)}
{expiredAt.map(l => <expiredAt>{l.format(DateUtils.utcDateFormatter)}</expiredAt>).getOrElse(new NodeBuffer())}
</consent>.clean()
}

Expand Down Expand Up @@ -439,14 +439,13 @@ case class ConsentFact(
</lastUpdate>
<orgKey>
{orgKey.getOrElse("")}
</orgKey>{
if (metaData.isDefined)
metaData.map { md =>
<metaData>
{md.map(e => <metaDataEntry key={e._1} value={e._2}/>)}
</metaData>
}.get
}
</orgKey>
{metaData.map { md =>
<metaData>
{md.map(e => <metaDataEntry key={e._1} value={e._2}/>)}
</metaData>
}.getOrElse(new NodeBuffer())
}
</consentFact>.clean()

case class KeyPermissionGroup(group: String, permission: String)
Expand Down
17 changes: 6 additions & 11 deletions nio-server/test/models/ModelValidationSpec.scala
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package models

import java.time.{LocalDateTime, Clock}
import java.time.{Clock, LocalDateTime}
import org.scalatest.matchers.must.Matchers
import org.scalatest.wordspec.AnyWordSpecLike
import play.api.libs.json.JsValue
import utils.DateUtils
import utils.Result.AppErrors

import scala.xml.Elem
import scala.xml.{Elem, NodeBuffer}

class ModelValidationSpec extends AnyWordSpecLike with Matchers {

Expand Down Expand Up @@ -72,9 +72,7 @@ class ModelValidationSpec extends AnyWordSpecLike with Matchers {
"xml serialize/deserialize" in {

val xml: Elem = consentFact.asXml()
val consentFactEither: Either[AppErrors, ConsentFact] =
ConsentFact.fromXml(xml)

val consentFactEither: Either[AppErrors, ConsentFact] = ConsentFact.fromXml(xml)
consentFactEither.isRight must be(true)

val consentFactFromXml: ConsentFact = consentFactEither.toOption.get
Expand Down Expand Up @@ -152,13 +150,11 @@ class ModelValidationSpec extends AnyWordSpecLike with Matchers {
</groups>
<invalidLastUpdate>{consentFact.lastUpdate.format(DateUtils.utcDateFormatter)}</invalidLastUpdate>
<invalidOrgKey>{consentFact.orgKey.getOrElse("")}</invalidOrgKey>
{
if (consentFact.metaData.isDefined)
consentFact.metaData.map { md =>
{consentFact.metaData.map { md =>
<metaData>
{md.map(e => <metaDataEntry invalidKey={e._1} invalidValue={e._2}/>)}
</metaData>
}.get
}.getOrElse(new NodeBuffer())
}
</consentFact>

Expand Down Expand Up @@ -194,8 +190,7 @@ class ModelValidationSpec extends AnyWordSpecLike with Matchers {

consentFact.orgKey.get must be("orgKey")

consentFact.metaData.get.toSeq.head must be("key1", "value1")
consentFact.metaData.get.toSeq(1) must be("key2", "value2")
consentFact.metaData must be(Some(Map("key1" -> "value1", "key2" -> "value2")))
}
}

Expand Down

0 comments on commit bf0d1fa

Please sign in to comment.