Skip to content

Commit

Permalink
Merge pull request apache#26 from Rikkola/migrate_to_j2cl_tools_yard
Browse files Browse the repository at this point in the history
yard migration
  • Loading branch information
treblereel authored Mar 26, 2024
2 parents c98b39a + b9856e6 commit a7d3428
Show file tree
Hide file tree
Showing 15 changed files with 77 additions and 56 deletions.
4 changes: 2 additions & 2 deletions packages/yard-model/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@

<dependencies>
<dependency>
<groupId>org.treblereel.gwt.yaml.mapper</groupId>
<groupId>org.kie.j2cl.tools.yaml.mapper</groupId>
<artifactId>common</artifactId>
<version>${yaml.mapper}</version>
</dependency>

<dependency>
<groupId>org.treblereel.gwt.yaml.mapper</groupId>
<groupId>org.kie.j2cl.tools.yaml.mapper</groupId>
<artifactId>processor</artifactId>
<version>${yaml.mapper}</version>
<scope>provided</scope>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
package org.yard.model;


import org.treblereel.gwt.yaml.api.annotation.YamlSubtype;
import org.treblereel.gwt.yaml.api.annotation.YamlTypeInfo;
import org.kie.j2cl.tools.yaml.mapper.api.annotation.YamlSubtype;
import org.kie.j2cl.tools.yaml.mapper.api.annotation.YamlTypeInfo;

