Search in sources :

Example 51 with NodeSettings

use of org.knime.core.node.NodeSettings in project knime-core by knime.

the class FixedHistogramDataModel method save2File.

/**
 * @param directory the directory to write to
 * @param exec the {@link ExecutionMonitor} to provide progress messages
 * @throws IOException if a file exception occurs
 * @throws CanceledExecutionException if the operation is canceled
 */
public void save2File(final File directory, final ExecutionMonitor exec) throws IOException, CanceledExecutionException {
    if (exec != null) {
        exec.setProgress(0.0, "Start saving histogram data model to file");
    }
    final File dataFile = new File(directory, CFG_DATA_FILE);
    final FileOutputStream os = new FileOutputStream(dataFile);
    final GZIPOutputStream dataOS = new GZIPOutputStream(os);
    final Config config = new NodeSettings(CFG_DATA);
    final ConfigWO xConf = config.addConfig(CFG_X_COL_SPEC);
    m_xColSpec.save(xConf);
    if (exec != null) {
        exec.setProgress(0.1, "Binning column specification saved");
        exec.setMessage("Start saving aggregation columns...");
    }
    config.addBoolean(CFG_NOMINAL, m_binNominal);
    config.addString(CFG_AGGR_METHOD, m_aggrMethod.getActionCommand());
    final Config aggrConf = config.addConfig(CFG_AGGR_COLS);
    aggrConf.addInt(CFG_AGGR_COL_COUNTER, m_aggrColumns.size());
    int idx = 0;
    for (final ColorColumn col : m_aggrColumns) {
        final ConfigWO aggrColConf = aggrConf.addConfig(CFG_COLOR_COL + idx++);
        col.save2File(aggrColConf, exec);
    }
    if (exec != null) {
        exec.setProgress(0.3, "Start saving bins...");
    }
    final ConfigWO binsConf = config.addConfig(CFG_BINS);
    binsConf.addInt(CFG_BIN_COUNTER, m_bins.size());
    idx = 0;
    for (final BinDataModel bin : m_bins) {
        final ConfigWO binConf = binsConf.addConfig(CFG_BIN + idx++);
        bin.save2File(binConf, exec);
    }
    final ConfigWO missingBin = binsConf.addConfig(CFG_MISSING_BIN);
    m_missingValueBin.save2File(missingBin, exec);
    if (m_invalidValueBin != null) {
        final ConfigWO invalidBin = binsConf.addConfig(CFG_INVALID_BIN);
        m_invalidValueBin.save2File(invalidBin, exec);
    }
    if (exec != null) {
        exec.setProgress(0.8, "Start saving element colors...");
    }
    final List<Color> rowColors = getRowColors();
    final ConfigWO colorColsConf = config.addConfig(CFG_COLOR_COLS);
    colorColsConf.addInt(CFG_ROW_COLOR_COUNTER, rowColors.size());
    idx = 0;
    for (final Color color : rowColors) {
        colorColsConf.addInt(CFG_ROW_COLOR + idx++, color.getRGB());
    }
    config.saveToXML(dataOS);
    dataOS.flush();
    dataOS.close();
    os.flush();
    os.close();
    if (exec != null) {
        exec.setProgress(1.0, "Histogram data model saved");
    }
}
Also used : NodeSettings(org.knime.core.node.NodeSettings) GZIPOutputStream(java.util.zip.GZIPOutputStream) Config(org.knime.core.node.config.Config) FileOutputStream(java.io.FileOutputStream) ColorColumn(org.knime.base.node.viz.histogram.util.ColorColumn) Color(java.awt.Color) ConfigWO(org.knime.core.node.config.ConfigWO) File(java.io.File)

Example 52 with NodeSettings

use of org.knime.core.node.NodeSettings in project knime-core by knime.

the class AbstractHistogramNodeModel method saveInternals.

/**
 * {@inheritDoc}
 */
@Override
protected void saveInternals(final File nodeInternDir, final ExecutionMonitor exec) {
    if (m_tableSpec == null) {
        return;
    }
    try {
        final File settingsFile = new File(nodeInternDir, CFG_TABLESPEC_FILE);
        final FileOutputStream settingsOS = new FileOutputStream(settingsFile);
        final NodeSettings settings = new NodeSettings(CFG_TABLESPEC_TAG);
        m_tableSpec.save(settings);
        settings.saveToXML(settingsOS);
        if (!new File(nodeInternDir, CFG_DATA_DIR_NAME).mkdir()) {
            throw new Exception("Unable to create internal data directory");
        }
        final File histoDataDir = new File(nodeInternDir, CFG_DATA_DIR_NAME);
        // save the data of the implementation
        saveHistogramInternals(histoDataDir, exec);
    } catch (final Exception e) {
        LOGGER.warn("Error while saving table specification: " + e.getMessage());
    }
}
Also used : NodeSettings(org.knime.core.node.NodeSettings) FileOutputStream(java.io.FileOutputStream) File(java.io.File) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) CanceledExecutionException(org.knime.core.node.CanceledExecutionException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException)

