Initial commit with all the necessary files
[aai/aai-common.git] / aai-core / src / main / java / org / openecomp / aai / introspection / sideeffect / SideEffectRunnerHelper.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * org.openecomp.aai
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
10
11      http://www.apache.org/licenses/LICENSE-2.0
12
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=========================================================
19  */
20
21 package org.openecomp.aai.introspection.sideeffect;
22
23 import org.openecomp.aai.exceptions.AAIException;
24 import org.openecomp.aai.introspection.Introspector;
25 import org.openecomp.aai.introspection.Wanderer;
26 import org.openecomp.aai.serialization.db.DBSerializer;
27 import org.openecomp.aai.serialization.engines.TransactionalGraphEngine;
28
29 import java.io.UnsupportedEncodingException;
30 import java.lang.reflect.InvocationTargetException;
31 import java.net.URISyntaxException;
32 import java.util.List;
33 import java.util.Set;
34
35 class SideEffectRunnerHelper implements Wanderer {
36
37         
38         protected final TransactionalGraphEngine dbEngine;
39         protected final DBSerializer serializer;
40         protected final Set<Class<? extends SideEffect>> sideEffects;
41         protected SideEffectRunnerHelper(final TransactionalGraphEngine dbEngine, final DBSerializer serializer, final Set<Class<? extends SideEffect>> sideEffects) {
42                 this.dbEngine = dbEngine;
43                 this.serializer = serializer;
44                 this.sideEffects = sideEffects;
45         }
46         
47         private void runSideEffects(Introspector obj) throws AAIException {
48                 for (Class<? extends SideEffect> se : sideEffects) {
49                         try {
50                                 se.getConstructor(Introspector.class, TransactionalGraphEngine.class, DBSerializer.class)
51                                 .newInstance(obj, dbEngine, serializer).execute();
52                         } catch (UnsupportedEncodingException | InstantiationException | IllegalAccessException
53                                         | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException
54                                         | URISyntaxException e) {
55                                 throw new AAIException("strange exception", e);
56                         }
57                 }
58         }
59         @Override
60         public void processPrimitive(String propName, Introspector obj) {
61                 // TODO Auto-generated method stub
62
63         }
64
65         @Override
66         public void processPrimitiveList(String propName, Introspector obj) {
67                 // TODO Auto-generated method stub
68
69         }
70
71         @Override
72         public void processComplexObj(Introspector obj) throws AAIException {
73                 
74                 runSideEffects(obj);
75         
76         }
77
78         @Override
79         public void modifyComplexList(List<Introspector> list, List<Object> listReference, Introspector parent,
80                                   Introspector child) {
81                 // TODO Auto-generated method stub
82
83         }
84
85 }