use of com.tinkerpop.blueprints.Element in project orientdb by orientechnologies.
the class OGraphSONUtility method createJSONMap.
private static ObjectNode createJSONMap(final Map map, final List<String> propertyKeys, final boolean showTypes) {
final ObjectNode jsonMap = jsonNodeFactory.objectNode();
for (Object key : map.keySet()) {
Object value = map.get(key);
if (value != null) {
if (value instanceof List) {
value = createJSONList((List) value, propertyKeys, showTypes);
} else if (value instanceof Map) {
value = createJSONMap((Map) value, propertyKeys, showTypes);
} else if (value instanceof Element) {
value = objectNodeFromElement((Element) value, propertyKeys, showTypes ? GraphSONMode.EXTENDED : GraphSONMode.NORMAL);
} else if (value.getClass().isArray()) {
value = createJSONList(convertArrayToList(value), propertyKeys, showTypes);
}
}
putObject(jsonMap, key.toString(), getValue(value, showTypes));
}
return jsonMap;
}
use of com.tinkerpop.blueprints.Element in project frames by tinkerpop.
the class GremlinGroovyAnnotationHandler method processVertex.
public Object processVertex(final GremlinGroovy annotation, final Method method, final Object[] arguments, final FramedGraph framedGraph, final Vertex vertex) {
try {
final CompiledScript script = this.engine.compile(annotation.value());
final Bindings bindings = getBindings(method, arguments);
bindings.put(IT, vertex);
bindings.put(G, framedGraph);
final Object result = script.eval(bindings);
// TODO: Deprecate the use of _() and replace with it
if (result instanceof Pipe & annotation.value().startsWith(PIPE)) {
LOGGER.warning("_() is deprecated in favor of using 'it' to represent the framed vertex");
((Pipe) result).setStarts(new SingleIterator<Element>(vertex));
}
if (annotation.frame()) {
if (result instanceof Iterable) {
final FramedVertexIterable r = new FramedVertexIterable(framedGraph, (Iterable) result, ClassUtilities.getGenericClass(method));
return (ClassUtilities.returnsIterable(method)) ? r : r.iterator().hasNext() ? r.iterator().next() : null;
} else if (ClassUtilities.returnsMap(method)) {
return new FramedVertexMap(framedGraph, (Map) result, ClassUtilities.getGenericClass(method));
} else if (result instanceof Vertex) {
return framedGraph.frame((Vertex) result, ClassUtilities.getGenericClass(method));
} else {
throw new IllegalStateException("The returned object can not be framed: " + result.getClass());
}
} else {
return result;
}
} catch (ScriptException e) {
//Preserve original exception functionality.
ExceptionUtils.sneakyThrow(e);
return null;
}
}
use of com.tinkerpop.blueprints.Element in project blueprints by tinkerpop.
the class ElementHelperTest method testRemoveProperties.
public void testRemoveProperties() {
Graph graph = TinkerGraphFactory.createTinkerGraph();
Vertex vertex = graph.getVertex(1);
assertEquals(vertex.getProperty("name"), "marko");
assertEquals(vertex.getProperty("age"), 29);
assertEquals(vertex.getPropertyKeys().size(), 2);
ElementHelper.removeProperties(Arrays.asList((Element) vertex));
assertNull(vertex.getProperty("name"));
assertNull(vertex.getProperty("age"));
assertEquals(vertex.getPropertyKeys().size(), 0);
ElementHelper.removeProperties(Arrays.asList((Element) vertex));
assertNull(vertex.getProperty("name"));
assertNull(vertex.getProperty("age"));
assertEquals(vertex.getPropertyKeys().size(), 0);
}
Aggregations