From 7a3624b46906085fa9ceb5e441fbcd65ac577638 Mon Sep 17 00:00:00 2001 From: David Roon Date: Fri, 23 Aug 2019 00:35:28 +0200 Subject: [PATCH] fix link type (#185) * fix link type * ooops forgot to remove the println --- .../openlaw/parser/template/CompiledAgreement.scala | 3 +-- .../parser/template/variableTypes/LinkType.scala | 10 ++++++---- .../parser/template/variableTypes/SectionType.scala | 4 ++-- .../parser/template/variableTypes/VariableType.scala | 2 ++ .../parser/OpenlawTemplateLanguageParserSpec.scala | 4 ++-- .../openlaw/vm/OpenlawExecutionEngineSpec.scala | 2 -- 6 files changed, 13 insertions(+), 12 deletions(-) diff --git a/shared/src/main/scala/org/adridadou/openlaw/parser/template/CompiledAgreement.scala b/shared/src/main/scala/org/adridadou/openlaw/parser/template/CompiledAgreement.scala index 2f79b4b0c..1c7df1dd7 100644 --- a/shared/src/main/scala/org/adridadou/openlaw/parser/template/CompiledAgreement.scala +++ b/shared/src/main/scala/org/adridadou/openlaw/parser/template/CompiledAgreement.scala @@ -4,7 +4,6 @@ import java.time.Clock import cats.implicits._ import org.adridadou.openlaw.{OpenlawBigDecimal, OpenlawBoolean} -import org.adridadou.openlaw.parser.template import org.adridadou.openlaw.parser.template.variableTypes._ import org.adridadou.openlaw.result.{Failure, Result, Success} @@ -128,7 +127,7 @@ final case class CompiledAgreement( getAgreementElementsFromElement(renderedElements, variableDefinition.copy(name = VariableName(executionResult.generateAnonymousName(nbAnonymous + 1))), executionResult) case variableDefinition:VariableDefinition if !variableDefinition.isHidden => executionResult.getAliasOrVariableType(variableDefinition.name) match { - case Right(variableType @ SectionType) => + case Right(variableType: NoShowInFormButRender) => getDependencies(variableDefinition.name, executionResult).flatMap { dependencies => generateVariable(variableDefinition.name, Seq(), variableDefinition.formatter, executionResult).map { list => renderedElements :+ VariableElement(variableDefinition.name, Some(variableType), list, dependencies) diff --git a/shared/src/main/scala/org/adridadou/openlaw/parser/template/variableTypes/LinkType.scala b/shared/src/main/scala/org/adridadou/openlaw/parser/template/variableTypes/LinkType.scala index ce80ce6ec..b15b1fc60 100644 --- a/shared/src/main/scala/org/adridadou/openlaw/parser/template/variableTypes/LinkType.scala +++ b/shared/src/main/scala/org/adridadou/openlaw/parser/template/variableTypes/LinkType.scala @@ -9,12 +9,14 @@ import org.adridadou.openlaw.parser.template.formatters.Formatter import org.adridadou.openlaw.parser.template._ import org.adridadou.openlaw.result.{Failure, FailureException, Result, Success} -final case class LinkInfo(label: String, url:String) extends OpenlawNativeValue +object LinkInfo { + implicit val linkInfoEnc: Encoder[LinkInfo] = deriveEncoder + implicit val linkInfoDec: Decoder[LinkInfo] = deriveDecoder +} -case object LinkType extends VariableType(name = "Link") { +final case class LinkInfo(label: String, url:String) extends OpenlawNativeValue - private implicit val enc: Encoder[LinkInfo] = deriveEncoder - private implicit val dec: Decoder[LinkInfo] = deriveDecoder +case object LinkType extends VariableType(name = "Link") with NoShowInFormButRender { override def cast(value: String, executionResult: TemplateExecutionResult): Result[LinkInfo] = decode[LinkInfo](value).leftMap(FailureException(_)) diff --git a/shared/src/main/scala/org/adridadou/openlaw/parser/template/variableTypes/SectionType.scala b/shared/src/main/scala/org/adridadou/openlaw/parser/template/variableTypes/SectionType.scala index b54c46956..3d60ed29e 100644 --- a/shared/src/main/scala/org/adridadou/openlaw/parser/template/variableTypes/SectionType.scala +++ b/shared/src/main/scala/org/adridadou/openlaw/parser/template/variableTypes/SectionType.scala @@ -7,11 +7,11 @@ import io.circe.parser.decode import org.adridadou.openlaw.{OpenlawNativeValue, OpenlawString, OpenlawValue} import org.adridadou.openlaw.parser.template.formatters.Formatter import org.adridadou.openlaw.parser.template._ -import org.adridadou.openlaw.result.{Failure, FailureException, Result, Success, attempt} +import org.adridadou.openlaw.result.{Failure, FailureException, Result, Success} final case class SectionInfo(name: Option[String], numbering: String, value:String) extends OpenlawNativeValue -case object SectionType extends VariableType(name = "Section") with NoShowInForm { +case object SectionType extends VariableType(name = "Section") with NoShowInFormButRender { private implicit val enc: Encoder[SectionInfo] = deriveEncoder private implicit val dec: Decoder[SectionInfo] = deriveDecoder diff --git a/shared/src/main/scala/org/adridadou/openlaw/parser/template/variableTypes/VariableType.scala b/shared/src/main/scala/org/adridadou/openlaw/parser/template/variableTypes/VariableType.scala index f94788e0b..13804401c 100644 --- a/shared/src/main/scala/org/adridadou/openlaw/parser/template/variableTypes/VariableType.scala +++ b/shared/src/main/scala/org/adridadou/openlaw/parser/template/variableTypes/VariableType.scala @@ -22,6 +22,8 @@ import org.adridadou.openlaw.vm.Executions trait NoShowInForm +trait NoShowInFormButRender extends NoShowInForm + trait ActionValue { def nextActionSchedule(executionResult: TemplateExecutionResult, pastExecutions:Seq[OpenlawExecution]): Result[Option[LocalDateTime]] def identifier(executionResult:TemplateExecutionResult):Result[ActionIdentifier] diff --git a/shared/src/test/scala/org/adridadou/openlaw/parser/OpenlawTemplateLanguageParserSpec.scala b/shared/src/test/scala/org/adridadou/openlaw/parser/OpenlawTemplateLanguageParserSpec.scala index 5199b394e..8dee5c693 100644 --- a/shared/src/test/scala/org/adridadou/openlaw/parser/OpenlawTemplateLanguageParserSpec.scala +++ b/shared/src/test/scala/org/adridadou/openlaw/parser/OpenlawTemplateLanguageParserSpec.scala @@ -306,7 +306,7 @@ class OpenlawTemplateLanguageParserSpec extends FlatSpec with Matchers { val text = """[[link1:Link(label: 'Log In';url:'/login')]]""" executeTemplate(text) match { - case Right(executionResult) => + case Success(executionResult) => executionResult.getVariables(LinkType).size shouldBe 1 val link = executionResult.getVariableValues[LinkInfo](LinkType).right.value.head.underlying @@ -1373,7 +1373,7 @@ class OpenlawTemplateLanguageParserSpec extends FlatSpec with Matchers { structureType === NumberType shouldBe false val newExecutionResult = executeTemplate(text, Map("name1" -> structureType.internalFormat(OpenlawMap(Map(VariableName("first") -> OpenlawString("John"), VariableName("last") -> OpenlawString("Doe")))).right.value)).right.value - service.parseExpression("name1.first").flatMap(_.evaluate(newExecutionResult)).right.value.value.toString shouldBe ("John") + service.parseExpression("name1.first").flatMap(_.evaluate(newExecutionResult)).right.value.value.toString shouldBe "John" case Left(ex) => fail(ex) } diff --git a/shared/src/test/scala/org/adridadou/openlaw/vm/OpenlawExecutionEngineSpec.scala b/shared/src/test/scala/org/adridadou/openlaw/vm/OpenlawExecutionEngineSpec.scala index 7e6b2b15d..ae93e63f4 100644 --- a/shared/src/test/scala/org/adridadou/openlaw/vm/OpenlawExecutionEngineSpec.scala +++ b/shared/src/test/scala/org/adridadou/openlaw/vm/OpenlawExecutionEngineSpec.scala @@ -15,8 +15,6 @@ import org.scalatest.OptionValues._ import play.api.libs.json.Json import org.adridadou.openlaw.{OpenlawMap, _} -import scala.concurrent.Await - class OpenlawExecutionEngineSpec extends FlatSpec with Matchers { val parser = new OpenlawTemplateLanguageParserService(Clock.systemDefaultZone())