Activiti Struts Integration Program

6 篇文章 0 订阅

1. Activiti External Form Rendering

Reference: Activiti in Action

Reference: Activiti 5.10 User Guide. http://activiti.org/userguide/index.html#externalFormRendering

Reference: http://rongjih.blog.163.com/blog/static/33574461201263124922670/

We should be aware of the difference of StartForm and TaskForm.


Fact 1: FormService Interface should be implemented by myself

StartForm Methods
TaskForm MethodsNote
getStartFormDatagetTaskFormDatano template involved
getRenderedStartFormgetRenderedTaskFormtemplate loaded, and script like juel in template evaluated
submitStartFormDatasubmitTaskFormData 

Any reference implementation of FormService interface? YES! org.activiti.engine.impl.FormServiceImpl

public class FormServiceImpl extends ServiceImpl implements FormService {

  //HERE COMMAND PATTERN APPLIED
  public Object getRenderedStartForm(String processDefinitionId) {
    return commandExecutor.execute(new GetRenderedStartFormCmd(processDefinitionId, null));
  }

  public Object getRenderedStartForm(String processDefinitionId, String engineName) {
    return commandExecutor.execute(new GetRenderedStartFormCmd(processDefinitionId, engineName));
  }

  public Object getRenderedTaskForm(String taskId) {
    return commandExecutor.execute(new GetRenderedTaskFormCmd(taskId, null));
  }

  public Object getRenderedTaskForm(String taskId, String engineName) {
    return commandExecutor.execute(new GetRenderedTaskFormCmd(taskId, engineName));
  }

  public StartFormData getStartFormData(String processDefinitionId) {
    return commandExecutor.execute(new GetStartFormCmd(processDefinitionId));
  }

  public TaskFormData getTaskFormData(String taskId) {
    return commandExecutor.execute(new GetTaskFormCmd(taskId));
  }

  public ProcessInstance submitStartFormData(String processDefinitionId, Map<String, String> properties) {
    return commandExecutor.execute(new SubmitStartFormCmd(processDefinitionId, null, properties));
  }
  
  public ProcessInstance submitStartFormData(String processDefinitionId, String businessKey, Map<String, String> properties) {
	  return commandExecutor.execute(new SubmitStartFormCmd(processDefinitionId, businessKey, properties));
  }

  public void submitTaskFormData(String taskId, Map<String, String> properties) {
    commandExecutor.execute(new SubmitTaskFormCmd(taskId, properties));
  }

  public String getStartFormKey(String processDefinitionId) {
    return commandExecutor.execute(new GetFormKeyCmd(processDefinitionId));
  }

  public String getTaskFormKey(String processDefinitionId, String taskDefinitionKey) {
    return commandExecutor.execute(new GetFormKeyCmd(processDefinitionId, taskDefinitionKey));
  }

}

public class GetRenderedStartFormCmd implements Command<Object>, Serializable {

  private static final long serialVersionUID = 1L;
  protected String processDefinitionId;
  protected String formEngineName;
  
  public GetRenderedStartFormCmd(String processDefinitionId, String formEngineName) {
    this.processDefinitionId = processDefinitionId;
    this.formEngineName = formEngineName;
  }

  public Object execute(CommandContext commandContext) {
    ProcessDefinitionEntity processDefinition = Context
      .getProcessEngineConfiguration()
      .getDeploymentCache()
      .findDeployedProcessDefinitionById(processDefinitionId);
    if (processDefinition == null) {
      throw new ActivitiException("Process Definition '" + processDefinitionId +"' not found");
    }
    StartFormHandler startFormHandler = processDefinition.getStartFormHandler();
    if (startFormHandler == null) {
      return null;
    }
    
    FormEngine formEngine = Context
      .getProcessEngineConfiguration()
      .getFormEngines()
      .get(formEngineName);
    
    if (formEngine==null) {
      throw new ActivitiException("No formEngine '" + formEngineName +"' defined process engine configuration");
    }
    
    StartFormData startForm = startFormHandler.createStartFormData(processDefinition);
    
    return formEngine.renderStartForm(startForm);
  }
}



Noteworthy: business key

/** 
   * Start a new process instance with the user data that was entered as properties in a start form. 
   * 
   * A business key can be provided to associate the process instance with a
   * certain identifier that has a clear business meaning. For example in an
   * order process, the business key could be an order id. This business key can
   * then be used to easily look up that process instance , see
   * {@link ProcessInstanceQuery#processInstanceBusinessKey(String)}. Providing such a business
   * key is definitely a best practice.
   * 
   * Note that a business key MUST be unique for the given process definition.
   * Process instance from different process definition are allowed to have the
   * same business key.
   * 
   * @param processDefinitionId the id of the process definition, cannot be null.
   * @param businessKey a key that uniquely identifies the process instance in the context or the
   *                    given process definition.
   * @param properties the properties to pass, can be null.
   */  
  ProcessInstance submitStartFormData(String processDefinitionId, String businessKey, Map<String, String> properties);

public abstract class AbstractFormType implements FormType {
  //What does this mean?
  public abstract Object convertFormValueToModelValue(String propertyValue);

  public abstract String convertModelValueToFormValue(Object modelValue);

  public Object getInformation(String key) {
    return null;
  }

}


public abstract class FormDataImpl implements FormData, Serializable {

  private static final long serialVersionUID = 1L;
  //UNDERSTANDING
  protected String formKey;
  protected String deploymentId;
  protected List<FormProperty> formProperties = new ArrayList<FormProperty>();


public interface FormHandler {

  ThreadLocal<FormHandler> current = new ThreadLocal<FormHandler>();

  void parseConfiguration(Element activityElement, DeploymentEntity deployment, ProcessDefinitionEntity processDefinition, BpmnParse bpmnParse);

  void submitFormProperties(Map<String, String> properties, ExecutionEntity execution);
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Struts2和Activiti是两个独立的开源项目,用于Web应用程序开发和业务流程管理。Struts2是一个基于Java的Web应用程序开发框架,提供了一套MVC(Model-View-Controller)架构模式的解决方案,帮助开发者构建可扩展、灵活和易于维护的Web应用程序。 Activiti是一个轻量级的业务流程管理框架,它实现了BPMN 2.0(Business Process Model and Notation)规范并提供了一套完整的工作流引擎,用于管理和执行各种业务流程。Activiti可以与各种Java框架集成,包括Struts2。 如果你想在Struts2应用程序中使用Activiti,你可以通过以下步骤实现集成: 1. 引入Activiti依赖:在你的项目中添加Activiti的依赖,可以通过Maven或手动下载jar包的方式引入。 2. 配置Activiti引擎:在你的应用程序中配置Activiti引擎,包括数据库连接和其他相关参数的配置。 3. 编写业务流程定义:使用Activiti提供的BPMN 2.0规范定义你的业务流程,并将其部署到Activiti引擎中。 4. 在Struts2中使用Activiti:根据你的业务需求,在Struts2的Action中调用Activiti引擎提供的API,例如启动流程实例、查询任务列表、完成任务等操作。 通过以上步骤,你可以在Struts2应用程序中利用Activiti来管理和执行业务流程。请注意,具体的集成细节可能会因项目需求和版本差异而有所不同,你需要参考官方文档或相关教程进行更详细的配置和使用。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值