Search in sources :

Example 1 with ScriptTask

use of org.kie.workbench.common.stunner.bpmn.definition.ScriptTask in project kie-wb-common by kiegroup.

the class TaskConverter method scriptTask.

private BpmnNode scriptTask(org.eclipse.bpmn2.ScriptTask task) {
    Node<View<ScriptTask>, Edge> node = factoryManager.newNode(task.getId(), ScriptTask.class);
    ScriptTask definition = node.getContent().getDefinition();
    ScriptTaskPropertyReader p = propertyReaderFactory.of(task);
    definition.setGeneral(new TaskGeneralSet(new Name(p.getName()), new Documentation(p.getDocumentation())));
    definition.setExecutionSet(new ScriptTaskExecutionSet(new Script(p.getScript()), new IsAsync(p.isAsync())));
    node.getContent().setBounds(p.getBounds());
    definition.setDimensionsSet(p.getRectangleDimensionsSet());
    definition.setBackgroundSet(p.getBackgroundSet());
    definition.setFontSet(p.getFontSet());
    definition.setSimulationSet(p.getSimulationSet());
    return BpmnNode.of(node);
}
Also used : Script(org.kie.workbench.common.stunner.bpmn.definition.property.task.Script) ScriptTask(org.kie.workbench.common.stunner.bpmn.definition.ScriptTask) Documentation(org.kie.workbench.common.stunner.bpmn.definition.property.general.Documentation) TaskGeneralSet(org.kie.workbench.common.stunner.bpmn.definition.property.general.TaskGeneralSet) IsAsync(org.kie.workbench.common.stunner.bpmn.definition.property.task.IsAsync) View(org.kie.workbench.common.stunner.core.graph.content.view.View) Edge(org.kie.workbench.common.stunner.core.graph.Edge) ScriptTaskPropertyReader(org.kie.workbench.common.stunner.bpmn.backend.converters.tostunner.properties.ScriptTaskPropertyReader) Name(org.kie.workbench.common.stunner.bpmn.definition.property.general.Name) TaskName(org.kie.workbench.common.stunner.bpmn.definition.property.task.TaskName) ScriptTaskExecutionSet(org.kie.workbench.common.stunner.bpmn.definition.property.task.ScriptTaskExecutionSet)

Example 2 with ScriptTask

use of org.kie.workbench.common.stunner.bpmn.definition.ScriptTask in project kie-wb-common by kiegroup.

the class DefaultRouteFormProviderTest method setUp.

@Before
public void setUp() throws Exception {
    super.setUp();
    when(definitionManager.adapters()).thenReturn(adapterManager);
    when(adapterManager.forDefinition()).thenReturn(definitionAdapter);
    when(session.getSelectionControl()).thenReturn(selectionControl);
    Collection<String> selectedItems = new ArrayList<>();
    when(selectedNode.getUUID()).thenReturn(SELECTED_UUID);
    selectedItems.add(selectedNode.getUUID());
    when(selectionControl.getSelectedItems()).thenReturn(selectedItems);
    when(graph.getNode(SELECTED_UUID)).thenReturn(selectedNode);
    outEdges = new ArrayList<>();
    UserTask userTask1 = new UserTask(new TaskGeneralSet(new Name("UserTask1"), null), null, null, null, null, null, null);
    when(definitionAdapter.getTitle(eq(userTask1))).thenReturn("User Task");
    outEdges.add(mockEdge("Edge1", userTask1));
    UserTask userTask2 = new UserTask(new TaskGeneralSet(new Name("UserTask2"), null), null, null, null, null, null, null);
    when(definitionAdapter.getTitle(eq(userTask2))).thenReturn("User Task");
    outEdges.add(mockEdge("Edge2", userTask2));
    ScriptTask scriptTask3 = new ScriptTask(new TaskGeneralSet(new Name("ScriptTask3"), null), null, null, null, null, null, null);
    when(definitionAdapter.getTitle(eq(scriptTask3))).thenReturn("Script Task");
    outEdges.add(mockEdge("Edge3", scriptTask3));
    ExclusiveGateway gateway4 = new ExclusiveGateway(new BPMNGeneralSet("Gateway4"), null, null, null, null);
    when(definitionAdapter.getTitle(eq(gateway4))).thenReturn("Exclusive Gateway");
    outEdges.add(mockEdge("Edge4", gateway4));
    InclusiveGateway gateway5 = new InclusiveGateway(new BPMNGeneralSet(""), null, null, null, null);
    when(definitionAdapter.getTitle(eq(gateway5))).thenReturn("Inclusive Gateway");
    outEdges.add(mockEdge("Edge5", gateway5));
}
Also used : ExclusiveGateway(org.kie.workbench.common.stunner.bpmn.definition.ExclusiveGateway) ScriptTask(org.kie.workbench.common.stunner.bpmn.definition.ScriptTask) InclusiveGateway(org.kie.workbench.common.stunner.bpmn.definition.InclusiveGateway) ArrayList(java.util.ArrayList) UserTask(org.kie.workbench.common.stunner.bpmn.definition.UserTask) TaskGeneralSet(org.kie.workbench.common.stunner.bpmn.definition.property.general.TaskGeneralSet) BPMNGeneralSet(org.kie.workbench.common.stunner.bpmn.definition.property.general.BPMNGeneralSet) Name(org.kie.workbench.common.stunner.bpmn.definition.property.general.Name) Before(org.junit.Before)

