4faa719b26868d02e7210d901675dde9360057fd
[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.*;
29 import java.util.stream.Collectors;
30 @Component
31 public class FormatIntentInputDecisionModule extends DecisionModule {
32     @Autowired
33     ApplicationContext applicationContext;
34
35     @Override
36     public void determineUltimateGoal() {
37     }
38
39     @Override
40     public IntentManagementFunction exploreIntentHandlers(IntentGoalBean intentGoalBean) {
41         // if intentName contain cll  return
42         if (intentGoalBean.getIntent().getIntentName().toLowerCase(Locale.ROOT).contains("cll")) {
43         return (IntentManagementFunction) applicationContext.getBean(CLLBusinessIntentManagementFunction.class.getSimpleName());
44         }
45         return null;
46     }
47
48     @Override
49     public void intentDefinition() {
50     }
51
52     @Override
53     public void decideSuitableAction() {
54     }
55
56     @Override
57     public void interactWithTemplateDb() {
58     }
59
60     @Override
61     public List<Map<IntentGoalBean, IntentManagementFunction>> findHandler(IntentGoalBean intentGoalBean) {
62         List<Map<IntentGoalBean, IntentManagementFunction>> intentMapList = new ArrayList<>();
63         boolean needDecompostion = needDecompostion(intentGoalBean);
64         if (needDecompostion) {
65             intentDecomposition(intentGoalBean);
66         }else{
67             Map<IntentGoalBean, IntentManagementFunction> map = new HashMap<>();
68             map.put(intentGoalBean, exploreIntentHandlers(intentGoalBean));
69             intentMapList.add(map);
70         }
71         return intentMapList;
72     }
73
74     public boolean needDecompostion(IntentGoalBean intentGoalBean) {
75         //expectationName just contain cll and slicing need decompost
76         List<Expectation> intentExpectations = intentGoalBean.getIntent().getIntentExpectations();
77         List<String> expectationNameList = intentExpectations.stream().map(Expectation::getExpectationName)
78                 .distinct().collect(Collectors.toList());
79         if (expectationNameList.size() > 1) {
80             List<String> cllList = expectationNameList.stream().filter(x -> StringUtils.equalsIgnoreCase(x, "cll")).collect(Collectors.toList());
81             List<String> slicingList = expectationNameList.stream().filter(x -> StringUtils.equalsIgnoreCase(x, "slicing")).collect(Collectors.toList());
82             if (cllList.size() > 0 && slicingList.size() > 0) {
83                 return true;
84             }
85         }
86         return false;
87     }
88
89     public List<IntentGoalBean> intentDecomposition(IntentGoalBean intentGoalBean) {
90         //todo
91         return null;
92     }
93 }