private CanonicalProcessType buildCPF() {
    CanonicalProcessType cpf = new CanonicalProcessType();

    NetType net = new NetType();

    EventType event = new EventType();
    event.setId("1");
    event.setOriginalID("1");
    event.setName("event");

    TaskType task = new TaskType();
    task.setId("2");
    task.setOriginalID("2");
    task.setName("task");

    EdgeType edge = new EdgeType();
    edge.setId("3");
    edge.setOriginalID("3");
    edge.setSourceId("1");
    edge.setTargetId("2");

    net.getNode().add(event);
    net.getNode().add(task);
    net.getEdge().add(edge);
    cpf.getNet().add(net);

    return cpf;
  }
  @Test
  public void testSimpleMerge() {
    final NetType rootNet = yawl2Canonical.getCpf().getNet().get(0);
    assertEquals(9, rootNet.getEdge().size());
    assertEquals(8, rootNet.getNode().size());

    final List<EdgeType> edges = getOutgoingEdges(rootNet, getNodeByName(rootNet, "IN").getId());
    assertEquals(1, edges.size());
    final NodeType routingNode = getNodeByID(rootNet, edges.get(0).getTargetId());
    checkNode(rootNet, routingNode, StateType.class, 1, 3);

    final List<EdgeType> routingEdges = getOutgoingEdges(rootNet, routingNode.getId());
    for (final EdgeType edge : routingEdges) {
      assertNull("No condition after StateNode", edge.getConditionExpr());
    }

    checkNode(rootNet, "A", TaskType.class, 1, 1);
    checkNode(rootNet, "B", TaskType.class, 1, 1);
    final NodeType nodeC = checkNode(rootNet, "C", TaskType.class, 1, 1);

    final List<EdgeType> cEdges = getOutgoingEdges(rootNet, nodeC.getId());
    assertEquals(1, cEdges.size());
    final NodeType joiningNode = getNodeByID(rootNet, cEdges.get(0).getTargetId());
    checkNode(rootNet, joiningNode, XORJoinType.class, 3, 1);

    checkNode(rootNet, "D", TaskType.class, 1, 1);
  }
 /* loop through the list of edges and process each one. */
 private void manipulateEdges(
     CanonicalProcessType cpf, AnnotationsType anf, Map<String, AnnotationData> annotations) {
   GraphicsType annotation;
   for (NetType net : cpf.getNet()) {
     for (EdgeType edge : net.getEdge()) {
       annotation = findGraphicsType(anf, edge.getId());
       if (annotation != null) {
         manipulateEdge(annotation, edge, annotations);
       }
     }
   }
 }
 /* loop through the list of nodes and process each one. */
 private void manipulateShapes(
     CanonicalProcessType cpf, AnnotationsType anf, Map<String, AnnotationData> annotations) {
   GraphicsType annotation;
   for (NetType net : cpf.getNet()) {
     for (NodeType node : net.getNode()) {
       annotation = findGraphicsType(anf, node.getId());
       if (annotation != null) {
         if (node instanceof EventType) {
           manipulateEvent(annotation, node, annotations);
         } else if (node instanceof TaskType) {
           manipulateTask(annotation, node, annotations);
         }
       }
     }
   }
 }
