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.Component;
35 import java.util.ArrayList;
36 import java.util.HashMap;
37 import java.util.List;
39 import java.util.stream.Collectors;
43 public class CLLBusinessDecisionModule extends DecisionModule {
45 private ImfRegInfoService imfRegInfoService;
47 private ApplicationContext applicationContext;
50 public void determineUltimateGoal() {
54 public IntentManagementFunction exploreIntentHandlers(IntentGoalBean intentGoalBean) {
55 // db filter imf supportArea;
56 //SupportInterface> supportInterfaces;
57 IntentManagementFunctionRegInfo imfRegInfo = imfRegInfoService.getImfRegInfoList(intentGoalBean);
58 return (IntentManagementFunction) applicationContext.getBean(imfRegInfo.getHandleName());
62 public void intentDefinition() {
66 public void decideSuitableAction() {
70 public boolean needDecompostion(IntentGoalBean intentGoalBean) {
71 //different expectationType need decompostion ExpectationType>1 or objtype>1
72 if (intentGoalBean.getIntentGoalType().equals(IntentGoalType.CREATE)) {
73 List<Expectation> intentExpectations = intentGoalBean.getIntent().getIntentExpectations();
74 List<ExpectationType> expectationTypeList = intentExpectations.stream()
75 .map(Expectation::getExpectationType).distinct().collect(Collectors.toList());
76 if (expectationTypeList.size() > 1) {
79 List<ObjectType> objectTypeList = intentExpectations.stream().map(x ->
80 x.getExpectationObject().getObjectType()).collect(Collectors.toList());
81 if (objectTypeList.size() > 1) {
89 public List<IntentGoalBean> intentDecomposition(IntentGoalBean intentGoalBean) {
90 //ExpectationType expectation.ExpectationObject.objtype
91 Map<ExpectationType, List<Expectation>> expectationTypeListMap = intentGoalBean.getIntent().getIntentExpectations()
92 .stream().collect(Collectors.groupingBy(x -> x.getExpectationType()));
93 List<IntentGoalBean> subIntentGoalList = new ArrayList<>();
94 IntentGoalType intentGoalType = intentGoalBean.getIntentGoalType();
95 for (Map.Entry<ExpectationType, List<Expectation>> entry : expectationTypeListMap.entrySet()) {
97 Map<ObjectType, List<Expectation>> objTypeMap = entry.getValue().stream()
98 .collect(Collectors.groupingBy(x -> x.getExpectationObject().getObjectType()));
99 for (Map.Entry<ObjectType, List<Expectation>> objEntry : objTypeMap.entrySet()) {
100 IntentGoalBean subIntentGoalBean = new IntentGoalBean();
101 Intent subIntent = new Intent();
102 subIntent.setIntentId(CommonUtil.getUUid());
103 subIntent.setIntentName(objEntry.getValue().get(0).getExpectationName().replace("Expectation", "Intent"));
104 subIntent.setIntentExpectations(objEntry.getValue());
105 //TODO intentFulfilmentInfo intentContexts
106 subIntentGoalBean.setIntentGoalType(intentGoalType);
107 subIntentGoalBean.setIntent(subIntent);
108 subIntentGoalList.add(subIntentGoalBean);
111 return subIntentGoalList;
114 public List<IntentGoalBean> intentOrchestration(List<IntentGoalBean> subIntentGoalList) {
115 List<IntentGoalBean> sortList = new ArrayList<>();
116 List<IntentGoalBean> deliveryGoalList = subIntentGoalList.stream().filter(x -> x.getIntent().getIntentName()
117 .equalsIgnoreCase("delivery")).collect(Collectors.toList());
118 List<IntentGoalBean> assuranceGoalList = subIntentGoalList.stream().filter(x -> x.getIntent().getIntentName()
119 .equalsIgnoreCase("assurance")).collect(Collectors.toList());
120 List<IntentGoalBean> otherGoalList = subIntentGoalList.stream().filter(x -> !x.getIntent().getIntentName()
121 .equalsIgnoreCase("assurance") && !x.getIntent().getIntentName()
122 .equalsIgnoreCase("delivery")).collect(Collectors.toList());
123 sortList.addAll(deliveryGoalList);
124 sortList.addAll(assuranceGoalList);
125 sortList.addAll(otherGoalList);
130 public void interactWithTemplateDb() {
134 public List<Map<IntentGoalBean, IntentManagementFunction>> findHandler(IntentGoalBean intentGoalBean) {
135 boolean needDecompostion = needDecompostion(intentGoalBean);
136 List<Map<IntentGoalBean, IntentManagementFunction>> intentMapList = new ArrayList<>();
137 if (needDecompostion) {
138 List<IntentGoalBean> subIntentGoalList = intentDecomposition(intentGoalBean);
139 List<IntentGoalBean> sortList = intentOrchestration(subIntentGoalList);
140 for (IntentGoalBean subIntentGoal : sortList) {
141 Map<IntentGoalBean, IntentManagementFunction> map = new HashMap<>();
142 IntentManagementFunction imf = exploreIntentHandlers(subIntentGoal);
143 map.put(subIntentGoal, imf);
144 intentMapList.add(map);
147 Map<IntentGoalBean, IntentManagementFunction> map = new HashMap<>();
148 map.put(intentGoalBean, exploreIntentHandlers(intentGoalBean));
149 intentMapList.add(map);
151 return intentMapList;