Search in sources :

Example 41 with Issue

use of org.gephi.io.importer.api.Issue in project gephi by gephi.

the class ImportContainerImpl method setInterval.

@Override
public void setInterval(String startDateTime, String endDateTime) {
    try {
        double start, end;
        if (startDateTime == null || startDateTime.isEmpty() || "-inf".equalsIgnoreCase(startDateTime) || "-infinity".equalsIgnoreCase(startDateTime)) {
            start = Double.NEGATIVE_INFINITY;
        } else {
            start = timeFormat.equals(TimeFormat.DOUBLE) ? Double.parseDouble(startDateTime) : AttributeUtils.parseDateTime(startDateTime);
        }
        if (endDateTime == null || endDateTime.isEmpty() || "inf".equalsIgnoreCase(endDateTime) || "infinity".equalsIgnoreCase(endDateTime)) {
            end = Double.POSITIVE_INFINITY;
        } else {
            end = timeFormat.equals(TimeFormat.DOUBLE) ? Double.parseDouble(endDateTime) : AttributeUtils.parseDateTime(endDateTime);
        }
        this.interval = new Interval(start, end);
    } catch (Exception e) {
        report.logIssue(new Issue(NbBundle.getMessage(ImportContainerImpl.class, "ImportContainerException_Interval_Parse_Error", "[" + startDateTime + "," + endDateTime + "]"), Level.SEVERE));
        return;
    }
    report.log(NbBundle.getMessage(ImportContainerImpl.class, "ImportContainerLog.GraphInterval", "[" + startDateTime + "," + endDateTime + "]"));
}
Also used : Issue(org.gephi.io.importer.api.Issue) Interval(org.gephi.graph.api.Interval)

Example 42 with Issue

use of org.gephi.io.importer.api.Issue 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();
    while (rs.next()) {
        String id = null;
        for (int i = 0; i < columnsCount; i++) {
            String columnName = metaData.getColumnLabel(i + 1);
            NodeProperties p = properties.getNodeProperty(columnName);
            if (p != null && p.equals(NodeProperties.ID)) {
                String ide = rs.getString(i + 1);
                if (ide != null) {
                    id = ide;
                }
            }
        }
        NodeDraft node;
        if (id != null) {
            node = factory.newNodeDraft(id);
        } else {
            node = factory.newNodeDraft();
        }
        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();
}
Also used : ColumnDraft(org.gephi.io.importer.api.ColumnDraft) Issue(org.gephi.io.importer.api.Issue) SQLException(java.sql.SQLException) ElementDraft(org.gephi.io.importer.api.ElementDraft) PropertiesAssociations(org.gephi.io.importer.api.PropertiesAssociations) Statement(java.sql.Statement) NodeDraft(org.gephi.io.importer.api.NodeDraft) ResultSetMetaData(java.sql.ResultSetMetaData) NodeProperties(org.gephi.io.importer.api.PropertiesAssociations.NodeProperties) ResultSet(java.sql.ResultSet)

Example 43 with Issue

use of org.gephi.io.importer.api.Issue in project gephi by gephi.

the class ImporterEdgeList method injectElementAttribute.

