Search in sources :

Example 1 with SettingsModelOptionalString

use of org.knime.core.node.defaultnodesettings.SettingsModelOptionalString in project GenericKnimeNodes by genericworkflownodes.

the class MimeFileImporterNodeModel method validateSettings.

/**
 * {@inheritDoc}
 */
@Override
protected void validateSettings(final NodeSettingsRO settings) throws InvalidSettingsException {
    SettingsModelString tmp_filename = m_filename.createCloneWithValidatedValue(settings);
    if (tmp_filename.getStringValue().isEmpty()) {
        throw new InvalidSettingsException("No File selected.");
    }
    convertToURL(tmp_filename);
    SettingsModelOptionalString tmp_file_extension = m_file_extension.createCloneWithValidatedValue(settings);
    if (tmp_file_extension.isActive()) {
        if (tmp_file_extension.getStringValue().equals("")) {
            throw new InvalidSettingsException("No File extension (override) provided.");
        } else if (MIMETypeHelper.getMIMEtypeByExtension(tmp_file_extension.getStringValue()) == null) {
            throw new InvalidSettingsException("No MIME type registered for file extension: " + tmp_file_extension.getStringValue());
        }
    } else if (MIMETypeHelper.getMIMEtype(tmp_filename.getStringValue()) == null) {
        throw new InvalidSettingsException("File of unknown MIME type selected: " + tmp_filename.getStringValue());
    }
}
Also used : InvalidSettingsException(org.knime.core.node.InvalidSettingsException) SettingsModelOptionalString(org.knime.core.node.defaultnodesettings.SettingsModelOptionalString) SettingsModelString(org.knime.core.node.defaultnodesettings.SettingsModelString)

Example 2 with SettingsModelOptionalString

use of org.knime.core.node.defaultnodesettings.SettingsModelOptionalString in project GenericKnimeNodes by genericworkflownodes.

the class ListMimeFileImporterNodeModel method validateSettings.

/**
 * {@inheritDoc}
 */
@Override
protected void validateSettings(final NodeSettingsRO settings) throws InvalidSettingsException {
    SettingsModelStringArray tmp_filenames = m_filenames.createCloneWithValidatedValue(settings);
    if (tmp_filenames == null || tmp_filenames.getStringArrayValue().length == 0) {
        throw new InvalidSettingsException("No Files selected.");
    }
    SettingsModelOptionalString tmp_file_extension = m_file_extension.createCloneWithValidatedValue(settings);
    if (tmp_file_extension.isActive()) {
        if (tmp_file_extension.getStringValue().equals("")) {
            throw new InvalidSettingsException("No File extension (override) provided.");
        } else if (MIMETypeHelper.getMIMEtypeByExtension(tmp_file_extension.getStringValue()) == null) {
            throw new InvalidSettingsException("No MIMEtype registered for file extension: " + tmp_file_extension.getStringValue());
        }
    } else {
        List<String> mts = new ArrayList<String>();
        String mt = null;
        for (String filename : tmp_filenames.getStringArrayValue()) {
            mt = MIMETypeHelper.getMIMEtype(filename);
            if (mt == null) {
                throw new InvalidSettingsException("Files of unknown MIMEtype selected: " + filename);
            }
            mts.add(mt);
        }
        for (String mimeType : mts) {
            if (!mimeType.equals(mt)) {
                throw new InvalidSettingsException("Files with mixed MIMEType loaded");
            }
        }
    }
}
Also used : SettingsModelStringArray(org.knime.core.node.defaultnodesettings.SettingsModelStringArray) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) SettingsModelOptionalString(org.knime.core.node.defaultnodesettings.SettingsModelOptionalString) ArrayList(java.util.ArrayList) SettingsModelOptionalString(org.knime.core.node.defaultnodesettings.SettingsModelOptionalString)

Aggregations

InvalidSettingsException (org.knime.core.node.InvalidSettingsException)2 SettingsModelOptionalString (org.knime.core.node.defaultnodesettings.SettingsModelOptionalString)2 ArrayList (java.util.ArrayList)1 SettingsModelString (org.knime.core.node.defaultnodesettings.SettingsModelString)1 SettingsModelStringArray (org.knime.core.node.defaultnodesettings.SettingsModelStringArray)1