private PictogramElement addContainerElement(
      BaseElement element, BpmnMemoryModel model, ContainerShape parent) {
    GraphicInfo graphicInfo = model.getBpmnModel().getGraphicInfo(element.getId());
    if (graphicInfo == null) {
      return null;
    }

    final IFeatureProvider featureProvider = getDiagramTypeProvider().getFeatureProvider();

    AddContext context = new AddContext(new AreaContext(), element);
    IAddFeature addFeature = featureProvider.getAddFeature(context);
    context.setNewObject(element);
    context.setSize((int) graphicInfo.getWidth(), (int) graphicInfo.getHeight());
    context.setTargetContainer(parent);

    int x = (int) graphicInfo.getX();
    int y = (int) graphicInfo.getY();

    if (parent instanceof Diagram == false) {
      x = x - parent.getGraphicsAlgorithm().getX();
      y = y - parent.getGraphicsAlgorithm().getY();
    }

    context.setLocation(x, y);

    PictogramElement pictElement = null;
    if (addFeature.canAdd(context)) {
      pictElement = addFeature.add(context);
      featureProvider.link(pictElement, new Object[] {element});
    }

    return pictElement;
  }
  protected void createDataAssociation(
      DataAssociation dataAssociation, boolean incoming, Activity activity) {
    String sourceRef = null;
    String targetRef = null;
    if (incoming) {
      sourceRef = dataAssociation.getSourceRef();
      targetRef = activity.getId();

    } else {
      sourceRef = activity.getId();
      targetRef = dataAssociation.getTargetRef();
    }

    ObjectNode flowNode =
        BpmnJsonConverterUtil.createChildShape(
            dataAssociation.getId(), STENCIL_DATA_ASSOCIATION, 172, 212, 128, 212);
    ArrayNode dockersArrayNode = objectMapper.createArrayNode();
    ObjectNode dockNode = objectMapper.createObjectNode();

    dockNode.put(EDITOR_BOUNDS_X, model.getGraphicInfo(sourceRef).getWidth() / 2.0);
    dockNode.put(EDITOR_BOUNDS_Y, model.getGraphicInfo(sourceRef).getHeight() / 2.0);
    dockersArrayNode.add(dockNode);

    if (model.getFlowLocationGraphicInfo(dataAssociation.getId()).size() > 2) {
      for (int i = 1;
          i < model.getFlowLocationGraphicInfo(dataAssociation.getId()).size() - 1;
          i++) {
        GraphicInfo graphicInfo = model.getFlowLocationGraphicInfo(dataAssociation.getId()).get(i);
        dockNode = objectMapper.createObjectNode();
        dockNode.put(EDITOR_BOUNDS_X, graphicInfo.getX());
        dockNode.put(EDITOR_BOUNDS_Y, graphicInfo.getY());
        dockersArrayNode.add(dockNode);
      }
    }

    dockNode = objectMapper.createObjectNode();
    dockNode.put(EDITOR_BOUNDS_X, model.getGraphicInfo(targetRef).getWidth() / 2.0);
    dockNode.put(EDITOR_BOUNDS_Y, model.getGraphicInfo(targetRef).getHeight() / 2.0);
    dockersArrayNode.add(dockNode);
    flowNode.put("dockers", dockersArrayNode);
    ArrayNode outgoingArrayNode = objectMapper.createArrayNode();
    outgoingArrayNode.add(BpmnJsonConverterUtil.createResourceNode(targetRef));
    flowNode.put("outgoing", outgoingArrayNode);
    flowNode.put("target", BpmnJsonConverterUtil.createResourceNode(targetRef));

    ObjectNode propertiesNode = objectMapper.createObjectNode();
    propertiesNode.put(PROPERTY_OVERRIDE_ID, dataAssociation.getId());

    flowNode.put(EDITOR_SHAPE_PROPERTIES, propertiesNode);
    shapesArrayNode.add(flowNode);
  }
 protected void convertElementToJson(ObjectNode propertiesNode, FlowElement flowElement) {
   SubProcess subProcess = (SubProcess) flowElement;
   propertiesNode.put("activitytype", "Sub-Process");
   propertiesNode.put("subprocesstype", "Embedded");
   ArrayNode subProcessShapesArrayNode = objectMapper.createArrayNode();
   GraphicInfo graphicInfo = model.getGraphicInfo(flowElement.getId());
   processor.processFlowElements(
       subProcess.getFlowElements(),
       model,
       subProcessShapesArrayNode,
       graphicInfo.getX(),
       graphicInfo.getY());
   flowElementNode.put("childShapes", subProcessShapesArrayNode);
 }
Ejemplo n.º 4
0
  public void parse(XMLStreamReader xtr, BpmnModel model) throws Exception {

    String id = xtr.getAttributeValue(null, ATTRIBUTE_DI_BPMNELEMENT);
    while (xtr.hasNext()) {
      xtr.next();
      if (xtr.isStartElement() && ELEMENT_DI_BOUNDS.equalsIgnoreCase(xtr.getLocalName())) {
        GraphicInfo graphicInfo = new GraphicInfo();
        graphicInfo.x = Double.valueOf(xtr.getAttributeValue(null, ATTRIBUTE_DI_X)).intValue();
        graphicInfo.y = Double.valueOf(xtr.getAttributeValue(null, ATTRIBUTE_DI_Y)).intValue();
        FlowElement flowElement = model.getMainProcess().getFlowElement(id);
        if (flowElement instanceof Event) {
          graphicInfo.width = 30;
          graphicInfo.height = 30;
        } else {
          graphicInfo.width =
              Double.valueOf(xtr.getAttributeValue(null, ATTRIBUTE_DI_WIDTH)).intValue();
          graphicInfo.height =
              Double.valueOf(xtr.getAttributeValue(null, ATTRIBUTE_DI_HEIGHT)).intValue();
        }

        model.addGraphicInfo(id, graphicInfo);
        break;
      } else if (xtr.isEndElement() && ELEMENT_DI_SHAPE.equalsIgnoreCase(xtr.getLocalName())) {
        break;
      }
    }
  }
  private void drawArtifacts(
      final Collection<Artifact> artifacts,
      final Map<String, GraphicInfo> locationMap,
      final ContainerShape parent,
      final Process process) {

    final IFeatureProvider featureProvider = getDiagramTypeProvider().getFeatureProvider();

    final List<Artifact> artifactsWithoutDI = new ArrayList<Artifact>();
    for (final Artifact artifact : artifacts) {

      if (artifact instanceof Association) {
        continue;
      }

      final AddContext context = new AddContext(new AreaContext(), artifact);
      final IAddFeature addFeature = featureProvider.getAddFeature(context);

      if (addFeature == null) {
        System.out.println("Element not supported: " + artifact);
        return;
      }

      final GraphicInfo gi = locationMap.get(artifact.getId());
      if (gi == null) {
        artifactsWithoutDI.add(artifact);
      } else {
        context.setNewObject(artifact);
        context.setSize((int) gi.getWidth(), (int) gi.getHeight());

        ContainerShape parentContainer = null;
        if (parent instanceof Diagram) {
          parentContainer = getParentContainer(artifact.getId(), process, (Diagram) parent);
        } else {
          parentContainer = parent;
        }

        context.setTargetContainer(parentContainer);
        if (parentContainer instanceof Diagram) {
          context.setLocation((int) gi.getX(), (int) gi.getY());
        } else {
          final Point location = getLocation(parentContainer);

          context.setLocation((int) gi.getX() - location.x, (int) gi.getY() - location.y);
        }

        if (addFeature.canAdd(context)) {
          final PictogramElement newContainer = addFeature.add(context);
          featureProvider.link(newContainer, new Object[] {artifact});
        }
      }
    }

    for (final Artifact artifact : artifactsWithoutDI) {
      artifacts.remove(artifact);
    }
  }
