7a24bf2a40c137fd0e0248d2a4a7055a84265cea
[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.Intent;
21 import org.onap.usecaseui.intentanalysis.bean.models.IntentGoalBean;
22 import org.onap.usecaseui.intentanalysis.cllBusinessIntentMgt.CLLBusinessIntentManagementFunction;
23 import org.onap.usecaseui.intentanalysis.intentBaseService.IntentManagementFunction;
24 import org.onap.usecaseui.intentanalysis.intentBaseService.intentModule.DecisionModule;
25 import org.springframework.beans.factory.annotation.Autowired;
26 import org.springframework.context.ApplicationContext;
27 import org.springframework.stereotype.Component;
28
29 import java.util.LinkedHashMap;
30 import java.util.List;
31 import java.util.Locale;
32 import java.util.stream.Collectors;
33 @Component
34 public class FormatIntentInputDecisionModule extends DecisionModule {
35     @Autowired
36     ApplicationContext applicationContext;
37
38     @Override
39     public void determineUltimateGoal() {
40     }
41
42     @Override
43     public IntentManagementFunction exploreIntentHandlers(IntentGoalBean intentGoalBean) {
44         // if intentName contain cll  return
45         if (intentGoalBean.getIntent().getIntentName().toLowerCase(Locale.ROOT).contains("cll")) {
46             return (IntentManagementFunction) applicationContext.getBean(CLLBusinessIntentManagementFunction.class.getSimpleName());
47         }
48         return null;
49     }
50
51
52     @Override
53     public void decideSuitableAction() {
54     }
55
56     @Override
57     public void interactWithTemplateDb() {
58     }
59
60     @Override
61     public LinkedHashMap<IntentGoalBean, IntentManagementFunction> findHandler(IntentGoalBean intentGoalBean) {
62         LinkedHashMap<IntentGoalBean, IntentManagementFunction> intentMap = new LinkedHashMap<>();
63         boolean needDecompostion = needDecompostion(intentGoalBean);
64         if (needDecompostion) {
65             intentDecomposition(intentGoalBean);
66         } else {
67             intentMap.put(intentGoalBean, exploreIntentHandlers(intentGoalBean));
68         }
69         return intentMap;
70     }
71
72     public boolean needDecompostion(IntentGoalBean intentGoalBean) {
73         //expectationName just contain cll and slicing need decompost
74         List<Expectation> intentExpectations = intentGoalBean.getIntent().getIntentExpectations();
75         List<String> expectationNameList = intentExpectations.stream().map(Expectation::getExpectationName)
76                 .distinct().collect(Collectors.toList());
77         if (expectationNameList.size() > 1) {
78             List<String> cllList = expectationNameList.stream().filter(x -> StringUtils.containsIgnoreCase(x, "cll")).collect(Collectors.toList());
79             List<String> slicingList = expectationNameList.stream().filter(x -> StringUtils.containsIgnoreCase(x, "slicing")).collect(Collectors.toList());
80             if (cllList.size() > 0 && slicingList.size() > 0) {
81                 return true;
82             }
83         }
84         return false;
85     }
86
87     public List<IntentGoalBean> intentDecomposition(IntentGoalBean intentGoalBean) {
88         //todo
89         return null;
90     }
91
92
93     @Override
94     public void updateIntentWithOriginIntent(Intent originIntent, Intent intent){
95
96     }
97
98     @Override
99     public void updateIntentInfo(Intent originIntent, IntentGoalBean intentGoalBean){
100
101     }
102 }