dddadc6289dc88bba0379f7fa822b1ddae5cc819
[usecase-ui/intent-analysis.git] /
1 /*
2  * Copyright (C) 2022 CMCC, Inc. and others. All rights reserved.
3  *
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
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16 package org.onap.usecaseui.intentanalysis.formatintentinputMgt.formatintentinputModule;
17
18 import org.apache.commons.lang.StringUtils;
19 import org.onap.usecaseui.intentanalysis.bean.models.Expectation;
20 import org.onap.usecaseui.intentanalysis.bean.models.IntentGoalBean;
21 import org.onap.usecaseui.intentanalysis.cllBusinessIntentMgt.CLLBusinessIntentManagementFunction;
22 import org.onap.usecaseui.intentanalysis.intentBaseService.IntentManagementFunction;
23 import org.onap.usecaseui.intentanalysis.intentBaseService.intentModule.DecisionModule;
24 import org.springframework.beans.factory.annotation.Autowired;
25 import org.springframework.context.ApplicationContext;
26 import org.springframework.stereotype.Component;
27
28 import java.util.LinkedHashMap;
29 import java.util.List;
30 import java.util.Locale;
31 import java.util.stream.Collectors;
32 @Component
33 public class FormatIntentInputDecisionModule extends DecisionModule {
34     @Autowired
35     ApplicationContext applicationContext;
36
37     @Override
38     public void determineUltimateGoal() {
39     }
40
41     @Override
42     public IntentManagementFunction exploreIntentHandlers(IntentGoalBean intentGoalBean) {
43         // if intentName contain cll  return
44         if (intentGoalBean.getIntent().getIntentName().toLowerCase(Locale.ROOT).contains("cll")) {
45             return (IntentManagementFunction) applicationContext.getBean(CLLBusinessIntentManagementFunction.class.getSimpleName());
46         }
47         return null;
48     }
49
50
51     @Override
52     public void decideSuitableAction() {
53     }
54
55     @Override
56     public void interactWithTemplateDb() {
57     }
58
59     @Override
60     public LinkedHashMap<IntentGoalBean, IntentManagementFunction> findHandler(IntentGoalBean intentGoalBean) {
61         LinkedHashMap<IntentGoalBean, IntentManagementFunction> intentMap = new LinkedHashMap<>();
62         boolean needDecompostion = needDecompostion(intentGoalBean);
63         if (needDecompostion) {
64             intentDecomposition(intentGoalBean);
65         } else {
66             intentMap.put(intentGoalBean, exploreIntentHandlers(intentGoalBean));
67         }
68         return intentMap;
69     }
70
71     public boolean needDecompostion(IntentGoalBean intentGoalBean) {
72         //expectationName just contain cll and slicing need decompost
73         List<Expectation> intentExpectations = intentGoalBean.getIntent().getIntentExpectations();
74         List<String> expectationNameList = intentExpectations.stream().map(Expectation::getExpectationName)
75                 .distinct().collect(Collectors.toList());
76         if (expectationNameList.size() > 1) {
77             List<String> cllList = expectationNameList.stream().filter(x -> StringUtils.containsIgnoreCase(x, "cll")).collect(Collectors.toList());
78             List<String> slicingList = expectationNameList.stream().filter(x -> StringUtils.containsIgnoreCase(x, "slicing")).collect(Collectors.toList());
79             if (cllList.size() > 0 && slicingList.size() > 0) {
80                 return true;
81             }
82         }
83         return false;
84     }
85
86     public List<IntentGoalBean> intentDecomposition(IntentGoalBean intentGoalBean) {
87         //todo
88         return null;
89     }
90 }