Skip to content

Commit

Permalink
Sequences of labels now render distinct values
Browse files Browse the repository at this point in the history
  • Loading branch information
rousso committed Oct 20, 2023
1 parent 1288d0e commit 7b561c8
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 71 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
<sdk.antlr4.dir>${project.build.directory}/eforms-sdk/antlr4</sdk.antlr4.dir>

<!-- Versions - eForms -->
<version.eforms-core>1.0.6-SNAPSHOT</version.eforms-core>
<version.eforms-core>1.2.0-SNAPSHOT</version.eforms-core>

<!-- Versions - Third-party libraries -->
<version.antlr4>4.9.3</version.antlr4>
Expand Down
60 changes: 33 additions & 27 deletions src/main/java/eu/europa/ted/efx/sdk1/EfxTemplateTranslatorV1.java
Original file line number Diff line number Diff line change
Expand Up @@ -303,36 +303,42 @@ private void shorthandIndirectLabelReference(final String fieldId) {
this.script.composeVariableReference("item", StringExpression.class));
switch (fieldType) {
case "indicator":
this.stack.push(this.markup.renderLabelFromExpression(this.script.composeForExpression(
this.script.composeIteratorList(
List.of(
this.script.composeIteratorExpression(loopVariable.declarationExpression, valueReference))),
this.script.composeStringConcatenation(
List.of(this.script.getStringLiteralFromUnquotedString(ASSET_TYPE_INDICATOR),
this.script.getStringLiteralFromUnquotedString("|"),
this.script.getStringLiteralFromUnquotedString(LABEL_TYPE_WHEN),
this.script.getStringLiteralFromUnquotedString("-"),
new StringExpression(loopVariable.referenceExpression.getScript()),
this.script.getStringLiteralFromUnquotedString("|"),
this.script.getStringLiteralFromUnquotedString(fieldId))),
StringSequenceExpression.class)));
this.stack.push(this.markup.renderLabelFromExpression(
this.script.composeDistinctValuesFunction(
this.script.composeForExpression(
this.script.composeIteratorList(
List.of(
this.script.composeIteratorExpression(loopVariable.declarationExpression, valueReference))),
this.script.composeStringConcatenation(
List.of(this.script.getStringLiteralFromUnquotedString(ASSET_TYPE_INDICATOR),
this.script.getStringLiteralFromUnquotedString("|"),
this.script.getStringLiteralFromUnquotedString(LABEL_TYPE_WHEN),
this.script.getStringLiteralFromUnquotedString("-"),
new StringExpression(loopVariable.referenceExpression.getScript()),
this.script.getStringLiteralFromUnquotedString("|"),
this.script.getStringLiteralFromUnquotedString(fieldId))),
StringSequenceExpression.class),
StringSequenceExpression.class)));
break;
case "code":
case "internal-code":
this.stack.push(this.markup.renderLabelFromExpression(this.script.composeForExpression(
this.script.composeIteratorList(
List.of(
this.script.composeIteratorExpression(loopVariable.declarationExpression, valueReference))),
this.script.composeStringConcatenation(List.of(
this.script.getStringLiteralFromUnquotedString(ASSET_TYPE_CODE),
this.script.getStringLiteralFromUnquotedString("|"),
this.script.getStringLiteralFromUnquotedString(LABEL_TYPE_NAME),
this.script.getStringLiteralFromUnquotedString("|"),
this.script.getStringLiteralFromUnquotedString(
this.symbols.getRootCodelistOfField(fieldId)),
this.script.getStringLiteralFromUnquotedString("."),
new StringExpression(loopVariable.referenceExpression.getScript()))),
StringSequenceExpression.class)));
this.stack.push(this.markup.renderLabelFromExpression(
this.script.composeDistinctValuesFunction(
this.script.composeForExpression(
this.script.composeIteratorList(
List.of(
this.script.composeIteratorExpression(loopVariable.declarationExpression, valueReference))),
this.script.composeStringConcatenation(List.of(
this.script.getStringLiteralFromUnquotedString(ASSET_TYPE_CODE),
this.script.getStringLiteralFromUnquotedString("|"),
this.script.getStringLiteralFromUnquotedString(LABEL_TYPE_NAME),
this.script.getStringLiteralFromUnquotedString("|"),
this.script.getStringLiteralFromUnquotedString(
this.symbols.getRootCodelistOfField(fieldId)),
this.script.getStringLiteralFromUnquotedString("."),
new StringExpression(loopVariable.referenceExpression.getScript()))),
StringSequenceExpression.class),
StringSequenceExpression.class)));
break;
default:
throw new ParseCancellationException(String.format(
Expand Down
62 changes: 35 additions & 27 deletions src/main/java/eu/europa/ted/efx/sdk2/EfxTemplateTranslatorV2.java
Original file line number Diff line number Diff line change
Expand Up @@ -347,36 +347,44 @@ private void shorthandIndirectLabelReference(final String fieldId, final Numeric
this.script.composeVariableReference("item", StringExpression.class));
switch (fieldType) {
case "indicator":
this.stack.push(this.markup.renderLabelFromExpression(this.script.composeForExpression(
this.script.composeIteratorList(
List.of(
this.script.composeIteratorExpression(loopVariable.declarationExpression, valueReference))),
this.script.composeStringConcatenation(
List.of(this.script.getStringLiteralFromUnquotedString(ASSET_TYPE_INDICATOR),
this.script.getStringLiteralFromUnquotedString("|"),
this.script.getStringLiteralFromUnquotedString(LABEL_TYPE_WHEN),
this.script.getStringLiteralFromUnquotedString("-"),
new StringExpression(loopVariable.referenceExpression.getScript()),
this.script.getStringLiteralFromUnquotedString("|"),
this.script.getStringLiteralFromUnquotedString(fieldId))),
StringSequenceExpression.class), quantity));
this.stack.push(this.markup.renderLabelFromExpression(
this.script.composeDistinctValuesFunction(
this.script.composeForExpression(
this.script.composeIteratorList(
List.of(
this.script.composeIteratorExpression(loopVariable.declarationExpression, valueReference))),
this.script.composeStringConcatenation(
List.of(this.script.getStringLiteralFromUnquotedString(ASSET_TYPE_INDICATOR),
this.script.getStringLiteralFromUnquotedString("|"),
this.script.getStringLiteralFromUnquotedString(LABEL_TYPE_WHEN),
this.script.getStringLiteralFromUnquotedString("-"),
new StringExpression(loopVariable.referenceExpression.getScript()),
this.script.getStringLiteralFromUnquotedString("|"),
this.script.getStringLiteralFromUnquotedString(fieldId))),
StringSequenceExpression.class),
StringSequenceExpression.class),
quantity));
break;
case "code":
case "internal-code":
this.stack.push(this.markup.renderLabelFromExpression(this.script.composeForExpression(
this.script.composeIteratorList(
List.of(
this.script.composeIteratorExpression(loopVariable.declarationExpression, valueReference))),
this.script.composeStringConcatenation(List.of(
this.script.getStringLiteralFromUnquotedString(ASSET_TYPE_CODE),
this.script.getStringLiteralFromUnquotedString("|"),
this.script.getStringLiteralFromUnquotedString(LABEL_TYPE_NAME),
this.script.getStringLiteralFromUnquotedString("|"),
this.script.getStringLiteralFromUnquotedString(
this.symbols.getRootCodelistOfField(fieldId)),
this.script.getStringLiteralFromUnquotedString("."),
new StringExpression(loopVariable.referenceExpression.getScript()))),
StringSequenceExpression.class), quantity));
this.stack.push(this.markup.renderLabelFromExpression(
this.script.composeDistinctValuesFunction(
this.script.composeForExpression(
this.script.composeIteratorList(
List.of(
this.script.composeIteratorExpression(loopVariable.declarationExpression, valueReference))),
this.script.composeStringConcatenation(List.of(
this.script.getStringLiteralFromUnquotedString(ASSET_TYPE_CODE),
this.script.getStringLiteralFromUnquotedString("|"),
this.script.getStringLiteralFromUnquotedString(LABEL_TYPE_NAME),
this.script.getStringLiteralFromUnquotedString("|"),
this.script.getStringLiteralFromUnquotedString(
this.symbols.getRootCodelistOfField(fieldId)),
this.script.getStringLiteralFromUnquotedString("."),
new StringExpression(loopVariable.referenceExpression.getScript()))),
StringSequenceExpression.class),
StringSequenceExpression.class),
quantity));
break;
default:
throw new ParseCancellationException(String.format(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,42 +203,42 @@ void testShorthandBtLabelReference_MissingLabelType() {
@Test
void testShorthandIndirectLabelReferenceForIndicator() {
assertEquals(
"let block01() -> { label(for $item in ../IndicatorField return concat('indicator', '|', 'when', '-', $item, '|', 'BT-00-Indicator')) }\nfor-each(/*/PathNode/TextField).call(block01())",
"let block01() -> { label(distinct-values(for $item in ../IndicatorField return concat('indicator', '|', 'when', '-', $item, '|', 'BT-00-Indicator'))) }\nfor-each(/*/PathNode/TextField).call(block01())",
translateTemplate("{BT-00-Text} #{BT-00-Indicator}"));
}

@Test
void testShorthandIndirectLabelReferenceForCode() {
assertEquals(
"let block01() -> { label(for $item in ../CodeField/normalize-space(text()) return concat('code', '|', 'name', '|', 'main-activity', '.', $item)) }\nfor-each(/*/PathNode/TextField).call(block01())",
"let block01() -> { label(distinct-values(for $item in ../CodeField/normalize-space(text()) return concat('code', '|', 'name', '|', 'main-activity', '.', $item))) }\nfor-each(/*/PathNode/TextField).call(block01())",
translateTemplate("{BT-00-Text} #{BT-00-Code}"));
}

@Test
void testShorthandIndirectLabelReferenceForInternalCode() {
assertEquals(
"let block01() -> { label(for $item in ../InternalCodeField/normalize-space(text()) return concat('code', '|', 'name', '|', 'main-activity', '.', $item)) }\nfor-each(/*/PathNode/TextField).call(block01())",
"let block01() -> { label(distinct-values(for $item in ../InternalCodeField/normalize-space(text()) return concat('code', '|', 'name', '|', 'main-activity', '.', $item))) }\nfor-each(/*/PathNode/TextField).call(block01())",
translateTemplate("{BT-00-Text} #{BT-00-Internal-Code}"));
}

@Test
void testShorthandIndirectLabelReferenceForCodeAttribute() {
assertEquals(
"let block01() -> { label(for $item in ../CodeField/@attribute return concat('code', '|', 'name', '|', 'main-activity', '.', $item)) }\nfor-each(/*/PathNode/TextField).call(block01())",
"let block01() -> { label(distinct-values(for $item in ../CodeField/@attribute return concat('code', '|', 'name', '|', 'main-activity', '.', $item))) }\nfor-each(/*/PathNode/TextField).call(block01())",
translateTemplate("{BT-00-Text} #{BT-00-CodeAttribute}"));
}

@Test
void testShorthandIndirectLabelReferenceForCodeAttribute_WithSameAttributeInContext() {
assertEquals(
"let block01() -> { label(for $item in ../@attribute return concat('code', '|', 'name', '|', 'main-activity', '.', $item)) }\nfor-each(/*/PathNode/CodeField/@attribute).call(block01())",
"let block01() -> { label(distinct-values(for $item in ../@attribute return concat('code', '|', 'name', '|', 'main-activity', '.', $item))) }\nfor-each(/*/PathNode/CodeField/@attribute).call(block01())",
translateTemplate("{BT-00-CodeAttribute} #{BT-00-CodeAttribute}"));
}

@Test
void testShorthandIndirectLabelReferenceForCodeAttribute_WithSameElementInContext() {
assertEquals(
"let block01() -> { label(for $item in ./@attribute return concat('code', '|', 'name', '|', 'main-activity', '.', $item)) }\nfor-each(/*/PathNode/CodeField).call(block01())",
"let block01() -> { label(distinct-values(for $item in ./@attribute return concat('code', '|', 'name', '|', 'main-activity', '.', $item))) }\nfor-each(/*/PathNode/CodeField).call(block01())",
translateTemplate("{BT-00-Code} #{BT-00-CodeAttribute}"));
}

Expand Down Expand Up @@ -297,7 +297,7 @@ void testShorthandLabelReferenceFromContext_WithNodeContext() {
@Test
void testShorthandIndirectLabelReferenceFromContextField() {
assertEquals(
"let block01() -> { label(for $item in ./normalize-space(text()) return concat('code', '|', 'name', '|', 'main-activity', '.', $item)) }\nfor-each(/*/PathNode/CodeField).call(block01())",
"let block01() -> { label(distinct-values(for $item in ./normalize-space(text()) return concat('code', '|', 'name', '|', 'main-activity', '.', $item))) }\nfor-each(/*/PathNode/CodeField).call(block01())",
translateTemplate("{BT-00-Code} #value"));
}

Expand All @@ -318,7 +318,7 @@ void testShorthandFieldValueReferenceFromContextField() {
@Test
void testShorthandFieldValueReferenceFromContextField_WithText() {
assertEquals(
"let block01() -> { text('blah ')label(for $item in ./normalize-space(text()) return concat('code', '|', 'name', '|', 'main-activity', '.', $item))text(' ')text('blah ')eval(./normalize-space(text()))text(' ')text('blah') }\nfor-each(/*/PathNode/CodeField).call(block01())",
"let block01() -> { text('blah ')label(distinct-values(for $item in ./normalize-space(text()) return concat('code', '|', 'name', '|', 'main-activity', '.', $item)))text(' ')text('blah ')eval(./normalize-space(text()))text(' ')text('blah') }\nfor-each(/*/PathNode/CodeField).call(block01())",
translateTemplate("{BT-00-Code} blah #value blah $value blah"));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -292,42 +292,42 @@ void testShorthandBtLabelReference_MissingLabelType() {
@Test
void testShorthandIndirectLabelReferenceForIndicator() {
assertEquals(
"let block01() -> { label(for $item in ../IndicatorField return concat('indicator', '|', 'when', '-', $item, '|', 'BT-00-Indicator')) }\nfor-each(/*/PathNode/TextField).call(block01())",
"let block01() -> { label(distinct-values(for $item in ../IndicatorField return concat('indicator', '|', 'when', '-', $item, '|', 'BT-00-Indicator'))) }\nfor-each(/*/PathNode/TextField).call(block01())",
translateTemplate("{BT-00-Text} #{BT-00-Indicator}"));
}

@Test
void testShorthandIndirectLabelReferenceForCode() {
assertEquals(
"let block01() -> { label(for $item in ../CodeField/normalize-space(text()) return concat('code', '|', 'name', '|', 'main-activity', '.', $item)) }\nfor-each(/*/PathNode/TextField).call(block01())",
"let block01() -> { label(distinct-values(for $item in ../CodeField/normalize-space(text()) return concat('code', '|', 'name', '|', 'main-activity', '.', $item))) }\nfor-each(/*/PathNode/TextField).call(block01())",
translateTemplate("{BT-00-Text} #{BT-00-Code}"));
}

@Test
void testShorthandIndirectLabelReferenceForInternalCode() {
assertEquals(
"let block01() -> { label(for $item in ../InternalCodeField/normalize-space(text()) return concat('code', '|', 'name', '|', 'main-activity', '.', $item)) }\nfor-each(/*/PathNode/TextField).call(block01())",
"let block01() -> { label(distinct-values(for $item in ../InternalCodeField/normalize-space(text()) return concat('code', '|', 'name', '|', 'main-activity', '.', $item))) }\nfor-each(/*/PathNode/TextField).call(block01())",
translateTemplate("{BT-00-Text} #{BT-00-Internal-Code}"));
}

@Test
void testShorthandIndirectLabelReferenceForCodeAttribute() {
assertEquals(
"let block01() -> { label(for $item in ../CodeField/@attribute return concat('code', '|', 'name', '|', 'main-activity', '.', $item)) }\nfor-each(/*/PathNode/TextField).call(block01())",
"let block01() -> { label(distinct-values(for $item in ../CodeField/@attribute return concat('code', '|', 'name', '|', 'main-activity', '.', $item))) }\nfor-each(/*/PathNode/TextField).call(block01())",
translateTemplate("{BT-00-Text} #{BT-00-CodeAttribute}"));
}

@Test
void testShorthandIndirectLabelReferenceForCodeAttribute_WithSameAttributeInContext() {
assertEquals(
"let block01() -> { label(for $item in ../@attribute return concat('code', '|', 'name', '|', 'main-activity', '.', $item)) }\nfor-each(/*/PathNode/CodeField/@attribute).call(block01())",
"let block01() -> { label(distinct-values(for $item in ../@attribute return concat('code', '|', 'name', '|', 'main-activity', '.', $item))) }\nfor-each(/*/PathNode/CodeField/@attribute).call(block01())",
translateTemplate("{BT-00-CodeAttribute} #{BT-00-CodeAttribute}"));
}

@Test
void testShorthandIndirectLabelReferenceForCodeAttribute_WithSameElementInContext() {
assertEquals(
"let block01() -> { label(for $item in ./@attribute return concat('code', '|', 'name', '|', 'main-activity', '.', $item)) }\nfor-each(/*/PathNode/CodeField).call(block01())",
"let block01() -> { label(distinct-values(for $item in ./@attribute return concat('code', '|', 'name', '|', 'main-activity', '.', $item))) }\nfor-each(/*/PathNode/CodeField).call(block01())",
translateTemplate("{BT-00-Code} #{BT-00-CodeAttribute}"));
}

Expand Down Expand Up @@ -386,7 +386,7 @@ void testShorthandLabelReferenceFromContext_WithNodeContext() {
@Test
void testShorthandIndirectLabelReferenceFromContextField() {
assertEquals(
"let block01() -> { label(for $item in ./normalize-space(text()) return concat('code', '|', 'name', '|', 'main-activity', '.', $item)) }\nfor-each(/*/PathNode/CodeField).call(block01())",
"let block01() -> { label(distinct-values(for $item in ./normalize-space(text()) return concat('code', '|', 'name', '|', 'main-activity', '.', $item))) }\nfor-each(/*/PathNode/CodeField).call(block01())",
translateTemplate("{BT-00-Code} #value"));
}

Expand All @@ -407,7 +407,7 @@ void testShorthandFieldValueReferenceFromContextField() {
@Test
void testShorthandFieldValueReferenceFromContextField_WithText() {
assertEquals(
"let block01() -> { text('blah ')label(for $item in ./normalize-space(text()) return concat('code', '|', 'name', '|', 'main-activity', '.', $item))text(' blah ')eval(./normalize-space(text()))text(' blah') }\nfor-each(/*/PathNode/CodeField).call(block01())",
"let block01() -> { text('blah ')label(distinct-values(for $item in ./normalize-space(text()) return concat('code', '|', 'name', '|', 'main-activity', '.', $item)))text(' blah ')eval(./normalize-space(text()))text(' blah') }\nfor-each(/*/PathNode/CodeField).call(block01())",
translateTemplate("{BT-00-Code} blah #value blah $value blah"));
}

Expand Down

0 comments on commit 7b561c8

Please sign in to comment.