Search in sources :

Example 86 with PortObjectSpec

use of org.knime.core.node.port.PortObjectSpec in project knime-core by knime.

the class TableColumnToVariableNodeModel method configure.

/**
 * {@inheritDoc}
 */
@Override
protected PortObjectSpec[] configure(final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
    if (inSpecs[0] instanceof DataTableSpec) {
        final DataTableSpec spec = (DataTableSpec) inSpecs[0];
        if (m_column.getColumnName().equals(DEFAULT_COLUMN)) {
            errorOrDefault(spec, "No column selected");
        }
        final int colIndex = spec.findColumnIndex(m_column.getStringValue());
        if (colIndex < 0) {
            String errorMessage = "Wrong column name, not in input: " + m_column.getStringValue() + " in: " + spec;
            errorOrDefault(spec, errorMessage);
        }
    } else {
        throw new InvalidSettingsException("Wrong input type: " + inSpecs[0]);
    }
    return new PortObjectSpec[] { FlowVariablePortObjectSpec.INSTANCE };
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) PortObjectSpec(org.knime.core.node.port.PortObjectSpec) FlowVariablePortObjectSpec(org.knime.core.node.port.flowvariable.FlowVariablePortObjectSpec)

Example 87 with PortObjectSpec

use of org.knime.core.node.port.PortObjectSpec in project knime-core by knime.

the class DBColumnFilterNodeModel method configure.

/**
 * {@inheritDoc}
 */
@Override
protected PortObjectSpec[] configure(final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
    DatabasePortObjectSpec spec = (DatabasePortObjectSpec) inSpecs[0];
    StringBuilder buf = new StringBuilder();
    for (String column : m_filter.getIncludeList()) {
        if (!spec.getDataTableSpec().containsName(column)) {
            buf.append("\"" + column + "\" ");
        }
    }
    if (buf.length() > 0) {
        throw new InvalidSettingsException("Not all columns available in " + "input spec: " + buf.toString());
    }
    DatabaseQueryConnectionSettings conn = spec.getConnectionSettings(getCredentialsProvider());
    ColumnRearranger colre = new ColumnRearranger(spec.getDataTableSpec());
    colre.keepOnly(m_filter.getIncludeList().toArray(new String[0]));
    final DataTableSpec resultSpec = colre.createSpec();
    final String newQuery = createQuery(conn, resultSpec);
    conn = createDBQueryConnection(spec, newQuery);
    return new PortObjectSpec[] { new DatabasePortObjectSpec(resultSpec, conn.createConnectionModel()) };
}
Also used : DatabaseQueryConnectionSettings(org.knime.core.node.port.database.DatabaseQueryConnectionSettings) DataTableSpec(org.knime.core.data.DataTableSpec) ColumnRearranger(org.knime.core.data.container.ColumnRearranger) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) PortObjectSpec(org.knime.core.node.port.PortObjectSpec) DatabasePortObjectSpec(org.knime.core.node.port.database.DatabasePortObjectSpec) DatabasePortObjectSpec(org.knime.core.node.port.database.DatabasePortObjectSpec) SettingsModelFilterString(org.knime.core.node.defaultnodesettings.SettingsModelFilterString)

Example 88 with PortObjectSpec

use of org.knime.core.node.port.PortObjectSpec in project knime-core by knime.

the class TableRowToImageNodeModel method configure.

/**
 * {@inheritDoc}
 */
@Override
protected PortObjectSpec[] configure(final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
    DataTableSpec inSpec = (DataTableSpec) inSpecs[0];
    String column = m_imageColSettingsModel.getStringValue();
    int columnIndex = inSpec.findColumnIndex(column);
    if (columnIndex < 0) {
        columnIndex = findImageColumnIndex(inSpec);
        if (columnIndex >= 0) {
            setWarningMessage("Found image column '" + inSpec.getColumnSpec(columnIndex).getName() + "'.");
        }
    }
    if (columnIndex < 0) {
        String error = column == null ? "No image column in input" : "No such image column in input table: " + column;
        throw new InvalidSettingsException(error);
    }
    DataColumnSpec columnSpec = inSpec.getColumnSpec(columnIndex);
    if (!columnSpec.getType().isCompatible(ImageValue.class)) {
        throw new InvalidSettingsException("Column \"" + column + "\" does not contain images");
    }
    return new PortObjectSpec[] { new ImagePortObjectSpec(columnSpec.getType()) };
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) DataColumnSpec(org.knime.core.data.DataColumnSpec) ImagePortObjectSpec(org.knime.core.node.port.image.ImagePortObjectSpec) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) ImagePortObjectSpec(org.knime.core.node.port.image.ImagePortObjectSpec) PortObjectSpec(org.knime.core.node.port.PortObjectSpec) SettingsModelString(org.knime.core.node.defaultnodesettings.SettingsModelString) ImageValue(org.knime.core.data.image.ImageValue)

