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 List<Intent> subIntentList = intentContextService.getSubIntentInfoFromContext(intentGoalBean.getIntent());
112 for (Intent intent : subIntentList) {
113 IntentManagementFunction intentHandlerInfo = intentContextService.getHandlerInfo(intent);
114 UpdateIntentInfo(intentGoalBean.getIntent(), intent);
115 IntentGoalBean subIntentGoalBean = new IntentGoalBean(intent, IntentGoalType.UPDATE);
116 intentMap.put(subIntentGoalBean, intentHandlerInfo);
121 public void UpdateIntentInfo(Intent originIntent, Intent intent){
123 List<Expectation> originIntentExpectationList = originIntent.getIntentExpectations();
124 List<Expectation> intentExpectationList = intent.getIntentExpectations();
125 int newIntentExpectationNum = originIntentExpectationList.size();
126 int oldIntentExpectationNum = intentExpectationList.size();
128 if (newIntentExpectationNum != oldIntentExpectationNum){
129 if (newIntentExpectationNum < oldIntentExpectationNum){
130 boolean bFindExpectation = false;
131 for (Expectation oldExpectation : intentExpectationList) {
132 for (Expectation newExpectation : originIntentExpectationList) {
133 if (oldExpectation.getExpectationName().equals(newExpectation.getExpectationName())){
134 bFindExpectation = true;
137 if (bFindExpectation == false){
138 intentExpectationList.remove(oldExpectation);
147 public LinkedHashMap<IntentGoalBean, IntentManagementFunction> investigationDeleteProcess(IntentGoalBean intentGoalBean) {
148 LinkedHashMap<IntentGoalBean, IntentManagementFunction> intentMap = new LinkedHashMap<>();
149 List<Intent> subIntentList = intentContextService.getSubIntentInfoFromContext(intentGoalBean.getIntent());
150 for (Intent intent : subIntentList) {
151 IntentManagementFunction intentHandlerInfo = intentContextService.getHandlerInfo(intent);
152 IntentGoalBean subIntentGoalBean = new IntentGoalBean(intent, IntentGoalType.DELETE);
153 intentMap.put(subIntentGoalBean, intentHandlerInfo);