Skip to content

Commit

Permalink
Merge pull request #101 from OP-TED/release/2.0.0-alpha.3
Browse files Browse the repository at this point in the history
Release/2.0.0 alpha.3
  • Loading branch information
bertrand-lorentz authored Feb 16, 2024
2 parents 80b40c2 + de77851 commit 05b0a51
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 20 deletions.
14 changes: 3 additions & 11 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,13 @@
# EFX Toolkit 2.0.0-alpha.2 Release Notes
# EFX Toolkit 2.0.0-alpha.3 Release Notes

_The EFX Toolkit for Java developers is a library that enables the transpilation of [EFX](https://docs.ted.europa.eu/eforms/latest/efx) expressions and templates to different target languages. It also includes an implementation of an EFX-to-XPath transpiler._

---

## In this release

This release improves translation of EFX-1 templates as follows:

- Renders sequences of labels when a sequence expression is used to provide asset-ids.
- Renders distinct labels from sequences.
- Improves date and time formatting.

This release also includes a refactoring that moved XPath processing classes to the eForms Core Library 1.2.0 to improve reusability.

There are no changes in EFX-2 translation included in this release.

This release fixes an a bug that caused an exception to be thrown by XSLT processors when trying to format sequences of dates or times.
This bug was reported by a user in [eForms Notice Viewer issue #88](https://github.com/OP-TED/eforms-notice-viewer/issues/88).

## EFX-1 Support

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<groupId>eu.europa.ted.eforms</groupId>
<artifactId>efx-toolkit-java</artifactId>
<version>2.0.0-alpha.2</version>
<version>2.0.0-alpha.3</version>
<packaging>jar</packaging>

<name>EFX Toolkit for Java</name>
Expand Down
27 changes: 25 additions & 2 deletions src/main/java/eu/europa/ted/efx/sdk1/EfxTemplateTranslatorV1.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,11 @@
import eu.europa.ted.efx.model.expressions.TypedExpression;
import eu.europa.ted.efx.model.expressions.path.PathExpression;
import eu.europa.ted.efx.model.expressions.path.StringPathExpression;
import eu.europa.ted.efx.model.expressions.scalar.DateExpression;
import eu.europa.ted.efx.model.expressions.scalar.StringExpression;
import eu.europa.ted.efx.model.expressions.sequence.DateSequenceExpression;
import eu.europa.ted.efx.model.expressions.sequence.StringSequenceExpression;
import eu.europa.ted.efx.model.expressions.sequence.TimeSequenceExpression;
import eu.europa.ted.efx.model.templates.ContentBlock;
import eu.europa.ted.efx.model.templates.ContentBlockStack;
import eu.europa.ted.efx.model.templates.Markup;
Expand Down Expand Up @@ -496,9 +499,29 @@ public void exitStandardExpressionBlock(StandardExpressionBlockContext ctx) {
// functions.
if (TypedExpression.class.isAssignableFrom(expression.getClass())) {
if (EfxDataType.Date.class.isAssignableFrom(((TypedExpression) expression).getDataType())) {
expression = new StringExpression("format-date(" + expression.getScript() + ", '[D01]/[M01]/[Y0001]')");

var loopVariable = new Variable("item",
this.script.composeVariableDeclaration("item", DateExpression.class), DateExpression.empty(),
this.script.composeVariableReference("item", DateExpression.class));

expression = this.script.composeForExpression(
this.script.composeIteratorList(
List.of(this.script.composeIteratorExpression(loopVariable.declarationExpression,
new DateSequenceExpression(expression.getScript())))),
new StringExpression("format-date($item, '[D01]/[M01]/[Y0001]')"),
StringSequenceExpression.class);
} else if (EfxDataType.Time.class.isAssignableFrom(((TypedExpression) expression).getDataType())) {
expression = new StringExpression("format-time(" + expression.getScript() + ", '[H01]:[m01] [Z]')");

var loopVariable = new Variable("item",
this.script.composeVariableDeclaration("item", DateExpression.class), DateExpression.empty(),
this.script.composeVariableReference("item", DateExpression.class));

expression = this.script.composeForExpression(
this.script.composeIteratorList(
List.of(this.script.composeIteratorExpression(loopVariable.declarationExpression,
new TimeSequenceExpression(expression.getScript())))),
new StringExpression("format-time($item, '[H01]:[m01] [Z]')"),
StringSequenceExpression.class);
}
}

Expand Down
26 changes: 24 additions & 2 deletions src/main/java/eu/europa/ted/efx/sdk2/EfxTemplateTranslatorV2.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@
import eu.europa.ted.efx.model.expressions.scalar.ScalarExpression;
import eu.europa.ted.efx.model.expressions.scalar.StringExpression;
import eu.europa.ted.efx.model.expressions.scalar.TimeExpression;
import eu.europa.ted.efx.model.expressions.sequence.DateSequenceExpression;
import eu.europa.ted.efx.model.expressions.sequence.StringSequenceExpression;
import eu.europa.ted.efx.model.expressions.sequence.TimeSequenceExpression;
import eu.europa.ted.efx.model.templates.ContentBlock;
import eu.europa.ted.efx.model.templates.ContentBlockStack;
import eu.europa.ted.efx.model.templates.Markup;
Expand Down Expand Up @@ -559,9 +561,29 @@ public void exitStandardExpressionBlock(StandardExpressionBlockContext ctx) {
// functions.
if (TypedExpression.class.isAssignableFrom(expression.getClass())) {
if (EfxDataType.Date.class.isAssignableFrom(((TypedExpression) expression).getDataType())) {
expression = new StringExpression("format-date(" + expression.getScript() + ", '[D01]/[M01]/[Y0001]')");

var loopVariable = new Variable("item",
this.script.composeVariableDeclaration("item", DateExpression.class), DateExpression.empty(),
this.script.composeVariableReference("item", DateExpression.class));

expression = this.script.composeForExpression(
this.script.composeIteratorList(
List.of(this.script.composeIteratorExpression(loopVariable.declarationExpression,
new DateSequenceExpression(expression.getScript())))),
new StringExpression("format-date($item, '[D01]/[M01]/[Y0001]')"),
StringSequenceExpression.class);
} else if (EfxDataType.Time.class.isAssignableFrom(((TypedExpression) expression).getDataType())) {
expression = new StringExpression("format-time(" + expression.getScript() + ", '[H01]:[m01] [Z]')");

var loopVariable = new Variable("item",
this.script.composeVariableDeclaration("item", DateExpression.class), DateExpression.empty(),
this.script.composeVariableReference("item", DateExpression.class));

expression = this.script.composeForExpression(
this.script.composeIteratorList(
List.of(this.script.composeIteratorExpression(loopVariable.declarationExpression,
new TimeSequenceExpression(expression.getScript())))),
new StringExpression("format-time($item, '[H01]:[m01] [Z]')"),
StringSequenceExpression.class);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -353,11 +353,11 @@ void testEndOfLineComments() {

@Test
void testImplicitFormatting_Dates() {
assertEquals("let block01() -> { eval(format-date(PathNode/StartDateField/xs:date(text()), '[D01]/[M01]/[Y0001]')) }\nfor-each(/*).call(block01())", translateTemplate("{ND-Root} ${BT-00-StartDate}"));
}
assertEquals("let block01() -> { eval(for $item in PathNode/StartDateField/xs:date(text()) return format-date($item, '[D01]/[M01]/[Y0001]')) }\nfor-each(/*).call(block01())", translateTemplate("{ND-Root} ${BT-00-StartDate}"));
}

@Test
void testImplicitFormatting_Times() {
assertEquals("let block01() -> { eval(format-time(PathNode/StartTimeField/xs:time(text()), '[H01]:[m01] [Z]')) }\nfor-each(/*).call(block01())", translateTemplate("{ND-Root} ${BT-00-StartTime}"));
}
assertEquals("let block01() -> { eval(for $item in PathNode/StartTimeField/xs:time(text()) return format-time($item, '[H01]:[m01] [Z]')) }\nfor-each(/*).call(block01())", translateTemplate("{ND-Root} ${BT-00-StartTime}"));
}
}

0 comments on commit 05b0a51

Please sign in to comment.