org.activiti.bpmn.model.BpmnModel Java Examples

The following examples show how to use org.activiti.bpmn.model.BpmnModel. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AddBpmnModelTest.java    From CrazyWorkflowHandoutsActiviti6 with MIT License 6 votes vote down vote up
public static void main(String[] args) throws Exception {
	// 新建流程引擎
	ProcessEngine engine = ProcessEngines.getDefaultProcessEngine();
	// 存储服务
	RepositoryService repositoryService = engine.getRepositoryService();
	// 新建部署构造器
	DeploymentBuilder deploymentBuilder = repositoryService.createDeployment();
	String resourceName = "My Process";
	BpmnModel bpmnModel = createProcessModel();
	// 发布部署构造器
	deploymentBuilder.addBpmnModel(resourceName, bpmnModel);
	// 发布部署构造器
	deploymentBuilder.deploy();
	// 关闭流程引擎
	engine.close();
}
 
Example #2
Source File: EventSubprocessValidator.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Override
protected void executeValidation(BpmnModel bpmnModel, Process process, List<ValidationError> errors) {
  List<EventSubProcess> eventSubprocesses = process.findFlowElementsOfType(EventSubProcess.class);
  for (EventSubProcess eventSubprocess : eventSubprocesses) {

    List<StartEvent> startEvents = process.findFlowElementsInSubProcessOfType(eventSubprocess, StartEvent.class);
    for (StartEvent startEvent : startEvents) {
      if (startEvent.getEventDefinitions() != null && !startEvent.getEventDefinitions().isEmpty()) {
        EventDefinition eventDefinition = startEvent.getEventDefinitions().get(0);
        if (!(eventDefinition instanceof org.activiti.bpmn.model.ErrorEventDefinition) && !(eventDefinition instanceof MessageEventDefinition) && !(eventDefinition instanceof SignalEventDefinition)) {
          addError(errors, Problems.EVENT_SUBPROCESS_INVALID_START_EVENT_DEFINITION, process, eventSubprocess, "start event of event subprocess must be of type 'error', 'message' or 'signal'");
        }
      }
    }

  }
}
 
Example #3
Source File: SignalValidator.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Override
public void validate(BpmnModel bpmnModel, List<ValidationError> errors) {
  Collection<Signal> signals = bpmnModel.getSignals();
  if (signals != null && !signals.isEmpty()) {

    for (Signal signal : signals) {
      if (StringUtils.isEmpty(signal.getId())) {
        addError(errors, Problems.SIGNAL_MISSING_ID, signal, "Signal must have an id");
      }

      if (StringUtils.isEmpty(signal.getName())) {
        addError(errors, Problems.SIGNAL_MISSING_NAME, signal, "Signal must have a name");
      }

      if (!StringUtils.isEmpty(signal.getName()) && duplicateName(signals, signal.getId(), signal.getName())) {
        addError(errors, Problems.SIGNAL_DUPLICATE_NAME, signal, "Duplicate signal name found");
      }

      if (signal.getScope() != null && !signal.getScope().equals(Signal.SCOPE_GLOBAL) && !signal.getScope().equals(Signal.SCOPE_PROCESS_INSTANCE)) {
        addError(errors, Problems.SIGNAL_INVALID_SCOPE, signal, "Invalid value for 'scope'. Only values 'global' and 'processInstance' are supported");
      }
    }

  }
}
 
Example #4
Source File: DataStoreConverterTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
private void validateModel(BpmnModel model) {
  assertEquals(1, model.getDataStores().size());
  DataStore dataStore = model.getDataStore("DataStore_1");
  assertNotNull(dataStore);
  assertEquals("DataStore_1", dataStore.getId());
  assertEquals("test", dataStore.getDataState());
  assertEquals("Test Database", dataStore.getName());
  assertEquals("test", dataStore.getItemSubjectRef());

  FlowElement refElement = model.getFlowElement("DataStoreReference_1");
  assertNotNull(refElement);
  assertTrue(refElement instanceof DataStoreReference);

  assertEquals(1, model.getPools().size());
  Pool pool = model.getPools().get(0);
  assertEquals("pool1", pool.getId());
}
 
