use of org.gephi.io.importer.api.ColumnDraft in project gephi by gephi.
the class AbstractProcessor method flushToElementAttributes.
protected void flushToElementAttributes(ContainerUnloader container, ElementDraft elementDraft, Element element) {
for (ColumnDraft columnDraft : elementDraft.getColumns()) {
if (elementDraft instanceof EdgeDraft && columnDraft.getId().equalsIgnoreCase("weight")) {
// Special weight column
continue;
}
Object val = elementDraft.getValue(columnDraft.getId());
Column column = element.getTable().getColumn(columnDraft.getId());
if (column == null) {
// The column might be not present, for cases when it cannot be added due to time representation mismatch, etc
continue;
}
if (column.isReadOnly()) {
continue;
}
Class columnDraftTypeClass = columnDraft.getResolvedTypeClass(container);
if (!column.getTypeClass().equals(columnDraftTypeClass)) {
if (!columnsTypeMismatchAlreadyWarned.contains(column)) {
columnsTypeMismatchAlreadyWarned.add(column);
String error = NbBundle.getMessage(AbstractProcessor.class, "AbstractProcessor.error.columnTypeMismatch", column.getId(), column.getTypeClass().getSimpleName(), columnDraftTypeClass.getSimpleName());
report.logIssue(new Issue(error, Issue.Level.SEVERE));
}
// Incompatible types!
continue;
}
if (val != null) {
Object processedNewValue = val;
Object existingValue = element.getAttribute(columnDraft.getId());
if (columnDraft.isDynamic() && existingValue != null) {
if (TimeMap.class.isAssignableFrom(columnDraft.getTypeClass())) {
TimeMap existingMap = (TimeMap) existingValue;
if (!existingMap.isEmpty()) {
TimeMap valMap = (TimeMap) val;
TimeMap newMap = (TimeMap) existingMap;
Object[] keys = valMap.toKeysArray();
Object[] vals = valMap.toValuesArray();
for (int i = 0; i < keys.length; i++) {
try {
newMap.put(keys[i], vals[i]);
} catch (IllegalArgumentException e) {
// Overlapping intervals, ignore
}
}
processedNewValue = newMap;
}
} else if (TimeSet.class.isAssignableFrom(columnDraft.getTypeClass())) {
TimeSet existingTimeSet = (TimeSet) existingValue;
processedNewValue = mergeTimeSets(existingTimeSet, (TimeSet) val);
}
}
element.setAttribute(columnDraft.getId(), processedNewValue);
}
}
}
use of org.gephi.io.importer.api.ColumnDraft in project gephi by gephi.
the class AbstractProcessor method addColumnsToTable.
private void addColumnsToTable(ContainerUnloader container, Table table, Iterable<ColumnDraft> columns) {
TimeRepresentation timeRepresentation = container.getTimeRepresentation();
for (ColumnDraft col : columns) {
if (!table.hasColumn(col.getId())) {
Class typeClass = col.getResolvedTypeClass(container);
if (Attributes.isTypeAvailable(typeClass, timeRepresentation)) {
Object defaultValue = col.getResolvedDefaultValue(container);
if (defaultValue != null && !typeClass.isAssignableFrom(defaultValue.getClass())) {
String error = NbBundle.getMessage(AbstractProcessor.class, "AbstractProcessor.error.columnDefaultValueTypeMismatch", col.getId(), defaultValue.toString(), defaultValue.getClass().getSimpleName(), typeClass.getSimpleName());
report.logIssue(new Issue(error, Issue.Level.SEVERE));
defaultValue = null;
}
table.addColumn(col.getId(), col.getTitle(), typeClass, Origin.DATA, defaultValue, !col.isDynamic());
} else {
String error = NbBundle.getMessage(AbstractProcessor.class, "AbstractProcessor.error.unavailableColumnType", typeClass.getSimpleName(), timeRepresentation.name(), col.getId());
report.logIssue(new Issue(error, Issue.Level.SEVERE));
}
}
}
}
use of org.gephi.io.importer.api.ColumnDraft in project gephi by gephi.
the class AbstractProcessor method flushToElementAttributes.
protected void flushToElementAttributes(ElementDraft elementDraft, Element element) {
for (ColumnDraft col : elementDraft.getColumns()) {
if (elementDraft instanceof EdgeDraft && col.getId().equals("weight")) {
continue;
}
Object val = elementDraft.getValue(col.getId());
if (val != null) {
TimeMap existingMap;
if (col.isDynamic() && (existingMap = (TimeMap) element.getAttribute(col.getId())) != null && !existingMap.isEmpty()) {
TimeMap valMap = (TimeMap) val;
Object[] keys = existingMap.toKeysArray();
Object[] vals = existingMap.toValuesArray();
for (int i = 0; i < keys.length; i++) {
valMap.put(keys[i], vals[i]);
}
element.setAttribute(col.getId(), valMap);
} else {
element.setAttribute(col.getId(), val);
}
}
}
}
use of org.gephi.io.importer.api.ColumnDraft in project gephi by gephi.
the class ImporterGDF method findEdgeColumns.
private void findEdgeColumns(String line) throws Exception {
String[] columns = line.split(",");
edgeColumns = new GDFColumn[columns.length - 2];
for (int i = 2; i < columns.length; i++) {
String columnString = columns[i];
String typeString = "";
String columnName = "";
Class type = String.class;
try {
typeString = columnString.substring(columnString.lastIndexOf(" ")).trim().toLowerCase();
} catch (IndexOutOfBoundsException e) {
}
try {
int end = columnString.lastIndexOf(" ");
if (end != -1) {
columnName = columnString.substring(0, end).trim().toLowerCase();
} else {
columnName = columnString.trim().toLowerCase();
}
} catch (IndexOutOfBoundsException e) {
}
// Check error
if (columnName.isEmpty()) {
report.logIssue(new Issue(NbBundle.getMessage(ImporterGDF.class, "importerGDF_error_dataformat2"), Issue.Level.SEVERE));
columnName = "default" + i;
}
if (typeString.isEmpty()) {
report.logIssue(new Issue(NbBundle.getMessage(ImporterGDF.class, "importerGDF_error_dataformat6", columnName), Issue.Level.INFO));
typeString = "varchar";
}
// Clean parenthesis
typeString = typeString.replaceAll("\\([0-9]*\\)", "");
if (typeString.equals("varchar")) {
type = String.class;
} else if (typeString.equals("bool")) {
type = Boolean.class;
} else if (typeString.equals("boolean")) {
type = Boolean.class;
} else if (typeString.equals("integer")) {
type = Integer.class;
} else if (typeString.equals("tinyint")) {
type = Integer.class;
} else if (typeString.equals("int")) {
type = Integer.class;
} else if (typeString.equals("double")) {
type = Double.class;
} else if (typeString.equals("float")) {
type = Float.class;
} else {
report.logIssue(new Issue(NbBundle.getMessage(ImporterGDF.class, "importerGDF_error_dataformat5", typeString), Issue.Level.WARNING));
}
if (columnName.equals("color")) {
edgeColumns[i - 2] = new GDFColumn(GDFColumn.EdgeGuessColumn.COLOR);
report.log("Edge property found: color");
} else if (columnName.equals("visible")) {
edgeColumns[i - 2] = new GDFColumn(GDFColumn.EdgeGuessColumn.VISIBLE);
report.log("Edge property found: visible");
} else if (columnName.equals("weight")) {
edgeColumns[i - 2] = new GDFColumn(GDFColumn.EdgeGuessColumn.WEIGHT);
report.log("Edge property found: weight");
} else if (columnName.equals("directed")) {
edgeColumns[i - 2] = new GDFColumn(GDFColumn.EdgeGuessColumn.DIRECTED);
report.log("Edge property found: directed");
} else if (columnName.equals("label")) {
edgeColumns[i - 2] = new GDFColumn(GDFColumn.EdgeGuessColumn.LABEL);
report.log("Edge property found: label");
} else if (columnName.equals("labelvisible")) {
edgeColumns[i - 2] = new GDFColumn(GDFColumn.EdgeGuessColumn.LABELVISIBLE);
report.log("Edge property found: labelvisible");
} else {
ColumnDraft column = container.getEdgeColumn(columnName);
if (column == null) {
column = container.addEdgeColumn(columnName, type);
edgeColumns[i - 2] = new GDFColumn(column);
report.log("Edge attribute " + columnName + " (" + type.getSimpleName() + ")");
} else {
report.logIssue(new Issue(NbBundle.getMessage(ImporterGDF.class, "importerGDF_error_dataformat9", columnName), Issue.Level.SEVERE));
}
}
}
}
use of org.gephi.io.importer.api.ColumnDraft in project gephi by gephi.
the class ImporterGDF method findNodeColumns.
private void findNodeColumns(String line) throws Exception {
String[] columns = line.split(",");
nodeColumns = new GDFColumn[columns.length - 1];
for (int i = 1; i < columns.length; i++) {
String columnString = columns[i];
String typeString = "";
String columnName = "";
Class type = String.class;
try {
typeString = columnString.substring(columnString.lastIndexOf(" ")).trim().toLowerCase();
} catch (IndexOutOfBoundsException e) {
}
try {
int end = columnString.lastIndexOf(" ");
if (end != -1) {
columnName = columnString.substring(0, end).trim().toLowerCase();
} else {
columnName = columnString.trim().toLowerCase();
}
} catch (IndexOutOfBoundsException e) {
}
// Check error
if (columnName.isEmpty()) {
report.logIssue(new Issue(NbBundle.getMessage(ImporterGDF.class, "importerGDF_error_dataformat2"), Issue.Level.SEVERE));
columnName = "default" + i;
}
if (typeString.isEmpty()) {
report.logIssue(new Issue(NbBundle.getMessage(ImporterGDF.class, "importerGDF_error_dataformat6", columnName), Issue.Level.INFO));
typeString = "varchar";
}
// Clean parenthesis
typeString = typeString.replaceAll("\\([0-9]*\\)", "");
if (typeString.equals("varchar")) {
type = String.class;
} else if (typeString.equals("bool")) {
type = Boolean.class;
} else if (typeString.equals("boolean")) {
type = Boolean.class;
} else if (typeString.equals("integer")) {
type = Integer.class;
} else if (typeString.equals("tinyint")) {
type = Integer.class;
} else if (typeString.equals("int")) {
type = Integer.class;
} else if (typeString.equals("double")) {
type = Double.class;
} else if (typeString.equals("float")) {
type = Float.class;
} else {
report.logIssue(new Issue(NbBundle.getMessage(ImporterGDF.class, "importerGDF_error_dataformat5", typeString), Issue.Level.WARNING));
}
if (columnName.equals("x")) {
nodeColumns[i - 1] = new GDFColumn(GDFColumn.NodeGuessColumn.X);
report.log("Node property found: x");
} else if (columnName.equals("y")) {
nodeColumns[i - 1] = new GDFColumn(GDFColumn.NodeGuessColumn.Y);
report.log("Node property found: y");
} else if (columnName.equals("visible")) {
nodeColumns[i - 1] = new GDFColumn(GDFColumn.NodeGuessColumn.VISIBLE);
report.log("Node property found: visible");
} else if (columnName.equals("color")) {
nodeColumns[i - 1] = new GDFColumn(GDFColumn.NodeGuessColumn.COLOR);
report.log("Node property found: color");
} else if (columnName.equals("fixed")) {
nodeColumns[i - 1] = new GDFColumn(GDFColumn.NodeGuessColumn.FIXED);
report.log("Node property found: fixed");
} else if (columnName.equals("style")) {
nodeColumns[i - 1] = new GDFColumn(GDFColumn.NodeGuessColumn.STYLE);
report.log("Node property found: style");
} else if (columnName.equals("width")) {
nodeColumns[i - 1] = new GDFColumn(GDFColumn.NodeGuessColumn.WIDTH);
report.log("Node property found: width");
} else if (columnName.equals("height")) {
nodeColumns[i - 1] = new GDFColumn(GDFColumn.NodeGuessColumn.HEIGHT);
report.log("Node property found: height");
} else if (columnName.equals("label")) {
nodeColumns[i - 1] = new GDFColumn(GDFColumn.NodeGuessColumn.LABEL);
report.log("Node property found: label");
} else if (columnName.equals("labelvisible")) {
nodeColumns[i - 1] = new GDFColumn(GDFColumn.NodeGuessColumn.LABELVISIBLE);
report.log("Node property found: labelvisible");
} else {
ColumnDraft column = container.getNodeColumn(columnName);
if (column == null) {
column = container.addNodeColumn(columnName, type);
nodeColumns[i - 1] = new GDFColumn(column);
report.log("Node attribute " + columnName + " (" + type.getSimpleName() + ")");
} else {
report.logIssue(new Issue(NbBundle.getMessage(ImporterGDF.class, "importerGDF_error_dataformat8", columnName), Issue.Level.SEVERE));
}
}
}
}
Aggregations