Search in sources :

Example 41 with InvalidSettingsException

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

the class DurationPeriodToStringNodeModel method createColumnRearranger.

/**
 * {@inheritDoc}
 */
@Override
protected ColumnRearranger createColumnRearranger(final DataTableSpec spec) throws InvalidSettingsException {
    if (!m_hasValidatedConfiguration) {
        m_colSelect.loadDefaults(spec);
    }
    final ColumnRearranger rearranger = new ColumnRearranger(spec);
    final String[] includeList = m_colSelect.applyTo(spec).getIncludes();
    final int[] includeIndices = Arrays.stream(m_colSelect.applyTo(spec).getIncludes()).mapToInt(s -> spec.findColumnIndex(s)).toArray();
    int i = 0;
    for (String includedCol : includeList) {
        if (m_isReplaceOrAppend.getStringValue().equals(OPTION_REPLACE)) {
            DataColumnSpecCreator dataColumnSpecCreator = new DataColumnSpecCreator(includedCol, StringCell.TYPE);
            DurationPeriodToStringCellFactory cellFac = new DurationPeriodToStringCellFactory(dataColumnSpecCreator.createSpec(), includeIndices[i++]);
            rearranger.replace(cellFac, includedCol);
        } else {
            DataColumnSpec dataColSpec = new UniqueNameGenerator(spec).newColumn(includedCol + m_suffix.getStringValue(), StringCell.TYPE);
            DurationPeriodToStringCellFactory cellFac = new DurationPeriodToStringCellFactory(dataColSpec, includeIndices[i++]);
            rearranger.append(cellFac);
        }
    }
    return rearranger;
}
Also used : Period(java.time.Period) DurationPeriodFormatUtils(org.knime.time.util.DurationPeriodFormatUtils) Arrays(java.util.Arrays) NodeSettingsRO(org.knime.core.node.NodeSettingsRO) DataTableSpec(org.knime.core.data.DataTableSpec) PeriodValue(org.knime.core.data.time.period.PeriodValue) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) StringCellFactory(org.knime.core.data.def.StringCell.StringCellFactory) UniqueNameGenerator(org.knime.core.util.UniqueNameGenerator) DurationValue(org.knime.core.data.time.duration.DurationValue) SettingsModelColumnFilter2(org.knime.core.node.defaultnodesettings.SettingsModelColumnFilter2) DataRow(org.knime.core.data.DataRow) SettingsModelString(org.knime.core.node.defaultnodesettings.SettingsModelString) NodeSettingsWO(org.knime.core.node.NodeSettingsWO) SingleCellFactory(org.knime.core.data.container.SingleCellFactory) DataColumnSpec(org.knime.core.data.DataColumnSpec) SimpleStreamableFunctionNodeModel(org.knime.core.node.streamable.simple.SimpleStreamableFunctionNodeModel) DataColumnSpecCreator(org.knime.core.data.DataColumnSpecCreator) Duration(java.time.Duration) ColumnRearranger(org.knime.core.data.container.ColumnRearranger) StringCell(org.knime.core.data.def.StringCell) DataCell(org.knime.core.data.DataCell) ColumnRearranger(org.knime.core.data.container.ColumnRearranger) DataColumnSpecCreator(org.knime.core.data.DataColumnSpecCreator) DataColumnSpec(org.knime.core.data.DataColumnSpec) SettingsModelString(org.knime.core.node.defaultnodesettings.SettingsModelString) UniqueNameGenerator(org.knime.core.util.UniqueNameGenerator)

Example 42 with InvalidSettingsException

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

the class DurationToNumberNodeModel method createColumnRearranger.

/**
 * {@inheritDoc}
 */
