--- /dev/null
+/*
+ * 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.bean.models;
+
+import lombok.Data;
+import lombok.ToString;
+
+@Data
+@ToString
+public class TimeParam {
+ private String intentId;
+ private String startDate;
+ private String endData;
+}
package org.onap.usecaseui.intentanalysis.controller;
import lombok.extern.log4j.Log4j2;
+import org.apache.commons.lang3.StringUtils;
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.*;
+import java.nio.charset.StandardCharsets;
+
@Log4j2
@RestController
@RequestMapping("/intentReport")
@PathVariable("intentId") String intentId) {
return intentReportService.getIntentReportByIntentId(intentId);
}
+
+ @PostMapping(value = "/export")
+ public ResponseEntity<byte[]> exportIntentReportByTime(@RequestBody TimeParam param) {
+ String csvData = intentReportService.exportIntentReportByTime(param);
+ byte[] bytes = StringUtils.isEmpty(csvData) ? new byte[0] : csvData.getBytes(StandardCharsets.UTF_8);
+ return ResponseEntity.ok()
+ .body(bytes);
+ }
}
import org.apache.ibatis.annotations.Param;
import org.onap.usecaseui.intentanalysis.bean.models.FulfillmentInfo;
+import java.util.List;
+
@Mapper
public interface IntentReportFulfillmentInfoMapper {
- int insertIntentReportFulfillment(@Param(value = "fulfillmentInfo") FulfillmentInfo fulfillmentInfo,@Param(value = "parentId") String parentId);
+ int insertIntentReportFulfillment(@Param(value = "fulfillmentInfo") FulfillmentInfo fulfillmentInfo, @Param(value = "parentId") String parentId);
+
+ List<FulfillmentInfo> getFulfillmentInfosByParentId(@Param(value = "parentId") String parentId);
}
int insertIntentReport(@Param(value = "intentReport") IntentReport intentReport);
List<String> getIntentReportIds(@Param(value = "intentReference") String intentReference);
+
+ List<IntentReport> getIntentReportsByTime(@Param(value = "intentInstanceId") String intentInstanceId,
+ @Param(value = "startTime") String startTime,
+ @Param(value = "endTime") String endTime);
}
package org.onap.usecaseui.intentanalysis.service;
import org.onap.usecaseui.intentanalysis.bean.models.ServiceResult;
+import org.onap.usecaseui.intentanalysis.bean.models.TimeParam;
import java.util.List;
void saveIntentReportByIntentId(String intentId);
List<String> getIntentReportIds(String intentReference);
+
+ String exportIntentReportByTime(TimeParam param);
}
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;
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;
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);
context-path: /api/usecaseui-intent-analysis/v1
spring:
datasource:
- url: jdbc:postgresql://${POSTGRES_IP:127.0.0.1}:${POSTGRES_PORT:5432}/${POSTGRES_DB_NAME:intentdb}
+ url: jdbc:postgresql://${POSTGRES_IP:127.0.0.1}:${POSTGRES_PORT:5432}/${POSTGRES_DB_NAME}
username: ${POSTGRES_USERNAME}
password: ${POSTGRES_PASSWORD}
driver-class-name: org.postgresql.Driver
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>
+ <select id="getFulfillmentInfosByParentId"
+ resultType="org.onap.usecaseui.intentanalysis.bean.models.FulfillmentInfo">
+ select fulfillment_info_id fulfillmentId,
+ fulfillment_info_status fulfillmentStatus,
+ not_fulfilled_state notFulfilledState,
+ not_fulfilled_reason notFulfilledReason,
+ achieve_value achieveValue
+ from intent_report_fulfillment_info
+ where parent_id = #{parentId}
+ </select>
</mapper>
from intent_report
where intent_reference = #{intentReference}
</select>
+
+ <select id="getIntentReportsByTime" resultType="org.onap.usecaseui.intentanalysis.bean.models.IntentReport">
+ select intent_report_id intentReportId,
+ intent_reference intentReference,
+ to_char(report_time,'yyyy-mm-dd HH24:mi:ss') reportTime
+ from intent_report
+ where report_time >= to_timestamp(#{startTime},'yyyy-MM-dd HH24:mi:ss')
+ and report_time < to_timestamp(#{endTime},'yyyy-MM-dd HH24:mi:ss')
+ and intent_reference = #{intentInstanceId}
+ </select>
</mapper>