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.onap.usecaseui.intentanalysis.bean.enums.ExpectationType;
21 import org.onap.usecaseui.intentanalysis.bean.enums.IntentGoalType;
22 import org.onap.usecaseui.intentanalysis.bean.enums.ObjectType;
23 import org.onap.usecaseui.intentanalysis.bean.models.Expectation;
24 import org.onap.usecaseui.intentanalysis.bean.models.Intent;
25 import org.onap.usecaseui.intentanalysis.bean.models.IntentGoalBean;
26 import org.onap.usecaseui.intentanalysis.bean.models.IntentManagementFunctionRegInfo;
27 import org.onap.usecaseui.intentanalysis.intentBaseService.IntentManagementFunction;
28 import org.onap.usecaseui.intentanalysis.intentBaseService.intentModule.DecisionModule;
29 import org.onap.usecaseui.intentanalysis.service.ImfRegInfoService;
30 import org.onap.usecaseui.intentanalysis.util.CommonUtil;
31 import org.springframework.beans.factory.annotation.Autowired;
32 import org.springframework.context.ApplicationContext;
33 import org.springframework.stereotype.Service;
36 import java.util.stream.Collectors;
40 public class CLLBusinessDecisionModule extends DecisionModule {
42 private ImfRegInfoService imfRegInfoService;
44 private ApplicationContext applicationContext;
47 public void determineUltimateGoal() {
51 public IntentManagementFunction exploreIntentHandlers(IntentGoalBean intentGoalBean) {
52 // db filter imf supportArea;
53 //SupportInterface> supportInterfaces;
54 IntentManagementFunctionRegInfo imfRegInfo = imfRegInfoService.getImfRegInfoList(intentGoalBean);
55 return (IntentManagementFunction) applicationContext.getBean(imfRegInfo.getHandleName());
59 public void intentDefinition() {
63 public void decideSuitableAction() {
67 public boolean needDecompostion(IntentGoalBean intentGoalBean) {
68 //different expectationType need decompostion ExpectationType>1 or objtype>1
69 if (intentGoalBean.getIntentGoalType().equals(IntentGoalType.CREATE)) {
70 List<Expectation> intentExpectations = intentGoalBean.getIntent().getIntentExpectations();
71 List<ExpectationType> expectationTypeList = intentExpectations.stream()
72 .map(Expectation::getExpectationType).distinct().collect(Collectors.toList());
73 if (expectationTypeList.size() > 1) {
76 List<ObjectType> objectTypeList = intentExpectations.stream().map(x ->
77 x.getExpectationObject().getObjectType()).collect(Collectors.toList());
78 if (objectTypeList.size() > 1) {
86 public List<IntentGoalBean> intentDecomposition(IntentGoalBean intentGoalBean) {
87 //ExpectationType expectation.ExpectationObject.objtype
88 Map<ExpectationType, List<Expectation>> expectationTypeListMap = intentGoalBean.getIntent().getIntentExpectations()
89 .stream().collect(Collectors.groupingBy(x -> x.getExpectationType()));
90 List<IntentGoalBean> subIntentGoalList = new ArrayList<>();
91 IntentGoalType intentGoalType = intentGoalBean.getIntentGoalType();
92 for (Map.Entry<ExpectationType, List<Expectation>> entry : expectationTypeListMap.entrySet()) {
94 Map<ObjectType, List<Expectation>> objTypeMap = entry.getValue().stream()
95 .collect(Collectors.groupingBy(x -> x.getExpectationObject().getObjectType()));
96 for (Map.Entry<ObjectType, List<Expectation>> objEntry : objTypeMap.entrySet()) {
97 IntentGoalBean subIntentGoalBean = new IntentGoalBean();
98 Intent subIntent = new Intent();
99 subIntent.setIntentId(CommonUtil.getUUid());
100 subIntent.setIntentName(objEntry.getValue().get(0).getExpectationName().replace("Expectation", "Intent"));
101 subIntent.setIntentExpectations(objEntry.getValue());
102 //TODO intentFulfilmentInfo intentContexts
103 subIntentGoalBean.setIntentGoalType(intentGoalType);
104 subIntentGoalBean.setIntent(subIntent);
105 subIntentGoalList.add(subIntentGoalBean);
108 return subIntentGoalList;
111 public List<IntentGoalBean> intentOrchestration(List<IntentGoalBean> subIntentGoalList) {
112 List<IntentGoalBean> sortList = new ArrayList<>();
113 List<IntentGoalBean> deliveryGoalList = subIntentGoalList.stream().filter(x -> x.getIntent().getIntentName()
114 .equalsIgnoreCase("delivery")).collect(Collectors.toList());
115 List<IntentGoalBean> assuranceGoalList = subIntentGoalList.stream().filter(x -> x.getIntent().getIntentName()
116 .equalsIgnoreCase("assurance")).collect(Collectors.toList());
117 List<IntentGoalBean> otherGoalList = subIntentGoalList.stream().filter(x -> !x.getIntent().getIntentName()
118 .equalsIgnoreCase("assurance") && !x.getIntent().getIntentName()
119 .equalsIgnoreCase("delivery")).collect(Collectors.toList());
120 sortList.addAll(deliveryGoalList);
121 sortList.addAll(assuranceGoalList);
122 sortList.addAll(otherGoalList);
127 public void interactWithTemplateDb() {
131 public List<Map<IntentGoalBean, IntentManagementFunction>> findHandler(IntentGoalBean intentGoalBean) {
132 boolean needDecompostion = needDecompostion(intentGoalBean);
133 List<Map<IntentGoalBean, IntentManagementFunction>> intentMapList = new ArrayList<>();
134 if (needDecompostion) {
135 List<IntentGoalBean> subIntentGoalList = intentDecomposition(intentGoalBean);
136 List<IntentGoalBean> sortList = intentOrchestration(subIntentGoalList);
137 for (IntentGoalBean subIntentGoal : sortList) {
138 Map<IntentGoalBean, IntentManagementFunction> map = new HashMap<>();
139 IntentManagementFunction imf = exploreIntentHandlers(subIntentGoal);
140 map.put(subIntentGoal, imf);
141 intentMapList.add(map);
144 Map<IntentGoalBean, IntentManagementFunction> map = new HashMap<>();
145 map.put(intentGoalBean, exploreIntentHandlers(intentGoalBean));
146 intentMapList.add(map);
148 return intentMapList;