Search in sources :

Example 1 with KeyForType

use of org.graphdrawing.graphml.KeyForType in project opennms by OpenNMS.

the class GraphMLWriter method addProperties.

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);
    }
}
Also used : KeyTypeType(org.graphdrawing.graphml.KeyTypeType) Collectors(java.util.stream.Collectors) DataType(org.graphdrawing.graphml.DataType) File(java.io.File) List(java.util.List) NodeType(org.graphdrawing.graphml.NodeType) KeyForType(org.graphdrawing.graphml.KeyForType) Map(java.util.Map) GraphmlType(org.graphdrawing.graphml.GraphmlType) KeyType(org.graphdrawing.graphml.KeyType) GraphType(org.graphdrawing.graphml.GraphType) JAXB(javax.xml.bind.JAXB) EdgeType(org.graphdrawing.graphml.EdgeType) KeyType(org.graphdrawing.graphml.KeyType) DataType(org.graphdrawing.graphml.DataType) Map(java.util.Map)

Aggregations

File (java.io.File)1 List (java.util.List)1 Map (java.util.Map)1 Collectors (java.util.stream.Collectors)1 JAXB (javax.xml.bind.JAXB)1 DataType (org.graphdrawing.graphml.DataType)1 EdgeType (org.graphdrawing.graphml.EdgeType)1 GraphType (org.graphdrawing.graphml.GraphType)1 GraphmlType (org.graphdrawing.graphml.GraphmlType)1 KeyForType (org.graphdrawing.graphml.KeyForType)1 KeyType (org.graphdrawing.graphml.KeyType)1 KeyTypeType (org.graphdrawing.graphml.KeyTypeType)1 NodeType (org.graphdrawing.graphml.NodeType)1