Example #5
Source File: SimpleFlowWorkController.java    From activiti-demo with Apache License 2.0 6 votes vote down vote up
/**
 * 显示图片
 * @return
 */
@RequestMapping(value = "/viewPic.do")
public void viewPic(HttpServletRequest request,
                    HttpServletResponse response,
                    @RequestParam("executionId") String executionId) throws Exception{
    ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().processInstanceId(executionId).singleResult();
    BpmnModel bpmnModel = repositoryService.getBpmnModel(processInstance.getProcessDefinitionId());
    List<String> activeActivityIds = runtimeService.getActiveActivityIds(executionId);

    // 使用spring注入引擎请使用下面的这行代码
    Context.setProcessEngineConfiguration(processEngine.getProcessEngineConfiguration());

    InputStream imageStream = ProcessDiagramGenerator.generateDiagram(bpmnModel, "png", activeActivityIds);

    // 输出资源内容到相应对象
    byte[] b = new byte[1024];
    int len;
    while ((len = imageStream.read(b, 0, 1024)) != -1) {
        response.getOutputStream().write(b, 0, len);
    }
}
 
Example #6
Source File: BoundaryEventXMLConverter.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Override
protected BaseElement convertXMLToElement(XMLStreamReader xtr, BpmnModel model) throws Exception {
  BoundaryEvent boundaryEvent = new BoundaryEvent();
  BpmnXMLUtil.addXMLLocation(boundaryEvent, xtr);
  if (StringUtils.isNotEmpty(xtr.getAttributeValue(null, ATTRIBUTE_BOUNDARY_CANCELACTIVITY))) {
    String cancelActivity = xtr.getAttributeValue(null, ATTRIBUTE_BOUNDARY_CANCELACTIVITY);
    if (ATTRIBUTE_VALUE_FALSE.equalsIgnoreCase(cancelActivity)) {
      boundaryEvent.setCancelActivity(false);
    }
  }
  boundaryEvent.setAttachedToRefId(xtr.getAttributeValue(null, ATTRIBUTE_BOUNDARY_ATTACHEDTOREF));
  parseChildElements(getXMLElementName(), boundaryEvent, model, xtr);

  // Explicitly set cancel activity to false for error boundary events
  if (boundaryEvent.getEventDefinitions().size() == 1) {
    EventDefinition eventDef = boundaryEvent.getEventDefinitions().get(0);

    if (eventDef instanceof ErrorEventDefinition) {
      boundaryEvent.setCancelActivity(false);
    }
  }

  return boundaryEvent;
}
 
Example #7
Source File: BpmnShapeParser.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
public void parse(XMLStreamReader xtr, BpmnModel model) throws Exception {

    String id = xtr.getAttributeValue(null, ATTRIBUTE_DI_BPMNELEMENT);
    GraphicInfo graphicInfo = new GraphicInfo();

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

    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)));
        graphicInfo.setY(Double.valueOf(xtr.getAttributeValue(null, ATTRIBUTE_DI_Y)));
        graphicInfo.setWidth(Double.valueOf(xtr.getAttributeValue(null, ATTRIBUTE_DI_WIDTH)));
        graphicInfo.setHeight(Double.valueOf(xtr.getAttributeValue(null, ATTRIBUTE_DI_HEIGHT)));

        model.addGraphicInfo(id, graphicInfo);
        break;
      } else if (xtr.isEndElement() && ELEMENT_DI_SHAPE.equalsIgnoreCase(xtr.getLocalName())) {
        break;
      }
    }
  }
 
