1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
|
/*
* Copyright (C) 2022 CMCC, Inc. and others. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onap.usecaseui.intentanalysis.cllBusinessIntentMgt.cllBusinessModule;
import lombok.extern.log4j.Log4j2;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils;
import org.onap.usecaseui.intentanalysis.bean.enums.ExpectationType;
import org.onap.usecaseui.intentanalysis.bean.enums.IntentGoalType;
import org.onap.usecaseui.intentanalysis.bean.enums.ObjectType;
import org.onap.usecaseui.intentanalysis.bean.models.*;
import org.onap.usecaseui.intentanalysis.intentBaseService.IntentManagementFunction;
import org.onap.usecaseui.intentanalysis.intentBaseService.intentModule.DecisionModule;
import org.onap.usecaseui.intentanalysis.service.ImfRegInfoService;
import org.onap.usecaseui.intentanalysis.util.CommonUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component;
import java.util.*;
import java.util.stream.Collectors;
@Log4j2
@Component
public class CLLBusinessDecisionModule extends DecisionModule {
@Autowired
private ImfRegInfoService imfRegInfoService;
@Autowired
private ApplicationContext applicationContext;
@Override
public void determineUltimateGoal() {
}
@Override
public IntentManagementFunction exploreIntentHandlers(IntentGoalBean intentGoalBean) {
// db filter imf supportArea;
//SupportInterface> supportInterfaces;
IntentManagementFunctionRegInfo imfRegInfo = imfRegInfoService.getImfRegInfo(intentGoalBean);
return (IntentManagementFunction) applicationContext.getBean(imfRegInfo.getHandleName());
}
@Override
public void decideSuitableAction() {
}
public boolean needDecompostion(IntentGoalBean intentGoalBean) {
//different expectationType need decompostion ExpectationType>1 or objtype>1
if (intentGoalBean.getIntentGoalType().equals(IntentGoalType.CREATE)) {
List<Expectation> intentExpectations = intentGoalBean.getIntent().getIntentExpectations();
List<ExpectationType> expectationTypeList = intentExpectations.stream()
.map(Expectation::getExpectationType).distinct().collect(Collectors.toList());
if (expectationTypeList.size() > 1) {
return true;
} else {
List<ObjectType> objectTypeList = intentExpectations.stream().map(x ->
x.getExpectationObject().getObjectType()).distinct().collect(Collectors.toList());
if (objectTypeList.size() > 1) {
return true;
}
}
}
return false;
}
public List<IntentGoalBean> intentDecomposition(IntentGoalBean intentGoalBean) {
//ExpectationType expectation.ExpectationObject.objtype
Map<ExpectationType, List<Expectation>> expectationTypeListMap = intentGoalBean.getIntent().getIntentExpectations()
.stream().collect(Collectors.groupingBy(x -> x.getExpectationType()));
List<IntentGoalBean> subIntentGoalList = new ArrayList<>();
IntentGoalType intentGoalType = intentGoalBean.getIntentGoalType();
for (Map.Entry<ExpectationType, List<Expectation>> entry : expectationTypeListMap.entrySet()) {
Map<ObjectType, List<Expectation>> objTypeMap = entry.getValue().stream()
.collect(Collectors.groupingBy(x -> x.getExpectationObject().getObjectType()));
for (Map.Entry<ObjectType, List<Expectation>> objEntry : objTypeMap.entrySet()) {
IntentGoalBean subIntentGoalBean = new IntentGoalBean();
Intent subIntent = new Intent();
subIntent.setIntentName(objEntry.getValue().get(0).getExpectationName().replace("Expectation", "Intent"));
subIntent.setIntentExpectations(objEntry.getValue());
//List<Expectation> newExpectationList = getNewExpectationList(objEntry.getValue());
//subIntent.setIntentExpectations(newExpectationList);
//TODO intentFulfilmentInfo intentContexts
subIntentGoalBean.setIntentGoalType(intentGoalType);
subIntentGoalBean.setIntent(subIntent);
subIntentGoalList.add(subIntentGoalBean);
}
}
return subIntentGoalList;
}
public List<IntentGoalBean> intentOrchestration(List<IntentGoalBean> subIntentGoalList) {
List<IntentGoalBean> sortList = new ArrayList<>();
List<IntentGoalBean> deliveryGoalList = subIntentGoalList.stream().filter(x ->
StringUtils.containsIgnoreCase(x.getIntent().getIntentName(), "delivery")).collect(Collectors.toList());
List<IntentGoalBean> assuranceGoalList = subIntentGoalList.stream().filter(x ->
StringUtils.containsIgnoreCase(x.getIntent().getIntentName(), "assurance")).collect(Collectors.toList());
List<IntentGoalBean> otherGoalList = subIntentGoalList.stream().filter(x ->
!StringUtils.containsIgnoreCase(x.getIntent().getIntentName(), "delivery")
&& !StringUtils.containsIgnoreCase(x.getIntent().getIntentName(), "assurance")).collect(Collectors.toList());
sortList.addAll(deliveryGoalList);
sortList.addAll(assuranceGoalList);
sortList.addAll(otherGoalList);
return sortList;
}
@Override
public void interactWithTemplateDb() {
}
@Override
public LinkedHashMap<IntentGoalBean, IntentManagementFunction> findHandler(IntentGoalBean intentGoalBean) {
boolean needDecompostion = needDecompostion(intentGoalBean);
LinkedHashMap<IntentGoalBean, IntentManagementFunction> intentMap = new LinkedHashMap<>();
if (needDecompostion) {
List<IntentGoalBean> subIntentGoalList = intentDecomposition(intentGoalBean);
List<IntentGoalBean> sortList = intentOrchestration(subIntentGoalList);
for (IntentGoalBean subIntentGoal : sortList) {
IntentManagementFunction imf = exploreIntentHandlers(subIntentGoal);
intentMap.put(subIntentGoal, imf);
}
} else {
intentMap.put(intentGoalBean, exploreIntentHandlers(intentGoalBean));
}
return intentMap;
}
}
|