use of org.knime.core.node.NodeSettingsRO in project knime-core by knime.
the class ObsoleteMetaNodeFileWorkflowPersistor method preLoadNodeContainer.
/**
* {@inheritDoc}
*/
@Override
public void preLoadNodeContainer(final WorkflowPersistor parentPersistor, final NodeSettingsRO parentSettings, final LoadResult result) throws IOException, InvalidSettingsException {
ReferencedFile workflowKNIMEFile = super.getWorkflowKNIMEFile();
File setFile = workflowKNIMEFile.getFile();
if (!setFile.getName().equals("settings.xml")) {
String warn = "Settings file of obsolete metanode is not " + "named settings.xml: " + setFile.getName();
getLogger().warn(warn);
result.addError(warn);
}
ReferencedFile parent = workflowKNIMEFile.getParent();
if (parent == null) {
throw new IOException("Parent directory not represented by class " + ReferencedFile.class);
}
ReferencedFile workflowKnimeRef = new ReferencedFile(parent, "workflow.knime");
File workflowKnime = workflowKnimeRef.getFile();
if (!workflowKnime.isFile()) {
throw new IOException("Can't find file " + workflowKnime.getAbsolutePath());
}
String factory = parentSettings.getString("factory");
if ("org.knime.base.node.meta.xvalidation.XValidateNodeFactory".equals(factory)) {
m_metaNodeType = MetaNodeType.CROSSVALIDATION;
} else if ("org.knime.base.node.meta.looper.LooperFactory".equals(factory)) {
m_metaNodeType = MetaNodeType.LOOPER;
} else {
m_metaNodeType = MetaNodeType.ORDINARY;
}
NodeSettingsRO settings = NodeSettings.loadFromXML(new BufferedInputStream(new FileInputStream(setFile)));
NodeSettingsRO modelSet = settings.getNodeSettings("model");
m_dataInNodeIDs = modelSet.getIntArray("dataInContainerIDs");
m_dataOutNodeIDs = modelSet.getIntArray("dataOutContainerIDs");
super.preLoadNodeContainer(parentPersistor, parentSettings, result);
String name = "Looper";
switch(m_metaNodeType) {
case CROSSVALIDATION:
name = "Cross Validation";
case LOOPER:
result.addError("Workflow contains obsolete \"" + name + "\" metanode implementation, not all settings could " + "be restored, please re-configure and execute again.");
setNeedsResetAfterLoad();
default:
}
}
use of org.knime.core.node.NodeSettingsRO in project knime-core by knime.
the class NodeViewManagerTest method testLoadViewSettingsOnViewCreation.
/**
* Makes sure that view settings are loaded from the node into the node view when created for the first time.
*
* @throws InvalidSettingsException
*/
@Test
public void testLoadViewSettingsOnViewCreation() throws InvalidSettingsException {
var page = Page.builder(() -> "test page content", "index.html").build();
AtomicReference<NodeSettingsRO> loadedNodeSettings = new AtomicReference<>();
NativeNodeContainer nc = createNodeWithNodeView(m_wfm, m -> new // NOSONAR
NodeView() {
@Override
public Optional<InitialDataService> createInitialDataService() {
return Optional.empty();
}
@Override
public Optional<DataService> createDataService() {
return Optional.empty();
}
@Override
public Optional<ApplyDataService> createApplyDataService() {
return Optional.empty();
}
@Override
public Page getPage() {
return page;
}
@Override
public void validateSettings(final NodeSettingsRO settings) throws InvalidSettingsException {
//
}
@Override
public void loadValidatedSettingsFrom(final NodeSettingsRO settings) {
loadedNodeSettings.set(settings);
}
});
// prepare view settings
var settings = new NodeSettings("node_settings");
m_wfm.saveNodeSettings(nc.getID(), settings);
var viewSettings = new NodeSettings("view");
viewSettings.addString("view setting key", "view setting value");
settings.addNodeSettings(viewSettings);
settings.addNodeSettings(new NodeSettings("model"));
m_wfm.loadNodeSettings(nc.getID(), settings);
// test
NodeViewManager.getInstance().getNodeView(nc);
assertTrue(loadedNodeSettings.get().containsKey("view setting key"));
}
use of org.knime.core.node.NodeSettingsRO in project knime-core by knime.
the class FileSingleNodeContainerPersistor method preLoadNodeContainer.
/**
* {@inheritDoc}
*/
@Override
public void preLoadNodeContainer(final WorkflowPersistor parentPersistor, final NodeSettingsRO parentSettings, final LoadResult result) throws InvalidSettingsException, IOException {
FileNodeContainerMetaPersistor meta = getMetaPersistor();
final ReferencedFile settingsFileRef = meta.getNodeSettingsFile();
File settingsFile = settingsFileRef.getFile();
if (!settingsFile.isFile()) {
setDirtyAfterLoad();
throw new IOException("Can't read node file \"" + settingsFile.getAbsolutePath() + "\"");
}
NodeSettingsRO settings;
try {
InputStream in = new FileInputStream(settingsFile);
// parentPersitor is null for loaded subnode templates
in = parentPersistor == null ? in : parentPersistor.decipherInput(in);
settings = NodeSettings.loadFromXML(new BufferedInputStream(in));
} catch (IOException ioe) {
setDirtyAfterLoad();
throw ioe;
}
boolean resetRequired = meta.load(settings, parentSettings, result);
m_nodeSettings = settings;
if (resetRequired) {
setNeedsResetAfterLoad();
setDirtyAfterLoad();
}
if (meta.isDirtyAfterLoad()) {
setDirtyAfterLoad();
}
}
use of org.knime.core.node.NodeSettingsRO in project knime-core by knime.
the class FileSingleNodeContainerPersistor method loadNodeContainer.
/**
* {@inheritDoc}
*/
@Override
public void loadNodeContainer(final Map<Integer, BufferedDataTable> tblRep, final ExecutionMonitor exec, final LoadResult result) throws InvalidSettingsException, CanceledExecutionException, IOException {
final NodeSettingsRO settingsForNode = loadSettingsForNode(result);
m_sncSettings = new SingleNodeContainerSettings();
exec.checkCanceled();
try {
m_sncSettings.setMemoryPolicy(loadMemoryPolicySettings(m_nodeSettings));
} catch (InvalidSettingsException e) {
String error = "Unable to load SNC settings: " + e.getMessage();
result.addError(error);
getLogger().debug(error, e);
setDirtyAfterLoad();
return;
}
NodeSettingsRO modelSettings = null;
try {
modelSettings = loadModelSettings(settingsForNode);
} catch (InvalidSettingsException ise) {
String error = "Unable to load model settings: " + ise.getMessage();
result.addError(error);
getLogger().debug(error, ise);
setDirtyAfterLoad();
}
if (Node.DISALLOW_WEAK_PASSWORDS_IN_NODE_CONFIGURATION && modelSettings != null && ConfigPasswordEntry.containsPassword((NodeSettings) modelSettings, false)) {
result.addWarning(String.format("Node stores passwords in its configuration. These will be lost when saving " + "the workflow in this installation (as per \"%s\" system property)", KNIMEConstants.PROPERTY_WEAK_PASSWORDS_IN_SETTINGS_FORBIDDEN));
}
try {
modelSettings = loadNCAndWashModelSettings(settingsForNode, modelSettings, tblRep, exec, result);
} catch (InvalidSettingsException ise) {
String error = "Unable to load node container and wash settings: " + ise.getMessage();
result.addError(error);
getLogger().debug(error, ise);
setDirtyAfterLoad();
}
m_sncSettings.setModelSettings(modelSettings);
try {
m_sncSettings.setViewSettings(loadViewSettings(settingsForNode));
} catch (InvalidSettingsException e) {
String msg = "Unable load view settings: " + e.getMessage();
result.addError(msg);
getLogger().debug(msg, e);
setDirtyAfterLoad();
}
try {
m_sncSettings.setVariablesSettings(loadVariableSettings(settingsForNode));
} catch (InvalidSettingsException e) {
String msg = "Could not load variable settings: " + e.getMessage();
result.addError(msg);
setDirtyAfterLoad();
setNeedsResetAfterLoad();
}
try {
m_flowObjects = loadFlowObjects(m_nodeSettings);
} catch (Exception e) {
m_flowObjects = Collections.emptyList();
String error = "Error loading flow variables: " + e.getMessage();
getLogger().warn(error, e);
result.addError(error);
setDirtyAfterLoad();
setNeedsResetAfterLoad();
}
exec.setProgress(1.0);
}
use of org.knime.core.node.NodeSettingsRO in project knime-core by knime.
the class FileSingleNodeContainerPersistor method loadMemoryPolicySettings.
/**
* Load configuration of node.
*
* @param nodeSettings to load from (used in sub-classes)
* @return node config
* @throws InvalidSettingsException if that fails for any reason.
*/
MemoryPolicy loadMemoryPolicySettings(final NodeSettingsRO nodeSettings) throws InvalidSettingsException {
if (getLoadVersion().isOlderThan(LoadVersion.V210_Pre)) {
// we use the default, i.e. small data are kept in memory
if (nodeSettings.containsKey(Node.CFG_MISC_SETTINGS) && nodeSettings.getNodeSettings(Node.CFG_MISC_SETTINGS).containsKey(SingleNodeContainer.CFG_MEMORY_POLICY)) {
NodeSettingsRO sub = nodeSettings.getNodeSettings(Node.CFG_MISC_SETTINGS);
String memoryPolicy = sub.getString(SingleNodeContainer.CFG_MEMORY_POLICY, MemoryPolicy.CacheSmallInMemory.toString());
if (memoryPolicy == null) {
throw new InvalidSettingsException("Can't use null memory policy.");
}
try {
return MemoryPolicy.valueOf(memoryPolicy);
} catch (IllegalArgumentException iae) {
throw new InvalidSettingsException("Invalid memory policy: " + memoryPolicy);
}
} else {
return MemoryPolicy.CacheSmallInMemory;
}
} else {
// any version after 2.0 saves the snc settings in the settings.xml
// (previously these settings were saves as part of the node.xml)
NodeSettingsRO sub = nodeSettings.getNodeSettings(Node.CFG_MISC_SETTINGS);
String memoryPolicy = sub.getString(SingleNodeContainer.CFG_MEMORY_POLICY, MemoryPolicy.CacheSmallInMemory.toString());
if (memoryPolicy == null) {
throw new InvalidSettingsException("Can't use null memory policy.");
}
try {
return MemoryPolicy.valueOf(memoryPolicy);
} catch (IllegalArgumentException iae) {
throw new InvalidSettingsException("Invalid memory policy: " + memoryPolicy);
}
}
}
Aggregations