Search in sources :

Example 1 with IFileParameter

use of com.genericworkflownodes.knime.parameter.IFileParameter in project GenericKnimeNodes by genericworkflownodes.

the class CTDConfigurationWriter method addMimeTypeRestrictions.

private void addMimeTypeRestrictions(StringBuffer item, Parameter<?> p) {
    Port associatedPort = ((IFileParameter) p).getPort();
    item.append(" supported_formats=\"");
    String sep = "";
    for (String mt : associatedPort.getMimeTypes()) {
        item.append(sep);
        sep = ",";
        item.append(String.format("*.%s", mt));
    }
    item.append('\"');
}
Also used : IFileParameter(com.genericworkflownodes.knime.parameter.IFileParameter) Port(com.genericworkflownodes.knime.port.Port)

Example 2 with IFileParameter

use of com.genericworkflownodes.knime.parameter.IFileParameter in project GenericKnimeNodes by genericworkflownodes.

the class GenericKnimeNodeDialog method loadSettingsFrom.

@Override
protected void loadSettingsFrom(NodeSettingsRO settings, PortObjectSpec[] specs) throws NotConfigurableException {
    String errorsFound = "";
    for (String key : config.getParameterKeys()) {
        Parameter<?> param = config.getParameter(key);
        // skip file parameters
        if (param instanceof IFileParameter) {
            continue;
        }
        String value = null;
        try {
            value = settings.getString(key);
            param.fillFromString(value);
        } catch (InvalidSettingsException e) {
            errorsFound += "- Entry for " + key + " not found in settings.xml.\n";
        } catch (InvalidParameterValueException e) {
            errorsFound += "- Entry for " + key + " in settings.xml has a value that does not match it restrictions.\n";
        // Do not hard fail. Users should be able to edit the value in the dialog.
        /*throw new NotConfigurableException(e.getMessage(), e);*/
        }
    }
    if (!errorsFound.isEmpty()) {
        LOGGER.error("Errors found loading Settings from disk. Maybe you are loading a node created with another version." + "\nUsing default values as defined in the Tool description." + "\nWe recommend to check the parameters highlighted in red carefully before clicking OK: \n" + errorsFound);
    }
    int nP = config.getNumberOfOutputPorts();
    int[] selectedPorts = new int[nP];
    for (int i = 0; i < nP; i++) {
        try {
            int idx = settings.getInt(GenericKnimeNodeModel.GENERIC_KNIME_NODES_OUTTYPE_PREFIX + i);
            selectedPorts[i] = idx;
        } catch (InvalidSettingsException e) {
            throw new NotConfigurableException(e.getMessage(), e);
        }
    }
    mtc.setSelectedTypes(selectedPorts);
}
Also used : IFileParameter(com.genericworkflownodes.knime.parameter.IFileParameter) NotConfigurableException(org.knime.core.node.NotConfigurableException) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) InvalidParameterValueException(com.genericworkflownodes.knime.parameter.InvalidParameterValueException)

Example 3 with IFileParameter

use of com.genericworkflownodes.knime.parameter.IFileParameter 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 4 with IFileParameter

use of com.genericworkflownodes.knime.parameter.IFileParameter 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 5 with IFileParameter

use of com.genericworkflownodes.knime.parameter.IFileParameter in project GenericKnimeNodes by genericworkflownodes.

the class DynamicGenericNodeModel method transferIncomingPorts2Config.

/**
 * Transfers the incoming ports into the config, that it can be written out
 * into a config file or can be transferred to the command line.
 *
 * @param inData
 *            The incoming port objects.
 * @throws Exception
 */
