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);
}
}
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('\"');
}
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;
}
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;
}
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;
}
Aggregations