// @Test
 // removing until we start supporting global tasks
 public void testManualTaskUnmarshalling() throws Exception {
   Bpmn2JsonUnmarshaller unmarshaller = new Bpmn2JsonUnmarshaller();
   Definitions definitions =
       ((Definitions)
           unmarshaller.unmarshall(getTestJsonFile("manualTask.json"), "").getContents().get(0));
   assertTrue(definitions.getRootElements().size() == 1);
   GlobalManualTask task = (GlobalManualTask) definitions.getRootElements().get(0);
   assertEquals("pull a lever", task.getName());
   definitions.eResource().save(System.out, Collections.emptyMap());
 }
 // @Test
 // removing until we start supporting global tasks
 public void testSimpleGlobalTaskUnmarshalling() throws Exception {
   Bpmn2JsonUnmarshaller unmarshaller = new Bpmn2JsonUnmarshaller();
   Definitions definitions =
       ((Definitions)
           unmarshaller.unmarshall(getTestJsonFile("oneTask.json"), "").getContents().get(0));
   assertTrue(definitions.getRootElements().size() == 1);
   assertTrue(definitions.getRootElements().iterator().next() instanceof GlobalTask);
   GlobalTask task = (GlobalTask) definitions.getRootElements().iterator().next();
   assertEquals("oneTask", task.getName());
   assertEquals("my task doc", task.getDocumentation().iterator().next().getText());
   definitions.eResource().save(System.out, Collections.emptyMap());
 }
 @Test
 public void testDataStoreUnmarshalling() throws Exception {
   Bpmn2JsonUnmarshaller unmarshaller = new Bpmn2JsonUnmarshaller();
   Definitions definitions =
       ((Definitions)
           unmarshaller.unmarshall(getTestJsonFile("dataStore.json"), "").getContents().get(0));
   assertTrue(definitions.getRootElements().size() == 1);
   assertTrue(definitions.getRootElements().iterator().next() instanceof DataStore);
   DataStore da = (DataStore) definitions.getRootElements().iterator().next();
   assertEquals("data store", da.getName());
   definitions.eResource().save(System.out, Collections.emptyMap());
 }
 @Test
 public void testMessageUnmarshalling() throws Exception {
   Bpmn2JsonUnmarshaller unmarshaller = new Bpmn2JsonUnmarshaller();
   Definitions definitions =
       ((Definitions)
           unmarshaller.unmarshall(getTestJsonFile("message.json"), "").getContents().get(0));
   assertTrue(definitions.getRootElements().size() == 2);
   assertTrue(definitions.getRootElements().iterator().next() instanceof Message);
   Message msg = (Message) definitions.getRootElements().iterator().next();
   assertEquals("message", msg.getName());
   definitions.eResource().save(System.out, Collections.emptyMap());
 }
 // @Test
 // removing until we start supporting global tasks
 public void testScriptTaskUnmarshalling() throws Exception {
   Bpmn2JsonUnmarshaller unmarshaller = new Bpmn2JsonUnmarshaller();
   Definitions definitions =
       ((Definitions)
           unmarshaller.unmarshall(getTestJsonFile("scriptTask.json"), "").getContents().get(0));
   assertTrue(definitions.getRootElements().size() == 1);
   GlobalScriptTask task = (GlobalScriptTask) definitions.getRootElements().get(0);
   assertEquals("my script", task.getName());
   assertEquals(
       "git status | grep modified | awk '{print $3}' | xargs echo | xargs git add",
       task.getScript());
   assertEquals("bash", task.getScriptLanguage());
   definitions.eResource().save(System.out, Collections.emptyMap());
 }
  void createDefinitionsIfMissing() {
    EList<EObject> contents = resource.getContents();

    if (contents.isEmpty() || !(contents.get(0) instanceof DocumentRoot)) {
      TransactionalEditingDomain domain = TransactionUtil.getEditingDomain(resource);

      if (domain != null) {
        final DocumentRoot docRoot = FACTORY.createDocumentRoot();
        final Definitions definitions = FACTORY.createDefinitions();
        //				definitions.setId(EcoreUtil.generateUUID());
        ModelUtil.setID(definitions, resource);
        Collaboration collaboration = FACTORY.createCollaboration();
        //				collaboration.setId(EcoreUtil.generateUUID());
        ModelUtil.setID(collaboration, resource);
        Participant participant = FACTORY.createParticipant();
        //				participant.setId(EcoreUtil.generateUUID());
        ModelUtil.setID(participant, resource);
        participant.setName("Internal");
        collaboration.getParticipants().add(participant);
        definitions.getRootElements().add(collaboration);

        domain
            .getCommandStack()
            .execute(
                new RecordingCommand(domain) {
                  @Override
                  protected void doExecute() {
                    docRoot.setDefinitions(definitions);
                    resource.getContents().add(docRoot);
                  }
                });
        return;
      }
    }
  }
 private Process getRootProcess(Definitions def) {
   for (RootElement nextRootElement : def.getRootElements()) {
     if (nextRootElement instanceof Process) {
       return (Process) nextRootElement;
     }
   }
   return null;
 }
 @Test
 public void testEndEventUnmarshalling() throws Exception {
   Bpmn2JsonUnmarshaller unmarshaller = new Bpmn2JsonUnmarshaller();
   Definitions definitions =
       ((Definitions)
           unmarshaller.unmarshall(getTestJsonFile("endEvent.json"), "").getContents().get(0));
   assertTrue(definitions.getRootElements().size() == 1);
   Process process = getRootProcess(definitions);
   EndEvent g = (EndEvent) process.getFlowElements().get(0);
   assertEquals("end event", g.getName());
   definitions.eResource().save(System.out, Collections.emptyMap());
 }
