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);
43 public abstract void decideSuitableAction();
45 public abstract void interactWithTemplateDb();
47 public abstract LinkedHashMap<IntentGoalBean, IntentManagementFunction> investigationCreateProcess(IntentGoalBean intentGoalBean);
49 public abstract LinkedHashMap<IntentGoalBean, IntentManagementFunction> investigationUpdateProcess(IntentGoalBean intentGoalBean);
51 public abstract LinkedHashMap<IntentGoalBean, IntentManagementFunction> investigationDeleteProcess(IntentGoalBean intentGoalBean);
54 * build new Intent with uuid
56 * @param originalExpectationList
59 public List<Expectation> getNewExpectationList(List<Expectation> originalExpectationList) {
60 if (CollectionUtils.isEmpty(originalExpectationList)) {
61 return Collections.emptyList();
63 List<Expectation> newExpectations = new ArrayList<>();
64 for (Expectation expectation : originalExpectationList) {
65 expectation.setExpectationId(CommonUtil.getUUid());
67 ExpectationObject expectationObject = expectation.getExpectationObject();
68 ExpectationObject newExpectationObject = getNewExpectationObject(expectationObject);
69 expectation.setExpectationObject(newExpectationObject);
71 List<ExpectationTarget> expectationTargets = expectation.getExpectationTargets();
72 if (CollectionUtils.isNotEmpty(expectationTargets)) {
73 for (ExpectationTarget expectationTarget : expectationTargets) {
74 expectationTarget.setTargetId(CommonUtil.getUUid());
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);
83 expectationTarget.setTargetContexts(newTargetContexts);
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);
93 expectationTarget.setTargetConditions(newTargetConditions);
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);
105 expectation.setExpectationContexts(newEexpectationContexts);
107 newExpectations.add(expectation);
109 return newExpectations;
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);
121 expectationObject.setObjectContexts(newObjectContexts);
122 return expectationObject;
125 return expectationObject;
128 public Condition getNewCondition(Condition condition) {
129 condition.setConditionId(CommonUtil.getUUid());
130 List<Condition> conditionList = condition.getConditionList();
131 if (CollectionUtils.isEmpty(conditionList)) {
134 for (Condition subCondition : conditionList) {
135 getNewCondition(subCondition);
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));
149 context.setContextConditions(newConditionList);