Modify Intent Model 53/135853/1
authorkaixiliu <liukaixi@chinamobile.com>
Tue, 29 Aug 2023 02:45:18 +0000 (10:45 +0800)
committerkaixiliu <liukaixi@chinamobile.com>
Tue, 29 Aug 2023 02:45:56 +0000 (10:45 +0800)
Issue-ID: USECASEUI-819
Change-Id: I63041d772aac1e4591d2f8d71be7f699c25be3a1
Signed-off-by: kaixiliu <liukaixi@chinamobile.com>
27 files changed:
intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/Thread/CreateCallable.java
intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/bean/models/ExpectationObject.java
intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/cllassuranceIntentmgt/CLLAssuranceIntentManagementFunction.java
intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/cllassuranceIntentmgt/cllassurancemodule/CLLAssuranceActuationModule.java
intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/cllassuranceIntentmgt/cllassurancemodule/CLLAssuranceKnowledgeModule.java
intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/clldeliveryIntentmgt/CLLDeliveryIntentManagementFunction.java
intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/clldeliveryIntentmgt/clldeliverymodule/CLLDeliveryActuationModule.java
intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/intentBaseService/IntentManagementFunction.java
intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/mapper/ExpectationObjectMapper.java
intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/mapper/ObjectInstanceMapper.java
intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/service/ObjectInstanceService.java
intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/service/impl/ComponentNotificationServiceImpl.java
intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/service/impl/ExpectationObjectServiceImpl.java
intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/service/impl/ObjectInstanceServiceImpl.java
intentanalysis/src/main/resources/intent-analysis-init.sql
intentanalysis/src/main/resources/mybatis/sql/ExpectationObjectMapper.xml
intentanalysis/src/main/resources/mybatis/sql/ObjectInstanceMapper.xml
intentanalysis/src/test/java/org/onap/usecaseui/intentanalysis/bean/models/ExpectationObjectTest.java
intentanalysis/src/test/java/org/onap/usecaseui/intentanalysis/cllassuranceIntentmgt/cllassurancemodule/CLLAssuranceActuationModuleTest.java
intentanalysis/src/test/java/org/onap/usecaseui/intentanalysis/clldeliveryIntentmgt/clldeliverymodule/CLLDeliveryActuationModuleTest.java
intentanalysis/src/test/java/org/onap/usecaseui/intentanalysis/service/ExpectationObjectServiceTest.java
intentanalysis/src/test/java/org/onap/usecaseui/intentanalysis/service/ExpectationServiceTest.java
intentanalysis/src/test/java/org/onap/usecaseui/intentanalysis/service/IntentServiceTest.java
intentanalysis/src/test/java/org/onap/usecaseui/intentanalysis/service/impl/IntentReportServiceTest.java
intentanalysis/src/test/resources/intent.json
intentanalysis/src/test/resources/intentdb-test-data.sql
intentanalysis/src/test/resources/intentdb-test-init.sql

index 2d548f2..3f029be 100644 (file)
@@ -15,6 +15,7 @@
  */
 package org.onap.usecaseui.intentanalysis.Thread;
 
+import lombok.extern.slf4j.Slf4j;
 import org.onap.usecaseui.intentanalysis.bean.enums.IntentGoalType;
 import org.onap.usecaseui.intentanalysis.bean.models.Intent;
 import org.onap.usecaseui.intentanalysis.bean.models.IntentGoalBean;
@@ -25,6 +26,7 @@ import org.springframework.context.ApplicationContext;
 
 import java.util.concurrent.Callable;
 
+@Slf4j
 public class CreateCallable implements Callable<String> {
     private Intent originalIntent;
     private IntentGoalBean intentGoalBean;
@@ -58,6 +60,7 @@ public class CreateCallable implements Callable<String> {
         String intentStatus = "success";
         IntentCreateEvent intentCreateEvent = new IntentCreateEvent(this, originalIntent, intentGoalBean, handler, intentStatus);
         applicationContext.publishEvent(intentCreateEvent);
+        log.info(intentGoalBean.getIntent().getIntentName() + " Intent operate finished");
         return  intentGoalBean.getIntent().getIntentName() +" Intent operate finished";
     }
 }
index eb4d0a8..a94948c 100644 (file)
 
 package org.onap.usecaseui.intentanalysis.bean.models;
 
-
 import java.util.List;
+
 import lombok.Data;
 import org.onap.usecaseui.intentanalysis.bean.enums.ObjectType;
 
-
 @Data
-
 public class ExpectationObject {
 
     private ObjectType objectType;
 
-    private String objectInstance;
+    private List<String> objectInstance;
 
     private List<Context> objectContexts;
 }
