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.models.Expectation;
21 import org.onap.usecaseui.intentanalysis.bean.models.State;
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<Expectation> expectationList, String intentId) {
45 for (Expectation expectation : expectationList) {
46 if (null != expectation) {
47 stateService.createStateList(expectation.getStateList(), expectation.getExpectationId());
50 expectationMapper.insertExpectation(expectationList, intentId);
54 public List<Expectation> getExpectationListByIntentId(String intentId) {
55 List<Expectation> expectationList = expectationMapper.selectExpectationByIntentId(intentId);
56 for (Expectation expectation : expectationList) {
57 List<State> stateList = stateService.getStateListByExpectationId(expectation.getExpectationId());
58 expectation.setStateList(stateList);
60 return expectationList;
64 public void deleteExpectationListById(String intentId) {
65 List<Expectation> expectationList = expectationMapper.selectExpectationByIntentId(intentId);
66 expectationMapper.deleteExpectationByIntentId(intentId);
67 for (Expectation expectation : expectationList) {
68 stateService.deleteStateListByExpectationId(expectation.getExpectationId());
73 public void updateExpectationListById(List<Expectation> expectationList, String intentId) {
74 List<Expectation> expectationDBList = expectationMapper.selectExpectationByIntentId(intentId);
75 if (expectationDBList == null) {
76 LOGGER.error("Intent ID {} doesn't exist in database.", intentId);
77 throw new IllegalArgumentException("This intent ID doesn't exist in database.");
79 expectationMapper.updateExpectation(expectationDBList);
80 LOGGER.info("Expectations are successfully updated.");