Hello,
I am currently somewhat stuck on getting a custom P predicate to work nicely - I'm wondering if I may have gone down a rabbit hole.
We are working using Java-Gremlin. We have a need to be able to use a String.contains(), String.startsWith() and String.endsWith() to filter vertices by properties. Having had a good read of various pieces of documentation it seemed that implementing a simple custom BiPredicates was a sensible way to go i.e.:
public class ContainsPredicate implements Serializable, BiPredicate<Object, Object> {
@Override
public boolean test( Object first, Object second ) {
boolean result;
if ( isNotNullOrEmpty( first ) && isNotNullOrEmpty( second ) ) {
result = first.toString().contains( second.toString() );
} else {
result = false;
}
return result;
}
private boolean isNotNullOrEmpty( Object o ) {
return o != null && !o.toString().isEmpty();
}
public static P<Object> contains( Object value ) {
BiPredicate<Object, Object> pred = new ContainsPredicate();
return new P<>( pred, value );
}
}
This has worked fine for me with unit tests run against a local tinker graph, where the gremlin query is something like:
g.V().hasLabel("person").has( "name", ContainsPredicate.contains( "sh" ) ).values().toList()
Would get me the values for the vertex for Josh from the Modern toy graph.
So far so good.
The sticking point has been talking to a remote TinkerPop instance - I am not sure how to get the remote TinkerPop server to have my class available. I have tried: adding a plugins line
org.apache.tinkerpop.gremlin.jsr223.ImportGremlinPlugin: {classImports: [com.predicates.ContainsPredicate], methodImports: [com.service.predicates.ContainsPredicate#*]},
and / or putting an import statement in the startup script (generate-empty.groovy):
and setting the serializeToString option to false. I believe I have Wildfly configured correctly to make my class available on the classpath (i.e. the calling code can see it, it's the test remote that can't - both in the same Wildfly instance)
I am consistently getting the error: Request [PooledUnsafeDirectByteBuf(ridx: 245, widx: 245, cap: 279)] could not be deserialized by org.apache.tinkerpop.gremlin.driver.ser.AbstractGryoMessageSerializerV3d0.: java.lang.IllegalStateException: org.apache.tinkerpop.gremlin.process.traversal.P.com.predicates.ContainsPredicate@2aa0e166(java.lang.Object)
Which is caused by: java.lang.NoSuchMethodException: org.apache.tinkerpop.gremlin.process.traversal.P.com.predicates.ContainsPredicate@2aa0e166(java.lang.Object)
I've attached the relevant log fragment.
Not sure what the correct way to proceed would be: am I barking up the wrong tree completely, have I missed something obvious or would I need to think about putting together a TinkerPop plugin to make it available?
Any help gratefully received,
Gareth Jones