Search in sources :

Example 1 with BPMNDiagram

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

the class ProcessVariablesProvider method findElements.

@Override
protected Collection<Pair<Object, String>> findElements(Predicate<Node> filter, Function<Node, Pair<Object, String>> mapper) {
    Collection<Pair<Object, String>> result = new ArrayList<>();
    String elementUUID = sessionManager.getCurrentSession().getCanvasHandler().getDiagram().getMetadata().getCanvasRootUUID();
    Node node;
    if (elementUUID != null) {
        node = sessionManager.getCurrentSession().getCanvasHandler().getDiagram().getGraph().getNode(elementUUID);
        Object oDefinition = ((View) node.getContent()).getDefinition();
        if (oDefinition instanceof BPMNDiagram) {
            BPMNDiagramImpl bpmnDiagram = (BPMNDiagramImpl) oDefinition;
            ProcessVariables processVars = bpmnDiagram.getProcessData().getProcessVariables();
            if (processVars.getValue().length() > 0) {
                List<String> list = Arrays.asList(processVars.getValue().split(","));
                list.forEach(s1 -> {
                    String value = s1.split(":")[0];
                    result.add(new Pair<>(value, value));
                });
            }
        }
    }
    return result;
}
Also used : ProcessVariables(org.kie.workbench.common.stunner.bpmn.definition.property.variables.ProcessVariables) BPMNDiagram(org.kie.workbench.common.stunner.bpmn.definition.BPMNDiagram) Node(org.kie.workbench.common.stunner.core.graph.Node) ArrayList(java.util.ArrayList) BPMNDiagramImpl(org.kie.workbench.common.stunner.bpmn.definition.BPMNDiagramImpl) View(org.kie.workbench.common.stunner.core.graph.content.view.View) Pair(org.uberfire.commons.data.Pair)

Example 2 with BPMNDiagram

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

the class BPMNDirectDiagramMarshallerTest method testUnmarshallProcessVariables.

@Test
@SuppressWarnings("unchecked")
public void testUnmarshallProcessVariables() throws Exception {
    Diagram<Graph, Metadata> diagram = unmarshall(BPMN_PROCESSVARIABLES);
    assertDiagram(diagram, 8);
    assertEquals("ProcessVariables", diagram.getMetadata().getTitle());
    ProcessVariables variables = 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 BPMNDiagram) {
                BPMNDiagramImpl bpmnDiagram = (BPMNDiagramImpl) oDefinition;
                variables = bpmnDiagram.getProcessData().getProcessVariables();
                break;
            }
        }
    }
    assertEquals(variables.getValue(), "employee:java.lang.String,reason:java.lang.String,performance:java.lang.String");
    Node<? extends Definition, ?> diagramNode = diagram.getGraph().getNode("_luRBMdEjEeWXpsZ1tNStKQ");
    assertTrue(diagramNode.getContent().getDefinition() instanceof BPMNDiagram);
    BPMNDiagramImpl bpmnDiagram = (BPMNDiagramImpl) diagramNode.getContent().getDefinition();
    assertTrue(bpmnDiagram.getProcessData() != null);
    assertTrue(bpmnDiagram.getProcessData().getProcessVariables() != null);
    variables = bpmnDiagram.getProcessData().getProcessVariables();
    assertEquals(variables.getValue(), "employee:java.lang.String,reason:java.lang.String,performance:java.lang.String");
}
Also used : ProcessVariables(org.kie.workbench.common.stunner.bpmn.definition.property.variables.ProcessVariables) BPMNDiagram(org.kie.workbench.common.stunner.bpmn.definition.BPMNDiagram) Graph(org.kie.workbench.common.stunner.core.graph.Graph) 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) BPMNDiagramImpl(org.kie.workbench.common.stunner.bpmn.definition.BPMNDiagramImpl) View(org.kie.workbench.common.stunner.core.graph.content.view.View) Test(org.junit.Test)

Example 3 with BPMNDiagram

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

the class BPMNDirectDiagramMarshallerTest method testUnmarshallProcessProperties.

@Test
@SuppressWarnings("unchecked")
public void testUnmarshallProcessProperties() throws Exception {
    Diagram<Graph, Metadata> diagram = unmarshall(BPMN_PROCESSPROPERTIES);
    assertDiagram(diagram, 4);
    assertEquals("BPSimple", diagram.getMetadata().getTitle());
    DiagramSet diagramProperties = 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 BPMNDiagram) {
                BPMNDiagramImpl bpmnDiagram = (BPMNDiagramImpl) oDefinition;
                diagramProperties = bpmnDiagram.getDiagramSet();
                break;
            }
        }
    }
    assertEquals("BPSimple", diagramProperties.getName().getValue());
    assertEquals("This is a\n" + "simple\n" + "process", diagramProperties.getDocumentation().getValue());
    assertEquals("JDLProj.BPSimple", diagramProperties.getId().getValue());
    assertEquals("org.jbpm", diagramProperties.getPackageProperty().getValue());
    assertEquals(Boolean.TRUE, diagramProperties.getExecutable().getValue());
    assertEquals(Boolean.TRUE, diagramProperties.getAdHoc().getValue());
    assertEquals("This is the\n" + "Process\n" + "Instance\n" + "Description", diagramProperties.getProcessInstanceDescription().getValue());
}
Also used : BPMNDiagram(org.kie.workbench.common.stunner.bpmn.definition.BPMNDiagram) Graph(org.kie.workbench.common.stunner.core.graph.Graph) DiagramSet(org.kie.workbench.common.stunner.bpmn.definition.property.diagram.DiagramSet) 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) BPMNDiagramImpl(org.kie.workbench.common.stunner.bpmn.definition.BPMNDiagramImpl) View(org.kie.workbench.common.stunner.core.graph.content.view.View) Test(org.junit.Test)

