b1a0924326c4a254196beeccbc9801782d182d88
[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         log.info("cllDeliveryActuationModule begin to update originIntent subIntentInfo");
75         contextService.updateContextList(originIntent.getIntentContexts(), originIntent.getIntentId());
76     }
77
78     private String getBandwidth(String cllId) {
79         List<Intent> deliveryIntentList = intentService.getIntentByName("CLL Delivery Intent");
80         for (Intent deliveryIntent : deliveryIntentList) {
81             List<Expectation> deliveryExpectationList = deliveryIntent.getIntentExpectations();
82             for (Expectation deliveryExpectation : deliveryExpectationList) {
83                 if (StringUtils.equalsIgnoreCase(cllId, deliveryExpectation.getExpectationObject().getObjectInstance())) {
84                     List<ExpectationTarget> deliveryTargetList = deliveryExpectation.getExpectationTargets();
85                     for (ExpectationTarget deliveryTarget : deliveryTargetList) {
86                         if (StringUtils.equalsIgnoreCase("bandwidth", deliveryTarget.getTargetName())) {
87                             List<Condition> deliveryConditionList = deliveryTarget.getTargetConditions();
88                             for (Condition deliveryCondition : deliveryConditionList) {
89                                 if (StringUtils.equalsIgnoreCase("condition of the cll service bandwidth", deliveryCondition.getConditionName())) {
90                                     return deliveryCondition.getConditionValue();
91                                 }
92                             }
93                         }
94                     }
95                 }
96             }
97         }
98         return null;
99     }
100
101     public String getCLLId(Intent intent) {
102         List<Expectation> expectationList = intent.getIntentExpectations();
103         for (Expectation expectation : expectationList) {
104             if (StringUtils.equalsIgnoreCase("assurance", expectation.getExpectationType().name())) {
105                 return expectation.getExpectationObject().getObjectInstance();
106             }
107         }
108         return null;
109     }
110 }