aboutsummaryrefslogtreecommitdiffstats
path: root/intentanalysis/src/main/java
diff options
context:
space:
mode:
authorKeguang He <hekeguang@chinamobile.com>2022-07-26 01:17:21 +0000
committerGerrit Code Review <gerrit@onap.org>2022-07-26 01:17:21 +0000
commit0c41af52f3f453219a0240cf54ea321829a49c0e (patch)
tree682c84b423f65e9c5b7476a30f504e8a757cace2 /intentanalysis/src/main/java
parent7753765f0712e846ff87a8b2dd6b9586b2e02f47 (diff)
parentc556b574b03a0458e1f8121351c80286ac02bb63 (diff)
Merge "Intent service impletation"
Diffstat (limited to 'intentanalysis/src/main/java')
-rw-r--r--intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/IntentAnalysisApplication.java3
-rw-r--r--intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/bean/po/IntentPo.java1
-rw-r--r--intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/controller/IntentController.java2
-rw-r--r--intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/mapper/ExpectationMapper.java33
-rw-r--r--intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/mapper/IntentMapper.java36
-rw-r--r--intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/mapper/StateMapper.java31
-rw-r--r--intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/service/IntentService.java2
-rw-r--r--intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/service/impl/ExpectationServiceImpl.java83
-rw-r--r--intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/service/impl/IntentServiceImpl.java101
-rw-r--r--intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/service/impl/StateServiceImpl.java56
10 files changed, 345 insertions, 3 deletions
diff --git a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/IntentAnalysisApplication.java b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/IntentAnalysisApplication.java
index 819c1e7..c2a0ec2 100644
--- a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/IntentAnalysisApplication.java
+++ b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/IntentAnalysisApplication.java
@@ -16,9 +16,10 @@
package org.onap.usecaseui.intentanalysis;
+import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
-
+@MapperScan("org.onap.usecaseui.intentanalysis.mapper")
@SpringBootApplication
public class IntentAnalysisApplication {
diff --git a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/bean/po/IntentPo.java b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/bean/po/IntentPo.java
index 5372081..844ff6d 100644
--- a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/bean/po/IntentPo.java
+++ b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/bean/po/IntentPo.java
@@ -35,6 +35,7 @@ public class IntentPo {
Intent intent = new Intent();
intent.setIntentId(this.intentPoId);
intent.setIntentName(this.intentPoName);
+
intent.setExpectationList(getExpectationList());
return intent;
}
diff --git a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/controller/IntentController.java b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/controller/IntentController.java
index 00d8d3a..d1b4aac 100644
--- a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/controller/IntentController.java
+++ b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/controller/IntentController.java
@@ -53,7 +53,7 @@ public class IntentController {
public ResponseEntity<Intent> updateIntentById(
@PathVariable(INTENT_ID) String intentId,
@RequestBody Intent intent) {
- return ResponseEntity.ok(intentService.updateIntentById(intentId, intent));
+ return ResponseEntity.ok(intentService.updateIntent(intent));
}
@DeleteMapping(value = "/{intentId}", produces = MediaType.APPLICATION_JSON_VALUE)
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
new file mode 100644
index 0000000..bcca440
--- /dev/null
+++ b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/mapper/ExpectationMapper.java
@@ -0,0 +1,33 @@
+/*
+ * 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 org.apache.ibatis.annotations.Mapper;
+import org.onap.usecaseui.intentanalysis.bean.po.ExpectationPo;
+
+import java.util.List;
+@Mapper
+public interface ExpectationMapper {
+
+ void insertExpectation(List<ExpectationPo> expectation);
+
+ List<ExpectationPo> selectExpectationByIntentId(String intentId);
+
+ void deleteExpectationByIntentId(String intentId);
+
+ void updateExpectation(List<ExpectationPo> expectation);
+
+}
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
new file mode 100644
index 0000000..4de598a
--- /dev/null
+++ b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/mapper/IntentMapper.java
@@ -0,0 +1,36 @@
+/*
+ * 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 org.apache.ibatis.annotations.Mapper;
+import org.onap.usecaseui.intentanalysis.bean.po.IntentPo;
+
+import java.util.List;
+
+@Mapper
+public interface IntentMapper {
+
+ void insertIntent(IntentPo intentPo);
+
+ void updateIntent(IntentPo intentPo);
+
+ IntentPo selectIntentById(String intentId);
+
+ List<IntentPo> selectIntents();
+
+ void deleteIntentById(String intentId);
+}
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
new file mode 100644
index 0000000..b1b1416
--- /dev/null
+++ b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/mapper/StateMapper.java
@@ -0,0 +1,31 @@
+/*
+ * 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 org.apache.ibatis.annotations.Mapper;
+import org.onap.usecaseui.intentanalysis.bean.po.StatePo;
+
+import java.util.List;
+@Mapper
+public interface StateMapper {
+
+ void insertState(List<StatePo> state);
+
+ List<StatePo> selectStateByExpectation(String expectationId);
+
+ void deleteStateByExpectationId(String expectationId);
+}
diff --git a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/service/IntentService.java b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/service/IntentService.java
index 4e8765a..36615ab 100644
--- a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/service/IntentService.java
+++ b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/service/IntentService.java
@@ -27,7 +27,7 @@ public interface IntentService {
Intent createIntent(Intent intent);
- Intent updateIntentById(String intentId, Intent intent);
+ Intent updateIntent(Intent intent);
void deleteIntentById(String intentId);
}
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
new file mode 100644
index 0000000..98e5364
--- /dev/null
+++ b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/service/impl/ExpectationServiceImpl.java
@@ -0,0 +1,83 @@
+/*
+ * 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 org.onap.usecaseui.intentanalysis.bean.po.ExpectationPo;
+import org.onap.usecaseui.intentanalysis.bean.po.StatePo;
+import org.onap.usecaseui.intentanalysis.mapper.ExpectationMapper;
+import org.onap.usecaseui.intentanalysis.service.ExpectationService;
+import org.onap.usecaseui.intentanalysis.service.StateService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+import java.util.List;
+
+@Service
+public class ExpectationServiceImpl implements ExpectationService {
+
+ private static Logger LOGGER = LoggerFactory.getLogger(ExpectationServiceImpl.class);
+ @Autowired
+ private ExpectationMapper expectationMapper;
+
+ @Autowired
+ private StateService stateService;
+
+ @Override
+ public void createExpectationList(List<ExpectationPo> expectationPoList, String intentId) {
+ for (ExpectationPo expectationPo : expectationPoList) {
+ if (null != expectationPo) {
+ expectationPo.setIntentPoId(intentId);
+ stateService.createStateList(expectationPo.getStatePoList(), expectationPo.getExpectationPoId());
+ }
+ }
+ expectationMapper.insertExpectation(expectationPoList);
+ }
+
+ @Override
+ public List<ExpectationPo> getExpectationListByIntentId(String intentId) {
+ List<ExpectationPo> expectationList = expectationMapper.selectExpectationByIntentId(intentId);
+ for (ExpectationPo expectation : expectationList) {
+ List<StatePo> stateList = stateService.getStateListByExpectationId(expectation.getExpectationPoId());
+ expectation.setStatePoList(stateList);
+ }
+ return expectationList;
+ }
+
+ @Override
+ public void deleteExpectationListById(String intentId) {
+ List<ExpectationPo> expectationList = expectationMapper.selectExpectationByIntentId(intentId);
+ expectationMapper.deleteExpectationByIntentId(intentId);
+ for (ExpectationPo expectation : expectationList) {
+ stateService.deleteStateListByExpectationId(expectation.getExpectationPoId());
+ }
+ }
+
+ @Override
+ public void updateExpectationListById(List<ExpectationPo> expectationPoList, String intentId) {
+ List<ExpectationPo> expectationList = expectationMapper.selectExpectationByIntentId(intentId);
+ if (expectationList == null) {
+ LOGGER.error("Intent ID {} doesn't exist in database.", intentId);
+ throw new IllegalArgumentException("This intent ID doesn't exist in database.");
+ }
+ expectationMapper.updateExpectation(expectationPoList);
+ LOGGER.info("Expectations are successfully updated.");
+ }
+}
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
new file mode 100644
index 0000000..29a7480
--- /dev/null
+++ b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/service/impl/IntentServiceImpl.java
@@ -0,0 +1,101 @@
+/*
+ * 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 org.onap.usecaseui.intentanalysis.bean.models.Intent;
+import org.onap.usecaseui.intentanalysis.bean.po.IntentPo;
+import org.onap.usecaseui.intentanalysis.mapper.IntentMapper;
+import org.onap.usecaseui.intentanalysis.service.ExpectationService;
+import org.onap.usecaseui.intentanalysis.service.IntentService;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+import java.util.ArrayList;
+import java.util.List;
+
+@Service
+public class IntentServiceImpl implements IntentService {
+ private static Logger LOGGER = LoggerFactory.getLogger(IntentService.class);
+
+ @Autowired
+ private IntentMapper intentMapper;
+
+ @Autowired
+ private ExpectationService expectationService;
+
+ @Override
+ public List<Intent> getIntentList() {
+ List<Intent> intentList = new ArrayList<>();
+ List<IntentPo> intentPoList = intentMapper.selectIntents();
+ if (intentPoList == null || intentPoList.size() <= 0) {
+ return intentList;
+ }
+ for (IntentPo intentPo : intentPoList) {
+ if (intentPo != null) {
+ intentPo.setExpectationPoList(expectationService.getExpectationListByIntentId(intentPo.getIntentPoId()));
+ intentList.add(intentPo.transferToIntent());
+ }
+ }
+ return intentList;
+ }
+
+ @Override
+ public Intent getIntentById(String intentId) {
+ IntentPo intentPo = intentMapper.selectIntentById(intentId);
+ if (intentPo != null) {
+ intentPo.setExpectationPoList(expectationService.getExpectationListByIntentId(intentPo.getIntentPoId()));
+ return intentPo.transferToIntent();
+ } else {
+ String msg = "Intent Id requested doesn't exist in the intent database";
+ LOGGER.error(msg);
+ throw new IllegalArgumentException(msg);
+ }
+ }
+
+ @Transactional(rollbackFor = RuntimeException.class)
+ @Override
+ public Intent createIntent(Intent intent) {
+ IntentPo intentPo = intent.transferToIntentPo();
+ intentMapper.insertIntent(intentPo);
+ // saving expectation list into expectation table
+ expectationService.createExpectationList(intentPo.getExpectationPoList(), intentPo.getIntentPoId());
+ LOGGER.info("Intent was successfully created.");
+ return intent;
+ }
+
+ @Override
+ public Intent updateIntent(Intent intent) {
+ String intentId = intent.getIntentId();
+ IntentPo intentPo = intentMapper.selectIntentById(intentId);
+ if (intentPo == null) {
+ LOGGER.error("intent id {} not exists in db.", intentId);
+ }
+ intentMapper.updateIntent(intentPo);
+ LOGGER.info("update intent successfully.");
+ return intentMapper.selectIntentById(intentId).transferToIntent();
+ }
+
+ @Override
+ public void deleteIntentById(String intentId) {
+ intentMapper.deleteIntentById(intentId);
+ expectationService.deleteExpectationListById(intentId);
+ }
+}
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
new file mode 100644
index 0000000..c907ff8
--- /dev/null
+++ b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/service/impl/StateServiceImpl.java
@@ -0,0 +1,56 @@
+/*
+ * 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 org.onap.usecaseui.intentanalysis.bean.po.StatePo;
+import org.onap.usecaseui.intentanalysis.mapper.StateMapper;
+import org.onap.usecaseui.intentanalysis.service.StateService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.List;
+
+@Service
+public class StateServiceImpl implements StateService {
+
+ @Autowired
+ private StateMapper stateMapper;
+
+ @Override
+ public void createStateList(List<StatePo> stateList, String expectationId) {
+ for (StatePo state : stateList) {
+ state.setStatePoId(expectationId);
+ }
+ stateMapper.insertState(stateList);
+ }
+
+ @Override
+ public List<StatePo> getStateListByExpectationId(String expectationId) {
+ List<StatePo> stateList = stateMapper.selectStateByExpectation(expectationId);
+ return stateList;
+ }
+
+ @Override
+ public void deleteStateListByExpectationId(String expectationId) {
+ stateMapper.deleteStateByExpectationId(expectationId);
+ }
+
+ @Override
+ public void updateStateListByExpectationId(List<StatePo> statePoList, String expectationId){
+ };
+}