forked from apache/incubator-kie-drools
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
AF-593: Decouple DMO from Drools (apache#596)
- Loading branch information
Showing
371 changed files
with
13,832 additions
and
13,589 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/target/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/target/ |
1 change: 1 addition & 0 deletions
1
drools-wb-extensions/drools-wb-drl-extension/drools-wb-drl-extension-server/.gitignore
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/target/ |
50 changes: 50 additions & 0 deletions
50
drools-wb-extensions/drools-wb-drl-extension/drools-wb-drl-extension-server/pom.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>org.drools</groupId> | ||
<artifactId>drools-wb-drl-extension</artifactId> | ||
<version>8.0.0-SNAPSHOT</version> | ||
</parent> | ||
|
||
<artifactId>drools-wb-drl-extension-server</artifactId> | ||
<packaging>jar</packaging> | ||
|
||
<name>Drools Workbench - Extensions - DRL - Server</name> | ||
<description>Drools Workbench - Extensions - DRL - Server</description> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.kie.workbench.services</groupId> | ||
<artifactId>kie-wb-common-datamodel-api</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.kie.workbench.services</groupId> | ||
<artifactId>kie-wb-common-services-backend</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.kie.workbench.services</groupId> | ||
<artifactId>kie-wb-common-datamodel-backend</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.drools</groupId> | ||
<artifactId>drools-compiler</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.drools</groupId> | ||
<artifactId>drools-workbench-models-datamodel-api</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.kie.soup</groupId> | ||
<artifactId>kie-soup-project-datamodel-api</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.uberfire</groupId> | ||
<artifactId>uberfire-nio2-model</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.slf4j</groupId> | ||
<artifactId>slf4j-api</artifactId> | ||
</dependency> | ||
</dependencies> | ||
</project> |
101 changes: 101 additions & 0 deletions
101
...n/java/org/kie/workbench/common/services/datamodel/backend/server/cache/DSLExtension.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
/* | ||
* Copyright 2017 Red Hat, Inc. and/or its affiliates. | ||
* | ||
* 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 org.kie.workbench.common.services.datamodel.backend.server.cache; | ||
|
||
import java.io.IOException; | ||
import java.io.StringReader; | ||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
import javax.enterprise.context.Dependent; | ||
|
||
import org.drools.compiler.lang.dsl.DSLMappingEntry; | ||
import org.drools.compiler.lang.dsl.DSLTokenizedMappingFile; | ||
import org.drools.workbench.models.datamodel.oracle.DSLActionSentence; | ||
import org.drools.workbench.models.datamodel.oracle.DSLConditionSentence; | ||
import org.drools.workbench.models.datamodel.rule.DSLSentence; | ||
import org.kie.soup.project.datamodel.oracle.ExtensionKind; | ||
import org.kie.workbench.common.services.backend.file.DSLFileFilter; | ||
import org.kie.workbench.common.services.datamodel.spi.DataModelExtension; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.uberfire.java.nio.file.DirectoryStream.Filter; | ||
import org.uberfire.java.nio.file.Path; | ||
|
||
@Dependent | ||
public class DSLExtension implements DataModelExtension { | ||
|
||
public static final DSLFileFilter DSL_FILE_FILTER = new DSLFileFilter(); | ||
private static final Logger log = LoggerFactory.getLogger(DSLExtension.class); | ||
|
||
private static class DSLMapping implements ExtensionMapping<DSLSentence> { | ||
|
||
private ExtensionKind<DSLSentence> kind; | ||
private List<DSLSentence> sentences; | ||
|
||
DSLMapping(ExtensionKind<DSLSentence> kind, List<DSLSentence> sentences) { | ||
this.kind = kind; | ||
this.sentences = sentences; | ||
} | ||
|
||
@Override | ||
public ExtensionKind<DSLSentence> getKind() { | ||
return kind; | ||
} | ||
|
||
@Override | ||
public List<DSLSentence> getValues() { | ||
return sentences; | ||
} | ||
} | ||
|
||
@Override | ||
public Filter<Path> getFilter() { | ||
return DSL_FILE_FILTER; | ||
} | ||
|
||
@Override | ||
public List<ExtensionMapping<?>> getExtensions(Path path, String content) { | ||
final DSLTokenizedMappingFile dslLoader = new DSLTokenizedMappingFile(); | ||
List<DSLSentence> actionSentences = new ArrayList<>(); | ||
List<DSLSentence> conditionSentences = new ArrayList<>(); | ||
try { | ||
if (dslLoader.parseAndLoad(new StringReader(content))) { | ||
for (DSLMappingEntry entry : dslLoader.getMapping().getEntries()) { | ||
if (entry.getSection() == DSLMappingEntry.CONDITION) { | ||
final DSLMappingEntry definition = entry; | ||
final DSLSentence sentence = new DSLSentence(); | ||
sentence.setDrl(definition.getMappingValue()); | ||
sentence.setDefinition(definition.getMappingKey()); | ||
conditionSentences.add(sentence); | ||
} else if (entry.getSection() == DSLMappingEntry.CONSEQUENCE) { | ||
final DSLMappingEntry definition = entry; | ||
final DSLSentence sentence = new DSLSentence(); | ||
sentence.setDrl(definition.getMappingValue()); | ||
sentence.setDefinition(definition.getMappingKey()); | ||
actionSentences.add(sentence); | ||
} | ||
} | ||
} | ||
} catch (IOException e) { | ||
log.error(e.getMessage()); | ||
} | ||
|
||
return Arrays.asList(new DSLMapping(DSLActionSentence.INSTANCE, actionSentences), | ||
new DSLMapping(DSLConditionSentence.INSTANCE, conditionSentences)); | ||
} | ||
} |
97 changes: 97 additions & 0 deletions
97
...est/java/org/kie/workbench/common/services/datamodel/backend/server/DSLExtensionTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
/* | ||
* Copyright 2017 Red Hat, Inc. and/or its affiliates. | ||
* | ||
* 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 org.kie.workbench.common.services.datamodel.backend.server; | ||
|
||
import java.util.List; | ||
|
||
import org.drools.workbench.models.datamodel.oracle.DSLActionSentence; | ||
import org.drools.workbench.models.datamodel.oracle.DSLConditionSentence; | ||
import org.junit.Test; | ||
import org.kie.soup.project.datamodel.commons.util.RawMVELEvaluator; | ||
import org.kie.soup.project.datamodel.oracle.ExtensionKind; | ||
import org.kie.soup.project.datamodel.oracle.PackageDataModelOracle; | ||
import org.kie.workbench.common.services.datamodel.backend.server.builder.packages.PackageDataModelOracleBuilder; | ||
import org.kie.workbench.common.services.datamodel.backend.server.cache.DSLExtension; | ||
import org.kie.workbench.common.services.datamodel.spi.DataModelExtension.ExtensionMapping; | ||
|
||
import static junit.framework.Assert.*; | ||
|
||
public class DSLExtensionTest { | ||
|
||
private DSLExtension extension = new DSLExtension(); | ||
|
||
@Test | ||
public void testAddConditionDSLSentence() { | ||
List<ExtensionMapping<?>> mappings = extension.getExtensions(null, | ||
"[when]There is a Smurf=Smurf()"); | ||
|
||
assertEquals(1, | ||
totalValues(mappings)); | ||
assertEquals(1, | ||
valuesOfKind(mappings, DSLConditionSentence.INSTANCE)); | ||
} | ||
|
||
@Test | ||
public void testAddActionDSLSentence() { | ||
List<ExtensionMapping<?>> mappings = extension.getExtensions(null, | ||
"[then]Greet Smurf=System.out.println(\"Hello Smurf\");"); | ||
|
||
assertEquals(1, | ||
totalValues(mappings)); | ||
assertEquals(1, | ||
valuesOfKind(mappings, DSLActionSentence.INSTANCE)); | ||
} | ||
|
||
@Test | ||
public void testAddMultipleConditionDSLSentence() { | ||
List<ExtensionMapping<?>> mappings = extension.getExtensions(null, | ||
"[when]There is a Smurf=Smurf()\n" | ||
+ "[when]There is Happy Smurf=Smurf( nature = HAPPY )"); | ||
|
||
assertEquals(2, | ||
totalValues(mappings)); | ||
assertEquals(2, | ||
valuesOfKind(mappings, DSLConditionSentence.INSTANCE)); | ||
} | ||
|
||
@Test | ||
public void testAddMultipleActionDSLSentence() { | ||
List<ExtensionMapping<?>> mappings = extension.getExtensions(null, | ||
"[then]Report Smurfs=System.out.println(\"There is a Smurf\");\n" | ||
+ "[then]Greet Happy Smurf=System.out.println(\"Hello Happy Smurf\");"); | ||
|
||
assertEquals(2, | ||
totalValues(mappings)); | ||
assertEquals(2, | ||
valuesOfKind(mappings, DSLActionSentence.INSTANCE)); | ||
} | ||
|
||
private static int totalValues(final List<ExtensionMapping<?>> mappings) { | ||
return (int) mappings | ||
.stream() | ||
.flatMap(em -> em.getValues().stream()) | ||
.count(); | ||
} | ||
|
||
private static int valuesOfKind(final List<ExtensionMapping<?>> mappings, final ExtensionKind kind) { | ||
return (int) mappings | ||
.stream() | ||
.filter(em -> kind.equals(em.getKind())) | ||
.flatMap(em -> em.getValues().stream()) | ||
.count(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>org.drools</groupId> | ||
<artifactId>drools-wb-extensions</artifactId> | ||
<version>8.0.0-SNAPSHOT</version> | ||
</parent> | ||
|
||
<artifactId>drools-wb-drl-extension</artifactId> | ||
<packaging>pom</packaging> | ||
|
||
<name>Drools Workbench - Extensions - DRL</name> | ||
<description>Drools Workbench - DRL</description> | ||
|
||
<modules> | ||
<module>drools-wb-drl-extension-server</module> | ||
</modules> | ||
|
||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>org.drools</groupId> | ||
<artifactId>drools-wb</artifactId> | ||
<version>8.0.0-SNAPSHOT</version> | ||
</parent> | ||
|
||
<artifactId>drools-wb-extensions</artifactId> | ||
<packaging>pom</packaging> | ||
|
||
<name>Drools Workbench - Extensions</name> | ||
<description>Drools Workbench - Extensions</description> | ||
|
||
<modules> | ||
<module>drools-wb-drl-extension</module> | ||
</modules> | ||
|
||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.