Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
Issue #611
  • Loading branch information
rsoika committed Nov 23, 2019
1 parent 04e7142 commit 033d462
Show file tree
Hide file tree
Showing 22 changed files with 467 additions and 224 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -153,16 +153,17 @@ public ScriptEngine getScriptEngine() {
*/
public ItemCollection evaluateBusinessRule(String script, ItemCollection documentContext, ItemCollection event)
throws PluginException {

boolean debug = logger.isLoggable(Level.FINE);
// test if a business rule is defined
if ("".equals(script.trim()))
return null; // nothing to do

// set activity properties into engine
scriptEngine.put("event", convertItemCollection(event));
scriptEngine.put("workitem", convertItemCollection(documentContext));

logger.finest("......SCRIPT:" + script);
if (debug) {
logger.finest("......SCRIPT:" + script);
}
try {
scriptEngine.eval(script);
} catch (ScriptException e) {
Expand Down Expand Up @@ -220,15 +221,17 @@ public ItemCollection evaluateJsonByScript(String json, String script) throws Sc
* @throws PluginException
*/
public boolean evaluateBooleanExpression(String script, ItemCollection documentContext) throws PluginException {

boolean debug = logger.isLoggable(Level.FINE);
// test if a business rule is defined
if ("".equals(script.trim()))
return false; // nothing to do

// set activity properties into engine
scriptEngine.put("workitem", convertItemCollection(documentContext));

logger.finest("......SCRIPT:" + script);
if (debug) {
logger.finest("......SCRIPT:" + script);
}
Object result = null;
try {
result = scriptEngine.eval(script);
Expand Down Expand Up @@ -257,7 +260,7 @@ public boolean evaluateBooleanExpression(String script, ItemCollection documentC
*/
public Object[] evaluateNativeScriptArray(String expression) {
Object[] params = null;

boolean debug = logger.isLoggable(Level.FINE);
if (scriptEngine == null) {
logger.severe("evaluateScritpObject error: no script engine! - call run()");
return null;
Expand Down Expand Up @@ -293,7 +296,7 @@ public Object[] evaluateNativeScriptArray(String expression) {
return null;
}
// logging
if (logger.isLoggable(Level.FINE)) {
if (debug) {
logger.finest("......evalueateScript object to Java");
for (Object val : resultList) {
logger.finest(" " + val.toString());
Expand All @@ -304,7 +307,9 @@ public Object[] evaluateNativeScriptArray(String expression) {
} catch (ScriptException se) {
// not convertable!
// se.printStackTrace();
logger.finest("......error evaluating " + expression + " - " + se.getMessage());
if (debug) {
logger.finest("......error evaluating " + expression + " - " + se.getMessage());
}
return null;
}

Expand Down Expand Up @@ -357,6 +362,7 @@ private Map<String, Object[]> convertItemCollection(ItemCollection itemCol) {
@SuppressWarnings({ "unchecked", "rawtypes" })
public ItemCollection convertScriptVariableToItemCollection(String variable) {
ItemCollection result = null;
boolean debug = logger.isLoggable(Level.FINE);
// get result object from engine
Map<String, Object> scriptResult = (Map) scriptEngine.get(variable);
// test if the json object exists and has child objects...
Expand All @@ -370,7 +376,9 @@ public ItemCollection convertScriptVariableToItemCollection(String variable) {
// test if the entry value is a single object or an array....
if (isBasicObjectType(entry.getValue().getClass())) {
// single value - build array....
logger.finest("......adding " + variable + " property " + entry.getKey());
if (debug) {
logger.finest("......adding " + variable + " property " + entry.getKey());
}
List<Object> list = new ArrayList();
list.add(entry.getValue());
result.replaceItemValue(entry.getKey(), list);
Expand All @@ -381,7 +389,9 @@ public ItemCollection convertScriptVariableToItemCollection(String variable) {
if (oScript == null) {
continue;
}
logger.finest("......adding " + variable + " property " + entry.getKey());
if (debug) {
logger.finest("......adding " + variable + " property " + entry.getKey());
}
List<?> list = new ArrayList(Arrays.asList(oScript));
result.replaceItemValue(entry.getKey(), list);
}
Expand Down
Loading

0 comments on commit 033d462

Please sign in to comment.