@Override
protected ColumnRearranger createColumnRearranger(final DataTableSpec spec) throws InvalidSettingsException {
    final ColumnRearranger rearranger = new ColumnRearranger(spec);
    if (m_colSelectModel.getStringValue() == null) {
        throw new InvalidSettingsException("Node must be configured!");
    }
    if (spec.findColumnIndex(m_colSelectModel.getStringValue()) < 0) {
        throw new InvalidSettingsException("Column '" + m_colSelectModel.getStringValue() + "' not found in the input table.");
    }
    final boolean exact = m_typeSelectModel.getStringValue().equals(DataTypeMode.Exact.name());
    final DataColumnSpec colSpec = new UniqueNameGenerator(spec).newColumn((m_durationFieldSelectModel.getStringValue()), exact ? DoubleCell.TYPE : LongCell.TYPE);
    final CellFactory cellFac = new ExtractDurationSingleFieldCellFactory(spec.findColumnIndex(m_colSelectModel.getStringValue()), exact, colSpec);
    rearranger.append(cellFac);
    return rearranger;
}
Also used : ColumnRearranger(org.knime.core.data.container.ColumnRearranger) DataColumnSpec(org.knime.core.data.DataColumnSpec) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) UniqueNameGenerator(org.knime.core.util.UniqueNameGenerator) AbstractCellFactory(org.knime.core.data.container.AbstractCellFactory) DoubleCellFactory(org.knime.core.data.def.DoubleCell.DoubleCellFactory) SingleCellFactory(org.knime.core.data.container.SingleCellFactory) CellFactory(org.knime.core.data.container.CellFactory) LongCellFactory(org.knime.core.data.def.LongCell.LongCellFactory)

Example 43 with InvalidSettingsException

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

the class TimestampToDateTimeNodeModel method createColumnRearranger.

/**
 * @param inSpec table input spec
 * @return the CR describing the output
 */
@Override
protected ColumnRearranger createColumnRearranger(final DataTableSpec inSpec) throws InvalidSettingsException {
    CheckUtils.checkSetting(m_hasValidatedConfiguration, "Node must be configured!");
    final ColumnRearranger rearranger = new ColumnRearranger(inSpec);
    final String[] includeList = m_colSelect.applyTo(inSpec).getIncludes();
    final int[] includeIndeces = Arrays.stream(m_colSelect.applyTo(inSpec).getIncludes()).mapToInt(s -> inSpec.findColumnIndex(s)).toArray();
    int i = 0;
    final boolean isReplace = m_isReplaceOrAppend.getStringValue().equals(OPTION_REPLACE);
    UniqueNameGenerator uniqueNameGenerator = new UniqueNameGenerator(inSpec);
    for (String includedCol : includeList) {
        if (isReplace) {
            final DataColumnSpecCreator dataColumnSpecCreator = new DataColumnSpecCreator(includedCol, DateTimeType.valueOf(m_selectedType).getDataType());
            final TimestampToTimeCellFactory cellFac = new TimestampToTimeCellFactory(dataColumnSpecCreator.createSpec(), includeIndeces[i++]);
            rearranger.replace(cellFac, includedCol);
        } else {
            final DataColumnSpec dataColSpec = uniqueNameGenerator.newColumn(includedCol + m_suffix.getStringValue(), DateTimeType.valueOf(m_selectedType).getDataType());
            final TimestampToTimeCellFactory cellFac = new TimestampToTimeCellFactory(dataColSpec, includeIndeces[i++]);
            rearranger.append(cellFac);
        }
    }
    return rearranger;
}
Also used : LongValue(org.knime.core.data.LongValue) Arrays(java.util.Arrays) NodeSettingsRO(org.knime.core.node.NodeSettingsRO) DataTableSpec(org.knime.core.data.DataTableSpec) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) ZonedDateTime(java.time.ZonedDateTime) UniqueNameGenerator(org.knime.core.util.UniqueNameGenerator) LocalDateTime(java.time.LocalDateTime) LocalDateTimeCellFactory(org.knime.core.data.time.localdatetime.LocalDateTimeCellFactory) SingleCellFactory(org.knime.core.data.container.SingleCellFactory) DataColumnSpec(org.knime.core.data.DataColumnSpec) ZonedDateTimeCellFactory(org.knime.core.data.time.zoneddatetime.ZonedDateTimeCellFactory) SimpleStreamableFunctionNodeModel(org.knime.core.node.streamable.simple.SimpleStreamableFunctionNodeModel) DataColumnSpecCreator(org.knime.core.data.DataColumnSpecCreator) LocalTime(java.time.LocalTime) DateTimeType(org.knime.time.util.DateTimeType) DataCell(org.knime.core.data.DataCell) InputFilter(org.knime.core.node.util.filter.InputFilter) IntValue(org.knime.core.data.IntValue) LocalDateCellFactory(org.knime.core.data.time.localdate.LocalDateCellFactory) LocalTimeCellFactory(org.knime.core.data.time.localtime.LocalTimeCellFactory) SettingsModelColumnFilter2(org.knime.core.node.defaultnodesettings.SettingsModelColumnFilter2) Instant(java.time.Instant) ZoneId(java.time.ZoneId) DataRow(org.knime.core.data.DataRow) SettingsModelString(org.knime.core.node.defaultnodesettings.SettingsModelString) NodeSettingsWO(org.knime.core.node.NodeSettingsWO) TimeUnit(java.util.concurrent.TimeUnit) LocalDate(java.time.LocalDate) ColumnRearranger(org.knime.core.data.container.ColumnRearranger) CheckUtils(org.knime.core.node.util.CheckUtils) ColumnRearranger(org.knime.core.data.container.ColumnRearranger) DataColumnSpecCreator(org.knime.core.data.DataColumnSpecCreator) DataColumnSpec(org.knime.core.data.DataColumnSpec) SettingsModelString(org.knime.core.node.defaultnodesettings.SettingsModelString) UniqueNameGenerator(org.knime.core.util.UniqueNameGenerator)

