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.FulfilmentInfo;
27 import org.onap.usecaseui.intentanalysis.mapper.FulfilmentInfoMapper;
28 import org.onap.usecaseui.intentanalysis.service.FulfilmentInfoService;
29 import lombok.extern.slf4j.Slf4j;
34 public class FulfilmentInfoServiceImpl implements FulfilmentInfoService {
37 private FulfilmentInfoMapper fulfilmentInfoMapper;
40 private FulfilmentInfoService fulfilmentInfoService;
43 public void createFulfilmentInfo(FulfilmentInfo fulfilmentInfo, String parentId) {
44 if (fulfilmentInfo != null) {
45 if (fulfilmentInfoMapper.insertFulfilmentInfo(fulfilmentInfo, parentId) < 1) {
46 String msg = "Failed to create fulfilment info to database.";
48 throw new DataBaseException(msg, ResponseConsts.RET_INSERT_DATA_FAIL);
50 log.info("Successfully created fulfilment info to database.");
55 public void deleteFulfilmentInfo(String parentId) {
56 if (fulfilmentInfoService.getFulfilmentInfo(parentId) != null) {
57 if (fulfilmentInfoMapper.deleteFulfilmentInfo(parentId) < 1) {
58 String msg = "Failed to delete fulfilment info to database.";
60 throw new DataBaseException(msg, ResponseConsts.RET_DELETE_DATA_FAIL);
62 log.info("Successfully deleted fulfilment info to database.");
67 public void updateFulfilmentInfo(FulfilmentInfo fulfilmentInfo, String parentId) {
69 FulfilmentInfo fulfillmentInfoDB = fulfilmentInfoService.getFulfilmentInfo(parentId);
70 if (fulfillmentInfoDB == null && fulfilmentInfo != null) {
71 fulfilmentInfoService.createFulfilmentInfo(fulfilmentInfo, parentId);
72 } else if (fulfillmentInfoDB != null && fulfilmentInfo == null) {
73 fulfilmentInfoService.deleteFulfilmentInfo(parentId);
74 } else if (fulfillmentInfoDB != null) {
75 if (fulfilmentInfoMapper.updateFulfilmentInfo(fulfilmentInfo, parentId) < 1) {
76 String msg = "Failed to update fulfilment info to database.";
78 throw new DataBaseException(msg, ResponseConsts.RET_UPDATE_DATA_FAIL);
80 log.info("Successfully updated fulfilment info to database.");
85 public FulfilmentInfo getFulfilmentInfo(String parentId) {
86 FulfilmentInfo fulfilmentInfo = fulfilmentInfoMapper.selectFulfilmentInfo(parentId);
87 if (fulfilmentInfo == null) {
88 log.info(String.format("FulfilmentInfo is null, parentId = %s", parentId));
90 return fulfilmentInfo;