Search in sources :

Example 6 with URIPortObjectSpec

use of org.knime.core.data.uri.URIPortObjectSpec in project GenericKnimeNodes by genericworkflownodes.

the class OutputFilesNodeModel method mimeTypeCompatible.

/**
 * Checks if incoming and outgoing mime types are compatible.
 *
 * @param inSpecs
 *            The incoming port spec.
 * @return True if the mime types are compatible, false otherwise.
 */
private boolean mimeTypeCompatible(PortObjectSpec[] inSpecs) {
    String selectedMimeType = MIMETypeHelper.getMIMEtype(m_filename.getStringValue());
    String incomingMimeType = MIMETypeHelper.getMIMEtypeByExtension(((URIPortObjectSpec) inSpecs[0]).getFileExtensions().get(0));
    return incomingMimeType.equals(selectedMimeType);
}
Also used : URIPortObjectSpec(org.knime.core.data.uri.URIPortObjectSpec) SettingsModelString(org.knime.core.node.defaultnodesettings.SettingsModelString)

Example 7 with URIPortObjectSpec

use of org.knime.core.data.uri.URIPortObjectSpec in project GenericKnimeNodes by genericworkflownodes.

the class OutputFileNodeModel method compareMIMETypes.

public boolean compareMIMETypes(PortObjectSpec[] inSpecs) {
    String selectedMimeType = MIMETypeHelper.getMIMEtype(m_filename.getStringValue());
    String incomingMimeType = MIMETypeHelper.getMIMEtypeByExtension(((URIPortObjectSpec) inSpecs[0]).getFileExtensions().get(0));
    return incomingMimeType.equals(selectedMimeType);
}
Also used : URIPortObjectSpec(org.knime.core.data.uri.URIPortObjectSpec) SettingsModelString(org.knime.core.node.defaultnodesettings.SettingsModelString)

Example 8 with URIPortObjectSpec

use of org.knime.core.data.uri.URIPortObjectSpec in project GenericKnimeNodes by genericworkflownodes.

the class DynamicGenericNodeModel method configure.

/**
 * {@inheritDoc}
 */
@Override
protected PortObjectSpec[] configure(PortObjectSpec[] inSpecs) throws InvalidSettingsException {
    // Test if the named tool exists in the tool-db, if not throws an
    // exception to tell the user that the executable is missing.
    checkIfToolExists();
    for (Parameter<?> param : m_nodeConfig.getParameters()) {
        if (!param.isOptional() && param.getValue() != null && "".equals(param.getStringRep()) && !(param instanceof IFileParameter)) {
            setWarningMessage("Some mandatory parameters might not be set.");
        }
    }
    int nIn = m_fileEndingsInPorts.length;
    for (int i = 0; i < nIn; i++) {
        // not connected input ports have nulls in inSpec
        if (inSpecs[i] == null) {
            // .. if port is optional everything is fine
            if (m_nodeConfig.getInputPorts().get(i).isOptional()) {
                continue;
            } else {
                throw new InvalidSettingsException("Non-optional input port is not connected.");
            }
        }
        URIPortObjectSpec spec = (URIPortObjectSpec) inSpecs[i];
        // get MIMEType from incoming port
        // TODO: we should check all file extensions, if its more than one (e.g. last node outputs mixed list of txt and jpg)
        String mt = MIMEMap.getMIMEType(spec.getFileExtensions().get(0));
        // check whether input MIMEType is in list of allowed MIMETypes
        boolean ok = false;
        if (m_fileEndingsInPorts[i].length > 0) {
            for (int j = 0; j < m_fileEndingsInPorts[i].length && !ok; j++) {
                if (mt.equals(MIMEMap.getMIMEType(m_fileEndingsInPorts[i][j]))) {
                    ok = true;
                }
            }
        } else {
            // we accept all incoming data if the node does not restrict the
            // file endings
            ok = true;
        }
        // we require consistent file endings for non prefix ports
        if (!ok && !m_nodeConfig.getInputPorts().get(i).isPrefix()) {
            String mismatch = String.format("has extension: [%s]; expected one of:[%s]", mt, Arrays.toString(m_fileEndingsInPorts[i]));
            throw new InvalidSettingsException("Invalid MIMEtype at port number " + i + " : " + mismatch);
        }
    }
    return createOutSpec();
}
Also used : IFileParameter(com.genericworkflownodes.knime.parameter.IFileParameter) URIPortObjectSpec(org.knime.core.data.uri.URIPortObjectSpec) InvalidSettingsException(org.knime.core.node.InvalidSettingsException)

