-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #316 from CorvusYe/master
demo: add a demo project for kg api
- Loading branch information
Showing
13 changed files
with
452 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-parent</artifactId> | ||
<version>2.7.0</version> | ||
<relativePath/> <!-- lookup parent from repository --> | ||
</parent> | ||
|
||
<artifactId>kg-api</artifactId> | ||
<packaging>jar</packaging> | ||
|
||
<name>kg-api</name> | ||
<url>http://maven.apache.org</url> | ||
|
||
<properties> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
</properties> | ||
|
||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-data-redis</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-web</artifactId> | ||
<exclusions> | ||
<exclusion> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-tomcat</artifactId> | ||
</exclusion> | ||
</exclusions> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-undertow</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.projectlombok</groupId> | ||
<artifactId>lombok</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-test</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.nebula-contrib</groupId> | ||
<artifactId>ngbatis</artifactId> | ||
<version>1.2.2</version> | ||
</dependency> | ||
</dependencies> | ||
|
||
</project> |
22 changes: 22 additions & 0 deletions
22
examples/kg-api/src/main/java/org/nebula/contrib/kg/KgApiApp.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package org.nebula.contrib.kg; | ||
|
||
// Copyright (c) 2024 All project authors. All rights reserved. | ||
// | ||
// This source code is licensed under Apache 2.0 License. | ||
|
||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; | ||
|
||
/** | ||
* Hello world! | ||
*/ | ||
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class}, | ||
scanBasePackages = {"org.nebula.contrib", "org.nebula.contrib.kg"}) | ||
public class KgApiApp { | ||
|
||
public static void main(String[] args) { | ||
SpringApplication app = new SpringApplication(KgApiApp.class); | ||
app.run(args); | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
examples/kg-api/src/main/java/org/nebula/contrib/kg/controller/DataController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package org.nebula.contrib.kg.controller; | ||
|
||
// Copyright (c) 2024 All project authors. All rights reserved. | ||
// | ||
// This source code is licensed under Apache 2.0 License. | ||
|
||
import java.util.List; | ||
import org.nebula.contrib.kg.pojo.Triplet; | ||
import org.nebula.contrib.kg.service.DataService; | ||
import org.nebula.contrib.kg.utils.R; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
/** | ||
* @author yeweicheng | ||
* @since 2024-09-02 15:46 | ||
* <br>Now is history! | ||
*/ | ||
@RestController | ||
@RequestMapping("/kg/data") | ||
public class DataController { | ||
|
||
@Autowired | ||
private DataService service; | ||
|
||
@RequestMapping("next") | ||
public R<List<Triplet<String>>> next(String id) { | ||
return R.ok(service.next(id)); | ||
} | ||
|
||
} |
21 changes: 21 additions & 0 deletions
21
examples/kg-api/src/main/java/org/nebula/contrib/kg/controller/SchemaController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package org.nebula.contrib.kg.controller; | ||
|
||
// Copyright (c) 2024 All project authors. All rights reserved. | ||
// | ||
// This source code is licensed under Apache 2.0 License. | ||
|
||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
/** | ||
* @author yeweicheng | ||
* @since 2024-09-02 15:46 | ||
* <br>Now is history! | ||
*/ | ||
@RestController | ||
@RequestMapping("/kg/schema") | ||
public class SchemaController { | ||
|
||
// TODO | ||
|
||
} |
20 changes: 20 additions & 0 deletions
20
examples/kg-api/src/main/java/org/nebula/contrib/kg/dao/DataDao.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package org.nebula.contrib.kg.dao; | ||
|
||
// Copyright (c) 2024 All project authors. All rights reserved. | ||
// | ||
// This source code is licensed under Apache 2.0 License. | ||
|
||
import java.util.List; | ||
import org.nebula.contrib.kg.pojo.Triplet; | ||
import org.springframework.data.repository.query.Param; | ||
|
||
/** | ||
* @author yeweicheng | ||
* @since 2024-09-02 15:54 | ||
* <br>Now is history! | ||
*/ | ||
public interface DataDao<T> { | ||
|
||
List<Triplet<T>> selectTriplets(@Param("id") T id); | ||
|
||
} |
40 changes: 40 additions & 0 deletions
40
...es/kg-api/src/main/java/org/nebula/contrib/kg/ngbatis/CollectionTripletResultHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package org.nebula.contrib.kg.ngbatis; | ||
|
||
// Copyright (c) 2024 All project authors. All rights reserved. | ||
// | ||
// This source code is licensed under Apache 2.0 License. | ||
|
||
import com.vesoft.nebula.client.graph.data.ResultSet; | ||
import java.util.Collection; | ||
import org.nebula.contrib.kg.pojo.Triplet; | ||
import org.nebula.contrib.ngbatis.handler.AbstractResultHandler; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Component; | ||
|
||
/** | ||
* @author yeweicheng | ||
* @since 2024-08-28 13:59 | ||
* <br>Now is history! | ||
*/ | ||
@Component | ||
public class CollectionTripletResultHandler extends | ||
AbstractResultHandler<Collection, Triplet<String>> { | ||
|
||
@Autowired | ||
private TripletResultHandler singleHandler; | ||
|
||
@Override | ||
public Collection handle(Collection newResult, ResultSet result, Class resultType) | ||
throws NoSuchFieldException, IllegalAccessException, InstantiationException { | ||
|
||
int rowsSize = result.rowsSize(); | ||
for (int i = 0; i < rowsSize; i++) { | ||
ResultSet.Record row = result.rowValues(i); | ||
Triplet<String> triplet = new Triplet<>(); | ||
triplet = singleHandler.handle(triplet, row); | ||
newResult.add(triplet); | ||
} | ||
return newResult; | ||
} | ||
|
||
} |
58 changes: 58 additions & 0 deletions
58
examples/kg-api/src/main/java/org/nebula/contrib/kg/ngbatis/TripletResultHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package org.nebula.contrib.kg.ngbatis; | ||
|
||
// Copyright (c) 2024 All project authors. All rights reserved. | ||
// | ||
// This source code is licensed under Apache 2.0 License. | ||
|
||
import com.vesoft.nebula.client.graph.data.ResultSet; | ||
import com.vesoft.nebula.client.graph.data.ResultSet.Record; | ||
import com.vesoft.nebula.client.graph.data.ValueWrapper; | ||
import org.nebula.contrib.kg.pojo.Triplet; | ||
import org.nebula.contrib.ngbatis.handler.AbstractResultHandler; | ||
import org.nebula.contrib.ngbatis.handler.NgEdgeResultHandler; | ||
import org.nebula.contrib.ngbatis.handler.NgVertexResultHandler; | ||
import org.nebula.contrib.ngbatis.models.data.NgEdge; | ||
import org.nebula.contrib.ngbatis.models.data.NgVertex; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Component; | ||
|
||
/** | ||
* @author yeweicheng | ||
* @since 2024-08-28 13:50 | ||
* <br>Now is history! | ||
*/ | ||
@Component | ||
public class TripletResultHandler extends AbstractResultHandler<Triplet<String>, Triplet<String>> { | ||
|
||
@Autowired | ||
private NgVertexResultHandler vertexHandler; | ||
@Autowired | ||
private NgEdgeResultHandler edgeHandler; | ||
|
||
@Override | ||
public Triplet<String> handle( | ||
Triplet<String> newResult, ResultSet result, Class resultType) { | ||
return handle(newResult, result.rowValues(0)); | ||
} | ||
|
||
public Triplet<String> handle(Triplet<String> newResult, Record row) { | ||
|
||
NgVertex<String> src = new NgVertex<>(); | ||
|
||
ValueWrapper valueWrapper = row.get(0); | ||
vertexHandler.handle(src, valueWrapper); | ||
newResult.setSrc(src); | ||
|
||
NgEdge<String> edge = new NgEdge<>(); | ||
valueWrapper = row.get(1); | ||
edgeHandler.handle(edge, valueWrapper); | ||
newResult.setEdge(edge); | ||
|
||
NgVertex<String> dst = new NgVertex<>(); | ||
valueWrapper = row.get(2); | ||
vertexHandler.handle(dst, valueWrapper); | ||
newResult.setDst(dst); | ||
|
||
return newResult; | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
examples/kg-api/src/main/java/org/nebula/contrib/kg/pojo/Triplet.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package org.nebula.contrib.kg.pojo; | ||
|
||
// Copyright (c) 2024 All project authors. All rights reserved. | ||
// | ||
// This source code is licensed under Apache 2.0 License. | ||
|
||
import org.nebula.contrib.ngbatis.models.data.NgEdge; | ||
import org.nebula.contrib.ngbatis.models.data.NgVertex; | ||
|
||
/** | ||
* @author yeweicheng | ||
* @since 2024-08-28 13:28 | ||
* <br>Now is history! | ||
*/ | ||
|
||
public class Triplet<T> { | ||
|
||
private NgVertex<T> src; | ||
private NgVertex<T> dst; | ||
private NgEdge<T> edge; | ||
|
||
public NgVertex<T> getSrc() { | ||
return src; | ||
} | ||
|
||
public void setSrc(NgVertex<T> src) { | ||
this.src = src; | ||
} | ||
|
||
public NgVertex<T> getDst() { | ||
return dst; | ||
} | ||
|
||
public void setDst(NgVertex<T> dst) { | ||
this.dst = dst; | ||
} | ||
|
||
public NgEdge<T> getEdge() { | ||
return edge; | ||
} | ||
|
||
public void setEdge(NgEdge<T> edge) { | ||
this.edge = edge; | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
examples/kg-api/src/main/java/org/nebula/contrib/kg/service/DataService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package org.nebula.contrib.kg.service; | ||
|
||
// Copyright (c) 2024 All project authors. All rights reserved. | ||
// | ||
// This source code is licensed under Apache 2.0 License. | ||
|
||
import java.util.List; | ||
import org.nebula.contrib.kg.pojo.Triplet; | ||
|
||
/** | ||
* @author yeweicheng | ||
* @since 2024-09-02 16:08 | ||
* <br>Now is history! | ||
*/ | ||
public interface DataService { | ||
|
||
List<Triplet<String>> next(String id); | ||
|
||
} |
29 changes: 29 additions & 0 deletions
29
examples/kg-api/src/main/java/org/nebula/contrib/kg/service/impl/DataServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package org.nebula.contrib.kg.service.impl; | ||
|
||
// Copyright (c) 2024 All project authors. All rights reserved. | ||
// | ||
// This source code is licensed under Apache 2.0 License. | ||
|
||
import java.util.List; | ||
import org.nebula.contrib.kg.dao.DataDao; | ||
import org.nebula.contrib.kg.pojo.Triplet; | ||
import org.nebula.contrib.kg.service.DataService; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Service; | ||
|
||
/** | ||
* @author yeweicheng | ||
* @since 2024-09-02 16:12 | ||
* <br>Now is history! | ||
*/ | ||
@Service | ||
public class DataServiceImpl implements DataService { | ||
|
||
@Autowired | ||
private DataDao<String> dao; | ||
|
||
@Override | ||
public List<Triplet<String>> next(String id) { | ||
return dao.selectTriplets(id); | ||
} | ||
} |
Oops, something went wrong.