2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017-2018 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 package org.onap.aai.restcore.search;
22 import groovy.lang.GroovyShell;
23 import groovy.transform.TimedInterrupt;
24 import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal;
25 import org.codehaus.groovy.ast.ClassHelper;
26 import org.codehaus.groovy.ast.expr.ClassExpression;
27 import org.codehaus.groovy.ast.expr.PropertyExpression;
28 import org.codehaus.groovy.control.CompilerConfiguration;
29 import org.codehaus.groovy.control.customizers.ASTTransformationCustomizer;
30 import org.codehaus.groovy.control.customizers.ImportCustomizer;
31 import org.onap.aai.serialization.engines.TransactionalGraphEngine;
33 import java.util.HashMap;
35 import java.util.concurrent.TimeUnit;
37 public abstract class AAIAbstractGroovyShell {
39 protected final GroovyShell shell;
41 public AAIAbstractGroovyShell() {
42 Map<String, Object> parameters = new HashMap<>();
43 parameters.put("value", 30000);
44 parameters.put("unit", new PropertyExpression(new ClassExpression(ClassHelper.make(TimeUnit.class)),"MILLISECONDS"));
46 ASTTransformationCustomizer custom = new ASTTransformationCustomizer(parameters, TimedInterrupt.class);
47 ImportCustomizer imports = new ImportCustomizer();
48 imports.addStaticStars(
49 "org.apache.tinkerpop.gremlin.process.traversal.P",
50 "org.apache.tinkerpop.gremlin.process.traversal.Order"
53 "org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__",
54 "org.apache.tinkerpop.gremlin.structure.T",
55 "org.apache.tinkerpop.gremlin.process.traversal.P",
56 "org.onap.aai.edges.enums.EdgeType",
57 "java.util.Map.Entry");
58 imports.addStarImports("java.util");
59 CompilerConfiguration config = new CompilerConfiguration();
60 config.addCompilationCustomizers(custom, imports);
62 this.shell = new GroovyShell(config);
70 * @return result of graph traversal
72 public abstract String executeTraversal (TransactionalGraphEngine engine, String traversal, Map<String, Object> params);
77 * @return result of graph traversal
79 public abstract GraphTraversal<?, ?> executeTraversal (String traversal, Map<String, Object> params);