Example 3 with ScriptTask

use of org.kie.workbench.common.stunner.bpmn.definition.ScriptTask in project kie-wb-common by kiegroup.

the class TaskConverter method scriptTask.

private PropertyWriter scriptTask(Node<View<ScriptTask>, ?> n) {
    org.eclipse.bpmn2.ScriptTask task = bpmn2.createScriptTask();
    task.setId(n.getUUID());
    ScriptTask definition = n.getContent().getDefinition();
    ScriptTaskPropertyWriter p = propertyWriterFactory.of(task);
    TaskGeneralSet general = definition.getGeneral();
    p.setName(general.getName().getValue());
    p.setDocumentation(general.getDocumentation().getValue());
    ScriptTaskExecutionSet executionSet = definition.getExecutionSet();
    p.setScript(executionSet.getScript().getValue());
    p.setAsync(executionSet.getIsAsync().getValue());
    p.setSimulationSet(definition.getSimulationSet());
    p.setBounds(n.getContent().getBounds());
    return p;
}
Also used : ScriptTaskPropertyWriter(org.kie.workbench.common.stunner.bpmn.backend.converters.fromstunner.properties.ScriptTaskPropertyWriter) ScriptTask(org.kie.workbench.common.stunner.bpmn.definition.ScriptTask) TaskGeneralSet(org.kie.workbench.common.stunner.bpmn.definition.property.general.TaskGeneralSet) Factories.bpmn2(org.kie.workbench.common.stunner.bpmn.backend.converters.fromstunner.Factories.bpmn2) ScriptTaskExecutionSet(org.kie.workbench.common.stunner.bpmn.definition.property.task.ScriptTaskExecutionSet)

Example 4 with ScriptTask

use of org.kie.workbench.common.stunner.bpmn.definition.ScriptTask in project kie-wb-common by kiegroup.

the class ScriptTaskConverter method convert.

public Node<? extends View<? extends BPMNViewDefinition>, ?> convert(org.eclipse.bpmn2.ScriptTask task) {
    Node<View<ScriptTask>, Edge> node = factoryManager.newNode(task.getId(), ScriptTask.class);
    ScriptTask definition = node.getContent().getDefinition();
    ScriptTaskPropertyReader p = propertyReaderFactory.of(task);
    definition.setGeneral(new TaskGeneralSet(new Name(p.getName()), new Documentation(p.getDocumentation())));
    definition.setExecutionSet(new ScriptTaskExecutionSet(new Script(p.getScript()), new IsAsync(p.isAsync())));
    node.getContent().setBounds(p.getBounds());
    definition.setDimensionsSet(p.getRectangleDimensionsSet());
    definition.setBackgroundSet(p.getBackgroundSet());
    definition.setFontSet(p.getFontSet());
    definition.setSimulationSet(p.getSimulationSet());
    return node;
}
Also used : Script(org.kie.workbench.common.stunner.bpmn.definition.property.task.Script) ScriptTask(org.kie.workbench.common.stunner.bpmn.definition.ScriptTask) Documentation(org.kie.workbench.common.stunner.bpmn.definition.property.general.Documentation) TaskGeneralSet(org.kie.workbench.common.stunner.bpmn.definition.property.general.TaskGeneralSet) IsAsync(org.kie.workbench.common.stunner.bpmn.definition.property.task.IsAsync) View(org.kie.workbench.common.stunner.core.graph.content.view.View) Edge(org.kie.workbench.common.stunner.core.graph.Edge) ScriptTaskPropertyReader(org.kie.workbench.common.stunner.bpmn.backend.converters.tostunner.properties.ScriptTaskPropertyReader) Name(org.kie.workbench.common.stunner.bpmn.definition.property.general.Name) ScriptTaskExecutionSet(org.kie.workbench.common.stunner.bpmn.definition.property.task.ScriptTaskExecutionSet)

Example 5 with ScriptTask

use of org.kie.workbench.common.stunner.bpmn.definition.ScriptTask in project kie-wb-common by kiegroup.

the class BPMNDirectDiagramMarshallerTest method testUnmarshallScriptTask.

