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.º 2
0
  private void createXML(Artifact artifact, BpmnModel model, XMLStreamWriter xtw) throws Exception {

    Class<? extends BaseBpmnXMLConverter> converter = convertersToXMLMap.get(artifact.getClass());

    if (converter == null) {
      throw new XMLException("No converter for " + artifact.getClass() + " found");
    }

    converter.newInstance().convertToXML(xtw, artifact, model);
  }
  public void convertToBpmnModel(
      JsonNode elementNode,
      JsonNode modelNode,
      ActivityProcessor processor,
      BaseElement parentElement,
      Map<String, JsonNode> shapeMap,
      BpmnModel bpmnModel) {

    this.processor = processor;
    this.model = bpmnModel;

    BaseElement baseElement = convertJsonToElement(elementNode, modelNode, shapeMap);
    baseElement.setId(BpmnJsonConverterUtil.getElementId(elementNode));

    if (baseElement instanceof FlowElement) {
      FlowElement flowElement = (FlowElement) baseElement;
      flowElement.setName(getPropertyValueAsString(PROPERTY_NAME, elementNode));
      flowElement.setDocumentation(getPropertyValueAsString(PROPERTY_DOCUMENTATION, elementNode));

      BpmnJsonConverterUtil.convertJsonToListeners(elementNode, flowElement);

      if (baseElement instanceof Activity) {
        Activity activity = (Activity) baseElement;
        activity.setAsynchronous(getPropertyValueAsBoolean(PROPERTY_ASYNCHRONOUS, elementNode));
        activity.setNotExclusive(!getPropertyValueAsBoolean(PROPERTY_EXCLUSIVE, elementNode));

        String multiInstanceType =
            getPropertyValueAsString(PROPERTY_MULTIINSTANCE_TYPE, elementNode);
        String multiInstanceCardinality =
            getPropertyValueAsString(PROPERTY_MULTIINSTANCE_CARDINALITY, elementNode);
        String multiInstanceCollection =
            getPropertyValueAsString(PROPERTY_MULTIINSTANCE_COLLECTION, elementNode);
        String multiInstanceCondition =
            getPropertyValueAsString(PROPERTY_MULTIINSTANCE_CONDITION, elementNode);

        if (StringUtils.isNotEmpty(multiInstanceType)
            && "none".equalsIgnoreCase(multiInstanceType) == false) {

          String multiInstanceVariable =
              getPropertyValueAsString(PROPERTY_MULTIINSTANCE_VARIABLE, elementNode);

          MultiInstanceLoopCharacteristics multiInstanceObject =
              new MultiInstanceLoopCharacteristics();
          if ("sequential".equalsIgnoreCase(multiInstanceType)) {
            multiInstanceObject.setSequential(true);
          } else {
            multiInstanceObject.setSequential(false);
          }
          multiInstanceObject.setLoopCardinality(multiInstanceCardinality);
          multiInstanceObject.setInputDataItem(multiInstanceCollection);
          multiInstanceObject.setElementVariable(multiInstanceVariable);
          multiInstanceObject.setCompletionCondition(multiInstanceCondition);
          activity.setLoopCharacteristics(multiInstanceObject);
        }

      } else if (baseElement instanceof Gateway) {
        JsonNode flowOrderNode = getProperty(PROPERTY_SEQUENCEFLOW_ORDER, elementNode);
        if (flowOrderNode != null) {
          flowOrderNode = BpmnJsonConverterUtil.validateIfNodeIsTextual(flowOrderNode);
          JsonNode orderArray = flowOrderNode.get("sequenceFlowOrder");
          if (orderArray != null && orderArray.size() > 0) {
            for (JsonNode orderNode : orderArray) {
              ExtensionElement orderElement = new ExtensionElement();
              orderElement.setName("EDITOR_FLOW_ORDER");
              orderElement.setElementText(orderNode.asText());
              flowElement.addExtensionElement(orderElement);
            }
          }
        }
      }
    }

    if (baseElement instanceof FlowElement) {
      FlowElement flowElement = (FlowElement) baseElement;
      if (flowElement instanceof SequenceFlow) {
        ExtensionElement idExtensionElement = new ExtensionElement();
        idExtensionElement.setName("EDITOR_RESOURCEID");
        idExtensionElement.setElementText(elementNode.get(EDITOR_SHAPE_ID).asText());
        flowElement.addExtensionElement(idExtensionElement);
      }

      if (parentElement instanceof Process) {
        ((Process) parentElement).addFlowElement(flowElement);

      } else if (parentElement instanceof SubProcess) {
        ((SubProcess) parentElement).addFlowElement(flowElement);

      } else if (parentElement instanceof Lane) {
        Lane lane = (Lane) parentElement;
        lane.getFlowReferences().add(flowElement.getId());
        lane.getParentProcess().addFlowElement(flowElement);
      }

    } else if (baseElement instanceof Artifact) {
      Artifact artifact = (Artifact) baseElement;
      if (parentElement instanceof Process) {
        ((Process) parentElement).addArtifact(artifact);

      } else if (parentElement instanceof SubProcess) {
        ((SubProcess) parentElement).addArtifact(artifact);

      } else if (parentElement instanceof Lane) {
        Lane lane = (Lane) parentElement;
        lane.getFlowReferences().add(artifact.getId());
        lane.getParentProcess().addArtifact(artifact);
      }
    }
  }
  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);
      }
    }
  }
