Bugfix for intent analysis server delete function. 44/131944/1
authorhekeguang <hekeguang@chinamobile.com>
Wed, 2 Nov 2022 02:48:58 +0000 (10:48 +0800)
committerhekeguang <hekeguang@chinamobile.com>
Wed, 2 Nov 2022 02:49:14 +0000 (10:49 +0800)
Issue-ID: USECASEUI-749
Change-Id: I551057366c70b68c1ec8af0eaacc4403b4bfd7cc
Signed-off-by: hekeguang <hekeguang@chinamobile.com>
13 files changed:
intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/cllBusinessIntentMgt/cllBusinessModule/CLLBusinessDecisionModule.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/controller/IntentController.java
intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/formatintentinputMgt/formatintentinputModule/FormatIntentInputActuationModule.java
intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/formatintentinputMgt/formatintentinputModule/FormatIntentInputDecisionModule.java
intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/intentBaseService/contextService/IntentContextService.java
intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/intentBaseService/intentModule/ActuationModule.java
intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/intentBaseService/intentProcessService/IntentDefinitionService.java
intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/intentBaseService/intentProcessService/IntentProcessService.java
intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/service/IntentService.java
intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/service/impl/IntentServiceImpl.java
intentanalysis/src/main/resources/mybatis/sql/ConditionMapper.xml