private void injectElementAttribute(ResultSet rs, int columnIndex, ColumnDraft column, ElementDraft draft) {
    String elementName;
    if (draft instanceof NodeDraft) {
        elementName = "node";
    } else {
        elementName = "edge";
    }
    Class typeClass = column.getTypeClass();
    if (typeClass.equals(Boolean.class)) {
        try {
            boolean val = rs.getBoolean(columnIndex);
            draft.setValue(column.getId(), val);
        } catch (SQLException ex) {
            report.logIssue(new Issue("Failed to get a BOOLEAN value for " + elementName + " attribute '" + column.getId() + "'", Issue.Level.SEVERE, ex));
        }
    } else if (typeClass.equals(Double.class)) {
        try {
            double val = rs.getDouble(columnIndex);
            draft.setValue(column.getId(), val);
        } catch (SQLException ex) {
            report.logIssue(new Issue("Failed to get a DOUBLE value for " + elementName + " attribute '" + column.getId() + "'", Issue.Level.SEVERE, ex));
        }
    } else if (typeClass.equals(Float.class)) {
        try {
            float val = rs.getFloat(columnIndex);
            draft.setValue(column.getId(), val);
        } catch (SQLException ex) {
            report.logIssue(new Issue("Failed to get a FLOAT value for " + elementName + " attribute '" + column.getId() + "'", Issue.Level.SEVERE, ex));
        }
    } else if (typeClass.equals(Integer.class)) {
        try {
            int val = rs.getInt(columnIndex);
            draft.setValue(column.getId(), val);
        } catch (SQLException ex) {
            report.logIssue(new Issue("Failed to get a INT value for " + elementName + " attribute '" + column.getId() + "'", Issue.Level.SEVERE, ex));
        }
    } else if (typeClass.equals(Long.class)) {
        try {
            long val = rs.getLong(columnIndex);
            draft.setValue(column.getId(), val);
        } catch (SQLException ex) {
            report.logIssue(new Issue("Failed to get a LONG value for " + elementName + " attribute '" + column.getId() + "'", Issue.Level.SEVERE, ex));
        }
    } else if (typeClass.equals(Short.class)) {
        try {
            short val = rs.getShort(columnIndex);
            draft.setValue(column.getId(), val);
        } catch (SQLException ex) {
            report.logIssue(new Issue("Failed to get a SHORT value for " + elementName + " attribute '" + column.getId() + "'", Issue.Level.SEVERE, ex));
        }
    } else if (typeClass.equals(Byte.class)) {
        try {
            byte val = rs.getByte(columnIndex);
            draft.setValue(column.getId(), val);
        } catch (SQLException ex) {
            report.logIssue(new Issue("Failed to get a BYTE value for " + elementName + " attribute '" + column.getId() + "'", Issue.Level.SEVERE, ex));
        }
    } else {
        try {
            String val = rs.getString(columnIndex);
            if (val != null) {
                draft.setValue(column.getId(), val);
            } else {
                report.logIssue(new Issue("Failed to get a STRING value for " + elementName + " attribute '" + column.getId() + "'", Issue.Level.WARNING));
            }
        } catch (SQLException ex) {
            report.logIssue(new Issue("Failed to get a STRING value for " + elementName + " attribute '" + column.getId() + "'", Issue.Level.SEVERE, ex));
        }
    }
}
Also used : Issue(org.gephi.io.importer.api.Issue) SQLException(java.sql.SQLException) NodeDraft(org.gephi.io.importer.api.NodeDraft)

Example 44 with Issue

use of org.gephi.io.importer.api.Issue in project gephi by gephi.

the class ImporterPajek method readVertex.

private void readVertex(String curLine, int num_vertices) throws Exception {
    String[] parts = null;
    // index of first coordinate in parts; -1 indicates no coordinates found
    int firstParts = -1;
    String index;
    String label = null;
    // if there are quote marks on this line, split on them; label is surrounded by them
    if (curLine.indexOf('"') != -1) {
        String[] initial_split = curLine.trim().split("\"");
        // if there are any quote marks, there should be exactly 2
        if (initial_split.length < 1 || initial_split.length > 3) {
            report.logIssue(new Issue(NbBundle.getMessage(ImporterPajek.class, "importerNET_error_dataformat3", lineReader.getLineNumber()), Issue.Level.SEVERE));
        }
        index = initial_split[0].trim();
        if (initial_split.length > 1) {
            label = initial_split[1].trim();
        }
        if (initial_split.length == 3) {
            parts = initial_split[2].trim().split("\\s+", -1);
        }
        firstParts = 0;
    } else // no quote marks, but are there coordinates?
    {
        parts = curLine.trim().split("\\s+", -1);
        index = parts[0];
        switch(parts.length) {
            case // just the ID; nothing to do, continue
            1:
                break;
            case // just the ID and a label
            2:
                label = parts[1];
                break;
            case // ID, no label, coordinates
            3:
                firstParts = 1;
                break;
            case // ID, label, (x,y) coordinates
            4:
                firstParts = 2;
                break;
        }
    }
    // go from 1-based to 0-based index
    int v_id = Integer.parseInt(index) - 1;
    if (v_id >= num_vertices || v_id < 0) {
        report.logIssue(new Issue(NbBundle.getMessage(ImporterPajek.class, "importerNET_error_dataformat4", v_id, num_vertices), Issue.Level.SEVERE));
    }
    NodeDraft node = verticesArray[v_id];
    // only attach the label if there's one to attach
    if (label != null && label.length() > 0) {
        node.setLabel(label);
    }
    // parse the rest of the line
    if (firstParts != -1 && parts != null && parts.length >= firstParts + 2) {
        int i = firstParts;
        //Coordinates
        if (i < parts.length - 1) {
            try {
                float x = Float.parseFloat(parts[i]);
                float y = Float.parseFloat(parts[i + 1]);
                node.setX(x);
                node.setY(y);
                i++;
            } catch (Exception e) {
                report.logIssue(new Issue(NbBundle.getMessage(ImporterPajek.class, "importerNET_error_dataformat5", lineReader.getLineNumber()), Issue.Level.WARNING));
            }
        }
        //Size
        if (i < parts.length - 1) {
            try {
                float size = Float.parseFloat(parts[i]);
                node.setSize(size);
                i++;
            } catch (Exception e) {
                report.logIssue(new Issue(NbBundle.getMessage(ImporterPajek.class, "importerNET_error_dataformat6", lineReader.getLineNumber()), Issue.Level.WARNING));
            }
        }
        // parse colors
        for (; i < parts.length - 1; i++) {
            // node's internal color
            if ("ic".equals(parts[i])) {
                // remove spaces from color's name so we can look it up
                String colorName = parts[i + 1].replaceAll(" ", "");
                node.setColor(colorName);
                break;
            }
        }
    }
}
Also used : Issue(org.gephi.io.importer.api.Issue) NodeDraft(org.gephi.io.importer.api.NodeDraft) IOException(java.io.IOException)