Example #8
Source File: UserTaskXMLConverter.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
protected void writeAdditionalAttributes(BaseElement element, BpmnModel model, XMLStreamWriter xtw) throws Exception {
  UserTask userTask = (UserTask) element;
  writeQualifiedAttribute(ATTRIBUTE_TASK_USER_ASSIGNEE, userTask.getAssignee(), xtw);
  writeQualifiedAttribute(ATTRIBUTE_TASK_USER_OWNER, userTask.getOwner(), xtw);
  writeQualifiedAttribute(ATTRIBUTE_TASK_USER_CANDIDATEUSERS, convertToDelimitedString(userTask.getCandidateUsers()), xtw);
  writeQualifiedAttribute(ATTRIBUTE_TASK_USER_CANDIDATEGROUPS, convertToDelimitedString(userTask.getCandidateGroups()), xtw);
  writeQualifiedAttribute(ATTRIBUTE_TASK_USER_DUEDATE, userTask.getDueDate(), xtw);
  writeQualifiedAttribute(ATTRIBUTE_TASK_USER_BUSINESS_CALENDAR_NAME, userTask.getBusinessCalendarName(), xtw);
  writeQualifiedAttribute(ATTRIBUTE_TASK_USER_CATEGORY, userTask.getCategory(), xtw);
  writeQualifiedAttribute(ATTRIBUTE_FORM_FORMKEY, userTask.getFormKey(), xtw);
  if (userTask.getPriority() != null) {
    writeQualifiedAttribute(ATTRIBUTE_TASK_USER_PRIORITY, userTask.getPriority().toString(), xtw);
  }
  if (StringUtils.isNotEmpty(userTask.getExtensionId())) {
    writeQualifiedAttribute(ATTRIBUTE_TASK_SERVICE_EXTENSIONID, userTask.getExtensionId(), xtw);
  }
  if (userTask.getSkipExpression() != null) {
    writeQualifiedAttribute(ATTRIBUTE_TASK_USER_SKIP_EXPRESSION, userTask.getSkipExpression(), xtw);
  }
  // write custom attributes
  BpmnXMLUtil.writeCustomAttributes(userTask.getAttributes().values(), xtw, defaultElementAttributes, 
      defaultActivityAttributes, defaultUserTaskAttributes);
}
 
Example #9
Source File: CallActivityTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
public void testInstantiateSuspendedProcessByMessage() throws Exception {
  BpmnModel messageTriggeredBpmnModel = loadBPMNModel(MESSAGE_TRIGGERED_PROCESS_RESOURCE);

  Deployment messageTriggeredBpmnDeployment = processEngine.getRepositoryService().createDeployment().name("messageTriggeredProcessDeployment")
      .addBpmnModel("messageTriggered.bpmn20.xml", messageTriggeredBpmnModel).deploy();

  suspendProcessDefinitions(messageTriggeredBpmnDeployment);

  try {
    ProcessInstance childProcessInstance = runtimeService.startProcessInstanceByMessage("TRIGGER_PROCESS_MESSAGE");
    fail("Exception expected");
  } catch (ActivitiException ae) {
    assertTextPresent("Cannot start process instance. Process definition Message Triggered Process", ae.getMessage());
  }

}
 
Example #10
Source File: ActivitiTestCaseProcessValidator.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Override
public List<ValidationError> validate(BpmnModel bpmnModel) {
  List<ValidationError> errorList = new ArrayList<ValidationError>();
  CustomParseValidator customParseValidator = new CustomParseValidator();
 
  for (Process process : bpmnModel.getProcesses()) {
    customParseValidator.executeParse(bpmnModel, process);
  }
 
  for (String errorRef : bpmnModel.getErrors().keySet()) {
    ValidationError error = new ValidationError();
    error.setValidatorSetName("Manual BPMN parse validator");
    error.setProblem(errorRef);
    error.setActivityId(bpmnModel.getErrors().get(errorRef));
    errorList.add(error);
  }
  return errorList;
}
 
