Add the delete objectInstance method 14/134714/1
authorkaixiliu <liukaixi@chinamobile.com>
Tue, 30 May 2023 08:57:39 +0000 (16:57 +0800)
committerkaixiliu <liukaixi@chinamobile.com>
Tue, 30 May 2023 08:58:32 +0000 (16:58 +0800)
Issue-ID: USECASEUI-812
Signed-off-by: kaixiliu <liukaixi@chinamobile.com>
Change-Id: I6e200975c8265ec193babb47323eb932bf1600f1

intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/clldeliveryIntentmgt/clldeliverymodule/CLLDeliveryActuationModule.java
intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/controller/IntentReportController.java
intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/mapper/ObjectInstanceMapper.java
intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/service/IntentReportService.java
intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/service/impl/ComponentNotificationServiceImpl.java
intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/service/impl/IntentReportServiceImpl.java
intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/service/impl/IntentServiceImpl.java
intentanalysis/src/main/resources/mybatis/sql/ObjectInstanceMapper.xml
intentanalysis/src/test/java/org/onap/usecaseui/intentanalysis/service/impl/IntentReportServiceTest.java

index 592c1b1..dc63ba5 100644 (file)
@@ -114,6 +114,7 @@ public class CLLDeliveryActuationModule extends ActuationModule {
 
             ExpectationObject expectationObject = expectationObjectService.getExpectationObject(expectationId);
             expectationObject.setObjectInstance((String) params.get("name"));
+            intent.getIntentExpectations().get(0).getExpectationObject().setObjectInstance((String) params.get("name"));
             expectationObjectService.updateExpectationObject(expectationObject, expectationId);
         } else if (StringUtils.equalsIgnoreCase("delete", intentGoalBean.getIntentGoalType().name())) {
             String instanceId = intent.getIntentExpectations().get(0).getExpectationObject().getObjectInstance();
index 87ac149..d4066b6 100644 (file)
@@ -22,8 +22,6 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.http.MediaType;
 import org.springframework.web.bind.annotation.*;
 
-import static org.onap.usecaseui.intentanalysis.common.ResponseConsts.RSEPONSE_SUCCESS;
-
 @Log4j2
 @RestController
 @RequestMapping("/intentReport")
@@ -34,8 +32,6 @@ public class IntentReportController {
     @GetMapping(value = "/{intentId}", produces = MediaType.APPLICATION_JSON_VALUE)
     public ServiceResult getIntentById(
             @PathVariable("intentId") String intentId) {
-        IntentReport report = intentReportService.getIntentReportByIntentId(intentId);
-        return new ServiceResult(new ResultHeader(RSEPONSE_SUCCESS, "get report success"),
-                report);
+        return intentReportService.getIntentReportByIntentId(intentId);
     }
 }
index abd207d..5331177 100644 (file)
@@ -26,4 +26,6 @@ public interface ObjectInstanceMapper {
                                  @Param(value = "parentId") String parentId);
 
     List<String> getObjectInstances(@Param(value = "parentId") String parentId);
+
+    int deleteObjectInstances(@Param(value = "parentId") String parentId);
 }
index 97e90d1..63b5d51 100644 (file)
 
 package org.onap.usecaseui.intentanalysis.service;
 
-import org.onap.usecaseui.intentanalysis.bean.models.IntentReport;
+import org.onap.usecaseui.intentanalysis.bean.models.ServiceResult;
 
 public interface IntentReportService {
-    IntentReport getIntentReportByIntentId(String intentId);
+    ServiceResult getIntentReportByIntentId(String intentId);
 
     void saveIntentReportByIntentId(String intentId);
 }
index 43d6082..608423e 100644 (file)
@@ -116,7 +116,16 @@ public class ComponentNotificationServiceImpl implements ComponentNotificationSe
             log.error(msg);
             throw new DataBaseException(msg, ResponseConsts.RET_INSERT_DATA_FAIL);
         }
