Hi Guys,
I'm trying to set a timestamp on vertex properties as they get created. To do that, in my strategy I would have to replace the AddPropertyStep with a new instance of the AddPropertyStep that takes in my property and it's value through the vertexPropertyKeyValues parameter:
stepsToModify.addAll(TraversalHelper.getStepsOfAssignableClass(AddPropertyStep.class, traversal));
stepsToModify.forEach(s -> {
AddPropertyStep ps = (AddPropertyStep) s;
TraversalHelper.replaceStep(s, new AddPropertyStep(traversal, ps.getCardinality(), ps.getKey(), ps.getValue(), appendToKeyValues(ps.getVertexPropertyKeyValues(), Constants.CREATED, System.currentTimeMillis())), traversal);
});
where appendToKeyValues method will simply add the "created" property and it's value to the vertexPropertyKeyValues collection.
It works when adding properties on vertices g.V(0).property("my key", "my value") but obviously it fails when adding properties to edges g.V(0).outE("some edge").property("my key", "my value"). That is because if I make use of the vertexPropertyKeyValues, the AddPropertyStep will consider that I'm trying to add vertex properties which doesn't make sense in case of edges.
//pasted from the AddPropertyStep's constructor
this.asVertex = null != cardinality || this.vertexPropertyKeyValues.length > 0;
//pasted from the sideEffect method of the AddPropertyStep class
if (asVertex)
((Vertex) traverser.get()).property(cardinality, key, value, vertexPropertyKeyValues);
else
traverser.get().property(key, value);
To fix it, I think the sideEffect method should do the following:
if (Vertex.class.isAssignableFrom(traverser.get().getClass())){
((Vertex) traverser.get()).property(cardinality, key, value, vertexPropertyKeyValues);
else
traverser.get().property(key, value);
The only work around that I could think of was to create a custom AddPropertyStep that applies the above fix. But custom steps are not recommended in TP3, for reasons that are beyond the current topic.
Am I missing something ? Is there any solution to find out whether the AddPropertyStep is applied to a vertex or an edge, at the strategy level ?
Thanks,
Cosmin.