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.Expectation;
22 import org.onap.usecaseui.intentanalysis.bean.models.Intent;
23 import org.onap.usecaseui.intentanalysis.bean.models.IntentGoalBean;
24 import org.onap.usecaseui.intentanalysis.cllBusinessIntentMgt.CLLBusinessIntentManagementFunction;
25 import org.onap.usecaseui.intentanalysis.common.ResponseConsts;
26 import org.onap.usecaseui.intentanalysis.exception.IntentInputException;
27 import org.onap.usecaseui.intentanalysis.intentBaseService.IntentManagementFunction;
28 import org.onap.usecaseui.intentanalysis.intentBaseService.contextService.IntentContextService;
29 import org.onap.usecaseui.intentanalysis.intentBaseService.intentModule.DecisionModule;
30 import org.onap.usecaseui.intentanalysis.service.IntentService;
31 import org.springframework.beans.factory.annotation.Autowired;
32 import org.springframework.context.ApplicationContext;
33 import org.springframework.stereotype.Component;
35 import java.util.ArrayList;
36 import java.util.LinkedHashMap;
37 import java.util.List;
38 import java.util.Locale;
39 import java.util.stream.Collectors;
42 public class FormatIntentInputDecisionModule extends DecisionModule {
44 ApplicationContext applicationContext;
47 public IntentContextService intentContextService;
50 public IntentService intentService;
53 public void determineUltimateGoal() {
57 public IntentManagementFunction exploreIntentHandlers(IntentGoalBean intentGoalBean) {
58 // if intentName contain cll return
59 if (intentGoalBean.getIntent().getIntentName().toLowerCase(Locale.ROOT).contains("cll")) {
60 return (IntentManagementFunction) applicationContext.getBean(CLLBusinessIntentManagementFunction.class.getSimpleName());
62 String msg = String.format("intentName is: %s can't find corresponding IntentManagementFunction,please check Intent Name",intentGoalBean.getIntent().getIntentName());
64 throw new IntentInputException(msg, ResponseConsts.RET_FIND_CORRESPONDING_FAIL);
70 public void decideSuitableAction() {
74 public void interactWithTemplateDb() {
78 public LinkedHashMap<IntentGoalBean, IntentManagementFunction> investigationCreateProcess(IntentGoalBean intentGoalBean) {
79 log.info("FormatIntentInputMgt investigation create process start");
80 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 UpdateIntentInfo(intentGoalBean.getIntent(), intent);
125 IntentGoalBean subIntentGoalBean = new IntentGoalBean(intent, IntentGoalType.UPDATE);
126 intentMap.put(subIntentGoalBean, intentHandlerInfo);
128 log.info("FormatIntentInputMgt investigation update process finished");
132 public void UpdateIntentInfo(Intent originIntent, Intent intent){
134 List<Expectation> originIntentExpectationList = originIntent.getIntentExpectations();
135 List<Expectation> intentExpectationList = intent.getIntentExpectations();
136 int newIntentExpectationNum = originIntentExpectationList.size();
137 int oldIntentExpectationNum = intentExpectationList.size();
139 List<Expectation> changeList = new ArrayList<>();
140 if (newIntentExpectationNum != oldIntentExpectationNum){
141 if (newIntentExpectationNum < oldIntentExpectationNum){
143 for (Expectation oldExpectation : intentExpectationList) {//search
144 boolean bFindExpectation = false;
145 for (Expectation newExpectation : originIntentExpectationList) {//param
146 if (oldExpectation.getExpectationName().equals(newExpectation.getExpectationName())){
147 bFindExpectation = true;
151 if (bFindExpectation){
152 changeList.add(oldExpectation);
157 intent.setIntentExpectations(changeList);
161 public LinkedHashMap<IntentGoalBean, IntentManagementFunction> investigationDeleteProcess(IntentGoalBean intentGoalBean) {
162 LinkedHashMap<IntentGoalBean, IntentManagementFunction> intentMap = new LinkedHashMap<>();
163 List<Intent> subIntentList = intentContextService.getSubIntentInfoFromContext(intentGoalBean.getIntent());
164 for (Intent intent : subIntentList) {
165 IntentManagementFunction intentHandlerInfo = intentContextService.getHandlerInfo(intent);
166 IntentGoalBean subIntentGoalBean = new IntentGoalBean(intent, IntentGoalType.DELETE);
167 intentMap.put(subIntentGoalBean, intentHandlerInfo);