2 * Copyright (C) 2022 CMCC, Inc. and others. All rights reserved.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 package org.onap.usecaseui.intentanalysis.clldeliveryIntentmgt.clldeliverymodule;
18 import org.apache.commons.lang.StringUtils;
19 import org.onap.usecaseui.intentanalysis.adapters.so.SOService;
20 import org.onap.usecaseui.intentanalysis.bean.models.*;
21 import org.onap.usecaseui.intentanalysis.intentBaseService.IntentManagementFunction;
22 import org.onap.usecaseui.intentanalysis.intentBaseService.intentModule.ActuationModule;
23 import org.onap.usecaseui.intentanalysis.service.ExpectationObjectService;
24 import org.onap.usecaseui.intentanalysis.service.IntentService;
25 import org.springframework.beans.factory.annotation.Autowired;
26 import org.springframework.stereotype.Component;
28 import java.util.HashMap;
29 import java.util.List;
31 import java.util.UUID;
34 public class CLLDeliveryActuationModule extends ActuationModule {
37 private SOService soService;
40 private ExpectationObjectService expectationObjectService;
43 private IntentService intentService;
46 public void toNextIntentHandler(IntentGoalBean intentGoalBean, IntentManagementFunction IntentHandler) {
51 public void directOperation(IntentGoalBean intentGoalBean) {
52 Intent intent = intentGoalBean.getIntent();
53 if (StringUtils.equalsIgnoreCase("create", intentGoalBean.getIntentGoalType().name())) {
54 Map<String, Object> params = new HashMap<>();
55 Map<String, String> accessPointOne = new HashMap<>();
56 List<ExpectationTarget> targetList = intent.getIntentExpectations().get(0).getExpectationTargets();
57 for (ExpectationTarget target : targetList) {
58 String conditionName = target.getTargetConditions().get(0).getConditionName();
59 String conditionValue = target.getTargetConditions().get(0).getConditionValue();
60 if (StringUtils.containsIgnoreCase(conditionName, "source")) {
61 accessPointOne.put("name", conditionValue);
62 } else if (StringUtils.containsIgnoreCase(conditionName, "destination")) {
63 params.put("cloudPointName", conditionValue);
64 } else if (StringUtils.containsIgnoreCase(conditionName, "bandwidth")) {
65 accessPointOne.put("bandwidth", conditionValue);
68 params.put("accessPointOne", accessPointOne);
69 params.put("instanceId", getInstanceId());
70 params.put("name", "cll-" + params.get("instanceId"));
71 params.put("protect", false);
72 soService.createIntentInstance(params);
73 String expectationId = intent.getIntentExpectations().get(0).getExpectationId();
74 ExpectationObject expectationObject = expectationObjectService.getExpectationObject(expectationId);
75 expectationObject.setObjectInstance((String) params.get("name"));
76 expectationObjectService.updateExpectationObject(expectationObject, expectationId);
78 String instanceId = intent.getIntentExpectations().get(0).getExpectationObject().getObjectInstance();
79 soService.deleteIntentInstance(instanceId);
80 intentService.deleteIntent(intent.getIntentId());
85 public void interactWithIntentHandle() {
90 public void fulfillIntent(IntentGoalBean intentGoalBean, IntentManagementFunction intentHandler) {
91 this.directOperation(intentGoalBean);
94 public String getInstanceId() {
95 int random = (int) (Math.random() * 9 + 1);
97 String randomString = String.valueOf(random);
98 int hashCode = UUID.randomUUID().toString().hashCode();
100 hashCode = -hashCode;
102 return randomString + String.format("%015d", hashCode);
105 public void updateIntentOperationInfo(Intent originIntent, IntentGoalBean intentGoalBean){
106 Intent subIntent = intentGoalBean.getIntent();
107 if (subIntent.getIntentName().contains("delivery")){
108 List<Expectation> deliveryIntentExpectationList = intentGoalBean.getIntent().getIntentExpectations();
109 List<Expectation> originIntentExpectationList = originIntent.getIntentExpectations();
110 ExpectationObject deliveryExpectationObject = deliveryIntentExpectationList.get(0).getExpectationObject();
111 String objectInstance = deliveryExpectationObject.getObjectInstance();
113 for (Expectation originExpectation : originIntentExpectationList) {
114 ExpectationObject originExpectationObject = originExpectation.getExpectationObject();
115 originExpectationObject.setObjectInstance(objectInstance);
118 intentService.updateIntent(originIntent);