Esempio n. 9
0
  private DiagramElementTree findMissingDIElements() {

    DiagramElementTree missing = new DiagramElementTree(null, null);

    // look for any BPMN2 elements that do not have corresponding DI elements
    for (BaseElement be : definitions.getRootElements()) {
      findMissingDIElements(missing, be);
    }

    removeDuplicates(missing.getChildren());
    return missing;
  }
 @Test
 public void testSimpleDefinitionsUnmarshalling() throws Exception {
   Bpmn2JsonUnmarshaller unmarshaller = new Bpmn2JsonUnmarshaller();
   Definitions definitions =
       ((Definitions)
           unmarshaller.unmarshall(getTestJsonFile("empty.json"), "").getContents().get(0));
   assertEquals("my doc", definitions.getDocumentation().iterator().next().getText());
   assertEquals("http://www.w3.org/1999/XPath", definitions.getExpressionLanguage());
   assertEquals("http://www.omg.org/bpmn20", definitions.getTargetNamespace());
   assertEquals("http://www.w3.org/2001/XMLSchema", definitions.getTypeLanguage());
   assertTrue(definitions.getRootElements().isEmpty());
   definitions.eResource().save(System.out, Collections.emptyMap());
 }
 @Test
 public void testDataObjectUnmarshalling() throws Exception {
   Bpmn2JsonUnmarshaller unmarshaller = new Bpmn2JsonUnmarshaller();
   Definitions definitions =
       ((Definitions)
           unmarshaller.unmarshall(getTestJsonFile("dataObject.json"), "").getContents().get(0));
   assertTrue(definitions.getRootElements().size() == 2);
   Process process = getRootProcess(definitions);
   assertTrue(process.getFlowElements().iterator().next() instanceof DataObject);
   DataObject da = (DataObject) process.getFlowElements().iterator().next();
   assertEquals("data object", da.getName());
   definitions.eResource().save(System.out, Collections.emptyMap());
 }
 @Test
 public void testPoolUnmarshalling() throws Exception {
   Bpmn2JsonUnmarshaller unmarshaller = new Bpmn2JsonUnmarshaller();
   Definitions definitions =
       ((Definitions)
           unmarshaller.unmarshall(getTestJsonFile("pool.json"), "").getContents().get(0));
   assertTrue(definitions.getRootElements().size() == 1);
   assertTrue(definitions.getRootElements().get(0) instanceof Process);
   Process process = getRootProcess(definitions);
   assertEquals("pool", process.getName());
   assertEquals(ProcessType.PRIVATE, process.getProcessType());
   assertTrue(process.isIsClosed());
   definitions.eResource().save(System.out, Collections.emptyMap());
 }
 @Test
 public void testLaneUnmarshalling() throws Exception {
   Bpmn2JsonUnmarshaller unmarshaller = new Bpmn2JsonUnmarshaller();
   Definitions definitions =
       ((Definitions)
           unmarshaller.unmarshall(getTestJsonFile("pool.json"), "").getContents().get(0));
   assertTrue(definitions.getRootElements().size() == 1);
   assertTrue(definitions.getRootElements().get(0) instanceof Process);
   Process process = getRootProcess(definitions);
   assertTrue(process.getLaneSets().size() == 1);
   assertTrue(process.getLaneSets().get(0).getLanes().size() == 1);
   Lane l = process.getLaneSets().get(0).getLanes().get(0);
   assertEquals("my first lane", l.getName());
   definitions.eResource().save(System.out, Collections.emptyMap());
 }
 @Test
 public void testIntermediateThrowSignalUnmarshalling() throws Exception {
   Bpmn2JsonUnmarshaller unmarshaller = new Bpmn2JsonUnmarshaller();
   Definitions definitions =
       ((Definitions)
           unmarshaller
               .unmarshall(getTestJsonFile("intermediateThrowSignalEvent.json"), "")
               .getContents()
               .get(0));
   assertTrue(definitions.getRootElements().size() == 1);
   Process process = getRootProcess(definitions);
   ThrowEvent g = (ThrowEvent) process.getFlowElements().get(0);
   assertEquals("throw signal event", g.getName());
   assertTrue(g.getEventDefinitions().iterator().next() instanceof SignalEventDefinition);
   definitions.eResource().save(System.out, Collections.emptyMap());
 }
 @Test
 public void testSimpleChainUnmarshalling() throws Exception {
   Bpmn2JsonUnmarshaller unmarshaller = new Bpmn2JsonUnmarshaller();
   Definitions definitions =
       ((Definitions)
           unmarshaller
               .unmarshall(getTestJsonFile("startEvent-task-endEvent.json"), "")
               .getContents()
               .get(0));
   assertTrue(definitions.getRootElements().size() == 1);
   Process process = getRootProcess(definitions);
   assertTrue(process.getFlowElements().size() == 5);
   assertTrue(process.getLaneSets().size() == 1);
   assertTrue(process.getLaneSets().get(0).getLanes().size() == 1);
   definitions.eResource().save(System.out, Collections.emptyMap());
 }
 @Test
 public void testStartParallelMultipleEventUnmarshalling() throws Exception {
   Bpmn2JsonUnmarshaller unmarshaller = new Bpmn2JsonUnmarshaller();
   Definitions definitions =
       ((Definitions)
           unmarshaller
               .unmarshall(getTestJsonFile("startParallelMultipleEvent.json"), "")
               .getContents()
               .get(0));
   assertTrue(definitions.getRootElements().size() == 1);
   Process process = getRootProcess(definitions);
   StartEvent g = (StartEvent) process.getFlowElements().get(0);
   assertEquals("start parallel multiple event", g.getName());
   // TODO multiple event definitions ???
   definitions.eResource().save(System.out, Collections.emptyMap());
 }
 /**
  * @Test this test needs to be revised (the json) public void testGroupUnmarshalling() throws
  * Exception { Bpmn2JsonUnmarshaller unmarshaller = new Bpmn2JsonUnmarshaller(); Definitions
  * definitions = ((Definitions) unmarshaller.unmarshall(getTestJsonFile("group.json"),
  * "").getContents().get(0)); assertTrue(definitions.getRootElements().size() == 1); Process
  * process = getRootProcess(definitions); assertTrue(process.getArtifacts().iterator().next()
  * instanceof Group); definitions.eResource().save(System.out, Collections.emptyMap()); }*
  */
 @Test
 public void testTextAnnotationUnmarshalling() throws Exception {
   Bpmn2JsonUnmarshaller unmarshaller = new Bpmn2JsonUnmarshaller();
   Definitions definitions =
       ((Definitions)
           unmarshaller
               .unmarshall(getTestJsonFile("textAnnotation.json"), "")
               .getContents()
               .get(0));
   assertTrue(definitions.getRootElements().size() == 1);
   Process process = getRootProcess(definitions);
   assertTrue(process.getArtifacts().iterator().next() instanceof TextAnnotation);
   TextAnnotation ta = (TextAnnotation) process.getArtifacts().iterator().next();
   assertEquals("text annotation", ta.getText());
   definitions.eResource().save(System.out, Collections.emptyMap());
 }
 @Test
 public void testAssociationUnmarshalling() throws Exception {
   Bpmn2JsonUnmarshaller unmarshaller = new Bpmn2JsonUnmarshaller();
   Definitions definitions =
       ((Definitions)
           unmarshaller.unmarshall(getTestJsonFile("association.json"), "").getContents().get(0));
   assertTrue(definitions.getRootElements().size() == 1);
   Process process = getRootProcess(definitions);
   Task g = (Task) process.getFlowElements().get(0);
   assertEquals("task", g.getName());
   TextAnnotation textA = (TextAnnotation) process.getArtifacts().get(0);
   Association association = (Association) process.getArtifacts().get(1);
   assertEquals(g, association.getSourceRef());
   assertEquals(textA, association.getTargetRef());
   assertEquals(AssociationDirection.NONE, association.getAssociationDirection());
   definitions.eResource().save(System.out, Collections.emptyMap());
 }
 @Test
 public void testSequenceFlowUnmarshalling() throws Exception {
   Bpmn2JsonUnmarshaller unmarshaller = new Bpmn2JsonUnmarshaller();
   Definitions definitions =
       ((Definitions)
           unmarshaller.unmarshall(getTestJsonFile("sequenceFlow.json"), "").getContents().get(0));
   assertTrue(definitions.getRootElements().size() == 1);
   Process process = getRootProcess(definitions);
   assertTrue(process.getFlowElements().get(0) instanceof Task);
   Task task = (Task) process.getFlowElements().get(0);
   assertEquals("task1", task.getName());
   Task task2 = (Task) process.getFlowElements().get(1);
   assertEquals("task2", task2.getName());
   SequenceFlow flow = (SequenceFlow) process.getFlowElements().get(2);
   assertEquals("seqFlow", flow.getName());
   assertEquals(task, flow.getSourceRef());
   assertEquals(task2, flow.getTargetRef());
   definitions.eResource().save(System.out, Collections.emptyMap());
 }
