Skip to content

Commit

Permalink
Merge pull request #602 from opatrascoiu/master
Browse files Browse the repository at this point in the history
Add support for DMN 1.4
  • Loading branch information
opatrascoiu authored Oct 30, 2023
2 parents 92244a9 + 575ccf8 commit 8d19c78
Show file tree
Hide file tree
Showing 1,099 changed files with 233,842 additions and 3,916 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: "build jdk 19"
name: "build jdk 20"

on:
[ push, pull_request ]
Expand All @@ -8,11 +8,11 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up JDK 19
- name: Set up JDK Latest
uses: actions/setup-java@v3
with:
distribution: 'oracle'
java-version: '19'
java-version: '20'
- name: Set up Python 3.10
uses: actions/setup-python@v3
with:
Expand Down
2 changes: 0 additions & 2 deletions dmn-aggregate/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,6 @@
<exclude>org/omg/**/*</exclude>
<!-- JPA integration -->
<exclude>com/gs/jpa/**/*</exclude>
<!-- Signavio integration -->
<exclude>com/gs/**/jmh/**/*</exclude>
</excludes>
</configuration>
<executions>
Expand Down
17 changes: 2 additions & 15 deletions dmn-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,7 @@
<dependency>
<groupId>org.fitnesse</groupId>
<artifactId>fitnesse</artifactId>
<version>20221219</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-jdk14</artifactId>
</exclusion>
</exclusions>
<version>20230503</version>
<scope>test</scope>
</dependency>

Expand All @@ -125,13 +119,6 @@
<scope>test</scope>
</dependency>

<dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
<version>3.2.2</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>com.google.googlejavaformat</groupId>
<artifactId>google-java-format</artifactId>
Expand All @@ -141,7 +128,7 @@
<dependency>
<groupId>com.thoughtworks.xstream</groupId>
<artifactId>xstream</artifactId>
<version>1.4.19</version>
<version>1.4.20</version>
</dependency>

