Questions about basic Understanding of the process engine

Hello,

I am new to the Camunda Process Engine and currently working with it inside my Spring Boot application as described here:

I am using my own custom REST API and behind it I am using the Java API and its services via DI. I have been working through the documentation and watching the tutorial videos to find out how to interact with my process instances. Yet I have difficulties to implement the logic for it.

Example: I provided a Form Key and Form Fields for a User Task with the Camunda Modeler. I implemented a TaskListener to interact with this Task (or ActivityInstance?) at creation time. According to the REST API documentation (Get Task Form Variables | docs.camunda.org) I would have to send a request to receive this data. Since I am using the Java API I am interested in the logic behind that REST endpoint. Currently I am extracting the TaskFormData into my own Model inside the TaskListener:

public class UserTaskFormListener implements TaskListener {

@Override
public void notify(DelegateTask delegateTask) {
    String taskId = delegateTask.getId();

    ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
    FormService formService = processEngine.getFormService();

    TaskFormData taskForm = formService.getTaskFormData(taskId);
    List<FormField> formFields = taskForm.getFormFields();

   // logic for saving data to my own model (form)

   delegateTask.setVariable(taskId, form);
}
}

This should save the form to the task and I can access a “VariableMap” which I can extract the form data again into my custom model at request time. Additionally I could just access the “TaskFormData” from here, which would make my TaskListener unnecessary. I would imagine to get a single Object with all information according to the modeler for example by the InstanceID or TaskID.

The documentation explains “Retrieving the Form using the Task Service” (User Task | docs.camunda.org). It is not explaining how the retrieve the actual form data. What would be the best practice on how to get the form of the active user task(s) by a given InstanceID?

What am I missing here? It is kind of trial and error until i get the correct functionality and still then I don’t know if it is intended by Camunda. I don’t want to worry too much about the process and focus on implementing my own logic. Is it possible to get the logic behind the REST API? Maybe I am completely failing to understand the concept.

For example, this is how I start a process:

// Starting a process
public ApplicationProcess startProcess() {
    UUID businessKey = UUID.randomUUID();
    ProcessInstance process = runtimeService.startProcessInstanceByKey(processName, businessKey.toString());
    String instanceId = process.getProcessInstanceId();

    // custom model
    ApplicationProcess applicationProcess = new ApplicationProcess();
    applicationProcess.setInstanceId(instanceId);
    applicationProcess.setBusinessKey(businessKey.toString());
    applicationProcess.setProcessDefinition(process.getProcessDefinitionId());

    log.info("New Instance of {} with ID {} started", processName, instanceId);
    return applicationProcess;
}

Thank you.
Andreas