import org.onap.aai.exceptions.AAIException;
import org.onap.aai.introspection.Introspector;
import org.onap.aai.introspection.Loader;
-import org.onap.aai.restcore.search.GremlinGroovyShellSingleton;
+import org.onap.aai.restcore.search.GremlinGroovyShell;
import org.onap.aai.schema.enums.ObjectMetadata;
import org.onap.aai.edges.EdgeRule;
import org.onap.aai.edges.EdgeRuleQuery;
private static final String ARGUMENT2 = "#!#argument#!#";
private static final String HAS = ".has('";
- private GremlinGroovyShellSingleton gremlinGroovy = GremlinGroovyShellSingleton.getInstance();
+ private GremlinGroovyShell gremlinGroovy = new GremlinGroovyShell();
private GraphTraversal<?, ?> completeTraversal = null;
protected List<String> list = null;
return (QueryBuilder<Vertex>) this;
}
+ /**
+ * @{inheritDoc}
+ */
+ @Override
+ public QueryBuilder<Vertex> getVerticesByNumberProperty(String key, Object value) {
+ list.add(HAS + key + "', " + value + ")");
+ stepIndex++;
+ return (QueryBuilder<Vertex>) this;
+ }
+
@Override
public QueryBuilder<Vertex> getVerticesByBooleanProperty(String key, Object value) {
boolean bValue = false;
stepIndex++;
return (QueryBuilder<Vertex>) this;
}
-
+
/**
* @{inheritDoc}
*/
stepIndex++;
return (QueryBuilder<Vertex>) this;
}
-
+
/**
* @{inheritDoc}
*/
stepIndex++;
return (QueryBuilder<Vertex>) this;
}
-
+
/**
* @{inheritDoc}
*/
stepIndex++;
return (QueryBuilder<Vertex>) this;
}
-
+
@Override
public QueryBuilder<Vertex> getVerticesGreaterThanProperty(String key, Object value) {
String predicate = "P.gte(#!#argument1#!#)";
stepIndex++;
return (QueryBuilder<Vertex>) this;
}
-
+
@Override
public QueryBuilder<Vertex> getVerticesLessThanProperty(String key, Object value) {
String predicate = "P.lte(#!#argument1#!#)";
stepIndex++;
return (QueryBuilder<Vertex>) this;
}
-
-
+
+
/**
* @{inheritDoc}
*/
//TODO
return (QueryBuilder<Vertex>) this;
}
-
+
/**
* @{inheritDoc}
*/
@Override
public QueryBuilder<Vertex> getTypedVerticesByMap(String type, Map<String, String> map) {
-
+
for (Map.Entry<String, String> es : map.entrySet()) {
list.add(HAS + es.getKey() + "', '" + es.getValue() + "')");
stepIndex++;
stepIndex++;
return (QueryBuilder<Vertex>) this;
}
-
+
/**
* @{inheritDoc}
*/
Set<String> keys = obj.getKeys();
for (String key : keys) {
-
+
this.getVerticesByProperty(key, obj.<Object>getValue(key));
-
- }
+
+ }
return (QueryBuilder<Vertex>) this;
}
-
+
/**
- * @throws NoEdgeRuleFoundException
- * @throws AAIException
+ * @throws NoEdgeRuleFoundException
+ * @throws AAIException
* @{inheritDoc}
*/
@Override
}
this.edgeQueryToVertex(type, parentName, childName, null);
return this;
-
+
}
@Override
} else {
if (Direction.IN.equals(rule.getDirection())) {
inLabels.add(rule.getLabel());
+ if(inType.equals(outType)) {//code to handle when a type edges to itself, to add both in and out
+ outLabels.add(rule.getLabel());
+ }
} else {
outLabels.add(rule.getLabel());
+ if(inType.equals(outType)) {//code to handle when a type edges to itself, to add both in and out
+ inLabels.add(rule.getLabel());
+ }
}
}
}
stepIndex++;
list.add(HAS + AAIProperties.NODE_TYPE + "', '" + inType + "')");
stepIndex++;
-
+
}
-
+
/**
* Edge query.
*
* @param outType the out type
* @param inType the in type
- * @throws NoEdgeRuleFoundException
- * @throws AAIException
+ * @throws NoEdgeRuleFoundException
+ * @throws AAIException
*/
private void edgeQuery(EdgeType type, String outType, String inType, List<String> labels) throws AAIException {
markParentBoundary();
} catch (EdgeRuleNotFoundException e) {
throw new NoEdgeRuleFoundException(e);
}
-
+
final List<String> inLabels = new ArrayList<>();
final List<String> outLabels = new ArrayList<>();
} else {
list.add(".union(__.inE('" + String.join("','", inLabels) + "')" + ", __.outE('" + String.join("','", outLabels) + "'))");
}
-
+
stepIndex++;
-
+
}
@Override
public QueryBuilder<E> limit(long amount) {
command.append(Joiner.on(",").join(wrapped));
command.append(")");
list.add(".has('aai-node-type', " + command + ")");
-
+
} else {
list.add(".has('aai-node-type', '" + type + "')");
}
this.markContainer();
return (QueryBuilder<Vertex>) this;
}
-
+
@Override
public QueryBuilder<E> union(QueryBuilder<E>... builder) {
markParentBoundary();
command.append(")");
list.add(command.toString());
stepIndex++;
-
+
return this;
}
-
+
@Override
public QueryBuilder<E> where(QueryBuilder<E>... builder) {
markParentBoundary();
stepIndex++;
}
list.addAll(traversals);
-
-
+
+
return this;
}
return this;
}
-
+
@Override
public QueryBuilder<E> store(String name) {
this.list.add(".store('"+ name + "')");
stepIndex++;
-
+
return this;
}
-
+
@Override
public QueryBuilder<E> cap(String name) {
this.list.add(".cap('"+ name + "')");
stepIndex++;
-
+
return this;
}
-
+
@Override
public QueryBuilder<E> unfold() {
this.list.add(".unfold()");
stepIndex++;
-
+
return this;
}
-
+
@Override
public QueryBuilder<E> dedup() {
this.list.add(".dedup()");
stepIndex++;
-
+
return this;
}
-
+
@Override
public QueryBuilder<E> emit() {
this.list.add(".emit()");
stepIndex++;
-
+
return this;
}
-
+
@Override
public QueryBuilder<E> repeat(QueryBuilder<E> builder) {
this.list.add(".repeat(__" + builder.getQuery() + ")");
stepIndex++;
-
+
return this;
}
-
+
@Override
public QueryBuilder<E> until(QueryBuilder<E> builder) {
this.list.add(".until(__" + builder.getQuery() + ")");
stepIndex++;
-
+
return this;
}
-
+
@Override
public QueryBuilder<E> groupCount() {
this.list.add(".groupCount()");
stepIndex++;
-
+
return this;
}
-
+
@Override
public QueryBuilder<E> both() {
this.list.add(".both()");
stepIndex++;
-
+
return this;
}
-
+
@Override
public QueryBuilder<Tree> tree() {
this.list.add(".tree()");
stepIndex++;
-
+
return (QueryBuilder<Tree>)this;
}
-
+
@Override
public QueryBuilder<E> by(String name) {
this.list.add(".by('"+ name + "')");
stepIndex++;
-
+
return this;
}
-
+
/**
* {@inheritDoc}
*/
stepIndex++;
return (QueryBuilder<Path>)this;
}
-
+
@Override
public QueryBuilder<Edge> outE() {
this.list.add(".outE()");
stepIndex++;
-
+
return (QueryBuilder<Edge>)this;
}
-
+
@Override
public QueryBuilder<Edge> inE() {
this.list.add(".inE()");
stepIndex++;
-
+
return (QueryBuilder<Edge>)this;
}
-
+
@Override
public QueryBuilder<Vertex> outV() {
this.list.add(".outV()");
stepIndex++;
-
+
return (QueryBuilder<Vertex>)this;
}
-
+
@Override
public QueryBuilder<Vertex> inV() {
this.list.add(".inV()");
stepIndex++;
-
+
return (QueryBuilder<Vertex>)this;
}
-
+
@Override
public QueryBuilder<E> not(QueryBuilder<E> builder) {
this.list.add(".not(" + "__" + builder.getQuery() + ")");
stepIndex++;
-
+
return this;
}
-
+
@Override
public QueryBuilder<E> as(String name) {
this.list.add(".as('" + name + "')");
stepIndex++;
-
+
return this;
}
-
+
@Override
public QueryBuilder<E> select(String name) {
this.list.add(".select('" + name + "')");
stepIndex++;
-
+
+ return this;
+ }
+
+ @Override
+ public QueryBuilder<E> select(String... names) {
+ String stepString = ".select('";
+ for(int i = 0; i<names.length; i++) {
+ stepString = stepString + names[i] +"'";
+ if(i!=(names.length-1)) {
+ stepString = stepString + ",'";
+ }
+ }
+ stepString = stepString + ")";
+ this.list.add(stepString);
+ stepIndex++;
+
return this;
}
/**
public QueryBuilder<E> getParentQuery() {
return cloneQueryAtStep(parentStepIndex);
}
-
+
@Override
public QueryBuilder<E> getContainerQuery() {
return cloneQueryAtStep(containerStepIndex);
}
-
+
/**
* @{inheritDoc}
*/
@Override
public <T2> T2 getQuery() {
StringBuilder sb = new StringBuilder();
-
+
for (String piece : this.list) {
sb.append(piece);
}
-
+
return (T2)sb.toString();
}
-
+
/**
* @{inheritDoc}
*/
public void markParentBoundary() {
parentStepIndex = stepIndex;
}
-
+
@Override
public void markContainer() {
this.containerStepIndex = stepIndex;
}
-
+
/**
* @{inheritDoc}
*/
protected int getStepIndex() {
return stepIndex;
}
-
+
private void executeQuery() {
String queryString = "g" + Joiner.on("").join(list);
Map<String, Object> params = new HashMap<>();
if (this.completeTraversal == null) {
executeQuery();
}
-
+
return this.completeTraversal.hasNext();
}
-
+
@Override
public E next() {
if (this.completeTraversal == null) {
executeQuery();
}
-
+
return (E)this.completeTraversal.next();
}
-
+
@Override
public List<E> toList() {
if (this.completeTraversal == null) {
executeQuery();
}
-
+
return (List<E>)this.completeTraversal.toList();
}
return (QueryBuilder<Edge>)this;
}
-
+
}