Example #11
Source File: TerminateEndEventTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
public void testParseTerminateEndEventDefinitionWithExtensions() {
  org.activiti.engine.repository.Deployment deployment = repositoryService.createDeployment().addClasspathResource("org/activiti5/engine/test/bpmn/event/end/TerminateEndEventTest.parseExtensionElements.bpmn20.xml").deploy();
  ProcessDefinition processDefinitionQuery = repositoryService.createProcessDefinitionQuery().deploymentId(deployment.getId()).singleResult();
  BpmnModel bpmnModel = this.processEngineConfiguration.getProcessDefinitionCache()
      .get(processDefinitionQuery.getId()).getBpmnModel();

  Map<String, List<ExtensionElement>> extensionElements = bpmnModel.getProcesses().get(0)
      .findFlowElementsOfType(EndEvent.class).get(0).getExtensionElements();
  assertThat(extensionElements.size(), is(1));
  List<ExtensionElement> strangeProperties = extensionElements.get("strangeProperty");
  assertThat(strangeProperties.size(), is(1));
  ExtensionElement strangeProperty = strangeProperties.get(0);
  assertThat(strangeProperty.getNamespace(), is("http://activiti.org/bpmn"));
  assertThat(strangeProperty.getElementText(), is("value"));
  assertThat(strangeProperty.getAttributes().size(), is(1));
  ExtensionAttribute id = strangeProperty.getAttributes().get("id").get(0);
  assertThat(id.getName(), is("id"));
  assertThat(id.getValue(), is("strangeId"));


  repositoryService.deleteDeployment(deployment.getId());
}
 
Example #12
Source File: ActivitiTestCaseProcessValidator.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Override
public List<ValidationError> validate(BpmnModel bpmnModel) {
  List<ValidationError> errorList = new ArrayList<ValidationError>();
  CustomParseValidator customParseValidator = new CustomParseValidator();

  for (Process process : bpmnModel.getProcesses()) {
    customParseValidator.executeParse(bpmnModel, process);
  }

  for (String errorRef : bpmnModel.getErrors().keySet()) {
    ValidationError error = new ValidationError();
    error.setValidatorSetName("Manual BPMN parse validator");
    error.setProblem(errorRef);
    error.setActivityId(bpmnModel.getErrors().get(errorRef));
    errorList.add(error);
  }
  return errorList;
}
 
Example #13
Source File: FlowNodeConverterTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Test
public void doubleConversionValidation() throws Exception {
  BpmnModel bpmnModel = readJsonFile();
  validateModel(bpmnModel);
  bpmnModel = convertToJsonAndBack(bpmnModel);
  // System.out.println("xml " + new String(new
  // BpmnXMLConverter().convertToXML(bpmnModel), "utf-8"));
  validateModel(bpmnModel);
}
 
Example #14
Source File: ManualTaskXMLConverter.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Override
protected BaseElement convertXMLToElement(XMLStreamReader xtr, BpmnModel model) throws Exception {
  ManualTask manualTask = new ManualTask();
  BpmnXMLUtil.addXMLLocation(manualTask, xtr);
  parseChildElements(getXMLElementName(), manualTask, model, xtr);
  return manualTask;
}
 
Example #15
Source File: SubProcessMultiDiagramConverterTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Override
protected BpmnModel exportAndReadXMLFile(BpmnModel bpmnModel) throws Exception {
  byte[] xml = new SubprocessXMLConverter().convertToXML(bpmnModel);
  System.out.println("xml " + new String(xml, "UTF-8"));
  XMLInputFactory xif = XMLInputFactory.newInstance();
  InputStreamReader in = new InputStreamReader(new ByteArrayInputStream(xml), "UTF-8");
  XMLStreamReader xtr = xif.createXMLStreamReader(in);
  return new SubprocessXMLConverter().convertToBpmnModel(xtr);
}
 
Example #16
Source File: AbstractActivitiTestCase.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
/**
 * Creates and deploys the one task process. See {@link #createOneTaskTestProcess()}.
 * 
 * @return The process definition id (NOT the process definition key) of deployed one task process.
 */
public String deployOneTaskTestProcess() {
	BpmnModel bpmnModel = createOneTaskTestProcess();
	Deployment deployment = repositoryService.createDeployment()
			.addBpmnModel("oneTasktest.bpmn20.xml", bpmnModel).deploy();
	
	deploymentIdsForAutoCleanup.add(deployment.getId()); // For auto-cleanup
	
	ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery()
			.deploymentId(deployment.getId()).singleResult();
	return processDefinition.getId(); 
}
 
