Search in sources :

Example 1 with JSONWebNodePage

use of org.knime.js.core.JSONWebNodePage in project knime-core by knime.

the class TestSubnodeView method testSubnodeViewableModel.

/**
 * Creates and tests the {@link SubnodeViewableModel}
 * @throws Exception
 */
@Test
public void testSubnodeViewableModel() throws Exception {
    initialExecute();
    SubNodeContainer snc = getManager().getNodeContainer(m_subnodeID, SubNodeContainer.class, true);
    SubnodeViewableModel svm = new SubnodeViewableModel(snc, "testView");
    JSONWebNodePage page = svm.getViewRepresentation();
    validateJSONPage(page);
    SubnodeViewValue viewValue = svm.getViewValue();
    assertNotNull("Combined view value should exist", viewValue);
    assertNotNull("Combined view value map should exist", viewValue.getViewValues());
    assertEquals("Combined view value should contain three entries", 3, viewValue.getViewValues().size());
    Map<String, String> changedValueMap = new HashMap<String, String>(3);
    changedValueMap.putAll(viewValue.getViewValues());
    changedValueMap = changeStringInputTo("foo", changedValueMap);
    SubnodeViewValue newViewValue = new SubnodeViewValue();
    newViewValue.setViewValues(changedValueMap);
    ValidationError validationError = svm.validateViewValue(newViewValue);
    assertTrue("Validation error should be instance of CollectionValidationError", validationError instanceof CollectionValidationError);
    Map<String, String> errorMap = ((CollectionValidationError) validationError).getErrorMap();
    assertNotNull("Error map should exist", errorMap);
    changedValueMap.putAll(viewValue.getViewValues());
    changeStringInputTo(CHANGED_URL, changedValueMap);
    selectRowInTable(changedValueMap);
    validationError = svm.validateViewValue(newViewValue);
    assertNull("There should not be any validation errors", validationError);
    svm.loadViewValue(newViewValue, false);
    waitWhileNodeInExecution(m_subnodeID);
    assertTrue("Subnode should be executed.", getManager().getNodeContainer(m_subnodeID).getNodeContainerState().isExecuted());
    validateReexecutionResult();
    svm.discard();
    assertNull("Page should be null after reset", svm.getViewRepresentation());
    assertNull("View value should be null after reset", svm.getViewValue());
}
Also used : HashMap(java.util.HashMap) SubnodeViewableModel(org.knime.core.wizard.SubnodeViewableModel) ValidationError(org.knime.core.node.web.ValidationError) CollectionValidationError(org.knime.core.wizard.SubnodeViewableModel.CollectionValidationError) CollectionValidationError(org.knime.core.wizard.SubnodeViewableModel.CollectionValidationError) JSONWebNodePage(org.knime.js.core.JSONWebNodePage) SubnodeViewValue(org.knime.core.wizard.SubnodeViewValue) Test(org.junit.Test)

Example 2 with JSONWebNodePage

use of org.knime.js.core.JSONWebNodePage in project knime-core by knime.

the class TestSubnodeView method testExecuteAndCreateSerializablePageView.

/**
 * Simple test if a serializable page object (view) can be created.
 * @throws Exception
 */
@Test
public void testExecuteAndCreateSerializablePageView() throws Exception {
    initialExecute();
    JSONWebNodePage page = m_spm.createWizardPage(m_subnodeID);
    validateJSONPage(page);
}
Also used : JSONWebNodePage(org.knime.js.core.JSONWebNodePage) Test(org.junit.Test)

Example 3 with JSONWebNodePage

use of org.knime.js.core.JSONWebNodePage in project knime-core by knime.

the class AbstractPageManager method createWizardPageInternal.

/**
 * Performs a transformation from {@link WizardPageContent} to {@link JSONWebNodePage} which can be used for serialization.
 * @param page the {@link WizardPageContent} to transform
 * @return the transformed {@link JSONWebNodePage}
 * @throws IOException if layout of page can not be generated
 */
