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=========================================================
21 package org.onap.aai.restcore.search;
23 import groovy.lang.GroovyShell;
24 import groovy.transform.TimedInterrupt;
26 import java.util.HashMap;
28 import java.util.concurrent.TimeUnit;
30 import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal;
31 import org.codehaus.groovy.ast.ClassHelper;
32 import org.codehaus.groovy.ast.expr.ClassExpression;
33 import org.codehaus.groovy.ast.expr.PropertyExpression;
34 import org.codehaus.groovy.control.CompilerConfiguration;
35 import org.codehaus.groovy.control.customizers.ASTTransformationCustomizer;
36 import org.codehaus.groovy.control.customizers.ImportCustomizer;
37 import org.onap.aai.serialization.engines.TransactionalGraphEngine;
39 public abstract class AAIAbstractGroovyShell {
41 protected final GroovyShell shell;
43 public AAIAbstractGroovyShell() {
44 Map<String, Object> parameters = new HashMap<>();
45 parameters.put("value", 30000);
46 parameters.put("unit",
47 new PropertyExpression(new ClassExpression(ClassHelper.make(TimeUnit.class)), "MILLISECONDS"));
49 ASTTransformationCustomizer custom = new ASTTransformationCustomizer(parameters, TimedInterrupt.class);
50 ImportCustomizer imports = new ImportCustomizer();
51 imports.addStaticStars("org.apache.tinkerpop.gremlin.process.traversal.P",
52 "org.apache.tinkerpop.gremlin.process.traversal.Order");
53 imports.addImports("org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__",
54 "org.apache.tinkerpop.gremlin.structure.T", "org.apache.tinkerpop.gremlin.process.traversal.P",
55 "org.onap.aai.edges.enums.EdgeType", "java.util.Map.Entry");
56 imports.addStarImports("java.util");
57 CompilerConfiguration config = new CompilerConfiguration();
58 config.addCompilationCustomizers(custom, imports);
60 this.shell = new GroovyShell(config);
68 * @return result of graph traversal
70 public abstract String executeTraversal(TransactionalGraphEngine engine, String traversal,
71 Map<String, Object> params);
76 * @return result of graph traversal
78 public abstract GraphTraversal<?, ?> executeTraversal(String traversal, Map<String, Object> params);