040ced315f797a327cb5b43a7e964989e13b0307
[usecase-ui/intent-analysis.git] /
1 /*
2  * Copyright (C) 2022 CMCC, Inc. and others. All rights reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package org.onap.usecaseui.intentanalysis.intentBaseService.intentModule;
17
18
19 import org.apache.commons.collections.CollectionUtils;
20 import org.onap.usecaseui.intentanalysis.bean.models.*;
21 import org.onap.usecaseui.intentanalysis.intentBaseService.IntentManagementFunction;
22 import org.onap.usecaseui.intentanalysis.util.CommonUtil;
23
24 import java.util.ArrayList;
25 import java.util.Collections;
26 import java.util.LinkedHashMap;
27 import java.util.List;
28
29 public abstract class DecisionModule {
30     public abstract void determineUltimateGoal();
31
32     // find intentManageFunction
33     public abstract IntentManagementFunction exploreIntentHandlers(IntentGoalBean intentGoalBean);
34
35     public Intent intentDefinition(Intent originIntent, Intent intent) {
36         intent.setIntentId(CommonUtil.getUUid());
37         List<Expectation> originalExpectationList = intent.getIntentExpectations();
38         List<Expectation> newExpectationList = getNewExpectationList(originalExpectationList);
39         intent.setIntentExpectations(newExpectationList);
40         return intent;
41     }
42
43     public abstract void decideSuitableAction();
44
45     public abstract void interactWithTemplateDb();
46
47     public abstract LinkedHashMap<IntentGoalBean, IntentManagementFunction> investigationCreateProcess(IntentGoalBean intentGoalBean);
48
49     public abstract LinkedHashMap<IntentGoalBean, IntentManagementFunction> investigationUpdateProcess(IntentGoalBean intentGoalBean);
50
51     public abstract LinkedHashMap<IntentGoalBean, IntentManagementFunction> investigationDeleteProcess(IntentGoalBean intentGoalBean);
52
53     /**
54      * build new Intent with uuid
55      *
56      * @param originalExpectationList
57      * @return
58      */
59     public List<Expectation> getNewExpectationList(List<Expectation> originalExpectationList) {
60         if (CollectionUtils.isEmpty(originalExpectationList)) {
61             return Collections.emptyList();
62         }
63         List<Expectation> newExpectations = new ArrayList<>();
64         for (Expectation expectation : originalExpectationList) {
65             expectation.setExpectationId(CommonUtil.getUUid());
66             //ExpectationObject
67             ExpectationObject expectationObject = expectation.getExpectationObject();
68             ExpectationObject newExpectationObject = getNewExpectationObject(expectationObject);
69             expectation.setExpectationObject(newExpectationObject);
70             //ExpectationTarget
71             List<ExpectationTarget> expectationTargets = expectation.getExpectationTargets();
72             if (CollectionUtils.isNotEmpty(expectationTargets)) {
73                 for (ExpectationTarget expectationTarget : expectationTargets) {
74                     expectationTarget.setTargetId(CommonUtil.getUUid());
75                     //targetContexts
76                     List<Context> targetContexts = expectationTarget.getTargetContexts();
77                     if (CollectionUtils.isNotEmpty(targetContexts)) {
78                         List<Context> newTargetContexts = new ArrayList<>();
79                         for (Context context : targetContexts) {
80                             Context newContext = getNewContext(context);
81                             newTargetContexts.add(newContext);
82                         }
83                         expectationTarget.setTargetContexts(newTargetContexts);
84                     }
85                     //targetConditions
86                     List<Condition> targetConditions = expectationTarget.getTargetConditions();
87                     if (CollectionUtils.isNotEmpty(targetConditions)) {
88                         List<Condition> newTargetConditions = new ArrayList<>();
89                         for (Condition condition : targetConditions) {
90                             Condition newCondition = getNewCondition(condition);
91                             newTargetConditions.add(newCondition);
92                         }
93                         expectationTarget.setTargetConditions(newTargetConditions);
94                     }
95                 }
96             }
97             //expectationContexts
98             List<Context> expectationContexts = expectation.getExpectationContexts();
99             if (CollectionUtils.isNotEmpty(expectationContexts)) {
100                 List<Context> newEexpectationContexts = new ArrayList<>();
101                 for (Context context : expectationContexts) {
102                     Context newContext = getNewContext(context);
103                     newEexpectationContexts.add(newContext);
104                 }
105                 expectation.setExpectationContexts(newEexpectationContexts);
106             }
107             newExpectations.add(expectation);
108         }
109         return newExpectations;
110     }
111
112     public ExpectationObject getNewExpectationObject(ExpectationObject expectationObject) {
113         if (null != expectationObject) {
114             List<Context> objectContexts = expectationObject.getObjectContexts();
115             if (CollectionUtils.isNotEmpty(objectContexts)) {
116                 List<Context> newObjectContexts = new ArrayList<>();
117                 for (Context context : objectContexts) {
118                     Context newContext = getNewContext(context);
119                     newObjectContexts.add(newContext);
120                 }
121                 expectationObject.setObjectContexts(newObjectContexts);
122                 return expectationObject;
123             }
124         }
125         return expectationObject;
126     }
127
128     public Condition getNewCondition(Condition condition) {
129         condition.setConditionId(CommonUtil.getUUid());
130         List<Condition> conditionList = condition.getConditionList();
131         if (CollectionUtils.isEmpty(conditionList)) {
132             return condition;
133         } else {
134             for (Condition subCondition : conditionList) {
135                 getNewCondition(subCondition);
136             }
137         }
138         return condition;
139     }
140
141     public Context getNewContext(Context context) {
142         context.setContextId(CommonUtil.getUUid());
143         List<Condition> contextConditions = context.getContextConditions();
144         if (CollectionUtils.isNotEmpty(contextConditions)) {
145             List<Condition> newConditionList = new ArrayList<>();
146             for (Condition condition : contextConditions) {
147                 newConditionList.add(getNewCondition(condition));
148             }
149             context.setContextConditions(newConditionList);
150         }
151         return context;
152     }
153
154
155 }