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.
Extend support for Signavio custom List operations functions. (#2)
- Loading branch information
Showing
9 changed files
with
369 additions
and
3 deletions.
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/AppendAllFunction.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,31 @@ | ||
/* | ||
* Copyright 2016 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.dmn.feel.runtime.functions; | ||
|
||
import java.util.List; | ||
|
||
public class AppendAllFunction | ||
extends BaseFEELFunction { | ||
|
||
public AppendAllFunction() { | ||
super("appendAll"); | ||
} | ||
|
||
public FEELFnResult<List> invoke(@ParameterName("list") Object[] lists) { | ||
return BuiltInFunctions.getFunction(ConcatenateFunction.class).invoke(lists); | ||
} | ||
} |
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
48 changes: 48 additions & 0 deletions
48
...-feel/src/main/java/org/kie/dmn/feel/runtime/functions/SignavioAreElementsOfFunction.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,48 @@ | ||
/* | ||
* Copyright 2016 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.dmn.feel.runtime.functions; | ||
|
||
import java.util.List; | ||
|
||
import org.kie.dmn.api.feel.runtime.events.FEELEvent.Severity; | ||
import org.kie.dmn.feel.runtime.events.InvalidParametersEvent; | ||
|
||
public class SignavioAreElementsOfFunction | ||
extends BaseFEELFunction { | ||
|
||
public SignavioAreElementsOfFunction() { | ||
super("areElementsOf"); | ||
} | ||
|
||
public FEELFnResult<Boolean> invoke(@ParameterName("list1") List list1, @ParameterName("list2") List list2) { | ||
if (list2 == null) { | ||
return FEELFnResult.ofError(new InvalidParametersEvent(Severity.ERROR, "list2", "cannot be null")); | ||
} | ||
|
||
boolean result = true; | ||
for (Object element : list1) { | ||
result = list2.contains(element) && result; | ||
|
||
// optimization: terminate early if an element is not actually contained. | ||
if (!result) { | ||
return FEELFnResult.ofResult(result); | ||
} | ||
} | ||
|
||
return FEELFnResult.ofResult( result ); | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
...n-feel/src/main/java/org/kie/dmn/feel/runtime/functions/SignavioContainsOnlyFunction.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,48 @@ | ||
/* | ||
* Copyright 2016 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.dmn.feel.runtime.functions; | ||
|
||
import java.util.List; | ||
|
||
import org.kie.dmn.api.feel.runtime.events.FEELEvent.Severity; | ||
import org.kie.dmn.feel.runtime.events.InvalidParametersEvent; | ||
|
||
public class SignavioContainsOnlyFunction | ||
extends BaseFEELFunction { | ||
|
||
public SignavioContainsOnlyFunction() { | ||
super("containsOnly"); | ||
} | ||
|
||
public FEELFnResult<Boolean> invoke(@ParameterName("list1") List list1, @ParameterName("list2") List list2) { | ||
if (list1 == null) { | ||
return FEELFnResult.ofError(new InvalidParametersEvent(Severity.ERROR, "list1", "cannot be null")); | ||
} | ||
|
||
boolean result = true; | ||
for (Object element : list2) { | ||
result = list1.contains(element) && result; | ||
|
||
// optimization: terminate early if an element is not actually contained. | ||
if (!result) { | ||
return FEELFnResult.ofResult(result); | ||
} | ||
} | ||
|
||
return FEELFnResult.ofResult( result ); | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
...feel/src/main/java/org/kie/dmn/feel/runtime/functions/SignavioNotContainsAnyFunction.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,48 @@ | ||
/* | ||
* Copyright 2016 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.dmn.feel.runtime.functions; | ||
|
||
import java.util.List; | ||
|
||
import org.kie.dmn.api.feel.runtime.events.FEELEvent.Severity; | ||
import org.kie.dmn.feel.runtime.events.InvalidParametersEvent; | ||
|
||
public class SignavioNotContainsAnyFunction | ||
extends BaseFEELFunction { | ||
|
||
public SignavioNotContainsAnyFunction() { | ||
super("notContainsAny"); | ||
} | ||
|
||
public FEELFnResult<Boolean> invoke(@ParameterName("list1") List list1, @ParameterName("list2") List list2) { | ||
if (list1 == null) { | ||
return FEELFnResult.ofError(new InvalidParametersEvent(Severity.ERROR, "list1", "cannot be null")); | ||
} | ||
|
||
boolean result = true; | ||
for (Object element : list2) { | ||
result = (!list1.contains(element)) && result; | ||
|
||
// optimization: terminate early if any element is actually contained. | ||
if (!result) { | ||
return FEELFnResult.ofResult(result); | ||
} | ||
} | ||
|
||
return FEELFnResult.ofResult( result ); | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
...-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/SignavioRemoveAllFunction.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,46 @@ | ||
/* | ||
* Copyright 2016 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.dmn.feel.runtime.functions; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import org.kie.dmn.api.feel.runtime.events.FEELEvent.Severity; | ||
import org.kie.dmn.feel.runtime.events.InvalidParametersEvent; | ||
|
||
public class SignavioRemoveAllFunction | ||
extends BaseFEELFunction { | ||
|
||
public SignavioRemoveAllFunction() { | ||
super("removeAll"); | ||
} | ||
|
||
public FEELFnResult<List> invoke(@ParameterName("list1") List list1, @ParameterName("list2") List list2) { | ||
if (list1 == null) { | ||
return FEELFnResult.ofError(new InvalidParametersEvent(Severity.ERROR, "list1", "cannot be null")); | ||
} | ||
|
||
// spec requires us to return a new list | ||
List<Object> result = new ArrayList<Object>(list1); | ||
|
||
for (Object element : list2) { | ||
result.remove(element); | ||
} | ||
|
||
return FEELFnResult.ofResult( result ); | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
...kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/SignavioRemoveFunction.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,47 @@ | ||
/* | ||
* Copyright 2016 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.dmn.feel.runtime.functions; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import org.kie.dmn.api.feel.runtime.events.FEELEvent.Severity; | ||
import org.kie.dmn.feel.runtime.events.InvalidParametersEvent; | ||
|
||
public class SignavioRemoveFunction | ||
extends BaseFEELFunction { | ||
|
||
public SignavioRemoveFunction() { | ||
super( "remove" ); | ||
} | ||
|
||
public FEELFnResult<List> invoke(@ParameterName("list") List list, @ParameterName("element") Object element) { | ||
if ( list == null ) { | ||
return FEELFnResult.ofError(new InvalidParametersEvent(Severity.ERROR, "list", "cannot be null")); | ||
} | ||
if (element == null) { | ||
return FEELFnResult.ofError(new InvalidParametersEvent(Severity.ERROR, "element", "cannot be null")); | ||
} | ||
|
||
// spec requires us to return a new list | ||
List<Object> result = new ArrayList<Object>( list ); | ||
|
||
result.remove(element); | ||
|
||
return FEELFnResult.ofResult( result ); | ||
} | ||
} |
72 changes: 72 additions & 0 deletions
72
kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/ZipFunction.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,72 @@ | ||
/* | ||
* Copyright 2016 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.dmn.feel.runtime.functions; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import org.kie.dmn.api.feel.runtime.events.FEELEvent.Severity; | ||
import org.kie.dmn.feel.runtime.events.InvalidParametersEvent; | ||
|
||
public class ZipFunction | ||
extends BaseFEELFunction { | ||
|
||
public ZipFunction() { | ||
super("zip"); | ||
} | ||
|
||
public FEELFnResult<List> invoke(@ParameterName("attributes") List<?> attributes, @ParameterName("values") Object[] values) { | ||
if (attributes.isEmpty()) { | ||
return FEELFnResult.ofError(new InvalidParametersEvent(Severity.ERROR, "attributes", "attributes cannot be empty")); | ||
} else if (!(attributes.get(0) instanceof String)) { | ||
return FEELFnResult.ofError(new InvalidParametersEvent(Severity.ERROR, "attributes", "attributes must be a list of string")); | ||
} | ||
|
||
if (values.length != attributes.size()) { | ||
return FEELFnResult.ofError(new InvalidParametersEvent(Severity.ERROR, "values", "values must be a list of the same size as of attributes")); | ||
} | ||
|
||
// spec requires us to return a new list | ||
final List<Map<Object, Object>> result = new ArrayList<>(); | ||
|
||
for (int aIdx = 0; aIdx < values.length; aIdx++) { | ||
if (!(values[aIdx] instanceof List)) { | ||
return FEELFnResult.ofError(new InvalidParametersEvent(Severity.ERROR, "values", "each value must be a list")); | ||
} | ||
List<?> value = (List<?>) values[aIdx]; | ||
|
||
if (result.isEmpty()) { | ||
// first time init list | ||
value.forEach(x -> result.add(new HashMap<>())); | ||
} else { | ||
if (value.size() != result.size()) { | ||
return FEELFnResult.ofError(new InvalidParametersEvent(Severity.ERROR, "values", "each value must be consistent in size")); | ||
} | ||
} | ||
|
||
Object attribute = attributes.get(aIdx); | ||
|
||
for (int vIdx = 0; vIdx < value.size(); vIdx++) { | ||
result.get(vIdx).put(attribute, value.get(vIdx)); | ||
} | ||
} | ||
|
||
return FEELFnResult.ofResult(result); | ||
} | ||
} |
Oops, something went wrong.