use of org.knime.core.data.uri.URIPortObjectSpec in project GenericKnimeNodes by genericworkflownodes.
the class OutputFilesNodeModel method mimeTypeCompatible.
/**
* Checks if incoming and outgoing mime types are compatible.
*
* @param inSpecs
* The incoming port spec.
* @return True if the mime types are compatible, false otherwise.
*/
private boolean mimeTypeCompatible(PortObjectSpec[] inSpecs) {
String selectedMimeType = MIMETypeHelper.getMIMEtype(m_filename.getStringValue());
String incomingMimeType = MIMETypeHelper.getMIMEtypeByExtension(((URIPortObjectSpec) inSpecs[0]).getFileExtensions().get(0));
return incomingMimeType.equals(selectedMimeType);
}
use of org.knime.core.data.uri.URIPortObjectSpec in project GenericKnimeNodes by genericworkflownodes.
the class OutputFileNodeModel method compareMIMETypes.
public boolean compareMIMETypes(PortObjectSpec[] inSpecs) {
String selectedMimeType = MIMETypeHelper.getMIMEtype(m_filename.getStringValue());
String incomingMimeType = MIMETypeHelper.getMIMEtypeByExtension(((URIPortObjectSpec) inSpecs[0]).getFileExtensions().get(0));
return incomingMimeType.equals(selectedMimeType);
}
use of org.knime.core.data.uri.URIPortObjectSpec 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();
}
use of org.knime.core.data.uri.URIPortObjectSpec in project GenericKnimeNodes by genericworkflownodes.
the class DynamicGenericNodeModel 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.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 FileSplitterNodeDialog method loadAdditionalSettingsFrom.
@Override
public void loadAdditionalSettingsFrom(NodeSettingsRO settings, PortObjectSpec[] specs) throws NotConfigurableException {
String factoryId;
SettingsModelString facId = FileSplitterNodeModel.createFactoryIDSettingsModel();
try {
facId.loadSettingsFrom(settings);
factoryId = facId.getStringValue();
} catch (InvalidSettingsException e) {
factoryId = null;
}
URIPortObjectSpec spec = (URIPortObjectSpec) specs[0];
String ext = spec.getFileExtensions().get(0);
String mimetype = MIMETypeHelper.getMIMEtypeByExtension(ext);
List<SplitterFactory> factories = SplitterFactoryManager.getInstance().getFactories(mimetype);
List<String> facs = new ArrayList<String>();
if (factories.size() == 0) {
facs = Collections.singletonList(NO_FACTORY);
}
for (SplitterFactory f : factories) {
facs.add(f.getID());
}
m_factories.replaceListItems(facs, factoryId != null ? factoryId : facs.get(0));
}
Aggregations