Example 9 with URIPortObjectSpec

use of org.knime.core.data.uri.URIPortObjectSpec in project GenericKnimeNodes by genericworkflownodes.

the class DynamicGenericNodeModel method createOutSpec.

protected PortObjectSpec[] createOutSpec() {
    int nOut = m_fileEndingsOutPorts.length;
    PortObjectSpec[] out_spec = new PortObjectSpec[nOut];
    // set selected MIMEURIPortObjectSpecs at output ports
    for (int i = 0; i < nOut; i++) {
        // selected output MIMEType
        int selectedMIMETypeIndex = getOutputTypeIndex(i);
        // TODO: check
        String mt = m_fileEndingsOutPorts[i][selectedMIMETypeIndex];
        if (!mt.equals("Inactive")) {
            out_spec[i] = new URIPortObjectSpec(mt);
        } else {
            out_spec[i] = InactiveBranchPortObjectSpec.INSTANCE;
        }
    }
    return out_spec;
}
Also used : URIPortObjectSpec(org.knime.core.data.uri.URIPortObjectSpec) InactiveBranchPortObjectSpec(org.knime.core.node.port.inactive.InactiveBranchPortObjectSpec) URIPortObjectSpec(org.knime.core.data.uri.URIPortObjectSpec) PortObjectSpec(org.knime.core.node.port.PortObjectSpec)

Example 10 with URIPortObjectSpec

use of org.knime.core.data.uri.URIPortObjectSpec in project GenericKnimeNodes by genericworkflownodes.

the class FileSplitterNodeDialog method loadAdditionalSettingsFrom.

@Override
public void loadAdditionalSettingsFrom(NodeSettingsRO settings, PortObjectSpec[] specs) throws NotConfigurableException {
    String factoryId;
    SettingsModelString facId = FileSplitterNodeModel.createFactoryIDSettingsModel();
    try {
        facId.loadSettingsFrom(settings);
        factoryId = facId.getStringValue();
    } catch (InvalidSettingsException e) {
        factoryId = null;
    }
    URIPortObjectSpec spec = (URIPortObjectSpec) specs[0];
    String ext = spec.getFileExtensions().get(0);
    String mimetype = MIMETypeHelper.getMIMEtypeByExtension(ext);
    List<SplitterFactory> factories = SplitterFactoryManager.getInstance().getFactories(mimetype);
    List<String> facs = new ArrayList<String>();
    if (factories.size() == 0) {
        facs = Collections.singletonList(NO_FACTORY);
    }
    for (SplitterFactory f : factories) {
        facs.add(f.getID());
    }
    m_factories.replaceListItems(facs, factoryId != null ? factoryId : facs.get(0));
}
Also used : SplitterFactory(com.genericworkflownodes.knime.cluster.filesplitter.SplitterFactory) URIPortObjectSpec(org.knime.core.data.uri.URIPortObjectSpec) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) ArrayList(java.util.ArrayList) SettingsModelString(org.knime.core.node.defaultnodesettings.SettingsModelString) SettingsModelString(org.knime.core.node.defaultnodesettings.SettingsModelString)

Aggregations

URIPortObjectSpec (org.knime.core.data.uri.URIPortObjectSpec)13 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)6 PortObjectSpec (org.knime.core.node.port.PortObjectSpec)6 SettingsModelString (org.knime.core.node.defaultnodesettings.SettingsModelString)4 SplitterFactory (com.genericworkflownodes.knime.cluster.filesplitter.SplitterFactory)2 IFileParameter (com.genericworkflownodes.knime.parameter.IFileParameter)2 ArrayList (java.util.ArrayList)2 InactiveBranchPortObjectSpec (org.knime.core.node.port.inactive.InactiveBranchPortObjectSpec)2 IDemangler (com.genericworkflownodes.knime.mime.demangler.IDemangler)1 DataTableSpec (org.knime.core.data.DataTableSpec)1 SettingsModelOptionalString (org.knime.core.node.defaultnodesettings.SettingsModelOptionalString)1