Skip to content

Commit

Permalink
Support get schema by names
Browse files Browse the repository at this point in the history
Change-Id: Id188751189ddd651a32604fb364410bcf857745d
  • Loading branch information
Linary committed Sep 12, 2019
1 parent 1c062b8 commit 2efaa84
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 16 deletions.
2 changes: 1 addition & 1 deletion hugegraph-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
</addDefaultSpecificationEntries>
</manifest>
<manifestEntries>
<Implementation-Version>0.44.0.0</Implementation-Version>
<Implementation-Version>0.45.0.0</Implementation-Version>
</manifestEntries>
</archive>
</configuration>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

package com.baidu.hugegraph.api.schema;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

Expand Down Expand Up @@ -104,11 +105,20 @@ public String update(@Context GraphManager manager,
@Timed
@Produces(APPLICATION_JSON_WITH_CHARSET)
public String list(@Context GraphManager manager,
@PathParam("graph") String graph) {
LOG.debug("Graph [{}] get edge labels", graph);
@PathParam("graph") String graph,
@QueryParam("names") List<String> names) {
LOG.debug("Graph [{}] get edge labels by names {}", graph, names);

HugeGraph g = graph(manager, graph);
List<EdgeLabel> labels = g.schema().getEdgeLabels();
List<EdgeLabel> labels;
if (names == null || names.isEmpty()) {
labels = g.schema().getEdgeLabels();
} else {
labels = new ArrayList<>(names.size());
for (String name : names) {
labels.add(g.schema().getEdgeLabel(name));
}
}
return manager.serializer(g).writeEdgeLabels(labels);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Context;

import org.slf4j.Logger;
Expand Down Expand Up @@ -79,12 +80,21 @@ public String create(@Context GraphManager manager,
@Timed
@Produces(APPLICATION_JSON_WITH_CHARSET)
public String list(@Context GraphManager manager,
@PathParam("graph") String graph) {
LOG.debug("Graph [{}] get edge labels", graph);
@PathParam("graph") String graph,
@QueryParam("names") List<String> names) {
LOG.debug("Graph [{}] get index labels by names {}", graph, names);

HugeGraph g = graph(manager, graph);
List<IndexLabel> labels = g.schema().getIndexLabels();
return manager.serializer(g).writeIndexlabels(mapIndexLabels(labels));
List<IndexLabel> labels;
if (names == null || names.isEmpty()) {
labels = g.schema().getIndexLabels();
} else {
labels = new ArrayList<>(names.size());
for (String name : names) {
labels.add(g.schema().getIndexLabel(name));
}
}
return manager.serializer(g).writeIndexlabels(labels);
}

@GET
Expand All @@ -94,7 +104,7 @@ public String list(@Context GraphManager manager,
public String get(@Context GraphManager manager,
@PathParam("graph") String graph,
@PathParam("name") String name) {
LOG.debug("Graph [{}] get edge label by name '{}'", graph, name);
LOG.debug("Graph [{}] get index label by name '{}'", graph, name);

HugeGraph g = graph(manager, graph);
IndexLabel indexLabel = g.schema().getIndexLabel(name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

package com.baidu.hugegraph.api.schema;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

Expand Down Expand Up @@ -105,11 +106,20 @@ public String update(@Context GraphManager manager,
@Timed
@Produces(APPLICATION_JSON_WITH_CHARSET)
public String list(@Context GraphManager manager,
@PathParam("graph") String graph) {
LOG.debug("Graph [{}] get property keys", graph);
@PathParam("graph") String graph,
@QueryParam("names") List<String> names) {
LOG.debug("Graph [{}] get property keys by names {}", graph, names);

HugeGraph g = graph(manager, graph);
List<PropertyKey> propKeys = g.schema().getPropertyKeys();
List<PropertyKey> propKeys;
if (names == null || names.isEmpty()) {
propKeys = g.schema().getPropertyKeys();
} else {
propKeys = new ArrayList<>(names.size());
for (String name : names) {
propKeys.add(g.schema().getPropertyKey(name));
}
}
return manager.serializer(g).writePropertyKeys(propKeys);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

package com.baidu.hugegraph.api.schema;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

Expand Down Expand Up @@ -107,11 +108,20 @@ public String update(@Context GraphManager manager,
@Timed
@Produces(APPLICATION_JSON_WITH_CHARSET)
public String list(@Context GraphManager manager,
@PathParam("graph") String graph) {
LOG.debug("Graph [{}] get vertex labels", graph);
@PathParam("graph") String graph,
@QueryParam("names") List<String> names) {
LOG.debug("Graph [{}] get vertex labels by names {}", graph, names);

HugeGraph g = graph(manager, graph);
List<VertexLabel> labels = g.schema().getVertexLabels();
List<VertexLabel> labels;
if (names == null || names.isEmpty()) {
labels = g.schema().getVertexLabels();
} else {
labels = new ArrayList<>(names.size());
for (String name : names) {
labels.add(g.schema().getVertexLabel(name));
}
}
return manager.serializer(g).writeVertexLabels(labels);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,11 @@ public final class ApiVersion {
* [0.43] Issue-270 & 398: support shard-index and vertex + sortke prefix,
* and split range to rangeInt, rangeFloat, rangeLong and rangeDouble
* [0.44] Issue-633: Support unique index
* [0.45] Issue-686: Support get schema by names
*/

// The second parameter of Version.of() is for IDE running without JAR
public static final Version VERSION = Version.of(ApiVersion.class, "0.44");
public static final Version VERSION = Version.of(ApiVersion.class, "0.45");

public static final void check() {
// Check version of hugegraph-core. Firstly do check from version 0.3
Expand Down

0 comments on commit 2efaa84

Please sign in to comment.