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