protected JSONWebNodePage createWizardPageInternal(final WizardPageContent page) throws IOException {
    // process layout
    JSONLayoutPage layout = new JSONLayoutPage();
    try {
        String lString = page.getLayoutInfo();
        if (StringUtils.isNotEmpty(lString)) {
            layout = getJSONLayoutFromSubnode(page.getPageNodeID(), page.getLayoutInfo());
        }
    } catch (IOException e) {
        throw new IOException("Layout for page could not be generated: " + e.getMessage(), e);
    }
    // process selection translators
    List<JSONSelectionTranslator> selectionTranslators = new ArrayList<JSONSelectionTranslator>();
    if (page.getHiLiteTranslators() != null) {
        for (HiLiteTranslator hiLiteTranslator : page.getHiLiteTranslators()) {
            if (hiLiteTranslator != null) {
                selectionTranslators.add(new JSONSelectionTranslator(hiLiteTranslator));
            }
        }
    }
    if (page.getHiliteManagers() != null) {
        for (HiLiteManager hiLiteManager : page.getHiliteManagers()) {
            if (hiLiteManager != null) {
                selectionTranslators.add(new JSONSelectionTranslator(hiLiteManager));
            }
        }
    }
    if (selectionTranslators.size() < 1) {
        selectionTranslators = null;
    }
    JSONWebNodePageConfiguration pageConfig = new JSONWebNodePageConfiguration(layout, null, selectionTranslators);
    Map<String, JSONWebNode> nodes = new HashMap<String, JSONWebNode>();
    for (Map.Entry<NodeIDSuffix, WizardPageNodeInfo> e : page.getInfoMap().entrySet()) {
        WizardPageNodeInfo pInfo = e.getValue();
        JSONWebNode jsonNode = new JSONWebNode();
        JSONWebNodeInfo info = new JSONWebNodeInfo();
        info.setNodeName(pInfo.getNodeName());
        info.setNodeAnnotation(pInfo.getNodeAnnotation());
        NodeContainerState state = pInfo.getNodeState();
        if (state.isIdle()) {
            info.setNodeState(JSONNodeState.IDLE);
        }
        if (state.isConfigured()) {
            info.setNodeState(JSONNodeState.CONFIGURED);
        }
        if (state.isExecutionInProgress() || state.isExecutingRemotely()) {
            info.setNodeState(JSONNodeState.EXECUTING);
        }
        if (state.isExecuted()) {
            info.setNodeState(JSONNodeState.EXECUTED);
        }
        NodeMessage message = pInfo.getNodeMessage();
        if (org.knime.core.node.workflow.NodeMessage.Type.ERROR.equals(message.getMessageType())) {
            info.setNodeErrorMessage(message.getMessage());
        }
        if (org.knime.core.node.workflow.NodeMessage.Type.WARNING.equals(message.getMessageType())) {
            info.setNodeWarnMessage(message.getMessage());
        }
        WizardNode<?, ?> wizardNode = page.getPageMap().get(e.getKey());
        if (wizardNode == null) {
            info.setDisplayPossible(false);
        } else {
            info.setDisplayPossible(true);
            WebTemplate template = WebResourceController.getWebTemplateFromJSObjectID(wizardNode.getJavascriptObjectID());
            List<String> jsList = new ArrayList<String>();
            List<String> cssList = new ArrayList<String>();
            for (WebResourceLocator locator : template.getWebResources()) {
                if (locator.getType() == WebResourceType.JAVASCRIPT) {
                    jsList.add(locator.getRelativePathTarget());
                } else if (locator.getType() == WebResourceType.CSS) {
                    cssList.add(locator.getRelativePathTarget());
                }
            }
            jsonNode.setJavascriptLibraries(jsList);
            jsonNode.setStylesheets(cssList);
            jsonNode.setNamespace(template.getNamespace());
            jsonNode.setInitMethodName(template.getInitMethodName());
            jsonNode.setValidateMethodName(template.getValidateMethodName());
            jsonNode.setSetValidationErrorMethodName(template.getSetValidationErrorMethodName());
            jsonNode.setGetViewValueMethodName(template.getPullViewContentMethodName());
            jsonNode.setViewRepresentation((JSONViewContent) wizardNode.getViewRepresentation());
            jsonNode.setViewValue((JSONViewContent) wizardNode.getViewValue());
        }
        jsonNode.setNodeInfo(info);
        nodes.put(e.getKey().toString(), jsonNode);
    }
    return new JSONWebNodePage(pageConfig, nodes);
}
Also used : JSONLayoutPage(org.knime.js.core.layout.bs.JSONLayoutPage) HashMap(java.util.HashMap) JSONWebNodePageConfiguration(org.knime.js.core.JSONWebNodePageConfiguration) ArrayList(java.util.ArrayList) JSONWebNode(org.knime.js.core.JSONWebNode) HiLiteTranslator(org.knime.core.node.property.hilite.HiLiteTranslator) IOException(java.io.IOException) HiLiteManager(org.knime.core.node.property.hilite.HiLiteManager) JSONWebNodePage(org.knime.js.core.JSONWebNodePage) NodeContainerState(org.knime.core.node.workflow.NodeContainerState) WebResourceLocator(org.knime.core.node.web.WebResourceLocator) JSONWebNodeInfo(org.knime.js.core.JSONWebNodeInfo) NodeIDSuffix(org.knime.core.node.workflow.NodeID.NodeIDSuffix) WebTemplate(org.knime.core.node.web.WebTemplate) JSONSelectionTranslator(org.knime.js.core.selections.json.JSONSelectionTranslator) NodeMessage(org.knime.core.node.workflow.NodeMessage) HashMap(java.util.HashMap) Map(java.util.Map) WizardPageNodeInfo(org.knime.core.node.workflow.WebResourceController.WizardPageContent.WizardPageNodeInfo)

