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;
19 import lombok.extern.log4j.Log4j2;
20 import org.apache.commons.lang.StringUtils;
21 import org.onap.usecaseui.intentanalysis.bean.enums.ExpectationType;
22 import org.onap.usecaseui.intentanalysis.bean.enums.IntentGenerateType;
23 import org.onap.usecaseui.intentanalysis.bean.enums.IntentGoalType;
24 import org.onap.usecaseui.intentanalysis.bean.enums.ObjectType;
25 import org.onap.usecaseui.intentanalysis.bean.models.Expectation;
26 import org.onap.usecaseui.intentanalysis.bean.models.Intent;
27 import org.onap.usecaseui.intentanalysis.bean.models.IntentGoalBean;
28 import org.onap.usecaseui.intentanalysis.bean.models.IntentManagementFunctionRegInfo;
29 import org.onap.usecaseui.intentanalysis.intentBaseService.IntentManagementFunction;
30 import org.onap.usecaseui.intentanalysis.intentBaseService.contextService.IntentContextService;
31 import org.onap.usecaseui.intentanalysis.intentBaseService.intentModule.DecisionModule;
32 import org.onap.usecaseui.intentanalysis.service.ImfRegInfoService;
33 import org.onap.usecaseui.intentanalysis.service.IntentService;
34 import org.springframework.beans.factory.annotation.Autowired;
35 import org.springframework.context.ApplicationContext;
36 import org.springframework.stereotype.Component;
38 import java.util.ArrayList;
39 import java.util.LinkedHashMap;
40 import java.util.List;
42 import java.util.stream.Collectors;
46 public class CLLBusinessDecisionModule extends DecisionModule {
48 private ImfRegInfoService imfRegInfoService;
50 private ApplicationContext applicationContext;
53 IntentService intentService;
56 IntentContextService intentContextService;
59 public void determineUltimateGoal() {
63 public IntentManagementFunction exploreIntentHandlers(IntentGoalBean intentGoalBean) {
64 // db filter imf supportArea;
65 //SupportInterface> supportInterfaces;
66 IntentManagementFunctionRegInfo imfRegInfo = imfRegInfoService.getImfRegInfo(intentGoalBean);
67 return (IntentManagementFunction) applicationContext.getBean(imfRegInfo.getHandleName());
72 public void decideSuitableAction() {
76 public boolean needDecompostion(IntentGoalBean intentGoalBean) {
77 //different expectationType need decompostion ExpectationType>1 or objtype>1
78 if (intentGoalBean.getIntentGoalType().equals(IntentGoalType.CREATE)) {
79 List<Expectation> intentExpectations = intentGoalBean.getIntent().getIntentExpectations();
80 List<ExpectationType> expectationTypeList = intentExpectations.stream()
81 .map(Expectation::getExpectationType).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 if (objectTypeList.size() > 1) {
95 public List<IntentGoalBean> intentDecomposition(IntentGoalBean intentGoalBean) {
96 //ExpectationType expectation.ExpectationObject.objtype
97 Map<ExpectationType, List<Expectation>> expectationTypeListMap = intentGoalBean.getIntent().getIntentExpectations()
98 .stream().collect(Collectors.groupingBy(x -> x.getExpectationType()));
99 List<IntentGoalBean> subIntentGoalList = new ArrayList<>();
100 IntentGoalType intentGoalType = intentGoalBean.getIntentGoalType();
101 for (Map.Entry<ExpectationType, List<Expectation>> entry : expectationTypeListMap.entrySet()) {
103 Map<ObjectType, List<Expectation>> objTypeMap = entry.getValue().stream()
104 .collect(Collectors.groupingBy(x -> x.getExpectationObject().getObjectType()));
105 for (Map.Entry<ObjectType, List<Expectation>> objEntry : objTypeMap.entrySet()) {
106 IntentGoalBean subIntentGoalBean = new IntentGoalBean();
107 Intent subIntent = new Intent();
108 subIntent.setIntentName(objEntry.getValue().get(0).getExpectationName().replace("Expectation", "Intent"));
109 subIntent.setIntentExpectations(objEntry.getValue());
110 subIntent.setIntentGenerateType(IntentGenerateType.SYSTEMGENARATE);
111 //TODO intentFulfilmentInfo intentContexts
112 subIntentGoalBean.setIntentGoalType(intentGoalType);
113 subIntentGoalBean.setIntent(subIntent);
114 subIntentGoalList.add(subIntentGoalBean);
117 return subIntentGoalList;
120 public List<IntentGoalBean> intentOrchestration(List<IntentGoalBean> subIntentGoalList) {
121 List<IntentGoalBean> sortList = new ArrayList<>();
122 List<IntentGoalBean> deliveryGoalList = subIntentGoalList.stream().filter(x ->
123 StringUtils.containsIgnoreCase(x.getIntent().getIntentName(), "delivery")).collect(Collectors.toList());
124 List<IntentGoalBean> assuranceGoalList = subIntentGoalList.stream().filter(x ->
125 StringUtils.containsIgnoreCase(x.getIntent().getIntentName(), "assurance")).collect(Collectors.toList());
126 List<IntentGoalBean> otherGoalList = subIntentGoalList.stream().filter(x ->
127 !StringUtils.containsIgnoreCase(x.getIntent().getIntentName(), "delivery")
128 && !StringUtils.containsIgnoreCase(x.getIntent().getIntentName(), "assurance")).collect(Collectors.toList());
129 sortList.addAll(deliveryGoalList);
130 sortList.addAll(assuranceGoalList);
131 sortList.addAll(otherGoalList);
136 public void interactWithTemplateDb() {
140 public LinkedHashMap<IntentGoalBean, IntentManagementFunction> investigationCreateProcess(IntentGoalBean intentGoalBean) {
141 log.info("CLLBusinessIntentManagementFunction investigation create process start");
142 boolean needDecompostion = needDecompostion(intentGoalBean);
143 log.debug("CLLBusinessIntentManagementFunction need decompose :" + needDecompostion);
144 LinkedHashMap<IntentGoalBean, IntentManagementFunction> intentMap = new LinkedHashMap<>();
145 if (needDecompostion) {
146 List<IntentGoalBean> subIntentGoalList = intentDecomposition(intentGoalBean);
147 List<IntentGoalBean> sortList = intentOrchestration(subIntentGoalList);
148 for (IntentGoalBean subIntentGoal : sortList) {
149 IntentManagementFunction imf = exploreIntentHandlers(subIntentGoal);
150 intentMap.put(subIntentGoal, imf);
153 intentMap.put(intentGoalBean, exploreIntentHandlers(intentGoalBean));
155 log.info("CLLBusinessIntentManagementFunction investigation create process finished");
156 log.debug("CLLBusinessIntentManagementFunction decomposed subIntent list name :"
157 + StringUtils.join(intentMap.keySet().stream().map(IntentGoalBean::getIntent)
158 .map(Intent::getIntentName).collect(Collectors.toList()), ","));
165 public LinkedHashMap<IntentGoalBean, IntentManagementFunction> investigationUpdateProcess(IntentGoalBean intentGoalBean) {
166 log.info("CLLBusinessIntentManagementFunction investigation update process start");
167 //get cll-delivery cll-assurance intent
168 Intent originIntent = intentGoalBean.getIntent();
169 List<Expectation> originIntentExpectationList = originIntent.getIntentExpectations();
171 LinkedHashMap<IntentGoalBean, IntentManagementFunction> intentMap = new LinkedHashMap<>();
172 List<Intent> subIntentList = intentContextService.getSubIntentInfoFromContext(intentGoalBean.getIntent());
173 for (Intent intent : subIntentList) {
174 IntentManagementFunction intentHandlerInfo = intentContextService.getHandlerInfo(intent);
175 boolean bFindIntent = false;
176 for (Expectation originExpectation : originIntentExpectationList) {
177 if (intent.getIntentName().replace("Intent", "")
178 .equals(originExpectation.getExpectationName().replace("Expectation", ""))) {
184 if (false == bFindIntent) {
185 intentContextService.deleteSubIntentContext(originIntent, intent.getIntentId());
186 IntentGoalBean subIntentGoalBean = new IntentGoalBean(intent, IntentGoalType.DELETE);
187 intentMap.put(subIntentGoalBean, intentHandlerInfo);
189 IntentGoalBean subIntentGoalBean = new IntentGoalBean(intent, IntentGoalType.UPDATE);
190 intentMap.put(subIntentGoalBean, intentHandlerInfo);
193 log.info("CLLBusinessIntentManagementFunction investigation update process finished");
194 log.debug("CLLBusinessIntentManagementFunction investigation update process intent list name "
195 + StringUtils.join(intentMap.keySet().stream().map(IntentGoalBean::getIntent)
196 .map(Intent::getIntentName).collect(Collectors.toList()), ","));
201 public LinkedHashMap<IntentGoalBean, IntentManagementFunction> investigationDeleteProcess(IntentGoalBean intentGoalBean) {
202 LinkedHashMap<IntentGoalBean, IntentManagementFunction> intentMap = new LinkedHashMap<>();
203 List<Intent> subIntentList = intentContextService.getSubIntentInfoFromContext(intentGoalBean.getIntent());
204 for (Intent intent : subIntentList) {
205 IntentManagementFunction intentHandlerInfo = intentContextService.getHandlerInfo(intent);
206 IntentGoalBean subIntentGoalBean = new IntentGoalBean(intent, IntentGoalType.DELETE);
207 intentMap.put(subIntentGoalBean, intentHandlerInfo);