2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 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=========================================================
21 package org.openecomp.aai.introspection.sideeffect;
23 import org.apache.tinkerpop.gremlin.structure.Vertex;
24 import org.openecomp.aai.exceptions.AAIException;
25 import org.openecomp.aai.introspection.Introspector;
26 import org.openecomp.aai.serialization.db.DBSerializer;
27 import org.openecomp.aai.serialization.engines.TransactionalGraphEngine;
29 import java.io.UnsupportedEncodingException;
30 import java.lang.reflect.InvocationTargetException;
31 import java.net.URISyntaxException;
32 import java.util.LinkedHashSet;
35 public class SideEffectRunner {
37 protected final TransactionalGraphEngine dbEngine;
38 protected final DBSerializer serializer;
39 protected final Set<Class<? extends SideEffect>> sideEffects;
40 protected SideEffectRunner(Builder builder) {
41 this.dbEngine = builder.getDbEngine();
42 this.serializer = builder.getSerializer();
43 this.sideEffects = builder.getSideEffects();
46 public void execute(Introspector obj, Vertex self) throws AAIException {
48 for (Class<? extends SideEffect> se : sideEffects) {
50 se.getConstructor(Introspector.class, Vertex.class, TransactionalGraphEngine.class, DBSerializer.class)
51 .newInstance(obj, self, dbEngine, serializer).execute();
52 } catch (UnsupportedEncodingException | InstantiationException | IllegalAccessException
53 | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException
54 | URISyntaxException e) {
55 throw new AAIException("strange exception", e);
60 public static class Builder {
62 private final TransactionalGraphEngine dbEngine;
63 private final DBSerializer serializer;
64 private final Set<Class<? extends SideEffect>> sideEffects;
66 public Builder(final TransactionalGraphEngine dbEngine, final DBSerializer serializer) {
67 this.dbEngine = dbEngine;
68 this.serializer = serializer;
69 this.sideEffects = new LinkedHashSet<>();
72 public Builder addSideEffect(Class<? extends SideEffect> se) {
77 public Builder addSideEffects(Class<? extends SideEffect>... sideEffects) {
78 for (Class<? extends SideEffect> se : sideEffects) {
79 this.addSideEffect(se);
84 public SideEffectRunner build() {
85 return new SideEffectRunner(this);
87 protected TransactionalGraphEngine getDbEngine() {
91 protected DBSerializer getSerializer() {
95 protected Set<Class<? extends SideEffect>> getSideEffects() {