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 java.io.UnsupportedEncodingException;
24 import java.lang.reflect.InvocationTargetException;
25 import java.net.URISyntaxException;
26 import java.util.LinkedHashSet;
29 import org.apache.tinkerpop.gremlin.structure.Vertex;
31 import org.openecomp.aai.exceptions.AAIException;
32 import org.openecomp.aai.introspection.Introspector;
33 import org.openecomp.aai.serialization.db.DBSerializer;
34 import org.openecomp.aai.serialization.engines.TransactionalGraphEngine;
36 public class SideEffectRunner {
38 protected final TransactionalGraphEngine dbEngine;
39 protected final DBSerializer serializer;
40 protected final Set<Class<? extends SideEffect>> sideEffects;
41 protected SideEffectRunner(Builder builder) {
42 this.dbEngine = builder.getDbEngine();
43 this.serializer = builder.getSerializer();
44 this.sideEffects = builder.getSideEffects();
47 public void execute(Introspector obj, Vertex self) throws AAIException {
49 for (Class<? extends SideEffect> se : sideEffects) {
51 se.getConstructor(Introspector.class, Vertex.class, TransactionalGraphEngine.class, DBSerializer.class)
52 .newInstance(obj, self, dbEngine, serializer).execute();
53 } catch (UnsupportedEncodingException | InstantiationException | IllegalAccessException
54 | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException
55 | URISyntaxException e) {
56 throw new AAIException("strange exception", e);
61 public static class Builder {
63 private final TransactionalGraphEngine dbEngine;
64 private final DBSerializer serializer;
65 private final Set<Class<? extends SideEffect>> sideEffects;
67 public Builder(final TransactionalGraphEngine dbEngine, final DBSerializer serializer) {
68 this.dbEngine = dbEngine;
69 this.serializer = serializer;
70 this.sideEffects = new LinkedHashSet<>();
73 public Builder addSideEffect(Class<? extends SideEffect> se) {
78 public Builder addSideEffects(Class<? extends SideEffect>... sideEffects) {
79 for (Class<? extends SideEffect> se : sideEffects) {
80 this.addSideEffect(se);
85 public SideEffectRunner build() {
86 return new SideEffectRunner(this);
88 protected TransactionalGraphEngine getDbEngine() {
92 protected DBSerializer getSerializer() {
96 protected Set<Class<? extends SideEffect>> getSideEffects() {