Activiti uses the form engine to generate form definition data

Activiti uses the form engine to generate form definition data

Project address: activiti-workflow
For the approval flow, form information can be defined through activiti's form engine. Design the form information first, and then associate the form during the design process.

This article mainly introduces the pits that I stepped on when saving form data. The version of activiti is 6.0.0 .

Form table introduction:

  1. act_fo_form_definition: form definition table
  2. act_fo_form_deployment: form deployment form
  3. act_fo_form_resource: form source data table

Activiti provides the service of the form engine for manipulating forms. Save the form data throughprocessEngine.getFormEngineRepositoryService().createDeployment().addFormDefinition(resourceName, formDefinition).name(formName).deploy();

At that time, the form data was saved in this way during development. It turned out that only the act_fo_form_deployment and act_fo_form_resource tables had data, and the act_fo_form_definition table had no data. The interface for querying the number of forms provided by activiti is shown in the figure.
Insert picture description here
To find out the definition data of the form, it is necessary to query act_fo_form_definition. Now that there is no data in this table, the form data can be saved in, but cannot be found out.

Followed by the deployment method of deploy, in the org.activiti.form.engine.impl.deployer.FormDeployer#deploy method

public void deploy(FormDeploymentEntity deployment) {
    
    
    log.debug("Processing deployment {}", deployment.getName());

    // The ParsedDeployment represents the deployment, the forms, and the form
    // resource, parse, and model associated with each form.
    //将表单定义数据封装为部署的数据,主要是这里的build方法
    ParsedDeployment parsedDeployment = parsedDeploymentBuilderFactory.getBuilderForDeployment(deployment).build();

    formDeploymentHelper.verifyFormsDoNotShareKeys(parsedDeployment.getAllForms());

    formDeploymentHelper.copyDeploymentValuesToForms(parsedDeployment.getDeployment(), parsedDeployment.getAllForms());
    formDeploymentHelper.setResourceNamesOnForms(parsedDeployment);

    if (deployment.isNew()) {
    
    
      Map<FormEntity, FormEntity> mapOfNewFormToPreviousVersion = getPreviousVersionsOfForms(parsedDeployment);
      setFormVersionsAndIds(parsedDeployment, mapOfNewFormToPreviousVersion);
      //插入表单定义数据
      persistForms(parsedDeployment);
    } else {
    
    
      makeFormsConsistentWithPersistedVersions(parsedDeployment);
    }

    cachingAndArtifactsManager.updateCachingAndArtifacts(parsedDeployment);
  }

Follow up with the build method. Here, the ResourceEntity is parsed into FormEntity and the validity of the original file name is verified, that is, the resourceName. If the verification fails, the forms attribute of ParsedDeployment will be empty. Mainly depends on the isFormResource method

 public ParsedDeployment build() {
    
    
    List<FormEntity> forms = new ArrayList<FormEntity>();
    Map<FormEntity, FormParse> formToParseMap = new LinkedHashMap<FormEntity, FormParse>();
    Map<FormEntity, ResourceEntity> formToResourceMap = new LinkedHashMap<FormEntity, ResourceEntity>();

    for (ResourceEntity resource : deployment.getResources().values()) {
    
    
      //校验文件名是否合法,合法后将ResourceEntity解析为FormEntity
      if (isFormResource(resource.getName())) {
    
    
        log.debug("Processing Form resource {}", resource.getName());
        FormParse parse = createFormParseFromResource(resource);
        for (FormEntity form : parse.getForms()) {
    
    
          forms.add(form);
          formToParseMap.put(form, parse);
          formToResourceMap.put(form, resource);
        }
      }
    }

    return new ParsedDeployment(deployment, forms, formToParseMap, formToResourceMap);
  }

isFormResource method

 protected boolean isFormResource(String resourceName) {
    
    
    for (String suffix : FORM_RESOURCE_SUFFIXES) {
    
    
      //校验resourceName的后缀是否是form
      //这里的FORM_RESOURCE_SUFFIXES = new String[] { "form" };
      if (resourceName.endsWith(suffix)) {
    
    
        return true;
      }
    }

    return false;
  }

Looking at the persistForms method, the ParsedDeployment form is not empty to insert data. In the previous verification, if the resourceName is invalid, the ResourceEntity will not be parsed as a FormEntity, and the forms will be empty, and no data will be inserted here.

 protected void persistForms(ParsedDeployment parsedDeployment) {
    
    
    CommandContext commandContext = Context.getCommandContext();
    FormEntityManager formEntityManager = commandContext.getFormEntityManager();

    for (FormEntity form : parsedDeployment.getAllForms()) {
    
    
      formEntityManager.insert(form);
    }
  }

At this point, it is clear, because processEngine.getFormEngineRepositoryService().createDeployment().addFormDefinition(resourceName, formDefinition).name(formName).deploy();the value of resourceName is randomly taken when the call is made, and it does not end with form, which results in failure to verify the resourceName and no data is inserted in the definition table.

Guess you like

Origin blog.csdn.net/qq_34758074/article/details/103331260