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 java.util.ArrayList;
19 import org.apache.commons.lang.StringUtils;
20 import org.onap.usecaseui.intentanalysis.bean.enums.IntentGoalType;
21 import org.onap.usecaseui.intentanalysis.bean.enums.OperatorType;
22 import org.onap.usecaseui.intentanalysis.bean.models.Condition;
23 import org.onap.usecaseui.intentanalysis.bean.models.Context;
24 import org.onap.usecaseui.intentanalysis.bean.models.Expectation;
25 import org.onap.usecaseui.intentanalysis.bean.models.Intent;
26 import org.onap.usecaseui.intentanalysis.bean.models.IntentGoalBean;
27 import org.onap.usecaseui.intentanalysis.cllBusinessIntentMgt.CLLBusinessIntentManagementFunction;
28 import org.onap.usecaseui.intentanalysis.intentBaseService.IntentManagementFunction;
29 import org.onap.usecaseui.intentanalysis.intentBaseService.contextService.IntentContextService;
30 import org.onap.usecaseui.intentanalysis.intentBaseService.intentModule.DecisionModule;
31 import org.onap.usecaseui.intentanalysis.service.IntentService;
32 import org.onap.usecaseui.intentanalysis.util.CommonUtil;
33 import org.springframework.beans.factory.annotation.Autowired;
34 import org.springframework.context.ApplicationContext;
35 import org.springframework.stereotype.Component;
37 import java.util.LinkedHashMap;
38 import java.util.List;
39 import java.util.Locale;
40 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());
67 public void decideSuitableAction() {
71 public void interactWithTemplateDb() {
75 public LinkedHashMap<IntentGoalBean, IntentManagementFunction> investigationCreateProcess(IntentGoalBean intentGoalBean) {
76 LinkedHashMap<IntentGoalBean, IntentManagementFunction> intentMap = new LinkedHashMap<>();
77 boolean needDecompostion = needDecompostion(intentGoalBean);
78 if (needDecompostion) {
79 intentDecomposition(intentGoalBean);
81 intentMap.put(intentGoalBean, exploreIntentHandlers(intentGoalBean));
86 public boolean needDecompostion(IntentGoalBean intentGoalBean) {
87 //expectationName just contain cll and slicing need decompost
88 List<Expectation> intentExpectations = intentGoalBean.getIntent().getIntentExpectations();
89 List<String> expectationNameList = intentExpectations.stream().map(Expectation::getExpectationName)
90 .distinct().collect(Collectors.toList());
91 if (expectationNameList.size() > 1) {
92 List<String> cllList = expectationNameList.stream().filter(x -> StringUtils.containsIgnoreCase(x, "cll")).collect(Collectors.toList());
93 List<String> slicingList = expectationNameList.stream().filter(x -> StringUtils.containsIgnoreCase(x, "slicing")).collect(Collectors.toList());
94 if (cllList.size() > 0 && slicingList.size() > 0) {
101 public List<IntentGoalBean> intentDecomposition(IntentGoalBean intentGoalBean) {
108 public LinkedHashMap<IntentGoalBean, IntentManagementFunction> investigationUpdateProcess(IntentGoalBean intentGoalBean) {
109 //get format-cll intent
110 LinkedHashMap<IntentGoalBean, IntentManagementFunction> intentMap = new LinkedHashMap<>();
111 // update format-cll intentContext
112 Intent intent1 = intentService.getIntent(intentGoalBean.getIntent().getIntentId());
113 intentGoalBean.getIntent().setIntentContexts(intent1.getIntentContexts());
114 List<Intent> subIntentList = intentContextService.getSubIntentInfoFromContext(intentGoalBean.getIntent());
115 for (Intent intent : subIntentList) {
116 IntentManagementFunction intentHandlerInfo = intentContextService.getHandlerInfo(intent);
117 UpdateIntentInfo(intentGoalBean.getIntent(), intent);
118 IntentGoalBean subIntentGoalBean = new IntentGoalBean(intent, IntentGoalType.UPDATE);
119 intentMap.put(subIntentGoalBean, intentHandlerInfo);
124 public void UpdateIntentInfo(Intent originIntent, Intent intent){
126 List<Expectation> originIntentExpectationList = originIntent.getIntentExpectations();
127 List<Expectation> intentExpectationList = intent.getIntentExpectations();
128 int newIntentExpectationNum = originIntentExpectationList.size();
129 int oldIntentExpectationNum = intentExpectationList.size();
131 List<Expectation> changeList = new ArrayList<>();
132 if (newIntentExpectationNum != oldIntentExpectationNum){
133 if (newIntentExpectationNum < oldIntentExpectationNum){
135 for (Expectation oldExpectation : intentExpectationList) {//search
136 boolean bFindExpectation = false;
137 for (Expectation newExpectation : originIntentExpectationList) {//param
138 if (oldExpectation.getExpectationName().equals(newExpectation.getExpectationName())){
139 bFindExpectation = true;
143 if (bFindExpectation){
144 changeList.add(oldExpectation);
149 intent.setIntentExpectations(changeList);
153 public LinkedHashMap<IntentGoalBean, IntentManagementFunction> investigationDeleteProcess(IntentGoalBean intentGoalBean) {
154 LinkedHashMap<IntentGoalBean, IntentManagementFunction> intentMap = new LinkedHashMap<>();
155 List<Intent> subIntentList = intentContextService.getSubIntentInfoFromContext(intentGoalBean.getIntent());
156 for (Intent intent : subIntentList) {
157 IntentManagementFunction intentHandlerInfo = intentContextService.getHandlerInfo(intent);
158 IntentGoalBean subIntentGoalBean = new IntentGoalBean(intent, IntentGoalType.DELETE);
159 intentMap.put(subIntentGoalBean, intentHandlerInfo);