Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added the beginnings of an idea for a bsh data router
- Loading branch information
Showing
3 changed files
with
57 additions
and
0 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
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
symmetric/src/main/java/org/jumpmind/symmetric/route/BshDataRouter.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 @@ | ||
package org.jumpmind.symmetric.route; | ||
|
||
import java.util.Collection; | ||
import java.util.Collections; | ||
import java.util.HashSet; | ||
import java.util.Set; | ||
|
||
import org.jumpmind.symmetric.model.DataMetaData; | ||
import org.jumpmind.symmetric.model.Node; | ||
|
||
import bsh.EvalError; | ||
import bsh.Interpreter; | ||
|
||
/** | ||
* In Progress ... | ||
* TODO javadoc and unit test | ||
*/ | ||
public class BshDataRouter extends AbstractDataRouter { | ||
|
||
public void completeBatch(IRouterContext context) { | ||
} | ||
|
||
public Collection<String> routeToNodes(IRouterContext context, DataMetaData dataMetaData, Set<Node> nodes, | ||
boolean initialLoad) { | ||
try { | ||
Interpreter interpreter = new Interpreter(); | ||
interpreter.set("nodes", nodes); | ||
// set old and new and cur column values | ||
Object value = interpreter.eval(dataMetaData.getTrigger().getRouterExpression()); | ||
if (value instanceof Boolean && value.equals(Boolean.TRUE)) { | ||
return toNodeIds(nodes); | ||
} else if (value instanceof Collection<?>) { | ||
Collection<?> values = (Collection<?>) value; | ||
Set<String> nodeIds = new HashSet<String>(values.size()); | ||
for (Object v : values) { | ||
if (v != null) { | ||
nodeIds.add(v.toString()); | ||
} | ||
} | ||
return nodeIds; | ||
} | ||
} catch (EvalError e) { | ||
logger.error(e, e); | ||
} | ||
return Collections.emptySet(); | ||
} | ||
|
||
} |