Ejemplo n.º 6
0
  public void parse(XMLStreamReader xtr, BpmnModel model) throws Exception {

    String id = xtr.getAttributeValue(null, ATTRIBUTE_DI_BPMNELEMENT);
    GraphicInfo graphicInfo = new GraphicInfo();
    BpmnXMLUtil.addXMLLocation(graphicInfo, xtr);
    while (xtr.hasNext()) {
      xtr.next();
      if (xtr.isStartElement() && ELEMENT_DI_BOUNDS.equalsIgnoreCase(xtr.getLocalName())) {
        graphicInfo.setX(Double.valueOf(xtr.getAttributeValue(null, ATTRIBUTE_DI_X)).intValue());
        graphicInfo.setY(Double.valueOf(xtr.getAttributeValue(null, ATTRIBUTE_DI_Y)).intValue());
        graphicInfo.setWidth(
            Double.valueOf(xtr.getAttributeValue(null, ATTRIBUTE_DI_WIDTH)).intValue());
        graphicInfo.setHeight(
            Double.valueOf(xtr.getAttributeValue(null, ATTRIBUTE_DI_HEIGHT)).intValue());

        String strIsExpanded = xtr.getAttributeValue(null, ATTRIBUTE_DI_IS_EXPANDED);
        if ("true".equalsIgnoreCase(strIsExpanded)) {
          graphicInfo.setExpanded(true);
        }

        model.addGraphicInfo(id, graphicInfo);
        break;
      } else if (xtr.isEndElement() && ELEMENT_DI_SHAPE.equalsIgnoreCase(xtr.getLocalName())) {
        break;
      }
    }
  }