Example #17
Source File: BpmnImageTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
protected void calculateWidthForArtifacts(Collection<Artifact> artifactList, BpmnModel bpmnModel, GraphicInfo diagramInfo) {
    for (Artifact artifact : artifactList) {
    	List<GraphicInfo> graphicInfoList = new ArrayList<GraphicInfo>();
    	if (artifact instanceof Association) {
    		graphicInfoList.addAll(bpmnModel.getFlowLocationGraphicInfo(artifact.getId()));
    	} else {
    		graphicInfoList.add(bpmnModel.getGraphicInfo(artifact.getId()));
    	}
    	
    	processGraphicInfoList(graphicInfoList, diagramInfo);
    }
}
 
Example #18
Source File: CallActivityTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public void testInstantiateSubprocess() throws Exception {
  BpmnModel mainBpmnModel = loadBPMNModel(MAIN_PROCESS_RESOURCE);
  BpmnModel childBpmnModel = loadBPMNModel(CHILD_PROCESS_RESOURCE);

  Deployment childDeployment = processEngine.getRepositoryService()
      .createDeployment()
      .name("childProcessDeployment")
      .addBpmnModel("childProcess.bpmn20.xml", childBpmnModel)
      .deploymentProperty(DeploymentProperties.DEPLOY_AS_ACTIVITI5_PROCESS_DEFINITION, Boolean.TRUE)
      .deploy();

  processEngine.getRepositoryService()
      .createDeployment()
      .name("masterProcessDeployment")
      .addBpmnModel("masterProcess.bpmn20.xml", mainBpmnModel)
      .deploymentProperty(DeploymentProperties.DEPLOY_AS_ACTIVITI5_PROCESS_DEFINITION, Boolean.TRUE)
      .deploy();

  suspendProcessDefinitions(childDeployment);

  try {
    runtimeService.startProcessInstanceByKey("masterProcess");
    fail("Exception expected");
  } catch (ActivitiException ae) {
    assertTextPresent("Cannot start process instance. Process definition Child Process", ae.getMessage());
  }

}
 
Example #19
Source File: FlowableDeploymentController.java    From hsweb-framework with Apache License 2.0 5 votes vote down vote up
/***
 * 流程定义转换Model
 */
@PutMapping(value = "/convert-to-model/{processDefinitionId}")
@ApiOperation("流程定义转换模型")
@Authorize(action = Permission.ACTION_UPDATE)
public ResponseMessage<String> convertToModel(@PathVariable("processDefinitionId") String processDefinitionId)
        throws UnsupportedEncodingException, XMLStreamException {
    ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery()
            .processDefinitionId(processDefinitionId).singleResult();
    if (null == processDefinition) {
        throw new NotFoundException();
    }
    InputStream bpmnStream = repositoryService.getResourceAsStream(processDefinition.getDeploymentId(),
            processDefinition.getResourceName());

    XMLInputFactory xif = XMLInputFactory.newInstance();
    InputStreamReader in = new InputStreamReader(bpmnStream, "UTF-8");
    XMLStreamReader xtr = xif.createXMLStreamReader(in);
    BpmnModel bpmnModel = new BpmnXMLConverter().convertToBpmnModel(xtr);


    BpmnJsonConverter converter = new BpmnJsonConverter();
    com.fasterxml.jackson.databind.node.ObjectNode modelNode = converter.convertToJson(bpmnModel);
    org.activiti.engine.repository.Model modelData = repositoryService.newModel();
    modelData.setKey(processDefinition.getKey());
    modelData.setName(processDefinition.getResourceName().substring(0, processDefinition.getResourceName().indexOf(".")));
    modelData.setCategory(processDefinition.getDeploymentId());

    ObjectNode modelObjectNode = new ObjectMapper().createObjectNode();
    modelObjectNode.put(ModelDataJsonConstants.MODEL_NAME, processDefinition.getName());
    modelObjectNode.put(ModelDataJsonConstants.MODEL_REVISION, 1);
    modelObjectNode.put(ModelDataJsonConstants.MODEL_DESCRIPTION, processDefinition.getDescription());
    modelData.setMetaInfo(modelObjectNode.toString());

    repositoryService.saveModel(modelData);

    repositoryService.addModelEditorSource(modelData.getId(), modelNode.toString().getBytes("utf-8"));
    return ResponseMessage.ok(modelData.getId());
}
 
