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 lombok.extern.slf4j.Slf4j;
20 import org.apache.commons.collections.CollectionUtils;
21 import org.onap.usecaseui.intentanalysis.bean.enums.IntentGenerateType;
22 import org.onap.usecaseui.intentanalysis.bean.models.*;
23 import org.onap.usecaseui.intentanalysis.intentBaseService.IntentManagementFunction;
24 import org.onap.usecaseui.intentanalysis.util.CommonUtil;
25 import org.springframework.beans.BeanUtils;
27 import java.util.ArrayList;
28 import java.util.Collections;
29 import java.util.LinkedHashMap;
30 import java.util.List;
32 public abstract class DecisionModule {
33 public abstract void determineUltimateGoal();
35 // find intentManageFunction
36 public abstract IntentManagementFunction exploreIntentHandlers(IntentGoalBean intentGoalBean);
38 public Intent intentDefinition(Intent originIntent, Intent intent) {
39 log.debug("definition create process start to define intent:" + intent.getIntentName());
40 Intent newIntent = new Intent();
41 newIntent.setIntentId(CommonUtil.getUUid());
42 newIntent.setIntentName(intent.getIntentName());
43 newIntent.setIntentGenerateType(IntentGenerateType.SYSTEMGENARATE);
45 List<Expectation> originalExpectationList = intent.getIntentExpectations();
46 List<Expectation> newExpectationList = new ArrayList<>();
47 for (Expectation exp:originalExpectationList) {
48 Expectation expectation = new Expectation();
49 BeanUtils.copyProperties(exp,expectation);
50 newExpectationList.add(expectation);
52 List<Expectation> newIdExpectationList = getNewExpectationList(newExpectationList);
53 newIntent.setIntentExpectations(newIdExpectationList);
57 public abstract void decideSuitableAction();
59 public abstract void interactWithTemplateDb();
61 public abstract LinkedHashMap<IntentGoalBean, IntentManagementFunction> investigationCreateProcess(IntentGoalBean intentGoalBean);
63 public abstract LinkedHashMap<IntentGoalBean, IntentManagementFunction> investigationUpdateProcess(IntentGoalBean intentGoalBean);
65 public abstract LinkedHashMap<IntentGoalBean, IntentManagementFunction> investigationDeleteProcess(IntentGoalBean intentGoalBean);
68 * build new Intent with uuid
70 * @param originalExpectationList
73 public List<Expectation> getNewExpectationList(List<Expectation> originalExpectationList) {
74 if (CollectionUtils.isEmpty(originalExpectationList)) {
75 return Collections.emptyList();
77 List<Expectation> newExpectations = new ArrayList<>();
78 for (Expectation expectation : originalExpectationList) {
79 expectation.setExpectationId(CommonUtil.getUUid());
81 ExpectationObject expectationObject = expectation.getExpectationObject();
82 ExpectationObject newExpectationObject = getNewExpectationObject(expectationObject);
83 expectation.setExpectationObject(newExpectationObject);
85 List<ExpectationTarget> expectationTargets = expectation.getExpectationTargets();
86 List<ExpectationTarget> newExpTargetList = new ArrayList<>();
87 if (CollectionUtils.isNotEmpty(expectationTargets)) {
88 for (ExpectationTarget expectationTarget : expectationTargets) {
89 ExpectationTarget expTarget =new ExpectationTarget();
90 BeanUtils.copyProperties(expectationTarget,expTarget);
91 expTarget.setTargetId(CommonUtil.getUUid());
93 List<Context> targetContexts = expectationTarget.getTargetContexts();
94 if (CollectionUtils.isNotEmpty(targetContexts)) {
95 List<Context> newTargetContexts = new ArrayList<>();
96 for (Context context : targetContexts) {
97 Context con=new Context();
98 BeanUtils.copyProperties(context,con);
99 Context newContext = getNewContext(con);
100 newTargetContexts.add(newContext);
102 expTarget.setTargetContexts(newTargetContexts);
105 List<Condition> targetConditions = expectationTarget.getTargetConditions();
106 if (CollectionUtils.isNotEmpty(targetConditions)) {
107 List<Condition> newTargetConditions = new ArrayList<>();
108 for (Condition condition : targetConditions) {
109 Condition con =new Condition();
110 BeanUtils.copyProperties(condition,con);
111 Condition newCondition = getNewCondition(con);
112 newTargetConditions.add(newCondition);
114 expTarget.setTargetConditions(newTargetConditions);
116 newExpTargetList.add(expTarget);
118 expectation.setExpectationTargets(newExpTargetList);
120 //expectationContexts
121 List<Context> expectationContexts = expectation.getExpectationContexts();
122 if (CollectionUtils.isNotEmpty(expectationContexts)) {
123 List<Context> newEexpectationContexts = new ArrayList<>();
124 for (Context context : expectationContexts) {
125 Context newContext = getNewContext(context);
126 newEexpectationContexts.add(newContext);
128 expectation.setExpectationContexts(newEexpectationContexts);
130 newExpectations.add(expectation);
132 return newExpectations;
135 public ExpectationObject getNewExpectationObject(ExpectationObject expectationObject) {
136 if (null != expectationObject) {
137 List<Context> objectContexts = expectationObject.getObjectContexts();
138 if (CollectionUtils.isNotEmpty(objectContexts)) {
139 List<Context> newObjectContexts = new ArrayList<>();
140 for (Context context : objectContexts) {
141 Context newContext = getNewContext(context);
142 newObjectContexts.add(newContext);
144 expectationObject.setObjectContexts(newObjectContexts);
145 return expectationObject;
148 return expectationObject;
151 public Condition getNewCondition(Condition condition) {
152 condition.setConditionId(CommonUtil.getUUid());
153 List<Condition> conditionList = condition.getConditionList();
154 if (CollectionUtils.isEmpty(conditionList)) {
157 for (Condition subCondition : conditionList) {
158 getNewCondition(subCondition);
164 public Context getNewContext(Context context) {
165 context.setContextId(CommonUtil.getUUid());
166 List<Condition> contextConditions = context.getContextConditions();
167 if (CollectionUtils.isNotEmpty(contextConditions)) {
168 List<Condition> newConditionList = new ArrayList<>();
169 for (Condition condition : contextConditions) {
170 Condition con =new Condition();
171 BeanUtils.copyProperties(condition,con);
172 newConditionList.add(getNewCondition(con));
174 context.setContextConditions(newConditionList);