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