aboutsummaryrefslogtreecommitdiffstats
path: root/intentanalysis/src/main/java/org
diff options
context:
space:
mode:
Diffstat (limited to 'intentanalysis/src/main/java/org')
-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
7 files changed, 99 insertions, 13 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);
}
}