use of org.knime.core.node.workflow.WorkflowContext in project knime-core by knime.
the class ReadContextPropertyConfiguration method extractContextProperty.
private static String extractContextProperty(final String property) {
WorkflowManager manager = NodeContext.getContext().getWorkflowManager();
if (CONTEXT_WORKFLOW_NAME.equals(property)) {
return manager.getName();
}
if (CONTEXT_WORKFLOW_PATH.equals(property)) {
WorkflowContext context = manager.getContext();
File wfLocation = context.getOriginalLocation() == null ? context.getCurrentLocation() : context.getOriginalLocation();
File mpLocation = context.getMountpointRoot();
if (mpLocation == null || wfLocation == null) {
return "";
}
String wfPath = wfLocation.getAbsolutePath();
String mpPath = mpLocation.getAbsolutePath();
assert wfPath.startsWith(mpPath);
String resultPath = wfPath.substring(mpPath.length());
return resultPath.replace("\\", "/");
}
if (CONTEXT_WORKFLOW_ABSOLUTE_PATH.equals(property)) {
WorkflowContext context = manager.getContext();
File wfLocation = context.getCurrentLocation();
if (wfLocation == null) {
return "";
}
return wfLocation.getAbsolutePath().replace("\\", "/");
}
if (CONTEXT_SERVER_USER.equals(property)) {
return manager.getContext().getUserid();
}
if (CONTEXT_TEMP_LOCATION.equals(property)) {
return manager.getContext().getTempLocation().getAbsolutePath();
}
AuthorInformation author = manager.getAuthorInformation();
if (author != null) {
if (CONTEXT_AUTHOR.equals(property)) {
return author.getAuthor();
}
if (CONTEXT_EDITOR.equals(property)) {
return author.getLastEditor();
}
if (CONTEXT_CREATION_DATE.equals(property)) {
Date creationDate = author.getAuthoredDate();
if (creationDate != null) {
return creationDate.toString();
}
}
if (CONTEXT_LAST_MODIFIED.equals(property)) {
Date modDate = author.getLastEditDate();
if (modDate != null) {
return modDate.toString();
}
}
}
return null;
}
use of org.knime.core.node.workflow.WorkflowContext in project knime-core by knime.
the class NodeLogger method getLogObject.
/**
* @param message the logging message
* @return a KNIMELogMessage that not only contains the log message but also the information about the workflow
* and node that belong to the log message if applicable
*/
private Object getLogObject(final Object message) {
if (!LOG_NODE_ID && !LOG_IN_WF_DIR && !LOG_WF_DIR) {
return message;
}
final NodeContext context = NodeContext.getContext();
NodeID nodeID = null;
String nodeName = null;
File workflowDir = null;
if (context != null) {
if (LOG_NODE_ID) {
// retrieve and store the node id only if the user has requested to log it
final NodeContainer nodeContainer = context.getNodeContainer();
if (nodeContainer != null) {
nodeID = nodeContainer.getID();
nodeName = nodeContainer.getName();
}
}
if (LOG_IN_WF_DIR || LOG_WF_DIR) {
final WorkflowManager workflowManager = context.getWorkflowManager();
if (workflowManager != null) {
final WorkflowContext workflowContext = workflowManager.getContext();
if (workflowContext != null) {
workflowDir = workflowContext.getCurrentLocation();
}
}
}
}
return new KNIMELogMessage(nodeID, nodeName, workflowDir, message);
}
use of org.knime.core.node.workflow.WorkflowContext in project knime-core by knime.
the class FileUtil method getWorkflowTempDir.
/**
* Reads the temporary directory associated with the current workflow (set in the {@link WorkflowContext}), or - if
* that is <code>null</code> - the global temp dir (see {@link KNIMEConstants#getKNIMETempPath()}).
*
* @return the temp dir of the current {@link WorkflowContext} or the standard temp dir, if no context is set.
* @since 3.5
*/
public static File getWorkflowTempDir() {
final File fallbackDir = KNIMEConstants.getKNIMETempPath().toFile();
NodeContext nodeContext = NodeContext.getContext();
if (nodeContext == null) {
return fallbackDir;
}
WorkflowManager wfm = nodeContext.getWorkflowManager();
if (wfm == null) {
return fallbackDir;
}
WorkflowContext workflowContext = wfm.getContext();
if (workflowContext == null) {
return fallbackDir;
}
if (!workflowContext.getTempLocation().isDirectory()) {
LOGGER.error("Temp folder \"" + workflowContext.getTempLocation().getAbsolutePath() + "\" does not exist (associated with node context \"" + nodeContext + "\") - using fallback temp folder (\"" + fallbackDir.getAbsolutePath() + "\"");
return fallbackDir;
} else {
return workflowContext.getTempLocation();
}
}
Aggregations