Ejemplo n.º 7
0
 public void createBPMNEdge(String key, List<GraphicInfo> graphicList) {
   FlowElement flowElement = bpmnModel.getFlowElement(key);
   if (flowElement != null && sequenceFlows.containsKey(key)) {
     TransitionImpl sequenceFlow = sequenceFlows.get(key);
     List<Integer> waypoints = new ArrayList<Integer>();
     for (GraphicInfo waypointInfo : graphicList) {
       waypoints.add((int) waypointInfo.getX());
       waypoints.add((int) waypointInfo.getY());
     }
     sequenceFlow.setWaypoints(waypoints);
   } else if (bpmnModel.getArtifact(key) != null) {
     // it's an association, so nothing to do
   } else {
     GraphicInfo graphicInfo = null;
     if (graphicList != null && graphicList.size() > 0) {
       graphicInfo = graphicList.get(0);
     } else {
       graphicInfo = new GraphicInfo();
     }
     bpmnModel.addProblem(
         "Invalid reference in 'bpmnElement' attribute, sequenceFlow " + key + " not found",
         graphicInfo);
   }
 }
  public void convertToJson(
      BaseElement baseElement,
      ActivityProcessor processor,
      BpmnModel model,
      FlowElementsContainer container,
      ArrayNode shapesArrayNode,
      double subProcessX,
      double subProcessY) {

    this.model = model;
    this.processor = processor;
    this.subProcessX = subProcessX;
    this.subProcessY = subProcessY;
    this.shapesArrayNode = shapesArrayNode;
    GraphicInfo graphicInfo = model.getGraphicInfo(baseElement.getId());

    String stencilId = null;
    if (baseElement instanceof ServiceTask) {
      ServiceTask serviceTask = (ServiceTask) baseElement;
      if ("mail".equalsIgnoreCase(serviceTask.getType())) {
        stencilId = STENCIL_TASK_MAIL;
      } else if ("camel".equalsIgnoreCase(serviceTask.getType())) {
        stencilId = STENCIL_TASK_CAMEL;
      } else if ("mule".equalsIgnoreCase(serviceTask.getType())) {
        stencilId = STENCIL_TASK_MULE;
      } else {
        stencilId = getStencilId(baseElement);
      }
    } else {
      stencilId = getStencilId(baseElement);
    }

    flowElementNode =
        BpmnJsonConverterUtil.createChildShape(
            baseElement.getId(),
            stencilId,
            graphicInfo.getX() - subProcessX + graphicInfo.getWidth(),
            graphicInfo.getY() - subProcessY + graphicInfo.getHeight(),
            graphicInfo.getX() - subProcessX,
            graphicInfo.getY() - subProcessY);
    shapesArrayNode.add(flowElementNode);
    ObjectNode propertiesNode = objectMapper.createObjectNode();
    propertiesNode.put(PROPERTY_OVERRIDE_ID, baseElement.getId());

    if (baseElement instanceof FlowElement) {
      FlowElement flowElement = (FlowElement) baseElement;
      if (StringUtils.isNotEmpty(flowElement.getName())) {
        propertiesNode.put(PROPERTY_NAME, flowElement.getName());
      }

      if (StringUtils.isNotEmpty(flowElement.getDocumentation())) {
        propertiesNode.put(PROPERTY_DOCUMENTATION, flowElement.getDocumentation());
      }
    }

    convertElementToJson(propertiesNode, baseElement);

    flowElementNode.put(EDITOR_SHAPE_PROPERTIES, propertiesNode);
    ArrayNode outgoingArrayNode = objectMapper.createArrayNode();

    if (baseElement instanceof FlowNode) {
      FlowNode flowNode = (FlowNode) baseElement;
      for (SequenceFlow sequenceFlow : flowNode.getOutgoingFlows()) {
        outgoingArrayNode.add(BpmnJsonConverterUtil.createResourceNode(sequenceFlow.getId()));
      }

      for (MessageFlow messageFlow : model.getMessageFlows().values()) {
        if (messageFlow.getSourceRef().equals(flowNode.getId())) {
          outgoingArrayNode.add(BpmnJsonConverterUtil.createResourceNode(messageFlow.getId()));
        }
      }
    }

    if (baseElement instanceof Activity) {

      Activity activity = (Activity) baseElement;
      for (BoundaryEvent boundaryEvent : activity.getBoundaryEvents()) {
        outgoingArrayNode.add(BpmnJsonConverterUtil.createResourceNode(boundaryEvent.getId()));
      }

      propertiesNode.put(PROPERTY_ASYNCHRONOUS, activity.isAsynchronous());
      propertiesNode.put(PROPERTY_EXCLUSIVE, !activity.isNotExclusive());

      if (activity.getLoopCharacteristics() != null) {
        MultiInstanceLoopCharacteristics loopDef = activity.getLoopCharacteristics();
        if (StringUtils.isNotEmpty(loopDef.getLoopCardinality())
            || StringUtils.isNotEmpty(loopDef.getInputDataItem())
            || StringUtils.isNotEmpty(loopDef.getCompletionCondition())) {

          if (loopDef.isSequential() == false) {
            propertiesNode.put(PROPERTY_MULTIINSTANCE_TYPE, "Parallel");
          } else {
            propertiesNode.put(PROPERTY_MULTIINSTANCE_TYPE, "Sequential");
          }

          if (StringUtils.isNotEmpty(loopDef.getLoopCardinality())) {
            propertiesNode.put(PROPERTY_MULTIINSTANCE_CARDINALITY, loopDef.getLoopCardinality());
          }
          if (StringUtils.isNotEmpty(loopDef.getInputDataItem())) {
            propertiesNode.put(PROPERTY_MULTIINSTANCE_COLLECTION, loopDef.getInputDataItem());
          }
          if (StringUtils.isNotEmpty(loopDef.getElementVariable())) {
            propertiesNode.put(PROPERTY_MULTIINSTANCE_VARIABLE, loopDef.getElementVariable());
          }
          if (StringUtils.isNotEmpty(loopDef.getCompletionCondition())) {
            propertiesNode.put(PROPERTY_MULTIINSTANCE_CONDITION, loopDef.getCompletionCondition());
          }
        }
      }

      if (activity instanceof UserTask) {
        BpmnJsonConverterUtil.convertListenersToJson(
            ((UserTask) activity).getTaskListeners(), false, propertiesNode);
      }

      BpmnJsonConverterUtil.convertListenersToJson(
          activity.getExecutionListeners(), true, propertiesNode);

      if (CollectionUtils.isNotEmpty(activity.getDataInputAssociations())) {
        for (DataAssociation dataAssociation : activity.getDataInputAssociations()) {
          if (model.getFlowElement(dataAssociation.getSourceRef()) != null) {
            createDataAssociation(dataAssociation, true, activity);
          }
        }
      }

      if (CollectionUtils.isNotEmpty(activity.getDataOutputAssociations())) {
        for (DataAssociation dataAssociation : activity.getDataOutputAssociations()) {
          if (model.getFlowElement(dataAssociation.getTargetRef()) != null) {
            createDataAssociation(dataAssociation, false, activity);
            outgoingArrayNode.add(
                BpmnJsonConverterUtil.createResourceNode(dataAssociation.getId()));
          }
        }
      }
    }

    for (Artifact artifact : container.getArtifacts()) {
      if (artifact instanceof Association) {
        Association association = (Association) artifact;
        if (StringUtils.isNotEmpty(association.getSourceRef())
            && association.getSourceRef().equals(baseElement.getId())) {
          outgoingArrayNode.add(BpmnJsonConverterUtil.createResourceNode(association.getId()));
        }
      }
    }

    if (baseElement instanceof DataStoreReference) {
      for (Process process : model.getProcesses()) {
        processDataStoreReferences(process, baseElement.getId(), outgoingArrayNode);
      }
    }

    flowElementNode.put("outgoing", outgoingArrayNode);
  }
  private void drawFlowElements(
      Collection<FlowElement> elementList,
      Map<String, GraphicInfo> locationMap,
      ContainerShape parentShape,
      Process process) {

    final IFeatureProvider featureProvider = getDiagramTypeProvider().getFeatureProvider();

    List<FlowElement> noDIList = new ArrayList<FlowElement>();
    for (FlowElement flowElement : elementList) {

      if (flowElement instanceof SequenceFlow) {
        continue;
      }

      AddContext context = new AddContext(new AreaContext(), flowElement);
      IAddFeature addFeature = featureProvider.getAddFeature(context);

      if (addFeature == null) {
        System.out.println("Element not supported: " + flowElement);
        return;
      }

      GraphicInfo graphicInfo = locationMap.get(flowElement.getId());
      if (graphicInfo == null) {

        noDIList.add(flowElement);

      } else {

        context.setNewObject(flowElement);
        context.setSize((int) graphicInfo.getWidth(), (int) graphicInfo.getHeight());

        ContainerShape parentContainer = null;
        if (parentShape instanceof Diagram) {
          parentContainer = getParentContainer(flowElement.getId(), process, (Diagram) parentShape);
        } else {
          parentContainer = parentShape;
        }

        context.setTargetContainer(parentContainer);
        if (parentContainer instanceof Diagram == false) {
          Point location = getLocation(parentContainer);
          context.setLocation(
              (int) graphicInfo.getX() - location.x, (int) graphicInfo.getY() - location.y);
        } else {
          context.setLocation((int) graphicInfo.getX(), (int) graphicInfo.getY());
        }

        if (flowElement instanceof ServiceTask) {

          ServiceTask serviceTask = (ServiceTask) flowElement;

          if (serviceTask.isExtended()) {

            CustomServiceTask targetTask = findCustomServiceTask(serviceTask);

            if (targetTask != null) {

              for (FieldExtension field : serviceTask.getFieldExtensions()) {
                CustomProperty customFieldProperty = new CustomProperty();
                customFieldProperty.setName(field.getFieldName());
                if (StringUtils.isNotEmpty(field.getExpression())) {
                  customFieldProperty.setSimpleValue(field.getExpression());
                } else {
                  customFieldProperty.setSimpleValue(field.getStringValue());
                }
                serviceTask.getCustomProperties().add(customFieldProperty);
              }

              serviceTask.getFieldExtensions().clear();
            }
          }
        }

        if (flowElement instanceof BoundaryEvent) {
          BoundaryEvent boundaryEvent = (BoundaryEvent) flowElement;
          if (boundaryEvent.getAttachedToRef() != null) {
            ContainerShape container =
                (ContainerShape)
                    featureProvider.getPictogramElementForBusinessObject(
                        boundaryEvent.getAttachedToRef());

            if (container != null) {
              AddContext boundaryContext = new AddContext(new AreaContext(), boundaryEvent);
              boundaryContext.setTargetContainer(container);
              Point location = getLocation(container);
              boundaryContext.setLocation(
                  (int) graphicInfo.getX() - location.x, (int) graphicInfo.getY() - location.y);

              if (addFeature.canAdd(boundaryContext)) {
                PictogramElement newBoundaryContainer = addFeature.add(boundaryContext);
                // featureProvider.link(newBoundaryContainer, new Object[] { boundaryEvent });
              }
            }
          }
        } else if (addFeature.canAdd(context)) {
          PictogramElement newContainer = addFeature.add(context);
          featureProvider.link(newContainer, new Object[] {flowElement});

          if (flowElement instanceof SubProcess) {
            drawFlowElements(
                ((SubProcess) flowElement).getFlowElements(),
                locationMap,
                (ContainerShape) newContainer,
                process);
          }
        }
      }
    }

    for (FlowElement flowElement : noDIList) {
      if (flowElement instanceof BoundaryEvent) {
        ((BoundaryEvent) flowElement).getAttachedToRef().getBoundaryEvents().remove(flowElement);
      } else {
        elementList.remove(flowElement);
      }
    }
  }
  protected void addProcessImage() {
    ProcessDefinitionEntity processDefinitionEntity =
        (ProcessDefinitionEntity)
            ((RepositoryServiceImpl) repositoryService)
                .getDeployedProcessDefinition(processDefinition.getId());

    // Only show when graphical notation is defined
    if (processDefinitionEntity != null) {

      boolean didDrawImage = false;

      if (ExplorerApp.get().isUseJavascriptDiagram()) {
        try {

          final InputStream definitionStream =
              repositoryService.getResourceAsStream(
                  processDefinition.getDeploymentId(), processDefinition.getResourceName());
          XMLInputFactory xif = XMLInputFactory.newInstance();
          XMLStreamReader xtr = xif.createXMLStreamReader(definitionStream);
          BpmnModel bpmnModel = new BpmnXMLConverter().convertToBpmnModel(xtr);

          if (bpmnModel.getFlowLocationMap().size() > 0) {

            int maxX = 0;
            int maxY = 0;
            for (String key : bpmnModel.getLocationMap().keySet()) {
              GraphicInfo graphicInfo = bpmnModel.getGraphicInfo(key);
              double elementX = graphicInfo.getX() + graphicInfo.getWidth();
              if (maxX < elementX) {
                maxX = (int) elementX;
              }
              double elementY = graphicInfo.getY() + graphicInfo.getHeight();
              if (maxY < elementY) {
                maxY = (int) elementY;
              }
            }

            Panel imagePanel = new Panel(); // using panel for scrollbars
            imagePanel.addStyleName(Reindeer.PANEL_LIGHT);
            imagePanel.setWidth(100, UNITS_PERCENTAGE);
            imagePanel.setHeight(100, UNITS_PERCENTAGE);
            URL explorerURL = ExplorerApp.get().getURL();
            URL url =
                new URL(
                    explorerURL.getProtocol(),
                    explorerURL.getHost(),
                    explorerURL.getPort(),
                    explorerURL.getPath().replace("/ui", "")
                        + "diagram-viewer/index.html?processDefinitionId="
                        + processDefinition.getId()
                        + "&processInstanceId="
                        + processInstance.getId());
            Embedded browserPanel = new Embedded("", new ExternalResource(url));
            browserPanel.setType(Embedded.TYPE_BROWSER);
            browserPanel.setWidth(maxX + 350 + "px");
            browserPanel.setHeight(maxY + 220 + "px");

            HorizontalLayout panelLayoutT = new HorizontalLayout();
            panelLayoutT.setSizeUndefined();
            imagePanel.setContent(panelLayoutT);
            imagePanel.addComponent(browserPanel);

            panelLayout.addComponent(imagePanel);

            didDrawImage = true;
          }

        } catch (Exception e) {
          LOGGER.error("Error loading process diagram component", e);
        }
      }

      if (didDrawImage == false && processDefinitionEntity.isGraphicalNotationDefined()) {

        StreamResource diagram =
            new ProcessDefinitionImageStreamResourceBuilder()
                .buildStreamResource(processInstance, repositoryService, runtimeService);

        if (diagram != null) {
          Label header = new Label(i18nManager.getMessage(Messages.PROCESS_HEADER_DIAGRAM));
          header.addStyleName(ExplorerLayout.STYLE_H3);
          header.addStyleName(ExplorerLayout.STYLE_DETAIL_BLOCK);
          header.addStyleName(ExplorerLayout.STYLE_NO_LINE);
          panelLayout.addComponent(header);

          Embedded embedded = new Embedded(null, diagram);
          embedded.setType(Embedded.TYPE_IMAGE);
          embedded.setSizeUndefined();

          Panel imagePanel = new Panel(); // using panel for scrollbars
          imagePanel.setScrollable(true);
          imagePanel.addStyleName(Reindeer.PANEL_LIGHT);
          imagePanel.setWidth(100, UNITS_PERCENTAGE);
          imagePanel.setHeight(100, UNITS_PERCENTAGE);

          HorizontalLayout panelLayoutT = new HorizontalLayout();
          panelLayoutT.setSizeUndefined();
          imagePanel.setContent(panelLayoutT);
          imagePanel.addComponent(embedded);

          panelLayout.addComponent(imagePanel);
        }
      }
    }
  }
  protected void drawArtifacts(
      final FlowElementsContainer container,
      final Map<String, GraphicInfo> locationMap,
      final ContainerShape parent,
      final Process process) {

    final IFeatureProvider featureProvider = getDiagramTypeProvider().getFeatureProvider();

    final List<Artifact> artifactsWithoutDI = new ArrayList<Artifact>();
    for (final Artifact artifact : container.getArtifacts()) {

      if (artifact instanceof Association) {
        continue;
      }

      final AddContext context = new AddContext(new AreaContext(), artifact);
      final IAddFeature addFeature = featureProvider.getAddFeature(context);

      if (addFeature == null) {
        System.out.println("Element not supported: " + artifact);
        return;
      }

      final GraphicInfo gi = locationMap.get(artifact.getId());
      if (gi == null) {
        artifactsWithoutDI.add(artifact);
      } else {
        context.setNewObject(artifact);
        context.setSize((int) gi.getWidth(), (int) gi.getHeight());

        ContainerShape parentContainer = null;
        if (parent instanceof Diagram) {
          FlowElement connectingElement = null;
          for (final Artifact associationArtifact : container.getArtifacts()) {
            if (associationArtifact instanceof Association) {
              Association association = (Association) associationArtifact;

              if (association.getSourceRef().equals(artifact.getId())) {
                connectingElement = container.getFlowElement(association.getTargetRef());

              } else if (association.getTargetRef().equals(artifact.getId())) {
                connectingElement = container.getFlowElement(association.getSourceRef());
              }
            }
          }

          if (connectingElement != null) {
            parentContainer =
                getParentContainer(connectingElement.getId(), process, (Diagram) parent);
          } else {
            parentContainer = parent;
          }
        } else {
          parentContainer = parent;
        }

        context.setTargetContainer(parentContainer);
        if (parentContainer instanceof Diagram) {
          context.setLocation((int) gi.getX(), (int) gi.getY());
        } else {
          final Point location = getLocation(parentContainer);

          context.setLocation((int) gi.getX() - location.x, (int) gi.getY() - location.y);
        }

        if (addFeature.canAdd(context)) {
          final PictogramElement newContainer = addFeature.add(context);
          featureProvider.link(newContainer, new Object[] {artifact});
        }
      }
    }

    for (final Artifact artifact : artifactsWithoutDI) {
      container.getArtifacts().remove(artifact);
    }

    for (FlowElement flowElement : container.getFlowElements()) {
      if (flowElement instanceof SubProcess) {
        ContainerShape subProcessShape =
            (ContainerShape) featureProvider.getPictogramElementForBusinessObject(flowElement);
        drawArtifacts((SubProcess) flowElement, locationMap, subProcessShape, process);
      }
    }
  }
  @SuppressWarnings({"rawtypes", "unchecked"})
  protected void drawFlowElements(
      Collection<FlowElement> elementList,
      Map<String, GraphicInfo> locationMap,
      ContainerShape parentShape,
      Process process) {

    final IFeatureProvider featureProvider = getDiagramTypeProvider().getFeatureProvider();

    List<FlowElement> noDIList = new ArrayList<FlowElement>();
    for (FlowElement flowElement : elementList) {

      if (flowElement instanceof SequenceFlow) {
        continue;
      }

      AddContext context = new AddContext(new AreaContext(), flowElement);
      IAddFeature addFeature = featureProvider.getAddFeature(context);

      if (addFeature == null) {
        System.out.println("Element not supported: " + flowElement);
        return;
      }

      GraphicInfo graphicInfo = locationMap.get(flowElement.getId());
      if (graphicInfo == null) {

        noDIList.add(flowElement);

      } else {

        context.setNewObject(flowElement);
        context.setSize((int) graphicInfo.getWidth(), (int) graphicInfo.getHeight());
        ContainerShape parentContainer = null;
        if (parentShape instanceof Diagram) {
          parentContainer = getParentContainer(flowElement.getId(), process, (Diagram) parentShape);
        } else {
          parentContainer = parentShape;
        }

        context.setTargetContainer(parentContainer);
        if (parentContainer instanceof Diagram == false) {
          Point location = getLocation(parentContainer);
          context.setLocation(
              (int) graphicInfo.getX() - location.x, (int) graphicInfo.getY() - location.y);
        } else {
          context.setLocation((int) graphicInfo.getX(), (int) graphicInfo.getY());
        }

        if (flowElement instanceof ServiceTask) {

          ServiceTask serviceTask = (ServiceTask) flowElement;

          if (serviceTask.isExtended()) {

            CustomServiceTask targetTask = findCustomServiceTask(serviceTask);

            if (targetTask != null) {

              for (FieldExtension field : serviceTask.getFieldExtensions()) {
                CustomProperty customFieldProperty = new CustomProperty();
                customFieldProperty.setName(field.getFieldName());
                if (StringUtils.isNotEmpty(field.getExpression())) {
                  customFieldProperty.setSimpleValue(field.getExpression());
                } else {
                  customFieldProperty.setSimpleValue(field.getStringValue());
                }
                serviceTask.getCustomProperties().add(customFieldProperty);
              }

              serviceTask.getFieldExtensions().clear();
            }
          }

        } else if (flowElement instanceof UserTask) {

          UserTask userTask = (UserTask) flowElement;

          if (userTask.isExtended()) {

            CustomUserTask targetTask = findCustomUserTask(userTask);

            if (targetTask != null) {

              final List<Class<CustomUserTask>> classHierarchy =
                  new ArrayList<Class<CustomUserTask>>();
              final List<String> fieldInfoObjects = new ArrayList<String>();

              Class clazz = targetTask.getClass();
              classHierarchy.add(clazz);

              boolean hierarchyOpen = true;
              while (hierarchyOpen) {
                clazz = clazz.getSuperclass();
                if (CustomUserTask.class.isAssignableFrom(clazz)) {
                  classHierarchy.add(clazz);
                } else {
                  hierarchyOpen = false;
                }
              }

              for (final Class<CustomUserTask> currentClass : classHierarchy) {
                for (final Field field : currentClass.getDeclaredFields()) {
                  if (field.isAnnotationPresent(Property.class)) {
                    fieldInfoObjects.add(field.getName());
                  }
                }
              }

              for (String fieldName : userTask.getExtensionElements().keySet()) {
                if (fieldInfoObjects.contains(fieldName)) {
                  CustomProperty customFieldProperty = new CustomProperty();
                  customFieldProperty.setName(fieldName);
                  customFieldProperty.setSimpleValue(
                      userTask.getExtensionElements().get(fieldName).get(0).getElementText());
                  userTask.getCustomProperties().add(customFieldProperty);
                }
              }

              for (String fieldName : fieldInfoObjects) {
                userTask.getExtensionElements().remove(fieldName);
              }
            }
          }
        }

        if (flowElement instanceof BoundaryEvent) {
          BoundaryEvent boundaryEvent = (BoundaryEvent) flowElement;
          if (boundaryEvent.getAttachedToRef() != null) {
            ContainerShape container =
                (ContainerShape)
                    featureProvider.getPictogramElementForBusinessObject(
                        boundaryEvent.getAttachedToRef());

            if (container != null) {
              AddContext boundaryContext = new AddContext(new AreaContext(), boundaryEvent);
              boundaryContext.setTargetContainer(container);
              Point location = getLocation(container);
              boundaryContext.setLocation(
                  (int) graphicInfo.getX() - location.x, (int) graphicInfo.getY() - location.y);

              if (addFeature.canAdd(boundaryContext)) {
                addFeature.add(boundaryContext);
              }
            }
          }
        } else if (addFeature.canAdd(context)) {
          PictogramElement newContainer = addFeature.add(context);
          featureProvider.link(newContainer, new Object[] {flowElement});

          if (flowElement instanceof SubProcess) {
            drawFlowElements(
                ((SubProcess) flowElement).getFlowElements(),
                locationMap,
                (ContainerShape) newContainer,
                process);
          }
        }
      }
    }

    for (FlowElement flowElement : noDIList) {
      if (flowElement instanceof BoundaryEvent) {
        ((BoundaryEvent) flowElement).getAttachedToRef().getBoundaryEvents().remove(flowElement);
      } else {
        // do not remove Data Objects
        if (flowElement instanceof DataObject == false) {
          elementList.remove(flowElement);
        }
      }
    }
  }
