use of org.gephi.io.importer.api.PropertiesAssociations.NodeProperties in project gephi by gephi.
the class ImporterGraphML method readNodeAttValue.
private void readNodeAttValue(XMLStreamReader reader, NodeDraft node) throws Exception {
String fore = "";
String value = "";
for (int i = 0; i < reader.getAttributeCount(); i++) {
String attName = reader.getAttributeName(i).getLocalPart();
if (ATTVALUE_FOR.equalsIgnoreCase(attName)) {
fore = reader.getAttributeValue(i).trim();
}
}
if (fore.isEmpty()) {
report.logIssue(new Issue(NbBundle.getMessage(ImporterGraphML.class, "importerGraphML_error_datakey", node), Issue.Level.SEVERE));
return;
}
boolean end = false;
while (reader.hasNext() && !end) {
int xmltype = reader.next();
switch(xmltype) {
case XMLStreamReader.CHARACTERS:
if (!xmlReader.isWhiteSpace()) {
value += xmlReader.getText();
}
break;
case XMLStreamReader.END_ELEMENT:
if (ATTVALUE.equalsIgnoreCase(xmlReader.getLocalName())) {
end = true;
}
break;
}
}
if (!value.isEmpty()) {
// Property
NodeProperties prop = nodePropertiesAttributes.get(fore);
if (prop != null) {
try {
switch(prop) {
case X:
node.setX(parseFloat(value));
break;
case Y:
node.setY(parseFloat(value));
break;
case Z:
node.setZ(parseFloat(value));
break;
case SIZE:
node.setSize(parseFloat(value));
break;
case LABEL:
node.setLabel(value);
break;
case COLOR:
node.setColor(value);
break;
case R:
if (node.getColor() == null) {
node.setColor(Integer.parseInt(value), 0, 0);
} else {
node.setColor(Integer.parseInt(value), node.getColor().getGreen(), node.getColor().getBlue());
}
break;
case G:
if (node.getColor() == null) {
node.setColor(0, Integer.parseInt(value), 0);
} else {
node.setColor(node.getColor().getRed(), Integer.parseInt(value), node.getColor().getBlue());
}
break;
case B:
if (node.getColor() == null) {
node.setColor(0, 0, Integer.parseInt(value));
} else {
node.setColor(node.getColor().getRed(), node.getColor().getGreen(), Integer.parseInt(value));
}
break;
}
} catch (Exception e) {
report.logIssue(new Issue(NbBundle.getMessage(ImporterGraphML.class, "importerGraphML_error_datavalue", fore, node, prop.toString()), Issue.Level.SEVERE));
}
}
// Data attribute value
ColumnDraft column = container.getNodeColumn(fore);
if (column != null) {
try {
node.parseAndSetValue(column.getId(), value);
} catch (Exception e) {
report.logIssue(new Issue(NbBundle.getMessage(ImporterGraphML.class, "importerGraphML_error_datavalue", fore, node, column.getTitle()), Issue.Level.SEVERE));
}
}
}
}
use of org.gephi.io.importer.api.PropertiesAssociations.NodeProperties in project gephi by gephi.
the class ImporterGraphML method readAttribute.
private void readAttribute(XMLStreamReader reader) throws Exception {
String id = "";
String type = "";
String title = "";
String defaultStr = "";
String forStr = "all";
for (int i = 0; i < reader.getAttributeCount(); i++) {
String attName = reader.getAttributeName(i).getLocalPart();
if (ATTRIBUTE_ID.equalsIgnoreCase(attName)) {
id = reader.getAttributeValue(i).trim();
} else if (ATTRIBUTE_TYPE.equalsIgnoreCase(attName)) {
type = reader.getAttributeValue(i).trim();
} else if (ATTRIBUTE_TITLE.equalsIgnoreCase(attName)) {
title = reader.getAttributeValue(i).trim();
} else if (ATTRIBUTE_FOR.equalsIgnoreCase(attName)) {
forStr = reader.getAttributeValue(i).trim();
}
}
if (title.isEmpty()) {
title = id;
}
boolean property = false;
if (!id.isEmpty()) {
// Properties
if (forStr.equalsIgnoreCase("node")) {
NodeProperties prop = properties.getNodeProperty(id) == null ? properties.getNodeProperty(title) : properties.getNodeProperty(id);
if (prop != null) {
nodePropertiesAttributes.put(id, prop);
report.log(NbBundle.getMessage(ImporterGraphML.class, "importerGraphML_log_nodeproperty", title));
property = true;
}
} else if (forStr.equalsIgnoreCase("edge")) {
EdgeProperties prop = properties.getEdgeProperty(id) == null ? properties.getEdgeProperty(title) : properties.getEdgeProperty(id);
if (prop != null) {
edgePropertiesAttributes.put(id, prop);
report.log(NbBundle.getMessage(ImporterGraphML.class, "importerGraphML_log_edgeproperty", title));
property = true;
}
}
if (property) {
return;
}
} else {
report.logIssue(new Issue(NbBundle.getMessage(ImporterGraphML.class, "importerGraphML_error_attributeempty", title), Issue.Level.SEVERE));
return;
}
if (!property && type.isEmpty()) {
report.logIssue(new Issue(NbBundle.getMessage(ImporterGraphML.class, "importerGraphML_error_attributetype1", title), Issue.Level.SEVERE));
type = "string";
}
if (!property) {
// Class type
if (forStr.isEmpty() || !(forStr.equalsIgnoreCase("node") || forStr.equalsIgnoreCase("edge") || forStr.equalsIgnoreCase("all"))) {
report.logIssue(new Issue(NbBundle.getMessage(ImporterGraphML.class, "importerGraphML_error_attributeclass", title), Issue.Level.SEVERE));
return;
}
// Default?
boolean end = false;
boolean defaultFlag = false;
while (reader.hasNext() && !end) {
int xmltype = reader.next();
switch(xmltype) {
case XMLStreamReader.START_ELEMENT:
if (ATTRIBUTE_DEFAULT.equalsIgnoreCase(xmlReader.getLocalName())) {
defaultFlag = true;
}
break;
case XMLStreamReader.CHARACTERS:
if (defaultFlag && !xmlReader.isWhiteSpace()) {
defaultStr = xmlReader.getText();
}
break;
case XMLStreamReader.END_ELEMENT:
if (ATTRIBUTE.equalsIgnoreCase(xmlReader.getLocalName())) {
end = true;
}
break;
}
}
// Type
Class attributeType = String.class;
if (type.equalsIgnoreCase("boolean") || type.equalsIgnoreCase("bool")) {
attributeType = boolean.class;
} else if (type.equalsIgnoreCase("integer") || type.equalsIgnoreCase("int")) {
attributeType = int.class;
} else if (type.equalsIgnoreCase("long")) {
attributeType = Long.class;
} else if (type.equalsIgnoreCase("float")) {
attributeType = Float.class;
} else if (type.equalsIgnoreCase("double")) {
attributeType = Double.class;
} else if (type.equalsIgnoreCase("string")) {
attributeType = String.class;
} else if (type.equalsIgnoreCase("bigdecimal")) {
attributeType = BigDecimal.class;
} else if (type.equalsIgnoreCase("biginteger")) {
attributeType = BigInteger.class;
} else if (type.equalsIgnoreCase("byte")) {
attributeType = Byte.class;
} else if (type.equalsIgnoreCase("char")) {
attributeType = Character.class;
} else if (type.equalsIgnoreCase("short")) {
attributeType = Short.class;
} else if (type.equalsIgnoreCase("listboolean")) {
attributeType = boolean[].class;
} else if (type.equalsIgnoreCase("listint")) {
attributeType = int[].class;
} else if (type.equalsIgnoreCase("listlong")) {
attributeType = long[].class;
} else if (type.equalsIgnoreCase("listfloat")) {
attributeType = float[].class;
} else if (type.equalsIgnoreCase("listdouble")) {
attributeType = double[].class;
} else if (type.equalsIgnoreCase("liststring")) {
attributeType = String[].class;
} else if (type.equalsIgnoreCase("listbigdecimal")) {
attributeType = BigDecimal[].class;
} else if (type.equalsIgnoreCase("listbiginteger")) {
attributeType = BigInteger[].class;
} else if (type.equalsIgnoreCase("listbyte")) {
attributeType = byte[].class;
} else if (type.equalsIgnoreCase("listchar")) {
attributeType = char[].class;
} else if (type.equalsIgnoreCase("listshort")) {
attributeType = short[].class;
} else {
report.logIssue(new Issue(NbBundle.getMessage(ImporterGraphML.class, "importerGraphML_error_attributetype2", type), Issue.Level.SEVERE));
return;
}
// Add to model
ColumnDraft column = null;
if ("node".equalsIgnoreCase(forStr) || "all".equalsIgnoreCase(forStr)) {
if (container.getNodeColumn(id) != null) {
report.log(NbBundle.getMessage(ImporterGraphML.class, "importerGraphML_error_attributecolumn_exist", id));
return;
}
column = container.addNodeColumn(id, attributeType);
column.setTitle(title);
report.log(NbBundle.getMessage(ImporterGraphML.class, "importerGraphML_log_nodeattribute", title, attributeType.getCanonicalName()));
}
if ("edge".equalsIgnoreCase(forStr) || "all".equalsIgnoreCase(forStr)) {
if (container.getEdgeColumn(id) != null) {
report.log(NbBundle.getMessage(ImporterGraphML.class, "importerGraphML_error_attributecolumn_exist", id));
return;
}
column = container.addEdgeColumn(id, attributeType);
column.setTitle(title);
report.log(NbBundle.getMessage(ImporterGraphML.class, "importerGraphML_log_edgeattribute", title, attributeType.getCanonicalName()));
}
if (column != null && !defaultStr.isEmpty()) {
try {
column.setDefaultValueString(defaultStr);
report.log(NbBundle.getMessage(ImporterGraphML.class, "importerGraphML_log_default", defaultStr, title));
} catch (Exception e) {
report.logIssue(new Issue(NbBundle.getMessage(ImporterGraphML.class, "importerGraphML_error_attributedefault", title, attributeType.getCanonicalName()), Issue.Level.SEVERE));
}
}
} else {
report.logIssue(new Issue(NbBundle.getMessage(ImporterGraphML.class, "importerGraphML_error_attributeempty", title), Issue.Level.SEVERE));
}
}
use of org.gephi.io.importer.api.PropertiesAssociations.NodeProperties in project gephi by gephi.
the class ImporterEdgeList method findNodeAttributesColumns.
private void findNodeAttributesColumns(ResultSet rs) throws SQLException {
ResultSetMetaData metaData = rs.getMetaData();
int columnsCount = metaData.getColumnCount();
for (int i = 0; i < columnsCount; i++) {
String columnName = metaData.getColumnLabel(i + 1);
NodeProperties p = database.getPropertiesAssociations().getNodeProperty(columnName);
if (p == null) {
// No property associated to this column is found, so we append it as an attribute
Class typeClass = findTypeClass(metaData, i);
container.addNodeColumn(columnName, typeClass);
}
}
}
use of org.gephi.io.importer.api.PropertiesAssociations.NodeProperties in project gephi by gephi.
the class ImporterEdgeList method getNodes.
private void getNodes(Connection connection) throws SQLException {
// Factory
ElementDraft.Factory factory = container.factory();
// Properties
PropertiesAssociations properties = database.getPropertiesAssociations();
Statement s = connection.createStatement();
ResultSet rs = null;
try {
rs = s.executeQuery(database.getNodeQuery());
} catch (SQLException ex) {
report.logIssue(new Issue("Failed to execute Node query", Issue.Level.SEVERE, ex));
return;
}
findNodeAttributesColumns(rs);
ResultSetMetaData metaData = rs.getMetaData();
int columnsCount = metaData.getColumnCount();
int idColumn = nodeColumns.findIdIndex(metaData, properties);
while (rs.next()) {
final NodeDraft node = nodeColumns.getNodeDraft(factory, rs, idColumn);
for (int i = 0; i < columnsCount; i++) {
String columnName = metaData.getColumnLabel(i + 1);
NodeProperties p = properties.getNodeProperty(columnName);
if (p != null) {
injectNodeProperty(p, rs, i + 1, node);
} else {
// Inject node attributes
ColumnDraft col = container.getNodeColumn(columnName);
injectElementAttribute(rs, i + 1, col, node);
}
}
injectTimeIntervalProperty(node);
container.addNode(node);
}
rs.close();
s.close();
}
Aggregations