2 * Copyright (C) 2023 CMCC, Inc. and others. All rights reserved.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package org.onap.usecaseui.intentanalysis.service.impl;
19 import lombok.extern.slf4j.Slf4j;
20 import org.onap.usecaseui.intentanalysis.bean.models.FulfillmentInfo;
21 import org.onap.usecaseui.intentanalysis.bean.models.IntentReport;
22 import org.onap.usecaseui.intentanalysis.common.ResponseConsts;
23 import org.onap.usecaseui.intentanalysis.exception.DataBaseException;
24 import org.onap.usecaseui.intentanalysis.mapper.IntentReportFulfillmentInfoMapper;
25 import org.onap.usecaseui.intentanalysis.mapper.IntentReportMapper;
26 import org.onap.usecaseui.intentanalysis.mapper.ObjectInstanceMapper;
27 import org.onap.usecaseui.intentanalysis.service.FulfillmentInfoService;
28 import org.onap.usecaseui.intentanalysis.service.IntentReportService;
29 import org.onap.usecaseui.intentanalysis.util.CommonUtil;
30 import org.springframework.beans.factory.annotation.Autowired;
31 import org.springframework.stereotype.Service;
32 import org.springframework.util.CollectionUtils;
34 import java.util.Collections;
35 import java.util.List;
39 public class IntentReportServiceImpl implements IntentReportService {
42 private FulfillmentInfoService fulfillmentInfoService;
45 private ObjectInstanceMapper objectInstanceMapper;
48 private IntentReportFulfillmentInfoMapper intentReportFulfillmentInfoMapper;
51 private IntentReportMapper intentReportMapper;
54 public IntentReport getIntentReportByIntentId(String intentId) {
55 FulfillmentInfo fulfillmentInfo = fulfillmentInfoService.getFulfillmentInfo(intentId);
56 System.out.println(fulfillmentInfo);
57 if (fulfillmentInfo == null) {
58 log.error("get fulfillmentInfo is failed,intentId is {}", intentId);
59 String msg = "get fulfillmentInfo is failed";
60 throw new DataBaseException(msg, ResponseConsts.RET_QUERY_DATA_EMPTY);
62 fulfillmentInfo.setFulfillmentId(intentId);
63 List<String> objectInstances = objectInstanceMapper.getObjectInstances(intentId);
64 if (CollectionUtils.isEmpty(objectInstances)) {
65 log.error("get objectInstance is failed,intentId is {}", intentId);
66 String msg = "get objectInstance is failed";
67 throw new DataBaseException(msg, ResponseConsts.RET_QUERY_DATA_EMPTY);
69 String uUid = CommonUtil.getUUid();
70 fulfillmentInfo.setObjectInstances(objectInstances);
71 IntentReport intentReport = new IntentReport();
72 intentReport.setIntentReportId(uUid);
73 intentReport.setIntentReference("intentReference");
74 intentReport.setFulfillmentInfos(Collections.singletonList(fulfillmentInfo));
75 intentReport.setReportTime(CommonUtil.getTime());
77 int num = intentReportMapper.insertIntentReport(intentReport);
79 String msg = "Failed to insert intent report to database.";
81 throw new DataBaseException(msg, ResponseConsts.RET_INSERT_DATA_FAIL);
83 int fulfillmentNum = intentReportFulfillmentInfoMapper.insertIntentReportFulfillment(fulfillmentInfo, uUid);
84 if (fulfillmentNum < 1) {
85 String msg = "Failed to insert fulfillmentInfo to database.";
87 throw new DataBaseException(msg, ResponseConsts.RET_INSERT_DATA_FAIL);