Search in sources :

Example 1 with URIPortObjectSpec

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

the class GenericKnimeNodeModel 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.toLowerCase().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 2 with URIPortObjectSpec

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

the class GenericKnimeNodeModel 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 then 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 3 with URIPortObjectSpec

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

the class ListZipLoopStartNodeModel method configure.

@Override
protected PortObjectSpec[] configure(PortObjectSpec[] inSpecs) throws InvalidSettingsException {
    assert m_iteration == 0;
    pushFlowVariableInt("currentIteration", m_iteration);
    pushFlowVariableInt("maxIterations", 0);
    List<URIPortObjectSpec> specs = new ArrayList<URIPortObjectSpec>();
    for (int i = 0; i < PORT_COUNT; i++) {
        if (inSpecs[i] == null) {
            break;
        }
        URIPortObjectSpec spec = (URIPortObjectSpec) inSpecs[i];
        specs.add(spec);
    }
    return getOutputSpec(specs);
}
Also used : URIPortObjectSpec(org.knime.core.data.uri.URIPortObjectSpec) ArrayList(java.util.ArrayList)

Example 4 with URIPortObjectSpec

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

the class FileMergerNodeModel method configure.

/**
 * {@inheritDoc}
 */
@Override
protected PortObjectSpec[] configure(final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
    // check not null
    checkNotNullSpecs(inSpecs);
    // check equal MIMEType
    checkEqualMIMETypes(inSpecs);
    // create output spec
    URIPortObjectSpec outSpec = new URIPortObjectSpec(((URIPortObjectSpec) inSpecs[0]).getFileExtensions());
    return new PortObjectSpec[] { outSpec };
}
Also used : URIPortObjectSpec(org.knime.core.data.uri.URIPortObjectSpec) PortObjectSpec(org.knime.core.node.port.PortObjectSpec) URIPortObjectSpec(org.knime.core.data.uri.URIPortObjectSpec)

Example 5 with URIPortObjectSpec

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

the class DemanglerNodeModel method configure.

@Override
protected PortObjectSpec[] configure(final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
    if (!(inSpecs[0] instanceof URIPortObjectSpec)) {
        throw new InvalidSettingsException("No URIPortObjectSpec compatible port object at port 0");
    }
    URIPortObjectSpec spec = (URIPortObjectSpec) inSpecs[0];
    fileExtension = spec.getFileExtensions().get(0);
    String mimeType = MIMETypeHelper.getMIMEtypeByExtension(fileExtension);
    // try to find a demangler for the data type ...
    List<IDemangler> availableDemanglers = DemanglerRegistry.getDemanglerRegistry().getDemangler(mimeType);
    if (availableDemanglers == null || availableDemanglers.size() == 0) {
        throw new InvalidSettingsException("No IDemangler found for " + fileExtension + ". Please register before transforming the a file with this MIMEType to a KNIME table.");
    }
    if (demangler == null) {
        demangler = availableDemanglers.get(0);
    }
    return new DataTableSpec[] { getDataTableSpec() };
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) URIPortObjectSpec(org.knime.core.data.uri.URIPortObjectSpec) IDemangler(com.genericworkflownodes.knime.mime.demangler.IDemangler) InvalidSettingsException(org.knime.core.node.InvalidSettingsException)

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