diff options
author | Keguang He <hekeguang@chinamobile.com> | 2022-09-01 07:44:55 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2022-09-01 07:44:55 +0000 |
commit | d004c121a83dfea3654d9ac47bd558e2237b7e6f (patch) | |
tree | 103640f096a16e868037470977bf77d4260258d8 /intentanalysis/src/main | |
parent | 63492d1459f46c889ba93641ec51ab8928cc0127 (diff) | |
parent | 54e7ca4ddf183cd15bd7afff0c53b1970698432b (diff) |
Merge "Add UT to intent service"
Diffstat (limited to 'intentanalysis/src/main')
7 files changed, 7 insertions, 258 deletions
diff --git a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/mapper/IntentMapper.java b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/mapper/IntentMapper.java index cc253ab..1178b6d 100644 --- a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/mapper/IntentMapper.java +++ b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/mapper/IntentMapper.java @@ -37,5 +37,5 @@ public interface IntentMapper { int deleteIntent(@Param(value = "intentId") String intentId); - List<Intent> getIntentByName(@Param(value = "name") String name); + List<Intent> getIntentByName(@Param(value = "intentName") String name); } diff --git a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/mapper/StateMapper.java b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/mapper/StateMapper.java deleted file mode 100644 index 10538c4..0000000 --- a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/mapper/StateMapper.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright 2022 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.usecaseui.intentanalysis.mapper; - - -import java.util.List; -import org.apache.ibatis.annotations.Mapper; -import org.apache.ibatis.annotations.Param; -import org.onap.usecaseui.intentanalysis.bean.models.Expectation; -import org.onap.usecaseui.intentanalysis.bean.models.State; - - -@Mapper - -public interface StateMapper { - - int insertStateList(@Param(value = "stateList") List<State> state, - @Param(value = "expectationId") String expectationId); - - List<State> selectStateByExpectation(@Param(value = "expectationId") String expectationId); - - int deleteStateByExpectationId(@Param(value = "expectationId") String expectationId); - - int updateState(@Param(value = "state") State state); - - int insertState(@Param(value = "state") State state, @Param(value = "expectationId") String expectationId); - - int deleteStateById(@Param(value = "stateId") String stateId); -} diff --git a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/service/StateService.java b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/service/StateService.java deleted file mode 100644 index d2d66c7..0000000 --- a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/service/StateService.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright 2022 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.usecaseui.intentanalysis.service; - - -import java.util.List; -import org.onap.usecaseui.intentanalysis.bean.models.State; - - -public interface StateService { - - void createStateList(List<State> stateList, String expectationId); - - void deleteStateListByExpectationId(String expectationId); - - void updateStateListByExpectationId(List<State> stateList, String expectationId); - - List<State> getStateListByExpectationId(String expectationId); - - void createState(State state, String expectationId); - - void deleteStateById(String stateId); -} diff --git a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/service/impl/IntentServiceImpl.java b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/service/impl/IntentServiceImpl.java index 952b6dd..bb1759c 100644 --- a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/service/impl/IntentServiceImpl.java +++ b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/service/impl/IntentServiceImpl.java @@ -87,7 +87,9 @@ public class IntentServiceImpl implements IntentService { public Intent getIntent(String intentId) { Intent intent = intentMapper.selectIntent(intentId); if (intent != null) { - intent.setIntentExpectations(expectationService.getIntentExpectationList(intent.getIntentId())); + intent.setIntentExpectations(expectationService.getIntentExpectationList(intentId)); + intent.setIntentContexts(contextService.getContextList(intentId)); + intent.setIntentFulfilmentInfo(fulfilmentInfoService.getFulfilmentInfo(intentId)); } else { log.info(String.format("Intent is null, intentId = %s", intentId)); } @@ -140,6 +142,8 @@ public class IntentServiceImpl implements IntentService { if (!CollectionUtils.isEmpty(intentList)) { for (Intent intent : intentList) { intent.setIntentExpectations(expectationService.getIntentExpectationList(intent.getIntentId())); + intent.setIntentContexts(contextService.getContextList(intent.getIntentId())); + intent.setIntentFulfilmentInfo(fulfilmentInfoService.getFulfilmentInfo(intent.getIntentId())); } } else { diff --git a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/service/impl/StateServiceImpl.java b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/service/impl/StateServiceImpl.java deleted file mode 100644 index b9c7b95..0000000 --- a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/service/impl/StateServiceImpl.java +++ /dev/null @@ -1,122 +0,0 @@ -/* - * Copyright 2022 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.usecaseui.intentanalysis.service.impl; - - -import lombok.extern.slf4j.Slf4j; -import org.onap.usecaseui.intentanalysis.bean.models.State; -import org.onap.usecaseui.intentanalysis.common.ResponseConsts; -import org.onap.usecaseui.intentanalysis.exception.DataBaseException; -import org.onap.usecaseui.intentanalysis.mapper.StateMapper; -import org.onap.usecaseui.intentanalysis.service.StateService; - -import java.util.ArrayList; -import java.util.List; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; - - -@Service -@Slf4j -public class StateServiceImpl implements StateService { - - @Autowired - private StateMapper stateMapper; - - @Autowired - private StateService stateService; - - @Override - public void createStateList(List<State> stateList, String expectationId) { - int res = stateMapper.insertStateList(stateList, expectationId); - if (res < 1) { - String msg = "Create state to database failed."; - log.error(msg); - throw new DataBaseException(msg, ResponseConsts.RET_INSERT_DATA_FAIL); - } - } - - @Override - public List<State> getStateListByExpectationId(String expectationId) { - List<State> stateList = stateMapper.selectStateByExpectation(expectationId); - if (stateList == null) { - String msg = String.format("State: Expectation id %s doesn't exist in database.", expectationId); - log.error(msg); - throw new DataBaseException(msg, ResponseConsts.RET_QUERY_DATA_EMPTY); - } - return stateList; - } - - @Override - public void deleteStateListByExpectationId(String expectationId) { - if (stateMapper.deleteStateByExpectationId(expectationId) < 1) { - String msg = "Delete state in database failed."; - log.error(msg); - throw new DataBaseException(msg, ResponseConsts.RET_DELETE_DATA_FAIL); - } - } - - @Override - public void updateStateListByExpectationId(List<State> stateList, String expectationId) { - List<State> stateDBList = stateMapper.selectStateByExpectation(expectationId); - if (stateDBList == null) { - String msg = String.format("Expectation id %s doesn't exist in database.", expectationId); - log.error(msg); - throw new DataBaseException(msg, ResponseConsts.RET_QUERY_DATA_EMPTY); - } - List<String> stateDBIdList = new ArrayList<>(); - for (State stateDB : stateDBList) { - stateDBIdList.add(stateDB.getStateId()); - } - for (State state : stateList) { - if (stateDBIdList.contains(state.getStateId())) { - int res = stateMapper.updateState(state); - if (res < 1) { - String msg = "Update state in database failed."; - log.error(msg); - throw new DataBaseException(msg, ResponseConsts.RET_UPDATE_DATA_FAIL); - } - stateDBIdList.remove(state.getStateId()); - } else { - stateService.createState(state, expectationId); - } - } - for (String stateDBId : stateDBIdList) { - stateService.deleteStateById(stateDBId); - } - log.info("States are successfully updated."); - } - - @Override - public void createState(State state, String expectationId) { - if (stateMapper.insertState(state, expectationId) < 1) { - String msg = "Create state to database failed."; - log.error(msg); - throw new DataBaseException(msg, ResponseConsts.RET_INSERT_DATA_FAIL); - } - } - - @Override - public void deleteStateById(String stateId) { - if (stateMapper.deleteStateById(stateId) < 1) { - String msg = "Delete state in database failed."; - log.error(msg); - throw new DataBaseException(msg, ResponseConsts.RET_DELETE_DATA_FAIL); - } - } -}
\ No newline at end of file diff --git a/intentanalysis/src/main/resources/mybatis/sql/IntentMapper.xml b/intentanalysis/src/main/resources/mybatis/sql/IntentMapper.xml index c5d3b3d..57c8952 100644 --- a/intentanalysis/src/main/resources/mybatis/sql/IntentMapper.xml +++ b/intentanalysis/src/main/resources/mybatis/sql/IntentMapper.xml @@ -34,7 +34,7 @@ <select id="getIntentByName" resultType="org.onap.usecaseui.intentanalysis.bean.models.Intent"> select intent_id intentId, intent_name intentName from intent - where intent_name like "%"#{intent.intentName}"%" + where intent_name like #{intentName} </select> </mapper>
\ No newline at end of file diff --git a/intentanalysis/src/main/resources/mybatis/sql/StateMapper.xml b/intentanalysis/src/main/resources/mybatis/sql/StateMapper.xml deleted file mode 100644 index d103015..0000000 --- a/intentanalysis/src/main/resources/mybatis/sql/StateMapper.xml +++ /dev/null @@ -1,53 +0,0 @@ -<?xml version="1.0" encoding="UTF-8" ?> -<!DOCTYPE mapper - PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> -<mapper namespace="org.onap.usecaseui.intentanalysis.mapper.StateMapper"> - - <select id="selectStateByExpectation" resultType="org.onap.usecaseui.intentanalysis.bean.models.State"> - select state_id stateId, state_name stateName, condition, - is_satisfied isSatisfied - from state - where expectation_id = #{expectationId} - </select> - - <insert id="insertStateList" parameterType="java.util.ArrayList"> - <if test="stateList != null"> - insert into state(state_id, state_name, expectation_id, is_satisfied, condition) - values - <foreach collection="stateList" index="index" item="item" separator=","> - (#{item.stateId}, #{item.stateName}, #{expectationId}, #{item.isSatisfied}, #{item.condition}) - </foreach> - </if> - </insert> - - <delete id="deleteStateByExpectationId"> - delete - from state - where expectation_id = #{expectationId} - </delete> - - <insert id="insertState"> - <if test="state != null"> - insert into state(state_id, state_name, expectation_id, is_satisfied, condition) - values (#{state.stateId}, #{state.stateName}, #{expectationId}, #{state.isSatisfied}, #{state.condition}) - </if> - </insert> - - <update id="updateState" parameterType="java.util.List"> - update state - <trim prefix="set" suffixOverrides=","> - <if test="stateName != null">state_name = #{stateName},</if> - <if test="isSatisfied != null">is_satisfied = #{isSatisfied},</if> - <if test="condition != null">condition = #{condition},</if> - </trim> - where state_id = #{stateId} - </update> - - <delete id="deleteStateById"> - delete - from state - where state_id = #{stateId} - </delete> - -</mapper>
\ No newline at end of file |