aboutsummaryrefslogtreecommitdiffstats
path: root/intentanalysis/src
diff options
context:
space:
mode:
authorzhangfan345 <zhangfan345@huawei.com>2022-07-30 10:38:41 +0800
committerFan Zhang <zhangfan345@huawei.com>2022-08-02 06:19:11 +0000
commit731c8ac3faac6b00bc39bdf2e3a0b6a511f94431 (patch)
tree0cf0a8f46018deacbff703d4e1456e8233c8f9ff /intentanalysis/src
parenta51fa2e8573a8463109e7c8b1ed6938c9488fb21 (diff)
Add update function in intent service
Signed-off-by: zhangfan345 <zhangfan345@huawei.com> Issue-ID: USECASEUI-706 Change-Id: I0f027fd8b8876e1b24cbb40ecc50bacc20fa9837
Diffstat (limited to 'intentanalysis/src')
-rw-r--r--intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/mapper/ExpectationMapper.java7
-rw-r--r--intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/mapper/StateMapper.java9
-rw-r--r--intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/service/ExpectationService.java4
-rw-r--r--intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/service/StateService.java4
-rw-r--r--intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/service/impl/ExpectationServiceImpl.java36
-rw-r--r--intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/service/impl/IntentServiceImpl.java10
-rw-r--r--intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/service/impl/StateServiceImpl.java42
-rw-r--r--intentanalysis/src/main/resources/mybatis/sql/ExpectationMapper.xml22
-rw-r--r--intentanalysis/src/main/resources/mybatis/sql/IntentMapper.xml1
-rw-r--r--intentanalysis/src/main/resources/mybatis/sql/StateMapper.xml23
10 files changed, 142 insertions, 16 deletions
diff --git a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/mapper/ExpectationMapper.java b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/mapper/ExpectationMapper.java
index c05a344..b53a01b 100644
--- a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/mapper/ExpectationMapper.java
+++ b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/mapper/ExpectationMapper.java
@@ -23,12 +23,15 @@ import java.util.List;
@Mapper
public interface ExpectationMapper {
- void insertExpectation(@Param(value = "expectationList") List<Expectation> expectationList, @Param(value = "intentId") String intentId);
+ void insertExpectationList(@Param(value = "expectationList") List<Expectation> expectationList, @Param(value = "intentId") String intentId);
List<Expectation> selectExpectationByIntentId(String intentId);
void deleteExpectationByIntentId(String intentId);
- void updateExpectation(List<Expectation> expectation);
+ void updateExpectation(Expectation expectation);
+ void insertExpectation(@Param(value = "expectation") Expectation expectation, @Param(value = "intentId") String intentId);
+
+ void deleteExpectationById(String expectationId);
}
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
index ab7e47b..54a1eb4 100644
--- a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/mapper/StateMapper.java
+++ b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/mapper/StateMapper.java
@@ -18,15 +18,22 @@ package org.onap.usecaseui.intentanalysis.mapper;
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;
import java.util.List;
@Mapper
public interface StateMapper {
- void insertState(@Param(value = "stateList") List<State> state, @Param(value = "expectationId") String expectationId);
+ void insertStateList(@Param(value = "stateList") List<State> state, @Param(value = "expectationId") String expectationId);
List<State> selectStateByExpectation(String expectationId);
void deleteStateByExpectationId(String expectationId);
+
+ void updateState(State state);
+
+ void insertState(@Param(value = "state") State state, @Param(value = "expectationId") String expectationId);
+
+ void deleteStateById(String stateId);
}
diff --git a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/service/ExpectationService.java b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/service/ExpectationService.java
index 8d0759f..ba51de1 100644
--- a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/service/ExpectationService.java
+++ b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/service/ExpectationService.java
@@ -30,4 +30,8 @@ public interface ExpectationService {
void updateExpectationListById(List<Expectation> expectationList, String intentId);
List<Expectation> getExpectationListByIntentId(String intentId);
+
+ void insertExpectation(Expectation expectation, String intentId);
+
+ void deleteExpectationById(String expectationId);
}
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
index 187f964..6ee82d6 100644
--- a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/service/StateService.java
+++ b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/service/StateService.java
@@ -29,4 +29,8 @@ public interface StateService {
void updateStateListByExpectationId(List<State> stateList, String expectationId);
List<State> getStateListByExpectationId(String expectationId);
+
+ void insertState(State state, String expectationId);
+
+ void deleteStateById(String stateId);
}
diff --git a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/service/impl/ExpectationServiceImpl.java b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/service/impl/ExpectationServiceImpl.java
index 5f21f58..5a79213 100644
--- a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/service/impl/ExpectationServiceImpl.java
+++ b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/service/impl/ExpectationServiceImpl.java
@@ -28,6 +28,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import java.util.ArrayList;
import java.util.List;
@Service
@@ -40,6 +41,9 @@ public class ExpectationServiceImpl implements ExpectationService {
@Autowired
private StateService stateService;
+ @Autowired
+ private ExpectationService expectationService;
+
@Override
public void createExpectationList(List<Expectation> expectationList, String intentId) {
for (Expectation expectation : expectationList) {
@@ -47,14 +51,14 @@ public class ExpectationServiceImpl implements ExpectationService {
stateService.createStateList(expectation.getStateList(), expectation.getExpectationId());
}
}
- expectationMapper.insertExpectation(expectationList, intentId);
+ expectationMapper.insertExpectationList(expectationList, intentId);
}
@Override
public List<Expectation> getExpectationListByIntentId(String intentId) {
List<Expectation> expectationList = expectationMapper.selectExpectationByIntentId(intentId);
for (Expectation expectation : expectationList) {
- List<State> stateList = stateService.getStateListByExpectationId(expectation.getExpectationId());
+ List<State> stateList = stateService.getStateListByExpectationId(expectation.getExpectationId());
expectation.setStateList(stateList);
}
return expectationList;
@@ -76,7 +80,33 @@ public class ExpectationServiceImpl implements ExpectationService {
LOGGER.error("Intent ID {} doesn't exist in database.", intentId);
throw new IllegalArgumentException("This intent ID doesn't exist in database.");
}
- expectationMapper.updateExpectation(expectationDBList);
+ List<String> expectationDBIdList = new ArrayList<>();
+ for (Expectation expectationDB : expectationDBList) {
+ expectationDBIdList.add(expectationDB.getExpectationId());
+ }
+
+ for (Expectation expectation : expectationList) {
+ if (expectationDBIdList.contains(expectation.getExpectationId())) {
+ stateService.updateStateListByExpectationId(expectation.getStateList(), expectation.getExpectationId());
+ expectationMapper.updateExpectation(expectation);
+ expectationDBIdList.remove(expectation.getExpectationId());
+ } else {
+ expectationService.insertExpectation(expectation, intentId);
+ }
+ }
+ for (String expectationDBId : expectationDBIdList) {
+ expectationService.deleteExpectationById(expectationDBId);
+ }
LOGGER.info("Expectations are successfully updated.");
}
+
+ @Override
+ public void insertExpectation(Expectation expectation, String intentId) {
+ expectationMapper.insertExpectation(expectation, intentId);
+ }
+
+ @Override
+ public void deleteExpectationById(String expectationId) {
+ expectationMapper.deleteExpectationById(expectationId);
+ }
}
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 7372510..aaf824e 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
@@ -77,14 +77,14 @@ public class IntentServiceImpl implements IntentService {
@Override
public Intent updateIntent(Intent intent) {
- String intentId = intent.getIntentId();
- Intent intentDB = intentMapper.selectIntentById(intentId);
+ Intent intentDB = intentMapper.selectIntentById(intent.getIntentId());
if (intentDB == null) {
- LOGGER.error("intent id {} not exists in db.", intentId);
+ LOGGER.error("intent id {} not exists in db.", intent.getIntentId());
}
- intentMapper.updateIntent(intentDB);
+ expectationService.updateExpectationListById(intent.getExpectationList(), intent.getIntentId());
+ intentMapper.updateIntent(intent);
LOGGER.info("update intent successfully.");
- return intentMapper.selectIntentById(intentId);
+ return intentMapper.selectIntentById(intent.getIntentId());
}
@Override
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
index 134e84a..e154446 100644
--- 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
@@ -20,20 +20,28 @@ package org.onap.usecaseui.intentanalysis.service.impl;
import org.onap.usecaseui.intentanalysis.bean.models.State;
import org.onap.usecaseui.intentanalysis.mapper.StateMapper;
import org.onap.usecaseui.intentanalysis.service.StateService;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
+import java.util.ArrayList;
import java.util.List;
@Service
public class StateServiceImpl implements StateService {
+ private static Logger LOGGER = LoggerFactory.getLogger(StateServiceImpl.class);
+
@Autowired
private StateMapper stateMapper;
+ @Autowired
+ private StateService stateService;
+
@Override
public void createStateList(List<State> stateList, String expectationId) {
- stateMapper.insertState(stateList, expectationId);
+ stateMapper.insertStateList(stateList, expectationId);
}
@Override
@@ -48,7 +56,37 @@ public class StateServiceImpl implements StateService {
}
@Override
- public void updateStateListByExpectationId(List<State> stateList, String expectationId){
+ public void updateStateListByExpectationId(List<State> stateList, String expectationId) {
+ List<State> stateDBList = stateMapper.selectStateByExpectation(expectationId);
+ if (stateDBList == null) {
+ LOGGER.error("Expectation ID {} doesn't exist in database.", expectationId);
+ throw new IllegalArgumentException("This expectation ID doesn't exist in database.");
+ }
+ List<String> stateDBIdList = new ArrayList<>();
+ for (State stateDB : stateDBList) {
+ stateDBIdList.add(stateDB.getStateId());
+ }
+ for (State state : stateList) {
+ if (stateDBIdList.contains(state.getStateId())) {
+ stateMapper.updateState(state);
+ stateDBIdList.remove(state.getStateId());
+ } else {
+ stateService.insertState(state, expectationId);
+ }
+ }
+ for (String stateDBId : stateDBIdList) {
+ stateService.deleteStateById(stateDBId);
+ }
+ LOGGER.info("States are successfully updated.");
+ }
+
+ @Override
+ public void insertState(State state, String expectationId) {
+ stateMapper.insertState(state, expectationId);
+ }
+ @Override
+ public void deleteStateById(String stateId) {
+ stateMapper.deleteStateById(stateId);
}
}
diff --git a/intentanalysis/src/main/resources/mybatis/sql/ExpectationMapper.xml b/intentanalysis/src/main/resources/mybatis/sql/ExpectationMapper.xml
index 720bdd5..3b0923f 100644
--- a/intentanalysis/src/main/resources/mybatis/sql/ExpectationMapper.xml
+++ b/intentanalysis/src/main/resources/mybatis/sql/ExpectationMapper.xml
@@ -12,7 +12,7 @@
where intent_id = #{intentId}
</select>
- <insert id="insertExpectation">
+ <insert id="insertExpectationList">
insert into expectation(expectation_id, expectation_name, target_moi, intent_id)
values
<foreach collection="expectationList" index="index" item="item" separator=",">
@@ -25,4 +25,24 @@
where intent_id = #{intentId}
</delete>
+ <update id="updateExpectation">
+ update expectation
+ <trim prefix="set" suffixOverrides=",">
+ <if test="expectationName != null">expectation_name = #{expectationName},</if>
+ <if test="targetMOI != null">target_moi = #{targetMOI},</if>
+ </trim>
+ where expectation_id = #{expectationId}
+ </update>
+
+ <insert id="insertExpectation">
+ insert into expectation(expectation_id, expectation_name, target_moi, intent_id)
+ values (#{expectation.expectationId}, #{expectation.expectationName}, #{expectation.targetMOI}, #{intentId})
+ </insert>
+
+ <delete id="deleteExpectationById">
+ delete
+ from expectation
+ where expectation_id = #{expectationId}
+ </delete>
+
</mapper> \ 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 335ba6d..5e2847b 100644
--- a/intentanalysis/src/main/resources/mybatis/sql/IntentMapper.xml
+++ b/intentanalysis/src/main/resources/mybatis/sql/IntentMapper.xml
@@ -21,7 +21,6 @@
<update id="updateIntent" parameterType="org.onap.usecaseui.intentanalysis.bean.models.Intent">
update intent
<trim prefix="set" suffixOverrides=",">
- <if test="intentId != null">intent_id = #{intentId},</if>
<if test="intentName != null">intent_name = #{intentName},</if>
</trim>
where intent_id = #{intentId}
diff --git a/intentanalysis/src/main/resources/mybatis/sql/StateMapper.xml b/intentanalysis/src/main/resources/mybatis/sql/StateMapper.xml
index 4850870..9e30981 100644
--- a/intentanalysis/src/main/resources/mybatis/sql/StateMapper.xml
+++ b/intentanalysis/src/main/resources/mybatis/sql/StateMapper.xml
@@ -11,7 +11,7 @@
where expectation_id = #{expectationId}
</select>
- <insert id="insertState" parameterType="java.util.ArrayList">
+ <insert id="insertStateList" parameterType="java.util.ArrayList">
insert into state(state_id, state_name, expectation_id, is_satisfied, condition)
values
<foreach collection="stateList" index="index" item="item" separator=",">
@@ -24,4 +24,25 @@
where expectation_id = #{expectationId}
</delete>
+ <insert id="insertState">
+ insert into state(state_id, state_name, expectation_id, is_satisfied, condition)
+ values (#{state.stateId}, #{state.stateName}, #{expectationId}, #{state.isSatisfied}, #{state.condition})
+ </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