Skip to content

Commit

Permalink
fix link type (#185)
Browse files Browse the repository at this point in the history
* fix link type

* ooops forgot to remove the println
  • Loading branch information
adridadou authored and jdville03 committed Aug 22, 2019
1 parent a47ea13 commit 7a3624b
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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}

Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(_))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down

0 comments on commit 7a3624b

Please sign in to comment.