Example 53 with NodeSettings

use of org.knime.core.node.NodeSettings in project knime-core by knime.

the class EndcaseNodeModel method saveInternals.

/**
 * {@inheritDoc}
 */
@Override
protected void saveInternals(final File nodeInternDir, final ExecutionMonitor exec) throws IOException, CanceledExecutionException {
    if (m_enableHiliting) {
        final NodeSettings config = new NodeSettings("hilite_mapping");
        ((DefaultHiLiteMapper) m_hiliteTranslator.getMapper()).save(config);
        config.saveToXML(new GZIPOutputStream(new FileOutputStream(new File(nodeInternDir, "hilite_mapping.xml.gz"))));
    }
}
Also used : NodeSettings(org.knime.core.node.NodeSettings) GZIPOutputStream(java.util.zip.GZIPOutputStream) FileOutputStream(java.io.FileOutputStream) DefaultHiLiteMapper(org.knime.core.node.property.hilite.DefaultHiLiteMapper) File(java.io.File)

Example 54 with NodeSettings

use of org.knime.core.node.NodeSettings in project knime-core by knime.

the class CreateTempDirectoryNodeModel method saveInternals.

/**
 * {@inheritDoc}
 */
@Override
protected void saveInternals(final File nodeInternDir, final ExecutionMonitor exec) throws IOException, CanceledExecutionException {
    if (m_id != null) {
        // added in 3.1
        try (OutputStream w = new FileOutputStream(new File(nodeInternDir, INTERNAL_FILE_NAME))) {
            NodeSettings s = new NodeSettings("temp-dir-node");
            s.addString("temp-folder-id", m_id);
            s.saveToXML(w);
        }
    }
// else this was a workflow saved in 2.x and then loaded and saved/converted in 3.1
}
Also used : NodeSettings(org.knime.core.node.NodeSettings) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) File(java.io.File)

Example 55 with NodeSettings

use of org.knime.core.node.NodeSettings in project knime-core by knime.

the class InteractivePieDataModel method save2File.

/**
 * @param dataDir the data directory to write to
 * @param exec the {@link ExecutionMonitor}
 * @throws IOException if the output file could not be created
 * @throws CanceledExecutionException if the saving was canceled
 */
public void save2File(final File dataDir, final ExecutionMonitor exec) throws IOException, CanceledExecutionException {
    final File settingFile = new File(dataDir, CFG_SETTING_FILE);
    final FileOutputStream os = new FileOutputStream(settingFile);
    final GZIPOutputStream settingOS = new GZIPOutputStream(os);
    final Config config = new NodeSettings(CFG_SETTING);
    config.addBoolean(CFG_HILITING, supportsHiliting());
    config.addBoolean(CFG_DETAILS, detailsAvailable());
    config.saveToXML(settingOS);
    exec.checkCanceled();
    final File dataFile = new File(dataDir, CFG_DATA_FILE);
    DataContainer.writeToZip(m_data, dataFile, exec);
}
Also used : NodeSettings(org.knime.core.node.NodeSettings) GZIPOutputStream(java.util.zip.GZIPOutputStream) Config(org.knime.core.node.config.Config) FileOutputStream(java.io.FileOutputStream) File(java.io.File)

Aggregations

NodeSettings (org.knime.core.node.NodeSettings)156 File (java.io.File)58 FileOutputStream (java.io.FileOutputStream)57 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)37 GZIPOutputStream (java.util.zip.GZIPOutputStream)27 NodeSettingsRO (org.knime.core.node.NodeSettingsRO)17 Test (org.junit.Test)16 NodeSettingsWO (org.knime.core.node.NodeSettingsWO)16 DefaultHiLiteMapper (org.knime.core.node.property.hilite.DefaultHiLiteMapper)16 IOException (java.io.IOException)14 OutputStream (java.io.OutputStream)12 ExecutionMonitor (org.knime.core.node.ExecutionMonitor)11 BufferedOutputStream (java.io.BufferedOutputStream)9 Map (java.util.Map)8 RowKey (org.knime.core.data.RowKey)8 Config (org.knime.core.node.config.Config)8 LinkedHashMap (java.util.LinkedHashMap)7 DataTableSpec (org.knime.core.data.DataTableSpec)7 CanceledExecutionException (org.knime.core.node.CanceledExecutionException)6 ArrayList (java.util.ArrayList)5