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.introspection.sideeffect;
23 import com.att.eelf.configuration.EELFLogger;
24 import com.att.eelf.configuration.EELFManager;
26 import java.io.UnsupportedEncodingException;
27 import java.lang.reflect.InvocationTargetException;
28 import java.net.URISyntaxException;
29 import java.util.LinkedHashSet;
32 import org.apache.tinkerpop.gremlin.structure.Vertex;
33 import org.onap.aai.exceptions.AAIException;
34 import org.onap.aai.introspection.Introspector;
35 import org.onap.aai.serialization.db.DBSerializer;
36 import org.onap.aai.serialization.engines.TransactionalGraphEngine;
38 public class SideEffectRunner {
40 protected final TransactionalGraphEngine dbEngine;
41 protected final DBSerializer serializer;
42 protected final Set<Class<? extends SideEffect>> sideEffects;
44 protected SideEffectRunner(Builder builder) {
45 this.dbEngine = builder.getDbEngine();
46 this.serializer = builder.getSerializer();
47 this.sideEffects = builder.getSideEffects();
50 public void execute(Introspector obj, Vertex self) throws AAIException {
52 for (Class<? extends SideEffect> se : sideEffects) {
54 se.getConstructor(Introspector.class, Vertex.class, TransactionalGraphEngine.class, DBSerializer.class)
55 .newInstance(obj, self, dbEngine, serializer).execute();
56 } catch (UnsupportedEncodingException | InstantiationException | IllegalAccessException
57 | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException
58 | URISyntaxException e) {
59 throw new AAIException("strange exception", e);
64 public static class Builder {
66 private final TransactionalGraphEngine dbEngine;
67 private final DBSerializer serializer;
68 private final Set<Class<? extends SideEffect>> sideEffects;
70 public Builder(final TransactionalGraphEngine dbEngine, final DBSerializer serializer) {
71 this.dbEngine = dbEngine;
72 this.serializer = serializer;
73 this.sideEffects = new LinkedHashSet<>();
76 public Builder addSideEffect(Class<? extends SideEffect> se) {
81 public Builder addSideEffects(Class<? extends SideEffect>... sideEffects) {
82 for (Class<? extends SideEffect> se : sideEffects) {
83 this.addSideEffect(se);
88 public SideEffectRunner build() {
89 return new SideEffectRunner(this);
92 protected TransactionalGraphEngine getDbEngine() {
96 protected DBSerializer getSerializer() {
100 protected Set<Class<? extends SideEffect>> getSideEffects() {