Ejemplo n.º 13
0
 protected void createDIBounds(GraphicInfo graphicInfo, HasDIBounds target) {
   target.setX((int) graphicInfo.getX());
   target.setY((int) graphicInfo.getY());
   target.setWidth((int) graphicInfo.getWidth());
   target.setHeight((int) graphicInfo.getHeight());
 }
Ejemplo n.º 14
0
  public static void writeBPMNDI(BpmnModel model, XMLStreamWriter xtw) throws Exception {
    // BPMN DI information
    xtw.writeStartElement(BPMNDI_PREFIX, ELEMENT_DI_DIAGRAM, BPMNDI_NAMESPACE);

    String processId = null;
    if (model.getPools().size() > 0) {
      processId = "Collaboration";
    } else {
      processId = model.getMainProcess().getId();
    }

    xtw.writeAttribute(ATTRIBUTE_ID, "BPMNDiagram_" + processId);

    xtw.writeStartElement(BPMNDI_PREFIX, ELEMENT_DI_PLANE, BPMNDI_NAMESPACE);
    xtw.writeAttribute(ATTRIBUTE_DI_BPMNELEMENT, processId);
    xtw.writeAttribute(ATTRIBUTE_ID, "BPMNPlane_" + processId);

    // System.out.println("DI EXPORT");
    for (String elementId : model.getLocationMap().keySet()) {

      if (model.getFlowElement(elementId) != null
          || model.getArtifact(elementId) != null
          || model.getPool(elementId) != null
          || model.getLane(elementId) != null) {

        xtw.writeStartElement(BPMNDI_PREFIX, ELEMENT_DI_SHAPE, BPMNDI_NAMESPACE);
        xtw.writeAttribute(ATTRIBUTE_DI_BPMNELEMENT, elementId);
        xtw.writeAttribute(ATTRIBUTE_ID, "BPMNShape_" + elementId);

        GraphicInfo graphicInfo = model.getGraphicInfo(elementId);
        FlowElement flowElement = model.getFlowElement(elementId);
        if (flowElement != null
            && flowElement instanceof SubProcess
            && graphicInfo.getExpanded() != null) {
          xtw.writeAttribute(ATTRIBUTE_DI_IS_EXPANDED, String.valueOf(graphicInfo.getExpanded()));
        }

        if (flowElement == null) {
          boolean foundLane = false;
          for (Pool pool : model.getPools()) {
            if (foundLane) {
              break;
            }
            if (elementId.equals(pool.getId())) {
              if (graphicInfo.getHorizontal() != null) {
                xtw.writeAttribute(
                    ATTRIBUTE_DI_IS_HORIZONTAL, String.valueOf(graphicInfo.getHorizontal()));
              }
            } else {
              Process process = model.getProcess(pool.getId());
              if (process != null) {
                for (Lane lane : process.getLanes()) {
                  if (elementId.equals(lane.getId())) {
                    foundLane = true;
                    if (graphicInfo.getHorizontal() != null) {
                      xtw.writeAttribute(
                          ATTRIBUTE_DI_IS_HORIZONTAL, String.valueOf(graphicInfo.getHorizontal()));
                    }
                    break;
                  }
                }
              }
            }
          }
        }

        xtw.writeStartElement(OMGDC_PREFIX, ELEMENT_DI_BOUNDS, OMGDC_NAMESPACE);
        xtw.writeAttribute(ATTRIBUTE_DI_HEIGHT, "" + graphicInfo.getHeight());
        xtw.writeAttribute(ATTRIBUTE_DI_WIDTH, "" + graphicInfo.getWidth());
        xtw.writeAttribute(ATTRIBUTE_DI_X, "" + graphicInfo.getX());
        xtw.writeAttribute(ATTRIBUTE_DI_Y, "" + graphicInfo.getY());
        xtw.writeEndElement();

        xtw.writeEndElement();
      }
    }

    for (String elementId : model.getFlowLocationMap().keySet()) {

      if (model.getFlowElement(elementId) != null || model.getArtifact(elementId) != null) {

        xtw.writeStartElement(BPMNDI_PREFIX, ELEMENT_DI_EDGE, BPMNDI_NAMESPACE);
        xtw.writeAttribute(ATTRIBUTE_DI_BPMNELEMENT, elementId);
        xtw.writeAttribute(ATTRIBUTE_ID, "BPMNEdge_" + elementId);

        List<GraphicInfo> graphicInfoList = model.getFlowLocationGraphicInfo(elementId);
        for (GraphicInfo graphicInfo : graphicInfoList) {
          xtw.writeStartElement(OMGDI_PREFIX, ELEMENT_DI_WAYPOINT, OMGDI_NAMESPACE);
          xtw.writeAttribute(ATTRIBUTE_DI_X, "" + graphicInfo.getX());
          xtw.writeAttribute(ATTRIBUTE_DI_Y, "" + graphicInfo.getY());
          xtw.writeEndElement();
        }

        GraphicInfo labelGraphicInfo = model.getLabelGraphicInfo(elementId);
        FlowElement flowElement = model.getFlowElement(elementId);
        if (labelGraphicInfo != null
            && flowElement != null
            && StringUtils.isNotEmpty(flowElement.getName())) {
          xtw.writeStartElement(BPMNDI_PREFIX, ELEMENT_DI_LABEL, BPMNDI_NAMESPACE);
          xtw.writeStartElement(OMGDC_PREFIX, ELEMENT_DI_BOUNDS, OMGDC_NAMESPACE);
          xtw.writeAttribute(ATTRIBUTE_DI_HEIGHT, "" + labelGraphicInfo.getHeight());
          xtw.writeAttribute(ATTRIBUTE_DI_WIDTH, "" + labelGraphicInfo.getWidth());
          xtw.writeAttribute(ATTRIBUTE_DI_X, "" + labelGraphicInfo.getX());
          xtw.writeAttribute(ATTRIBUTE_DI_Y, "" + labelGraphicInfo.getY());
          xtw.writeEndElement();
          xtw.writeEndElement();
        }

        xtw.writeEndElement();
      }
    }

    // end BPMN DI elements
    xtw.writeEndElement();
    xtw.writeEndElement();
  }
  public void drawSequenceFlow(
      BufferedImage image, String processDefinitionId, String sequenceFlowId) {
    GetBpmnModelCmd getBpmnModelCmd = new GetBpmnModelCmd(processDefinitionId);
    BpmnModel bpmnModel = getBpmnModelCmd.execute(Context.getCommandContext());

    Graphics2D graphics = image.createGraphics();
    graphics.setPaint(HISTORY_COLOR);
    graphics.setStroke(new BasicStroke(2f));

    try {
      List<GraphicInfo> graphicInfoList = bpmnModel.getFlowLocationGraphicInfo(sequenceFlowId);

      int[] xPoints = new int[graphicInfoList.size()];
      int[] yPoints = new int[graphicInfoList.size()];

      for (int i = 1; i < graphicInfoList.size(); i++) {
        GraphicInfo graphicInfo = graphicInfoList.get(i);
        GraphicInfo previousGraphicInfo = graphicInfoList.get(i - 1);

        if (i == 1) {
          xPoints[0] = (int) previousGraphicInfo.getX() - minX;
          yPoints[0] = (int) previousGraphicInfo.getY() - minY;
        }

        xPoints[i] = (int) graphicInfo.getX() - minX;
        yPoints[i] = (int) graphicInfo.getY() - minY;
      }

      int radius = 15;

      Path2D path = new Path2D.Double();

      for (int i = 0; i < xPoints.length; i++) {
        Integer anchorX = xPoints[i];
        Integer anchorY = yPoints[i];

        double targetX = anchorX;
        double targetY = anchorY;

        double ax = 0;
        double ay = 0;
        double bx = 0;
        double by = 0;
        double zx = 0;
        double zy = 0;

        if ((i > 0) && (i < (xPoints.length - 1))) {
          Integer cx = anchorX;
          Integer cy = anchorY;

          // pivot point of prev line
          double lineLengthY = yPoints[i] - yPoints[i - 1];

          // pivot point of prev line
          double lineLengthX = xPoints[i] - xPoints[i - 1];
          double lineLength = Math.sqrt(Math.pow(lineLengthY, 2) + Math.pow(lineLengthX, 2));
          double dx = (lineLengthX * radius) / lineLength;
          double dy = (lineLengthY * radius) / lineLength;
          targetX = targetX - dx;
          targetY = targetY - dy;

          // isDefaultConditionAvailable = isDefault && i == 1 && lineLength > 10;
          if ((lineLength < (2 * radius)) && (i > 1)) {
            targetX = xPoints[i] - (lineLengthX / 2);
            targetY = yPoints[i] - (lineLengthY / 2);
          }

          // pivot point of next line
          lineLengthY = yPoints[i + 1] - yPoints[i];
          lineLengthX = xPoints[i + 1] - xPoints[i];
          lineLength = Math.sqrt(Math.pow(lineLengthY, 2) + Math.pow(lineLengthX, 2));

          if (lineLength < radius) {
            lineLength = radius;
          }

          dx = (lineLengthX * radius) / lineLength;
          dy = (lineLengthY * radius) / lineLength;

          double nextSrcX = xPoints[i] + dx;
          double nextSrcY = yPoints[i] + dy;

          if ((lineLength < (2 * radius)) && (i < (xPoints.length - 2))) {
            nextSrcX = xPoints[i] + (lineLengthX / 2);
            nextSrcY = yPoints[i] + (lineLengthY / 2);
          }

          double dx0 = (cx - targetX) / 3;
          double dy0 = (cy - targetY) / 3;
          ax = cx - dx0;
          ay = cy - dy0;

          double dx1 = (cx - nextSrcX) / 3;
          double dy1 = (cy - nextSrcY) / 3;
          bx = cx - dx1;
          by = cy - dy1;

          zx = nextSrcX;
          zy = nextSrcY;
        }

        if (i == 0) {
          path.moveTo(targetX, targetY);
        } else {
          path.lineTo(targetX, targetY);
        }

        if ((i > 0) && (i < (xPoints.length - 1))) {
          // add curve
          path.curveTo(ax, ay, bx, by, zx, zy);
        }
      }

      graphics.draw(path);

      // draw arrow
      Line2D.Double line =
          new Line2D.Double(
              xPoints[xPoints.length - 2],
              yPoints[xPoints.length - 2],
              xPoints[xPoints.length - 1],
              yPoints[xPoints.length - 1]);

      int ARROW_WIDTH = 5;
      int doubleArrowWidth = 2 * ARROW_WIDTH;
      Polygon arrowHead = new Polygon();
      arrowHead.addPoint(0, 0);
      arrowHead.addPoint(-ARROW_WIDTH, -doubleArrowWidth);
      arrowHead.addPoint(ARROW_WIDTH, -doubleArrowWidth);

      AffineTransform transformation = new AffineTransform();
      transformation.setToIdentity();

      double angle = Math.atan2(line.y2 - line.y1, line.x2 - line.x1);
      transformation.translate(line.x2, line.y2);
      transformation.rotate((angle - (Math.PI / 2d)));

      AffineTransform originalTransformation = graphics.getTransform();
      graphics.setTransform(transformation);
      graphics.fill(arrowHead);
      graphics.setTransform(originalTransformation);
    } finally {
      graphics.dispose();
    }
  }
  protected Point getMinXAndMinY(BpmnModel bpmnModel) {
    // We need to calculate maximum values to know how big the image will be in its entirety
    double theMinX = java.lang.Double.MAX_VALUE;
    double theMaxX = 0;
    double theMinY = java.lang.Double.MAX_VALUE;
    double theMaxY = 0;

    for (Pool pool : bpmnModel.getPools()) {
      GraphicInfo graphicInfo = bpmnModel.getGraphicInfo(pool.getId());
      theMinX = graphicInfo.getX();
      theMaxX = graphicInfo.getX() + graphicInfo.getWidth();
      theMinY = graphicInfo.getY();
      theMaxY = graphicInfo.getY() + graphicInfo.getHeight();
    }

    List<FlowNode> flowNodes = gatherAllFlowNodes(bpmnModel);

    for (FlowNode flowNode : flowNodes) {
      GraphicInfo flowNodeGraphicInfo = bpmnModel.getGraphicInfo(flowNode.getId());

      // width
      if ((flowNodeGraphicInfo.getX() + flowNodeGraphicInfo.getWidth()) > theMaxX) {
        theMaxX = flowNodeGraphicInfo.getX() + flowNodeGraphicInfo.getWidth();
      }

      if (flowNodeGraphicInfo.getX() < theMinX) {
        theMinX = flowNodeGraphicInfo.getX();
      }

      // height
      if ((flowNodeGraphicInfo.getY() + flowNodeGraphicInfo.getHeight()) > theMaxY) {
        theMaxY = flowNodeGraphicInfo.getY() + flowNodeGraphicInfo.getHeight();
      }

      if (flowNodeGraphicInfo.getY() < theMinY) {
        theMinY = flowNodeGraphicInfo.getY();
      }

      for (SequenceFlow sequenceFlow : flowNode.getOutgoingFlows()) {
        List<GraphicInfo> graphicInfoList =
            bpmnModel.getFlowLocationGraphicInfo(sequenceFlow.getId());

        for (GraphicInfo graphicInfo : graphicInfoList) {
          // width
          if (graphicInfo.getX() > theMaxX) {
            theMaxX = graphicInfo.getX();
          }

          if (graphicInfo.getX() < theMinX) {
            theMinX = graphicInfo.getX();
          }

          // height
          if (graphicInfo.getY() > theMaxY) {
            theMaxY = graphicInfo.getY();
          }

          if (graphicInfo.getY() < theMinY) {
            theMinY = graphicInfo.getY();
          }
        }
      }
    }

    List<Artifact> artifacts = gatherAllArtifacts(bpmnModel);

    for (Artifact artifact : artifacts) {
      GraphicInfo artifactGraphicInfo = bpmnModel.getGraphicInfo(artifact.getId());

      if (artifactGraphicInfo != null) {
        // width
        if ((artifactGraphicInfo.getX() + artifactGraphicInfo.getWidth()) > theMaxX) {
          theMaxX = artifactGraphicInfo.getX() + artifactGraphicInfo.getWidth();
        }

        if (artifactGraphicInfo.getX() < theMinX) {
          theMinX = artifactGraphicInfo.getX();
        }

        // height
        if ((artifactGraphicInfo.getY() + artifactGraphicInfo.getHeight()) > theMaxY) {
          theMaxY = artifactGraphicInfo.getY() + artifactGraphicInfo.getHeight();
        }

        if (artifactGraphicInfo.getY() < theMinY) {
          theMinY = artifactGraphicInfo.getY();
        }
      }

      List<GraphicInfo> graphicInfoList = bpmnModel.getFlowLocationGraphicInfo(artifact.getId());

      if (graphicInfoList != null) {
        for (GraphicInfo graphicInfo : graphicInfoList) {
          // width
          if (graphicInfo.getX() > theMaxX) {
            theMaxX = graphicInfo.getX();
          }

          if (graphicInfo.getX() < theMinX) {
            theMinX = graphicInfo.getX();
          }

          // height
          if (graphicInfo.getY() > theMaxY) {
            theMaxY = graphicInfo.getY();
          }

          if (graphicInfo.getY() < theMinY) {
            theMinY = graphicInfo.getY();
          }
        }
      }
    }

    int nrOfLanes = 0;

    for (org.activiti.bpmn.model.Process process : bpmnModel.getProcesses()) {
      for (Lane l : process.getLanes()) {
        nrOfLanes++;

        GraphicInfo graphicInfo = bpmnModel.getGraphicInfo(l.getId());

        // // width
        if ((graphicInfo.getX() + graphicInfo.getWidth()) > theMaxX) {
          theMaxX = graphicInfo.getX() + graphicInfo.getWidth();
        }

        if (graphicInfo.getX() < theMinX) {
          theMinX = graphicInfo.getX();
        }

        // height
        if ((graphicInfo.getY() + graphicInfo.getHeight()) > theMaxY) {
          theMaxY = graphicInfo.getY() + graphicInfo.getHeight();
        }

        if (graphicInfo.getY() < theMinY) {
          theMinY = graphicInfo.getY();
        }
      }
    }

    // Special case, see http://jira.codehaus.org/browse/ACT-1431
    if ((flowNodes.size() == 0) && (bpmnModel.getPools().size() == 0) && (nrOfLanes == 0)) {
      // Nothing to show
      theMinX = 0;
      theMinY = 0;
    }

    return new Point((int) theMinX, (int) theMinY);
  }