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;
24 import java.util.ArrayList;
25 import java.util.Collections;
26 import java.util.LinkedHashMap;
27 import java.util.List;
29 public abstract class DecisionModule {
30 public abstract void determineUltimateGoal();
32 // find intentManageFunction
33 public abstract IntentManagementFunction exploreIntentHandlers(IntentGoalBean intentGoalBean);
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 updateIntentWithOriginIntent(originIntent, intent);
44 public abstract void updateIntentWithOriginIntent(Intent originIntent, Intent intent);
46 public abstract void decideSuitableAction();
48 public abstract void interactWithTemplateDb();
50 public abstract void updateIntentInfo(Intent originIntent, IntentGoalBean intentGoalBean);
53 public abstract LinkedHashMap<IntentGoalBean, IntentManagementFunction> findHandler(IntentGoalBean intentGoalBean);
56 * build new Intent with uuid
58 * @param originalExpectationList
61 public List<Expectation> getNewExpectationList(List<Expectation> originalExpectationList) {
62 if (CollectionUtils.isEmpty(originalExpectationList)) {
63 return Collections.emptyList();
65 List<Expectation> newExpectations = new ArrayList<>();
66 for (Expectation expectation : originalExpectationList) {
67 expectation.setExpectationId(CommonUtil.getUUid());
69 ExpectationObject expectationObject = expectation.getExpectationObject();
70 ExpectationObject newExpectationObject = getNewExpectationObject(expectationObject);
71 expectation.setExpectationObject(newExpectationObject);
73 List<ExpectationTarget> expectationTargets = expectation.getExpectationTargets();
74 if (CollectionUtils.isNotEmpty(expectationTargets)) {
75 for (ExpectationTarget expectationTarget : expectationTargets) {
76 expectationTarget.setTargetId(CommonUtil.getUUid());
78 List<Context> targetContexts = expectationTarget.getTargetContexts();
79 if (CollectionUtils.isNotEmpty(targetContexts)) {
80 List<Context> newTargetContexts = new ArrayList<>();
81 for (Context context : targetContexts) {
82 Context newContext = getNewContext(context);
83 newTargetContexts.add(newContext);
85 expectationTarget.setTargetContexts(newTargetContexts);
88 List<Condition> targetConditions = expectationTarget.getTargetConditions();
89 if (CollectionUtils.isNotEmpty(targetConditions)) {
90 List<Condition> newTargetConditions = new ArrayList<>();
91 for (Condition condition : targetConditions) {
92 Condition newCondition = getNewCondition(condition);
93 newTargetConditions.add(newCondition);
95 expectationTarget.setTargetConditions(newTargetConditions);
100 List<Context> expectationContexts = expectation.getExpectationContexts();
101 if (CollectionUtils.isNotEmpty(expectationContexts)) {
102 List<Context> newEexpectationContexts = new ArrayList<>();
103 for (Context context : expectationContexts) {
104 Context newContext = getNewContext(context);
105 newEexpectationContexts.add(newContext);
107 expectation.setExpectationContexts(newEexpectationContexts);
109 newExpectations.add(expectation);
111 return newExpectations;
114 public ExpectationObject getNewExpectationObject(ExpectationObject expectationObject) {
115 if (null != expectationObject) {
116 List<Context> objectContexts = expectationObject.getObjectContexts();
117 if (CollectionUtils.isNotEmpty(objectContexts)) {
118 List<Context> newObjectContexts = new ArrayList<>();
119 for (Context context : objectContexts) {
120 Context newContext = getNewContext(context);
121 newObjectContexts.add(newContext);
123 expectationObject.setObjectContexts(newObjectContexts);
124 return expectationObject;
127 return expectationObject;
130 public Condition getNewCondition(Condition condition) {
131 condition.setConditionId(CommonUtil.getUUid());
132 List<Condition> conditionList = condition.getConditionList();
133 if (CollectionUtils.isEmpty(conditionList)) {
136 for (Condition subCondition : conditionList) {
137 getNewCondition(subCondition);
143 public Context getNewContext(Context context) {
144 context.setContextId(CommonUtil.getUUid());
145 List<Condition> contextConditions = context.getContextConditions();
146 if (CollectionUtils.isNotEmpty(contextConditions)) {
147 List<Condition> newConditionList = new ArrayList<>();
148 for (Condition condition : contextConditions) {
149 newConditionList.add(getNewCondition(condition));
151 context.setContextConditions(newConditionList);