Search in sources :

Example 6 with Port

use of com.genericworkflownodes.knime.port.Port in project GenericKnimeNodes by genericworkflownodes.

the class ParamHandler method createPort.

/**
 * Convert the current element into a Port and the respective
 * IFileParameter.
 *
 * @param paramName
 *            The name of the Parameter.
 * @param attributes
 *            Attributes of the Parameter.
 */
private void createPort(String paramName, Attributes attributes, boolean isList) {
    // check if we want to create this port
    if (BLACKLIST.contains(paramName)) {
        LOG.setLevel(Level.ALL);
        LOG.info("Ignoring port: " + paramName);
        return;
    }
    Port p = new Port();
    p.setName(m_currentPath + paramName);
    p.setMultiFile(isList);
    p.setOptional(isOptional(attributes));
    p.setActive(true);
    List<String> mimetypes = extractMIMETypes(attributes);
    for (String mt : mimetypes) {
        p.addMimeType(mt);
    }
    String attr_type = attributes.getValue(ATTR_TYPE);
    boolean isInputPort = TYPE_INPUT_FILE.equals(attr_type) || getTags(attributes).contains(INPUTFILE_TAG) || TYPE_INPUT_PREFIX.equals(attr_type);
    // to save/load settings.
    if (p.isOptional() && !isInputPort) {
        p.addMimeType("Inactive");
    }
    String description = attributes.getValue(ATTR_DESCRIPTION);
    p.setDescription(description);
    m_currentParameter = null;
    // create port parameter
    if (isList) {
        m_currentParameter = new FileListParameter(paramName, new ArrayList<String>());
        ((FileListParameter) m_currentParameter).setPort(p);
        ((FileListParameter) m_currentParameter).setDescription(p.getDescription());
        ((FileListParameter) m_currentParameter).setIsOptional(p.isOptional());
    // Values will be filled at the end of the ITEMLIST tag.
    } else {
        m_currentParameter = new FileParameter(paramName, "");
        ((FileParameter) m_currentParameter).setPort(p);
        ((FileParameter) m_currentParameter).setDescription(p.getDescription());
        ((FileParameter) m_currentParameter).setIsOptional(p.isOptional());
        // Fills parameter with default value
        ((FileParameter) m_currentParameter).setValue(attributes.getValue(ATTR_VALUE));
    }
    p.setIsPrefix(TYPE_OUTPUT_PREFIX.equals(attr_type) || TYPE_INPUT_PREFIX.equals(attr_type));
    if (isInputPort) {
        m_inputPorts.add(p);
    } else {
        m_outputPorts.add(p);
    }
}
Also used : FileListParameter(com.genericworkflownodes.knime.parameter.FileListParameter) Port(com.genericworkflownodes.knime.port.Port) ArrayList(java.util.ArrayList) FileParameter(com.genericworkflownodes.knime.parameter.FileParameter)

Example 7 with Port

use of com.genericworkflownodes.knime.port.Port 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 8 with Port

use of com.genericworkflownodes.knime.port.Port in project GenericKnimeNodes by genericworkflownodes.

the class GenericKnimeNodeModel method getOutputBaseNames.

/**
 * Tries to guess the optimal output file names given all the input edges.
 * The file names will be extracted from the configuration, hence the file
 * names need to be transferred into config prior to using this method. See
 * {@link GenericKnimeNodeModel#transferIncomingPorts2Config(PortObject[])}.
 *
 * @return A list of base names for the output files.
 * @throws Exception
 */
