use of com.alibaba.maxgraph.sdkcommon.schema.mapper.EdgeTypeMapper in project GraphScope by alibaba.
the class GraphSchemaMapper method parseFromJson.
public static GraphSchemaMapper parseFromJson(String schemaJson) {
JSONObject jsonObject = JSONObject.parseObject(schemaJson);
GraphSchemaMapper graphSchema = new GraphSchemaMapper();
Integer version = jsonObject.getInteger("version");
if (null != version) {
graphSchema.version = version;
} else {
graphSchema.version = 0;
}
graphSchema.types = Lists.newArrayList();
JSONArray typeArray = jsonObject.getJSONArray("types");
for (int i = 0; i < typeArray.size(); i++) {
JSONObject typeObject = typeArray.getJSONObject(i);
String type = typeObject.getString("type");
if (StringUtils.equals("VERTEX", StringUtils.upperCase(type))) {
VertexTypeMapper vertexTypeMapper = typeObject.toJavaObject(VertexTypeMapper.class);
graphSchema.types.add(vertexTypeMapper);
} else {
EdgeTypeMapper edgeTypeMapper = typeObject.toJavaObject(EdgeTypeMapper.class);
graphSchema.types.add(edgeTypeMapper);
}
}
return graphSchema;
}
use of com.alibaba.maxgraph.sdkcommon.schema.mapper.EdgeTypeMapper in project GraphScope by alibaba.
the class GraphSchemaMapper method toGraphSchema.
public GraphSchema toGraphSchema() {
DefaultGraphSchema graphSchema = new DefaultGraphSchema();
Map<String, GraphVertex> vertexTypeMap = Maps.newHashMap();
for (SchemaElementMapper elementMapper : this.types) {
if (elementMapper instanceof VertexTypeMapper) {
GraphVertex graphVertex = ((VertexTypeMapper) elementMapper).toVertexType();
graphSchema.createVertexType(graphVertex);
vertexTypeMap.put(graphVertex.getLabel(), graphVertex);
}
}
for (SchemaElementMapper elementMapper : this.types) {
if (elementMapper instanceof EdgeTypeMapper) {
GraphEdge graphEdge = ((EdgeTypeMapper) elementMapper).toEdgeType(vertexTypeMap);
graphSchema.createEdgeType(graphEdge);
}
}
return graphSchema;
}
Aggregations