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.FulfillmentInfo;
24 import org.onap.usecaseui.intentanalysis.bean.models.Intent;
25 import org.onap.usecaseui.intentanalysis.bean.models.IntentGoalBean;
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.ActuationModule;
29 import org.onap.usecaseui.intentanalysis.intentBaseService.intentModule.DecisionModule;
30 import org.onap.usecaseui.intentanalysis.intentBaseService.intentModule.KnowledgeModule;
31 import org.onap.usecaseui.intentanalysis.intentBaseService.intentinterfaceservice.IntentInterfaceService;
32 import org.onap.usecaseui.intentanalysis.service.IntentService;
33 import org.springframework.beans.factory.annotation.Autowired;
34 import org.springframework.context.ApplicationContext;
35 import org.springframework.stereotype.Component;
36 import org.springframework.transaction.annotation.Transactional;
38 import javax.annotation.Resource;
43 @Component("formatIntentInputManagementFunction")
44 public class FormatIntentInputManagementFunction extends IntentManagementFunction {
46 public IntentContextService intentContextService;
48 @Resource(name = "formatIntentInputKnowledgeModule")
49 public void setKnowledgeModule(KnowledgeModule knowledgeModule) {
50 this.knowledgeModule = knowledgeModule;
53 @Resource(name = "formatIntentInputActuationModule")
54 public void setActuationModule(ActuationModule actuationModule) {
56 this.actuationModule = actuationModule;
59 @Resource(name = "formatIntentInputDecisionModule")
60 public void setDecisionModule(DecisionModule decisionModule) {
62 this.decisionModule = decisionModule;
66 IntentInterfaceService intentInterfaceService;
68 ApplicationContext applicationContext;
70 IntentService intentService;
72 @Transactional(rollbackFor = Exception.class)
74 public void receiveIntentAsOwner(IntentGoalBean intentGoalBean) {
76 IntentGoalBean originIntentGoalBean = detection(intentGoalBean);
77 LinkedHashMap<IntentGoalBean, IntentManagementFunction> linkedMap = investigation(originIntentGoalBean);
78 implementIntent(intentGoalBean.getIntent(), linkedMap);
82 public void receiveIntentAsHandler(Intent originalIntent, IntentGoalBean intentGoalBean, IntentManagementFunction handler) {
86 public void createReport(String intentId, FulfillmentInfo fulfillmentInfo) {
87 saveFulfillmentAndObjectInstance(intentId, fulfillmentInfo);
90 public IntentGoalBean detection(IntentGoalBean intentGoalBean) {
91 Intent originIntent = intentGoalBean.getIntent();
92 IntentGoalType intentGoalType = intentGoalBean.getIntentGoalType();
93 if (intentGoalType == IntentGoalType.CREATE) {
94 return knowledgeModule.intentCognition(originIntent);
95 } else if (intentGoalType == IntentGoalType.UPDATE) {
96 return new IntentGoalBean(intentGoalBean.getIntent(), IntentGoalType.UPDATE);
98 return new IntentGoalBean(intentGoalBean.getIntent(), IntentGoalType.DELETE);
102 public LinkedHashMap<IntentGoalBean, IntentManagementFunction> investigation(IntentGoalBean intentGoalBean) {
103 IntentGoalType intentGoalType = intentGoalBean.getIntentGoalType();
104 if (intentGoalType == IntentGoalType.CREATE) {
105 return decisionModule.investigationCreateProcess(intentGoalBean);
106 } else if (intentGoalType == IntentGoalType.UPDATE) {
107 return decisionModule.investigationUpdateProcess(intentGoalBean);
109 return decisionModule.investigationDeleteProcess(intentGoalBean);
113 public boolean implementIntent(Intent originIntent, LinkedHashMap<IntentGoalBean, IntentManagementFunction> linkedIntentMap) {
114 Iterator<Map.Entry<IntentGoalBean, IntentManagementFunction>> iterator = linkedIntentMap.entrySet().iterator();
115 while (iterator.hasNext()) {
116 Map.Entry<IntentGoalBean, IntentManagementFunction> next = iterator.next();
117 IntentGoalBean newIntentGoalBean = next.getKey();
118 IntentGoalType intentGoalType = newIntentGoalBean.getIntentGoalType();
119 if (intentGoalType == IntentGoalType.CREATE) {
120 Intent newIdIntent = decisionModule.intentObjectDefine(originIntent, next.getKey().getIntent());
121 intentContextService.updateIntentOwnerHandlerContext(newIdIntent, this, next.getValue());
122 intentContextService.updateParentIntentContext(originIntent, newIdIntent);
123 intentContextService.updateChindIntentContext(originIntent, newIdIntent);
124 //intent-Distribution-create
125 boolean isAcceptCreate = intentInterfaceService.createInterface(originIntent,
126 new IntentGoalBean(newIdIntent, IntentGoalType.CREATE), next.getValue());
127 originIntent.setIntentGenerateType(IntentGenerateType.USERINPUT);
128 //save user input intent
129 intentService.createIntent(originIntent);
130 return isAcceptCreate;
131 } else if (intentGoalType == IntentGoalType.UPDATE) {
132 log.info("formatIntentInputIMF UPDATE");
133 //update cllBusinessIntent's expectation
134 Intent subIntent = newIntentGoalBean.getIntent();
135 updateIntentInfo(originIntent, subIntent);
136 //update userInput intent
137 intentService.updateIntent(originIntent);
138 // intent-Distribution and operate |update cllBusiness intent
139 boolean isAcceptUpdate = intentInterfaceService.updateInterface(originIntent,
140 new IntentGoalBean(subIntent, IntentGoalType.UPDATE), next.getValue());
142 //deal with userInput intent
143 intentService.deleteIntent(originIntent.getIntentId());
144 // intent-Distribution-delete
145 boolean isAcceptDelete = intentInterfaceService.deleteInterface(originIntent, next.getKey(), next.getValue());
151 public void updateIntentInfo(Intent originIntent, Intent intent) {
153 List<Expectation> originIntentExpectationList = originIntent.getIntentExpectations();
154 List<Expectation> intentExpectationList = intent.getIntentExpectations();
155 int newIntentExpectationNum = originIntentExpectationList.size();
156 int oldIntentExpectationNum = intentExpectationList.size();
158 List<Expectation> changeList = new ArrayList<>();
159 if (newIntentExpectationNum != oldIntentExpectationNum) {
160 if (newIntentExpectationNum < oldIntentExpectationNum) {
162 for (Expectation oldExpectation : intentExpectationList) {//search
163 boolean bFindExpectation = false;
164 for (Expectation newExpectation : originIntentExpectationList) {//param
165 if (oldExpectation.getExpectationName().equals(newExpectation.getExpectationName())) {
166 bFindExpectation = true;
170 if (bFindExpectation) {
171 changeList.add(oldExpectation);
176 intent.setIntentExpectations(changeList);