private List<String> getOutputBaseNames() throws Exception {
    // 1. we select always the list with the highest number of files.
    // 2. we prefer lists over files (independent of the number of
    // elements).
    // 3. we prefer files over prefixes since we assume that prefixes are
    // often indices or reference data
    // 4. ignore optional parameters
    List<String> basenames = new ArrayList<String>();
    // find the port
    int naming_port = 0;
    int max_size = -1;
    boolean seen_prefix = false;
    boolean isFileParameter = false;
    for (int i = 0; i < m_nodeConfig.getInputPorts().size(); ++i) {
        Port port = m_nodeConfig.getInputPorts().get(i);
        String name = port.getName();
        Parameter<?> p = m_nodeConfig.getParameter(name);
        // we don't assume that optional ports are naming relevant
        if (p.isOptional()) {
            continue;
        }
        if (p instanceof FileListParameter) {
            FileListParameter flp = (FileListParameter) p;
            if (max_size == -1 || (isFileParameter && (max_size <= flp.getValue().size()))) {
                max_size = flp.getValue().size();
                naming_port = i;
            } else if (flp.getValue().size() != max_size) {
                throw new Exception("The number of output files cannot be determined since multiple input file lists with disagreeing numbers exist.");
            }
        } else if (max_size == -1 || seen_prefix) {
            // is a regular incoming port but we have no better option
            max_size = 1;
            naming_port = i;
            // indicating that we have (for now) selected a file parameter
            // which will be overruled by any FileListParameter
            isFileParameter = true;
            seen_prefix = port.isPrefix();
        }
    }
    if (m_nodeConfig.getInputPorts().size() > 0) {
        // generate the filenames if there are input ports
        // without ports, the names are set in transferOutgoingPorts2Config
        Port port = m_nodeConfig.getInputPorts().get(naming_port);
        String name = port.getName();
        Parameter<?> p = m_nodeConfig.getParameter(name);
        if (p instanceof FileListParameter) {
            // we have multiple base names
            FileListParameter flp = (FileListParameter) p;
            for (String fName : flp.getValue()) {
                basenames.add(FilenameUtils.getBaseName(fName));
            }
        } else {
            // we only have a single basename
            // FilenameUtils.getBaseName()
            basenames.add(FilenameUtils.getBaseName(((FileParameter) p).getValue()));
        }
    }
    return basenames;
}
Also used : FileListParameter(com.genericworkflownodes.knime.parameter.FileListParameter) Port(com.genericworkflownodes.knime.port.Port) ArrayList(java.util.ArrayList) FileParameter(com.genericworkflownodes.knime.parameter.FileParameter) IFileParameter(com.genericworkflownodes.knime.parameter.IFileParameter) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) InvalidParameterValueException(com.genericworkflownodes.knime.parameter.InvalidParameterValueException) 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)

Example 9 with Port

use of com.genericworkflownodes.knime.port.Port in project GenericKnimeNodes by genericworkflownodes.

the class DynamicGenericNodeFactory method createNodeDescription.

@Override
protected NodeDescription createNodeDescription() {
    try {
        INodeConfiguration cfg = getNodeConfiguration();
        KnimeNodeDocument doc = org.knime.node.v28.KnimeNodeDocument.Factory.newInstance();
        Document domDoc = (Document) doc.getDomNode();
        // Node
        KnimeNode node = doc.addNewKnimeNode();
        node.setDeprecated(m_deprecated);
        node.setName(cfg.getName());
        node.setIcon(getIconPath());
        node.setType(KnimeNode.Type.MANIPULATOR);
        node.setShortDescription(cfg.getDescription());
        FullDescription fullDescr = node.addNewFullDescription();
        // Intro
        Intro intro = fullDescr.addNewIntro();
        intro.addNewP().getDomNode().appendChild(domDoc.createTextNode(cfg.getManual()));
        // Options
        for (Parameter<?> p : cfg.getParameters()) {
            Option option = fullDescr.addNewOption();
            option.setName(p.getKey());
            option.getDomNode().appendChild(domDoc.createTextNode(p.getDescription()));
        }
        // Ports
        Ports ports = node.addNewPorts();
        int index = 0;
        for (Port p : cfg.getInputPorts()) {
            InPort ip = ports.addNewInPort();
            ip.setIndex(new BigInteger(Integer.toString(index++)));
            String mimetypes = mimetypes2String(p.getMimeTypes());
            ip.setName(p.getName() + mimetypes);
            ip.getDomNode().appendChild(domDoc.createTextNode(p.getDescription() + mimetypes));
        }
        index = 0;
        for (Port p : cfg.getOutputPorts()) {
            OutPort op = ports.addNewOutPort();
            op.setIndex(new BigInteger(Integer.toString(index++)));
            String mimetypes = mimetypes2String(p.getMimeTypes());
            op.setName(p.getName() + mimetypes);
            op.getDomNode().appendChild(domDoc.createTextNode(p.getDescription() + mimetypes));
        }
        return new NodeDescription28Proxy(doc);
    } catch (Exception e) {
        logger.error("Dynamic node description instantiation failed", e);
    }
    return null;
}
Also used : InPort(org.knime.node.v28.InPortDocument.InPort) InPort(org.knime.node.v28.InPortDocument.InPort) Port(com.genericworkflownodes.knime.port.Port) OutPort(org.knime.node.v28.OutPortDocument.OutPort) INodeConfiguration(com.genericworkflownodes.knime.config.INodeConfiguration) Ports(org.knime.node.v28.PortsDocument.Ports) Document(org.w3c.dom.Document) KnimeNodeDocument(org.knime.node.v28.KnimeNodeDocument) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) InvalidCTDFileException(com.genericworkflownodes.knime.config.reader.InvalidCTDFileException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) KnimeNode(org.knime.node.v28.KnimeNodeDocument.KnimeNode) Intro(org.knime.node.v28.IntroDocument.Intro) OutPort(org.knime.node.v28.OutPortDocument.OutPort) BigInteger(java.math.BigInteger) KnimeNodeDocument(org.knime.node.v28.KnimeNodeDocument) Option(org.knime.node.v28.OptionDocument.Option) NodeDescription28Proxy(org.knime.core.node.NodeDescription28Proxy) FullDescription(org.knime.node.v28.FullDescriptionDocument.FullDescription)

