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 intent) {
36 intent.setIntentId(CommonUtil.getUUid());
37 List<Expectation> originalExpectationList = intent.getIntentExpectations();
38 List<Expectation> newExpectationList = getNewExpectationList(originalExpectationList);
39 intent.setIntentExpectations(newExpectationList);
43 public abstract void decideSuitableAction();
45 public abstract void interactWithTemplateDb();
48 public abstract LinkedHashMap<IntentGoalBean, IntentManagementFunction> findHandler(IntentGoalBean intentGoalBean);
51 * build new Intent with uuid
53 * @param originalExpectationList
56 public List<Expectation> getNewExpectationList(List<Expectation> originalExpectationList) {
57 if (CollectionUtils.isEmpty(originalExpectationList)) {
58 return Collections.emptyList();
60 List<Expectation> newExpectations = new ArrayList<>();
61 for (Expectation expectation : originalExpectationList) {
62 expectation.setExpectationId(CommonUtil.getUUid());
64 ExpectationObject expectationObject = expectation.getExpectationObject();
65 ExpectationObject newExpectationObject = getNewExpectationObject(expectationObject);
66 expectation.setExpectationObject(newExpectationObject);
68 List<ExpectationTarget> expectationTargets = expectation.getExpectationTargets();
69 if (CollectionUtils.isNotEmpty(expectationTargets)) {
70 for (ExpectationTarget expectationTarget : expectationTargets) {
71 expectationTarget.setTargetId(CommonUtil.getUUid());
73 List<Context> targetContexts = expectationTarget.getTargetContexts();
74 if (CollectionUtils.isNotEmpty(targetContexts)) {
75 List<Context> newTargetContexts = new ArrayList<>();
76 for (Context context : targetContexts) {
77 Context newContext = getNewContext(context);
78 newTargetContexts.add(newContext);
80 expectationTarget.setTargetContexts(newTargetContexts);
83 List<Condition> targetConditions = expectationTarget.getTargetConditions();
84 if (CollectionUtils.isNotEmpty(targetConditions)) {
85 List<Condition> newTargetConditions = new ArrayList<>();
86 for (Condition condition : targetConditions) {
87 Condition newCondition = getNewCondition(condition);
88 newTargetConditions.add(newCondition);
90 expectationTarget.setTargetConditions(newTargetConditions);
95 List<Context> expectationContexts = expectation.getExpectationContexts();
96 if (CollectionUtils.isNotEmpty(expectationContexts)) {
97 List<Context> newEexpectationContexts = new ArrayList<>();
98 for (Context context : expectationContexts) {
99 Context newContext = getNewContext(context);
100 newEexpectationContexts.add(newContext);
102 expectation.setExpectationContexts(newEexpectationContexts);
104 newExpectations.add(expectation);
106 return newExpectations;
109 public ExpectationObject getNewExpectationObject(ExpectationObject expectationObject) {
110 if (null != expectationObject) {
111 List<Context> objectContexts = expectationObject.getObjectContexts();
112 if (CollectionUtils.isNotEmpty(objectContexts)) {
113 List<Context> newObjectContexts = new ArrayList<>();
114 for (Context context : objectContexts) {
115 Context newContext = getNewContext(context);
116 newObjectContexts.add(newContext);
118 expectationObject.setObjectContexts(newObjectContexts);
119 return expectationObject;
122 return expectationObject;
125 public Condition getNewCondition(Condition condition) {
126 condition.setConditionId(CommonUtil.getUUid());
127 List<Condition> conditionList = condition.getConditionList();
128 if (CollectionUtils.isEmpty(conditionList)) {
131 for (Condition subCondition : conditionList) {
132 getNewCondition(subCondition);
138 public Context getNewContext(Context context) {
139 context.setContextId(CommonUtil.getUUid());
140 List<Condition> contextConditions = context.getContextConditions();
141 if (CollectionUtils.isNotEmpty(contextConditions)) {
142 List<Condition> newConditionList = new ArrayList<>();
143 for (Condition condition : contextConditions) {
144 newConditionList.add(getNewCondition(condition));
146 context.setContextConditions(newConditionList);