diff options
Diffstat (limited to 'intentanalysis')
21 files changed, 468 insertions, 22 deletions
diff --git a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/cllassuranceIntentmgt/CLLAssuranceIntentManagementFunction.java b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/cllassuranceIntentmgt/CLLAssuranceIntentManagementFunction.java index c78ce5b..d47e67b 100644 --- a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/cllassuranceIntentmgt/CLLAssuranceIntentManagementFunction.java +++ b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/cllassuranceIntentmgt/CLLAssuranceIntentManagementFunction.java @@ -70,8 +70,9 @@ 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) { - ex.printStackTrace(); + log.error("exception is {}", ex.getMessage()); } } diff --git a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/cllassuranceIntentmgt/cllassurancemodule/CLLAssuranceActuationModule.java b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/cllassuranceIntentmgt/cllassurancemodule/CLLAssuranceActuationModule.java index 2c7c7a3..7a22226 100644 --- a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/cllassuranceIntentmgt/cllassurancemodule/CLLAssuranceActuationModule.java +++ b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/cllassuranceIntentmgt/cllassurancemodule/CLLAssuranceActuationModule.java @@ -26,8 +26,10 @@ 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 org.springframework.util.CollectionUtils; import java.util.List; +import java.util.stream.Collectors; @Slf4j @Component public class CLLAssuranceActuationModule extends ActuationModule { @@ -75,22 +77,44 @@ public class CLLAssuranceActuationModule extends ActuationModule { private String getBandwidth(String cllId) { List<Intent> deliveryIntentList = intentService.getIntentByName("CLL Delivery Intent"); + if (CollectionUtils.isEmpty(deliveryIntentList)) { + log.info("get CLL Delivery Intent from the database is empty"); + return null; + } for (Intent deliveryIntent : deliveryIntentList) { List<Expectation> deliveryExpectationList = deliveryIntent.getIntentExpectations(); + if (CollectionUtils.isEmpty(deliveryExpectationList)) { + log.info("expectation is empty,intentId is {}", deliveryIntent.getIntentId()); + continue; + } 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(); - } - } - } - } + ExpectationObject expectationObject = deliveryExpectation.getExpectationObject(); + if (expectationObject == null) { + 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); + continue; + } + List<ExpectationTarget> deliveryTargetList = deliveryExpectation.getExpectationTargets(); + List<ExpectationTarget> bandwidth = deliveryTargetList.stream() + .filter(target -> StringUtils.equalsIgnoreCase("bandwidth", target.getTargetName())) + .collect(Collectors.toList()); + if (CollectionUtils.isEmpty(bandwidth)) { + log.info("bandwidth target is empty,expectation is {}", deliveryExpectation.getExpectationId()); + continue; + } + List<Condition> deliveryConditionList = bandwidth.get(0).getTargetConditions(); + List<Condition> collect = deliveryConditionList.stream() + .filter(condition -> StringUtils.equalsIgnoreCase("condition of the cll service bandwidth", condition.getConditionName())) + .collect(Collectors.toList()); + if (CollectionUtils.isEmpty(collect)) { + log.info("condition of the cll service bandwidth is empty,targetId is {}", bandwidth.get(0).getTargetId()); + continue; } + return collect.get(0).getConditionValue(); } } return null; diff --git a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/clldeliveryIntentmgt/CLLDeliveryIntentManagementFunction.java b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/clldeliveryIntentmgt/CLLDeliveryIntentManagementFunction.java index 936076e..d4e3c80 100644 --- a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/clldeliveryIntentmgt/CLLDeliveryIntentManagementFunction.java +++ b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/clldeliveryIntentmgt/CLLDeliveryIntentManagementFunction.java @@ -69,8 +69,9 @@ 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) { - ex.printStackTrace(); + log.error("exception is {}", ex.getMessage()); } } } 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 b64dd9a..c090b4d 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 @@ -112,6 +112,9 @@ public class CLLDeliveryActuationModule extends ActuationModule { ExpectationObject expectationObject = expectationObjectService.getExpectationObject(expectationId); expectationObject.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(); + soService.deleteIntentInstance(instanceId); } else { String instanceId = intent.getIntentExpectations().get(0).getExpectationObject().getObjectInstance(); soService.deleteIntentInstance(instanceId); diff --git a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/common/ResponseConsts.java b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/common/ResponseConsts.java index 1a53be5..59b1741 100644 --- a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/common/ResponseConsts.java +++ b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/common/ResponseConsts.java @@ -53,4 +53,9 @@ public final class ResponseConsts { * response error */ public static final int RESPONSE_ERROR = 500; + + /** + * empty param + */ + public static final int EMPTY_PARAM = 10006; } diff --git a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/mapper/ExpectationMapper.java b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/mapper/ExpectationMapper.java index 076d815..93efb39 100644 --- a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/mapper/ExpectationMapper.java +++ b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/mapper/ExpectationMapper.java @@ -20,6 +20,7 @@ package org.onap.usecaseui.intentanalysis.mapper; import java.util.List; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; +import org.onap.usecaseui.intentanalysis.bean.enums.ExpectationType; import org.onap.usecaseui.intentanalysis.bean.models.Expectation; @@ -41,4 +42,7 @@ public interface ExpectationMapper { List<Expectation> selectIntentExpectationList(@Param(value = "intentId") String intentId); Expectation selectIntentExpectation(@Param(value = "expectationId") String expectationId); + + String getIntentIdByExpectationId(@Param(value = "expectationId") String expectationId, + @Param(value = "expectationType") ExpectationType expectationType); } diff --git a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/mapper/ExpectationObjectMapper.java b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/mapper/ExpectationObjectMapper.java index 563a5b3..d9df7c4 100644 --- a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/mapper/ExpectationObjectMapper.java +++ b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/mapper/ExpectationObjectMapper.java @@ -21,6 +21,7 @@ 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 { @@ -36,4 +37,8 @@ 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(); } diff --git a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/mapper/IntentReportFulfillmentInfoMapper.java b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/mapper/IntentReportFulfillmentInfoMapper.java new file mode 100644 index 0000000..70ab632 --- /dev/null +++ b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/mapper/IntentReportFulfillmentInfoMapper.java @@ -0,0 +1,26 @@ +/* + * Copyright (C) 2023 CMCC, Inc. and others. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +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.FulfillmentInfo; + +@Mapper +public interface IntentReportFulfillmentInfoMapper { + int insertIntentReportFulfillment(@Param(value = "fulfillmentInfo") FulfillmentInfo fulfillmentInfo,@Param(value = "parentId") String parentId); +} diff --git a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/mapper/IntentReportMapper.java b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/mapper/IntentReportMapper.java new file mode 100644 index 0000000..99ce7fe --- /dev/null +++ b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/mapper/IntentReportMapper.java @@ -0,0 +1,25 @@ +/* + * Copyright (C) 2023 CMCC, Inc. and others. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +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.IntentReport; + +@Mapper +public interface IntentReportMapper { + int insertIntentReport(@Param(value = "intentReport") IntentReport intentReport); +} 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 new file mode 100644 index 0000000..abd207d --- /dev/null +++ b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/mapper/ObjectInstanceMapper.java @@ -0,0 +1,29 @@ +/* + * Copyright (C) 2023 CMCC, Inc. and others. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onap.usecaseui.intentanalysis.mapper; + +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.List; + +@Mapper +public interface ObjectInstanceMapper { + int insertObjectInstanceList(@Param(value = "objectInstances") List<String> objectInstances, + @Param(value = "parentId") String parentId); + + List<String> getObjectInstances(@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 new file mode 100644 index 0000000..5e8d158 --- /dev/null +++ b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/service/IntentReportService.java @@ -0,0 +1,23 @@ +/* + * Copyright (C) 2023 CMCC, Inc. and others. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.usecaseui.intentanalysis.service; + +import org.onap.usecaseui.intentanalysis.bean.models.IntentReport; + +public interface IntentReportService { + IntentReport getIntentReportByIntentId(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 59c4f45..27d7bb4 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 @@ -16,22 +16,144 @@ package org.onap.usecaseui.intentanalysis.service.impl; import lombok.extern.slf4j.Slf4j; -import org.onap.usecaseui.intentanalysis.bean.models.FulfillmentOperation; +import org.apache.commons.lang.StringUtils; +import org.onap.usecaseui.intentanalysis.bean.enums.ExpectationType; +import org.onap.usecaseui.intentanalysis.bean.models.*; +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.mapper.*; import org.onap.usecaseui.intentanalysis.service.ComponentNotificationService; +import org.springframework.beans.BeanUtils; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import org.springframework.util.CollectionUtils; + +import java.util.List; +import java.util.stream.Collectors; @Slf4j @Service public class ComponentNotificationServiceImpl implements ComponentNotificationService { + @Autowired + private ExpectationObjectMapper expectationObjectMapper; + + @Autowired + private ExpectationMapper expectationMapper; + + @Autowired + private ContextMapper contextMapper; + + @Autowired + private ConditionMapper conditionMapper; + + @Autowired + private FulfillmentInfoMapper fulfillmentInfoMapper; + + @Autowired + private ObjectInstanceMapper objectInstanceMapper; + /** * Generate a new FulfillmentInfo based on third-party FulfillmentOperation * and save it in the database * - * @param eventModel + * @param eventModel param */ @Override public void callBack(FulfillmentOperation eventModel) { - log.info("callBack begin"); + if (eventModel == null) { + String msg = "The obtained fulfillmentInfo is null"; + throw new CommonException(msg, ResponseConsts.EMPTY_PARAM); + } + String operation = eventModel.getOperation(); + List<String> objectInstances = eventModel.getObjectInstances(); + if (CollectionUtils.isEmpty(objectInstances) || StringUtils.isEmpty(operation)) { + String msg = "The obtained objectInstances or operation are empty"; + throw new CommonException(msg, ResponseConsts.EMPTY_PARAM); + } + log.info("Get objectInstances is {}", objectInstances); + List<String> expectationIds = expectationObjectMapper.getExpectationIdByObjectInstance(objectInstances.get(0)); + if (CollectionUtils.isEmpty(expectationIds)) { + String msg = "Get expectationId is null from database"; + log.error(msg); + return; + } + log.info("ExpectationId is {}", expectationIds); + String intentId = null; + for (String expectationId : expectationIds) { + // TODO + ExpectationType expectationType = getExpectationType(operation); + intentId = expectationMapper.getIntentIdByExpectationId(expectationId, expectationType); + if (StringUtils.isNotEmpty(intentId)) { + break; + } + } + log.error("The intentId is {}", intentId); + + if (StringUtils.isEmpty(intentId)) { + String msg = "Get intentId is null from database"; + log.error(msg); + throw new DataBaseException(msg, ResponseConsts.RET_QUERY_DATA_EMPTY); + } + + String parentByIntentId = findParentByIntentId(findParentByIntentId(intentId)); + log.info("The parentByIntentId is {}", parentByIntentId); + + saveFulfillmentInfo(parentByIntentId, eventModel); + } + + private void saveFulfillmentInfo(String intentId, FulfillmentOperation eventModel) { + FulfillmentInfo fulfillmentInfo = fulfillmentInfoMapper.selectFulfillmentInfo(intentId); + if (fulfillmentInfo != null) { + fulfillmentInfoMapper.deleteFulfillmentInfo(intentId); + } + FulfillmentInfo newInfo = new FulfillmentInfo(); + BeanUtils.copyProperties(eventModel, newInfo); + int num = fulfillmentInfoMapper.insertFulfillmentInfo(newInfo, intentId); + FulfillmentInfo fulfillmentInfo1 = fulfillmentInfoMapper.selectFulfillmentInfo(intentId); + if (num < 1) { + String msg = "Failed to insert fulfillmentInfo to database."; + log.error(msg); + throw new DataBaseException(msg, ResponseConsts.RET_INSERT_DATA_FAIL); + } + int objectInstanceNum = objectInstanceMapper.insertObjectInstanceList(eventModel.getObjectInstances(), intentId); + if (objectInstanceNum < 1) { + String msg = "Failed to insert objectInstances to database."; + log.error(msg); + throw new DataBaseException(msg, ResponseConsts.RET_INSERT_DATA_FAIL); + } + } + + public String findParentByIntentId(String intentId) { + List<Context> contexts = contextMapper.selectContextList(intentId); + if (CollectionUtils.isEmpty(contexts)) { + log.error("Get context is empty,intentId is {}", intentId); + String msg = "Get Contexts is empty from database"; + throw new DataBaseException(msg, ResponseConsts.RET_QUERY_DATA_EMPTY); + } + List<Context> collect = contexts.stream() + .filter(context -> "parentIntent info".equalsIgnoreCase(context.getContextName())) + .collect(Collectors.toList()); + if (CollectionUtils.isEmpty(collect) || collect.size() != 1) { + log.error("This intent has not parent intent,intentId is {}", intentId); + String msg = "Get Context is empty from database"; + throw new DataBaseException(msg, ResponseConsts.RET_QUERY_DATA_EMPTY); + } + Context context = collect.get(0); + List<Condition> conditions = conditionMapper.selectConditionList(context.getContextId()); + if (CollectionUtils.isEmpty(conditions) || StringUtils.isEmpty(conditions.get(0).getConditionValue())) { + log.error(""); + String msg = "Get conditions is empty from database"; + throw new DataBaseException(msg, ResponseConsts.RET_QUERY_DATA_EMPTY); + } + return conditions.get(0).getConditionValue(); + } + + private ExpectationType getExpectationType(String operation) { + if (operation.contains("Assurance")) { + return ExpectationType.ASSURANCE; + } + return ExpectationType.DELIVERY; } } 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 new file mode 100644 index 0000000..6ea3e06 --- /dev/null +++ b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/service/impl/IntentReportServiceImpl.java @@ -0,0 +1,91 @@ +/* + * Copyright (C) 2023 CMCC, Inc. and others. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +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.common.ResponseConsts; +import org.onap.usecaseui.intentanalysis.exception.DataBaseException; +import org.onap.usecaseui.intentanalysis.mapper.IntentReportFulfillmentInfoMapper; +import org.onap.usecaseui.intentanalysis.mapper.IntentReportMapper; +import org.onap.usecaseui.intentanalysis.mapper.ObjectInstanceMapper; +import org.onap.usecaseui.intentanalysis.service.FulfillmentInfoService; +import org.onap.usecaseui.intentanalysis.service.IntentReportService; +import org.onap.usecaseui.intentanalysis.util.CommonUtil; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.util.CollectionUtils; + +import java.util.Collections; +import java.util.List; + +@Service +@Slf4j +public class IntentReportServiceImpl implements IntentReportService { + + @Autowired + private FulfillmentInfoService fulfillmentInfoService; + + @Autowired + private ObjectInstanceMapper objectInstanceMapper; + + @Autowired + private IntentReportFulfillmentInfoMapper intentReportFulfillmentInfoMapper; + + @Autowired + private IntentReportMapper intentReportMapper; + + @Override + public IntentReport getIntentReportByIntentId(String intentId) { + FulfillmentInfo fulfillmentInfo = fulfillmentInfoService.getFulfillmentInfo(intentId); + System.out.println(fulfillmentInfo); + if (fulfillmentInfo == null) { + log.error("get fulfillmentInfo is failed,intentId is {}", intentId); + String msg = "get fulfillmentInfo is failed"; + throw new DataBaseException(msg, ResponseConsts.RET_QUERY_DATA_EMPTY); + } + fulfillmentInfo.setFulfillmentId(intentId); + 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); + } + String uUid = CommonUtil.getUUid(); + fulfillmentInfo.setObjectInstances(objectInstances); + IntentReport intentReport = new IntentReport(); + intentReport.setIntentReportId(uUid); + intentReport.setIntentReference("intentReference"); + intentReport.setFulfillmentInfos(Collections.singletonList(fulfillmentInfo)); + intentReport.setReportTime(CommonUtil.getTime()); + + int num = intentReportMapper.insertIntentReport(intentReport); + if (num < 1) { + String msg = "Failed to insert intent report to database."; + log.error(msg); + throw new DataBaseException(msg, ResponseConsts.RET_INSERT_DATA_FAIL); + } + int fulfillmentNum = intentReportFulfillmentInfoMapper.insertIntentReportFulfillment(fulfillmentInfo, uUid); + if (fulfillmentNum < 1) { + String msg = "Failed to insert fulfillmentInfo to database."; + log.error(msg); + throw new DataBaseException(msg, ResponseConsts.RET_INSERT_DATA_FAIL); + } + return intentReport; + } +} diff --git a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/util/CommonUtil.java b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/util/CommonUtil.java index 260115a..5111123 100644 --- a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/util/CommonUtil.java +++ b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/util/CommonUtil.java @@ -15,10 +15,19 @@ */ package org.onap.usecaseui.intentanalysis.util; +import java.text.SimpleDateFormat; +import java.util.Date; import java.util.UUID; public class CommonUtil { public static String getUUid() { return UUID.randomUUID().toString().trim().replaceAll("-", ""); } + + public static String getTime() { + Date date = new Date(); + SimpleDateFormat dateFormat = new SimpleDateFormat("yyy-MM-dd HH:mm:ss"); + String format = dateFormat.format(date); + return format; + } } diff --git a/intentanalysis/src/main/resources/mybatis/sql/ExpectationMapper.xml b/intentanalysis/src/main/resources/mybatis/sql/ExpectationMapper.xml index e6a3b26..e97c915 100644 --- a/intentanalysis/src/main/resources/mybatis/sql/ExpectationMapper.xml +++ b/intentanalysis/src/main/resources/mybatis/sql/ExpectationMapper.xml @@ -53,4 +53,10 @@ where expectation_id = #{expectationId} </delete> + <select id="getIntentIdByExpectationId" resultType="java.lang.String"> + select intent_id + from expectation + where expectation_id = #{expectationId} + and expectation_type = #{expectationType} + </select> </mapper> diff --git a/intentanalysis/src/main/resources/mybatis/sql/ExpectationObjectMapper.xml b/intentanalysis/src/main/resources/mybatis/sql/ExpectationObjectMapper.xml index 1c8b513..74a0904 100644 --- a/intentanalysis/src/main/resources/mybatis/sql/ExpectationObjectMapper.xml +++ b/intentanalysis/src/main/resources/mybatis/sql/ExpectationObjectMapper.xml @@ -38,4 +38,15 @@ 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> diff --git a/intentanalysis/src/main/resources/mybatis/sql/FulfillmentInfoMapper.xml b/intentanalysis/src/main/resources/mybatis/sql/FulfillmentInfoMapper.xml index 5aa65c5..5ae998d 100644 --- a/intentanalysis/src/main/resources/mybatis/sql/FulfillmentInfoMapper.xml +++ b/intentanalysis/src/main/resources/mybatis/sql/FulfillmentInfoMapper.xml @@ -6,13 +6,13 @@ <insert id="insertFulfillmentInfo"> - insert into fulfillment_info(fulfillment_info_id, fulfillment_info_status, not_fulfilled_state, not_fulfilled_reason) - values (#{parentId}, #{fulfillmentInfo.fulfillmentStatus}, #{fulfillmentInfo.notFulfilledState}, #{fulfillmentInfo.notFulfilledReason}) + insert into fulfillment_info(fulfillment_info_id, fulfillment_info_status, not_fulfilled_state, not_fulfilled_reason,achieve_value) + values (#{parentId}, #{fulfillmentInfo.fulfillmentStatus}, #{fulfillmentInfo.notFulfilledState}, #{fulfillmentInfo.notFulfilledReason},#{fulfillmentInfo.achieveValue}) </insert> <select id="selectFulfillmentInfo" resultType="org.onap.usecaseui.intentanalysis.bean.models.FulfillmentInfo"> - select fulfillment_info_status fulfillmentStatus, not_fulfilled_state notFulfilledState, - not_fulfilled_reason notFulfilledReason + select fulfillment_info_id fulfillmentId, fulfillment_info_status fulfillmentStatus, not_fulfilled_state notFulfilledState, + not_fulfilled_reason notFulfilledReason, achieve_value achieveValue from fulfillment_info where fulfillment_info_id = #{parentId} </select> diff --git a/intentanalysis/src/main/resources/mybatis/sql/IntentReportFulfillmentInfoMapper.xml b/intentanalysis/src/main/resources/mybatis/sql/IntentReportFulfillmentInfoMapper.xml new file mode 100644 index 0000000..bfe413e --- /dev/null +++ b/intentanalysis/src/main/resources/mybatis/sql/IntentReportFulfillmentInfoMapper.xml @@ -0,0 +1,11 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<!DOCTYPE mapper + PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> +<mapper namespace="org.onap.usecaseui.intentanalysis.mapper.IntentReportFulfillmentInfoMapper"> + + <insert id="insertIntentReportFulfillment"> + insert into intent_report_fulfillment_info(parent_id,fulfillment_info_id, fulfillment_info_status, not_fulfilled_state, not_fulfilled_reason,achieve_value) + values (#{parentId},#{fulfillmentInfo.fulfillmentId}, #{fulfillmentInfo.fulfillmentStatus}, #{fulfillmentInfo.notFulfilledState}, #{fulfillmentInfo.notFulfilledReason},#{fulfillmentInfo.achieveValue}) + </insert> +</mapper> diff --git a/intentanalysis/src/main/resources/mybatis/sql/IntentReportMapper.xml b/intentanalysis/src/main/resources/mybatis/sql/IntentReportMapper.xml new file mode 100644 index 0000000..02a571b --- /dev/null +++ b/intentanalysis/src/main/resources/mybatis/sql/IntentReportMapper.xml @@ -0,0 +1,11 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<!DOCTYPE mapper + PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> +<mapper namespace="org.onap.usecaseui.intentanalysis.mapper.IntentReportMapper"> + + <insert id="insertIntentReport"> + insert into intent_report(intent_report_id, intent_reference,report_time) + values (#{intentReport.intentReportId},#{intentReport.intentReference},to_timestamp(#{intentReport.reportTime},'yyyy-MM-dd HH24:mi:ss')) + </insert> +</mapper> diff --git a/intentanalysis/src/main/resources/mybatis/sql/ObjectInstanceMapper.xml b/intentanalysis/src/main/resources/mybatis/sql/ObjectInstanceMapper.xml new file mode 100644 index 0000000..8cf9b3c --- /dev/null +++ b/intentanalysis/src/main/resources/mybatis/sql/ObjectInstanceMapper.xml @@ -0,0 +1,18 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<!DOCTYPE mapper + PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> +<mapper namespace="org.onap.usecaseui.intentanalysis.mapper.ObjectInstanceMapper"> + + <insert id="insertObjectInstanceList"> + insert into object_instance(parent_id, object_instance) + values + <foreach collection="objectInstances" index="index" item="item" separator=","> + (#{parentId}, #{item}) + </foreach> + </insert> + + <select id="getObjectInstances" resultType="java.lang.String"> + select object_instance from object_instance where parent_id = #{parentId} + </select> +</mapper> diff --git a/intentanalysis/src/test/resources/intentdb-test-init.sql b/intentanalysis/src/test/resources/intentdb-test-init.sql index 1741585..25dc9ba 100644 --- a/intentanalysis/src/test/resources/intentdb-test-init.sql +++ b/intentanalysis/src/test/resources/intentdb-test-init.sql @@ -67,7 +67,8 @@ create table if not exists fulfillment_info fulfillment_info_id varchar(255) primary key, fulfillment_info_status varchar(255), not_fulfilled_state varchar(255), - not_fulfilled_reason varchar(255) + not_fulfilled_reason varchar(255), + achieve_value varchar(255) ); create table if not exists condition @@ -97,3 +98,23 @@ create table if not exists intent_Event_Record( operateType varchar (225), parent_id varchar(255) ); + +create table if not exists intent_report( + intent_report_id varchar(255) primary key, + intent_reference varchar(255), + report_time varchar(255) + ); + +create table if not exists intent_report_fulfillment_info( + parent_id varchar(255), + fulfillment_info_id varchar(255), + fulfillment_info_status varchar(255), + not_fulfilled_state varchar(255), + not_fulfilled_reason varchar(255), + achieve_value varchar(255) + ); + +create table if not exists object_instance( + parent_id varchar(255), + object_instance varchar(255) + );
\ No newline at end of file |