Created
December 9, 2011 19:34
-
-
Save espeed/1452942 to your computer and use it in GitHub Desktop.
Gremlin YAML String Replacement
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
import groovy.json.JsonSlurper | |
def slurper = new JsonSlurper() | |
keys = data = null | |
if ('null' != 'null') | |
keys = slurper.parseText('null') | |
if ('{"age":35,"name":"James Thornton"}' != 'null') | |
data = slurper.parseText('{"age":35,"name":"James Thornton"}') | |
vertex = g.getRawGraph().getNodeById(9) | |
manager = g.getRawGraph().index() | |
index = manager.forNodes('test_idxV') | |
g.setMaxBufferSize(0) | |
g.startTransaction() | |
index.remove(vertex) | |
for (String key in vertex.getPropertyKeys()) | |
vertex.removeProperty(key) | |
for (entry in data.entrySet()) { | |
if (entry.value == null) continue; | |
vertex.setProperty(entry.key,entry.value) | |
if (keys == null || keys.contains(entry.key)) | |
index.add(vertex,entry.key,entry.value) | |
} | |
g.stopTransaction(TransactionalGraph.Conclusion.SUCCESS) | |
return vertex |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment