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.collections.CollectionUtils;
21 import org.apache.commons.lang.StringUtils;
22 import org.onap.usecaseui.intentanalysis.bean.enums.ExpectationType;
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.*;
26 import org.onap.usecaseui.intentanalysis.intentBaseService.IntentManagementFunction;
27 import org.onap.usecaseui.intentanalysis.intentBaseService.contextService.IntentContextService;
28 import org.onap.usecaseui.intentanalysis.intentBaseService.intentModule.DecisionModule;
29 import org.onap.usecaseui.intentanalysis.service.ImfRegInfoService;
30 import org.onap.usecaseui.intentanalysis.service.IntentService;
31 import org.onap.usecaseui.intentanalysis.util.CommonUtil;
32 import org.springframework.beans.factory.annotation.Autowired;
33 import org.springframework.context.ApplicationContext;
34 import org.springframework.stereotype.Component;
37 import java.util.stream.Collectors;
41 public class CLLBusinessDecisionModule extends DecisionModule {
43 private ImfRegInfoService imfRegInfoService;
45 private ApplicationContext applicationContext;
48 IntentService intentService;
51 IntentContextService intentContextService;
54 public void determineUltimateGoal() {
58 public IntentManagementFunction exploreIntentHandlers(IntentGoalBean intentGoalBean) {
59 // db filter imf supportArea;
60 //SupportInterface> supportInterfaces;
61 IntentManagementFunctionRegInfo imfRegInfo = imfRegInfoService.getImfRegInfo(intentGoalBean);
62 return (IntentManagementFunction) applicationContext.getBean(imfRegInfo.getHandleName());
67 public void decideSuitableAction() {
71 public boolean needDecompostion(IntentGoalBean intentGoalBean) {
72 //different expectationType need decompostion ExpectationType>1 or objtype>1
73 if (intentGoalBean.getIntentGoalType().equals(IntentGoalType.CREATE)) {
74 List<Expectation> intentExpectations = intentGoalBean.getIntent().getIntentExpectations();
75 List<ExpectationType> expectationTypeList = intentExpectations.stream()
76 .map(Expectation::getExpectationType).distinct().collect(Collectors.toList());
77 if (expectationTypeList.size() > 1) {
80 List<ObjectType> objectTypeList = intentExpectations.stream().map(x ->
81 x.getExpectationObject().getObjectType()).distinct().collect(Collectors.toList());
82 if (objectTypeList.size() > 1) {
90 public List<IntentGoalBean> intentDecomposition(IntentGoalBean intentGoalBean) {
91 //ExpectationType expectation.ExpectationObject.objtype
92 Map<ExpectationType, List<Expectation>> expectationTypeListMap = intentGoalBean.getIntent().getIntentExpectations()
93 .stream().collect(Collectors.groupingBy(x -> x.getExpectationType()));
94 List<IntentGoalBean> subIntentGoalList = new ArrayList<>();
95 IntentGoalType intentGoalType = intentGoalBean.getIntentGoalType();
96 for (Map.Entry<ExpectationType, List<Expectation>> entry : expectationTypeListMap.entrySet()) {
98 Map<ObjectType, List<Expectation>> objTypeMap = entry.getValue().stream()
99 .collect(Collectors.groupingBy(x -> x.getExpectationObject().getObjectType()));
100 for (Map.Entry<ObjectType, List<Expectation>> objEntry : objTypeMap.entrySet()) {
101 IntentGoalBean subIntentGoalBean = new IntentGoalBean();
102 Intent subIntent = new Intent();
103 subIntent.setIntentName(objEntry.getValue().get(0).getExpectationName().replace("Expectation", "Intent"));
104 subIntent.setIntentExpectations(objEntry.getValue());
105 //List<Expectation> newExpectationList = getNewExpectationList(objEntry.getValue());
106 //subIntent.setIntentExpectations(newExpectationList);
107 //TODO intentFulfilmentInfo intentContexts
108 subIntentGoalBean.setIntentGoalType(intentGoalType);
109 subIntentGoalBean.setIntent(subIntent);
110 subIntentGoalList.add(subIntentGoalBean);
113 return subIntentGoalList;
116 public List<IntentGoalBean> intentOrchestration(List<IntentGoalBean> subIntentGoalList) {
117 List<IntentGoalBean> sortList = new ArrayList<>();
118 List<IntentGoalBean> deliveryGoalList = subIntentGoalList.stream().filter(x ->
119 StringUtils.containsIgnoreCase(x.getIntent().getIntentName(), "delivery")).collect(Collectors.toList());
120 List<IntentGoalBean> assuranceGoalList = subIntentGoalList.stream().filter(x ->
121 StringUtils.containsIgnoreCase(x.getIntent().getIntentName(), "assurance")).collect(Collectors.toList());
122 List<IntentGoalBean> otherGoalList = subIntentGoalList.stream().filter(x ->
123 !StringUtils.containsIgnoreCase(x.getIntent().getIntentName(), "delivery")
124 && !StringUtils.containsIgnoreCase(x.getIntent().getIntentName(), "assurance")).collect(Collectors.toList());
125 sortList.addAll(deliveryGoalList);
126 sortList.addAll(assuranceGoalList);
127 sortList.addAll(otherGoalList);
132 public void interactWithTemplateDb() {
136 public LinkedHashMap<IntentGoalBean, IntentManagementFunction> investigationCreateProcess(IntentGoalBean intentGoalBean) {
137 boolean needDecompostion = needDecompostion(intentGoalBean);
138 LinkedHashMap<IntentGoalBean, IntentManagementFunction> intentMap = new LinkedHashMap<>();
139 if (needDecompostion) {
140 List<IntentGoalBean> subIntentGoalList = intentDecomposition(intentGoalBean);
141 List<IntentGoalBean> sortList = intentOrchestration(subIntentGoalList);
142 for (IntentGoalBean subIntentGoal : sortList) {
143 IntentManagementFunction imf = exploreIntentHandlers(subIntentGoal);
144 intentMap.put(subIntentGoal, imf);
147 intentMap.put(intentGoalBean, exploreIntentHandlers(intentGoalBean));
155 public LinkedHashMap<IntentGoalBean, IntentManagementFunction> investigationUpdateProcess(IntentGoalBean intentGoalBean) {
156 //get cll-delivery cll-assurance intent
157 Intent originIntent = intentGoalBean.getIntent();
158 List<Expectation> originIntentExpectationList = originIntent.getIntentExpectations();
160 LinkedHashMap<IntentGoalBean, IntentManagementFunction> intentMap = new LinkedHashMap<>();
161 List<Intent> subIntentList = intentContextService.getSubIntentInfoFromContext(intentGoalBean.getIntent());
162 for (Intent intent : subIntentList) {
163 IntentManagementFunction intentHandlerInfo = intentContextService.getHandlerInfo(intent);
164 boolean bFindIntent = false;
165 for (Expectation originExpectation : originIntentExpectationList) {
166 if (intent.getIntentName().replace("Intent","")
167 .equals(originExpectation.getExpectationName().replace("Expectation",""))){
173 if (false == bFindIntent){
174 intentContextService.deleteSubIntentContext(originIntent, intent.getIntentId());
175 IntentGoalBean subIntentGoalBean = new IntentGoalBean(intent, IntentGoalType.DELETE);
176 intentMap.put(subIntentGoalBean, intentHandlerInfo);
178 IntentGoalBean subIntentGoalBean = new IntentGoalBean(intent, IntentGoalType.UPDATE);
179 intentMap.put(subIntentGoalBean, intentHandlerInfo);
186 public LinkedHashMap<IntentGoalBean, IntentManagementFunction> investigationDeleteProcess(IntentGoalBean intentGoalBean) {
187 LinkedHashMap<IntentGoalBean, IntentManagementFunction> intentMap = new LinkedHashMap<>();
188 List<Intent> subIntentList = intentContextService.getSubIntentInfoFromContext(intentGoalBean.getIntent());
189 for (Intent intent : subIntentList) {
190 IntentManagementFunction intentHandlerInfo = intentContextService.getHandlerInfo(intent);
191 IntentGoalBean subIntentGoalBean = new IntentGoalBean(intent, IntentGoalType.DELETE);
192 intentMap.put(subIntentGoalBean, intentHandlerInfo);