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