Example 10 with Port

use of com.genericworkflownodes.knime.port.Port in project GenericKnimeNodes by genericworkflownodes.

the class NodeFactoryXMLTemplate method getOutPorts.

/**
 * Returns the xml representation of the output ports.
 *
 * @param nodeConfiguration
 *            The {@link INodeConfiguration} containing the port
 *            information.
 * @return A {@link String} representing the output port part of the xml
 *         config file.
 * @throws Exception
 */
private static String getOutPorts(final INodeConfiguration nodeConfiguration) throws IOException {
    String op = "\t\t<outPort index=\"__IDX__\" name=\"__PORTNAME__ [__MIMETYPE__]\">__PORTDESCR__ [__MIMETYPE__]</outPort>";
    String outPorts = "";
    int idx = 0;
    for (Port port : nodeConfiguration.getOutputPorts()) {
        Parameter<?> parameter = nodeConfiguration.getParameter(port.getName());
        String opp = op;
        opp = op.replace("__PORTNAME__", parameter.getKey());
        opp = opp.replace("__PORTDESCR__", StringEscapeUtils.escapeHtml(port.getDescription()));
        opp = opp.replace("__IDX__", String.format("%d", idx++));
        opp = opp.replace("__MIMETYPE__", join(port.getMimeTypes(), ","));
        outPorts += opp + "\n";
    }
    return outPorts;
}
Also used : Port(com.genericworkflownodes.knime.port.Port)

Aggregations

Port (com.genericworkflownodes.knime.port.Port)19 IOException (java.io.IOException)8 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)8 FileParameter (com.genericworkflownodes.knime.parameter.FileParameter)7 IFileParameter (com.genericworkflownodes.knime.parameter.IFileParameter)7 ArrayList (java.util.ArrayList)7 NoBinaryAvailableException (com.genericworkflownodes.knime.custom.config.NoBinaryAvailableException)6 UnknownCommandGeneratorException (com.genericworkflownodes.knime.execution.UnknownCommandGeneratorException)6 UnknownToolExecutorException (com.genericworkflownodes.knime.execution.UnknownToolExecutorException)6 InvalidParameterValueException (com.genericworkflownodes.knime.parameter.InvalidParameterValueException)6 ExecutionException (java.util.concurrent.ExecutionException)6 FileListParameter (com.genericworkflownodes.knime.parameter.FileListParameter)5 IPrefixURIPortObject (com.genericworkflownodes.knime.base.data.port.IPrefixURIPortObject)4 File (java.io.File)4 IURIPortObject (org.knime.core.data.uri.IURIPortObject)4 ExecutionFailedException (com.genericworkflownodes.knime.generic_node.ExecutionFailedException)3 FileStorePrefixURIPortObject (com.genericworkflownodes.knime.base.data.port.FileStorePrefixURIPortObject)2 FileStoreURIPortObject (com.genericworkflownodes.knime.base.data.port.FileStoreURIPortObject)2 INodeConfiguration (com.genericworkflownodes.knime.config.INodeConfiguration)2 InvalidCTDFileException (com.genericworkflownodes.knime.config.reader.InvalidCTDFileException)2