Example 4 with BPMNDiagram

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

the class BPMNProjectDiagramFactoryImpl method updateDiagramProperties.

@Override
protected void updateDiagramProperties(final String name, final Node<Definition<BPMNDiagram>, ?> diagramNode, final ProjectMetadata metadata) {
    super.updateDiagramProperties(name, diagramNode, metadata);
    // Set kie related properties for the current project.
    final BPMNDiagram diagram = diagramNode.getContent().getDefinition();
    final DiagramSet diagramSet = diagram.getDiagramSet();
    final String id = diagramSet.getId().getValue();
    if (id == null || id.isEmpty()) {
        final String projectName = null != metadata.getModuleName() ? metadata.getModuleName() + "." : "";
        diagramSet.getId().setValue(projectName + name);
    }
    final String p = diagramSet.getPackageProperty().getValue();
    if (p == null || p.isEmpty()) {
        final Package metadataPackage = metadata.getProjectPackage();
        final String value = metadataPackage == null ? org.kie.workbench.common.stunner.bpmn.definition.property.diagram.Package.DEFAULT_PACKAGE : metadata.getProjectPackage().getPackageName();
        diagramSet.getPackageProperty().setValue(value);
    }
    final String diagramName = diagramSet.getName().getValue();
    if (null == diagramName || diagramName.isEmpty()) {
        diagramSet.getName().setValue(name);
    }
}
Also used : BPMNDiagram(org.kie.workbench.common.stunner.bpmn.definition.BPMNDiagram) DiagramSet(org.kie.workbench.common.stunner.bpmn.definition.property.diagram.DiagramSet) Package(org.guvnor.common.services.project.model.Package)

Example 5 with BPMNDiagram

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

the class BPMNDiagramMarshallerTest method testUnmarshallProcessVariables.

@Test
@SuppressWarnings("unchecked")
public void testUnmarshallProcessVariables() throws Exception {
    Diagram<Graph, Metadata> diagram = unmarshall(BPMN_PROCESSVARIABLES);
    assertDiagram(diagram, 8);
    assertEquals("ProcessVariables", diagram.getMetadata().getTitle());
    ProcessVariables variables = 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 BPMNDiagram) {
                BPMNDiagramImpl bpmnDiagram = (BPMNDiagramImpl) oDefinition;
                variables = bpmnDiagram.getProcessData().getProcessVariables();
                break;
            }
        }
    }
    assertEquals(variables.getValue(), "employee:java.lang.String,reason:java.lang.String,performance:java.lang.String");
    Node<? extends Definition, ?> diagramNode = diagram.getGraph().getNode("_luRBMdEjEeWXpsZ1tNStKQ");
    assertTrue(diagramNode.getContent().getDefinition() instanceof BPMNDiagram);
    BPMNDiagramImpl bpmnDiagram = (BPMNDiagramImpl) diagramNode.getContent().getDefinition();
    assertTrue(bpmnDiagram.getProcessData() != null);
    assertTrue(bpmnDiagram.getProcessData().getProcessVariables() != null);
    variables = bpmnDiagram.getProcessData().getProcessVariables();
    assertEquals(variables.getValue(), "employee:java.lang.String,reason:java.lang.String,performance:java.lang.String");
}
Also used : ProcessVariables(org.kie.workbench.common.stunner.bpmn.definition.property.variables.ProcessVariables) BPMNDiagram(org.kie.workbench.common.stunner.bpmn.definition.BPMNDiagram) Graph(org.kie.workbench.common.stunner.core.graph.Graph) 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) BPMNDiagramImpl(org.kie.workbench.common.stunner.bpmn.definition.BPMNDiagramImpl) View(org.kie.workbench.common.stunner.core.graph.content.view.View) Test(org.junit.Test)

Aggregations

BPMNDiagram (org.kie.workbench.common.stunner.bpmn.definition.BPMNDiagram)7 BPMNDiagramImpl (org.kie.workbench.common.stunner.bpmn.definition.BPMNDiagramImpl)5 View (org.kie.workbench.common.stunner.core.graph.content.view.View)5 FlowElement (org.eclipse.bpmn2.FlowElement)4 ItemAwareElement (org.eclipse.bpmn2.ItemAwareElement)4 RootElement (org.eclipse.bpmn2.RootElement)4 Test (org.junit.Test)4 Metadata (org.kie.workbench.common.stunner.core.diagram.Metadata)4 Element (org.kie.workbench.common.stunner.core.graph.Element)4 Graph (org.kie.workbench.common.stunner.core.graph.Graph)4 DiagramSet (org.kie.workbench.common.stunner.bpmn.definition.property.diagram.DiagramSet)3 ProcessVariables (org.kie.workbench.common.stunner.bpmn.definition.property.variables.ProcessVariables)3 ArrayList (java.util.ArrayList)1 Package (org.guvnor.common.services.project.model.Package)1 Node (org.kie.workbench.common.stunner.core.graph.Node)1 Definition (org.kie.workbench.common.stunner.core.graph.content.definition.Definition)1 Pair (org.uberfire.commons.data.Pair)1