Example 44 with InvalidSettingsException

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

the class FileSubNodeContainerPersistor method preLoadNodeContainer.

/**
 * {@inheritDoc}
 */
@Override
public void preLoadNodeContainer(final WorkflowPersistor parentPersistor, final NodeSettingsRO parentSettings, final LoadResult result) throws InvalidSettingsException, IOException {
    super.preLoadNodeContainer(parentPersistor, parentSettings, result);
    // assigned by super
    NodeSettingsRO nodeSettings = getNodeSettings();
    try {
        int i = nodeSettings.getInt("virtual-in-ID");
        CheckUtils.checkSetting(i >= 0, "Node ID < 0: %d", i);
        m_virtualInNodeIDSuffix = i;
    } catch (InvalidSettingsException e) {
        String error = "Can't load virtual input node ID: " + e.getMessage();
        result.addError(error);
        getLogger().error(error, e);
        setDirtyAfterLoad();
    }
    try {
        int i = nodeSettings.getInt("virtual-in-ID");
        CheckUtils.checkSetting(i >= 0, "Node ID < 0: %d", i);
        m_virtualInNodeIDSuffix = i;
    } catch (InvalidSettingsException e) {
        String error = "Can't load virtual input node ID: " + e.getMessage();
        result.addError(error);
        getLogger().error(error, e);
        setDirtyAfterLoad();
    }
    Set<String> inportSetKeys = Collections.emptySet();
    NodeSettingsRO inportsSettings = null;
    try {
        inportsSettings = nodeSettings.getNodeSettings("inports");
        // input of subnode is represented by output of virtual in node.
        inportSetKeys = inportsSettings.keySet();
        // an extra for hidden flow var port
        m_inPortTemplates = new WorkflowPortTemplate[inportSetKeys.size() + 1];
        m_inPortTemplates[0] = new WorkflowPortTemplate(0, FlowVariablePortObject.TYPE_OPTIONAL);
        for (int i = 1; i < m_inPortTemplates.length; i++) {
            // fallback values, correctly set below
            m_inPortTemplates[i] = new WorkflowPortTemplate(i, BufferedDataTable.TYPE);
        }
    } catch (InvalidSettingsException e) {
        String error = "Can't load virtual input port information: " + e.getMessage();
        result.addError(error);
        getLogger().error(error, e);
        setDirtyAfterLoad();
        m_inPortTemplates = new WorkflowPortTemplate[0];
    }
    for (String key : inportSetKeys) {
        try {
            @SuppressWarnings("null") NodeSettingsRO inportSetting = inportsSettings.getNodeSettings(key);
            WorkflowPortTemplate portTemplate = loadPort(inportSetting, inportSetKeys.size());
            m_inPortTemplates[portTemplate.getPortIndex()] = portTemplate;
        } catch (InvalidSettingsException e) {
            String error = "Could not load input port information: " + e.getMessage();
            result.addError(error);
            getLogger().error(error, e);
            setDirtyAfterLoad();
            continue;
        }
    }
    try {
        if (m_templateInformation != null) {
            // template information was set after construction (this node is a link created from a template)
            assert m_templateInformation.getRole() == Role.Link;
        } else {
            m_templateInformation = MetaNodeTemplateInformation.load(nodeSettings, getLoadVersion());
            CheckUtils.checkSettingNotNull(m_templateInformation, "No template information");
        }
    } catch (InvalidSettingsException e) {
        String error = "Unable to load workflow template information: " + e.getMessage();
        getLogger().debug(error, e);
        setDirtyAfterLoad();
        result.addError(error);
        m_templateInformation = MetaNodeTemplateInformation.NONE;
    }
    try {
        int i = nodeSettings.getInt("virtual-out-ID");
        CheckUtils.checkSetting(i >= 0, "Node ID < 0: %d", i);
        m_virtualOutNodeIDSuffix = i;
    } catch (InvalidSettingsException e) {
        String error = "Can't load virtual output node ID: " + e.getMessage();
        result.addError(error);
        getLogger().error(error, e);
        setDirtyAfterLoad();
    }
    Set<String> outportSetKeys = Collections.emptySet();
    NodeSettingsRO outportsSettings = null;
    try {
        outportsSettings = nodeSettings.getNodeSettings("outports");
        // output of subnode is represented by input of virtual out node.
        outportSetKeys = outportsSettings.keySet();
        m_outPortTemplates = new WorkflowPortTemplate[outportSetKeys.size() + 1];
        m_outPortTemplates[0] = new WorkflowPortTemplate(0, FlowVariablePortObject.TYPE_OPTIONAL);
        for (int i = 1; i < m_outPortTemplates.length; i++) {
            // fallback values, correctly set below
            m_outPortTemplates[i] = new WorkflowPortTemplate(i, BufferedDataTable.TYPE);
        }
    } catch (InvalidSettingsException e) {
        String error = "Can't load virtual output port information: " + e.getMessage();
        result.addError(error);
        getLogger().error(error, e);
        setDirtyAfterLoad();
        m_outPortTemplates = new WorkflowPortTemplate[0];
    }
    for (String key : outportSetKeys) {
        try {
            @SuppressWarnings("null") NodeSettingsRO outportSetting = outportsSettings.getNodeSettings(key);
            WorkflowPortTemplate portTemplate = loadPort(outportSetting, outportSetKeys.size());
            m_outPortTemplates[portTemplate.getPortIndex()] = portTemplate;
        } catch (InvalidSettingsException e) {
            String error = "Could not load output port information: " + e.getMessage();
            result.addError(error);
            getLogger().error(error, e);
            setDirtyAfterLoad();
            continue;
        }
    }
    Set<String> layoutSetKeys = Collections.emptySet();
    m_layoutInfo = new HashMap<Integer, WizardNodeLayoutInfo>();
    NodeSettingsRO layoutSettings = null;
    try {
        layoutSettings = nodeSettings.getNodeSettings("layoutInfos");
        layoutSetKeys = layoutSettings.keySet();
        for (String key : layoutSetKeys) {
            NodeSettingsRO singleLayoutSetting = layoutSettings.getNodeSettings(key);
            int nodeID = singleLayoutSetting.getInt("nodeID");
            WizardNodeLayoutInfo layoutInfo = WizardNodeLayoutInfo.loadFromNodeSettings(singleLayoutSetting);
            m_layoutInfo.put(nodeID, layoutInfo);
        }
    } catch (InvalidSettingsException e) {
        String error = "Could not load Wrapped Metanode layout information: " + e.getMessage();
        result.addError(error);
        getLogger().error(error, e);
        setDirtyAfterLoad();
    }
    // added in 3.1, load with default value
    m_layoutJSONString = nodeSettings.getString("layoutJSON", "");
    m_workflowPersistor.preLoadNodeContainer(parentPersistor, parentSettings, result);
}
Also used : InvalidSettingsException(org.knime.core.node.InvalidSettingsException) NodeSettingsRO(org.knime.core.node.NodeSettingsRO) WorkflowPortTemplate(org.knime.core.node.workflow.WorkflowPersistor.WorkflowPortTemplate) WizardNodeLayoutInfo(org.knime.core.node.wizard.WizardNodeLayoutInfo)

