Parcourir la source

添加图谱实体属性更新的接口,暂时只支持化验

MarkHuang il y a 4 ans
Parent
commit
d3b9ffbd37

+ 132 - 0
src/main/java/com/diagbot/facade/EntityFacade.java

@@ -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;
+    }
+
+
+}

+ 50 - 0
src/main/java/com/diagbot/web/EntityController.java

@@ -0,0 +1,50 @@
+package com.diagbot.web;
+
+import com.diagbot.dto.NeoEntityDTO;
+import com.diagbot.facade.EntityFacade;
+import com.diagbot.vo.NeoEntityVO;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @Description: 图谱实体API控制层
+ * @author: zhoutg
+ * @time: 2018/8/30 10:12
+ */
+@RestController
+@RequestMapping("/entity")
+@Api(value = "实体API", tags = { "实体API" })
+@SuppressWarnings("unchecked")
+public class EntityController {
+
+    @Autowired
+    private EntityFacade entityFacade;
+
+    @ApiOperation(value = "实体API", notes = "")
+    @PostMapping("/initEntity")
+    public void initEntity() {
+        entityFacade.initEntity();
+    }
+
+    @ApiOperation(value = "实体标签API", notes = "")
+    @GetMapping("/getLabels")
+    public List<String> getLabels() {
+        return entityFacade.getLabels();
+    }
+
+
+    @ApiOperation(value = "实体更新API", notes = "")
+    @PostMapping("/updateNode")
+    public NeoEntityDTO updateNode(@RequestBody NeoEntityVO neoEntityVO) {
+
+        return entityFacade.updateNeoNode(neoEntityVO);
+    }
+
+}
+