Search in sources :

Example 91 with WorkflowManager

use of org.knime.core.node.workflow.WorkflowManager 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();
    }
}
Also used : NodeContext(org.knime.core.node.workflow.NodeContext) WorkflowManager(org.knime.core.node.workflow.WorkflowManager) WorkflowContext(org.knime.core.node.workflow.WorkflowContext) File(java.io.File)

Example 92 with WorkflowManager

use of org.knime.core.node.workflow.WorkflowManager in project knime-core by knime.

the class ContextProperties method extractContextProperty.

/**
 * Extracts the value of a context property.
 *
 * @param property the name of the context property.
 * @return the non-{@code null}, but possibly empty, value of the context property.
 * @throws IllegalArgumentException of {@code property} is not the name of a context property.
 */
public static String extractContextProperty(final String property) {
    final WorkflowManager manager = NodeContext.getContext().getWorkflowManager();
    if (CONTEXT_PROPERTY_WORKFLOW_NAME.equals(property)) {
        return manager.getName();
    }
    if (CONTEXT_PROPERTY_JOB_ID.equals(property)) {
        final WorkflowContext context = manager.getContext();
        return context == null ? null : context.getJobId().map(UUID::toString).orElse(null);
    }
    if (CONTEXT_PROPERTY_WORKFLOW_PATH.equals(property)) {
        final WorkflowContext context = manager.getContext();
        if (context.getRelativeRemotePath().isPresent()) {
            return context.getRelativeRemotePath().get();
        }
        final File wfLocation = context.getOriginalLocation() == null ? context.getCurrentLocation() : context.getOriginalLocation();
        final File mpLocation = context.getMountpointRoot();
        if (mpLocation == null || wfLocation == null) {
            return "";
        }
        final String wfPath = wfLocation.getAbsolutePath();
        final String mpPath = mpLocation.getAbsolutePath();
        assert wfPath.startsWith(mpPath);
        final String resultPath = wfPath.substring(mpPath.length());
        return resultPath.replace("\\", "/");
    }
    if (CONTEXT_PROPERTY_WORKFLOW_ABSOLUTE_PATH.equals(property)) {
        final WorkflowContext context = manager.getContext();
        final File wfLocation = context.getCurrentLocation();
        if (wfLocation == null) {
            return "";
        }
        return wfLocation.getAbsolutePath().replace("\\", "/");
    }
    if (CONTEXT_PROPERTY_SERVER_USER.equals(property)) {
        return manager.getContext().getUserid();
    }
    if (CONTEXT_PROPERTY_TEMP_LOCATION.equals(property)) {
        return manager.getContext().getTempLocation().getAbsolutePath();
    }
    final AuthorInformation authInfo = manager.getAuthorInformation();
    if (authInfo != null) {
        final String author = Optional.ofNullable(authInfo.getAuthor()).orElse("");
        final String dateCreated = Optional.ofNullable(authInfo.getAuthoredDate()).map(Object::toString).orElse("");
        if (CONTEXT_PROPERTY_AUTHOR.equals(property)) {
            return author;
        }
        if (CONTEXT_PROPERTY_EDITOR.equals(property)) {
            /**
             * If there is no known last editor (e.g., since the workflow has just been created), the original
             * author is returned as last editor.
             */
            return authInfo.getLastEditor().orElse(author);
        }
        if (CONTEXT_PROPERTY_CREATION_DATE.equals(property)) {
            return dateCreated;
        }
        if (CONTEXT_PROPERTY_LAST_MODIFIED.equals(property)) {
            /**
             * If there is no known last edit date (e.g., since the workflow has just been created), the created
             * date is returned as last edit date.
             */
            return authInfo.getLastEditDate().map(Object::toString).orElse(dateCreated);
        }
    } else if (CONTEXT_PROPERTY_AUTHOR.equals(property) || CONTEXT_PROPERTY_EDITOR.equals(property) || CONTEXT_PROPERTY_CREATION_DATE.equals(property) || CONTEXT_PROPERTY_LAST_MODIFIED.equals(property)) {
        return "";
    }
    throw new IllegalArgumentException("Not a context property : \"" + property + '"');
}
Also used : WorkflowManager(org.knime.core.node.workflow.WorkflowManager) WorkflowContext(org.knime.core.node.workflow.WorkflowContext) UUID(java.util.UUID) AuthorInformation(org.knime.core.util.workflowalizer.AuthorInformation) File(java.io.File)

Example 93 with WorkflowManager

use of org.knime.core.node.workflow.WorkflowManager in project knime-core by knime.

the class ExpandSubnodeResult method undo.

public void undo() {
    WorkflowManager hostWFM = m_hostWFM;
    for (NodeID id : m_expandedCopyContent.getNodeIDs()) {
        hostWFM.removeNode(id);
    }
    for (WorkflowAnnotation anno : hostWFM.getWorkflowAnnotations(m_expandedCopyContent.getAnnotationIDs())) {
        hostWFM.removeAnnotation(anno);
    }
    hostWFM.paste(m_undoCopyPersistor);
}
Also used : WorkflowManager(org.knime.core.node.workflow.WorkflowManager) NodeID(org.knime.core.node.workflow.NodeID) WorkflowAnnotation(org.knime.core.node.workflow.WorkflowAnnotation)

Example 94 with WorkflowManager