Esempio n. 20
0
  @Override
  protected void findGL(Definitions diagram) {
    StringBuilder temp = new StringBuilder();

    int num = 0;

    for (RootElement rootElement : diagram.getRootElements()) {
      if (rootElement instanceof Process) {
        Process process = (Process) rootElement;
        // System.out.format("Found a process: %s\n", process.getName());

        IDProcess = process.getId();
        for (FlowElement fe : process.getFlowElements()) {
          if (fe instanceof SubProcess) {
            SubProcess sub = (SubProcess) fe;
            // System.out.format("Found a SubProcess: %s\n", sub.getName());
            this.searchSubProcess(sub);
          } else if (fe instanceof IntermediateCatchEvent) {
            IntermediateCatchEvent a = (IntermediateCatchEvent) fe;
            if (a.getName() == null || (a.getName().length() == 0)) {
              num++;

              elementsBPMN.add(fe);
              String name =
                  fe.getName() != null
                      ? fe.getName()
                      : Messages.getString("Generic.LabelEmpty", l); // $NON-NLS-1$
              setElements(fe.getId(), IDProcess, name);
              temp.append(
                  "* name="
                      + name
                      + " ID="
                      + fe.getId() // $NON-NLS-1$ //$NON-NLS-2$
                      + "\n"); //$NON-NLS-1$
            }

          } else if (fe instanceof IntermediateThrowEvent) {
            IntermediateThrowEvent a = (IntermediateThrowEvent) fe;
            if (a.getName() == null || (a.getName().length() == 0)) {
              num++;

              elementsBPMN.add(fe);
              String name =
                  fe.getName() != null
                      ? fe.getName()
                      : Messages.getString("Generic.LabelEmpty", l); // $NON-NLS-1$
              setElements(fe.getId(), IDProcess, name);
              temp.append(
                  "* name="
                      + name
                      + " ID="
                      + fe.getId() // $NON-NLS-1$ //$NON-NLS-2$
                      + "\n"); //$NON-NLS-1$
            }
          }
        }
      }
    }
    if (num > 0) {

      this.Suggestion += Messages.getString("LabelingEvents.SuggestionKO", l); // $NON-NLS-1$
      this.status = false;
    } else {
      this.status = true;
      this.Suggestion += Messages.getString("LabelingEvents.SuggestionOK", l); // $NON-NLS-1$
    }
  }