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;
20 import lombok.SneakyThrows;
21 import lombok.extern.slf4j.Slf4j;
22 import org.apache.commons.lang.StringUtils;
23 import org.onap.usecaseui.intentanalysis.bean.enums.IntentGoalType;
24 import org.onap.usecaseui.intentanalysis.bean.models.Context;
25 import org.onap.usecaseui.intentanalysis.bean.models.Intent;
26 import org.onap.usecaseui.intentanalysis.bean.models.IntentEventRecord;
27 import org.onap.usecaseui.intentanalysis.bean.models.IntentGoalBean;
28 import org.onap.usecaseui.intentanalysis.exception.CommonException;
29 import org.onap.usecaseui.intentanalysis.intentBaseService.IntentManagementFunction;
30 import org.onap.usecaseui.intentanalysis.intentBaseService.contextService.IntentContextService;
31 import org.onap.usecaseui.intentanalysis.intentBaseService.intentEventRecord.IntentEventRecordService;
32 import org.onap.usecaseui.intentanalysis.intentBaseService.intentModule.ActuationModule;
33 import org.onap.usecaseui.intentanalysis.intentBaseService.intentModule.DecisionModule;
34 import org.onap.usecaseui.intentanalysis.intentBaseService.intentModule.KnowledgeModule;
35 import org.onap.usecaseui.intentanalysis.intentBaseService.intentinterfaceservice.IntentInterfaceService;
36 import org.onap.usecaseui.intentanalysis.service.ContextService;
37 import org.onap.usecaseui.intentanalysis.service.IntentService;
38 import org.springframework.beans.factory.annotation.Autowired;
39 import org.springframework.context.ApplicationContext;
40 import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
41 import org.springframework.stereotype.Component;
43 import javax.annotation.Resource;
44 import java.util.Iterator;
45 import java.util.LinkedHashMap;
46 import java.util.List;
48 import java.util.stream.Collectors;
52 @Component("CLLBusinessIntentManagementFunction")
53 public class CLLBusinessIntentManagementFunction extends IntentManagementFunction {
55 @Resource(name = "CLLBusinessActuationModule")
56 public void setActuationModule(ActuationModule actuationModule) {
57 this.actuationModule = actuationModule;
60 @Resource(name = "CLLBusinessKnowledgeModule")
61 public void setKnowledgeModule(KnowledgeModule knowledgeModule) {
62 this.knowledgeModule = knowledgeModule;
65 @Resource(name = "CLLBusinessDecisionModule")
66 public void setDecisionModule(DecisionModule decisionModule) {
67 this.decisionModule = decisionModule;
71 public IntentContextService intentContextService;
73 IntentInterfaceService intentInterfaceService;
75 ApplicationContext applicationContext;
77 ContextService contextService;
79 IntentService intentService;
81 IntentEventRecordService intentEventRecordService;
83 @Resource(name = "intentTaskExecutor")
84 ThreadPoolTaskExecutor executor;
87 public void receiveIntentAsOwner(IntentGoalBean intentGoalBean) {
88 IntentGoalBean originIntentGoalBean = detection(intentGoalBean);
89 LinkedHashMap<IntentGoalBean, IntentManagementFunction> linkedMap = investigation(originIntentGoalBean);
90 implementIntent(intentGoalBean.getIntent(), linkedMap);
91 if (intentGoalBean.getIntentGoalType() == IntentGoalType.DELETE) {
92 intentService.deleteIntent(intentGoalBean.getIntent().getIntentId());
97 public void receiveIntentAsHandler(Intent originalIntent, IntentGoalBean intentGoalBean, IntentManagementFunction handler) {
98 ActuationModule actuationModule = handler.getActuationModule();
99 IntentGoalType type = intentGoalBean.getIntentGoalType();
100 if (type == IntentGoalType.CREATE) {
101 actuationModule.saveIntentToDb(intentGoalBean.getIntent());
102 } else if (type == IntentGoalType.UPDATE) {
103 actuationModule.updateIntentToDb(intentGoalBean.getIntent());
104 } else if (type == IntentGoalType.DELETE) {
105 actuationModule.deleteIntentToDb(intentGoalBean.getIntent());
107 //update origin intent if need
108 actuationModule.updateIntentOperationInfo(originalIntent, intentGoalBean);
109 handler.receiveIntentAsOwner(intentGoalBean);
113 public IntentGoalBean detection(IntentGoalBean intentGoalBean) {
114 Intent originIntent = intentGoalBean.getIntent();
115 IntentGoalType intentGoalType = intentGoalBean.getIntentGoalType();
116 if (intentGoalType == IntentGoalType.CREATE) {
117 return knowledgeModule.intentCognition(originIntent);
118 } else if (intentGoalType == IntentGoalType.UPDATE) {
119 return new IntentGoalBean(intentGoalBean.getIntent(), IntentGoalType.UPDATE);
121 return new IntentGoalBean(intentGoalBean.getIntent(), IntentGoalType.DELETE);
125 public LinkedHashMap<IntentGoalBean, IntentManagementFunction> investigation(IntentGoalBean intentGoalBean) {
126 IntentGoalType intentGoalType = intentGoalBean.getIntentGoalType();
127 if (intentGoalType == IntentGoalType.CREATE) {
128 return decisionModule.investigationCreateProcess(intentGoalBean);
129 } else if (intentGoalType == IntentGoalType.UPDATE) {
130 return decisionModule.investigationUpdateProcess(intentGoalBean);
132 return decisionModule.investigationDeleteProcess(intentGoalBean);
137 public boolean implementIntent(Intent originIntent, LinkedHashMap<IntentGoalBean, IntentManagementFunction> linkedIntentMap) {
138 Iterator<Map.Entry<IntentGoalBean, IntentManagementFunction>> iterator = linkedIntentMap.entrySet().iterator();
139 while (iterator.hasNext()) {
140 Map.Entry<IntentGoalBean, IntentManagementFunction> next = iterator.next();
141 IntentGoalBean newIntentGoalBean = next.getKey();
142 IntentGoalType intentGoalType = newIntentGoalBean.getIntentGoalType();
143 IntentManagementFunction handler = next.getValue();
144 if (intentGoalType == IntentGoalType.CREATE) {
145 Intent newIdIntent = decisionModule.intentObjectDefine(originIntent, next.getKey().getIntent());
146 intentContextService.updateIntentOwnerHandlerContext(newIdIntent, this, next.getValue());
147 intentContextService.updateParentIntentContext(originIntent, newIdIntent);
148 intentContextService.updateChindIntentContext(originIntent, newIdIntent);
149 contextService.updateContextList(originIntent.getIntentContexts(), originIntent.getIntentId());
150 //intent-Distribution-create
151 boolean isAcceptCreate = intentInterfaceService.createInterface(originIntent,
152 new IntentGoalBean(newIdIntent, IntentGoalType.CREATE), next.getValue());
153 // TODO: 2023/3/27 isParallel status need deal before distribution
154 boolean isParallel = false;
156 //Block and regularly query whether the event is published
157 boolean isPublish = false;
161 IntentEventRecord record = intentEventRecordService.getIntentEventRecordByntentId(newIdIntent.getIntentId(), "create");
163 // it will take one hour to wait operation end
165 throw new CommonException("Operation took too long, failed",500);
167 if (null != record) {
172 // return isAcceptCreate;
173 } else if (intentGoalType == IntentGoalType.UPDATE) {
174 //define process just send probe interface
175 // intent-Distribution-update
176 boolean isAcceptupdate = intentInterfaceService.updateInterface(originIntent,
177 next.getKey(), next.getValue());
179 // actuationModule.deleteIntentToDb(next.getKey().getIntent());
180 // intent-Distribution-delete
181 boolean isAcceptDelete = intentInterfaceService.deleteInterface(originIntent,
182 next.getKey(), next.getValue());