5c447d93c17a47db71b810063a88e5f4a2e29955
[usecase-ui/intent-analysis.git] /
1 /*
2  * Copyright (C) 2022 CMCC, Inc. and others. All rights reserved.
3  *
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
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16 package org.onap.usecaseui.intentanalysis.intentBaseService.intentProcessService;
17
18 import org.onap.usecaseui.intentanalysis.bean.enums.IntentGoalType;
19 import org.onap.usecaseui.intentanalysis.bean.models.Intent;
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
26 import java.util.Iterator;
27 import java.util.LinkedHashMap;
28 import java.util.Map;
29
30 @Service
31 public class IntentProcessService {
32     @Autowired
33     IntentDetectionService intentDetectionService;
34     @Autowired
35     IntentInvestigationService intentInvestigationService;
36     @Autowired
37     IntentDefinitionService intentDefinitionService;
38     @Autowired
39     IntentDistributionService intentDistributionService;
40     @Autowired
41     IntentOperationService intentOperationService;
42     @Autowired
43     IntentService intentService;
44     private IntentManagementFunction intentOwner;
45     private IntentManagementFunction intentHandler;
46
47
48     public void setIntentRole(IntentManagementFunction intentOwner, IntentManagementFunction intentHandler) {
49         if (intentOwner != null) {
50             this.intentOwner = intentOwner;
51         }
52         if (intentHandler != null) {
53             this.intentHandler = intentHandler;
54         }
55     }
56
57     public IntentGoalBean intentProcess(IntentGoalBean originIntentGoalBean) {
58
59         intentDetectionService.setIntentRole(intentOwner, intentHandler);
60         IntentGoalBean newIntentGoalBean = intentDetectionService.detectionProcess(originIntentGoalBean);
61
62         //Èç¹ûÊÇupdate£¬Ö±½ÓÔÚinvestigationProcess»ñµÃintentÖж¨ÒåµÄhandlerµÄÐÅÏ¢£¬È»ºóÒ»¸öupdate  »òÕßÁ½¸öupdate
63         //investigation process
64         intentInvestigationService.setIntentRole(intentOwner, intentHandler);
65         LinkedHashMap<IntentGoalBean, IntentManagementFunction> intentMap =
66                 intentInvestigationService.investigationProcess(newIntentGoalBean);
67
68         Iterator<Map.Entry<IntentGoalBean, IntentManagementFunction>> iterator = intentMap.entrySet().iterator();
69         while (iterator.hasNext()) {
70             Map.Entry<IntentGoalBean, IntentManagementFunction> next = iterator.next();
71             //definition process  save subintent
72             intentDefinitionService.setIntentRole(intentOwner, intentHandler);
73             intentDefinitionService.definitionPorcess(originIntentGoalBean.getIntent(), next);
74
75             //distribution process
76             intentDistributionService.setIntentRole(intentOwner, intentHandler);
77             intentDistributionService.distributionProcess(next);
78
79             intentOperationService.setIntentRole(intentOwner, next.getValue());
80             intentOperationService.operationProcess(originIntentGoalBean.getIntent(), next.getKey());
81         }
82
83         return newIntentGoalBean;
84     }
85
86
87 }