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.cllBusinessIntentMgt.cllBusinessModule;
18 import lombok.extern.log4j.Log4j2;
19 import org.apache.commons.lang.StringUtils;
20 import org.onap.usecaseui.intentanalysis.bean.enums.ExpectationType;
21 import org.onap.usecaseui.intentanalysis.bean.enums.IntentGenerateType;
22 import org.onap.usecaseui.intentanalysis.bean.enums.IntentGoalType;
23 import org.onap.usecaseui.intentanalysis.bean.enums.ObjectType;
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.bean.models.IntentManagementFunctionRegInfo;
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.ImfRegInfoService;
32 import org.onap.usecaseui.intentanalysis.service.IntentService;
33 import org.springframework.beans.factory.annotation.Autowired;
34 import org.springframework.context.ApplicationContext;
35 import org.springframework.stereotype.Component;
37 import java.util.ArrayList;
38 import java.util.LinkedHashMap;
39 import java.util.List;
41 import java.util.stream.Collectors;
45 public class CLLBusinessDecisionModule extends DecisionModule {
47 private ImfRegInfoService imfRegInfoService;
49 private ApplicationContext applicationContext;
52 IntentService intentService;
55 IntentContextService intentContextService;
58 public void determineUltimateGoal() {
62 public IntentManagementFunction exploreIntentHandlers(IntentGoalBean intentGoalBean) {
63 // db filter imf supportArea;
64 //SupportInterface> supportInterfaces;
65 IntentManagementFunctionRegInfo imfRegInfo = imfRegInfoService.getImfRegInfo(intentGoalBean);
66 return (IntentManagementFunction) applicationContext.getBean(imfRegInfo.getHandleName());
71 public void decideSuitableAction() {
75 public boolean needDecompostion(IntentGoalBean intentGoalBean) {
76 //different expectationType need decompostion ExpectationType>1 or objtype>1
77 if (intentGoalBean.getIntentGoalType().equals(IntentGoalType.CREATE)) {
78 List<Expectation> intentExpectations = intentGoalBean.getIntent().getIntentExpectations();
79 List<ExpectationType> expectationTypeList = intentExpectations.stream()
80 .map(Expectation::getExpectationType)
81 .filter(expectationType -> !ExpectationType.REPORT.equals(expectationType)).distinct().collect(Collectors.toList());
82 if (expectationTypeList.size() > 1) {
85 List<ObjectType> objectTypeList = intentExpectations.stream().map(x ->
86 x.getExpectationObject().getObjectType()).distinct().collect(Collectors.toList());
87 return objectTypeList.size() > 1;
93 public List<IntentGoalBean> intentDecomposition(IntentGoalBean intentGoalBean) {
94 List<Expectation> intentExpectations = intentGoalBean.getIntent().getIntentExpectations();
95 List<Expectation> report = intentExpectations.stream()
96 .filter(expectation -> ExpectationType.REPORT.equals(expectation.getExpectationType()))
97 .collect(Collectors.toList());
98 //ExpectationType expectation.ExpectationObject.objtype
99 Map<ExpectationType, List<Expectation>> expectationTypeListMap = intentExpectations.stream()
100 .filter(expectation -> !ExpectationType.REPORT.equals(expectation.getExpectationType()))
101 .collect(Collectors.groupingBy(Expectation::getExpectationType));
102 List<IntentGoalBean> subIntentGoalList = new ArrayList<>();
103 IntentGoalType intentGoalType = intentGoalBean.getIntentGoalType();
104 for (Map.Entry<ExpectationType, List<Expectation>> entry : expectationTypeListMap.entrySet()) {
106 Map<ObjectType, List<Expectation>> objTypeMap = entry.getValue().stream()
107 .collect(Collectors.groupingBy(x -> x.getExpectationObject().getObjectType()));
108 for (Map.Entry<ObjectType, List<Expectation>> objEntry : objTypeMap.entrySet()) {
109 IntentGoalBean subIntentGoalBean = new IntentGoalBean();
110 Intent subIntent = new Intent();
111 subIntent.setIntentName(objEntry.getValue().get(0).getExpectationName().replace("Expectation", "Intent"));
112 List<Expectation> value = objEntry.getValue();
113 value.addAll(report);
114 subIntent.setIntentExpectations(value);
115 subIntent.setIntentGenerateType(IntentGenerateType.SYSTEMGENARATE);
116 //TODO intentFulfillmentInfo intentContexts
117 subIntentGoalBean.setIntentGoalType(intentGoalType);
118 subIntentGoalBean.setIntent(subIntent);
119 subIntentGoalList.add(subIntentGoalBean);
122 return subIntentGoalList;
125 public List<IntentGoalBean> intentOrchestration(List<IntentGoalBean> subIntentGoalList) {
126 List<IntentGoalBean> sortList = new ArrayList<>();
127 List<IntentGoalBean> deliveryGoalList = subIntentGoalList.stream().filter(x ->
128 StringUtils.containsIgnoreCase(x.getIntent().getIntentName(), "delivery")).collect(Collectors.toList());
129 List<IntentGoalBean> assuranceGoalList = subIntentGoalList.stream().filter(x ->
130 StringUtils.containsIgnoreCase(x.getIntent().getIntentName(), "assurance")).collect(Collectors.toList());
131 List<IntentGoalBean> otherGoalList = subIntentGoalList.stream().filter(x ->
132 !StringUtils.containsIgnoreCase(x.getIntent().getIntentName(), "delivery")
133 && !StringUtils.containsIgnoreCase(x.getIntent().getIntentName(), "assurance")).collect(Collectors.toList());
134 sortList.addAll(deliveryGoalList);
135 sortList.addAll(assuranceGoalList);
136 sortList.addAll(otherGoalList);
141 public void interactWithTemplateDb() {
145 public LinkedHashMap<IntentGoalBean, IntentManagementFunction> investigationCreateProcess(IntentGoalBean intentGoalBean) {
146 log.info("CLLBusinessIntentManagementFunction investigation create process start");
147 boolean needDecompostion = needDecompostion(intentGoalBean);
148 log.debug("CLLBusinessIntentManagementFunction need decompose :" + needDecompostion);
149 LinkedHashMap<IntentGoalBean, IntentManagementFunction> intentMap = new LinkedHashMap<>();
150 if (needDecompostion) {
151 List<IntentGoalBean> subIntentGoalList = intentDecomposition(intentGoalBean);
152 List<IntentGoalBean> sortList = intentOrchestration(subIntentGoalList);
153 for (IntentGoalBean subIntentGoal : sortList) {
154 IntentManagementFunction imf = exploreIntentHandlers(subIntentGoal);
155 intentMap.put(subIntentGoal, imf);
158 intentMap.put(intentGoalBean, exploreIntentHandlers(intentGoalBean));
160 log.info("CLLBusinessIntentManagementFunction investigation create process finished");
161 log.debug("CLLBusinessIntentManagementFunction decomposed subIntent list name :"
162 + StringUtils.join(intentMap.keySet().stream().map(IntentGoalBean::getIntent)
163 .map(Intent::getIntentName).collect(Collectors.toList()), ","));
170 public LinkedHashMap<IntentGoalBean, IntentManagementFunction> investigationUpdateProcess(IntentGoalBean intentGoalBean) {
171 log.info("CLLBusinessIntentManagementFunction investigation update process start");
172 //get cll-delivery cll-assurance intent
173 Intent originIntent = intentGoalBean.getIntent();
174 List<Expectation> originIntentExpectationList = originIntent.getIntentExpectations();
176 LinkedHashMap<IntentGoalBean, IntentManagementFunction> intentMap = new LinkedHashMap<>();
177 List<Intent> subIntentList = intentContextService.getSubIntentInfoFromContext(intentGoalBean.getIntent());
178 for (Intent intent : subIntentList) {
179 IntentManagementFunction intentHandlerInfo = intentContextService.getHandlerInfo(intent);
180 boolean bFindIntent = false;
181 for (Expectation originExpectation : originIntentExpectationList) {
182 if (intent.getIntentName().replace("Intent", "")
183 .equals(originExpectation.getExpectationName().replace("Expectation", ""))) {
189 if (false == bFindIntent) {
190 intentContextService.deleteSubIntentContext(originIntent, intent.getIntentId());
191 IntentGoalBean subIntentGoalBean = new IntentGoalBean(intent, IntentGoalType.DELETE);
192 intentMap.put(subIntentGoalBean, intentHandlerInfo);
194 IntentGoalBean subIntentGoalBean = new IntentGoalBean(intent, IntentGoalType.UPDATE);
195 intentMap.put(subIntentGoalBean, intentHandlerInfo);
198 log.info("CLLBusinessIntentManagementFunction investigation update process finished");
199 log.debug("CLLBusinessIntentManagementFunction investigation update process intent list name "
200 + StringUtils.join(intentMap.keySet().stream().map(IntentGoalBean::getIntent)
201 .map(Intent::getIntentName).collect(Collectors.toList()), ","));
206 public LinkedHashMap<IntentGoalBean, IntentManagementFunction> investigationDeleteProcess(IntentGoalBean intentGoalBean) {
207 LinkedHashMap<IntentGoalBean, IntentManagementFunction> intentMap = new LinkedHashMap<>();
208 List<Intent> subIntentList = intentContextService.getSubIntentInfoFromContext(intentGoalBean.getIntent());
209 for (Intent intent : subIntentList) {
210 IntentManagementFunction intentHandlerInfo = intentContextService.getHandlerInfo(intent);
211 IntentGoalBean subIntentGoalBean = new IntentGoalBean(intent, IntentGoalType.DELETE);
212 intentMap.put(subIntentGoalBean, intentHandlerInfo);