Commit 4e818eb9 authored by linpeiqin's avatar linpeiqin

增加知识图谱连接测试,

去除知识图谱健康检查
parent 9d1de662
package com.yice.webadmin.app.controller; package com.yice.webadmin.app.controller;
import com.yice.common.log.annotation.OperationLog;
import com.yice.common.log.model.constant.SysOperationLogType;
import com.github.pagehelper.page.PageMethod; import com.github.pagehelper.page.PageMethod;
import com.yice.webadmin.app.vo.*;
import com.yice.webadmin.app.dto.*;
import com.yice.webadmin.app.model.*;
import com.yice.webadmin.app.service.*;
import com.yice.common.core.object.*;
import com.yice.common.core.util.*;
import com.yice.common.core.constant.*;
import com.yice.common.core.annotation.MyRequestBody;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport; import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.yice.common.core.annotation.MyRequestBody;
import com.yice.common.core.constant.ErrorCodeEnum;
import com.yice.common.core.object.*;
import com.yice.common.core.util.MyCommonUtil;
import com.yice.common.core.util.MyModelUtil;
import com.yice.common.core.util.MyPageUtil;
import com.yice.common.log.annotation.OperationLog;
import com.yice.common.log.model.constant.SysOperationLogType;
import com.yice.webadmin.app.dto.KGManageDto;
import com.yice.webadmin.app.model.KGManage;
import com.yice.webadmin.app.service.KGManageService;
import com.yice.webadmin.app.vo.KGManageVo;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.neo4j.driver.*;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.util.*; import java.util.List;
/** /**
* 知识图谱管理操作控制器类。 * 知识图谱管理操作控制器类。
...@@ -79,6 +82,19 @@ public class KGManageController { ...@@ -79,6 +82,19 @@ public class KGManageController {
return ResponseResult.success(); return ResponseResult.success();
} }
/**
* 列出符合过滤条件的知识图谱列表。
*
* @return 应答结果对象,包含查询结果集。
*/
@PostMapping("/listForSelect")
public ResponseResult<List<KGManageVo>> listForSelect(@MyRequestBody KGManageDto kGManageDtoFilter) {
KGManage kGManageFilter = MyModelUtil.copyTo(kGManageDtoFilter, KGManage.class);
List<KGManage> kGManageList =
kGManageService.getKGManageListWithRelation(kGManageFilter, "");
return ResponseResult.success(KGManage.INSTANCE.fromModelList(kGManageList));
}
/** /**
* 删除知识图谱管理数据。 * 删除知识图谱管理数据。
* *
...@@ -98,8 +114,8 @@ public class KGManageController { ...@@ -98,8 +114,8 @@ public class KGManageController {
* 列出符合过滤条件的知识图谱管理列表。 * 列出符合过滤条件的知识图谱管理列表。
* *
* @param kGManageDtoFilter 过滤对象。 * @param kGManageDtoFilter 过滤对象。
* @param orderParam 排序参数。 * @param orderParam 排序参数。
* @param pageParam 分页参数。 * @param pageParam 分页参数。
* @return 应答结果对象,包含查询结果集。 * @return 应答结果对象,包含查询结果集。
*/ */
@PostMapping("/list") @PostMapping("/list")
...@@ -116,6 +132,36 @@ public class KGManageController { ...@@ -116,6 +132,36 @@ public class KGManageController {
return ResponseResult.success(MyPageUtil.makeResponseData(kGManageList, KGManage.INSTANCE)); return ResponseResult.success(MyPageUtil.makeResponseData(kGManageList, KGManage.INSTANCE));
} }
/**
* 测试知识图谱是否连接。
*
* @param kgId 知识图谱配置ID。
* @return 应答结果对象,包含查询结果集。
*/
@PostMapping("/connectionTest")
public ResponseResult<Long> connectionTest(@MyRequestBody Long kgId) {
String errorMessage;
// 验证关联Id的数据合法性
KGManage KGManage = kGManageService.getById(kgId);
if (KGManage == null) {
// NOTE: 修改下面方括号中的话述
errorMessage = "数据验证失败,当前 [对象] 并不存在,请刷新后重试!";
return ResponseResult.error(ErrorCodeEnum.DATA_NOT_EXIST, errorMessage);
}
try {
Driver driver = GraphDatabase.driver(KGManage.getKgUrl(), AuthTokens.basic(KGManage.getKgUserName(), KGManage.getKgPassword()));
Session session = driver.session();
String cypher = "MATCH (n) RETURN count(n)";
Result result = session.run(cypher);
long count = result.single().get("count(n)").asLong();
System.out.println("Neo4j连接成功,数据库中共有 " + count + " 个节点。");
driver.close();
return ResponseResult.success(count);
} catch (Exception e) {
return ResponseResult.error(ErrorCodeEnum.DATA_ACCESS_FAILED, "Neo4j连接失败: " + e.getMessage());
}
}
/** /**
* 查看指定知识图谱管理对象详情。 * 查看指定知识图谱管理对象详情。
* *
......
...@@ -116,6 +116,9 @@ management: ...@@ -116,6 +116,9 @@ management:
keys-to-sanitize: password keys-to-sanitize: password
server: server:
base-path: "/" base-path: "/"
health:
neo4j:
enabled: off
common-log: common-log:
# 操作日志配置,对应配置文件common-log/OperationLogProperties.java # 操作日志配置,对应配置文件common-log/OperationLogProperties.java
......
...@@ -161,6 +161,10 @@ ...@@ -161,6 +161,10 @@
<artifactId>spring-boot-starter-test</artifactId> <artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency>
<groupId>org.neo4j.driver</groupId>
<artifactId>neo4j-java-driver</artifactId>
</dependency>
<dependency> <dependency>
<groupId>javax.xml.bind</groupId> <groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId> <artifactId>jaxb-api</artifactId>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment