6776175a5fb4552715c755e48fbd51b8cbcef68a
[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 import org.springframework.transaction.annotation.Transactional;
26
27 import java.util.Iterator;
28 import java.util.LinkedHashMap;
29 import java.util.Map;
30
31 @Service
32 public class IntentProcessService {
33     @Autowired
34     IntentDetectionService intentDetectionService;
35     @Autowired
36     IntentInvestigationService intentInvestigationService;
37     @Autowired
38     IntentDefinitionService intentDefinitionService;
39     @Autowired
40     IntentDistributionService intentDistributionService;
41     @Autowired
42     IntentOperationService intentOperationService;
43     @Autowired
44     IntentService intentService;
45     private IntentManagementFunction intentOwner;
46     private IntentManagementFunction intentHandler;
47
48
49     public void setIntentRole(IntentManagementFunction intentOwner, IntentManagementFunction intentHandler) {
50         if (intentOwner != null) {
51             this.intentOwner = intentOwner;
52         }
53         if (intentHandler != null) {
54             this.intentHandler = intentHandler;
55         }
56     }
57
58     @Transactional(rollbackFor = Exception.class)
59     public IntentGoalBean intentProcess(IntentGoalBean originIntentGoalBean) {
60
61         intentDetectionService.setIntentRole(intentOwner, intentHandler);
62         IntentGoalBean newIntentGoalBean = intentDetectionService.detectionProcess(originIntentGoalBean);
63
64         //investigation process Decomposition
65         intentInvestigationService.setIntentRole(intentOwner, intentHandler);
66         LinkedHashMap<IntentGoalBean, IntentManagementFunction> intentMap =
67                 intentInvestigationService.investigationProcess(newIntentGoalBean);
68
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);
76
77             //distribution process
78             intentDistributionService.setIntentRole(intentOwner, intentHandler);
79             intentDistributionService.distributionProcess(next);
80
81             intentOperationService.setIntentRole(intentOwner, next.getValue());
82             intentOperationService.operationProcess(originIntentGoalBean.getIntent(), newIdIntentGoalBean);
83         }
84         //delete second intent
85         if (StringUtils.equals(originIntentGoalBean.getIntentGoalType().name(),IntentGoalType.DELETE.name())){
86                 intentService.deleteIntent(originIntentGoalBean.getIntent().getIntentId());
87         }
88         return newIntentGoalBean;
89     }
90 }