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;
36 import javax.annotation.Resource;
41 @Component("formatIntentInputManagementFunction")
42 public class FormatIntentInputManagementFunction extends IntentManagementFunction {
44 public IntentContextService intentContextService;
46 @Resource(name = "formatIntentInputKnowledgeModule")
47 public void setKnowledgeModule(KnowledgeModule knowledgeModule) {
48 this.knowledgeModule = knowledgeModule;
51 @Resource(name = "formatIntentInputActuationModule")
52 public void setActuationModule(ActuationModule actuationModule) {
54 this.actuationModule = actuationModule;
57 @Resource(name = "formatIntentInputDecisionModule")
58 public void setDecisionModule(DecisionModule decisionModule) {
60 this.decisionModule = decisionModule;
64 IntentInterfaceService intentInterfaceService;
66 ApplicationContext applicationContext;
68 IntentService intentService;
71 public void receiveIntentAsOwner(IntentGoalBean intentGoalBean) {
73 IntentGoalBean originIntentGoalBean = detection(intentGoalBean);
74 LinkedHashMap<IntentGoalBean, IntentManagementFunction> linkedMap = investigation(originIntentGoalBean);
75 implementIntent(intentGoalBean.getIntent(), linkedMap);
79 public void receiveIntentAsHandler(Intent originalIntent, IntentGoalBean intentGoalBean, IntentManagementFunction handler) {
82 public IntentGoalBean detection(IntentGoalBean intentGoalBean) {
83 Intent originIntent = intentGoalBean.getIntent();
84 IntentGoalType intentGoalType = intentGoalBean.getIntentGoalType();
85 if (intentGoalType == IntentGoalType.CREATE) {
86 return knowledgeModule.intentCognition(originIntent);
87 } else if (intentGoalType == IntentGoalType.UPDATE) {
88 return new IntentGoalBean(intentGoalBean.getIntent(), IntentGoalType.UPDATE);
90 return new IntentGoalBean(intentGoalBean.getIntent(), IntentGoalType.DELETE);
94 public LinkedHashMap<IntentGoalBean, IntentManagementFunction> investigation(IntentGoalBean intentGoalBean) {
95 IntentGoalType intentGoalType = intentGoalBean.getIntentGoalType();
96 if (intentGoalType == IntentGoalType.CREATE) {
97 return decisionModule.investigationCreateProcess(intentGoalBean);
98 } else if (intentGoalType == IntentGoalType.UPDATE) {
99 return decisionModule.investigationUpdateProcess(intentGoalBean);
101 return decisionModule.investigationDeleteProcess(intentGoalBean);
105 public boolean implementIntent(Intent originIntent, LinkedHashMap<IntentGoalBean, IntentManagementFunction> linkedIntentMap) {
106 Iterator<Map.Entry<IntentGoalBean, IntentManagementFunction>> iterator = linkedIntentMap.entrySet().iterator();
107 while (iterator.hasNext()) {
108 Map.Entry<IntentGoalBean, IntentManagementFunction> next = iterator.next();
109 IntentGoalBean newIntentGoalBean = next.getKey();
110 IntentGoalType intentGoalType = newIntentGoalBean.getIntentGoalType();
111 if (intentGoalType == IntentGoalType.CREATE) {
112 Intent newIdIntent = decisionModule.intentObjectDefine(originIntent, next.getKey().getIntent());
113 intentContextService.updateIntentOwnerHandlerContext(newIdIntent, this, next.getValue());
114 intentContextService.updateParentIntentContext(originIntent, newIdIntent);
115 intentContextService.updateChindIntentContext(originIntent, newIdIntent);
116 //intent-Distribution-create
117 boolean isAcceptCreate = intentInterfaceService.createInterface(originIntent,
118 new IntentGoalBean(newIdIntent, IntentGoalType.CREATE), next.getValue());
119 originIntent.setIntentGenerateType(IntentGenerateType.USERINPUT);
120 //save user input intent
121 intentService.createIntent(originIntent);
122 return isAcceptCreate;
123 } else if (intentGoalType == IntentGoalType.UPDATE) {
124 log.info("formatIntentInputIMF UPDATE");
125 //update cllBusinessIntent's expectation
126 Intent subIntent = newIntentGoalBean.getIntent();
127 updateIntentInfo(originIntent, subIntent);
128 // intent-Distribution and operate |update cllBusiness intent
129 boolean isAcceptUpdate = intentInterfaceService.updateInterface(originIntent,
130 new IntentGoalBean(subIntent, IntentGoalType.UPDATE), next.getValue());
131 //update userInput intent
132 intentService.updateIntent(originIntent);
134 //deal with userInput intent
135 intentService.deleteIntent(originIntent.getIntentId());
136 // intent-Distribution-delete
137 boolean isAcceptDelete = intentInterfaceService.deleteInterface(originIntent, next.getKey(), next.getValue());
143 public void updateIntentInfo(Intent originIntent, Intent intent) {
145 List<Expectation> originIntentExpectationList = originIntent.getIntentExpectations();
146 List<Expectation> intentExpectationList = intent.getIntentExpectations();
147 int newIntentExpectationNum = originIntentExpectationList.size();
148 int oldIntentExpectationNum = intentExpectationList.size();
150 List<Expectation> changeList = new ArrayList<>();
151 if (newIntentExpectationNum != oldIntentExpectationNum) {
152 if (newIntentExpectationNum < oldIntentExpectationNum) {
154 for (Expectation oldExpectation : intentExpectationList) {//search
155 boolean bFindExpectation = false;
156 for (Expectation newExpectation : originIntentExpectationList) {//param
157 if (oldExpectation.getExpectationName().equals(newExpectation.getExpectationName())) {
158 bFindExpectation = true;
162 if (bFindExpectation) {
163 changeList.add(oldExpectation);
168 intent.setIntentExpectations(changeList);