use of com.baidu.hugegraph.schema.PropertyKey in project incubator-hugegraph by apache.
the class PropertyKeyCoreTest method testAddPropertyKeyWithUserdata.
@Test
public void testAddPropertyKeyWithUserdata() {
SchemaManager schema = graph().schema();
PropertyKey age = schema.propertyKey("age").userdata("min", 0).userdata("max", 100).create();
Assert.assertEquals(3, age.userdata().size());
Assert.assertEquals(0, age.userdata().get("min"));
Assert.assertEquals(100, age.userdata().get("max"));
PropertyKey id = schema.propertyKey("id").userdata("length", 15).userdata("length", 18).create();
// The same key user data will be overwritten
Assert.assertEquals(2, id.userdata().size());
Assert.assertEquals(18, id.userdata().get("length"));
PropertyKey sex = schema.propertyKey("sex").userdata("range", ImmutableList.of("male", "female")).create();
Assert.assertEquals(2, sex.userdata().size());
Assert.assertEquals(ImmutableList.of("male", "female"), sex.userdata().get("range"));
}
use of com.baidu.hugegraph.schema.PropertyKey in project incubator-hugegraph by apache.
the class PropertyKeyCoreTest method testAddPropertyKey.
@Test
public void testAddPropertyKey() {
SchemaManager schema = graph().schema();
PropertyKey id = schema.propertyKey("id").asText().valueSingle().create();
Assert.assertEquals("id", id.name());
Assert.assertEquals(DataType.TEXT, id.dataType());
Assert.assertEquals(Cardinality.SINGLE, id.cardinality());
}
use of com.baidu.hugegraph.schema.PropertyKey in project incubator-hugegraph by apache.
the class PropertyKeyCoreTest method testEliminatePropertyKeyWithUserdata.
@Test
public void testEliminatePropertyKeyWithUserdata() {
SchemaManager schema = graph().schema();
PropertyKey age = schema.propertyKey("age").userdata("min", 0).userdata("max", 100).create();
Assert.assertEquals(3, age.userdata().size());
Assert.assertEquals(0, age.userdata().get("min"));
Assert.assertEquals(100, age.userdata().get("max"));
age = schema.propertyKey("age").userdata("max", "").eliminate();
Assert.assertEquals(2, age.userdata().size());
Assert.assertEquals(0, age.userdata().get("min"));
}
use of com.baidu.hugegraph.schema.PropertyKey in project incubator-hugegraph by apache.
the class EdgeAPI method getEdgeId.
private Id getEdgeId(HugeGraph g, JsonEdge newEdge) {
String sortKeys = "";
Id labelId = g.edgeLabel(newEdge.label).id();
List<Id> sortKeyIds = g.edgeLabel(labelId).sortKeys();
if (!sortKeyIds.isEmpty()) {
List<Object> sortKeyValues = new ArrayList<>(sortKeyIds.size());
sortKeyIds.forEach(skId -> {
PropertyKey pk = g.propertyKey(skId);
String sortKey = pk.name();
Object sortKeyValue = newEdge.properties.get(sortKey);
E.checkArgument(sortKeyValue != null, "The value of sort key '%s' can't be null", sortKey);
sortKeyValue = pk.validValueOrThrow(sortKeyValue);
sortKeyValues.add(sortKeyValue);
});
sortKeys = ConditionQuery.concatValues(sortKeyValues);
}
EdgeId edgeId = new EdgeId(HugeVertex.getIdValue(newEdge.source), Directions.OUT, labelId, sortKeys, HugeVertex.getIdValue(newEdge.target));
if (newEdge.id != null) {
E.checkArgument(edgeId.asString().equals(newEdge.id), "The ids are different between server and " + "request body ('%s' != '%s'). And note the sort " + "key values should either be null or equal to " + "the origin value when specified edge id", edgeId, newEdge.id);
}
return edgeId;
}
use of com.baidu.hugegraph.schema.PropertyKey in project incubator-hugegraph by apache.
the class VertexAPI method update.
@PUT
@Timed(name = "single-update")
@Path("{id}")
@Consumes(APPLICATION_JSON)
@Produces(APPLICATION_JSON_WITH_CHARSET)
@RolesAllowed({ "admin", "$owner=$graph $action=vertex_write" })
public String update(@Context GraphManager manager, @PathParam("graph") String graph, @PathParam("id") String idValue, @QueryParam("action") String action, JsonVertex jsonVertex) {
LOG.debug("Graph [{}] update vertex: {}", graph, jsonVertex);
checkUpdatingBody(jsonVertex);
Id id = checkAndParseVertexId(idValue);
// Parse action param
boolean append = checkAndParseAction(action);
HugeGraph g = graph(manager, graph);
HugeVertex vertex = (HugeVertex) g.vertex(id);
VertexLabel vertexLabel = vertex.schemaLabel();
for (String key : jsonVertex.properties.keySet()) {
PropertyKey pkey = g.propertyKey(key);
E.checkArgument(vertexLabel.properties().contains(pkey.id()), "Can't update property for vertex '%s' because " + "there is no property key '%s' in its vertex label", id, key);
}
commit(g, () -> updateProperties(vertex, jsonVertex, append));
return manager.serializer(g).writeVertex(vertex);
}
Aggregations