index e2865bf..6135195 100644 (file)
@@ -84,7 +84,6 @@ public class CLLAssuranceIntentManagementFunction extends IntentManagementFuncti
             CreateCallable assuranceCallable = new CreateCallable(originalIntent, intentGoalBean, handler, applicationContext);
             FutureTask<String> futureTask = new FutureTask<>(assuranceCallable);
             executor.submit(futureTask);
-            log.info(futureTask.get());
         } catch (Exception ex) {
             log.error("exception is {}", ex.getMessage());
         }
index 27efe40..1c515c7 100644 (file)
@@ -48,16 +48,18 @@ public class CLLAssuranceActuationModule extends ActuationModule {
     @Override
     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");
-        }
+        List<String> cllIds = getCLLId(intent);
+        cllIds.forEach(cllId -> {
+            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
@@ -94,9 +96,16 @@ public class CLLAssuranceActuationModule extends ActuationModule {
                     log.info("expectationObject is empty,expectationId is {}", deliveryExpectation.getExpectationId());
                     continue;
                 }
-                String objectInstance = expectationObject.getObjectInstance();
-                if (!StringUtils.equalsIgnoreCase(cllId, objectInstance)) {
-                    log.info("cllId and objectInstance are not equal,cllId is {},objectInstance is {}", cllId, objectInstance);
+                List<String> objectInstances = expectationObject.getObjectInstance();
+                String object = "";
+                for (String objectInstance : objectInstances) {
+                    if (StringUtils.equalsIgnoreCase(cllId, objectInstance)) {
+                        object = objectInstance;
+                        break;
+                    }
+                }
+                if (StringUtils.isEmpty(object)) {
+                    log.info("no objectInstance is equal cllId {}", cllId);
                     continue;
                 }
                 List<ExpectationTarget> deliveryTargetList = deliveryExpectation.getExpectationTargets();
@@ -121,7 +130,7 @@ public class CLLAssuranceActuationModule extends ActuationModule {
         return null;
     }
 
-    public String getCLLId(Intent intent) {
+    private List<String> getCLLId(Intent intent) {
         List<Expectation> expectationList = intent.getIntentExpectations();
         for (Expectation expectation : expectationList) {
             if (StringUtils.equalsIgnoreCase("assurance", expectation.getExpectationType().name())) {
index 44fb9f8..899eef9 100644 (file)
  */
 package org.onap.usecaseui.intentanalysis.cllassuranceIntentmgt.cllassurancemodule;
 
-import com.alibaba.fastjson.JSONObject;
 import lombok.extern.log4j.Log4j2;
-import org.apache.commons.collections.CollectionUtils;
-import org.apache.commons.lang.StringUtils;
-import org.onap.usecaseui.intentanalysis.adapters.aai.apicall.AAIAPICall;
-import org.onap.usecaseui.intentanalysis.adapters.aai.apicall.AAIAuthConfig;
 import org.onap.usecaseui.intentanalysis.bean.models.Intent;
 import org.onap.usecaseui.intentanalysis.bean.models.IntentGoalBean;
 import org.onap.usecaseui.intentanalysis.intentBaseService.intentModule.KnowledgeModule;
-import org.onap.usecaseui.intentanalysis.util.RestfulServices;
-import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
-import retrofit2.Response;
-
-import java.io.IOException;
 
 @Log4j2
 @Component
 public class CLLAssuranceKnowledgeModule extends KnowledgeModule {
-    private AAIAPICall aaiapiCall;
-    @Autowired
-    AAIAuthConfig aaiAuthConfig;
-
-    public AAIAPICall getAaiApiCall() {
-        if (null == aaiapiCall) {
-            this.aaiapiCall = RestfulServices.create(AAIAPICall.class,
-                    aaiAuthConfig.getUserName(), aaiAuthConfig.getPassword());
-        }
-        return this.aaiapiCall;
-    }
-
-    public void setAAIApiCall(AAIAPICall aaiApiCall) {
-        this.aaiapiCall = aaiApiCall;
-    }
-
     @Override
     public IntentGoalBean intentCognition(Intent intent) {
         return null;
@@ -69,29 +43,4 @@ public class CLLAssuranceKnowledgeModule extends KnowledgeModule {
     public boolean recieveDeleteIntent() {
         return true;
     }
-
-    /**
-     * healthy check
-     */
-    int getSystemStatus(Intent intent) {
-        try {
-            if (CollectionUtils.isEmpty(intent.getIntentExpectations())) {
-                return -1;
-            }
-            String objectInstance = intent.getIntentExpectations().get(0).getExpectationObject().getObjectInstance();
-            if (StringUtils.isEmpty(objectInstance)){
-                return -1;
-            }
-            Response<JSONObject> response = getAaiApiCall().getInstanceInfo(objectInstance).execute();
-            log.debug(response.toString());
-            if (response.isSuccessful()) {
-                // TODO: 2022/9/20 judge by the return result
-            }
-            log.error("getIntentInstance Create Statue Error:" + response.toString());
-            return -1;
-        } catch (Exception ex) {
-            log.error("Details:" + ex.getMessage());
-            return 0;
-        }
-    }
 }
index 1c5f7af..6286e60 100644 (file)
@@ -83,7 +83,6 @@ public class CLLDeliveryIntentManagementFunction extends IntentManagementFunctio
             CreateCallable deliveryCallable = new CreateCallable(originalIntent, intentGoalBean, handler, applicationContext);
             FutureTask<String> futureTask = new FutureTask<>(deliveryCallable);
             executor.submit(futureTask);
-            log.info(futureTask.get());
         } catch (Exception ex) {
             log.error("exception is {}", ex.getMessage());
         }
index 33d05f9..93b7043 100644 (file)
@@ -34,6 +34,7 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
 import java.util.Arrays;
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -97,7 +98,7 @@ public class CLLDeliveryActuationModule extends ActuationModule {
             updateFulfillment(params, deliveryExpectation.getExpectationId());
 
             // fill and update the objectInstance of intent expectation(include delivery and report)
-            String objectInstance = (String) params.get("name");
+            List<String> objectInstance = Collections.singletonList((String) params.get("name"));
             intent.getIntentExpectations().forEach(expectation -> {
                 ExpectationObject expectationObject = expectationObjectService.getExpectationObject(expectation.getExpectationId());
                 expectationObject.setObjectInstance(objectInstance);
@@ -105,11 +106,11 @@ public class CLLDeliveryActuationModule extends ActuationModule {
                 expectationObjectService.updateExpectationObject(expectationObject, expectation.getExpectationId());
             });
         } else if (StringUtils.equalsIgnoreCase("delete", intentGoalBean.getIntentGoalType().name())) {
-            String instanceId = deliveryExpectation.getExpectationObject().getObjectInstance();
-            soService.deleteIntentInstance(instanceId);
+            List<String> objectInstance = deliveryExpectation.getExpectationObject().getObjectInstance();
+            objectInstance.forEach(instanceId->soService.deleteIntentInstance(instanceId));
         } else {
-            String instanceId = deliveryExpectation.getExpectationObject().getObjectInstance();
-            soService.deleteIntentInstance(instanceId);
+            List<String> objectInstance = deliveryExpectation.getExpectationObject().getObjectInstance();
+            objectInstance.forEach(instanceId->soService.deleteIntentInstance(instanceId));
             intentService.deleteIntent(intent.getIntentId());
         }
     }
@@ -188,7 +189,7 @@ public class CLLDeliveryActuationModule extends ActuationModule {
                     .filter(expectation -> ExpectationType.DELIVERY.equals(expectation.getExpectationType()))
                     .collect(Collectors.toList());
             List<Expectation> originIntentExpectationList = originIntent.getIntentExpectations();
-            String objectInstance = deliveryIntentExpectationList.get(0).getExpectationObject().getObjectInstance();
+            List<String> objectInstance = deliveryIntentExpectationList.get(0).getExpectationObject().getObjectInstance();
             for (Expectation originExpectation : originIntentExpectationList) {
                 ExpectationObject originExpectationObject = originExpectation.getExpectationObject();
                 originExpectationObject.setObjectInstance(objectInstance);
index 65f40cb..c3c152a 100644 (file)
@@ -71,7 +71,7 @@ public class IntentManagementFunction {
     protected void saveFulfillmentAndObjectInstance(String intentId, FulfillmentInfo fulfillmentInfo) {
         // save fulfillmentInfo and objectInstance
         fulfillmentInfoService.saveFulfillmentInfo(intentId, fulfillmentInfo);
-        objectInstanceService.saveObjectInstances(intentId, fulfillmentInfo);
+        objectInstanceService.saveObjectInstances(intentId, fulfillmentInfo.getObjectInstances());
     }
 
     protected void generationIntentReport(IntentGoalBean intentGoalBean) {
index d9df7c4..4881362 100644 (file)
 
 package org.onap.usecaseui.intentanalysis.mapper;
 
-
 import org.apache.ibatis.annotations.Mapper;
 import org.apache.ibatis.annotations.Param;
 import org.onap.usecaseui.intentanalysis.bean.models.ExpectationObject;
 
-import java.util.List;
-
 @Mapper
 public interface ExpectationObjectMapper {
 
@@ -37,8 +34,4 @@ public interface ExpectationObjectMapper {
                                 @Param(value = "expectationId") String expectationId);
 
     int deleteExpectationObject(@Param(value = "expectationId") String expectationId);
-
-    List<String> getExpectationIdByObjectInstance(@Param(value = "objectInstance") String objectInstance);
-
-    List<String> getAllObjectInstances();
 }
index 5331177..6a780ae 100644 (file)
@@ -28,4 +28,8 @@ public interface ObjectInstanceMapper {
     List<String> getObjectInstances(@Param(value = "parentId") String parentId);
 
     int deleteObjectInstances(@Param(value = "parentId") String parentId);
+
+    List<String> queryAllObjectInstances();
+
+    List<String> getParentIdByInstance(@Param(value = "objectInstance") String objectInstance);
 }
index 5925c2d..aaef15a 100644 (file)
@@ -16,8 +16,8 @@
 
 package org.onap.usecaseui.intentanalysis.service;
 
-import org.onap.usecaseui.intentanalysis.bean.models.FulfillmentInfo;
+import java.util.List;
 
 public interface ObjectInstanceService {
-    void saveObjectInstances(String intentId, FulfillmentInfo eventModel);
+    void saveObjectInstances(String parentId, List<String> objectInstance);
 }
index c9de92a..01f32a4 100644 (file)
@@ -25,7 +25,6 @@ import org.onap.usecaseui.intentanalysis.common.ResponseConsts;
 import org.onap.usecaseui.intentanalysis.exception.CommonException;
 import org.onap.usecaseui.intentanalysis.exception.DataBaseException;
 import org.onap.usecaseui.intentanalysis.intentBaseService.IntentManagementFunction;
-import org.onap.usecaseui.intentanalysis.intentBaseService.intentinterfaceservice.IntentInterfaceService;
 import org.onap.usecaseui.intentanalysis.mapper.*;
 import org.onap.usecaseui.intentanalysis.service.ComponentNotificationService;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -39,10 +38,6 @@ import java.util.List;
 @Slf4j
 @Service
 public class ComponentNotificationServiceImpl implements ComponentNotificationService {
-
-    @Autowired
-    private ExpectationObjectMapper expectationObjectMapper;
-
     @Autowired
     private ExpectationMapper expectationMapper;
 
@@ -50,7 +45,7 @@ public class ComponentNotificationServiceImpl implements ComponentNotificationSe
     private ApplicationContext applicationContext;
 
     @Autowired
-    private IntentInterfaceService intentInterfaceService;
+    private ObjectInstanceMapper objectInstanceMapper;
 
     /**
      * Generate a new FulfillmentInfo based on third-party FulfillmentOperation
@@ -72,7 +67,7 @@ public class ComponentNotificationServiceImpl implements ComponentNotificationSe
             throw new CommonException(msg, ResponseConsts.EMPTY_PARAM);
         }
         log.info("Get objectInstances is {}", objectInstances);
-        List<String> expectationIds = expectationObjectMapper.getExpectationIdByObjectInstance(objectInstances.get(0));
+        List<String> expectationIds = objectInstanceMapper.getParentIdByInstance(objectInstances.get(0));
         if (CollectionUtils.isEmpty(expectationIds)) {
             String msg = "Get expectationId is null from database";
             log.error(msg);
@@ -100,7 +95,7 @@ public class ComponentNotificationServiceImpl implements ComponentNotificationSe
         } else {
             function = (IntentManagementFunction) applicationContext.getBean(CLLDeliveryIntentManagementFunction.class.getSimpleName());
         }
-        intentInterfaceService.reportInterface(function, intentId, eventModel);
+        function.createReport(intentId, eventModel);
     }
 
     private ExpectationType getExpectationType(String operation) {
index 2e7db09..b5b8022 100644 (file)
 
 package org.onap.usecaseui.intentanalysis.service.impl;
 
-
-import java.util.ArrayList;
 import java.util.List;
 
 import lombok.extern.slf4j.Slf4j;
 import org.onap.usecaseui.intentanalysis.common.ResponseConsts;
 import org.onap.usecaseui.intentanalysis.exception.DataBaseException;
+import org.onap.usecaseui.intentanalysis.mapper.ObjectInstanceMapper;
+import org.onap.usecaseui.intentanalysis.service.ObjectInstanceService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
-import org.onap.usecaseui.intentanalysis.bean.enums.ContextParentType;
 import org.onap.usecaseui.intentanalysis.bean.models.ExpectationObject;
 import org.onap.usecaseui.intentanalysis.bean.models.Context;
 import org.onap.usecaseui.intentanalysis.mapper.ExpectationObjectMapper;
@@ -33,13 +32,9 @@ import org.onap.usecaseui.intentanalysis.service.ContextService;
 import org.onap.usecaseui.intentanalysis.service.ExpectationObjectService;
 import org.springframework.util.CollectionUtils;
 
-
 @Service
 @Slf4j
 public class ExpectationObjectServiceImpl implements ExpectationObjectService {
-
-    private ContextParentType contextParentType;
-
     @Autowired
     private ExpectationObjectMapper expectationObjectMapper;
 
@@ -49,6 +44,12 @@ public class ExpectationObjectServiceImpl implements ExpectationObjectService {
     @Autowired
     private ContextService contextService;
 
+    @Autowired
+    private ObjectInstanceService objectInstanceService;
+
+    @Autowired
+    private ObjectInstanceMapper objectInstanceMapper;
+
     @Override
     public void createExpectationObject(ExpectationObject expectationObject, String expectationId) {
         if (expectationObjectService.getExpectationObject(expectationId) != null) {
@@ -56,19 +57,33 @@ public class ExpectationObjectServiceImpl implements ExpectationObjectService {
             log.error(msg);
             throw new DataBaseException(msg, ResponseConsts.RET_INSERT_DATA_FAIL);
         }
-        contextService.createContextList(expectationObject.getObjectContexts(),
-                expectationObjectMapper.selectExpectationObjectId(expectationId));
+
+        List<String> objectInstance = expectationObject.getObjectInstance();
+        if (!CollectionUtils.isEmpty(objectInstance)) {
+            objectInstanceService.saveObjectInstances(expectationId, objectInstance);
+        }
+
         if (expectationObjectMapper.insertExpectationObject(expectationObject, expectationId) < 1) {
             String msg = "Failed to create expectation object to database.";
             log.error(msg);
             throw new DataBaseException(msg, ResponseConsts.RET_INSERT_DATA_FAIL);
         }
+
+        String objectId = expectationObjectMapper.selectExpectationObjectId(expectationId);
+        List<Context> objectContexts = expectationObject.getObjectContexts();
+        if(!CollectionUtils.isEmpty(objectContexts)){
+            contextService.createContextList(objectContexts, objectId);
+        }
         log.info("Successfully created expectation object to database.");
     }
 
     @Override
     public ExpectationObject getExpectationObject(String expectationId) {
         ExpectationObject expectationObject = expectationObjectMapper.selectExpectationObject(expectationId);
+        if (expectationObject == null) {
+            log.info("get expectationObject is empty,expectationId is {}", expectationId);
+            return null;
+        }
         String expectationObjectId = expectationObjectMapper.selectExpectationObjectId(expectationId);
         List<Context> contextList = contextService.getContextList(expectationObjectId);
         if (!CollectionUtils.isEmpty(contextList)) {
@@ -76,6 +91,8 @@ public class ExpectationObjectServiceImpl implements ExpectationObjectService {
         } else {
             log.info(String.format("Expectation object is null, expectationObjectId = %s", expectationObjectId));
         }
+        List<String> objectInstances = objectInstanceMapper.getObjectInstances(expectationId);
+        expectationObject.setObjectInstance(objectInstances);
         return expectationObject;
     }
 
@@ -87,8 +104,9 @@ public class ExpectationObjectServiceImpl implements ExpectationObjectService {
         } else if (expectationObject != null && expectationObjectFromDB == null) {
             expectationObjectService.createExpectationObject(expectationObject, expectationId);
         } else if (expectationObject != null) {
-            contextService.updateContextList(expectationObject.getObjectContexts(),
-                    expectationObjectMapper.selectExpectationObjectId(expectationId));
+            String objectId = expectationObjectMapper.selectExpectationObjectId(expectationId);
+            contextService.updateContextList(expectationObject.getObjectContexts(), objectId);
+            objectInstanceService.saveObjectInstances(expectationId, expectationObject.getObjectInstance());
             if (expectationObjectMapper.updateExpectationObject(expectationObject, expectationId) < 1) {
                 String msg = "Failed to update expectation object to database.";
                 log.error(msg);
@@ -103,7 +121,9 @@ public class ExpectationObjectServiceImpl implements ExpectationObjectService {
     public void deleteExpectationObject(String expectationId) {
         ExpectationObject expectationObject = expectationObjectService.getExpectationObject(expectationId);
         if (expectationObject != null) {
-            contextService.deleteContextList(expectationObjectMapper.selectExpectationObjectId(expectationId));
+            String objectId = expectationObjectMapper.selectExpectationObjectId(expectationId);
+            contextService.deleteContextList(objectId);
+            objectInstanceMapper.deleteObjectInstances(expectationId);
             if (expectationObjectMapper.deleteExpectationObject(expectationId) < 1) {
                 String msg = "Failed to update expectation object to database.";
                 log.error(msg);
index 1d60ca5..700964f 100644 (file)
@@ -36,9 +36,9 @@ public class ObjectInstanceServiceImpl implements ObjectInstanceService {
     private ObjectInstanceMapper objectInstanceMapper;
 
     @Override
-    public void saveObjectInstances(String intentId, FulfillmentInfo eventModel) {
-        List<String> instances = new ArrayList<>(eventModel.getObjectInstances());
-        List<String> objectInstancesDb = objectInstanceMapper.getObjectInstances(intentId);
+    public void saveObjectInstances(String parentId, List<String> objectInstance) {
+        List<String> instances = new ArrayList<>(objectInstance);
+        List<String> objectInstancesDb = objectInstanceMapper.getObjectInstances(parentId);
         if (!CollectionUtils.isEmpty(objectInstancesDb)) {
             instances.removeAll(objectInstancesDb);
             if (CollectionUtils.isEmpty(instances)) {
@@ -46,7 +46,7 @@ public class ObjectInstanceServiceImpl implements ObjectInstanceService {
                 return;
             }
         }
-        int objectInstanceNum = objectInstanceMapper.insertObjectInstanceList(instances, intentId);
+        int objectInstanceNum = objectInstanceMapper.insertObjectInstanceList(instances, parentId);
         if (objectInstanceNum < 1) {
             String msg = "Failed to insert objectInstances to database.";
             log.error(msg);
index 00bf2cf..dedb4f4 100644 (file)
@@ -17,7 +17,6 @@ create table if not exists expectation_object(
     object_id varchar(255) DEFAULT uuid_generate_v4 (),
     primary key(object_id),
     object_type varchar(255),
-    object_instance varchar(255),
     expectation_id varchar(255)
 );
 
index 74a0904..21244c2 100644 (file)
@@ -7,14 +7,14 @@
 
     <insert id="insertExpectationObject">
         <if test="expectationObject != null">
-            insert into expectation_object(object_type, object_instance, expectation_id)
+            insert into expectation_object(object_type, expectation_id)
             values
-            (#{expectationObject.objectType}, #{expectationObject.objectInstance}, #{expectationId})
+            (#{expectationObject.objectType}, #{expectationId})
         </if>
     </insert>
 
     <select id="selectExpectationObject" resultType="org.onap.usecaseui.intentanalysis.bean.models.ExpectationObject">
-        select object_type objectType, object_instance objectInstance
+        select object_type objectType
         from expectation_object
         where expectation_id = #{expectationId}
     </select>
@@ -29,7 +29,6 @@
         update expectation_object
         <trim prefix="set" suffixOverrides=",">
             <if test="expectationObject.objectType != null">object_type = #{expectationObject.objectType},</if>
-            <if test="expectationObject.objectInstance != null">object_instance = #{expectationObject.objectInstance},</if>
         </trim>
         where expectation_id = #{expectationId}
     </update>
         delete from expectation_object
         where expectation_id = #{expectationId}
     </delete>
-
-    <select id="getExpectationIdByObjectInstance" resultType="java.lang.String">
-        select expectation_id
-        from expectation_object
-        where object_instance = #{objectInstance}
-    </select>
-
-    <select id="getAllObjectInstances" resultType="java.lang.String">
-        select object_instance
-        from expectation_object
-    </select>
 </mapper>
index cec563c..bf93c95 100644 (file)
         delete from object_instance where parent_id = #{parentId}
     </delete>
 
+    <select id="queryAllObjectInstances" resultType="java.lang.String">
+        select object_instance
+        from object_instance
+    </select>
+
+    <select id="getParentIdByInstance" resultType="java.lang.String">
+        select parent_id from object_instance where object_instance = #{objectInstance}
+    </select>
+
 </mapper>
index 7f9ca6d..3b854f6 100644 (file)
@@ -21,6 +21,7 @@ import org.junit.Test;
 import org.onap.usecaseui.intentanalysis.bean.enums.ObjectType;
 
 import java.util.ArrayList;
+import java.util.Collections;
 
 public class ExpectationObjectTest {
     @Before
@@ -43,7 +44,7 @@ public class ExpectationObjectTest {
     public void testSetExpectationObjectTest() {
         ExpectationObject test = new ExpectationObject();
         test.setObjectType(ObjectType.SLICING);
-        test.setObjectInstance("");
+        test.setObjectInstance(Collections.singletonList(""));
         test.setObjectContexts(new ArrayList<>());
     }
 }
index 95cb3e0..7b1948a 100644 (file)
@@ -34,6 +34,7 @@ import org.springframework.boot.test.context.SpringBootTest;
 import org.springframework.test.context.junit4.SpringRunner;
 
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.List;
 
 import static org.mockito.ArgumentMatchers.any;
@@ -61,7 +62,7 @@ public class CLLAssuranceActuationModuleTest {
         deliveryExpectation.setExpectationName("CLL Delivery Expectation");
         deliveryExpectation.setExpectationType(ExpectationType.DELIVERY);
         ExpectationObject expectationObject = new ExpectationObject();
-        expectationObject.setObjectInstance("");
+        expectationObject.setObjectInstance(Collections.singletonList(""));
         deliveryExpectation.setExpectationObject(expectationObject);
 
         List<ExpectationTarget> targetList = new ArrayList<>();
@@ -85,7 +86,7 @@ public class CLLAssuranceActuationModuleTest {
         Expectation assuranceExceptation = new Expectation();
         assuranceExceptation.setExpectationType(ExpectationType.ASSURANCE);
         ExpectationObject expectationObject2 = new ExpectationObject();
-        expectationObject2.setObjectInstance("");
+        expectationObject2.setObjectInstance(Collections.singletonList(""));
         assuranceExceptation.setExpectationObject(expectationObject2);
         expectationList.add(assuranceExceptation);
         intent.setIntentExpectations(expectationList);
index c88070f..245752a 100644 (file)
@@ -34,6 +34,7 @@ import org.springframework.boot.test.context.SpringBootTest;
 import org.springframework.test.context.junit4.SpringRunner;
 
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.List;
 
 import static org.mockito.ArgumentMatchers.any;
@@ -60,7 +61,7 @@ public class CLLDeliveryActuationModuleTest {
         List<Expectation> expectationList = new ArrayList<>();
         Expectation exp = new Expectation();
         ExpectationObject expectationObject = new ExpectationObject();
-        expectationObject.setObjectInstance("objectInstance");
+        expectationObject.setObjectInstance(Collections.singletonList("objectInstance"));
         exp.setExpectationObject(expectationObject);
         expectationList.add(exp);
         originalIntent.setIntentExpectations(expectationList);
@@ -69,7 +70,7 @@ public class CLLDeliveryActuationModuleTest {
         Expectation deliveryExpectation = new Expectation();
 
         ExpectationObject deliveryExpectationObject = new ExpectationObject();
-        deliveryExpectationObject.setObjectInstance("deliveryObjectInstance");
+        deliveryExpectationObject.setObjectInstance(Collections.singletonList("deliveryObjectInstance"));
 
         deliveryExpectation.setExpectationObject(deliveryExpectationObject);
         deliveryExpectation.setExpectationType(ExpectationType.DELIVERY);
index eb530d5..70ea564 100644 (file)
@@ -19,6 +19,7 @@
 package org.onap.usecaseui.intentanalysis.service;
 
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.List;
 import org.junit.Assert;
 import org.junit.jupiter.api.BeforeEach;
@@ -51,7 +52,7 @@ class ExpectationObjectServiceTest extends AbstractJUnit4SpringContextTests {
     public ExpectationObject createTestObject(String testName) {
         ExpectationObject expectationObject = new ExpectationObject();
         expectationObject.setObjectType(ObjectType.SLICING);
-        expectationObject.setObjectInstance("true");
+        expectationObject.setObjectInstance(Collections.singletonList("true"));
 
         List<Context> contextList = new ArrayList<>();
         Context context = new Context();
index 7539b6c..c4e77e8 100644 (file)
@@ -19,6 +19,7 @@
 package org.onap.usecaseui.intentanalysis.service;
 
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.List;
 import org.junit.Assert;
 import org.junit.jupiter.api.BeforeEach;
@@ -66,7 +67,7 @@ class ExpectationServiceTest extends AbstractJUnit4SpringContextTests {
 
         ExpectationObject object = new ExpectationObject();
         object.setObjectType(ObjectType.valueOf("SLICING"));
-        object.setObjectInstance("objectInstance");
+        object.setObjectInstance(Collections.singletonList("objectInstance"));
 
         Condition targetCondition = new Condition();
         targetCondition.setConditionId(testName + "-conditionId");
index f1003f0..908e7d8 100644 (file)
@@ -16,6 +16,7 @@ package org.onap.usecaseui.intentanalysis.service;
 
 import java.io.IOException;
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.List;
 
 import org.junit.Assert;
@@ -77,7 +78,7 @@ public class IntentServiceTest extends AbstractJUnit4SpringContextTests {
         List<ExpectationTarget> expectationTargetList = new ArrayList<>();
         expectationTargetList.add(target1);
         object1.setObjectType(ObjectType.valueOf("SLICING"));
-        object1.setObjectInstance("objectInstance");
+        object1.setObjectInstance(Collections.singletonList("objectInstance"));
         expectation1.setExpectationId("expectationId");
         expectation1.setExpectationName("expectationName");
         expectation1.setExpectationType(ExpectationType.valueOf("DELIVERY"));
@@ -137,7 +138,7 @@ public class IntentServiceTest extends AbstractJUnit4SpringContextTests {
         Expectation expectation = expectationList.get(0);
         expectation.setExpectationName("new expectation name");
         ExpectationObject expectationObject = expectation.getExpectationObject();
-        expectationObject.setObjectInstance("new object instance");
+        expectationObject.setObjectInstance(Collections.singletonList("new object instance"));
         expectation.setExpectationObject(expectationObject);
         List<ExpectationTarget> expectationTargetList = expectation.getExpectationTargets();
         ExpectationTarget expectationTarget = expectationTargetList.get(0);
index da9c794..d195d7f 100644 (file)
@@ -21,7 +21,7 @@ import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.onap.usecaseui.intentanalysis.IntentAnalysisApplicationTests;
 import org.onap.usecaseui.intentanalysis.bean.models.*;
-import org.onap.usecaseui.intentanalysis.mapper.ExpectationObjectMapper;
+import org.onap.usecaseui.intentanalysis.mapper.ObjectInstanceMapper;
 import org.onap.usecaseui.intentanalysis.service.IntentReportService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.boot.test.context.SpringBootTest;
@@ -41,11 +41,11 @@ public class IntentReportServiceTest {
     ComponentNotificationServiceImpl componentNotificationService;
 
     @Autowired
-    private ExpectationObjectMapper expectationObjectMapper;
+    private ObjectInstanceMapper objectInstanceMapper;
 
     @Test
     public void getIntentReportByIntentIdTest() {
-        List<String> allObjectInstances = expectationObjectMapper.getAllObjectInstances();
+        List<String> allObjectInstances = objectInstanceMapper.queryAllObjectInstances();
         List<String> cll = new ArrayList<>();
         for (String target : allObjectInstances) {
             if (target != null && target.contains("cll")) {
index 66ebb21..3fe6c83 100644 (file)
@@ -8,7 +8,7 @@
                        "expectationType":"DELIVERY",
                        "expectationObject":{
                                "objectType":"CCVPN",
-                               "objectInstance":""
+                               "objectInstance":[]
                        },
                        "expectationTargets":[
                                {
@@ -58,7 +58,7 @@
                        "expectationType":"ASSURANCE",
                        "expectationObject":{
                                "objectType":"CCVPN",
-                               "objectInstance":""
+                               "objectInstance":[]
                        },
                        "expectationTargets":[
                                {
@@ -82,7 +82,7 @@
                        "expectationType":"REPORT",
                        "expectationObject":{
                                "objectType":"CCVPN",
-                               "objectInstance":""
+                               "objectInstance":[]
                        },
                        "expectationTargets":[
                                {
index 1105411..647ecd2 100644 (file)
@@ -44,12 +44,12 @@ values ('expectation without affiliate 2', 'CLL Assurance Expectation', 'ASSURAN
 -- ----------------------------
 -- Records of expectation_object
 -- ----------------------------
-MERGE INTO expectation_object (object_id, object_type, object_instance, expectation_id) KEY (object_id)
-values ('b1bc45a6-f396-4b65-857d-6d2312bfb352', 'SLICING', '', 'expectationId1');
-MERGE INTO expectation_object (object_id, object_type, object_instance, expectation_id) KEY (object_id)
-values ('931a8690-fa61-4c2b-a387-9e0fa6152136', 'CCVPN', '', 'expectationId2');
-MERGE INTO expectation_object (object_id, object_type, object_instance, expectation_id) KEY (object_id)
-values ('3f36bf22-3416-4150-8005-cdc406a43310', 'CCVPN', '', 'expectationId3');
+MERGE INTO expectation_object (object_id, object_type, expectation_id) KEY (object_id)
+values ('b1bc45a6-f396-4b65-857d-6d2312bfb352', 'SLICING', 'expectationId1');
+MERGE INTO expectation_object (object_id, object_type, expectation_id) KEY (object_id)
+values ('931a8690-fa61-4c2b-a387-9e0fa6152136', 'CCVPN', 'expectationId2');
+MERGE INTO expectation_object (object_id, object_type, expectation_id) KEY (object_id)
+values ('3f36bf22-3416-4150-8005-cdc406a43310', 'CCVPN', 'expectationId3');
 
 -- ----------------------------
 -- Records of expectation_target
index 05ea854..3b150d6 100644 (file)
@@ -44,7 +44,6 @@ create table if not exists expectation_object
     object_id       varchar(255) DEFAULT random_uuid(),
     primary key (object_id),
     object_type     varchar(255),
-    object_instance varchar(255),
     expectation_id  varchar(255)
 );