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.formatintentinputMgt.formatintentinputModule;
18 import lombok.extern.slf4j.Slf4j;
19 import org.apache.commons.lang.StringUtils;
20 import org.onap.usecaseui.intentanalysis.bean.enums.IntentGoalType;
21 import org.onap.usecaseui.intentanalysis.bean.models.*;
22 import org.onap.usecaseui.intentanalysis.cllBusinessIntentMgt.CLLBusinessIntentManagementFunction;
23 import org.onap.usecaseui.intentanalysis.common.ResponseConsts;
24 import org.onap.usecaseui.intentanalysis.exception.IntentInputException;
25 import org.onap.usecaseui.intentanalysis.intentBaseService.IntentManagementFunction;
26 import org.onap.usecaseui.intentanalysis.intentBaseService.contextService.IntentContextService;
27 import org.onap.usecaseui.intentanalysis.intentBaseService.intentModule.DecisionModule;
28 import org.onap.usecaseui.intentanalysis.service.IntentService;
29 import org.springframework.beans.factory.annotation.Autowired;
30 import org.springframework.context.ApplicationContext;
31 import org.springframework.stereotype.Component;
33 import java.util.ArrayList;
34 import java.util.LinkedHashMap;
35 import java.util.List;
36 import java.util.Locale;
37 import java.util.stream.Collectors;
41 public class FormatIntentInputDecisionModule extends DecisionModule {
43 ApplicationContext applicationContext;
46 public IntentContextService intentContextService;
49 public IntentService intentService;
52 public void determineUltimateGoal() {
56 public IntentManagementFunction exploreIntentHandlers(IntentGoalBean intentGoalBean) {
57 // if intentName contain cll return
58 if (intentGoalBean.getIntent().getIntentName().toLowerCase(Locale.ROOT).contains("cll")) {
59 return (IntentManagementFunction) applicationContext.getBean(CLLBusinessIntentManagementFunction.class.getSimpleName());
61 String msg = String.format("intentName is: %s can't find corresponding IntentManagementFunction,please check Intent Name", intentGoalBean.getIntent().getIntentName());
63 throw new IntentInputException(msg, ResponseConsts.RET_FIND_CORRESPONDING_FAIL);
69 public void decideSuitableAction() {
73 public void interactWithTemplateDb() {
77 public LinkedHashMap<IntentGoalBean, IntentManagementFunction> investigationCreateProcess(IntentGoalBean intentGoalBean) {
78 log.info("FormatIntentInputMgt investigation create process start");
79 LinkedHashMap<IntentGoalBean, IntentManagementFunction> intentMap = new LinkedHashMap<>();
81 boolean needDecompostion = needDecompostion(intentGoalBean);
82 log.debug("FormatIntentInputMgt need decompose :" + needDecompostion);
83 if (needDecompostion) {
84 intentDecomposition(intentGoalBean);
86 intentMap.put(intentGoalBean, exploreIntentHandlers(intentGoalBean));
88 log.info("FormatIntentInputMgt investigation create process finished");
92 public boolean needDecompostion(IntentGoalBean intentGoalBean) {
93 //expectationName just contain cll and slicing need decompost
94 List<Expectation> intentExpectations = intentGoalBean.getIntent().getIntentExpectations();
95 List<String> expectationNameList = intentExpectations.stream().map(Expectation::getExpectationName)
96 .distinct().collect(Collectors.toList());
97 if (expectationNameList.size() > 1) {
98 List<String> cllList = expectationNameList.stream().filter(x -> StringUtils.containsIgnoreCase(x, "cll")).collect(Collectors.toList());
99 List<String> slicingList = expectationNameList.stream().filter(x -> StringUtils.containsIgnoreCase(x, "slicing")).collect(Collectors.toList());
100 if (cllList.size() > 0 && slicingList.size() > 0) {
107 public List<IntentGoalBean> intentDecomposition(IntentGoalBean intentGoalBean) {
114 public LinkedHashMap<IntentGoalBean, IntentManagementFunction> investigationUpdateProcess(IntentGoalBean intentGoalBean) {
115 log.info("FormatIntentInputMgt investigation update process start");
116 //get format-cll intent
117 LinkedHashMap<IntentGoalBean, IntentManagementFunction> intentMap = new LinkedHashMap<>();
118 // update format-cll intentContext
119 Intent intent1 = intentService.getIntent(intentGoalBean.getIntent().getIntentId());
120 intentGoalBean.getIntent().setIntentContexts(intent1.getIntentContexts());
121 List<Intent> subIntentList = intentContextService.getSubIntentInfoFromContext(intentGoalBean.getIntent());
122 for (Intent intent : subIntentList) {
123 IntentManagementFunction intentHandlerInfo = intentContextService.getHandlerInfo(intent);
124 IntentGoalBean subIntentGoalBean = new IntentGoalBean(intent, IntentGoalType.UPDATE);
125 intentMap.put(subIntentGoalBean, intentHandlerInfo);
127 log.info("FormatIntentInputMgt investigation update process finished");
131 public void UpdateIntentInfo(Intent originIntent, Intent intent) {
133 List<Expectation> originIntentExpectationList = originIntent.getIntentExpectations();
134 List<Expectation> intentExpectationList = intent.getIntentExpectations();
135 int newIntentExpectationNum = originIntentExpectationList.size();
136 int oldIntentExpectationNum = intentExpectationList.size();
138 List<Expectation> changeList = new ArrayList<>();
139 if (newIntentExpectationNum != oldIntentExpectationNum) {
140 if (newIntentExpectationNum < oldIntentExpectationNum) {
142 for (Expectation oldExpectation : intentExpectationList) {//search
143 boolean bFindExpectation = false;
144 for (Expectation newExpectation : originIntentExpectationList) {//param
145 if (oldExpectation.getExpectationName().equals(newExpectation.getExpectationName())) {
146 bFindExpectation = true;
150 if (bFindExpectation) {
151 changeList.add(oldExpectation);
156 intent.setIntentExpectations(changeList);
160 public LinkedHashMap<IntentGoalBean, IntentManagementFunction> investigationDeleteProcess(IntentGoalBean intentGoalBean) {
161 LinkedHashMap<IntentGoalBean, IntentManagementFunction> intentMap = new LinkedHashMap<>();
162 List<Intent> subIntentList = intentContextService.getSubIntentInfoFromContext(intentGoalBean.getIntent());
163 for (Intent intent : subIntentList) {
164 IntentManagementFunction intentHandlerInfo = intentContextService.getHandlerInfo(intent);
165 IntentGoalBean subIntentGoalBean = new IntentGoalBean(intent, IntentGoalType.DELETE);
166 intentMap.put(subIntentGoalBean, intentHandlerInfo);