Example 89 with PortObjectSpec

use of org.knime.core.node.port.PortObjectSpec in project knime-core by knime.

the class DBQueryNodeModel method configure.

/**
 * {@inheritDoc}
 */
@Override
protected PortObjectSpec[] configure(final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
    DatabasePortObjectSpec spec = (DatabasePortObjectSpec) inSpecs[0];
    DatabaseQueryConnectionSettings conn = spec.getConnectionSettings(getCredentialsProvider());
    String newQuery = createQuery(conn.getQuery());
    conn = createDBQueryConnection(spec, newQuery);
    if (!conn.getRetrieveMetadataInConfigure()) {
        return new PortObjectSpec[1];
    }
    try {
        DBReader reader = conn.getUtility().getReader(conn);
        DataTableSpec outSpec = reader.getDataTableSpec(getCredentialsProvider());
        DatabasePortObjectSpec dbSpec = new DatabasePortObjectSpec(outSpec, conn.createConnectionModel());
        return new PortObjectSpec[] { dbSpec };
    } catch (Throwable t) {
        throw new InvalidSettingsException(t);
    }
}
Also used : DatabaseQueryConnectionSettings(org.knime.core.node.port.database.DatabaseQueryConnectionSettings) DataTableSpec(org.knime.core.data.DataTableSpec) DBReader(org.knime.core.node.port.database.reader.DBReader) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) PortObjectSpec(org.knime.core.node.port.PortObjectSpec) DatabasePortObjectSpec(org.knime.core.node.port.database.DatabasePortObjectSpec) DatabasePortObjectSpec(org.knime.core.node.port.database.DatabasePortObjectSpec) SettingsModelString(org.knime.core.node.defaultnodesettings.SettingsModelString)

Example 90 with PortObjectSpec

use of org.knime.core.node.port.PortObjectSpec in project knime-core by knime.

the class DBSorterNodeModel method configure.

/**
 * {@inheritDoc}
 */
@Override
protected PortObjectSpec[] configure(final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
    DatabasePortObjectSpec spec = (DatabasePortObjectSpec) inSpecs[0];
    for (String columnName : m_columns) {
        if (!spec.getDataTableSpec().containsName(columnName)) {
            throw new InvalidSettingsException("Can't filter according to selected column \"" + columnName + "\".");
        }
    }
    DatabaseQueryConnectionSettings conn = spec.getConnectionSettings(getCredentialsProvider());
    String newQuery = createQuery(conn.getQuery(), conn.getUtility().getStatementManipulator());
    conn = createDBQueryConnection(spec, newQuery);
    return new PortObjectSpec[] { new DatabasePortObjectSpec(spec.getDataTableSpec(), conn.createConnectionModel()) };
}
Also used : DatabaseQueryConnectionSettings(org.knime.core.node.port.database.DatabaseQueryConnectionSettings) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) PortObjectSpec(org.knime.core.node.port.PortObjectSpec) DatabasePortObjectSpec(org.knime.core.node.port.database.DatabasePortObjectSpec) DatabasePortObjectSpec(org.knime.core.node.port.database.DatabasePortObjectSpec)

Aggregations

PortObjectSpec (org.knime.core.node.port.PortObjectSpec)139 DataTableSpec (org.knime.core.data.DataTableSpec)93 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)86 PMMLPortObjectSpec (org.knime.core.node.port.pmml.PMMLPortObjectSpec)35 SettingsModelString (org.knime.core.node.defaultnodesettings.SettingsModelString)30 DataColumnSpec (org.knime.core.data.DataColumnSpec)29 FlowVariablePortObjectSpec (org.knime.core.node.port.flowvariable.FlowVariablePortObjectSpec)25 IOException (java.io.IOException)24 ColumnRearranger (org.knime.core.data.container.ColumnRearranger)24 InactiveBranchPortObjectSpec (org.knime.core.node.port.inactive.InactiveBranchPortObjectSpec)24 PortObject (org.knime.core.node.port.PortObject)19 FlowVariablePortObject (org.knime.core.node.port.flowvariable.FlowVariablePortObject)16 InactiveBranchPortObject (org.knime.core.node.port.inactive.InactiveBranchPortObject)16 PMMLPortObjectSpecCreator (org.knime.core.node.port.pmml.PMMLPortObjectSpecCreator)14 FileStorePortObject (org.knime.core.data.filestore.FileStorePortObject)13 File (java.io.File)12 ArrayList (java.util.ArrayList)12 DatabasePortObjectSpec (org.knime.core.node.port.database.DatabasePortObjectSpec)12 DatabaseQueryConnectionSettings (org.knime.core.node.port.database.DatabaseQueryConnectionSettings)12 PMMLPortObject (org.knime.core.node.port.pmml.PMMLPortObject)12