Example 45 with InvalidSettingsException

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

the class AnnotationData method load.

/**
 * loads new values.
 * @param config To load from
 * @param loadVersion Version to load
 * @throws InvalidSettingsException If fails
 */
public void load(final NodeSettingsRO config, final FileWorkflowPersistor.LoadVersion loadVersion) throws InvalidSettingsException {
    setText(config.getString("text"));
    setBgColor(config.getInt("bgcolor"));
    int x = config.getInt("x-coordinate");
    int y = config.getInt("y-coordinate");
    int width = config.getInt("width");
    int height = config.getInt("height");
    // default to 0 for backward compatibility
    int borderSize = config.getInt("borderSize", 0);
    // default for backward compatibility
    int borderColor = config.getInt("borderColor", 0);
    // default for backward compatibility
    int defFontSize = config.getInt("defFontSize", -1);
    // added in 3.0
    m_version = config.getInt("annotation-version", VERSION_OLD);
    TextAlignment alignment = TextAlignment.LEFT;
    if (loadVersion.ordinal() >= FileWorkflowPersistor.LoadVersion.V250.ordinal()) {
        String alignmentS = config.getString("alignment");
        try {
            alignment = TextAlignment.valueOf(alignmentS);
        } catch (Exception e) {
            throw new InvalidSettingsException("Invalid alignment: " + alignmentS, e);
        }
    }
    setDimension(x, y, width, height);
    setAlignment(alignment);
    setBorderSize(borderSize);
    setBorderColor(borderColor);
    setDefaultFontSize(defFontSize);
    NodeSettingsRO styleConfigs = config.getNodeSettings("styles");
    StyleRange[] styles = new StyleRange[styleConfigs.getChildCount()];
    int i = 0;
    for (String key : styleConfigs.keySet()) {
        NodeSettingsRO cur = styleConfigs.getNodeSettings(key);
        styles[i++] = StyleRange.load(cur);
    }
    setStyleRanges(styles);
}
Also used : InvalidSettingsException(org.knime.core.node.InvalidSettingsException) NodeSettingsRO(org.knime.core.node.NodeSettingsRO) InvalidSettingsException(org.knime.core.node.InvalidSettingsException)