Example #20
Source File: BpmnJsonConverter.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
private void readShapeDI(JsonNode objectNode, double parentX, double parentY, Map<String, JsonNode> shapeMap, Map<String, JsonNode> sourceRefMap, BpmnModel bpmnModel) {

    if (objectNode.get(EDITOR_CHILD_SHAPES) != null) {
      for (JsonNode jsonChildNode : objectNode.get(EDITOR_CHILD_SHAPES)) {

        String stencilId = BpmnJsonConverterUtil.getStencilId(jsonChildNode);
        if (STENCIL_SEQUENCE_FLOW.equals(stencilId) == false) {

          GraphicInfo graphicInfo = new GraphicInfo();

          JsonNode boundsNode = jsonChildNode.get(EDITOR_BOUNDS);
          ObjectNode upperLeftNode = (ObjectNode) boundsNode.get(EDITOR_BOUNDS_UPPER_LEFT);
          graphicInfo.setX(upperLeftNode.get(EDITOR_BOUNDS_X).asDouble() + parentX);
          graphicInfo.setY(upperLeftNode.get(EDITOR_BOUNDS_Y).asDouble() + parentY);

          ObjectNode lowerRightNode = (ObjectNode) boundsNode.get(EDITOR_BOUNDS_LOWER_RIGHT);
          graphicInfo.setWidth(lowerRightNode.get(EDITOR_BOUNDS_X).asDouble() - graphicInfo.getX() + parentX);
          graphicInfo.setHeight(lowerRightNode.get(EDITOR_BOUNDS_Y).asDouble() - graphicInfo.getY() + parentY);

          String childShapeId = jsonChildNode.get(EDITOR_SHAPE_ID).asText();
          bpmnModel.addGraphicInfo(BpmnJsonConverterUtil.getElementId(jsonChildNode), graphicInfo);

          shapeMap.put(childShapeId, jsonChildNode);

          ArrayNode outgoingNode = (ArrayNode) jsonChildNode.get("outgoing");
          if (outgoingNode != null && outgoingNode.size() > 0) {
            for (JsonNode outgoingChildNode : outgoingNode) {
              JsonNode resourceNode = outgoingChildNode.get(EDITOR_SHAPE_ID);
              if (resourceNode != null) {
                sourceRefMap.put(resourceNode.asText(), jsonChildNode);
              }
            }
          }

          readShapeDI(jsonChildNode, graphicInfo.getX(), graphicInfo.getY(), shapeMap, sourceRefMap, bpmnModel);
        }
      }
    }
  }
 
Example #21
Source File: StartEventXMLConverter.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Override
protected void writeAdditionalAttributes(BaseElement element, BpmnModel model, XMLStreamWriter xtw) throws Exception {
  StartEvent startEvent = (StartEvent) element;
  writeQualifiedAttribute(ATTRIBUTE_EVENT_START_INITIATOR, startEvent.getInitiator(), xtw);
  writeQualifiedAttribute(ATTRIBUTE_FORM_FORMKEY, startEvent.getFormKey(), xtw);
  
  if (startEvent.getEventDefinitions() != null && startEvent.getEventDefinitions().size() > 0) {
    writeQualifiedAttribute(ATTRIBUTE_EVENT_START_INTERRUPTING, String.valueOf(startEvent.isInterrupting()), xtw);
  }
}
 
