Add direct operation code. 81/131581/4 5.1.1
authorhekeguang <hekeguang@chinamobile.com>
Thu, 20 Oct 2022 09:53:23 +0000 (17:53 +0800)
committerKeguang He <hekeguang@chinamobile.com>
Thu, 20 Oct 2022 10:47:57 +0000 (10:47 +0000)
Issue-ID: USECASEUI-696
Change-Id: I8dd133e1dee35b1e3d4da193c37e1c3492be9df2
Signed-off-by: hekeguang <hekeguang@chinamobile.com>
intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/cllBusinessIntentMgt/cllBusinessModule/CLLBusinessActuationModule.java
intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/cllassuranceIntentmgt/cllassurancemodule/CLLAssuranceActuationModule.java
intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/clldeliveryIntentmgt/clldeliverymodule/CLLDeliveryActuationModule.java
intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/formatintentinputMgt/formatintentinputModule/FormatIntentInputActuationModule.java
intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/intentBaseService/intentModule/ActuationModule.java
intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/intentBaseService/intentProcessService/IntentProcessService.java

index 6a091c5..c80c717 100644 (file)
  */
 package org.onap.usecaseui.intentanalysis.cllassuranceIntentmgt.cllassurancemodule;
 
-import org.onap.usecaseui.intentanalysis.bean.models.Intent;
-import org.onap.usecaseui.intentanalysis.bean.models.IntentGoalBean;
+import org.apache.commons.lang.StringUtils;
+import org.onap.usecaseui.intentanalysis.adapters.policy.PolicyService;
+import org.onap.usecaseui.intentanalysis.bean.enums.IntentGoalType;
+import org.onap.usecaseui.intentanalysis.bean.models.*;
 import org.onap.usecaseui.intentanalysis.intentBaseService.IntentManagementFunction;
 import org.onap.usecaseui.intentanalysis.intentBaseService.intentModule.ActuationModule;
+import org.onap.usecaseui.intentanalysis.service.IntentService;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
+import java.util.List;
+
 @Component
 public class CLLAssuranceActuationModule extends ActuationModule {
+    @Autowired
+    private IntentService intentService;
+
+    @Autowired
+    private PolicyService policyService;
+
     @Override
     public void toNextIntentHandler(IntentGoalBean intentGoalBean, IntentManagementFunction IntentHandler) {
 
     }
 
     @Override
-    public void directOperation() {
-
+    public void directOperation(IntentGoalBean intentGoalBean) {
+        Intent intent = intentGoalBean.getIntent();
+        String cllId = getCLLId(intent);
+        String bandwidth = getBandwidth(cllId);
+        IntentGoalType intentGoalType = intentGoalBean.getIntentGoalType();
+        if (StringUtils.equalsIgnoreCase("create", intentGoalType.name())) {
+            policyService.updateIntentConfigPolicy(cllId, bandwidth, "true");
+        } else if (StringUtils.equalsIgnoreCase("update", intentGoalType.name())) {
+            policyService.updateIntentConfigPolicy(cllId, bandwidth, "false");
+        } else if (StringUtils.equalsIgnoreCase("delete", intentGoalType.name())) {
+            policyService.updateIntentConfigPolicy(cllId, bandwidth, "false");
+        }
     }
 
     @Override
@@ -40,10 +62,44 @@ public class CLLAssuranceActuationModule extends ActuationModule {
 
     @Override
     public void fulfillIntent(IntentGoalBean intentGoalBean, IntentManagementFunction intentHandler) {
-        directOperation();
+        directOperation(intentGoalBean);
     }
 
+    @Override
     public void updateIntentOperationInfo(Intent originIntent, IntentGoalBean intentGoalBean){
 
     }
+
+    private String getBandwidth(String cllId) {
+        List<Intent> deliveryIntentList = intentService.getIntentByName("CLL Delivery Intent");
+        for (Intent deliveryIntent : deliveryIntentList) {
+            List<Expectation> deliveryExpectationList = deliveryIntent.getIntentExpectations();
+            for (Expectation deliveryExpectation : deliveryExpectationList) {
+                if (StringUtils.equalsIgnoreCase(cllId, deliveryExpectation.getExpectationObject().getObjectInstance())) {
+                    List<ExpectationTarget> deliveryTargetList = deliveryExpectation.getExpectationTargets();
+                    for (ExpectationTarget deliveryTarget : deliveryTargetList) {
+                        if (StringUtils.equalsIgnoreCase("bandwidth", deliveryTarget.getTargetName())) {
+                            List<Condition> deliveryConditionList = deliveryTarget.getTargetConditions();
+                            for (Condition deliveryCondition : deliveryConditionList) {
+                                if (StringUtils.equalsIgnoreCase("condition of the cll service bandwidth", deliveryCondition.getConditionName())) {
+                                    return deliveryCondition.getConditionValue();
+                                }
+                            }
+                        }
+                    }
+                }
+            }
+        }
+        return null;
+    }
+
+    public String getCLLId(Intent intent) {
+        List<Expectation> expectationList = intent.getIntentExpectations();
+        for (Expectation expectation : expectationList) {
+            if (StringUtils.equalsIgnoreCase("assurance", expectation.getExpectationType().name())) {
+                return expectation.getExpectationObject().getObjectInstance();
+            }
+        }
+        return null;
+    }
 }
index cca03fe..641ecaf 100644 (file)
  */
 package org.onap.usecaseui.intentanalysis.clldeliveryIntentmgt.clldeliverymodule;
 
-import java.util.List;
-import org.onap.usecaseui.intentanalysis.bean.models.Expectation;
-import org.onap.usecaseui.intentanalysis.bean.models.ExpectationObject;
-import org.onap.usecaseui.intentanalysis.bean.models.Intent;
-import org.onap.usecaseui.intentanalysis.bean.models.IntentGoalBean;
+import org.apache.commons.lang.StringUtils;
+import org.onap.usecaseui.intentanalysis.adapters.so.SOService;
+import org.onap.usecaseui.intentanalysis.bean.models.*;
 import org.onap.usecaseui.intentanalysis.intentBaseService.IntentManagementFunction;
 import org.onap.usecaseui.intentanalysis.intentBaseService.intentModule.ActuationModule;
+import org.onap.usecaseui.intentanalysis.service.ExpectationObjectService;
 import org.onap.usecaseui.intentanalysis.service.IntentService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+
 @Component
 public class CLLDeliveryActuationModule extends ActuationModule {
+
+    @Autowired
+    private SOService soService;
+
+    @Autowired
+    private ExpectationObjectService expectationObjectService;
+
     @Autowired
-    IntentService intentService;
+    private IntentService intentService;
 
     @Override
     public void toNextIntentHandler(IntentGoalBean intentGoalBean, IntentManagementFunction IntentHandler) {
@@ -37,8 +48,37 @@ public class CLLDeliveryActuationModule extends ActuationModule {
     }
 
     @Override
-    public void directOperation() {
-
+    public void directOperation(IntentGoalBean intentGoalBean) {
+        Intent intent = intentGoalBean.getIntent();
+        if (StringUtils.equalsIgnoreCase("create", intentGoalBean.getIntentGoalType().name())) {
+            Map<String, Object> params = new HashMap<>();
+            Map<String, String> accessPointOne = new HashMap<>();
+            List<ExpectationTarget> targetList = intent.getIntentExpectations().get(0).getExpectationTargets();
+            for (ExpectationTarget target : targetList) {
+                String conditionName = target.getTargetConditions().get(0).getConditionName();
+                String conditionValue = target.getTargetConditions().get(0).getConditionValue();
+                if (StringUtils.containsIgnoreCase(conditionName, "source")) {
+                    accessPointOne.put("name", conditionValue);
+                } else if (StringUtils.containsIgnoreCase(conditionName, "destination")) {
+                    params.put("cloudPointName", conditionValue);
+                } else if (StringUtils.containsIgnoreCase(conditionName, "bandwidth")) {
+                    accessPointOne.put("bandwidth", conditionValue);
+                }
+            }
+            params.put("accessPointOne", accessPointOne);
+            params.put("instanceId", getInstanceId());
+            params.put("name", "cll-" + params.get("instanceId"));
+            params.put("protect", false);
+            soService.createIntentInstance(params);
+            String expectationId = intent.getIntentExpectations().get(0).getExpectationId();
+            ExpectationObject expectationObject = expectationObjectService.getExpectationObject(expectationId);
+            expectationObject.setObjectInstance((String) params.get("name"));
+            expectationObjectService.updateExpectationObject(expectationObject, expectationId);
+        } else {
+            String instanceId = intent.getIntentExpectations().get(0).getExpectationObject().getObjectInstance();
+            soService.deleteIntentInstance(instanceId);
+            intentService.deleteIntent(intent.getIntentId());
+        }
     }
 
     @Override
@@ -48,7 +88,18 @@ public class CLLDeliveryActuationModule extends ActuationModule {
 
     @Override
     public void fulfillIntent(IntentGoalBean intentGoalBean, IntentManagementFunction intentHandler) {
-        this.directOperation();
+        this.directOperation(intentGoalBean);
+    }
+       
+       public String getInstanceId() {
+        int random = (int) (Math.random() * 9 + 1);
+
+        String randomString = String.valueOf(random);
+        int hashCode = UUID.randomUUID().toString().hashCode();
+        if (hashCode < 0) {
+            hashCode = -hashCode;
+        }
+        return randomString + String.format("%015d", hashCode);
     }
 
     public void updateIntentOperationInfo(Intent originIntent, IntentGoalBean intentGoalBean){
index 84c391e..5641e99 100644 (file)
@@ -36,7 +36,7 @@ public abstract class ActuationModule {
     public abstract void toNextIntentHandler(IntentGoalBean intentGoalBean, IntentManagementFunction IntentHandler);
 
     //Direct operation
-    public abstract void directOperation();
+    public abstract void directOperation(IntentGoalBean intentGoalBean);
 
     public abstract void interactWithIntentHandle();
 
index 5c447d9..4dfc492 100644 (file)
@@ -59,7 +59,6 @@ public class IntentProcessService {
         intentDetectionService.setIntentRole(intentOwner, intentHandler);
         IntentGoalBean newIntentGoalBean = intentDetectionService.detectionProcess(originIntentGoalBean);
 
-        //Èç¹ûÊÇupdate£¬Ö±½ÓÔÚinvestigationProcess»ñµÃintentÖж¨ÒåµÄhandlerµÄÐÅÏ¢£¬È»ºóÒ»¸öupdate  »òÕßÁ½¸öupdate
         //investigation process
         intentInvestigationService.setIntentRole(intentOwner, intentHandler);
         LinkedHashMap<IntentGoalBean, IntentManagementFunction> intentMap =