index f073cc2..b9e48ed 100644 (file)
@@ -163,8 +163,10 @@ public class CLLBusinessDecisionModule extends DecisionModule {
             IntentManagementFunction intentHandlerInfo = intentContextService.getHandlerInfo(intent);
             boolean bFindIntent = false;
             for (Expectation originExpectation : originIntentExpectationList) {
-                if (intent.getIntentName().equals(originExpectation.getExpectationName())){
+                if (intent.getIntentName().replace("Intent","")
+                        .equals(originExpectation.getExpectationName().replace("Expectation",""))){
                     bFindIntent = true;
+                    break;
                 }
             }
 
index c80c717..b1a0924 100644 (file)
  */
 package org.onap.usecaseui.intentanalysis.cllassuranceIntentmgt.cllassurancemodule;
 
+import lombok.extern.slf4j.Slf4j;
 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.ContextService;
 import org.onap.usecaseui.intentanalysis.service.IntentService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
 import java.util.List;
-
+@Slf4j
 @Component
 public class CLLAssuranceActuationModule extends ActuationModule {
     @Autowired
@@ -34,6 +36,8 @@ public class CLLAssuranceActuationModule extends ActuationModule {
 
     @Autowired
     private PolicyService policyService;
+    @Autowired
+    private ContextService contextService;
 
     @Override
     public void toNextIntentHandler(IntentGoalBean intentGoalBean, IntentManagementFunction IntentHandler) {
@@ -67,7 +71,8 @@ public class CLLAssuranceActuationModule extends ActuationModule {
 
     @Override
     public void updateIntentOperationInfo(Intent originIntent, IntentGoalBean intentGoalBean){
-
+        log.info("cllDeliveryActuationModule begin to update originIntent subIntentInfo");
+        contextService.updateContextList(originIntent.getIntentContexts(), originIntent.getIntentId());
     }
 
     private String getBandwidth(String cllId) {
index b642586..cf1072c 100644 (file)
@@ -21,6 +21,7 @@ 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.ContextService;
 import org.onap.usecaseui.intentanalysis.service.ExpectationObjectService;
 import org.onap.usecaseui.intentanalysis.service.IntentService;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -43,6 +44,8 @@ public class CLLDeliveryActuationModule extends ActuationModule {
 
     @Autowired
     private IntentService intentService;
+    @Autowired
+    private ContextService contextService;
 
     @Override
     public void toNextIntentHandler(IntentGoalBean intentGoalBean, IntentManagementFunction IntentHandler) {
@@ -118,7 +121,7 @@ public class CLLDeliveryActuationModule extends ActuationModule {
                 expectationObjectService.updateExpectationObject(originExpectationObject,originExpectation.getExpectationId());
             }
         }
-
-
+       log.info("cllDeliveryActuationModule begin to update originIntent subIntentInfo");
+        contextService.updateContextList(originIntent.getIntentContexts(), originIntent.getIntentId());
     }
 }
index 6e5c7d4..fcbee7c 100644 (file)
@@ -84,19 +84,9 @@ public class IntentController {
     public void removeIntentById(@PathVariable(INTENT_ID) String intentId) {
 
         processService.setIntentRole(formatIntentInputManagementFunction, null);
-        //save original intent
         Intent intent = intentService.getIntent(intentId);
         IntentGoalBean intentGoalBean = new IntentGoalBean(intent, IntentGoalType.DELETE);
         processService.intentProcess(intentGoalBean);
     }
 
-    @PostMapping(value = "/handleIntent", produces = MediaType.APPLICATION_JSON_VALUE)
-    public void handleIntent(@RequestBody Intent intent) {
-        processService.setIntentRole(formatIntentInputManagementFunction, null);
-        //save original intent
-
-        IntentGoalBean intentGoalBean = new IntentGoalBean(intent, IntentGoalType.CREATE);
-        IntentGoalBean newIntentGoalBean = processService.intentProcess(intentGoalBean);
-        intentService.createIntent(newIntentGoalBean.getIntent());
-    }
 }
index 2f8756c..3572687 100644 (file)
  */
 package org.onap.usecaseui.intentanalysis.formatintentinputMgt.formatintentinputModule;
 
-import lombok.extern.log4j.Log4j2;
-import org.apache.commons.collections.CollectionUtils;
-import org.onap.usecaseui.intentanalysis.bean.enums.OperatorType;
-import org.onap.usecaseui.intentanalysis.bean.models.Condition;
-import org.onap.usecaseui.intentanalysis.bean.models.Context;
+import lombok.extern.slf4j.Slf4j;
 import org.onap.usecaseui.intentanalysis.bean.models.Intent;
 import org.onap.usecaseui.intentanalysis.bean.models.IntentGoalBean;
-import org.onap.usecaseui.intentanalysis.formatintentinputMgt.FormatIntentInputManagementFunction;
 import org.onap.usecaseui.intentanalysis.intentBaseService.IntentManagementFunction;
 import org.onap.usecaseui.intentanalysis.intentBaseService.intentModule.ActuationModule;
 import org.onap.usecaseui.intentanalysis.intentBaseService.intentProcessService.IntentProcessService;
 import org.onap.usecaseui.intentanalysis.service.IntentService;
-import org.onap.usecaseui.intentanalysis.util.CommonUtil;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
-import java.util.ArrayList;
-import java.util.List;
-
-@Log4j2
+@Slf4j
 @Component
 public class FormatIntentInputActuationModule extends ActuationModule {
     @Autowired
index 0a01357..9e0a443 100644 (file)
@@ -108,6 +108,9 @@ public class FormatIntentInputDecisionModule extends DecisionModule {
     public LinkedHashMap<IntentGoalBean, IntentManagementFunction> investigationUpdateProcess(IntentGoalBean intentGoalBean) {
         //get format-cll intent
         LinkedHashMap<IntentGoalBean, IntentManagementFunction> intentMap = new LinkedHashMap<>();
+        // update format-cll intentContext
+        Intent intent1 = intentService.getIntent(intentGoalBean.getIntent().getIntentId());
+        intentGoalBean.getIntent().setIntentContexts(intent1.getIntentContexts());
         List<Intent> subIntentList = intentContextService.getSubIntentInfoFromContext(intentGoalBean.getIntent());
         for (Intent intent : subIntentList) {
             IntentManagementFunction intentHandlerInfo = intentContextService.getHandlerInfo(intent);
@@ -125,22 +128,25 @@ public class FormatIntentInputDecisionModule extends DecisionModule {
         int newIntentExpectationNum = originIntentExpectationList.size();
         int oldIntentExpectationNum = intentExpectationList.size();
 
+        List<Expectation> changeList = new ArrayList<>();
         if (newIntentExpectationNum != oldIntentExpectationNum){
             if (newIntentExpectationNum < oldIntentExpectationNum){
-                boolean bFindExpectation = false;
-                for (Expectation oldExpectation : intentExpectationList) {
-                    for (Expectation newExpectation : originIntentExpectationList) {
+
+                for (Expectation oldExpectation : intentExpectationList) {//search
+                    boolean bFindExpectation = false;
+                    for (Expectation newExpectation : originIntentExpectationList) {//param
                         if (oldExpectation.getExpectationName().equals(newExpectation.getExpectationName())){
                             bFindExpectation = true;
+                            break;
                         }
                     }
-                    if (bFindExpectation == false){
-                        intentExpectationList.remove(oldExpectation);
+                    if (bFindExpectation){
+                        changeList.add(oldExpectation);
                     }
                 }
             }
         }
-        intent.setIntentExpectations(intentExpectationList);
+        intent.setIntentExpectations(changeList);
     }
 
     @Override
index 8a97783..76ff2d2 100644 (file)
  */
 package org.onap.usecaseui.intentanalysis.intentBaseService.contextService;
 
+import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.collections.CollectionUtils;
+import org.apache.commons.lang.StringUtils;
 import org.onap.usecaseui.intentanalysis.bean.enums.OperatorType;
 import org.onap.usecaseui.intentanalysis.bean.models.Condition;
 import org.onap.usecaseui.intentanalysis.bean.models.Context;
 import org.onap.usecaseui.intentanalysis.bean.models.Intent;
-import org.onap.usecaseui.intentanalysis.cllBusinessIntentMgt.CLLBusinessIntentManagementFunction;
 import org.onap.usecaseui.intentanalysis.intentBaseService.IntentManagementFunction;
 import org.onap.usecaseui.intentanalysis.service.IntentService;
 import org.onap.usecaseui.intentanalysis.util.CommonUtil;
@@ -30,7 +31,7 @@ import org.springframework.stereotype.Service;
 
 import java.util.ArrayList;
 import java.util.List;
-
+@Slf4j
 @Service
 public class IntentContextService {
 
@@ -95,8 +96,8 @@ public class IntentContextService {
             conditionList.add(condition1);
             context.setContextConditions(conditionList);
             contextList.add(context);
-            originIntent.setIntentContexts(contextList);
         }
+        originIntent.setIntentContexts(contextList);
     }
 
     public void updateIntentOwnerHandlerContext(Intent intent, IntentManagementFunction intentOwner, IntentManagementFunction intentHandler){
@@ -163,8 +164,9 @@ public class IntentContextService {
             if (context.getContextName().contains("handler info")) {
                 List<Condition> conditionList = context.getContextConditions();
                 String handlerClassName = conditionList.get(0).getConditionValue();
+                String handleName = StringUtils.substringAfterLast(handlerClassName,".");
                 handler = (IntentManagementFunction) applicationContext
-                    .getBean(CLLBusinessIntentManagementFunction.class.getSimpleName());
+                    .getBean(handleName);
             }
         }
         return handler;
@@ -175,13 +177,16 @@ public class IntentContextService {
         for (Context context : contextList) {
             if (context.getContextName().contains("subIntent info")) {
                 List<Condition> conditionList = context.getContextConditions();
+                List<Condition> newConditionList = new ArrayList<>();
                 for (Condition condition : conditionList) {
-                    if (condition.getConditionValue() == deleteIntentId){
-                        conditionList.remove(condition);
+                    if (!StringUtils.equals(condition.getConditionValue(), deleteIntentId)){
+                        newConditionList.add(condition);
                     }
                 }
+                context.setContextConditions(newConditionList);
             }
         }
+        log.info("deleteSubIntentContext from intent finished");
     }
 
 }
index 5641e99..9b4c248 100644 (file)
@@ -15,6 +15,7 @@
  */
 package org.onap.usecaseui.intentanalysis.intentBaseService.intentModule;
 
+import org.apache.commons.collections.CollectionUtils;
 import org.apache.commons.lang.StringUtils;
 import org.onap.usecaseui.intentanalysis.bean.enums.IntentGoalType;
 import org.onap.usecaseui.intentanalysis.bean.models.Intent;
@@ -24,6 +25,7 @@ import org.onap.usecaseui.intentanalysis.intentBaseService.intentinterfaceservic
 import org.onap.usecaseui.intentanalysis.service.IntentService;
 import org.springframework.beans.factory.annotation.Autowired;
 
+import java.util.List;
 import java.util.Map;
 
 public abstract class ActuationModule {
@@ -52,6 +54,11 @@ public abstract class ActuationModule {
 
     //Delete intent information to the intent instance database
     public void deleteIntentToDb(Intent intent) {
+        //judge if exist subIntent,exist->don't delete
+        List<String> subIntentList = intentService.getSubIntentList(intent);
+        if (CollectionUtils.isNotEmpty(subIntentList)) {
+            return;
+        }
         intentService.deleteIntent(intent.getIntentId());
     }
 
index 4cf00f3..92be843 100644 (file)
@@ -67,7 +67,7 @@ public class IntentDefinitionService {
             intentActuationModule.updateIntentToDb(newIntentGoalBean.getIntent());
         }
         if (newIntentGoalBean.getIntentGoalType() == IntentGoalType.DELETE){
-            intentActuationModule.deleteIntentToDb(newIntentGoalBean.getIntent());
+            intentActuationModule.deleteIntentToDb(entry.getKey().getIntent());
         }
         return newIntentGoalBean;
     }
index 49f6d13..331628f 100644 (file)
@@ -15,8 +15,8 @@
  */
 package org.onap.usecaseui.intentanalysis.intentBaseService.intentProcessService;
 
+import org.apache.commons.lang.StringUtils;
 import org.onap.usecaseui.intentanalysis.bean.enums.IntentGoalType;
-import org.onap.usecaseui.intentanalysis.bean.models.Intent;
 import org.onap.usecaseui.intentanalysis.bean.models.IntentGoalBean;
 import org.onap.usecaseui.intentanalysis.intentBaseService.IntentManagementFunction;
 import org.onap.usecaseui.intentanalysis.service.IntentService;
@@ -79,6 +79,10 @@ public class IntentProcessService {
             intentOperationService.setIntentRole(intentOwner, next.getValue());
             intentOperationService.operationProcess(originIntentGoalBean.getIntent(), newIdIntentGoalBean);
         }
+        //delete second intent
+        if (StringUtils.equals(originIntentGoalBean.getIntentGoalType().name(),IntentGoalType.DELETE.name())){
+                intentService.deleteIntent(originIntentGoalBean.getIntent().getIntentId());
+        }
         return newIntentGoalBean;
     }
 }
index d823245..51bbea5 100644 (file)
@@ -33,4 +33,6 @@ public interface IntentService {
     void deleteIntent(String intentId);
 
     List<Intent> getIntentByName(String name);
+
+    List<String> getSubIntentList(Intent intent);
 }
index bb1759c..d2b41bb 100644 (file)
 package org.onap.usecaseui.intentanalysis.service.impl;
 
 
+import java.util.ArrayList;
 import java.util.List;
+import java.util.stream.Collectors;
 
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.collections.CollectionUtils;
+import org.apache.commons.lang.StringUtils;
+import org.onap.usecaseui.intentanalysis.bean.models.Condition;
+import org.onap.usecaseui.intentanalysis.bean.models.Context;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
@@ -151,4 +156,22 @@ public class IntentServiceImpl implements IntentService {
         }
         return intentList;
     }
+
+    @Override
+    public List<String> getSubIntentList(Intent intent){
+        List<Context> intentContexts = intent.getIntentContexts();
+        List<String> subIntentIds= new ArrayList<>();
+        if (CollectionUtils.isNotEmpty(intentContexts)) {
+            List<Context> subIntentInfoList = intentContexts.stream().filter(x -> StringUtils.equals(x.getContextName(), "subIntent info")).collect(Collectors.toList());
+            if (CollectionUtils.isNotEmpty(subIntentInfoList)) {
+                List<Condition> contextConditions = subIntentInfoList.get(0).getContextConditions();
+                if (CollectionUtils.isNotEmpty(contextConditions)) {
+                    for (Condition con:contextConditions) {
+                        subIntentIds.add(con.getConditionValue());
+                    }
+                }
+            }
+        }
+        return subIntentIds;
+    }
 }
index ccce147..f0bc629 100644 (file)
@@ -49,7 +49,7 @@
     </update>
 
     <delete id="deleteCondition">
-        DELETE FROM condition WHERE condition_id = #{condition.conditionId}
+        DELETE FROM condition WHERE condition_id = #{conditionId}
     </delete>
 
     <delete id="deleteConditionList">