@Test
public void testUnmarshallScriptTask() throws Exception {
    Diagram<Graph, Metadata> diagram = unmarshall(BPMN_SCRIPTTASK);
    ScriptTask javascriptScriptTask = null;
    ScriptTask javaScriptTask = null;
    Iterator<Element> it = nodesIterator(diagram);
    while (it.hasNext()) {
        Element element = it.next();
        if (element.getContent() instanceof View) {
            Object oDefinition = ((View) element.getContent()).getDefinition();
            if (oDefinition instanceof ScriptTask) {
                ScriptTask task = (ScriptTask) oDefinition;
                if ("Javascript Script Task".equals(task.getGeneral().getName().getValue())) {
                    javascriptScriptTask = task;
                } else if ("Java Script Task".equals(task.getGeneral().getName().getValue())) {
                    javaScriptTask = task;
                }
            }
        }
    }
    assertNotNull(javascriptScriptTask);
    assertNotNull(javascriptScriptTask.getExecutionSet());
    assertNotNull(javascriptScriptTask.getExecutionSet().getScript());
    assertEquals(javascriptScriptTask.getTaskType().getValue(), TaskTypes.SCRIPT);
    assertEquals("Javascript Script Task", javascriptScriptTask.getGeneral().getName().getValue());
    assertEquals("var str = FirstName + LastName;", javascriptScriptTask.getExecutionSet().getScript().getValue().getScript());
    assertEquals("javascript", javascriptScriptTask.getExecutionSet().getScript().getValue().getLanguage());
    assertEquals("true", javascriptScriptTask.getExecutionSet().getIsAsync().getValue().toString());
    assertEquals("true", javascriptScriptTask.getExecutionSet().getIsAsync().getValue().toString());
    assertNotNull(javaScriptTask);
    assertNotNull(javaScriptTask.getExecutionSet());
    assertNotNull(javaScriptTask.getExecutionSet().getScript());
    assertEquals(javaScriptTask.getTaskType().getValue(), TaskTypes.SCRIPT);
    assertEquals("Java Script Task", javaScriptTask.getGeneral().getName().getValue());
    assertEquals("if (name.toString().equals(\"Jay\")) {\n" + "\n" + "      System.out.println(\"Hello\\n\" + name.toString() + \"\\n\");\n" + "\n" + "} else {\n" + "\n" + "\n" + "  System.out.println(\"Hi\\n\" + name.toString() + \"\\n\");\n" + "\n" + "\n" + "}\n", javaScriptTask.getExecutionSet().getScript().getValue().getScript());
    assertEquals("java", javaScriptTask.getExecutionSet().getScript().getValue().getLanguage());
    assertEquals("true", javaScriptTask.getExecutionSet().getIsAsync().getValue().toString());
    assertEquals("true", javaScriptTask.getExecutionSet().getIsAsync().getValue().toString());
}
Also used : Graph(org.kie.workbench.common.stunner.core.graph.Graph) ScriptTask(org.kie.workbench.common.stunner.bpmn.definition.ScriptTask) ItemAwareElement(org.eclipse.bpmn2.ItemAwareElement) FlowElement(org.eclipse.bpmn2.FlowElement) RootElement(org.eclipse.bpmn2.RootElement) Element(org.kie.workbench.common.stunner.core.graph.Element) Metadata(org.kie.workbench.common.stunner.core.diagram.Metadata) View(org.kie.workbench.common.stunner.core.graph.content.view.View) Test(org.junit.Test)

Aggregations

ScriptTask (org.kie.workbench.common.stunner.bpmn.definition.ScriptTask)7 TaskGeneralSet (org.kie.workbench.common.stunner.bpmn.definition.property.general.TaskGeneralSet)4 View (org.kie.workbench.common.stunner.core.graph.content.view.View)4 Test (org.junit.Test)3 Name (org.kie.workbench.common.stunner.bpmn.definition.property.general.Name)3 ScriptTaskExecutionSet (org.kie.workbench.common.stunner.bpmn.definition.property.task.ScriptTaskExecutionSet)3 FlowElement (org.eclipse.bpmn2.FlowElement)2 ItemAwareElement (org.eclipse.bpmn2.ItemAwareElement)2 RootElement (org.eclipse.bpmn2.RootElement)2 ScriptTaskPropertyReader (org.kie.workbench.common.stunner.bpmn.backend.converters.tostunner.properties.ScriptTaskPropertyReader)2 UserTask (org.kie.workbench.common.stunner.bpmn.definition.UserTask)2 Documentation (org.kie.workbench.common.stunner.bpmn.definition.property.general.Documentation)2 IsAsync (org.kie.workbench.common.stunner.bpmn.definition.property.task.IsAsync)2 Script (org.kie.workbench.common.stunner.bpmn.definition.property.task.Script)2 Metadata (org.kie.workbench.common.stunner.core.diagram.Metadata)2 Edge (org.kie.workbench.common.stunner.core.graph.Edge)2 Element (org.kie.workbench.common.stunner.core.graph.Element)2 Graph (org.kie.workbench.common.stunner.core.graph.Graph)2 ArrayList (java.util.ArrayList)1 Before (org.junit.Before)1