|
@@ -0,0 +1,132 @@
|
|
|
+package com.diagbot.facade;
|
|
|
+
|
|
|
+import com.diagbot.dto.NeoEntityDTO;
|
|
|
+import com.diagbot.repository.*;
|
|
|
+import com.diagbot.vo.*;
|
|
|
+
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.core.io.ClassPathResource;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+
|
|
|
+import java.io.BufferedReader;
|
|
|
+import java.io.File;
|
|
|
+import java.io.FileReader;
|
|
|
+import java.io.IOException;
|
|
|
+import java.util.*;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @Description: 图谱facade
|
|
|
+ * @author: Mark
|
|
|
+ * @time: 2018/8/6 9:11
|
|
|
+ */
|
|
|
+@Component
|
|
|
+public class EntityFacade {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ BaseNodeRepository baseNodeRepository;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ LisRepository lisRepository;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ LisPackRepository lisPackRepository;
|
|
|
+
|
|
|
+
|
|
|
+ public List<String> getLabels() {
|
|
|
+ List<String> labels = baseNodeRepository.getLabels();
|
|
|
+
|
|
|
+ return labels;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public void initEntity() {
|
|
|
+ List<String> labels = getLabels();
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ public NeoEntityDTO updateNeoNode(NeoEntityVO neoEntityVO) {
|
|
|
+
|
|
|
+ List<String> keys;
|
|
|
+ String name = neoEntityVO.getName();
|
|
|
+ List<String> labels = neoEntityVO.getLabels();
|
|
|
+ Map<String, String> props = neoEntityVO.getProperty();
|
|
|
+
|
|
|
+ NeoEntityDTO neoEntityDTO = new NeoEntityDTO();
|
|
|
+
|
|
|
+ Map<String, String> map = getMapping("node_mapping");
|
|
|
+
|
|
|
+ String label = labels.get(0);
|
|
|
+ if (null!=map.get(label)) {
|
|
|
+ String clsname = map.get(label);
|
|
|
+
|
|
|
+ switch (clsname) {
|
|
|
+ case "LIS":
|
|
|
+ LisNode lisNode = new LisNode();
|
|
|
+ keys = getKeys(lisRepository.getKeys(), "name");
|
|
|
+ neoEntityDTO = lisNode.updateEntity(name, props, keys, lisRepository);
|
|
|
+ break;
|
|
|
+ case "LISPack":
|
|
|
+ LisPackNode lisPackNode = new LisPackNode();
|
|
|
+ keys = getKeys(lisPackRepository.getKeys(), "name");
|
|
|
+ neoEntityDTO = lisPackNode.updateEntity(name, props, keys, lisPackRepository);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ neoEntityDTO.setLabels(labels);
|
|
|
+ }
|
|
|
+
|
|
|
+ return neoEntityDTO;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取图谱节点类型到节点类名的静态映射
|
|
|
+ * @param fname
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private Map<String, String> getMapping(String fname) {
|
|
|
+ Map<String, String> mapping = new HashMap<>();
|
|
|
+ try {
|
|
|
+
|
|
|
+ ClassPathResource classPathResource = new ClassPathResource(fname);
|
|
|
+
|
|
|
+ File file = classPathResource.getFile();
|
|
|
+ BufferedReader br = new BufferedReader(new FileReader(file));
|
|
|
+ String line;
|
|
|
+ String[] pair;
|
|
|
+ while ((line=br.readLine())!=null) {
|
|
|
+ if (line.contains(":")) {
|
|
|
+ pair = line.split(":");
|
|
|
+ mapping.put(pair[0].trim(), pair[1].trim());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch (IOException ioe) {
|
|
|
+ ioe.printStackTrace();
|
|
|
+ }
|
|
|
+
|
|
|
+ return mapping;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取节点的属性列表
|
|
|
+ * @param keylist
|
|
|
+ * @param exclude
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private List<String> getKeys(List<List<String>> keylist, String exclude) {
|
|
|
+ List<String> finalkeys = new ArrayList<>();
|
|
|
+
|
|
|
+ for (List<String> keys : keylist) {
|
|
|
+ for (String key : keys) {
|
|
|
+ if (!key.equals(exclude) && !finalkeys.contains(key)) {
|
|
|
+ finalkeys.add(key);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return finalkeys;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+}
|