@YamlTypeInfo(
key = "type",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
package org.yard.model;


import org.treblereel.gwt.yaml.api.annotation.YAMLMapper;
import org.treblereel.gwt.yaml.api.annotation.YamlTypeDeserializer;
import org.treblereel.gwt.yaml.api.annotation.YamlTypeSerializer;
import org.kie.j2cl.tools.yaml.mapper.api.annotation.YAMLMapper;
import org.kie.j2cl.tools.yaml.mapper.api.annotation.YamlTypeDeserializer;
import org.kie.j2cl.tools.yaml.mapper.api.annotation.YamlTypeSerializer;
import org.yard.model.RuleDefSerializer;

import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
package org.yard.model;


import org.treblereel.gwt.yaml.api.annotation.YAMLMapper;

import org.kie.j2cl.tools.yaml.mapper.api.annotation.YAMLMapper;

import java.util.List;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,12 @@

public class InlineRule implements Rule {

private final int rowNumber;
public List def;

public InlineRule(int rowNumber, List data) {
this.rowNumber = rowNumber;
public InlineRule(List data) {
this.def = data;
}

@Override
public int getRowNumber() {
return rowNumber;
}

public List getDef() {
return def;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
package org.yard.model;


import org.treblereel.gwt.yaml.api.annotation.YAMLMapper;
import org.kie.j2cl.tools.yaml.mapper.api.annotation.YAMLMapper;

@YAMLMapper
public class Input {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
package org.yard.model;


import org.treblereel.gwt.yaml.api.annotation.YAMLMapper;
import org.kie.j2cl.tools.yaml.mapper.api.annotation.YAMLMapper;

@YAMLMapper
public class LiteralExpression implements DecisionLogic {
Expand Down
1 change: 0 additions & 1 deletion packages/yard-model/src/main/java/org/yard/model/Rule.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,4 @@
package org.yard.model;

public interface Rule {
int getRowNumber();
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,22 @@
package org.yard.model;


import org.treblereel.gwt.yaml.api.node.YamlMapping;
import org.treblereel.gwt.yaml.api.node.YamlNode;
import org.treblereel.gwt.yaml.api.node.YamlSequence;
import org.treblereel.gwt.yaml.api.YAMLDeserializer;
import org.treblereel.gwt.yaml.api.YAMLSerializer;
import org.treblereel.gwt.yaml.api.exception.YAMLDeserializationException;
import org.treblereel.gwt.yaml.api.internal.deser.YAMLDeserializationContext;
import org.treblereel.gwt.yaml.api.internal.ser.YAMLSerializationContext;

import org.kie.j2cl.tools.yaml.mapper.api.YAMLDeserializer;
import org.kie.j2cl.tools.yaml.mapper.api.YAMLSerializer;
import org.kie.j2cl.tools.yaml.mapper.api.exception.YAMLDeserializationException;
import org.kie.j2cl.tools.yaml.mapper.api.internal.deser.YAMLDeserializationContext;
import org.kie.j2cl.tools.yaml.mapper.api.internal.ser.YAMLSerializationContext;
import org.kie.j2cl.tools.yaml.mapper.api.node.YamlMapping;
import org.kie.j2cl.tools.yaml.mapper.api.node.YamlNode;
import org.kie.j2cl.tools.yaml.mapper.api.node.YamlSequence;

import java.util.ArrayList;
import java.util.List;

public class RuleDefSerializer
implements YAMLSerializer<Object>, YAMLDeserializer<Object> {

private int rowNumber = 1;
@Override
public Object deserialize(YamlMapping yamlMapping,
String s,
Expand All @@ -47,10 +47,10 @@ public Object deserialize(YamlNode yamlNode,
YAMLDeserializationContext yamlDeserializationContext) {
if (yamlNode instanceof YamlSequence) {
final List<Comparable> items = getItems(yamlNode);
return new InlineRule(rowNumber++, items);
return new InlineRule(items);

} else if (yamlNode instanceof YamlMapping) {
final WhenThenRule whenThenRule = new WhenThenRule(rowNumber++);
final WhenThenRule whenThenRule = new WhenThenRule();
final YamlNode when = ((YamlMapping) yamlNode).getNode("when");
final YamlNode then = ((YamlMapping) yamlNode).getNode("then");
whenThenRule.setWhen(getItems(when));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,14 @@

public class WhenThenRule implements Rule {

private final int rowNumber;
private List when;
private Object then;

public WhenThenRule(int rowNumber) {
this.rowNumber = rowNumber;
}
public WhenThenRule() {

@Override
public int getRowNumber() {
return rowNumber;
}


public List getWhen() {
return when;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@
*/
package org.yard.model;

import org.treblereel.gwt.yaml.api.YAMLDeserializer;
import org.treblereel.gwt.yaml.api.YAMLSerializer;
import org.treblereel.gwt.yaml.api.exception.YAMLDeserializationException;
import org.treblereel.gwt.yaml.api.internal.deser.YAMLDeserializationContext;
import org.treblereel.gwt.yaml.api.internal.ser.YAMLSerializationContext;
import org.treblereel.gwt.yaml.api.node.YamlMapping;
import org.treblereel.gwt.yaml.api.node.YamlNode;
import org.treblereel.gwt.yaml.api.node.YamlSequence;

import org.kie.j2cl.tools.yaml.mapper.api.YAMLDeserializer;
import org.kie.j2cl.tools.yaml.mapper.api.YAMLSerializer;
import org.kie.j2cl.tools.yaml.mapper.api.exception.YAMLDeserializationException;
import org.kie.j2cl.tools.yaml.mapper.api.internal.deser.YAMLDeserializationContext;
import org.kie.j2cl.tools.yaml.mapper.api.internal.ser.YAMLSerializationContext;
import org.kie.j2cl.tools.yaml.mapper.api.node.YamlMapping;
import org.kie.j2cl.tools.yaml.mapper.api.node.YamlNode;
import org.kie.j2cl.tools.yaml.mapper.api.node.YamlSequence;

import java.util.Locale;

Expand Down
3 changes: 2 additions & 1 deletion packages/yard-model/src/main/java/org/yard/model/YaRD.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
package org.yard.model;


import org.treblereel.gwt.yaml.api.annotation.YAMLMapper;

import org.kie.j2cl.tools.yaml.mapper.api.annotation.YAMLMapper;

import java.util.List;

Expand Down
29 changes: 29 additions & 0 deletions packages/yard-validator-worker/deps.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
[INFO] Scanning for projects...
[INFO]
[INFO] ----------------< org.kie.kogito:yard-validator-worker >----------------
[INFO] Building yard-validator-worker 0.0.0
[INFO] from pom.xml
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- dependency:3.6.0:tree (default-cli) @ yard-validator-worker ---
[INFO] org.kie.kogito:yard-validator-worker:jar:0.0.0
[INFO] +- org.kie.j2cl.tools.yaml.mapper:common:jar:0.4:compile
[INFO] | +- com.google.jsinterop:base:jar:1.0.0:compile
[INFO] | | \- com.google.jsinterop:jsinterop-annotations:jar:1.0.2:compile
[INFO] | +- com.google.elemental2:elemental2-dom:jar:1.1.0:compile
[INFO] | | +- com.google.elemental2:elemental2-core:jar:1.1.0:compile
[INFO] | | \- com.google.elemental2:elemental2-promise:jar:1.1.0:compile
[INFO] | \- org.kie.j2cl.tools.yaml.mapper:snakeyaml-engine:jar:0.4:compile
[INFO] | +- org.kie.j2cl.tools.jakarta:stdlib:jar:0.3:compile
[INFO] | | \- com.google.elemental2:elemental2-webstorage:jar:1.1.0:compile
[INFO] | \- org.kie.j2cl.tools.nio:gwt-nio:jar:1.3:compile
[INFO] +- org.kie.kogito:yard-model:jar:0.0.0:compile
[INFO] +- org.kie.kogito:yard-model:jar:sources:0.0.0:compile
[INFO] \- junit:junit:jar:4.13.1:test
[INFO] \- org.hamcrest:hamcrest-core:jar:1.3:test
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.833 s
[INFO] Finished at: 2024-03-22T10:41:53+02:00
[INFO] ------------------------------------------------------------------------
10 changes: 5 additions & 5 deletions packages/yard-validator-worker/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,15 @@
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<surefire-plugin.version>3.0.0-M5</surefire-plugin.version>
<version.junit>4.13.1</version.junit>
<j2cl.maven.plugin.version>0.20</j2cl.maven.plugin.version>
<j2cl.maven.plugin.version>0.23.0</j2cl.maven.plugin.version>
<version.org.junit>4.13.1</version.org.junit>
</properties>

<dependencies>
<dependency>
<groupId>org.treblereel.gwt.yaml.mapper</groupId>
<groupId>org.kie.j2cl.tools.yaml.mapper</groupId>
<artifactId>common</artifactId>
<version>${yaml.mapper}</version>
<version>0.4</version>
</dependency>

<dependency>
Expand Down Expand Up @@ -85,9 +85,9 @@
</resources>
<plugins>
<plugin>
<groupId>com.vertispan.j2cl</groupId>
<groupId>org.kie.j2cl.tools</groupId>
<artifactId>j2cl-maven-plugin</artifactId>
<version>${j2cl.maven.plugin.version}</version>
<version>0.23.0</version>
<executions>
<execution>
<goals>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public ParserResult parse(final String yaml) {

try {

final YaRD model = new YaRD_YamlMapperImpl().read(yaml);
final YaRD model = YaRD_YamlMapperImpl.INSTANCE.read(yaml);

Logger.log("YaRD model has been read.");
Logger.log("YaRD model name is " + model.getName());
Expand Down Expand Up @@ -70,25 +70,27 @@ private TreeMap<RowLocation, CustomTreeSet> visit(
Logger.log("Hit policy is : " + hitPolicy);
hitPolicy = dt.getHitPolicy();

int tableRowNumber = 1;
final List<Rule> rules = dt.getRules();
for (final Rule rule : rules) {
if (rule instanceof WhenThenRule) {
final RowLocation location = new RowLocation(
rule.getRowNumber(),
rule.getRowNumber() * 2 - 1 + rulesRow);
tableRowNumber,
tableRowNumber * 2 - 1 + rulesRow);
final CustomTreeSet keys = getWhenThenKeys(dt, (WhenThenRule) rule, location);
if (!keys.isEmpty()) {
result.put(location, keys);
}
} else if (rule instanceof InlineRule) {
final RowLocation location = new RowLocation(
rule.getRowNumber(),
rule.getRowNumber() + rulesRow);
tableRowNumber,
tableRowNumber + rulesRow);
final CustomTreeSet keys = getInlineRuleKeys(dt, (InlineRule) rule, location);
if (!keys.isEmpty()) {
result.put(location, keys);
}
}
tableRowNumber++;
}
}
}
Expand Down

0 comments on commit a7d3428

Please sign in to comment.