use of org.knime.core.node.workflow.WorkflowManager 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 && !LOG_JOB_ID) {
        return message;
    }
    final NodeContext context = NodeContext.getContext();
    NodeID nodeID = null;
    String nodeName = null;
    File workflowDir = null;
    UUID jobID = 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 || LOG_JOB_ID) {
            final WorkflowManager workflowManager = context.getWorkflowManager();
            if (workflowManager != null) {
                final WorkflowContext workflowContext = workflowManager.getContext();
                if (workflowContext != null) {
                    workflowDir = workflowContext.getCurrentLocation();
                    jobID = workflowContext.getJobId().orElse(null);
                }
            }
        }
    }
    return new KNIMELogMessage(nodeID, nodeName, workflowDir, jobID, message);
}
Also used : NodeContext(org.knime.core.node.workflow.NodeContext) WorkflowManager(org.knime.core.node.workflow.WorkflowManager) WorkflowContext(org.knime.core.node.workflow.WorkflowContext) NodeID(org.knime.core.node.workflow.NodeID) NodeContainer(org.knime.core.node.workflow.NodeContainer) UUID(java.util.UUID) ReferencedFile(org.knime.core.internal.ReferencedFile) File(java.io.File)

Example 95 with WorkflowManager

use of org.knime.core.node.workflow.WorkflowManager in project knime-core by knime.

the class WizardPageUtil method findNestedViewNodes.

/**
 * Collects different kind of infos for the 'wizard' nodes contained in a page (i.e. component). Nodes in nested
 * pages are recursively collected, too.
 *
 * @param subNC the page to collect the info for
 * @param infoMap the container for the collected {@link WizardPageNodeInfo}s, or <code>null</code> if it shouldn't
 *            be collected
 * @param sncMap the map of nested pages, or <code>null</code> if shouldn't be collected
 * @param initialHiliteHandlerSet collected hilite handlers or <code>null</code> if it shouldn't be collected
 */
private static void findNestedViewNodes(final SubNodeContainer subNC, final Map<NodeIDSuffix, NativeNodeContainer> resultMap, final Map<NodeIDSuffix, SubNodeContainer> sncMap, final Set<HiLiteHandler> initialHiliteHandlerSet) {
    var subWFM = subNC.getWorkflowManager();
    List<NativeNodeContainer> wizardNodes = getWizardPageNodes(subWFM);
    WorkflowManager projectWFM = subNC.getProjectWFM();
    for (NativeNodeContainer nc : wizardNodes) {
        if (nc.isInactive()) {
            // skip nodes in inactive branches
            continue;
        }
        NodeID.NodeIDSuffix idSuffix = NodeID.NodeIDSuffix.create(projectWFM.getID(), nc.getID());
        if (resultMap != null) {
            resultMap.put(idSuffix, nc);
        }
        if (initialHiliteHandlerSet != null) {
            for (var i = 0; i < nc.getNrInPorts() - 1; i++) {
                var hiLiteHandler = nc.getNodeModel().getInHiLiteHandler(i);
                if (hiLiteHandler != null) {
                    initialHiliteHandlerSet.add(hiLiteHandler);
                }
            }
        }
    }
    Map<NodeID, SubNodeContainer> subnodeContainers = getSubPageNodes(subNC.getWorkflowManager());
    for (Entry<NodeID, SubNodeContainer> entry : subnodeContainers.entrySet()) {
        SubNodeContainer snc = entry.getValue();
        NodeID.NodeIDSuffix idSuffix = NodeID.NodeIDSuffix.create(projectWFM.getID(), snc.getID());
        if (sncMap != null) {
            sncMap.put(idSuffix, snc);
        }
        findNestedViewNodes(snc, resultMap, sncMap, initialHiliteHandlerSet);
    }
}
Also used : SubNodeContainer(org.knime.core.node.workflow.SubNodeContainer) WorkflowManager(org.knime.core.node.workflow.WorkflowManager) NodeID(org.knime.core.node.workflow.NodeID) NodeIDSuffix(org.knime.core.node.workflow.NodeID.NodeIDSuffix) NativeNodeContainer(org.knime.core.node.workflow.NativeNodeContainer)

Aggregations

WorkflowManager (org.knime.core.node.workflow.WorkflowManager)99 NodeID (org.knime.core.node.workflow.NodeID)38 NodeContainer (org.knime.core.node.workflow.NodeContainer)22 SubNodeContainer (org.knime.core.node.workflow.SubNodeContainer)19 NativeNodeContainer (org.knime.core.node.workflow.NativeNodeContainer)15 NodeContainerEditPart (org.knime.workbench.editor2.editparts.NodeContainerEditPart)15 File (java.io.File)14 ConnectionContainer (org.knime.core.node.workflow.ConnectionContainer)14 IOException (java.io.IOException)11 ArrayList (java.util.ArrayList)10 Map (java.util.Map)10 SingleNodeContainer (org.knime.core.node.workflow.SingleNodeContainer)10 WorkflowAnnotation (org.knime.core.node.workflow.WorkflowAnnotation)10 MessageBox (org.eclipse.swt.widgets.MessageBox)9 NodeContainerUI (org.knime.core.ui.node.workflow.NodeContainerUI)9 List (java.util.List)8 ExecutionMonitor (org.knime.core.node.ExecutionMonitor)8 NodeUIInformation (org.knime.core.node.workflow.NodeUIInformation)8 WorkflowContext (org.knime.core.node.workflow.WorkflowContext)8 WorkflowCopyContent (org.knime.core.node.workflow.WorkflowCopyContent)8