2 * Copyright 2022 Huawei Technologies Co., Ltd.
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;
20 import org.onap.usecaseui.intentanalysis.common.ResponseConsts;
21 import org.onap.usecaseui.intentanalysis.exception.DataBaseException;
22 import org.slf4j.Logger;
23 import org.slf4j.LoggerFactory;
24 import org.springframework.beans.factory.annotation.Autowired;
25 import org.springframework.stereotype.Service;
26 import org.onap.usecaseui.intentanalysis.bean.models.FulfillmentInfo;
27 import org.onap.usecaseui.intentanalysis.mapper.FulfillmentInfoMapper;
28 import org.onap.usecaseui.intentanalysis.service.FulfillmentInfoService;
29 import lombok.extern.slf4j.Slf4j;
34 public class FulfillmentInfoServiceImpl implements FulfillmentInfoService {
37 private FulfillmentInfoMapper fulfillmentInfoMapper;
40 private FulfillmentInfoService fulfillmentInfoService;
43 public void createFulfillmentInfo(FulfillmentInfo fulfillmentInfo, String parentId) {
44 if (fulfillmentInfo != null) {
45 if (fulfillmentInfoMapper.insertFulfillmentInfo(fulfillmentInfo, parentId) < 1) {
46 String msg = "Failed to create fulfillment info to database.";
48 throw new DataBaseException(msg, ResponseConsts.RET_INSERT_DATA_FAIL);
50 log.info("Successfully created fulfillment info to database.");
55 public void deleteFulfillmentInfo(String parentId) {
56 if (fulfillmentInfoService.getFulfillmentInfo(parentId) != null) {
57 if (fulfillmentInfoMapper.deleteFulfillmentInfo(parentId) < 1) {
58 String msg = "Failed to delete fulfillment info to database.";
60 throw new DataBaseException(msg, ResponseConsts.RET_DELETE_DATA_FAIL);
62 log.info("Successfully deleted fulfillment info to database.");
67 public void updateFulfillmentInfo(FulfillmentInfo fulfillmentInfo, String parentId) {
69 FulfillmentInfo fulfillmentInfoDB = fulfillmentInfoService.getFulfillmentInfo(parentId);
70 if (fulfillmentInfoDB == null && fulfillmentInfo != null) {
71 fulfillmentInfoService.createFulfillmentInfo(fulfillmentInfo, parentId);
72 } else if (fulfillmentInfoDB != null && fulfillmentInfo == null) {
73 fulfillmentInfoService.deleteFulfillmentInfo(parentId);
74 } else if (fulfillmentInfoDB != null) {
75 if (fulfillmentInfoMapper.updateFulfillmentInfo(fulfillmentInfo, parentId) < 1) {
76 String msg = "Failed to update fulfillment info to database.";
78 throw new DataBaseException(msg, ResponseConsts.RET_UPDATE_DATA_FAIL);
80 log.info("Successfully updated fulfillment info to database.");
85 public FulfillmentInfo getFulfillmentInfo(String parentId) {
86 FulfillmentInfo fulfillmentInfo = fulfillmentInfoMapper.selectFulfillmentInfo(parentId);
87 if (fulfillmentInfo == null) {
88 log.info(String.format("FulfillmentInfo is null, parentId = %s", parentId));
90 return fulfillmentInfo;