aboutsummaryrefslogtreecommitdiffstats
path: root/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/service/impl/IntentReportServiceImpl.java
diff options
context:
space:
mode:
Diffstat (limited to 'intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/service/impl/IntentReportServiceImpl.java')
-rw-r--r--intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/service/impl/IntentReportServiceImpl.java64
1 files changed, 64 insertions, 0 deletions
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 d4c0f88..5250ead 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
@@ -17,11 +17,13 @@
package org.onap.usecaseui.intentanalysis.service.impl;
import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang.StringUtils;
import org.onap.usecaseui.intentanalysis.bean.models.FulfillmentInfo;
import org.onap.usecaseui.intentanalysis.bean.models.IntentReport;
import org.onap.usecaseui.intentanalysis.bean.models.ResultHeader;
import org.onap.usecaseui.intentanalysis.bean.models.ServiceResult;
import org.onap.usecaseui.intentanalysis.common.ResponseConsts;
+import org.onap.usecaseui.intentanalysis.bean.models.TimeParam;
import org.onap.usecaseui.intentanalysis.exception.DataBaseException;
import org.onap.usecaseui.intentanalysis.mapper.IntentReportFulfillmentInfoMapper;
import org.onap.usecaseui.intentanalysis.mapper.IntentReportMapper;
@@ -37,6 +39,7 @@ import org.springframework.util.CollectionUtils;
import java.util.Collections;
import java.util.List;
+import java.util.StringJoiner;
import java.util.stream.Collectors;
import static org.onap.usecaseui.intentanalysis.common.ResponseConsts.RSEPONSE_SUCCESS;
@@ -110,6 +113,67 @@ public class IntentReportServiceImpl implements IntentReportService {
return intentReportIds;
}
+ @Override
+ public String exportIntentReportByTime(TimeParam param) {
+ if (StringUtils.isEmpty(param.getStartDate()) || StringUtils.isEmpty(param.getEndData())) {
+ log.warn("please enter the correct time");
+ return null;
+ }
+ String intentInstanceId = intentInstanceService.queryIntentInstanceId(param.getIntentId());
+ List<IntentReport> intentReports = getIntentReports(intentInstanceId, param.getStartDate(), param.getEndData());
+ if (CollectionUtils.isEmpty(intentReports)) {
+ log.error("no intent report data");
+ return null;
+ }
+ List<String> objectInstances = objectInstanceMapper.getObjectInstances(param.getIntentId());
+ intentReports.forEach(intentReport -> {
+ String intentReportId = intentReport.getIntentReportId();
+ List<FulfillmentInfo> fulfillmentInfos = intentReportFulfillmentInfoMapper.getFulfillmentInfosByParentId(intentReportId);
+ fulfillmentInfos.forEach(fulfillmentInfo -> fulfillmentInfo.setObjectInstances(objectInstances));
+ intentReport.setFulfillmentInfos(fulfillmentInfos);
+ });
+ return convertToCSV(intentReports);
+ }
+
+ public List<IntentReport> getIntentReports(String intentInstanceId, String startTime, String endTime) {
+ List<IntentReport> intentReportsByTime = intentReportMapper.getIntentReportsByTime(intentInstanceId, startTime, endTime);
+ if (CollectionUtils.isEmpty(intentReportsByTime)) {
+ log.error("no intent report data");
+ }
+ return intentReportsByTime;
+ }
+
+ private String convertToCSV(List<IntentReport> intentReportList) {
+ StringBuilder stringBuilder = new StringBuilder();
+ StringJoiner title = new StringJoiner(",");
+ title.add("intentReportId").add("intentReference")
+ .add("fulfillmentId")
+ .add("fulfillmentStatus")
+ .add("notFulfilledState")
+ .add("notFulfilledReason")
+ .add("achieveValue")
+ .add("objectInstance")
+ .add("reportTime");
+ stringBuilder.append(title).append("\n");
+ intentReportList.forEach(intentReport -> {
+ List<FulfillmentInfo> fulfillmentInfos = intentReport.getFulfillmentInfos();
+ fulfillmentInfos.forEach(fulfillmentInfo -> {
+ StringJoiner data = new StringJoiner(",");
+ data.add(intentReport.getIntentReportId())
+ .add(intentReport.getIntentReference())
+ .add(fulfillmentInfo.getFulfillmentId())
+ .add(fulfillmentInfo.getFulfillmentStatus().getDesc())
+ .add(fulfillmentInfo.getNotFulfilledState().getDesc())
+ .add(fulfillmentInfo.getNotFulfilledReason())
+ .add(fulfillmentInfo.getAchieveValue())
+ .add(fulfillmentInfo.getObjectInstances().toString())
+ .add(intentReport.getReportTime());
+ stringBuilder.append(data).append("\n");
+ });
+ });
+ return stringBuilder.toString();
+ }
+
private FulfillmentInfo getFulfillmentInfo(String intentId) {
FulfillmentInfo fulfillmentInfo = fulfillmentInfoService.getFulfillmentInfo(intentId);
log.info("fulfillmentInfo is {}", fulfillmentInfo);