Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

In different threads you have to enter the context #178

Merged
merged 1 commit into from

2 participants

@edwardcapriolo
Collaborator

This fixes the javascript filters as they failed with anything but trivial examples.

@zznate zznate merged commit fd93661 into master
@zznate zznate deleted the javascript_context_fix branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
2  src/main/java/org/usergrid/vx/server/operations/FilterHandler.java
@@ -1,5 +1,6 @@
package org.usergrid.vx.server.operations;
+import org.mozilla.javascript.Context;
import org.usergrid.vx.experimental.filter.Filter;
import org.vertx.java.core.Handler;
import org.vertx.java.core.eventbus.Message;
@@ -19,6 +20,7 @@ public FilterHandler(Filter filter) {
@Override
public void handle(Message<JsonArray> event) {
JsonArray filteredArray = new JsonArray();
+ Context context = Context.enter();
for (Object obj : event.body) {
JsonObject jsonObject = (JsonObject) obj;
Map filtered = filter.filter(jsonObject.toMap());
View
9 src/test/java/org/usergrid/vx/experimental/FilterITest.java
@@ -65,7 +65,7 @@ public void executeClojureFilter() throws Exception {
Assert.assertEquals(1, results.size());
}
- @Ignore
+
@Test
/* why wont this work */
public void executeJavaScriptPhoneFilter() throws Exception {
@@ -78,15 +78,10 @@ public void executeJavaScriptPhoneFilter() throws Exception {
req.add(Operations.assumeOp("jsFilterks2", "filtercf2", "value", "UTF8Type"));//5
req.add(Operations.setOp("rowa", "col1", "{ \"last\" : \"Peters\", \"first\" : \"john\", \"pnumber\": \"914-555-5555\" }")); //6
req.add(Operations.setOp("rowa", "col2", "{ \"last\" : \"Peters2\", \"first\" : \"john\", \"pnumber\": \"915-555-5555\" }")); //6
- /*
req.add(Operations.createFilterOp("over22", "javascript",
"function over22(row) { x = JSON.parse( row['value'], null ); \n" +
"if ( String(x.pnumber).search(\"914\") != -1 ) { return row } else { return null } \n" +
"}")); // 8
- */
- //req.add(Operations.sliceOp("rowa", "col1", "col3", 10)); //10
- req.add(Operations.createFilterOp("over22", "javascript",
- "function over22(row) { if ( /914/.test(row['value']) ) {return row;} else {return null;} } " )); // 8
req.add(Operations.filterModeOp("over22", true)); //9
req.add(Operations.sliceOp("rowa", "col1", "col3", 10)); //10
IntraClient2 ic2 = new IntraClient2("localhost", 8080);
@@ -95,7 +90,7 @@ public void executeJavaScriptPhoneFilter() throws Exception {
List<Map> results = (List<Map>) res.getOpsRes().get(10);
System.out.println(results);
- Assert.assertEquals("22", results.get(0).get("value"));
+ Assert.assertEquals("{ \"last\" : \"Peters\", \"first\" : \"john\", \"pnumber\": \"914-555-5555\" }", results.get(0).get("value"));
Assert.assertEquals(1, results.size());
}
Something went wrong with that request. Please try again.