2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
20 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22 package org.onap.aai.serialization.engines.query;/*-
23 * ============LICENSE_START=======================================================
25 * ================================================================================
26 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
27 * ================================================================================
28 * Licensed under the Apache License, Version 2.0 (the "License");
29 * you may not use this file except in compliance with the License.
30 * You may obtain a copy of the License at
32 * http://www.apache.org/licenses/LICENSE-2.0
34 * Unless required by applicable law or agreed to in writing, software
35 * distributed under the License is distributed on an "AS IS" BASIS,
36 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
37 * See the License for the specific language governing permissions and
38 * limitations under the License.
39 * ============LICENSE_END=========================================================
43 //package org.onap.aai.serialization.engines.query;
45 //import java.util.List;
46 //import java.util.regex.Matcher;
47 //import java.util.regex.Pattern;
49 //import org.apache.commons.collections.IteratorUtils;
51 //import org.onap.aai.db.AAIProperties;
52 //import org.onap.aai.query.builder.QueryBuilder;
53 //import org.onap.aai.serialization.engines.TransactionalGraphEngine;
54 //import com.tinkerpop.blueprints.Direction;
55 //import com.tinkerpop.blueprints.Graph;
56 //import com.tinkerpop.blueprints.TransactionalGraph;
57 //import com.tinkerpop.blueprints.Vertex;
58 //import com.tinkerpop.gremlin.groovy.Gremlin;
59 //import com.tinkerpop.gremlin.java.GremlinPipeline;
60 //import com.tinkerpop.pipes.Pipe;
61 //import com.tinkerpop.pipes.util.iterators.SingleIterator;
63 //public class GremlinQueryEngine extends QueryEngine {
65 // public GremlinQueryEngine (TransactionalGraphEngine engine) {
72 // public List<Vertex> executeQuery(TransactionalGraph g, QueryBuilder query) {
73 // List<Vertex> result = null;
74 // Vertex start = query.getStart();
75 // if (start != null) {
76 // result = this.executeQuery(start, (String)query.getQuery());
78 // result = this.processGremlinQuery((String)query.getQuery());
85 // public List<Vertex> executeParentQuery(TransactionalGraph g, QueryBuilder query) {
87 // List<Vertex> result = null;
88 // Vertex start = query.getStart();
89 // if (start != null) {
90 // result = this.executeQuery(start, (String)query.getParentQuery());
92 // result = this.processGremlinQuery((String)query.getParentQuery());
97 // private List<Vertex> executeQuery(Vertex startVertex, String query) {
99 // return this.processGremlinQuery(startVertex, "_()" + query);
104 // public List<Vertex> findParents(Vertex start) {
106 // String findAllParents = ".as('x').inE.has('isParent', true).outV"
107 // + ".loop('x'){it.object.inE.has('isParent',true).count()==1}{true}";
109 // List<Vertex> results = this.executeQuery(start, findAllParents);
110 // results.add(0, start);
116 // public List<Vertex> findChildren(Vertex start) {
117 // String findAllChildren = ".as('x').outE.has('isParent', true).inV"
118 // + ".loop('x'){it.object.outE.has('isParent', true).count() >= 1}{true}";
120 // List<Vertex> results = this.executeQuery(start, findAllChildren);
121 // results.add(0, start);
127 // public List<Vertex> findDeletable(Vertex start) {
128 // String findAllChildren = ".as('x').outE.or(_().has('isParent', true), _().has('hasDelTarget', true)).inV"
129 // + ".loop('x'){it.object.outE.or(_().has('isParent', true), _().has('hasDelTarget', true)).count() >= 1}{true}";
131 // List<Vertex> results = this.executeQuery(start, findAllChildren);
132 // results.add(0, start);
135 // private List<Vertex> processGremlinQuery(String query) {
137 // Pattern firstHasSet = Pattern.compile("^(\\.has\\(.*?\\))(\\.has\\(.*?\\))*(?!\\.has)");
138 // Pattern p = Pattern.compile("\\.has\\('(.*?)',\\s?'(.*?)'\\)");
139 // Matcher m = firstHasSet.matcher(query);
140 // List<Vertex> results = null;
141 // GremlinPipeline<Graph, Vertex> pipe = new GremlinPipeline<>(dbEngine.getGraph());
143 // String hasSet = m.group();
144 // query = query.replace(m.group(0), "");
145 // m = p.matcher(hasSet);
147 // while (m.find()) {
148 // pipe.has(m.group(1), m.group(2));
150 // results = processGremlinQuery(pipe.toList(), "_()" + query);
156 // private List<Vertex> processGremlinQuery(Vertex startVertex, String query) {
158 // Pipe pipe = Gremlin.compile(query);
159 // pipe.setStarts(new SingleIterator<Vertex>(startVertex));
161 // return (List<Vertex>)IteratorUtils.toList(pipe.iterator());
163 // private List<Vertex> processGremlinQuery(List<Vertex> list, String query) {
165 // Pipe pipe = Gremlin.compile(query);
167 // pipe.setStarts(list);
169 // return (List<Vertex>)IteratorUtils.toList(pipe.iterator());
174 // public List<Vertex> findRelatedVertices(Vertex start, Direction direction, String label, String nodeType) {
175 // String findRelatedVertices = "_()";
176 // switch (direction) {
178 // findRelatedVertices += ".out('" + label + "')";
181 // findRelatedVertices += ".in('" + label + "')";
184 // findRelatedVertices += ".both('" + label + "')";
189 // findRelatedVertices += ".has('" + AAIProperties.NODE_TYPE + "', '" + nodeType + "').dedup()";
190 // List<Vertex> results = this.executeQuery(start, findRelatedVertices);
191 // results.add(0, start);