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);
}
}
Aggregations