Aggregations

InvalidSettingsException (org.knime.core.node.InvalidSettingsException)818 DataTableSpec (org.knime.core.data.DataTableSpec)278 DataColumnSpec (org.knime.core.data.DataColumnSpec)211 SettingsModelString (org.knime.core.node.defaultnodesettings.SettingsModelString)153 NodeSettingsRO (org.knime.core.node.NodeSettingsRO)121 ColumnRearranger (org.knime.core.data.container.ColumnRearranger)113 IOException (java.io.IOException)109 DataCell (org.knime.core.data.DataCell)99 ArrayList (java.util.ArrayList)96 DataType (org.knime.core.data.DataType)89 PortObjectSpec (org.knime.core.node.port.PortObjectSpec)82 File (java.io.File)72 DataColumnSpecCreator (org.knime.core.data.DataColumnSpecCreator)69 DataRow (org.knime.core.data.DataRow)66 DoubleValue (org.knime.core.data.DoubleValue)58 CanceledExecutionException (org.knime.core.node.CanceledExecutionException)48 SettingsModelFilterString (org.knime.core.node.defaultnodesettings.SettingsModelFilterString)47 FileInputStream (java.io.FileInputStream)43 LinkedHashMap (java.util.LinkedHashMap)42 NotConfigurableException (org.knime.core.node.NotConfigurableException)41