331628f8adc2029f74723439333301914b0ca7d0
[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.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
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         //investigation process Decomposition
63         intentInvestigationService.setIntentRole(intentOwner, intentHandler);
64         LinkedHashMap<IntentGoalBean, IntentManagementFunction> intentMap =
65                 intentInvestigationService.investigationProcess(newIntentGoalBean);
66
67         Iterator<Map.Entry<IntentGoalBean, IntentManagementFunction>> iterator = intentMap.entrySet().iterator();
68         while (iterator.hasNext()) {
69             Map.Entry<IntentGoalBean, IntentManagementFunction> next = iterator.next();
70             //definition process  save subintent
71             intentDefinitionService.setIntentRole(intentOwner, next.getValue());
72             //obtain newID IntentGoalBean               
73             IntentGoalBean newIdIntentGoalBean = 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(), newIdIntentGoalBean);
81         }
82         //delete second intent
83         if (StringUtils.equals(originIntentGoalBean.getIntentGoalType().name(),IntentGoalType.DELETE.name())){
84                 intentService.deleteIntent(originIntentGoalBean.getIntent().getIntentId());
85         }
86         return newIntentGoalBean;
87     }
88 }