camunda / camunda-bpm-platform

Flexible framework for workflow and decision automation with BPMN and DMN. Integration with Quarkus, Spring, Spring Boot, CDI.
https://camunda.com/
Apache License 2.0
4.11k stars 1.55k forks source link

Add new variable type DateInterval #3902

Closed antonkomarev closed 11 months ago

antonkomarev commented 11 months ago

User Story (Required on creation)

I want to create process instance with date interval variable.

Functional Requirements (Required before implementation)

On create process instance there should be available to pass variable of date interval type, it should be validated. If it is wrong formatted interval — process creation should fail.

Technical Requirements (Required before implementation)

POST http://localhost:8080/engine-rest/process-definition/key/:key/start

{
    "businessKey": "1234",
    "variables": {
        "processInstanceTtl": {
            "value": "PT10M",
            "type": "DateInterval"
        }
    }
}

Limitations of Scope

Hints

Links

Breakdown

### Pull Requests

Dev2QA handover

tasso94 commented 11 months ago

Hi @antonkomarev,

Thank you for reaching out to us.

Below are the steps to add customPreVariableSerializers or customPostVariableSerializers to the engine.

  1. Create a class (for example: MyCustomSerializer) that implements TypedValueSerializer interface. Write your implementation for a custom pre- or post-variable serializer in this class.

  2. Create a custom plugin (for example: MyCustomPlugin) that implements the ProcessEnginePlugin interface. And add MyCustomSerializer in the customPreVariableSerializers or customPostVariableSerializers property of the process engine configuration. Here is the sample code:

    public class MyCustomPlugin implements ProcessEnginePlugin  {
    public void preInit(ProcessEngineConfigurationImpl processEngineConfiguration) {
        List<TypedValueSerializer> serializers = new ArrayList();
        serializers.add(new MyCustomSerializer());
        processEngineConfiguration.setCustomPreVariableSerializers(serializers);
    }
    
    public void postInit(ProcessEngineConfigurationImpl processEngineConfiguration) {
        // TODO Auto-generated method stub
    }
    
    public void postProcessEngineBuild(ProcessEngine processEngine) {
        // TODO Auto-generated method stub
    }
    }
  3. Provide the custom plugin MyCustomPlugin and custom serializer MyCustomSerializer in the classpath of your process engine.

  4. Configure the custom process engine plugin MyCustomPlugin. For instance, for Tomcat, you can configure the plugin in the plugins section of your bpm-platform file. For example:

    
    <?xml version="1.0" encoding="UTF-8"?>
    <bpm-platform xmlns="http://www.camunda.org/schema/1.0/BpmPlatform"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.camunda.org/schema/1.0/BpmPlatform http://www.camunda.org/schema/1.0/BpmPlatform ">
    
    <process-engine name="default">
    <job-acquisition>default</job-acquisition>
    <configuration>org.camunda.bpm.engine.impl.cfg.JtaProcessEngineConfiguration</configuration>
    <datasource>jdbc/ProcessEngine</datasource>
    
    <plugins>
      <plugin>
        <class>org.camunda.bpm.engine.MyCustomPlugin</class>
      </plugin>
    </plugins>
    </process-engine>



Here is the link for configuring the process engine plugin for further reference https://docs.camunda.org/manual/7.20/user-guide/process-engine/process-engine-plugins/.

5. Restart the application server.

Does this work for you?

Best,
Tassilo
antonkomarev commented 11 months ago

@tasso94 thank you for sharing. Is it correct to make validation of the input in serializers? I thought there are some kind of Request Validators.

tasso94 commented 11 months ago

Hi @antonkomarev,

The variable types listed in our documentation ^1 are implemented via serializers.

Best, Tassilo