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.formatintentinputMgt;
19 import lombok.extern.slf4j.Slf4j;
20 import org.onap.usecaseui.intentanalysis.bean.enums.IntentGenerateType;
21 import org.onap.usecaseui.intentanalysis.bean.enums.IntentGoalType;
22 import org.onap.usecaseui.intentanalysis.bean.models.Expectation;
23 import org.onap.usecaseui.intentanalysis.bean.models.Intent;
24 import org.onap.usecaseui.intentanalysis.bean.models.IntentGoalBean;
25 import org.onap.usecaseui.intentanalysis.intentBaseService.IntentManagementFunction;
26 import org.onap.usecaseui.intentanalysis.intentBaseService.contextService.IntentContextService;
27 import org.onap.usecaseui.intentanalysis.intentBaseService.intentModule.ActuationModule;
28 import org.onap.usecaseui.intentanalysis.intentBaseService.intentModule.DecisionModule;
29 import org.onap.usecaseui.intentanalysis.intentBaseService.intentModule.KnowledgeModule;
30 import org.onap.usecaseui.intentanalysis.intentBaseService.intentinterfaceservice.IntentInterfaceService;
31 import org.onap.usecaseui.intentanalysis.service.IntentService;
32 import org.springframework.beans.factory.annotation.Autowired;
33 import org.springframework.context.ApplicationContext;
34 import org.springframework.stereotype.Component;
35 import org.springframework.transaction.annotation.Transactional;
37 import javax.annotation.Resource;
42 @Component("formatIntentInputManagementFunction")
43 public class FormatIntentInputManagementFunction extends IntentManagementFunction {
45 public IntentContextService intentContextService;
47 @Resource(name = "formatIntentInputKnowledgeModule")
48 public void setKnowledgeModule(KnowledgeModule knowledgeModule) {
49 this.knowledgeModule = knowledgeModule;
52 @Resource(name = "formatIntentInputActuationModule")
53 public void setActuationModule(ActuationModule actuationModule) {
55 this.actuationModule = actuationModule;
58 @Resource(name = "formatIntentInputDecisionModule")
59 public void setDecisionModule(DecisionModule decisionModule) {
61 this.decisionModule = decisionModule;
65 IntentInterfaceService intentInterfaceService;
67 ApplicationContext applicationContext;
69 IntentService intentService;
71 @Transactional(rollbackFor = Exception.class)
73 public void receiveIntentAsOwner(IntentGoalBean intentGoalBean) {
75 IntentGoalBean originIntentGoalBean = detection(intentGoalBean);
76 LinkedHashMap<IntentGoalBean, IntentManagementFunction> linkedMap = investigation(originIntentGoalBean);
77 implementIntent(intentGoalBean.getIntent(), linkedMap);
81 public void receiveIntentAsHandler(Intent originalIntent, IntentGoalBean intentGoalBean, IntentManagementFunction handler) {
84 public IntentGoalBean detection(IntentGoalBean intentGoalBean) {
85 Intent originIntent = intentGoalBean.getIntent();
86 IntentGoalType intentGoalType = intentGoalBean.getIntentGoalType();
87 if (intentGoalType == IntentGoalType.CREATE) {
88 return knowledgeModule.intentCognition(originIntent);
89 } else if (intentGoalType == IntentGoalType.UPDATE) {
90 return new IntentGoalBean(intentGoalBean.getIntent(), IntentGoalType.UPDATE);
92 return new IntentGoalBean(intentGoalBean.getIntent(), IntentGoalType.DELETE);
96 public LinkedHashMap<IntentGoalBean, IntentManagementFunction> investigation(IntentGoalBean intentGoalBean) {
97 IntentGoalType intentGoalType = intentGoalBean.getIntentGoalType();
98 if (intentGoalType == IntentGoalType.CREATE) {
99 return decisionModule.investigationCreateProcess(intentGoalBean);
100 } else if (intentGoalType == IntentGoalType.UPDATE) {
101 return decisionModule.investigationUpdateProcess(intentGoalBean);
103 return decisionModule.investigationDeleteProcess(intentGoalBean);
107 public boolean implementIntent(Intent originIntent, LinkedHashMap<IntentGoalBean, IntentManagementFunction> linkedIntentMap) {
108 Iterator<Map.Entry<IntentGoalBean, IntentManagementFunction>> iterator = linkedIntentMap.entrySet().iterator();
109 while (iterator.hasNext()) {
110 Map.Entry<IntentGoalBean, IntentManagementFunction> next = iterator.next();
111 IntentGoalBean newIntentGoalBean = next.getKey();
112 IntentGoalType intentGoalType = newIntentGoalBean.getIntentGoalType();
113 if (intentGoalType == IntentGoalType.CREATE) {
114 Intent newIdIntent = decisionModule.intentObjectDefine(originIntent, next.getKey().getIntent());
115 intentContextService.updateIntentOwnerHandlerContext(newIdIntent, this, next.getValue());
116 intentContextService.updateParentIntentContext(originIntent, newIdIntent);
117 intentContextService.updateChindIntentContext(originIntent, newIdIntent);
118 //intent-Distribution-create
119 boolean isAcceptCreate = intentInterfaceService.createInterface(originIntent,
120 new IntentGoalBean(newIdIntent, IntentGoalType.CREATE), next.getValue());
121 originIntent.setIntentGenerateType(IntentGenerateType.USERINPUT);
122 //save user input intent
123 intentService.createIntent(originIntent);
124 return isAcceptCreate;
125 } else if (intentGoalType == IntentGoalType.UPDATE) {
126 log.info("formatIntentInputIMF UPDATE");
127 //update cllBusinessIntent's expectation
128 Intent subIntent = newIntentGoalBean.getIntent();
129 updateIntentInfo(originIntent, subIntent);
130 //update userInput intent
131 intentService.updateIntent(originIntent);
132 // intent-Distribution and operate |update cllBusiness intent
133 boolean isAcceptUpdate = intentInterfaceService.updateInterface(originIntent,
134 new IntentGoalBean(subIntent, IntentGoalType.UPDATE), next.getValue());
136 //deal with userInput intent
137 intentService.deleteIntent(originIntent.getIntentId());
138 // intent-Distribution-delete
139 boolean isAcceptDelete = intentInterfaceService.deleteInterface(originIntent, next.getKey(), next.getValue());
145 public void updateIntentInfo(Intent originIntent, Intent intent) {
147 List<Expectation> originIntentExpectationList = originIntent.getIntentExpectations();
148 List<Expectation> intentExpectationList = intent.getIntentExpectations();
149 int newIntentExpectationNum = originIntentExpectationList.size();
150 int oldIntentExpectationNum = intentExpectationList.size();
152 List<Expectation> changeList = new ArrayList<>();
153 if (newIntentExpectationNum != oldIntentExpectationNum) {
154 if (newIntentExpectationNum < oldIntentExpectationNum) {
156 for (Expectation oldExpectation : intentExpectationList) {//search
157 boolean bFindExpectation = false;
158 for (Expectation newExpectation : originIntentExpectationList) {//param
159 if (oldExpectation.getExpectationName().equals(newExpectation.getExpectationName())) {
160 bFindExpectation = true;
164 if (bFindExpectation) {
165 changeList.add(oldExpectation);
170 intent.setIntentExpectations(changeList);