summaryrefslogtreecommitdiffstats
path: root/intentanalysis
diff options
context:
space:
mode:
Diffstat (limited to 'intentanalysis')
-rw-r--r--intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/Thread/ThreadPoolConfig.java9
-rw-r--r--intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/bean/enums/ExpectationType.java3
-rw-r--r--intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/clldeliveryIntentmgt/clldeliverymodule/CLLDeliveryActuationModule.java11
-rw-r--r--intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/controller/IntentReportController.java46
-rw-r--r--intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/formatintentinputMgt/formatintentinputModule/FormatIntentInputDecisionModule.java86
-rw-r--r--intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/service/IntentReportService.java2
-rw-r--r--intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/service/impl/ComponentNotificationServiceImpl.java6
-rw-r--r--intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/service/impl/IntentReportServiceImpl.java52
-rw-r--r--intentanalysis/src/main/resources/logback.xml6
-rw-r--r--intentanalysis/src/test/java/org/onap/usecaseui/intentanalysis/clldeliveryIntentmgt/clldeliverymodule/CLLDeliveryActuationModuleTest.java9
-rw-r--r--intentanalysis/src/test/java/org/onap/usecaseui/intentanalysis/service/impl/ComponentNotificationServiceImplTest.java58
-rw-r--r--intentanalysis/src/test/java/org/onap/usecaseui/intentanalysis/service/impl/IntentReportServiceTest.java62
-rw-r--r--intentanalysis/src/test/resources/intent.json104
-rw-r--r--intentanalysis/src/test/resources/intentdb-test-init.sql12
-rw-r--r--intentanalysis/src/test/resources/logback-test.xml6
15 files changed, 380 insertions, 92 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 e1f0af7..b6f53b7 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
@@ -19,8 +19,7 @@ import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
-import java.util.concurrent.Executor;
-import java.util.concurrent.ThreadPoolExecutor;
+import java.util.concurrent.*;
@Configuration
//@EnableAsync
@@ -47,5 +46,11 @@ public class ThreadPoolConfig {
executor.initialize();
return executor;
}
+
+ @Bean("intentReportExecutor")
+ public Executor getScheduledThreadPoolExecutor(){
+ ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(2);
+ return executor;
+ }
}
diff --git a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/bean/enums/ExpectationType.java b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/bean/enums/ExpectationType.java
index 34b0b8b..adc522c 100644
--- a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/bean/enums/ExpectationType.java
+++ b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/bean/enums/ExpectationType.java
@@ -21,7 +21,8 @@ import lombok.Getter;
@Getter
public enum ExpectationType {
DELIVERY(0, "delivery"),
- ASSURANCE(1, "assurance");
+ ASSURANCE(1, "assurance"),
+ REPORT(2, "report");
private int index;
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 c090b4d..592c1b1 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
@@ -89,10 +89,13 @@ public class CLLDeliveryActuationModule extends ActuationModule {
String expectationId = intent.getIntentExpectations().get(0).getExpectationId();
// Get the fulfillmentInfo of the first exception which need to be updated with resultHeader returned
- FulfillmentInfo fulfillmentInfo = expectationService.getIntentExpectation(expectationId).getExpectationFulfillmentInfo();
-
- if (fulfillmentInfo == null) {
- fulfillmentInfo = new FulfillmentInfo();
+ 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
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 c9e82a6..87ac149 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
@@ -16,23 +16,11 @@
package org.onap.usecaseui.intentanalysis.controller;
import lombok.extern.log4j.Log4j2;
-import org.onap.usecaseui.intentanalysis.bean.enums.FulfillmentStatus;
-import org.onap.usecaseui.intentanalysis.bean.enums.NotFulfilledState;
import org.onap.usecaseui.intentanalysis.bean.models.*;
+import org.onap.usecaseui.intentanalysis.service.IntentReportService;
+import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
-import org.springframework.http.ResponseEntity;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.PathVariable;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
-
-import java.text.SimpleDateFormat;
-import java.time.LocalDateTime;
-import java.time.ZoneId;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Date;
-import java.util.List;
+import org.springframework.web.bind.annotation.*;
import static org.onap.usecaseui.intentanalysis.common.ResponseConsts.RSEPONSE_SUCCESS;
@@ -40,36 +28,14 @@ import static org.onap.usecaseui.intentanalysis.common.ResponseConsts.RSEPONSE_S
@RestController
@RequestMapping("/intentReport")
public class IntentReportController {
+ @Autowired
+ private IntentReportService intentReportService;
@GetMapping(value = "/{intentId}", produces = MediaType.APPLICATION_JSON_VALUE)
public ServiceResult getIntentById(
@PathVariable("intentId") String intentId) {
- // test connection with ui,real log
- IntentReport report = new IntentReport();
- report.setIntentReportId("12345");
- report.setIntentReference("intentReort");
- //report.setFulfillmentInfos();
- Date date = new Date();
- SimpleDateFormat dateFormat = new SimpleDateFormat("yyy-MM-dd HH:mm:ss");
- report.setReportTime(dateFormat.format(date));
- FulfillmentInfo fu1= new FulfillmentInfo();
- fu1.setFulfillmentId("fulfillmentInfo1");
- fu1.setFulfillmentStatus(FulfillmentStatus.FULFILLED);
- fu1.setObjectInstances(Arrays.asList("instance1", "instance2", "instance3"));
- FulfillmentInfo fu2= new FulfillmentInfo();
- fu2.setFulfillmentId("fulfillmentInfo2");
- fu2.setFulfillmentStatus(FulfillmentStatus.NOT_FULFILLED);
- fu2.setNotFulfilledState(NotFulfilledState.DEGRADED);
- fu2.setNotFulfilledReason("not fulfilled Reason");
- fu2.setObjectInstances(Arrays.asList("instance1", "instance2"));
- List<FulfillmentInfo> list = new ArrayList<>();
- list.add(fu1);
- list.add(fu2);
- report.setFulfillmentInfos(list);
-
+ IntentReport report = intentReportService.getIntentReportByIntentId(intentId);
return new ServiceResult(new ResultHeader(RSEPONSE_SUCCESS, "get report success"),
report);
-
}
-
}
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 f9d0c74..4ca532e 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,26 +17,32 @@ 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.Expectation;
-import org.onap.usecaseui.intentanalysis.bean.models.Intent;
-import org.onap.usecaseui.intentanalysis.bean.models.IntentGoalBean;
+import org.onap.usecaseui.intentanalysis.bean.models.*;
import org.onap.usecaseui.intentanalysis.cllBusinessIntentMgt.CLLBusinessIntentManagementFunction;
import org.onap.usecaseui.intentanalysis.common.ResponseConsts;
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
@Component
public class FormatIntentInputDecisionModule extends DecisionModule {
@@ -49,6 +55,12 @@ public class FormatIntentInputDecisionModule extends DecisionModule {
@Autowired
public IntentService intentService;
+ @Autowired
+ private IntentReportService intentReportService;
+
+ @Resource(name = "intentReportExecutor")
+ private ScheduledThreadPoolExecutor executor;
+
@Override
public void determineUltimateGoal() {
}
@@ -58,8 +70,8 @@ public class FormatIntentInputDecisionModule extends DecisionModule {
// if intentName contain cll return
if (intentGoalBean.getIntent().getIntentName().toLowerCase(Locale.ROOT).contains("cll")) {
return (IntentManagementFunction) applicationContext.getBean(CLLBusinessIntentManagementFunction.class.getSimpleName());
- }else{
- String msg = String.format("intentName is: %s can't find corresponding IntentManagementFunction,please check Intent Name",intentGoalBean.getIntent().getIntentName());
+ } else {
+ String msg = String.format("intentName is: %s can't find corresponding IntentManagementFunction,please check Intent Name", intentGoalBean.getIntent().getIntentName());
log.error(msg);
throw new IntentInputException(msg, ResponseConsts.RET_FIND_CORRESPONDING_FAIL);
}
@@ -76,14 +88,17 @@ public class FormatIntentInputDecisionModule extends DecisionModule {
@Override
public LinkedHashMap<IntentGoalBean, IntentManagementFunction> investigationCreateProcess(IntentGoalBean intentGoalBean) {
- log.info("FormatIntentInputMgt investigation create process start");
+ log.info("FormatIntentInputMgt investigation create process start");
LinkedHashMap<IntentGoalBean, IntentManagementFunction> intentMap = new LinkedHashMap<>();
- boolean needDecompostion = needDecompostion(intentGoalBean);
- log.debug("FormatIntentInputMgt need decompose :"+ needDecompostion);
+
+ IntentGoalBean newIntentGoalBean = removeReportExpectation(intentGoalBean);
+
+ boolean needDecompostion = needDecompostion(newIntentGoalBean);
+ log.debug("FormatIntentInputMgt need decompose :" + needDecompostion);
if (needDecompostion) {
- intentDecomposition(intentGoalBean);
+ intentDecomposition(newIntentGoalBean);
} else {
- intentMap.put(intentGoalBean, exploreIntentHandlers(intentGoalBean));
+ intentMap.put(newIntentGoalBean, exploreIntentHandlers(newIntentGoalBean));
}
log.info("FormatIntentInputMgt investigation create process finished");
return intentMap;
@@ -128,7 +143,7 @@ public class FormatIntentInputDecisionModule extends DecisionModule {
return intentMap;
}
- public void UpdateIntentInfo(Intent originIntent, Intent intent){
+ public void UpdateIntentInfo(Intent originIntent, Intent intent) {
List<Expectation> originIntentExpectationList = originIntent.getIntentExpectations();
List<Expectation> intentExpectationList = intent.getIntentExpectations();
@@ -136,18 +151,18 @@ public class FormatIntentInputDecisionModule extends DecisionModule {
int oldIntentExpectationNum = intentExpectationList.size();
List<Expectation> changeList = new ArrayList<>();
- if (newIntentExpectationNum != oldIntentExpectationNum){
- if (newIntentExpectationNum < oldIntentExpectationNum){
+ if (newIntentExpectationNum != oldIntentExpectationNum) {
+ if (newIntentExpectationNum < oldIntentExpectationNum) {
for (Expectation oldExpectation : intentExpectationList) {//search
boolean bFindExpectation = false;
for (Expectation newExpectation : originIntentExpectationList) {//param
- if (oldExpectation.getExpectationName().equals(newExpectation.getExpectationName())){
+ if (oldExpectation.getExpectationName().equals(newExpectation.getExpectationName())) {
bFindExpectation = true;
break;
}
}
- if (bFindExpectation){
+ if (bFindExpectation) {
changeList.add(oldExpectation);
}
}
@@ -168,4 +183,45 @@ public class FormatIntentInputDecisionModule extends DecisionModule {
return intentMap;
}
+ private IntentGoalBean removeReportExpectation(IntentGoalBean intentGoalBean) {
+ Intent intent = intentGoalBean.getIntent();
+ List<Expectation> intentExpectations = intent.getIntentExpectations();
+ List<Expectation> 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<Expectation> 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<ExpectationTarget> 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<Condition> 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/service/IntentReportService.java b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/service/IntentReportService.java
index 5e8d158..97e90d1 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
@@ -20,4 +20,6 @@ import org.onap.usecaseui.intentanalysis.bean.models.IntentReport;
public interface IntentReportService {
IntentReport 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 27d7bb4..43d6082 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
@@ -27,6 +27,7 @@ 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.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import java.util.List;
@@ -61,6 +62,7 @@ public class ComponentNotificationServiceImpl implements ComponentNotificationSe
* @param eventModel param
*/
@Override
+ @Transactional(rollbackFor = DataBaseException.class)
public void callBack(FulfillmentOperation eventModel) {
if (eventModel == null) {
String msg = "The obtained fulfillmentInfo is null";
@@ -82,14 +84,12 @@ public class ComponentNotificationServiceImpl implements ComponentNotificationSe
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";
@@ -111,7 +111,6 @@ public class ComponentNotificationServiceImpl implements ComponentNotificationSe
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);
@@ -143,7 +142,6 @@ public class ComponentNotificationServiceImpl implements ComponentNotificationSe
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);
}
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 6ea3e06..d3e914b 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
@@ -29,6 +29,7 @@ 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.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import java.util.Collections;
@@ -51,41 +52,68 @@ public class IntentReportServiceImpl implements IntentReportService {
private IntentReportMapper intentReportMapper;
@Override
+ @Transactional(rollbackFor = DataBaseException.class)
public IntentReport getIntentReportByIntentId(String intentId) {
+ FulfillmentInfo fulfillmentInfo = getFulfillmentInfo(intentId);
+ fulfillmentInfo.setObjectInstances(getInstances(intentId));
+ IntentReport intentReport = new IntentReport();
+ intentReport.setIntentReportId(CommonUtil.getUUid());
+ intentReport.setIntentReference("intentReference");
+ intentReport.setFulfillmentInfos(Collections.singletonList(fulfillmentInfo));
+ intentReport.setReportTime(CommonUtil.getTime());
+
+ saveIntentReport(intentReport, fulfillmentInfo);
+ return intentReport;
+ }
+
+ @Override
+ @Transactional(rollbackFor = DataBaseException.class)
+ public void saveIntentReportByIntentId(String intentId) {
FulfillmentInfo fulfillmentInfo = fulfillmentInfoService.getFulfillmentInfo(intentId);
- System.out.println(fulfillmentInfo);
+ if (fulfillmentInfo == null) {
+ log.error("The fulfillmentInfo is null");
+ return;
+ }
+ IntentReport intentReport = new IntentReport();
+ intentReport.setIntentReportId(CommonUtil.getUUid());
+ intentReport.setIntentReference("intentReference");
+ intentReport.setReportTime(CommonUtil.getTime());
+ saveIntentReport(intentReport, fulfillmentInfo);
+ }
+
+ private FulfillmentInfo getFulfillmentInfo(String intentId) {
+ FulfillmentInfo fulfillmentInfo = fulfillmentInfoService.getFulfillmentInfo(intentId);
+ log.info("fulfillmentInfo is {}", fulfillmentInfo);
if (fulfillmentInfo == null) {
log.error("get fulfillmentInfo is failed,intentId is {}", intentId);
- String msg = "get fulfillmentInfo is failed";
+ String msg = "get fulfillmentInfo is empty, please enter the right intentId";
throw new DataBaseException(msg, ResponseConsts.RET_QUERY_DATA_EMPTY);
}
- fulfillmentInfo.setFulfillmentId(intentId);
+ return fulfillmentInfo;
+ }
+
+ private List<String> getInstances(String 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());
+ return objectInstances;
+ }
+ private void saveIntentReport(IntentReport intentReport, FulfillmentInfo fulfillmentInfo) {
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);
+ int fulfillmentNum = intentReportFulfillmentInfoMapper.insertIntentReportFulfillment(fulfillmentInfo, intentReport.getIntentReportId());
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/resources/logback.xml b/intentanalysis/src/main/resources/logback.xml
index 82a1954..05bf36d 100644
--- a/intentanalysis/src/main/resources/logback.xml
+++ b/intentanalysis/src/main/resources/logback.xml
@@ -17,7 +17,7 @@
<!-- encoders are assigned the type
ch.qos.logback.classic.encoder.PatternLayoutEncoder by default -->
<encoder>
- <pattern>%d{yyyy-MM-dd HH:mm:ss:SSS} %5p ${PID} --- [%15.15t] %-40.40c{40} : %m%n</pattern>
+ <pattern>%d{yyyy-MM-dd HH:mm:ss:SSS} %5p ${PID} --- [%15.15t] %-40.40c{40}[%L] : %m%n</pattern>
</encoder>
</appender>
@@ -32,7 +32,7 @@
<!-- set immediateFlush to false for much higher logging throughput -->
<immediateFlush>true</immediateFlush>
<encoder>
- <pattern>%d{yyyy-MM-dd HH:mm:ss:SSS} %5p ${PID} --- [%15.15t] %-40.40c{40} : %m%n</pattern>
+ <pattern>%d{yyyy-MM-dd HH:mm:ss:SSS} %5p ${PID} --- [%15.15t] %-40.40c{40}[%L] : %m%n</pattern>
</encoder>
</appender>
@@ -48,7 +48,7 @@
<totalSizeCap>3GB</totalSizeCap>
</rollingPolicy>
<encoder>
- <pattern>>%d{yyyy-MM-dd HH:mm:ss:SSS} %5p ${PID} --- [%15.15t] %-40.40c{40} : %m%n</pattern>
+ <pattern>>%d{yyyy-MM-dd HH:mm:ss:SSS} %5p ${PID} --- [%15.15t] %-40.40c{40}[%L] : %m%n</pattern>
</encoder>
</appender>
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 2c04e7b..30ffd01 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
@@ -28,6 +28,8 @@ 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.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
@@ -40,8 +42,11 @@ import static org.junit.jupiter.api.Assertions.*;
@SpringBootTest(classes = IntentAnalysisApplicationTests.class)
@RunWith(SpringRunner.class)
public class CLLDeliveryActuationModuleTest {
- @InjectMocks
+ @Autowired
CLLDeliveryActuationModule cllDeliveryActuationModulel;
+
+ @Autowired
+ private ExpectationService expectationService;
@Mock
private ExpectationObjectService expectationObjectService;
@Mock
@@ -92,7 +97,7 @@ public class CLLDeliveryActuationModuleTest {
Intent intent = new Intent();
List<Expectation> expectationList = new ArrayList<>();
Expectation expectation = new Expectation();
- expectation.setExpectationId("1234");
+ expectation.setExpectationId("expectationId1");
List<ExpectationTarget> targetList = new ArrayList<>();
ExpectationTarget target = new ExpectationTarget();
diff --git a/intentanalysis/src/test/java/org/onap/usecaseui/intentanalysis/service/impl/ComponentNotificationServiceImplTest.java b/intentanalysis/src/test/java/org/onap/usecaseui/intentanalysis/service/impl/ComponentNotificationServiceImplTest.java
new file mode 100644
index 0000000..1925d4e
--- /dev/null
+++ b/intentanalysis/src/test/java/org/onap/usecaseui/intentanalysis/service/impl/ComponentNotificationServiceImplTest.java
@@ -0,0 +1,58 @@
+/*
+ * 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 com.alibaba.fastjson.JSONObject;
+import org.apache.commons.io.FileUtils;
+import org.apache.ibatis.io.Resources;
+import org.mockito.Mock;
+import org.onap.usecaseui.intentanalysis.adapters.policy.PolicyService;
+import org.onap.usecaseui.intentanalysis.adapters.so.SOService;
+import org.onap.usecaseui.intentanalysis.bean.enums.IntentGoalType;
+import org.onap.usecaseui.intentanalysis.bean.models.Intent;
+import org.onap.usecaseui.intentanalysis.bean.models.IntentGoalBean;
+import org.onap.usecaseui.intentanalysis.formatintentinputMgt.FormatIntentInputManagementFunction;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.ApplicationArguments;
+import org.springframework.boot.ApplicationRunner;
+import org.springframework.stereotype.Component;
+
+import java.io.File;
+import java.nio.charset.StandardCharsets;
+
+@Component
+public class ComponentNotificationServiceImplTest implements ApplicationRunner {
+ @Autowired
+ ComponentNotificationServiceImpl componentNotificationService;
+
+ @Autowired
+ FormatIntentInputManagementFunction formatIntentInputManagementFunction;
+
+ @Mock
+ private PolicyService policyService;
+
+ @Mock
+ private SOService soService;
+
+ @Override
+ public void run(ApplicationArguments args) throws Exception {
+ File policyTypeFile = Resources.getResourceAsFile("intent.json");
+ String intentStr = FileUtils.readFileToString(policyTypeFile, StandardCharsets.UTF_8);
+ Intent intent = JSONObject.parseObject(intentStr, Intent.class);
+ formatIntentInputManagementFunction.receiveIntentAsOwner(new IntentGoalBean(intent, IntentGoalType.CREATE));
+ }
+}
diff --git a/intentanalysis/src/test/java/org/onap/usecaseui/intentanalysis/service/impl/IntentReportServiceTest.java b/intentanalysis/src/test/java/org/onap/usecaseui/intentanalysis/service/impl/IntentReportServiceTest.java
new file mode 100644
index 0000000..a2c3dd9
--- /dev/null
+++ b/intentanalysis/src/test/java/org/onap/usecaseui/intentanalysis/service/impl/IntentReportServiceTest.java
@@ -0,0 +1,62 @@
+/*
+ * 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 org.junit.Assert;
+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.service.IntentReportService;
+import org.springframework.beans.factory.annotation.Autowired;
+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;
+
+@SpringBootTest(classes = IntentAnalysisApplicationTests.class)
+@RunWith(SpringRunner.class)
+public class IntentReportServiceTest {
+ @Autowired
+ private IntentReportService intentReportService;
+
+ @Autowired
+ ComponentNotificationServiceImpl componentNotificationService;
+
+ @Autowired
+ private ExpectationObjectMapper expectationObjectMapper;
+
+ @Test
+ public void getIntentReportByIntentIdTest() {
+ List<String> allObjectInstances = expectationObjectMapper.getAllObjectInstances();
+ List<String> cll = new ArrayList<>();
+ for (String target : allObjectInstances) {
+ if (target != null && target.contains("cll")) {
+ cll.add(target);
+ }
+ }
+ FulfillmentOperation fulfillmentOperation = new FulfillmentOperation();
+ fulfillmentOperation.setObjectInstances(Collections.singletonList(cll.get(0)));
+ fulfillmentOperation.setOperation("delivery");
+ componentNotificationService.callBack(fulfillmentOperation);
+ IntentReport report = intentReportService.getIntentReportByIntentId("testIntentId111");
+ Assert.assertNotNull(report);
+ }
+}
diff --git a/intentanalysis/src/test/resources/intent.json b/intentanalysis/src/test/resources/intent.json
new file mode 100644
index 0000000..66ebb21
--- /dev/null
+++ b/intentanalysis/src/test/resources/intent.json
@@ -0,0 +1,104 @@
+{
+ "intentId":"testIntentId111",
+ "intentName":"CLLBusiness intent",
+ "intentExpectations":[
+ {
+ "expectationId":"expectationId111",
+ "expectationName":"CLL Delivery Expectation",
+ "expectationType":"DELIVERY",
+ "expectationObject":{
+ "objectType":"CCVPN",
+ "objectInstance":""
+ },
+ "expectationTargets":[
+ {
+ "targetId":"target111-1",
+ "targetName":"source",
+ "targetConditions":[
+ {
+ "conditionId":"condition111-1",
+ "conditionName":"condition of the cll service source",
+ "operator":"EQUALTO",
+ "conditionValue":"tranportEp_src_ID_111_1(onu-1(companyA))",
+ "conditionList":null
+ }
+ ]
+ },
+ {
+ "targetId":"target111-2",
+ "targetName":"destination",
+ "targetConditions":[
+ {
+ "conditionId":"condition111-2",
+ "conditionName":"condition of the cll service destination",
+ "operator":"EQUALTO",
+ "conditionValue":"tranportEp_dst_ID_212_1(cloud-pop-1(cloud 1))",
+ "conditionList":null
+ }
+ ]
+ },
+ {
+ "targetId":"target111-3",
+ "targetName":"bandwidth",
+ "targetConditions":[
+ {
+ "conditionId":"condition111-3",
+ "conditionName":"condition of the cll service bandwidth",
+ "operator":"EQUALTO",
+ "conditionValue":"1000",
+ "conditionList":null
+ }
+ ]
+ }
+ ]
+ },
+ {
+ "expectationId":"expectationId222",
+ "expectationName":"CLL Assurance Expectation",
+ "expectationType":"ASSURANCE",
+ "expectationObject":{
+ "objectType":"CCVPN",
+ "objectInstance":""
+ },
+ "expectationTargets":[
+ {
+ "targetId":"target222-1",
+ "targetName":"bandwidthAssurance",
+ "targetConditions":[
+ {
+ "conditionId":"condition222-1",
+ "conditionName":"condition of the cll service bandwidth assurance",
+ "operator":"EQUALTO",
+ "conditionValue":"true",
+ "conditionList":null
+ }
+ ]
+ }
+ ]
+ },
+ {
+ "expectationId":"expectationId333",
+ "expectationName":"CLL Report Expectation",
+ "expectationType":"REPORT",
+ "expectationObject":{
+ "objectType":"CCVPN",
+ "objectInstance":""
+ },
+ "expectationTargets":[
+ {
+ "targetId":"target333-1",
+ "targetName":"bandwidthAssurance",
+ "targetConditions":[
+ {
+ "conditionId":"condition333-1",
+ "conditionName":"condition of the cll service bandwidth assurance",
+ "operator":"EQUALTO",
+ "conditionValue":"10",
+ "conditionList":null
+ }
+ ]
+ }
+ ]
+ }
+ ]
+}
diff --git a/intentanalysis/src/test/resources/intentdb-test-init.sql b/intentanalysis/src/test/resources/intentdb-test-init.sql
index 25dc9ba..c3abda1 100644
--- a/intentanalysis/src/test/resources/intentdb-test-init.sql
+++ b/intentanalysis/src/test/resources/intentdb-test-init.sql
@@ -90,12 +90,12 @@ create table if not exists intent_management_function_reg_info(
intent_function_type varchar(255)
);
-create table if not exists intent_Event_Record(
- id varchar(255) DEFAULT random_uuid(),
- intentId varchar(255),
- intentName varchar(255),
- intentStatus varchar (225),
- operateType varchar (225),
+create table if not exists intent_event_record(
+ id varchar(255) DEFAULT random_uuid (),
+ intent_id varchar(255),
+ intent_name varchar(255),
+ intent_status varchar (225),
+ operate_type varchar (225),
parent_id varchar(255)
);
diff --git a/intentanalysis/src/test/resources/logback-test.xml b/intentanalysis/src/test/resources/logback-test.xml
index ed1faf9..2d81180 100644
--- a/intentanalysis/src/test/resources/logback-test.xml
+++ b/intentanalysis/src/test/resources/logback-test.xml
@@ -20,7 +20,7 @@
<!-- encoders are assigned the type
ch.qos.logback.classic.encoder.PatternLayoutEncoder by default -->
<encoder>
- <pattern>%d{yyyy-MM-dd HH:mm:ss:SSS} %5p ${PID} --- [%15.15t] %-40.40c{40} : %m%n</pattern>
+ <pattern>%d{yyyy-MM-dd HH:mm:ss:SSS} %5p ${PID} --- [%15.15t] %-40.40c{40}[%L] : %m%n</pattern>
</encoder>
</appender>
@@ -35,7 +35,7 @@
<!-- set immediateFlush to false for much higher logging throughput -->
<immediateFlush>true</immediateFlush>
<encoder>
- <pattern>%d{yyyy-MM-dd HH:mm:ss:SSS} %5p ${PID} --- [%15.15t] %-40.40c{40} : %m%n</pattern>
+ <pattern>%d{yyyy-MM-dd HH:mm:ss:SSS} %5p ${PID} --- [%15.15t] %-40.40c{40}[%L] : %m%n</pattern>
</encoder>
</appender>
@@ -51,7 +51,7 @@
<totalSizeCap>3GB</totalSizeCap>
</rollingPolicy>
<encoder>
- <pattern>>%d{yyyy-MM-dd HH:mm:ss:SSS} %5p ${PID} --- [%15.15t] %-40.40c{40} : %m%n</pattern>
+ <pattern>>%d{yyyy-MM-dd HH:mm:ss:SSS} %5p ${PID} --- [%15.15t] %-40.40c{40}[%L] : %m%n</pattern>
</encoder>
</appender>