/** * Create an instance of {@link GraphmlType } * */ public GraphmlType createGraphmlType() { return new GraphmlType(); }
@Override protected GraphmlType getTransformation() { final GraphmlType graphmlType = new GraphmlType(); for (final String key : this.nodeKeys) { final KeyType keyType = new KeyType(); keyType.setId(key); keyType.setFor(KeyForType.NODE); keyType.setAttrName(key); keyType.setAttrType(KeyTypeType.STRING); graphmlType.getKey().add(keyType); } for (final String key : this.edgeKeys) { final KeyType keyType = new KeyType(); keyType.setId(key); keyType.setFor(KeyForType.EDGE); keyType.setAttrName(key); keyType.setAttrType(KeyTypeType.STRING); graphmlType.getKey().add(keyType); } graphmlType.getGraphOrData().add(this.graphType); return graphmlType; }
final GraphMLTransformer graphmlTypeTransformer = new GraphMLTransformer(childGraph); final GraphmlType childGraphmlType = graphmlTypeTransformer.transform(); for (final Object childGraphType : childGraphmlType.getGraphOrData()) { if (childGraphType instanceof GraphType) { nodeType.setGraph((GraphType) childGraphType); for (final KeyType keyType : childGraphmlType.getKey()) { final KeyForType keyForType = keyType.getFor(); switch (keyForType) {
public static GraphmlType convert(GraphML graphML) throws InvalidGraphException { GraphmlType graphmlType = new GraphmlType(); addProperties(graphmlType, KeyForType.GRAPHML, graphML, dataType -> graphmlType.getGraphOrData().add(dataType)); for (GraphMLGraph eachGraph : graphML.getGraphs()) { GraphType graphType = new GraphType(); graphType.setId(eachGraph.getId()); addProperties(graphmlType, KeyForType.GRAPH, eachGraph, dataType -> graphType.getDataOrNodeOrEdge().add(dataType)); for (GraphMLNode eachNode : eachGraph.getNodes()) { NodeType nodeType = new NodeType(); nodeType.setId(eachNode.getId()); graphType.getDataOrNodeOrEdge().add(nodeType); addProperties(graphmlType, KeyForType.NODE, eachNode, dataType -> nodeType.getDataOrPort().add(dataType)); } for (GraphMLEdge eachEdge : eachGraph.getEdges()) { EdgeType edgeType = new EdgeType(); edgeType.setId(eachEdge.getId()); edgeType.setSource(eachEdge.getSource().getId()); edgeType.setTarget(eachEdge.getTarget().getId()); graphType.getDataOrNodeOrEdge().add(edgeType); addProperties(graphmlType, KeyForType.EDGE, eachEdge, dataType -> edgeType.getData().add(dataType)); } graphmlType.getGraphOrData().add(graphType); } return graphmlType; }
private static void addProperties(GraphmlType graphmlType, KeyForType keyForType, GraphMLElement element, DataTypeAddCallback callback) throws InvalidGraphException { for (Map.Entry<String, Object> eachEntry : element.getProperties().entrySet()) { if (eachEntry.getKey().equals(GraphMLElement.ID)) { // skip IDs continue; } List<KeyType> definedKeys = graphmlType.getKey().stream() .filter(eachKey -> eachKey.getFor() == keyForType) .filter(eachKey -> eachKey.getId().equals(eachEntry.getKey())) .collect(Collectors.toList()); if (definedKeys.isEmpty()) { KeyType keyType = new KeyType(); keyType.setFor(keyForType); keyType.setId(eachEntry.getKey()); keyType.setAttrName(eachEntry.getKey()); keyType.setAttrType(parseType(eachEntry.getValue())); graphmlType.getKey().add(keyType); } if (definedKeys.size() > 1) { throw new InvalidGraphException("Duplicate key found for id " + eachEntry.getKey()); } DataType dataType = new DataType(); dataType.setKey(eachEntry.getKey()); dataType.setContent(String.valueOf(eachEntry.getValue())); callback.addData(dataType); } }
public static GraphML convert(GraphmlType input) throws InvalidGraphException { final Map<String, GraphMLGraph> nodeIdToGraphMapping = new HashMap<>(); final Map<String, KeyType> keyIdToTypeMapping = getKeyIdToTypeMapping(input.getKey()); final List<GraphType> graphs = filter(input.getGraphOrData(), GraphType.class); addProperties(convertedGraphML, null, keyIdToTypeMapping, filter(input.getGraphOrData(), DataType.class));
/** * Create an instance of {@link GraphmlType } * */ public GraphmlType createGraphmlType() { return new GraphmlType(); }