From 99ad19125b3e667cca2adfc7a30c2f5c1f4daf8c Mon Sep 17 00:00:00 2001 From: kaixiliu Date: Wed, 23 Aug 2023 15:28:50 +0800 Subject: Optimize the logic for generating intention reports Issue-ID: USECASEUI-819 Change-Id: I1578f690cb94097abe7d1e263f47b7c976b8555a Signed-off-by: kaixiliu --- .../intentanalysis/Thread/ThreadPoolConfig.java | 5 +- .../CLLBusinessDecisionModule.java | 22 ++--- .../CLLAssuranceActuationModule.java | 9 ++- .../CLLDeliveryActuationModule.java | 94 ++++++++++++---------- .../FormatIntentInputManagementFunction.java | 1 + .../FormatIntentInputDecisionModule.java | 63 +-------------- .../IntentManagementFunction.java | 57 ++++++++++++- .../CLLDeliveryActuationModuleTest.java | 4 +- 8 files changed, 135 insertions(+), 120 deletions(-) diff --git a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/Thread/ThreadPoolConfig.java b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/Thread/ThreadPoolConfig.java index b6f53b7..cf693bc 100644 --- a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/Thread/ThreadPoolConfig.java +++ b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/Thread/ThreadPoolConfig.java @@ -15,6 +15,7 @@ */ package org.onap.usecaseui.intentanalysis.Thread; +import com.google.common.util.concurrent.ThreadFactoryBuilder; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; @@ -22,7 +23,6 @@ import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; import java.util.concurrent.*; @Configuration -//@EnableAsync public class ThreadPoolConfig { @Bean("intentTaskExecutor") @@ -49,7 +49,8 @@ public class ThreadPoolConfig { @Bean("intentReportExecutor") public Executor getScheduledThreadPoolExecutor(){ - ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(2); + ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(3); + executor.setThreadFactory(new ThreadFactoryBuilder().setNameFormat("Report-task-%d").build()); return executor; } } diff --git a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/cllBusinessIntentMgt/cllBusinessModule/CLLBusinessDecisionModule.java b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/cllBusinessIntentMgt/cllBusinessModule/CLLBusinessDecisionModule.java index 9975ef3..7ed852c 100644 --- a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/cllBusinessIntentMgt/cllBusinessModule/CLLBusinessDecisionModule.java +++ b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/cllBusinessIntentMgt/cllBusinessModule/CLLBusinessDecisionModule.java @@ -15,7 +15,6 @@ */ package org.onap.usecaseui.intentanalysis.cllBusinessIntentMgt.cllBusinessModule; - import lombok.extern.log4j.Log4j2; import org.apache.commons.lang.StringUtils; import org.onap.usecaseui.intentanalysis.bean.enums.ExpectationType; @@ -78,24 +77,28 @@ public class CLLBusinessDecisionModule extends DecisionModule { if (intentGoalBean.getIntentGoalType().equals(IntentGoalType.CREATE)) { List intentExpectations = intentGoalBean.getIntent().getIntentExpectations(); List expectationTypeList = intentExpectations.stream() - .map(Expectation::getExpectationType).distinct().collect(Collectors.toList()); + .map(Expectation::getExpectationType) + .filter(expectationType -> !ExpectationType.REPORT.equals(expectationType)).distinct().collect(Collectors.toList()); if (expectationTypeList.size() > 1) { return true; } else { List objectTypeList = intentExpectations.stream().map(x -> x.getExpectationObject().getObjectType()).distinct().collect(Collectors.toList()); - if (objectTypeList.size() > 1) { - return true; - } + return objectTypeList.size() > 1; } } return false; } public List intentDecomposition(IntentGoalBean intentGoalBean) { + List intentExpectations = intentGoalBean.getIntent().getIntentExpectations(); + List report = intentExpectations.stream() + .filter(expectation -> ExpectationType.REPORT.equals(expectation.getExpectationType())) + .collect(Collectors.toList()); //ExpectationType expectation.ExpectationObject.objtype - Map> expectationTypeListMap = intentGoalBean.getIntent().getIntentExpectations() - .stream().collect(Collectors.groupingBy(x -> x.getExpectationType())); + Map> expectationTypeListMap = intentExpectations.stream() + .filter(expectation -> !ExpectationType.REPORT.equals(expectation.getExpectationType())) + .collect(Collectors.groupingBy(Expectation::getExpectationType)); List subIntentGoalList = new ArrayList<>(); IntentGoalType intentGoalType = intentGoalBean.getIntentGoalType(); for (Map.Entry> entry : expectationTypeListMap.entrySet()) { @@ -106,7 +109,9 @@ public class CLLBusinessDecisionModule extends DecisionModule { IntentGoalBean subIntentGoalBean = new IntentGoalBean(); Intent subIntent = new Intent(); subIntent.setIntentName(objEntry.getValue().get(0).getExpectationName().replace("Expectation", "Intent")); - subIntent.setIntentExpectations(objEntry.getValue()); + List value = objEntry.getValue(); + value.addAll(report); + subIntent.setIntentExpectations(value); subIntent.setIntentGenerateType(IntentGenerateType.SYSTEMGENARATE); //TODO intentFulfillmentInfo intentContexts subIntentGoalBean.setIntentGoalType(intentGoalType); @@ -208,5 +213,4 @@ public class CLLBusinessDecisionModule extends DecisionModule { } return intentMap; } - } 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 7a22226..27efe40 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 @@ -18,11 +18,11 @@ package org.onap.usecaseui.intentanalysis.cllassuranceIntentmgt.cllassurancemodu import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang.StringUtils; import org.onap.usecaseui.intentanalysis.adapters.policy.PolicyService; +import org.onap.usecaseui.intentanalysis.bean.enums.ExpectationType; import org.onap.usecaseui.intentanalysis.bean.enums.IntentGoalType; import org.onap.usecaseui.intentanalysis.bean.models.*; import org.onap.usecaseui.intentanalysis.intentBaseService.IntentManagementFunction; import org.onap.usecaseui.intentanalysis.intentBaseService.intentModule.ActuationModule; -import org.onap.usecaseui.intentanalysis.service.ContextService; import org.onap.usecaseui.intentanalysis.service.IntentService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @@ -30,6 +30,7 @@ import org.springframework.util.CollectionUtils; import java.util.List; import java.util.stream.Collectors; + @Slf4j @Component public class CLLAssuranceActuationModule extends ActuationModule { @@ -38,8 +39,6 @@ public class CLLAssuranceActuationModule extends ActuationModule { @Autowired private PolicyService policyService; - @Autowired - private ContextService contextService; @Override public void toNextIntentHandler(IntentGoalBean intentGoalBean, IntentManagementFunction IntentHandler) { @@ -82,7 +81,9 @@ public class CLLAssuranceActuationModule extends ActuationModule { return null; } for (Intent deliveryIntent : deliveryIntentList) { - List deliveryExpectationList = deliveryIntent.getIntentExpectations(); + List deliveryExpectationList = deliveryIntent.getIntentExpectations().stream() + .filter(expectation -> ExpectationType.DELIVERY.equals(expectation.getExpectationType())) + .collect(Collectors.toList()); if (CollectionUtils.isEmpty(deliveryExpectationList)) { log.info("expectation is empty,intentId is {}", deliveryIntent.getIntentId()); continue; 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 e42b5de..33d05f9 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 @@ -25,7 +25,6 @@ import org.onap.usecaseui.intentanalysis.bean.models.*; import org.onap.usecaseui.intentanalysis.bean.enums.*; import org.onap.usecaseui.intentanalysis.intentBaseService.IntentManagementFunction; import org.onap.usecaseui.intentanalysis.intentBaseService.intentModule.ActuationModule; -import org.onap.usecaseui.intentanalysis.service.ContextService; import org.onap.usecaseui.intentanalysis.service.ExpectationObjectService; import org.onap.usecaseui.intentanalysis.service.ExpectationService; import org.onap.usecaseui.intentanalysis.service.FulfillmentInfoService; @@ -39,6 +38,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.UUID; +import java.util.stream.Collectors; @Component @Slf4j @@ -61,8 +61,6 @@ public class CLLDeliveryActuationModule extends ActuationModule { @Autowired private IntentService intentService; - @Autowired - private ContextService contextService; @Override public void toNextIntentHandler(IntentGoalBean intentGoalBean, IntentManagementFunction IntentHandler) { @@ -72,10 +70,13 @@ public class CLLDeliveryActuationModule extends ActuationModule { @Override public void directOperation(IntentGoalBean intentGoalBean) { Intent intent = intentGoalBean.getIntent(); + Expectation deliveryExpectation = intent.getIntentExpectations().stream() + .filter(expectation -> !ExpectationType.REPORT.equals(expectation.getExpectationType())) + .collect(Collectors.toList()).get(0); if (StringUtils.equalsIgnoreCase("create", intentGoalBean.getIntentGoalType().name())) { Map params = new HashMap<>(); Map accessPointOne = new HashMap<>(); - List targetList = intent.getIntentExpectations().get(0).getExpectationTargets(); + List targetList = deliveryExpectation.getExpectationTargets(); for (ExpectationTarget target : targetList) { String conditionName = target.getTargetConditions().get(0).getConditionName(); String conditionValue = target.getTargetConditions().get(0).getConditionValue(); @@ -92,44 +93,22 @@ public class CLLDeliveryActuationModule extends ActuationModule { params.put("instanceId", getInstanceId()); params.put("name", "cll-" + params.get("instanceId")); params.put("protect", false); - ResultHeader resultHeader = soService.createIntentInstance(params); - - // Get the expectationId of the first exception from intent which should be CLL_VPN DELIVERY - String expectationId = intent.getIntentExpectations().get(0).getExpectationId(); - - // Get the fulfillmentInfo of the first exception which need to be updated with resultHeader returned - FulfillmentInfo fulfillmentInfo = new FulfillmentInfo(); - Expectation intentExpectation = expectationService.getIntentExpectation(expectationId); - if (intentExpectation != null) { - FulfillmentInfo expectationFulfillmentInfo = intentExpectation.getExpectationFulfillmentInfo(); - if (expectationFulfillmentInfo != null) { - fulfillmentInfo = expectationFulfillmentInfo; - } - } - // Update fulfillmentInfo and write back to DB - // Originally set to be NOT_FULFILLED, and will change after requesting the SO operation status - fulfillmentInfo.setFulfillmentStatus(FulfillmentStatus.NOT_FULFILLED); - fulfillmentInfo.setNotFulfilledReason(resultHeader.getResult_message()); + updateFulfillment(params, deliveryExpectation.getExpectationId()); - // If SO request accepted, means intent acknowledged, otherwise, means failed - if (resultHeader.getResult_code() == 1) { - fulfillmentInfo.setNotFulfilledState(NotFulfilledState.ACKNOWLEDGED); - } else { - fulfillmentInfo.setNotFulfilledState(NotFulfilledState.FULFILMENTFAILED); - } - - fulfillmentInfoService.updateFulfillmentInfo(fulfillmentInfo, expectationId); - - 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); + // fill and update the objectInstance of intent expectation(include delivery and report) + String objectInstance = (String) params.get("name"); + intent.getIntentExpectations().forEach(expectation -> { + ExpectationObject expectationObject = expectationObjectService.getExpectationObject(expectation.getExpectationId()); + expectationObject.setObjectInstance(objectInstance); + expectation.getExpectationObject().setObjectInstance(objectInstance); + expectationObjectService.updateExpectationObject(expectationObject, expectation.getExpectationId()); + }); } else if (StringUtils.equalsIgnoreCase("delete", intentGoalBean.getIntentGoalType().name())) { - String instanceId = intent.getIntentExpectations().get(0).getExpectationObject().getObjectInstance(); + String instanceId = deliveryExpectation.getExpectationObject().getObjectInstance(); soService.deleteIntentInstance(instanceId); } else { - String instanceId = intent.getIntentExpectations().get(0).getExpectationObject().getObjectInstance(); + String instanceId = deliveryExpectation.getExpectationObject().getObjectInstance(); soService.deleteIntentInstance(instanceId); intentService.deleteIntent(intent.getIntentId()); } @@ -145,6 +124,31 @@ public class CLLDeliveryActuationModule extends ActuationModule { this.directOperation(intentGoalBean); } + private void updateFulfillment(Map params,String expectationId){ + // Get the fulfillmentInfo of the first exception which need to be updated with resultHeader returned + FulfillmentInfo fulfillmentInfo = new FulfillmentInfo(); + Expectation intentExpectation = expectationService.getIntentExpectation(expectationId); + if (intentExpectation != null) { + FulfillmentInfo expectationFulfillmentInfo = intentExpectation.getExpectationFulfillmentInfo(); + if (expectationFulfillmentInfo != null) { + fulfillmentInfo = expectationFulfillmentInfo; + } + } + ResultHeader resultHeader = soService.createIntentInstance(params); + // Update fulfillmentInfo and write back to DB + // Originally set to be NOT_FULFILLED, and will change after requesting the SO operation status + fulfillmentInfo.setFulfillmentStatus(FulfillmentStatus.NOT_FULFILLED); + fulfillmentInfo.setNotFulfilledReason(resultHeader.getResult_message()); + + // If SO request accepted, means intent acknowledged, otherwise, means failed + if (resultHeader.getResult_code() == 1) { + fulfillmentInfo.setNotFulfilledState(NotFulfilledState.ACKNOWLEDGED); + } else { + fulfillmentInfo.setNotFulfilledState(NotFulfilledState.FULFILMENTFAILED); + } + fulfillmentInfoService.updateFulfillmentInfo(fulfillmentInfo, expectationId); + } + private String getPredictValue(String name, String value) { String text = "expectationName is cloud leased line Delivery Expectation, " + "firstName is " + name + ",firstValue is " + value; @@ -171,19 +175,25 @@ public class CLLDeliveryActuationModule extends ActuationModule { return randomString + String.format("%015d", hashCode); } + /** + * update objectInstance of the previous layer’s intent + * + * @param originIntent intent of the previous layer + * @param intentGoalBean intent of this layer + */ public void updateIntentOperationInfo(Intent originIntent, IntentGoalBean intentGoalBean){ Intent subIntent = intentGoalBean.getIntent(); if (StringUtils.containsIgnoreCase(subIntent.getIntentName(),"delivery")) { - List deliveryIntentExpectationList = intentGoalBean.getIntent().getIntentExpectations(); + List deliveryIntentExpectationList = subIntent.getIntentExpectations().stream() + .filter(expectation -> ExpectationType.DELIVERY.equals(expectation.getExpectationType())) + .collect(Collectors.toList()); List originIntentExpectationList = originIntent.getIntentExpectations(); - ExpectationObject deliveryExpectationObject = deliveryIntentExpectationList.get(0).getExpectationObject(); - String objectInstance = deliveryExpectationObject.getObjectInstance(); - + String objectInstance = deliveryIntentExpectationList.get(0).getExpectationObject().getObjectInstance(); for (Expectation originExpectation : originIntentExpectationList) { ExpectationObject originExpectationObject = originExpectation.getExpectationObject(); originExpectationObject.setObjectInstance(objectInstance); } } - log.info("cllDeliveryActuationModule begin to update originIntent subIntentInfo"); + log.info("cllDeliveryActuationModule end to update originIntent subIntentInfo"); } } diff --git a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/formatintentinputMgt/FormatIntentInputManagementFunction.java b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/formatintentinputMgt/FormatIntentInputManagementFunction.java index cfa7df2..1090eba 100644 --- a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/formatintentinputMgt/FormatIntentInputManagementFunction.java +++ b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/formatintentinputMgt/FormatIntentInputManagementFunction.java @@ -76,6 +76,7 @@ public class FormatIntentInputManagementFunction extends IntentManagementFunctio IntentGoalBean originIntentGoalBean = detection(intentGoalBean); LinkedHashMap linkedMap = investigation(originIntentGoalBean); implementIntent(intentGoalBean.getIntent(), linkedMap); + generationIntentReport(intentGoalBean); } @Override diff --git a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/formatintentinputMgt/formatintentinputModule/FormatIntentInputDecisionModule.java b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/formatintentinputMgt/formatintentinputModule/FormatIntentInputDecisionModule.java index 4ca532e..334a6d3 100644 --- a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/formatintentinputMgt/formatintentinputModule/FormatIntentInputDecisionModule.java +++ b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/formatintentinputMgt/formatintentinputModule/FormatIntentInputDecisionModule.java @@ -17,7 +17,6 @@ package org.onap.usecaseui.intentanalysis.formatintentinputMgt.formatintentinput import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang.StringUtils; -import org.onap.usecaseui.intentanalysis.bean.enums.ExpectationType; import org.onap.usecaseui.intentanalysis.bean.enums.IntentGoalType; import org.onap.usecaseui.intentanalysis.bean.models.*; import org.onap.usecaseui.intentanalysis.cllBusinessIntentMgt.CLLBusinessIntentManagementFunction; @@ -26,21 +25,15 @@ import org.onap.usecaseui.intentanalysis.exception.IntentInputException; import org.onap.usecaseui.intentanalysis.intentBaseService.IntentManagementFunction; import org.onap.usecaseui.intentanalysis.intentBaseService.contextService.IntentContextService; import org.onap.usecaseui.intentanalysis.intentBaseService.intentModule.DecisionModule; -import org.onap.usecaseui.intentanalysis.service.IntentReportService; import org.onap.usecaseui.intentanalysis.service.IntentService; -import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationContext; import org.springframework.stereotype.Component; -import org.springframework.util.CollectionUtils; -import javax.annotation.Resource; import java.util.ArrayList; import java.util.LinkedHashMap; import java.util.List; import java.util.Locale; -import java.util.concurrent.ScheduledThreadPoolExecutor; -import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; @Slf4j @@ -55,12 +48,6 @@ public class FormatIntentInputDecisionModule extends DecisionModule { @Autowired public IntentService intentService; - @Autowired - private IntentReportService intentReportService; - - @Resource(name = "intentReportExecutor") - private ScheduledThreadPoolExecutor executor; - @Override public void determineUltimateGoal() { } @@ -91,14 +78,12 @@ public class FormatIntentInputDecisionModule extends DecisionModule { log.info("FormatIntentInputMgt investigation create process start"); LinkedHashMap intentMap = new LinkedHashMap<>(); - IntentGoalBean newIntentGoalBean = removeReportExpectation(intentGoalBean); - - boolean needDecompostion = needDecompostion(newIntentGoalBean); + boolean needDecompostion = needDecompostion(intentGoalBean); log.debug("FormatIntentInputMgt need decompose :" + needDecompostion); if (needDecompostion) { - intentDecomposition(newIntentGoalBean); + intentDecomposition(intentGoalBean); } else { - intentMap.put(newIntentGoalBean, exploreIntentHandlers(newIntentGoalBean)); + intentMap.put(intentGoalBean, exploreIntentHandlers(intentGoalBean)); } log.info("FormatIntentInputMgt investigation create process finished"); return intentMap; @@ -182,46 +167,4 @@ public class FormatIntentInputDecisionModule extends DecisionModule { } return intentMap; } - - private IntentGoalBean removeReportExpectation(IntentGoalBean intentGoalBean) { - Intent intent = intentGoalBean.getIntent(); - List intentExpectations = intent.getIntentExpectations(); - List report = intentExpectations.stream() - .filter(expectation -> ExpectationType.REPORT.equals(expectation.getExpectationType())) - .collect(Collectors.toList()); - if (CollectionUtils.isEmpty(report)) { - log.info("No expectation of type report is entered"); - return intentGoalBean; - } - generationIntentReport(report.get(0), intent.getIntentId()); - Intent newIntent = new Intent(); - BeanUtils.copyProperties(intent, newIntent); - List notReport = intentExpectations.stream() - .filter(expectation -> !ExpectationType.REPORT.equals(expectation.getExpectationType())) - .collect(Collectors.toList()); - newIntent.setIntentExpectations(notReport); - return new IntentGoalBean(newIntent, intentGoalBean.getIntentGoalType()); - } - - private void generationIntentReport(Expectation expectation, String intentId) { - List expectationTargets = expectation.getExpectationTargets(); - if (CollectionUtils.isEmpty(expectationTargets)) { - log.error("The expectation target is empty,expectationId is {}", expectation.getExpectationId()); - return; - } - ExpectationTarget expectationTarget = expectationTargets.get(0); - List targetConditions = expectationTarget.getTargetConditions(); - if (CollectionUtils.isEmpty(targetConditions)) { - log.error("The target condition is empty,expectationId is {}", expectation.getExpectationId()); - return; - } - Condition condition = targetConditions.get(0); - try { - int conditionValue = Integer.parseInt(condition.getConditionValue()); - log.info("Start executing scheduled intent report generation task "); - executor.scheduleAtFixedRate(() -> intentReportService.saveIntentReportByIntentId(intentId), 2, conditionValue, TimeUnit.SECONDS); - } catch (Exception e) { - log.error("The exception is {}", e.getMessage()); - } - } } diff --git a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/intentBaseService/IntentManagementFunction.java b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/intentBaseService/IntentManagementFunction.java index 7c01c81..65f40cb 100644 --- a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/intentBaseService/IntentManagementFunction.java +++ b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/intentBaseService/IntentManagementFunction.java @@ -15,8 +15,12 @@ */ package org.onap.usecaseui.intentanalysis.intentBaseService; - import lombok.Data; +import lombok.extern.log4j.Log4j2; +import org.onap.usecaseui.intentanalysis.bean.enums.ExpectationType; +import org.onap.usecaseui.intentanalysis.bean.models.Condition; +import org.onap.usecaseui.intentanalysis.bean.models.Expectation; +import org.onap.usecaseui.intentanalysis.bean.models.ExpectationTarget; import org.onap.usecaseui.intentanalysis.bean.models.FulfillmentInfo; import org.onap.usecaseui.intentanalysis.bean.models.Intent; import org.onap.usecaseui.intentanalysis.bean.models.IntentGoalBean; @@ -24,11 +28,22 @@ import org.onap.usecaseui.intentanalysis.intentBaseService.intentModule.Actuatio import org.onap.usecaseui.intentanalysis.intentBaseService.intentModule.DecisionModule; import org.onap.usecaseui.intentanalysis.intentBaseService.intentModule.KnowledgeModule; import org.onap.usecaseui.intentanalysis.service.FulfillmentInfoService; +import org.onap.usecaseui.intentanalysis.service.IntentReportService; import org.onap.usecaseui.intentanalysis.service.ObjectInstanceService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Configuration; import org.springframework.stereotype.Component; +import org.springframework.util.CollectionUtils; + +import javax.annotation.Resource; +import java.util.List; +import java.util.concurrent.ScheduledThreadPoolExecutor; +import java.util.concurrent.TimeUnit; +import java.util.stream.Collectors; +import static org.onap.usecaseui.intentanalysis.bean.enums.IntentGoalType.CREATE; + +@Log4j2 @Data @Configuration @Component @@ -43,6 +58,12 @@ public class IntentManagementFunction { @Autowired private ObjectInstanceService objectInstanceService; + @Autowired + private IntentReportService intentReportService; + + @Resource(name = "intentReportExecutor") + private ScheduledThreadPoolExecutor scheduledThreadPoolExecutor; + public void receiveIntentAsOwner(IntentGoalBean intentGoalBean){}; public void receiveIntentAsHandler(Intent originalIntent, IntentGoalBean intentGoalBean, IntentManagementFunction handler){}; public void createReport(String intentId, FulfillmentInfo fulfillmentInfo){}; @@ -52,4 +73,38 @@ public class IntentManagementFunction { fulfillmentInfoService.saveFulfillmentInfo(intentId, fulfillmentInfo); objectInstanceService.saveObjectInstances(intentId, fulfillmentInfo); } + + protected void generationIntentReport(IntentGoalBean intentGoalBean) { + if (CREATE != intentGoalBean.getIntentGoalType()) { + return; + } + Intent intent = intentGoalBean.getIntent(); + List intentExpectations = intent.getIntentExpectations(); + List report = intentExpectations.stream() + .filter(expectation -> ExpectationType.REPORT.equals(expectation.getExpectationType())) + .collect(Collectors.toList()); + if (CollectionUtils.isEmpty(report)) { + log.info("No expectation of type report is entered"); + return; + } + List expectationTargets = report.get(0).getExpectationTargets(); + if (CollectionUtils.isEmpty(expectationTargets)) { + log.error("The expectation target is empty,expectationId is {}", report.get(0).getExpectationId()); + return; + } + ExpectationTarget expectationTarget = expectationTargets.get(0); + List targetConditions = expectationTarget.getTargetConditions(); + if (CollectionUtils.isEmpty(targetConditions)) { + log.error("The target condition is empty,expectationId is {}", report.get(0).getExpectationId()); + return; + } + Condition condition = targetConditions.get(0); + try { + int conditionValue = Integer.parseInt(condition.getConditionValue()); + log.info("Start executing scheduled intent report generation task "); + scheduledThreadPoolExecutor.scheduleAtFixedRate(() -> intentReportService.saveIntentReportByIntentId(intent.getIntentId()), 2, conditionValue, TimeUnit.SECONDS); + } catch (Exception e) { + log.error("The exception is {}", e.getMessage()); + } + } } diff --git a/intentanalysis/src/test/java/org/onap/usecaseui/intentanalysis/clldeliveryIntentmgt/clldeliverymodule/CLLDeliveryActuationModuleTest.java b/intentanalysis/src/test/java/org/onap/usecaseui/intentanalysis/clldeliveryIntentmgt/clldeliverymodule/CLLDeliveryActuationModuleTest.java index 37a8b79..c88070f 100644 --- a/intentanalysis/src/test/java/org/onap/usecaseui/intentanalysis/clldeliveryIntentmgt/clldeliverymodule/CLLDeliveryActuationModuleTest.java +++ b/intentanalysis/src/test/java/org/onap/usecaseui/intentanalysis/clldeliveryIntentmgt/clldeliverymodule/CLLDeliveryActuationModuleTest.java @@ -20,16 +20,15 @@ import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; -import org.mockito.MockedStatic; import org.mockito.Mockito; import org.onap.usecaseui.intentanalysis.IntentAnalysisApplicationTests; import org.onap.usecaseui.intentanalysis.adapters.so.SOService; +import org.onap.usecaseui.intentanalysis.bean.enums.ExpectationType; import org.onap.usecaseui.intentanalysis.bean.enums.IntentGoalType; import org.onap.usecaseui.intentanalysis.bean.models.*; import org.onap.usecaseui.intentanalysis.service.ContextService; import org.onap.usecaseui.intentanalysis.service.ExpectationObjectService; import org.onap.usecaseui.intentanalysis.service.ExpectationService; -import org.onap.usecaseui.intentanalysis.util.HttpUtil; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.junit4.SpringRunner; @@ -73,6 +72,7 @@ public class CLLDeliveryActuationModuleTest { deliveryExpectationObject.setObjectInstance("deliveryObjectInstance"); deliveryExpectation.setExpectationObject(deliveryExpectationObject); + deliveryExpectation.setExpectationType(ExpectationType.DELIVERY); gbExpectationList.add(deliveryExpectation); intentGoalBean.setIntentGoalType(IntentGoalType.CREATE); Intent intent =new Intent(); -- cgit 1.2.3-korg