Skip to content

Commit

Permalink
Improved Error-Handling in IJ2 Integration
Browse files Browse the repository at this point in the history
  • Loading branch information
dietzc committed Jul 3, 2014
1 parent 8eebbc0 commit 05417ee
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
*/
public abstract class AbstractIJCellFactory implements CellFactory {

protected static final NodeLogger LOGGER = NodeLogger.getLogger(AbstractIJCellFactory.class);
private static final NodeLogger LOGGER = NodeLogger.getLogger(AbstractIJCellFactory.class);

/** counts the number of errors that resulted in missing cell output. */
private int m_missingCellCount;
Expand Down Expand Up @@ -201,8 +201,9 @@ protected void configureDataValueConfigItems(final DataRow row, final Module mod
*
* @param rowModule a fully configured module ready for execution
* @return list of DataCells that contains the module results
* @throws Exception
*/
protected List<DataCell> executeRowModule(final Module rowModule) {
protected List<DataCell> executeRowModule(final Module rowModule) throws Exception {
@SuppressWarnings("rawtypes")
final Map<Class<?>, IJOutputAdapterInstance> adapterMap = new HashMap<Class<?>, IJOutputAdapterInstance>();

Expand Down Expand Up @@ -255,4 +256,8 @@ public void setProgress(final int curRowNr, final int rowCount, final RowKey las
exec.setProgress((double)curRowNr / rowCount);
}

protected void fireWarning(final String rowKey, final String cause) {
LOGGER.warn("Error while executing row: " + rowKey + "! Cause: " + cause);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -126,16 +126,27 @@ public DataCell[] getCells(final DataRow row) {
final Module module = AbstractIJNodeModel.createDialogConfiguredModule(m_moduleInfo, m_dialogModuleSettings);

configureRowConfigItems(row, module, m_moduleItemConfigs);
List<DataCell> resCells = null;
try {
configureDataValueConfigItems(row, module, m_moduleItemConfigs, m_identifier2CellID);

//execute the configured plugin
resCells = executeRowModule(module);

} catch (MethodCallException e) {
LOGGER.warn("Error while executing row: " + row.getKey().getString()
+ "! Following problem occured: " + e.getCause().getCause().getMessage());
return null;
fireWarning(row.getKey().getString(), e.getCause().getCause().getMessage());
} catch (Exception e) {
fireWarning(row.getKey().getString(), e.getMessage());
}

if (resCells == null) {
DataCell[] cells = new DataCell[module.getOutputs().size()];
for (int i = 0; i < cells.length; i++) {
cells[i] = DataType.getMissingCell();
}
return cells;
}

//execute the configured plugin
final List<DataCell> resCells = executeRowModule(module);
return resCells.toArray(new DataCell[resCells.size()]);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,8 @@
import java.util.LinkedList;
import java.util.List;

import org.knime.core.data.DataCell;
import org.knime.core.data.DataRow;
import org.knime.core.data.DataTableSpec;
import org.knime.core.data.DataType;
import org.knime.core.data.RowIterator;
import org.knime.core.data.RowKey;
import org.knime.core.data.container.ColumnRearranger;
Expand Down Expand Up @@ -186,19 +184,8 @@ protected BufferedDataTable[] createResultTable(final BufferedDataTable[] inData
final BufferedDataContainer con = exec.createDataContainer(new DataTableSpec(cellFac.getColumnSpecs()));

final RowKey key = new RowKey("Row1");
DataCell[] cells = cellFac.getCells(null);

if (cells == null) {
cells = new DataCell[cellFac.getColumnSpecs().length];
for (int i = 0; i < cells.length; i++) {
cells[i] = DataType.getMissingCell();
}
}

con.addRowToTable(new DefaultRow(key, cells));

con.addRowToTable(new DefaultRow(key, cellFac.getCells(null)));
cellFac.setProgress(1, 1, key, exec);

con.close();
return new BufferedDataTable[]{con.getTable()};
} else if (m_appendColumns.getBooleanValue()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,35 +150,46 @@ public ValueToCellIJCellFactory(final ModuleInfo moduleInfo, final SettingsModel
@Override
public DataCell[] getCells(final DataRow row) {
final List<DataCell> resCells = new ArrayList<DataCell>();
for (int i = 0; i < m_selectedColIndices.length; i++) {
if (row.getCell(m_selectedColIndices[i]).isMissing()) {
resCells.add(DataType.getMissingCell());
} else {
final Module module =
AbstractIJNodeModel.createDialogConfiguredModule(m_moduleInfo, m_dialogModuleSettings);
//data value config
m_valueConfig.setConfigurationData(new DataValue[]{row.getCell(m_selectedColIndices[i])});
m_valueConfig.resolveHandledModuleItems(module, false);

synchronized (lock) {
m_valueConfig.configureModuleItem(module);
ModuleItem<?> item = m_valueConfig.getItem();
try {
try {
for (int i = 0; i < m_selectedColIndices.length; i++) {
if (row.getCell(m_selectedColIndices[i]).isMissing()) {
resCells.add(DataType.getMissingCell());
} else {
final Module module =
AbstractIJNodeModel.createDialogConfiguredModule(m_moduleInfo, m_dialogModuleSettings);
//data value config
m_valueConfig.setConfigurationData(new DataValue[]{row.getCell(m_selectedColIndices[i])});
m_valueConfig.resolveHandledModuleItems(module, false);

synchronized (lock) {
m_valueConfig.configureModuleItem(module);
ModuleItem<?> item = m_valueConfig.getItem();
item.callback(module);
} catch (MethodCallException e) {
LOGGER.warn("Error while executing row: " + row.getKey().getString()
+ "! Following problem occured: " + e.getCause().getCause().getMessage());
return null;
}

//remaining config only for row configs => column binding tab yes
//valueConfig no
configureRowConfigItems(row, module, m_moduleItemConfigs);

//execute - and add one data cell per iteration
DataCell dataCell = executeRowModule(module).get(0);
resCells.add(dataCell);
}
}

} catch (MethodCallException e) {
fireWarning(row.getKey().getString(), e.getCause().getCause().getMessage());

//remaining config only for row configs => column binding tab yes
//valueConfig no
configureRowConfigItems(row, module, m_moduleItemConfigs);
} catch (Exception e) {
fireWarning(row.getKey().getString(), e.getMessage());
}

//execute - and add one data cell per iteration
resCells.add(executeRowModule(module).get(0));
if (resCells.size() != m_selectedColIndices.length) {
DataCell[] cells = new DataCell[m_selectedColIndices.length];
for (int i = 0; i < cells.length; i++) {
cells[i] = DataType.getMissingCell();
}
return cells;
}

return resCells.toArray(new DataCell[resCells.size()]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,9 @@
import java.util.LinkedList;
import java.util.List;

import org.knime.core.data.DataCell;
import org.knime.core.data.DataColumnSpec;
import org.knime.core.data.DataRow;
import org.knime.core.data.DataTableSpec;
import org.knime.core.data.DataType;
import org.knime.core.data.DataValue;
import org.knime.core.data.RowIterator;
import org.knime.core.data.container.CellFactory;
Expand Down Expand Up @@ -194,17 +192,7 @@ protected BufferedDataTable[] createResultTable(final BufferedDataTable[] inData

while (it.hasNext()) {
row = it.next();

DataCell[] cells = cellFac.getCells(row);

if (cells == null) {
cells = new DataCell[cellFac.getColumnSpecs().length];
for (int k = 0; k < cells.length; k++) {
cells[k] = DataType.getMissingCell();
}
}

con.addRowToTable(new DefaultRow(row.getKey(), cells));
con.addRowToTable(new DefaultRow(row.getKey(), cellFac.getCells(row)));
exec.checkCanceled();
cellFac.setProgress(i, rowCount, row.getKey(), exec);
i++;
Expand Down

0 comments on commit 05417ee

Please sign in to comment.