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);
79 generationIntentReport(intentGoalBean);
83 public void receiveIntentAsHandler(Intent originalIntent, IntentGoalBean intentGoalBean, IntentManagementFunction handler) {
87 public void createReport(String intentId, FulfillmentInfo fulfillmentInfo) {
88 saveFulfillmentAndObjectInstance(intentId, fulfillmentInfo);
91 public IntentGoalBean detection(IntentGoalBean intentGoalBean) {
92 Intent originIntent = intentGoalBean.getIntent();
93 IntentGoalType intentGoalType = intentGoalBean.getIntentGoalType();
94 if (intentGoalType == IntentGoalType.CREATE) {
95 return knowledgeModule.intentCognition(originIntent);
96 } else if (intentGoalType == IntentGoalType.UPDATE) {
97 return new IntentGoalBean(intentGoalBean.getIntent(), IntentGoalType.UPDATE);
99 return new IntentGoalBean(intentGoalBean.getIntent(), IntentGoalType.DELETE);
103 public LinkedHashMap<IntentGoalBean, IntentManagementFunction> investigation(IntentGoalBean intentGoalBean) {
104 IntentGoalType intentGoalType = intentGoalBean.getIntentGoalType();
105 if (intentGoalType == IntentGoalType.CREATE) {
106 return decisionModule.investigationCreateProcess(intentGoalBean);
107 } else if (intentGoalType == IntentGoalType.UPDATE) {
108 return decisionModule.investigationUpdateProcess(intentGoalBean);
110 return decisionModule.investigationDeleteProcess(intentGoalBean);
114 public boolean implementIntent(Intent originIntent, LinkedHashMap<IntentGoalBean, IntentManagementFunction> linkedIntentMap) {
115 Iterator<Map.Entry<IntentGoalBean, IntentManagementFunction>> iterator = linkedIntentMap.entrySet().iterator();
116 while (iterator.hasNext()) {
117 Map.Entry<IntentGoalBean, IntentManagementFunction> next = iterator.next();
118 IntentGoalBean newIntentGoalBean = next.getKey();
119 IntentGoalType intentGoalType = newIntentGoalBean.getIntentGoalType();
120 if (intentGoalType == IntentGoalType.CREATE) {
121 Intent newIdIntent = decisionModule.intentObjectDefine(originIntent, next.getKey().getIntent());
122 intentContextService.updateIntentOwnerHandlerContext(newIdIntent, this, next.getValue());
123 intentContextService.updateParentIntentContext(originIntent, newIdIntent);
124 intentContextService.updateChindIntentContext(originIntent, newIdIntent);
125 //intent-Distribution-create
126 boolean isAcceptCreate = intentInterfaceService.createInterface(originIntent,
127 new IntentGoalBean(newIdIntent, IntentGoalType.CREATE), next.getValue());
128 originIntent.setIntentGenerateType(IntentGenerateType.USERINPUT);
129 //save user input intent
130 intentService.createIntent(originIntent);
131 return isAcceptCreate;
132 } else if (intentGoalType == IntentGoalType.UPDATE) {
133 log.info("formatIntentInputIMF UPDATE");
134 //update cllBusinessIntent's expectation
135 Intent subIntent = newIntentGoalBean.getIntent();
136 updateIntentInfo(originIntent, subIntent);
137 //update userInput intent
138 intentService.updateIntent(originIntent);
139 // intent-Distribution and operate |update cllBusiness intent
140 boolean isAcceptUpdate = intentInterfaceService.updateInterface(originIntent,
141 new IntentGoalBean(subIntent, IntentGoalType.UPDATE), next.getValue());
143 //deal with userInput intent
144 intentService.deleteIntent(originIntent.getIntentId());
145 // intent-Distribution-delete
146 boolean isAcceptDelete = intentInterfaceService.deleteInterface(originIntent, next.getKey(), next.getValue());
152 public void updateIntentInfo(Intent originIntent, Intent intent) {
154 List<Expectation> originIntentExpectationList = originIntent.getIntentExpectations();
155 List<Expectation> intentExpectationList = intent.getIntentExpectations();
156 int newIntentExpectationNum = originIntentExpectationList.size();
157 int oldIntentExpectationNum = intentExpectationList.size();
159 List<Expectation> changeList = new ArrayList<>();
160 if (newIntentExpectationNum != oldIntentExpectationNum) {
161 if (newIntentExpectationNum < oldIntentExpectationNum) {
163 for (Expectation oldExpectation : intentExpectationList) {//search
164 boolean bFindExpectation = false;
165 for (Expectation newExpectation : originIntentExpectationList) {//param
166 if (oldExpectation.getExpectationName().equals(newExpectation.getExpectationName())) {
167 bFindExpectation = true;
171 if (bFindExpectation) {
172 changeList.add(oldExpectation);
177 intent.setIntentExpectations(changeList);