-        int objectInstanceNum = objectInstanceMapper.insertObjectInstanceList(eventModel.getObjectInstances(), intentId);
+        List<String> instances = eventModel.getObjectInstances();
+        List<String> objectInstancesDb = objectInstanceMapper.getObjectInstances(intentId);
+        if (!CollectionUtils.isEmpty(objectInstancesDb)) {
+            instances.removeAll(objectInstancesDb);
+            if (CollectionUtils.isEmpty(instances)) {
+                log.info("The objectInstances already exist in the database");
+                return;
+            }
+        }
+        int objectInstanceNum = objectInstanceMapper.insertObjectInstanceList(instances, intentId);
         if (objectInstanceNum < 1) {
             String msg = "Failed to insert objectInstances to database.";
             log.error(msg);
index d3e914b..c443f9e 100644 (file)
@@ -19,6 +19,8 @@ package org.onap.usecaseui.intentanalysis.service.impl;
 import lombok.extern.slf4j.Slf4j;
 import org.onap.usecaseui.intentanalysis.bean.models.FulfillmentInfo;
 import org.onap.usecaseui.intentanalysis.bean.models.IntentReport;
+import org.onap.usecaseui.intentanalysis.bean.models.ResultHeader;
+import org.onap.usecaseui.intentanalysis.bean.models.ServiceResult;
 import org.onap.usecaseui.intentanalysis.common.ResponseConsts;
 import org.onap.usecaseui.intentanalysis.exception.DataBaseException;
 import org.onap.usecaseui.intentanalysis.mapper.IntentReportFulfillmentInfoMapper;
@@ -34,6 +36,9 @@ import org.springframework.util.CollectionUtils;
 
 import java.util.Collections;
 import java.util.List;
+import java.util.stream.Collectors;
+
+import static org.onap.usecaseui.intentanalysis.common.ResponseConsts.RSEPONSE_SUCCESS;
 
 @Service
 @Slf4j
@@ -53,8 +58,13 @@ public class IntentReportServiceImpl implements IntentReportService {
 
     @Override
     @Transactional(rollbackFor = DataBaseException.class)
-    public IntentReport getIntentReportByIntentId(String intentId) {
+    public ServiceResult getIntentReportByIntentId(String intentId) {
         FulfillmentInfo fulfillmentInfo = getFulfillmentInfo(intentId);
+
+        if (fulfillmentInfo == null) {
+            return new ServiceResult(new ResultHeader(RSEPONSE_SUCCESS, "The intent has not fulfillmentInfo"),
+                    new IntentReport());
+        }
         fulfillmentInfo.setObjectInstances(getInstances(intentId));
         IntentReport intentReport = new IntentReport();
         intentReport.setIntentReportId(CommonUtil.getUUid());
@@ -63,7 +73,8 @@ public class IntentReportServiceImpl implements IntentReportService {
         intentReport.setReportTime(CommonUtil.getTime());
 
         saveIntentReport(intentReport, fulfillmentInfo);
-        return intentReport;
+        return new ServiceResult(new ResultHeader(RSEPONSE_SUCCESS, "Get report success"),
+                intentReport);
     }
 
     @Override
@@ -86,8 +97,6 @@ public class IntentReportServiceImpl implements IntentReportService {
         log.info("fulfillmentInfo is {}", fulfillmentInfo);
         if (fulfillmentInfo == null) {
             log.error("get fulfillmentInfo is failed,intentId is {}", intentId);
-            String msg = "get fulfillmentInfo is empty, please enter the right intentId";
-            throw new DataBaseException(msg, ResponseConsts.RET_QUERY_DATA_EMPTY);
         }
         return fulfillmentInfo;
     }
@@ -96,10 +105,8 @@ public class IntentReportServiceImpl implements IntentReportService {
         List<String> objectInstances = objectInstanceMapper.getObjectInstances(intentId);
         if (CollectionUtils.isEmpty(objectInstances)) {
             log.error("get objectInstance is failed,intentId is {}", intentId);
-            String msg = "get objectInstance is failed";
-            throw new DataBaseException(msg, ResponseConsts.RET_QUERY_DATA_EMPTY);
         }
-        return objectInstances;
+        return objectInstances.stream().distinct().collect(Collectors.toList());
     }
 
     private void saveIntentReport(IntentReport intentReport, FulfillmentInfo fulfillmentInfo) {
index 10fd059..66d3f02 100644 (file)
@@ -26,6 +26,7 @@ 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.onap.usecaseui.intentanalysis.mapper.ObjectInstanceMapper;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
@@ -61,6 +62,9 @@ public class IntentServiceImpl implements IntentService {
     @Autowired
     private IntentService intentService;
 
+    @Autowired
+    private ObjectInstanceMapper objectInstanceMapper;
+
     @Transactional(rollbackFor = RuntimeException.class)
     @Override
     public Intent createIntent(Intent intent) {
@@ -133,6 +137,7 @@ public class IntentServiceImpl implements IntentService {
         fulfillmentInfoService.deleteFulfillmentInfo(intentId);
         contextService.deleteContextList(intentId);
         expectationService.deleteIntentExpectationList(intentId);
+        objectInstanceMapper.deleteObjectInstances(intentId);
         if (intentMapper.deleteIntent(intentId) < 1) {
             String msg = "Failed to delete intent to database.";
             log.error(msg);
index 8cf9b3c..63047ce 100644 (file)
     </insert>
 
     <select id="getObjectInstances" resultType="java.lang.String">
-        select object_instance from object_instance where parent_id = #{parentId}
+        select object_instance  from object_instance where parent_id = #{parentId}
     </select>
+
+    <delete id="deleteObjectInstances">
+        delete from object_instance where parent_id = #{parentId}
+    </delete>
+
 </mapper>
index a2c3dd9..da9c794 100644 (file)
@@ -56,7 +56,7 @@ public class IntentReportServiceTest {
         fulfillmentOperation.setObjectInstances(Collections.singletonList(cll.get(0)));
         fulfillmentOperation.setOperation("delivery");
         componentNotificationService.callBack(fulfillmentOperation);
-        IntentReport report = intentReportService.getIntentReportByIntentId("testIntentId111");
+        ServiceResult report = intentReportService.getIntentReportByIntentId("testIntentId111");
         Assert.assertNotNull(report);
     }
 }