Example #22
Source File: ChineseConverterTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
protected void deployProcess(BpmnModel bpmnModel)  {
  byte[] xml = new BpmnXMLConverter().convertToXML(bpmnModel);
  try {
    Deployment deployment = processEngine.getRepositoryService().createDeployment()
        .name("test")
        .deploymentProperty(DeploymentProperties.DEPLOY_AS_ACTIVITI5_PROCESS_DEFINITION, Boolean.TRUE)
        .addString("test.bpmn20.xml", new String(xml))
        .deploy();
    processEngine.getRepositoryService().deleteDeployment(deployment.getId());
  } finally {
    processEngine.close();
  }
}
 
Example #23
Source File: BpmnJsonConverter.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public void processFlowElements(FlowElementsContainer container, BpmnModel model, ArrayNode shapesArrayNode, 
    Map<String, ModelInfo> formKeyMap, Map<String, ModelInfo> decisionTableKeyMap, double subProcessX, double subProcessY) {

  for (FlowElement flowElement : container.getFlowElements()) {
    processFlowElement(flowElement, container, model, shapesArrayNode, formKeyMap, decisionTableKeyMap, subProcessX, subProcessY);
  }

  processArtifacts(container, model, shapesArrayNode, subProcessX, subProcessY);
}
 
Example #24
Source File: AssociationXMLConverter.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Override
protected void writeAdditionalAttributes(BaseElement element, BpmnModel model, XMLStreamWriter xtw) throws Exception {
  Association association = (Association) element;
  writeDefaultAttribute(ATTRIBUTE_FLOW_SOURCE_REF, association.getSourceRef(), xtw);
  writeDefaultAttribute(ATTRIBUTE_FLOW_TARGET_REF, association.getTargetRef(), xtw);
  AssociationDirection associationDirection = association.getAssociationDirection();
  if (associationDirection !=null) {
    writeDefaultAttribute(ATTRIBUTE_ASSOCIATION_DIRECTION, associationDirection.getValue(), xtw);
  }
}
 
Example #25
Source File: DataStoreReferenceXMLConverter.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Override
protected void writeAdditionalChildElements(BaseElement element, BpmnModel model, XMLStreamWriter xtw) throws Exception {
  DataStoreReference dataStoreRef = (DataStoreReference) element;
  if (StringUtils.isNotEmpty(dataStoreRef.getDataState())) {
    xtw.writeStartElement(ELEMENT_DATA_STATE);
    xtw.writeCharacters(dataStoreRef.getDataState());
    xtw.writeEndElement();
  }
}
 
Example #26
Source File: RuntimeDisplayJsonClientResource.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@RequestMapping(value = "/rest/process-instances/history/{processInstanceId}/model-json", method = RequestMethod.GET, produces = "application/json")
public JsonNode getModelHistoryJSON(@PathVariable String processInstanceId) {

  User currentUser = SecurityUtils.getCurrentUserObject();
  if (!permissionService.hasReadPermissionOnProcessInstance(currentUser, processInstanceId)) {
    throw new NotPermittedException();
  }

  HistoricProcessInstance processInstance = historyService.createHistoricProcessInstanceQuery().processInstanceId(processInstanceId).singleResult();
  if (processInstance == null) {
    throw new BadRequestException("No process instance found with id " + processInstanceId);
  }

  BpmnModel pojoModel = repositoryService.getBpmnModel(processInstance.getProcessDefinitionId());

  if (pojoModel == null || pojoModel.getLocationMap().isEmpty()) {
    throw new InternalServerErrorException("Process definition could not be found with id " + processInstance.getProcessDefinitionId());
  }

  // Fetch process-instance activities
  List<HistoricActivityInstance> activityInstances = historyService.createHistoricActivityInstanceQuery().processInstanceId(processInstanceId).list();

  Set<String> completedActivityInstances = new HashSet<String>();
  Set<String> currentActivityinstances = new HashSet<String>();
  if (CollectionUtils.isNotEmpty(activityInstances)) {
    for (HistoricActivityInstance activityInstance : activityInstances) {
      if (activityInstance.getEndTime() != null) {
        completedActivityInstances.add(activityInstance.getActivityId());
      } else {
        currentActivityinstances.add(activityInstance.getActivityId());
      }
    }
  }

  ObjectNode displayNode = processProcessElements(pojoModel, completedActivityInstances, currentActivityinstances);
  return displayNode;
}
 