private void transferIncomingPorts2Config(PortObject[] inData) throws Exception {
    // Transfer settings from the input ports into the configuration object
    for (int i = 0; i < inData.length; i++) {
        // find the internal port for this PortObject
        Port port = m_nodeConfig.getInputPorts().get(i);
        IURIPortObject po = (IURIPortObject) inData[i];
        String name = port.getName();
        // find the associated parameter in the configuration
        Parameter<?> p = m_nodeConfig.getParameter(name);
        boolean isMultiFile = port.isMultiFile();
        boolean isPrefix = port.isPrefix();
        // skip optional and unconnected inport ports
        if (inData[i] == null) {
            ((FileParameter) p).setValue(null);
            continue;
        }
        // connected: check contents
        List<URIContent> uris = po.getURIContents();
        // check validity of subtypes with actual inputs
        if (uris.size() > 1 && (!isMultiFile && !isPrefix)) {
            throw new Exception("IURIPortObject with multiple URIs supplied at single URI port #" + i);
        }
        // port
        if (!(p instanceof IFileParameter)) {
            throw new Exception("Invalid reference from port to non-file parameter. URI port #" + i);
        }
        if (isPrefix) {
            // we pass only the prefix to the tool
            IPrefixURIPortObject puri = (IPrefixURIPortObject) inData[i];
            ((FileParameter) p).setValue(puri.getPrefix());
        } else if (isMultiFile) {
            // we need to collect all filenames and then set them as a batch
            // in the config
            List<String> filenames = new ArrayList<String>();
            for (URIContent uric : uris) {
                URI uri = uric.getURI();
                filenames.add(new File(uri).getAbsolutePath());
            }
            ((FileListParameter) p).setValue(filenames);
        } else {
            // just one filename
            URI uri = uris.get(0).getURI();
            String filename = new File(uri).getAbsolutePath();
            ((FileParameter) p).setValue(filename);
        }
    }
}
Also used : IPrefixURIPortObject(com.genericworkflownodes.knime.base.data.port.IPrefixURIPortObject) Port(com.genericworkflownodes.knime.port.Port) URI(java.net.URI) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) InvalidParameterValueException(com.genericworkflownodes.knime.parameter.InvalidParameterValueException) ExecutionFailedException(com.genericworkflownodes.knime.generic_node.ExecutionFailedException) UnknownToolExecutorException(com.genericworkflownodes.knime.execution.UnknownToolExecutorException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) NoBinaryAvailableException(com.genericworkflownodes.knime.custom.config.NoBinaryAvailableException) UnknownCommandGeneratorException(com.genericworkflownodes.knime.execution.UnknownCommandGeneratorException) IFileParameter(com.genericworkflownodes.knime.parameter.IFileParameter) IURIPortObject(org.knime.core.data.uri.IURIPortObject) ArrayList(java.util.ArrayList) List(java.util.List) FileParameter(com.genericworkflownodes.knime.parameter.FileParameter) IFileParameter(com.genericworkflownodes.knime.parameter.IFileParameter) File(java.io.File) URIContent(org.knime.core.data.uri.URIContent)

Aggregations

IFileParameter (com.genericworkflownodes.knime.parameter.IFileParameter)7 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)5 FileParameter (com.genericworkflownodes.knime.parameter.FileParameter)3 InvalidParameterValueException (com.genericworkflownodes.knime.parameter.InvalidParameterValueException)3 Port (com.genericworkflownodes.knime.port.Port)3 IPrefixURIPortObject (com.genericworkflownodes.knime.base.data.port.IPrefixURIPortObject)2 NoBinaryAvailableException (com.genericworkflownodes.knime.custom.config.NoBinaryAvailableException)2 UnknownCommandGeneratorException (com.genericworkflownodes.knime.execution.UnknownCommandGeneratorException)2 UnknownToolExecutorException (com.genericworkflownodes.knime.execution.UnknownToolExecutorException)2 File (java.io.File)2 IOException (java.io.IOException)2 URI (java.net.URI)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 ExecutionException (java.util.concurrent.ExecutionException)2 IURIPortObject (org.knime.core.data.uri.IURIPortObject)2 URIContent (org.knime.core.data.uri.URIContent)2 URIPortObjectSpec (org.knime.core.data.uri.URIPortObjectSpec)2 CommandLineElement (com.genericworkflownodes.knime.commandline.CommandLineElement)1 CommandLineFile (com.genericworkflownodes.knime.commandline.impl.CommandLineFile)1