Example #5
0
  /**
   * Construct a BPMN model from a canonical model. In other words, de-canonise a CPF/ANF model into
   * a BPMN one.
   *
   * @param cpf a canonical process model
   * @param anf annotations for the canonical process model
   * @throws CanoniserException if unable to generate BPMN from the given CPF and ANF arguments
   */
  private BpmnDefinitions(final CpfCanonicalProcessType cpf, final AnnotationsType anf)
      throws CanoniserException {
    // We can get by without an ANF parameter, but we definitely need a CPF
    if (cpf == null) {
      throw new CanoniserException("Cannot create BPMN from null CPF");
    }

    Initializer initializer =
        new Initializer(this, cpf, "http://www.apromore.org/bpmn/" + UUID.randomUUID() + "#");

    // Set attributes of the document root
    setExporter(APROMORE_URI);
    setExporterVersion(APROMORE_VERSION);
    setExpressionLanguage(
        CPFSchema.EXPRESSION_LANGUAGE_XPATH); // This is the default, so specifying it is redundant
    setId(null);
    setName(cpf.getName());
    setTargetNamespace(initializer.getTargetNamespace());
    setTypeLanguage(
        CPFSchema.TYPE_LANGUAGE_XSD); // This is the default, so specifying it is redundant

    /* TODO - add as extension attributes
    String author = cpf.getAuthor();
    String creationDate = cpf.getCreationDate();
    String modificationDate = cpf.getModificationDate();
    */

    // Assume there will be pools, all of which belong to a single collaboration
    TCollaboration collaboration = initializer.getFactory().createTCollaboration();
    JAXBElement<TCollaboration> wrapperCollaboration =
        initializer.getFactory().createCollaboration(collaboration);

    // Workaround for the Apromore-core's failure to generate the CPF rootIds attribute
    final List<String> rootIds = cpf.getRootIds();
    final List<String> subnetIds = new ArrayList<String>();
    if (rootIds.size() == 0) {
      cpf.accept(
          new org.apromore.cpf.TraversingVisitor(
              new org.apromore.cpf.DepthFirstTraverserImpl(),
              new org.apromore.cpf.BaseVisitor() {
                @Override
                public void visit(final NetType net) {
                  rootIds.add(net.getId());
                }

                @Override
                public void visit(final TaskType task) {
                  subnetIds.add(task.getSubnetId());
                } // null check not required
              }));
      rootIds.removeAll(subnetIds);
      initializer.warn("Using reconstructed root net list: " + rootIds);
    }

    // Translate CPF Nets as BPMN Processes TODO: Fix
    for (final NetType net : cpf.getNet()) {
      // Only root elements are decanonised here; subnets are dealt with by recursion
      if (!rootIds.contains(net.getId())) {
        continue;
      }

      getRootElement()
          .add(
              initializer
                  .getFactory()
                  .createProcess(new BpmnProcess((CpfNetType) net, initializer, collaboration)));

      /*
      // If we haven't added the collaboration yet and this process is a pool, add the collaboration
      if (!getRootElement().contains(wrapperCollaboration)) {
          getRootElement().add(wrapperCollaboration);
      }
      */
    }

    // pc:variants occurring on the document element of the CPF need to be moved to one of the root
    // elements of the BPMN
    for (org.apromore.cpf.TypeAttribute attribute : cpf.getAttribute()) {
      outer:
      switch (attribute.getName()) {
        case "bpmn_cpf/extensions":
          for (JAXBElement<? extends TRootElement> jaxbRoot : getRootElement()) {
            TRootElement root = jaxbRoot.getValue();
            TExtensionElements extensionElements = root.getExtensionElements();
            if (extensionElements == null) {
              extensionElements = new BpmnObjectFactory().createTExtensionElements();
              root.setExtensionElements(extensionElements);
            }
            assert extensionElements != null;
            assert extensionElements == root.getExtensionElements();

            extensionElements.getAny().add(attribute.getAny());

            break outer;
          }
          throw new CanoniserException(
              "Couldn't find a root element to place the BPMN variants attribute");

        case "BranchID":
        case "BranchName":
        case "RootFragmentId":
        case "InitialFormat":
        case "IntialFormat":
        case "PMVID":
        case "ProcessName":
        case "VersionNumber":
          // recognized, but ignored
          break;

        default:
          throw new CanoniserException(
              "Unsupported extension attribute in CPF: "
                  + attribute.getName()
                  + " value="
                  + attribute.getValue()
                  + " any="
                  + attribute.getAny());
      }
    }

    // Make sure all the deferred fields did eventually get filled in
    initializer.close();

    // Translate any ANF annotations into a BPMNDI diagram element
    if (anf != null) {
      getBPMNDiagram().add(new BpmndiDiagram(anf, initializer));
    }
  }