diff options
author | kaixiliu <liukaixi@chinamobile.com> | 2023-05-30 16:57:39 +0800 |
---|---|---|
committer | kaixiliu <liukaixi@chinamobile.com> | 2023-05-30 16:58:32 +0800 |
commit | 09cd2f9f50b3ecde778e7d5ba4e243bbad74eef2 (patch) | |
tree | 14aed23ccf4393e749c0db1457ecb3ac576275aa /intentanalysis/src/main | |
parent | f89877a479fd7c4ca1257f4137bd1132bbf0e631 (diff) |
Add the delete objectInstance method
Issue-ID: USECASEUI-812
Signed-off-by: kaixiliu <liukaixi@chinamobile.com>
Change-Id: I6e200975c8265ec193babb47323eb932bf1600f1
Diffstat (limited to 'intentanalysis/src/main')
8 files changed, 41 insertions, 16 deletions
diff --git a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/clldeliveryIntentmgt/clldeliverymodule/CLLDeliveryActuationModule.java b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/clldeliveryIntentmgt/clldeliverymodule/CLLDeliveryActuationModule.java index 592c1b1..dc63ba5 100644 --- a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/clldeliveryIntentmgt/clldeliverymodule/CLLDeliveryActuationModule.java +++ b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/clldeliveryIntentmgt/clldeliverymodule/CLLDeliveryActuationModule.java @@ -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(); diff --git a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/controller/IntentReportController.java b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/controller/IntentReportController.java index 87ac149..d4066b6 100644 --- a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/controller/IntentReportController.java +++ b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/controller/IntentReportController.java @@ -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); } } diff --git a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/mapper/ObjectInstanceMapper.java b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/mapper/ObjectInstanceMapper.java index abd207d..5331177 100644 --- a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/mapper/ObjectInstanceMapper.java +++ b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/mapper/ObjectInstanceMapper.java @@ -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); } diff --git a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/service/IntentReportService.java b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/service/IntentReportService.java index 97e90d1..63b5d51 100644 --- a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/service/IntentReportService.java +++ b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/service/IntentReportService.java @@ -16,10 +16,10 @@ 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); } diff --git a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/service/impl/ComponentNotificationServiceImpl.java b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/service/impl/ComponentNotificationServiceImpl.java index 43d6082..608423e 100644 --- a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/service/impl/ComponentNotificationServiceImpl.java +++ b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/service/impl/ComponentNotificationServiceImpl.java @@ -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); diff --git a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/service/impl/IntentReportServiceImpl.java b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/service/impl/IntentReportServiceImpl.java index d3e914b..c443f9e 100644 --- a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/service/impl/IntentReportServiceImpl.java +++ b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/service/impl/IntentReportServiceImpl.java @@ -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) { diff --git a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/service/impl/IntentServiceImpl.java b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/service/impl/IntentServiceImpl.java index 10fd059..66d3f02 100644 --- a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/service/impl/IntentServiceImpl.java +++ b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/service/impl/IntentServiceImpl.java @@ -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); diff --git a/intentanalysis/src/main/resources/mybatis/sql/ObjectInstanceMapper.xml b/intentanalysis/src/main/resources/mybatis/sql/ObjectInstanceMapper.xml index 8cf9b3c..63047ce 100644 --- a/intentanalysis/src/main/resources/mybatis/sql/ObjectInstanceMapper.xml +++ b/intentanalysis/src/main/resources/mybatis/sql/ObjectInstanceMapper.xml @@ -13,6 +13,11 @@ </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> |