Ejemplo n.º 5
0
  public void convertToBpmnModel(
      XMLStreamReader xtr,
      BpmnModel model,
      Process activeProcess,
      List<SubProcess> activeSubProcessList)
      throws Exception {

    String elementId = xtr.getAttributeValue(null, ATTRIBUTE_ID);
    String elementName = xtr.getAttributeValue(null, ATTRIBUTE_NAME);
    boolean async = parseAsync(xtr);
    boolean notExclusive = parseNotExclusive(xtr);
    String defaultFlow = xtr.getAttributeValue(null, ATTRIBUTE_DEFAULT);
    boolean isForCompensation = parseForCompensation(xtr);

    BaseElement parsedElement = convertXMLToElement(xtr, model);

    if (parsedElement instanceof Artifact) {
      Artifact currentArtifact = (Artifact) parsedElement;
      currentArtifact.setId(elementId);

      if (isInSubProcess(activeSubProcessList)) {
        final SubProcess currentSubProcess =
            activeSubProcessList.get(activeSubProcessList.size() - 2);
        currentSubProcess.addArtifact(currentArtifact);

      } else {
        activeProcess.addArtifact(currentArtifact);
      }
    }

    if (parsedElement instanceof FlowElement) {

      FlowElement currentFlowElement = (FlowElement) parsedElement;
      currentFlowElement.setId(elementId);
      currentFlowElement.setName(elementName);

      if (currentFlowElement instanceof Activity) {

        Activity activity = (Activity) currentFlowElement;
        activity.setAsynchronous(async);
        activity.setNotExclusive(notExclusive);
        activity.setForCompensation(isForCompensation);
        if (StringUtils.isNotEmpty(defaultFlow)) {
          activity.setDefaultFlow(defaultFlow);
        }
      }

      if (currentFlowElement instanceof Gateway) {
        Gateway gateway = (Gateway) currentFlowElement;
        if (StringUtils.isNotEmpty(defaultFlow)) {
          gateway.setDefaultFlow(defaultFlow);
        }

        gateway.setAsynchronous(async);
        gateway.setNotExclusive(notExclusive);
      }

      if (currentFlowElement instanceof DataObject) {
        if (activeSubProcessList.size() > 0) {
          activeSubProcessList
              .get(activeSubProcessList.size() - 1)
              .getDataObjects()
              .add((ValuedDataObject) parsedElement);
        } else {
          activeProcess.getDataObjects().add((ValuedDataObject) parsedElement);
        }
      }

      if (activeSubProcessList.size() > 0) {
        activeSubProcessList
            .get(activeSubProcessList.size() - 1)
            .addFlowElement(currentFlowElement);
      } else {
        activeProcess.addFlowElement(currentFlowElement);
      }
    }
  }
  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);
  }