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.bean.po.ExpectationPo;
21 import org.onap.usecaseui.intentanalysis.bean.po.StatePo;
22 import org.onap.usecaseui.intentanalysis.mapper.ExpectationMapper;
23 import org.onap.usecaseui.intentanalysis.service.ExpectationService;
24 import org.onap.usecaseui.intentanalysis.service.StateService;
25 import org.springframework.beans.factory.annotation.Autowired;
26 import org.springframework.stereotype.Service;
27 import org.slf4j.Logger;
28 import org.slf4j.LoggerFactory;
31 import java.util.List;
34 public class ExpectationServiceImpl implements ExpectationService {
36 private static Logger LOGGER = LoggerFactory.getLogger(ExpectationServiceImpl.class);
38 private ExpectationMapper expectationMapper;
41 private StateService stateService;
44 public void createExpectationList(List<ExpectationPo> expectationPoList, String intentId) {
45 for (ExpectationPo expectationPo : expectationPoList) {
46 if (null != expectationPo) {
47 expectationPo.setIntentPoId(intentId);
48 stateService.createStateList(expectationPo.getStatePoList(), expectationPo.getExpectationPoId());
51 expectationMapper.insertExpectation(expectationPoList);
55 public List<ExpectationPo> getExpectationListByIntentId(String intentId) {
56 List<ExpectationPo> expectationList = expectationMapper.selectExpectationByIntentId(intentId);
57 for (ExpectationPo expectation : expectationList) {
58 List<StatePo> stateList = stateService.getStateListByExpectationId(expectation.getExpectationPoId());
59 expectation.setStatePoList(stateList);
61 return expectationList;
65 public void deleteExpectationListById(String intentId) {
66 List<ExpectationPo> expectationList = expectationMapper.selectExpectationByIntentId(intentId);
67 expectationMapper.deleteExpectationByIntentId(intentId);
68 for (ExpectationPo expectation : expectationList) {
69 stateService.deleteStateListByExpectationId(expectation.getExpectationPoId());
74 public void updateExpectationListById(List<ExpectationPo> expectationPoList, String intentId) {
75 List<ExpectationPo> expectationList = expectationMapper.selectExpectationByIntentId(intentId);
76 if (expectationList == null) {
77 LOGGER.error("Intent ID {} doesn't exist in database.", intentId);
78 throw new IllegalArgumentException("This intent ID doesn't exist in database.");
80 expectationMapper.updateExpectation(expectationPoList);
81 LOGGER.info("Expectations are successfully updated.");