Example #27
Source File: TimerEventDefinitionParser.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public void parseChildElement(XMLStreamReader xtr, BaseElement parentElement, BpmnModel model) throws Exception {
  if (parentElement instanceof Event == false)
    return;

  TimerEventDefinition eventDefinition = new TimerEventDefinition();
  String calendarName = xtr.getAttributeValue(ACTIVITI_EXTENSIONS_NAMESPACE, ATTRIBUTE_CALENDAR_NAME);
  if (StringUtils.isNotEmpty(calendarName)) {
    eventDefinition.setCalendarName(calendarName);
  }
  BpmnXMLUtil.addXMLLocation(eventDefinition, xtr);
  BpmnXMLUtil.parseChildElements(ELEMENT_EVENT_TIMERDEFINITION, eventDefinition, xtr, model);

  ((Event) parentElement).getEventDefinitions().add(eventDefinition);
}
 
Example #28
Source File: ProcessDefinitionScopedEventListenerTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
/**
 * Test to verify listeners on a process-definition are only called for events
 * related to that definition.
 */
@Deployment(resources = { "org/activiti5/engine/test/api/runtime/oneTaskProcess.bpmn20.xml",
    "org/activiti5/engine/test/api/event/simpleProcess.bpmn20.xml" })
public void testProcessDefinitionScopedListener() throws Exception {
	ProcessDefinition firstDefinition = repositoryService.createProcessDefinitionQuery().deploymentId(deploymentIdFromDeploymentAnnotation)
	    .processDefinitionKey("oneTaskProcess").singleResult();
	assertNotNull(firstDefinition);

	ProcessDefinition secondDefinition = repositoryService.createProcessDefinitionQuery().deploymentId(deploymentIdFromDeploymentAnnotation)
	    .processDefinitionKey("simpleProcess").singleResult();
	assertNotNull(firstDefinition);

	// Fetch a reference to the process definition entity to add the listener
	TestActivitiEventListener listener = new TestActivitiEventListener();
	BpmnModel bpmnModel = repositoryService.getBpmnModel(firstDefinition.getId());
	assertNotNull(bpmnModel);

	((ActivitiEventSupport) bpmnModel.getEventSupport()).addEventListener(listener);

	// Start a process for the first definition, events should be received
	ProcessInstance processInstance = runtimeService.startProcessInstanceById(firstDefinition.getId());
	assertNotNull(processInstance);

	assertFalse(listener.getEventsReceived().isEmpty());
	listener.clearEventsReceived();

	// Start an instance of the other definition
	ProcessInstance otherInstance = runtimeService.startProcessInstanceById(secondDefinition.getId());
	assertNotNull(otherInstance);
	assertTrue(listener.getEventsReceived().isEmpty());
}
 
Example #29
Source File: BpmnParseTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
protected void assertSequenceFlowWayPoints(BpmnModel bpmnModel, String sequenceFlowId, Integer... waypoints) {
  List<GraphicInfo> graphicInfos = bpmnModel.getFlowLocationGraphicInfo(sequenceFlowId);
  assertEquals(waypoints.length / 2, graphicInfos.size());
  for (int i = 0; i < waypoints.length; i += 2) {
    Integer x = waypoints[i];
    Integer y = waypoints[i+1];
    assertEquals(x.doubleValue(), graphicInfos.get(i/2).getX());
    assertEquals(y.doubleValue(), graphicInfos.get(i/2).getY());
  }
}
 
Example #30
Source File: TimeDateParser.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public void parseChildElement(XMLStreamReader xtr, BaseElement parentElement, BpmnModel model) throws Exception {
  if (parentElement instanceof TimerEventDefinition == false)
    return;

  TimerEventDefinition eventDefinition = (TimerEventDefinition) parentElement;
  eventDefinition.setTimeDate(xtr.getElementText());
}