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.intentBaseService.intentProcessService;
18 import org.apache.commons.lang.StringUtils;
19 import org.onap.usecaseui.intentanalysis.bean.enums.IntentGoalType;
20 import org.onap.usecaseui.intentanalysis.bean.models.IntentGoalBean;
21 import org.onap.usecaseui.intentanalysis.intentBaseService.IntentManagementFunction;
22 import org.onap.usecaseui.intentanalysis.service.IntentService;
23 import org.springframework.beans.factory.annotation.Autowired;
24 import org.springframework.stereotype.Service;
25 import org.springframework.transaction.annotation.Transactional;
27 import java.util.Iterator;
28 import java.util.LinkedHashMap;
32 public class IntentProcessService {
34 IntentDetectionService intentDetectionService;
36 IntentInvestigationService intentInvestigationService;
38 IntentDefinitionService intentDefinitionService;
40 IntentDistributionService intentDistributionService;
42 IntentOperationService intentOperationService;
44 IntentService intentService;
45 private IntentManagementFunction intentOwner;
46 private IntentManagementFunction intentHandler;
49 public void setIntentRole(IntentManagementFunction intentOwner, IntentManagementFunction intentHandler) {
50 if (intentOwner != null) {
51 this.intentOwner = intentOwner;
53 if (intentHandler != null) {
54 this.intentHandler = intentHandler;
58 @Transactional(rollbackFor = Exception.class)
59 public IntentGoalBean intentProcess(IntentGoalBean originIntentGoalBean) {
61 intentDetectionService.setIntentRole(intentOwner, intentHandler);
62 IntentGoalBean newIntentGoalBean = intentDetectionService.detectionProcess(originIntentGoalBean);
64 //investigation process Decomposition
65 intentInvestigationService.setIntentRole(intentOwner, intentHandler);
66 LinkedHashMap<IntentGoalBean, IntentManagementFunction> intentMap =
67 intentInvestigationService.investigationProcess(newIntentGoalBean);
69 Iterator<Map.Entry<IntentGoalBean, IntentManagementFunction>> iterator = intentMap.entrySet().iterator();
70 while (iterator.hasNext()) {
71 Map.Entry<IntentGoalBean, IntentManagementFunction> next = iterator.next();
72 //definition process save subintent
73 intentDefinitionService.setIntentRole(intentOwner, next.getValue());
74 //obtain newID IntentGoalBean
75 IntentGoalBean newIdIntentGoalBean = intentDefinitionService.definitionPorcess(originIntentGoalBean.getIntent(), next);
77 //distribution process
78 intentDistributionService.setIntentRole(intentOwner, intentHandler);
79 intentDistributionService.distributionProcess(next);
81 intentOperationService.setIntentRole(intentOwner, next.getValue());
82 intentOperationService.operationProcess(originIntentGoalBean.getIntent(), newIdIntentGoalBean);
84 //delete second intent
85 if (StringUtils.equals(originIntentGoalBean.getIntentGoalType().name(),IntentGoalType.DELETE.name())){
86 intentService.deleteIntent(originIntentGoalBean.getIntent().getIntentId());
88 return newIntentGoalBean;