Example 45 with Issue

use of org.gephi.io.importer.api.Issue in project gephi by gephi.

the class ImporterDL method readeMatrixBlock.

private void readeMatrixBlock(List<String> data) {
    int startTime = 0;
    for (int i = 0; i < data.size(); i++) {
        int rowNum = 0;
        for (; i < data.size() && !data.get(i).trim().equals("!"); i++) {
            if (rowNum <= numNodes) {
                readMatrixRow(data.get(i), i, rowNum, startTime, startTime + 1);
                rowNum++;
            } else {
                report.logIssue(new Issue(NbBundle.getMessage(ImporterDL.class, "importerDL_error_matrixrowscount", rowNum, numNodes), Issue.Level.SEVERE));
                break;
            }
        }
        if (rowNum < numNodes) {
            report.logIssue(new Issue(NbBundle.getMessage(ImporterDL.class, "importerDL_error_matrixrowscount2", rowNum, numNodes), Issue.Level.SEVERE));
        }
        startTime++;
    }
    if (startTime != numMatricies) {
        report.logIssue(new Issue(NbBundle.getMessage(ImporterDL.class, "importerDL_error_matriciescount", startTime, numMatricies), Issue.Level.SEVERE));
    }
}
Also used : Issue(org.gephi.io.importer.api.Issue)

Aggregations

Issue (org.gephi.io.importer.api.Issue)52 NodeDraft (org.gephi.io.importer.api.NodeDraft)14 IOException (java.io.IOException)11 ColumnDraft (org.gephi.io.importer.api.ColumnDraft)10 EdgeDraft (org.gephi.io.importer.api.EdgeDraft)9 StringTokenizer (java.util.StringTokenizer)5 SQLException (java.sql.SQLException)4 ArrayList (java.util.ArrayList)4 XMLStreamException (javax.xml.stream.XMLStreamException)3 Interval (org.gephi.graph.api.Interval)3 EdgeProperties (org.gephi.io.importer.api.PropertiesAssociations.EdgeProperties)3 NodeProperties (org.gephi.io.importer.api.PropertiesAssociations.NodeProperties)3 Color (java.awt.Color)2 ResultSet (java.sql.ResultSet)2 ResultSetMetaData (java.sql.ResultSetMetaData)2 Statement (java.sql.Statement)2 Pattern (java.util.regex.Pattern)2 IntervalSet (org.gephi.graph.api.types.IntervalSet)2 TimestampSet (org.gephi.graph.api.types.TimestampSet)2 ElementDraft (org.gephi.io.importer.api.ElementDraft)2