@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);
}
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);
}
void updateExpectationListById(List<Expectation> expectationList, String intentId);
List<Expectation> getExpectationListByIntentId(String intentId);
+
+ void insertExpectation(Expectation expectation, String intentId);
+
+ void deleteExpectationById(String expectationId);
}
void updateStateListByExpectationId(List<State> stateList, String expectationId);
List<State> getStateListByExpectationId(String expectationId);
+
+ void insertState(State state, String expectationId);
+
+ void deleteStateById(String stateId);
}
import org.slf4j.LoggerFactory;
+import java.util.ArrayList;
import java.util.List;
@Service
@Autowired
private StateService stateService;
+ @Autowired
+ private ExpectationService expectationService;
+
@Override
public void createExpectationList(List<Expectation> expectationList, String intentId) {
for (Expectation expectation : expectationList) {
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;
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);
+ }
}
@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
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
}
@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);
}
}
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=",">
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
<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}
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=",">
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