5f21f583ba35cf9da1bfb0bbf2e36fc8ce45174c
[usecase-ui/intent-analysis.git] /
1 /*
2  * Copyright 2022 Huawei Technologies Co., Ltd.
3  *
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
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 package org.onap.usecaseui.intentanalysis.service.impl;
18
19
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;
29
30
31 import java.util.List;
32
33 @Service
34 public class ExpectationServiceImpl implements ExpectationService {
35
36     private static Logger LOGGER = LoggerFactory.getLogger(ExpectationServiceImpl.class);
37     @Autowired
38     private ExpectationMapper expectationMapper;
39
40     @Autowired
41     private StateService stateService;
42
43     @Override
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());
48             }
49         }
50         expectationMapper.insertExpectation(expectationList, intentId);
51     }
52
53     @Override
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);
59         }
60         return expectationList;
61     }
62
63     @Override
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());
69         }
70     }
71
72     @Override
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.");
78         }
79         expectationMapper.updateExpectation(expectationDBList);
80         LOGGER.info("Expectations are successfully updated.");
81     }
82 }