c80c717db27c73aaff76d6dfd42e6703d5080fcc
[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.cllassuranceIntentmgt.cllassurancemodule;
17
18 import org.apache.commons.lang.StringUtils;
19 import org.onap.usecaseui.intentanalysis.adapters.policy.PolicyService;
20 import org.onap.usecaseui.intentanalysis.bean.enums.IntentGoalType;
21 import org.onap.usecaseui.intentanalysis.bean.models.*;
22 import org.onap.usecaseui.intentanalysis.intentBaseService.IntentManagementFunction;
23 import org.onap.usecaseui.intentanalysis.intentBaseService.intentModule.ActuationModule;
24 import org.onap.usecaseui.intentanalysis.service.IntentService;
25 import org.springframework.beans.factory.annotation.Autowired;
26 import org.springframework.stereotype.Component;
27
28 import java.util.List;
29
30 @Component
31 public class CLLAssuranceActuationModule extends ActuationModule {
32     @Autowired
33     private IntentService intentService;
34
35     @Autowired
36     private PolicyService policyService;
37
38     @Override
39     public void toNextIntentHandler(IntentGoalBean intentGoalBean, IntentManagementFunction IntentHandler) {
40
41     }
42
43     @Override
44     public void directOperation(IntentGoalBean intentGoalBean) {
45         Intent intent = intentGoalBean.getIntent();
46         String cllId = getCLLId(intent);
47         String bandwidth = getBandwidth(cllId);
48         IntentGoalType intentGoalType = intentGoalBean.getIntentGoalType();
49         if (StringUtils.equalsIgnoreCase("create", intentGoalType.name())) {
50             policyService.updateIntentConfigPolicy(cllId, bandwidth, "true");
51         } else if (StringUtils.equalsIgnoreCase("update", intentGoalType.name())) {
52             policyService.updateIntentConfigPolicy(cllId, bandwidth, "false");
53         } else if (StringUtils.equalsIgnoreCase("delete", intentGoalType.name())) {
54             policyService.updateIntentConfigPolicy(cllId, bandwidth, "false");
55         }
56     }
57
58     @Override
59     public void interactWithIntentHandle() {
60
61     }
62
63     @Override
64     public void fulfillIntent(IntentGoalBean intentGoalBean, IntentManagementFunction intentHandler) {
65         directOperation(intentGoalBean);
66     }
67
68     @Override
69     public void updateIntentOperationInfo(Intent originIntent, IntentGoalBean intentGoalBean){
70
71     }
72
73     private String getBandwidth(String cllId) {
74         List<Intent> deliveryIntentList = intentService.getIntentByName("CLL Delivery Intent");
75         for (Intent deliveryIntent : deliveryIntentList) {
76             List<Expectation> deliveryExpectationList = deliveryIntent.getIntentExpectations();
77             for (Expectation deliveryExpectation : deliveryExpectationList) {
78                 if (StringUtils.equalsIgnoreCase(cllId, deliveryExpectation.getExpectationObject().getObjectInstance())) {
79                     List<ExpectationTarget> deliveryTargetList = deliveryExpectation.getExpectationTargets();
80                     for (ExpectationTarget deliveryTarget : deliveryTargetList) {
81                         if (StringUtils.equalsIgnoreCase("bandwidth", deliveryTarget.getTargetName())) {
82                             List<Condition> deliveryConditionList = deliveryTarget.getTargetConditions();
83                             for (Condition deliveryCondition : deliveryConditionList) {
84                                 if (StringUtils.equalsIgnoreCase("condition of the cll service bandwidth", deliveryCondition.getConditionName())) {
85                                     return deliveryCondition.getConditionValue();
86                                 }
87                             }
88                         }
89                     }
90                 }
91             }
92         }
93         return null;
94     }
95
96     public String getCLLId(Intent intent) {
97         List<Expectation> expectationList = intent.getIntentExpectations();
98         for (Expectation expectation : expectationList) {
99             if (StringUtils.equalsIgnoreCase("assurance", expectation.getExpectationType().name())) {
100                 return expectation.getExpectationObject().getObjectInstance();
101             }
102         }
103         return null;
104     }
105 }