98e5364243d282d9da02dc6a3a7a48fc7026a1de
[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.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;
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<ExpectationPo> expectationPoList, String intentId) {
45         for (ExpectationPo expectationPo : expectationPoList) {
46             if (null != expectationPo) {
47                 expectationPo.setIntentPoId(intentId);
48                 stateService.createStateList(expectationPo.getStatePoList(), expectationPo.getExpectationPoId());
49             }
50         }
51         expectationMapper.insertExpectation(expectationPoList);
52     }
53
54     @Override
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);
60         }
61         return expectationList;
62     }
63
64     @Override
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());
70         }
71     }
72
73     @Override
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.");
79         }
80         expectationMapper.updateExpectation(expectationPoList);
81         LOGGER.info("Expectations are successfully updated.");
82     }
83 }