Example 4 with JSONWebNodePage

use of org.knime.js.core.JSONWebNodePage in project knime-core by knime.

the class WizardPageManager method createCurrentWizardPageString.

/**
 * Creates a JSON string containing a wizard page for the current subnode in wizard execution
 *
 * @return a JSON string containing the wizard page
 * @throws IOException if the layout of the wizard page can not be generated
 * @throws JsonProcessingException on serialization errors
 */
public String createCurrentWizardPageString() throws IOException, JsonProcessingException {
    JSONWebNodePage jsonPage = createCurrentWizardPage();
    ObjectMapper mapper = JSONLayoutPage.getConfiguredVerboseObjectMapper();
    return mapper.writeValueAsString(jsonPage);
}
Also used : ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) JSONWebNodePage(org.knime.js.core.JSONWebNodePage)

Aggregations

JSONWebNodePage (org.knime.js.core.JSONWebNodePage)4 HashMap (java.util.HashMap)2 Test (org.junit.Test)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 HiLiteManager (org.knime.core.node.property.hilite.HiLiteManager)1 HiLiteTranslator (org.knime.core.node.property.hilite.HiLiteTranslator)1 ValidationError (org.knime.core.node.web.ValidationError)1 WebResourceLocator (org.knime.core.node.web.WebResourceLocator)1 WebTemplate (org.knime.core.node.web.WebTemplate)1 NodeContainerState (org.knime.core.node.workflow.NodeContainerState)1 NodeIDSuffix (org.knime.core.node.workflow.NodeID.NodeIDSuffix)1 NodeMessage (org.knime.core.node.workflow.NodeMessage)1 WizardPageNodeInfo (org.knime.core.node.workflow.WebResourceController.WizardPageContent.WizardPageNodeInfo)1 SubnodeViewValue (org.knime.core.wizard.SubnodeViewValue)1 SubnodeViewableModel (org.knime.core.wizard.SubnodeViewableModel)1 CollectionValidationError (org.knime.core.wizard.SubnodeViewableModel.CollectionValidationError)1 JSONWebNode (org.knime.js.core.JSONWebNode)1