2 * Copyright (C) 2022 CMCC, Inc. and others. All rights reserved.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 package org.onap.usecaseui.intentanalysis.intentBaseService.intentModule;
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 import org.springframework.beans.BeanUtils;
25 import java.util.ArrayList;
26 import java.util.Collections;
27 import java.util.LinkedHashMap;
28 import java.util.List;
30 public abstract class DecisionModule {
31 public abstract void determineUltimateGoal();
33 // find intentManageFunction
34 public abstract IntentManagementFunction exploreIntentHandlers(IntentGoalBean intentGoalBean);
36 public Intent intentDefinition(Intent originIntent, Intent intent) {
37 Intent newIntent = new Intent();
38 newIntent.setIntentId(CommonUtil.getUUid());
39 newIntent.setIntentName(intent.getIntentName());
41 List<Expectation> originalExpectationList = intent.getIntentExpectations();
42 List<Expectation> newExpectationList = new ArrayList<>();
43 for (Expectation exp:originalExpectationList) {
44 Expectation expectation = new Expectation();
45 BeanUtils.copyProperties(exp,expectation);
46 newExpectationList.add(expectation);
48 List<Expectation> newIdExpectationList = getNewExpectationList(newExpectationList);
49 newIntent.setIntentExpectations(newIdExpectationList);
53 public abstract void decideSuitableAction();
55 public abstract void interactWithTemplateDb();
57 public abstract LinkedHashMap<IntentGoalBean, IntentManagementFunction> investigationCreateProcess(IntentGoalBean intentGoalBean);
59 public abstract LinkedHashMap<IntentGoalBean, IntentManagementFunction> investigationUpdateProcess(IntentGoalBean intentGoalBean);
61 public abstract LinkedHashMap<IntentGoalBean, IntentManagementFunction> investigationDeleteProcess(IntentGoalBean intentGoalBean);
64 * build new Intent with uuid
66 * @param originalExpectationList
69 public List<Expectation> getNewExpectationList(List<Expectation> originalExpectationList) {
70 if (CollectionUtils.isEmpty(originalExpectationList)) {
71 return Collections.emptyList();
73 List<Expectation> newExpectations = new ArrayList<>();
74 for (Expectation expectation : originalExpectationList) {
75 expectation.setExpectationId(CommonUtil.getUUid());
77 ExpectationObject expectationObject = expectation.getExpectationObject();
78 ExpectationObject newExpectationObject = getNewExpectationObject(expectationObject);
79 expectation.setExpectationObject(newExpectationObject);
81 List<ExpectationTarget> expectationTargets = expectation.getExpectationTargets();
82 List<ExpectationTarget> newExpTargetList = new ArrayList<>();
83 if (CollectionUtils.isNotEmpty(expectationTargets)) {
84 for (ExpectationTarget expectationTarget : expectationTargets) {
85 ExpectationTarget expTarget =new ExpectationTarget();
86 BeanUtils.copyProperties(expectationTarget,expTarget);
87 expTarget.setTargetId(CommonUtil.getUUid());
89 List<Context> targetContexts = expectationTarget.getTargetContexts();
90 if (CollectionUtils.isNotEmpty(targetContexts)) {
91 List<Context> newTargetContexts = new ArrayList<>();
92 for (Context context : targetContexts) {
93 Context con=new Context();
94 BeanUtils.copyProperties(context,con);
95 Context newContext = getNewContext(con);
96 newTargetContexts.add(newContext);
98 expTarget.setTargetContexts(newTargetContexts);
101 List<Condition> targetConditions = expectationTarget.getTargetConditions();
102 if (CollectionUtils.isNotEmpty(targetConditions)) {
103 List<Condition> newTargetConditions = new ArrayList<>();
104 for (Condition condition : targetConditions) {
105 Condition con =new Condition();
106 BeanUtils.copyProperties(condition,con);
107 Condition newCondition = getNewCondition(con);
108 newTargetConditions.add(newCondition);
110 expTarget.setTargetConditions(newTargetConditions);
112 newExpTargetList.add(expTarget);
114 expectation.setExpectationTargets(newExpTargetList);
116 //expectationContexts
117 List<Context> expectationContexts = expectation.getExpectationContexts();
118 if (CollectionUtils.isNotEmpty(expectationContexts)) {
119 List<Context> newEexpectationContexts = new ArrayList<>();
120 for (Context context : expectationContexts) {
121 Context newContext = getNewContext(context);
122 newEexpectationContexts.add(newContext);
124 expectation.setExpectationContexts(newEexpectationContexts);
126 newExpectations.add(expectation);
128 return newExpectations;
131 public ExpectationObject getNewExpectationObject(ExpectationObject expectationObject) {
132 if (null != expectationObject) {
133 List<Context> objectContexts = expectationObject.getObjectContexts();
134 if (CollectionUtils.isNotEmpty(objectContexts)) {
135 List<Context> newObjectContexts = new ArrayList<>();
136 for (Context context : objectContexts) {
137 Context newContext = getNewContext(context);
138 newObjectContexts.add(newContext);
140 expectationObject.setObjectContexts(newObjectContexts);
141 return expectationObject;
144 return expectationObject;
147 public Condition getNewCondition(Condition condition) {
148 condition.setConditionId(CommonUtil.getUUid());
149 List<Condition> conditionList = condition.getConditionList();
150 if (CollectionUtils.isEmpty(conditionList)) {
153 for (Condition subCondition : conditionList) {
154 getNewCondition(subCondition);
160 public Context getNewContext(Context context) {
161 context.setContextId(CommonUtil.getUUid());
162 List<Condition> contextConditions = context.getContextConditions();
163 if (CollectionUtils.isNotEmpty(contextConditions)) {
164 List<Condition> newConditionList = new ArrayList<>();
165 for (Condition condition : contextConditions) {
166 Condition con =new Condition();
167 BeanUtils.copyProperties(condition,con);
168 newConditionList.add(getNewCondition(con));
170 context.setContextConditions(newConditionList);