</dependencies>
Expand Down
62 changes: 48 additions & 14 deletions dmn-core/src/main/java/com/gs/dmn/DMNModelRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ public class DMNModelRepository {
protected final List<TDefinitions> allDefinitions = new ArrayList<>();
protected final Map<String, TDefinitions> namespaceToDefinitions = new LinkedHashMap<>();
protected final Map<TNamedElement, TDefinitions> elementToDefinitions = new LinkedHashMap<>();
protected List<TBusinessKnowledgeModel> businessKnowledgeModels;
protected List<TInvocable> invocables;
protected List<TItemDefinition> itemDefinitions;
protected Map<String, TDRGElement> drgElementByName = new LinkedHashMap<>();
protected Map<String, TBusinessKnowledgeModel> knowledgeModelByName = new LinkedHashMap<>();
protected Map<String, TInvocable> invocablesByName = new LinkedHashMap<>();
protected Map<String, TDRGElement> drgElementByRef = new LinkedHashMap<>();
protected Map<TDefinitions, List<TDRGElement>> drgElementsByModel = new LinkedHashMap<>();
protected Map<TDefinitions, List<TDecision>> decisionsByModel = new LinkedHashMap<>();
Expand Down Expand Up @@ -260,14 +260,14 @@ public String getModelName(TNamedElement element) {
return definitions == null ? null : definitions.getName();
}

private List<TBusinessKnowledgeModel> findAllBKMs() {
if (this.businessKnowledgeModels == null) {
this.businessKnowledgeModels = new ArrayList<>();
private List<TInvocable> findAllInvocables() {
if (this.invocables == null) {
this.invocables = new ArrayList<>();
for (TDefinitions definitions: this.allDefinitions) {
collectBKMs(definitions, this.businessKnowledgeModels);
collectInvocables(definitions, this.invocables);
}
}
return this.businessKnowledgeModels;
return this.invocables;
}

private List<TItemDefinition> findAllItemDefinitions() {
Expand Down Expand Up @@ -376,6 +376,14 @@ protected void collectDSs(TDefinitions definitions, List<TDecisionService> resul
}
}

protected void collectInvocables(TDefinitions definitions, List<TInvocable> result) {
for (TDRGElement element: definitions.getDrgElement()) {
if (element instanceof TInvocable) {
result.add((TInvocable) element);
}
}
}

public boolean hasComponents(TItemDefinition itemDefinition) {
return !this.isEmpty(itemDefinition.getItemComponent());
}
Expand Down Expand Up @@ -534,18 +542,18 @@ protected TDefinitions findChildDefinitions(TDRGElement parent, String href) {
}
}

public TBusinessKnowledgeModel findKnowledgeModelByName(String name) {
TBusinessKnowledgeModel result = this.knowledgeModelByName.get(name);
public TInvocable findInvocableByName(String name) {
TInvocable result = this.invocablesByName.get(name);
if (result == null) {
List<TBusinessKnowledgeModel> value = new ArrayList<>();
for (TBusinessKnowledgeModel knowledgeModel: findAllBKMs()) {
if (sameName(knowledgeModel, name)) {
value.add(knowledgeModel);
List<TInvocable> value = new ArrayList<>();
for (TInvocable invocable: findAllInvocables()) {
if (sameName(invocable, name)) {
value.add(invocable);
}
}
if (value.size() == 1) {
result = value.get(0);
this.knowledgeModelByName.put(name, result);
this.invocablesByName.put(name, result);
} else if (value.size() > 1) {
throw new DMNRuntimeException(String.format("Found %s business knowledge models for name='%s'", value.size(), name));
}
Expand Down Expand Up @@ -932,6 +940,32 @@ public boolean isFunctionDefinitionExpression(TDRGElement element) {
return expression instanceof TFunctionDefinition;
}

public boolean isConditionalExpression(TDRGElement element) {
TExpression expression = expression(element);
return expression instanceof TConditional;
}

public boolean isFilterExpression(TDRGElement element) {
TExpression expression = expression(element);
return expression instanceof TFilter;
}

public boolean isForExpression(TDRGElement element) {
TExpression expression = expression(element);
return expression instanceof TFor;
}

public boolean isSomeExpression(TDRGElement element) {
TExpression expression = expression(element);
return expression instanceof TSome;
}

public boolean isEveryExpression(TDRGElement element) {
TExpression expression = expression(element);
return expression instanceof TEvery;
}


//
// Item definition related functions
//
Expand Down
2 changes: 1 addition & 1 deletion dmn-core/src/main/java/com/gs/dmn/NameUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public static String removeDoubleQuotes(String key) {
}
}

public static String bkmName(String text) {
public static String invocableName(String text) {
if (StringUtils.isBlank(text)) {
return text;
} else {
Expand Down
99 changes: 99 additions & 0 deletions dmn-core/src/main/java/com/gs/dmn/ast/DefaultDMNVisitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,95 @@ public <C> Object visit(TUnaryTests element, C context) {
return element;
}

@Override
public <C> Object visit(TConditional element, C context) {
visitTExpressionProperties(element, context);
TChildExpression ifExp = element.getIf();
if (ifExp != null) {
ifExp.accept(this, context);
}
TChildExpression thenExp = element.getThen();
if (thenExp != null) {
thenExp.accept(this, context);
}
TChildExpression elseExp = element.getElse();
if (elseExp != null) {
elseExp.accept(this, context);
}
return element;
}

@Override
public <C> Object visit(TFor element, C context) {
visitTExpressionProperties(element, context);
TChildExpression inExp = element.getIn();
if (inExp != null) {
inExp.accept(this, context);
}
TChildExpression returnExp = element.getReturn();
if (returnExp != null) {
returnExp.accept(this, context);
}
return element;
}

@Override
public <C> Object visit(TFilter element, C context) {
visitTExpressionProperties(element, context);
TChildExpression inExp = element.getIn();
if (inExp != null) {
inExp.accept(this, context);
}
TChildExpression matchExp = element.getMatch();
if (matchExp != null) {
matchExp.accept(this, context);
}
return element;
}

@Override
public <C> Object visit(TEvery element, C context) {
visitTExpressionProperties(element, context);
visitTQuantifiedProperties(element, context);
return element;
}

@Override
public <C> Object visit(TSome element, C context) {
visitTExpressionProperties(element, context);
visitTQuantifiedProperties(element, context);
return element;
}

@Override
public <C> Object visit(TChildExpression element, C context) {
TExpression exp = element.getExpression();
if (exp != null) {
visitTExpression(exp, context);
}
return element;
}

@Override
public <C> Object visit(TTypedChildExpression element, C context) {
TExpression exp = element.getExpression();
if (exp != null) {
visitTExpression(exp, context);
}
return element;
}

private <C> void visitTQuantifiedProperties(TQuantified element, C context) {
TChildExpression inExp = element.getIn();
if (inExp != null) {
inExp.accept(this, context);
}
TChildExpression satisfiesExp = element.getSatisfies();
if (satisfiesExp != null) {
satisfiesExp.accept(this, context);
}
}

// Requirements
@Override
public <C> Object visit(TAuthorityRequirement element, C context) {
Expand Down Expand Up @@ -638,6 +727,16 @@ private <C> void visitTExpression(TExpression element, C context) {
((TRelation) element).accept(this, context);
} else if (element instanceof TUnaryTests) {
((TUnaryTests) element).accept(this, context);
} else if (element instanceof TConditional) {
((TConditional) element).accept(this, context);
} else if (element instanceof TFor) {
((TFor) element).accept(this, context);
} else if (element instanceof TFilter) {
((TFilter) element).accept(this, context);
} else if (element instanceof TEvery) {
((TEvery) element).accept(this, context);
} else if (element instanceof TSome) {
((TSome) element).accept(this, context);
}
}

Expand Down
40 changes: 40 additions & 0 deletions dmn-core/src/main/java/com/gs/dmn/ast/ObjectFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,46 @@ public TList createTList() {
return new TList();
}

/**
* Create an instance of {@link TConditional }
*
*/
public TConditional createTConditional() {
return new TConditional();
}

/**
* Create an instance of {@link TFilter }
*
*/
public TFilter createTFilter() {
return new TFilter();
}

/**
* Create an instance of {@link TFor }
*
*/
public TFor createTFor() {
return new TFor();
}

/**
* Create an instance of {@link TSome }
*
*/
public TSome createTSome() {
return new TSome();
}

/**
* Create an instance of {@link TEvery }
*
*/
public TEvery createTEvery() {
return new TEvery();
}

/**
* Create an instance of {@link TDecisionService }
*
Expand Down
45 changes: 45 additions & 0 deletions dmn-core/src/main/java/com/gs/dmn/ast/TChildExpression.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Copyright 2016 Goldman Sachs.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
*
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/
package com.gs.dmn.ast;

import com.fasterxml.jackson.annotation.JsonPropertyOrder;

@JsonPropertyOrder({
"id",
"expression"
})
public class TChildExpression extends DMNBaseElement implements Visitable {
protected String id;
protected TExpression expression;

public String getId() {
return id;
}

public void setId(String id) {
this.id = id;
}

public TExpression getExpression() {
return expression;
}

public void setExpression(TExpression expression) {
this.expression = expression;
}

@Override
public <C> Object accept(Visitor visitor, C context) {
return visitor.visit(this, context);
}
}
Loading

0 comments on commit 8d19c78

Please sign in to comment.