Modeling business processes for generating excerpts in csv and docx format

🌐 This document is available in both English and Ukrainian. Use the language toggle in the top right corner to switch between versions.

The description of the business process modeling mechanism is given in the example of the Registry of certified laboratories, namely in creating the "Laboratory report in csv format" excerpt. Modeling a business process for generating excerpts in the docx format is similar, except for the step where the file format is selected.

Fulfil the required preconditions for creating a business process, follow the link for instructions.

1. Initial steps for creating a business process

  1. Create a new BPMN diagram.

    bp 1

  2. Add the Create pool/Participant element.

    In the right-hand side window with parameters, you have to enter the appropriate values into the fields:

    • In the Participant Name field, enter the pool name — Generate a report on laboratories in csv format.

    • In the Process id field, enter the ID of the business process — zvit-csv-bp.

    • In the Process name field, enter the business name of the process — Generate a report on laboratories in csv format.

    bp modeling excerpt csv docx 01

  1. Create the start event for starting the business process by a user.

    In the settings panel on the right-hand side, enter the appropriate values into the following parameters:

    • In the General tab:

      • In the Id field, enter the StartEvent_lab1 value.

      • In the Name field, enter the name of the start event — Start Form.

      • in the Initiator field, enter the initiator value.

        initiator is a special variable set for the user, which initiated the process.

      bp modeling excerpt csv docx 02

    • In the Form tab:

      • in the FormKey field, enter the form ID — add-startform-zvit.

    In the FormKey field, enter the service name of the created UI form in the Regulations administrator portal.

    bp modeling excerpt csv docx 02.1

    The following steps describe modeling of the start form.

2. Data preparation and signing

  1. Create a service task Read data by laboratoryId.

    Select the customized Read entity from data factory template.

    You can find more details about this delegate on the page Read entity from data factory.

    In the settings panel, enter the following values:

    • In the Name field, enter the name of the task — Data reading by laboratoryId.

    • In the Resource field, enter the laboratory resource.

    • in the Resource id field, enter the resource ID — ${submission('StartEvent_lab1').formData.prop('laboratory').prop('laboratoryId').value()}.

      In our case, we pass the StartEvent_lab1 resource identifier from the start form of the business process using the submission() function.

    • In the X-Access-Token field, specify the access token to the user’s system that is used to perform the ${initiator().accessToken} operation.

    • In the Result Variable field, enter the output parameter name — labResponse.

    bp modeling excerpt csv docx 03

  2. Create the Search for employees data service task.

    Select the configured Search for entities in data factory template.

    You can find more details about this delegate on the page Search for entities in data factory.

    In the settings panel, enter the following values:

    • In the Name field, enter the name of the task — Search for employees data.

    • In the Input Parameters section:

      • Expand the Resource block:

        • Local Variable Assignment is set to on. This allows creation of a local variable for the request body.

        • Variable Assignment Type, select the String of Expression variable assignment type from the dropdown list.

        • Variable Assignment Value, enter staff-equal-laboratory-id.

      staff-equal-laboratory-id is the endpoint name for the search criteria, where a request is made to find entities.

      • Expand the Search variable block:

        • Local Variable Assignment has the on value.

        • Variable Assignment Type, select Map.

        • Add Entry, enter laboratoryId in Key, and enter ${submission('StartEvent_lab1').formData.prop('laboratory').prop('laboratoryId').value()} in Value.

      • Expand the X-Access-Token block:

        • Local Variable Assignment has the on value.

        • Variable Assignment Type, select String of Expression.

        • Variable Assignment Value, enter ${initiator().accessToken}.

    • In the Output Parameters section:

      • Expand the Result variable block:

        • Local Variable Assignment has the on value.

        • Assign to Process Variable, enter the value of the variable used for writing the request result — staffResponse.

    bp modeling excerpt csv docx 04

  3. Create the Prepare data for displaying script task.

    In the settings panel, enter the following values:

    • In the Name field, enter the Prepare data for displaying name.

    • In the Script Format field, enter the script type (language) — groovy.

    • In the Script Type field, select the script type — Inline Script.

    • In the Script field, insert the following groovy script:

      def labResponseBody = labResponse.responseBody
      def payload = [:]
      def personnelGrid = []
      
      def addPersonPropClosure = { person, staffIt, key ->
      if (staffIt.hasProp(key)) {
      if (!staffIt.prop(key).isNull()) {
      person[key] = staffIt.prop(key).value()
      }
      }
      }
      
      staffResponse.responseBody.elements().each {
      def person = [:]
      
          addPersonPropClosure(person, it, 'fullName')
          addPersonPropClosure(person, it, 'specializationDate')
          addPersonPropClosure(person, it, 'salary')
          addPersonPropClosure(person, it, 'hygienistFlag')
          addPersonPropClosure(person, it, 'fullTimeFlag')
      
          personnelGrid.add(person)
      }
      
      payload['name'] = labResponseBody .prop('name').value()
      payload['edrpou'] = labResponseBody .prop('edrpou').value()
      payload['address'] = labResponseBody .prop('address').value()
      payload['headName'] = labResponseBody .prop('headName').value()
      payload['personnelGrid'] = personnelGrid
      
      execution.removeVariable('payload')
      set_transient_variable('payload', S(payload, 'application/json'))

      bp modeling excerpt csv docx 05

  1. Create the Display personnel data custom task.

    In the settings panel, set the following values:

    • In the Id field, enter the personnelDataZvitForm value.

    • In the Name field, enter the Display personnel data name.

    • In the Form key field, enter the read-personnel-data-zvit value.

    In the FormKey field, you have to enter the service name of the created UI form in the Regulations administrator portal.

    The following steps describe modeling of the personnel data display form.

    • In the Assignee field, enter the ${initiator} value.

      ${initiator} indicates that the business process will be assigned to the user who initiated the business process.

    • In the Form data pre-population field, enter the ${payload} value.

      bp modeling excerpt csv docx 06

  2. Create the Prepare data for creating database record (transient var) script task.

    In the settings panel, set the following values:

    • In the Name field, enter the Prepare data for creating database record (transient var) value.

    • In the Script Format field, enter the script type (language) — groovy.

    • In the Script Type field, select the Inline Script script type.

    • In the Script field, insert the following groovy script:

      def personnelFormData = submission('personnelDataZvitForm').formData
      
      def excerptInputData = [:]
      def requests = []
      
      def prepopulatedDataMap = [:]
      prepopulatedDataMap['name'] = personnelFormData.prop('name').value()
      prepopulatedDataMap['address'] = personnelFormData.prop('address').value()
      prepopulatedDataMap['headName'] = personnelFormData.prop('headName').value()
      prepopulatedDataMap['edrpou'] = personnelFormData.prop('edrpou').value()
      
      personnelFormData.prop('personnelGrid').elements().each {
          def request = [:]
          request.putAll(prepopulatedDataMap)
          it.fieldNames().each { fieldName ->
              request[fieldName] = it.prop(fieldName).value()
          }
          request['hygienistFlag'] = it.prop('hygienistFlag').boolValue() ? '1' : '0'
          request['fullTimeFlag'] = it.prop('fullTimeFlag').boolValue() ? '1' : '0'
      
          requests.add(request)
      }
      
      excerptInputData['requests'] = requests
      
      def request = [:]
      request['recordId'] = null
      request['excerptType'] = 'lab-staff-excerpt-csv'
      request['excerptInputData'] = excerptInputData
      request['requiresSystemSignature'] = false
      
      def payload = S(request, 'application/json')
      execution.removeVariable('payload')
      set_transient_variable('payload', payload)
      
      execution.removeVariable('excerpt')
      set_transient_variable('excerpt', excerptInputData)

    bp modeling excerpt csv docx 07

  3. Add a service task for data signing with the system key.

    For a detailed overview of the delegate description for signing data with the system key, follow this link.

    Select the configured template Digital signature by DSO service.

    In the settings panel, specify the following values:

    • In the Name field, indicate the task name Sign data with the system key.

    • In the Payload field, enter the data to be signed — ${payload}.

    • In the X-Access-Token source field, indicate the user access token under which the operation is performed — ${initiator().accessToken}.

    • In the Result variable field, specify the variable name system_signature_ceph_key, to which the system signing key should be saved.

3. Generating a report

  1. Create a service task Request for generating an excerpt.

    Select the `Generate Excerpt' configured template.

    • In the Name field, enter the Request for generating an excerpt name.

    • In the Excerpt Type field, enter the name of the file that defines the format — lab-staff-excerpt-csv.

    • In the Excerpt Input Data field, enter the ${excerpt} value.

    • In the Requires System Signature field, enter the false value.

      A possibility to sign excerpt data in .csv and .docx formats using a system key is not available. Therefore, the Requires System Signature parameter should contain the false value by default. If true is set, the business process will not run. Signing using the system key is only available for the .pdf format.

    • In the X-Access-Token field, enter the token to access the user system, which is used to perform the ${initiator().accessToken} operation.

    • In the X-Digital-Signature source field, enter the source of the digital signature — ${sign_submission('StartEvent_lab1').signatureDocumentId}.

    • In the X-Digital-Signature-Derived source field, enter the source of the system digital signature — ${system_signature_ceph_key}.

    • In the Result variable field, enter the response output parameter name.

    bp modeling excerpt csv docx 09

The data transmitted to generate the excerptInputData excerpt must have the following format:

{
   "requests":[
      {
         "field1":"value1"
      },
      {
         "field2":"value2"
      }

..........
   ]
}
  1. Create a file in the root of the cluster, placing it in the corresponding project directory.

    The file name has to be identical to the name entered in Excerpt Type (at the previous step). In our example, that is lab-staff-excerpt-csv.csv.

    Diagram

    At this stage, the .csv and .docx file format is determined.

  2. Create a "Save excerpt’s request ID" script task.

    In the settings panel, set the following values:

    • In the Name field, enter the name of the task — Save excerpt’s request ID.

    • In the Script Format field, enter the script type (language) — groovy.

    • In the Script Type field, select the Inline Script script type.

    • In the Script field, insert the following groovy script:

      response.responseBody.prop('excerptIdentifier').value()
    • In the Result Variable field, enter the name of the variable to which the extract identifier will be written, — excerptIdentifier.

    bp modeling excerpt csv docx 11

4. Setting the conditions of the output generation result checks

  1. Add the task for calling an external business process (Call Activity) "Check excerpt generation status".

    Select the configured Check excerpt status template.

    Follow the link to find more details about the Check excerpt status delegate.

    In the settings panel, enter the following values:

    • In the Name field, enter the name of the task — Check the status of excerpt generation.

    • In the Input excerpt identifier field, enter the excerpt ID that has to be passed to the called business process — ${excerptIdentifier}.

    • In the Output variable name field, enter the excerptStatus variable, where the excerpt status, recived as the result of a sub-process execution, has to be saved.

      bp modeling excerpt csv docx 12.1

    Example 1. "Check excerpt generation status" business process

    bp modeling excerpt csv docx 13

  2. Add the Create Intermediate/Boundary Event element, define its type by clicking the key icon (Change type) and selecting the Timer Boundary Event item from the menu.

    Follow the link to find more detailed description of the Timer event modeling element.

    Go to the settings panel and configure the event:

    • In the Name field, enter the P2M waiting time expired.

    • In the Timer Definition Type field, set the Duration timer type;

    • In the Timer Definition field, set the P2M timer duration.

    bp modeling excerpt csv docx 12.2

  3. Add XOR gateways for the "Check excerpt generation status" Call Activity and for the "P2M Timed Out" Timer Boundary Event.

    bp modeling excerpt csv docx 14

  4. Create the "Save the generated excerpt identifier to the system BP" service task.

    In the settings panel, set the following values:

    • In the General tab:

      • In the Name field, enter the value Save the identifier of the generated excerpt to the system BP.

      • in the Implementation field ,select the Delegate Expression value.

      • In the Delegate Expression field, enter ${defineProcessExcerptIdDelegate}.

    • In the Input/Output tab:

      • In the Local Variable Name field, enter the excerptId value.

      • In the Variable Assignment Type field, select String or Expression.

      • In the Variable Assignment Value field, enter ${excerptIdentifier}.

      bp modeling excerpt csv docx 15.1

      bp modeling excerpt csv docx 15.2

    The value specified in the Id field is used as the name of the file that a user downloads from the portal.

  5. Configure the flow process for the XOR gateway.

    Create Connect using sequence (branches):

    1. To the "Save the identifier of the generated excerpt to the system BP" service task:

      • Enter yes in the Name field.

      • In the Condition Type field, select Expression.

      • In the Expression field, enter the ${excerptStatus.equals('COMPLETED')} value.

      bp modeling excerpt csv docx 16

    2. To another XOR gateway:

      • In the Name field, enter no.

      • In the Condition Type field, select Expression.

      • In the Expression field, enter ${excerptStatus.equals('FAILED')}.

    bp modeling excerpt csv docx 17

5. Process execution result

5.1. Unsuccessful result of business process execution

  1. Create the "Execution result "Excerpt not generated"" service task.

    Choose the Define business process status configured template.

    + In the settings panel, set the following values:

    • In the Name field, enter the Execution result "Excerpt not generated" value.

    • In the Status field, enter the Excerpt not generated value. This status is displayed after process completion.

    bp modeling excerpt csv docx 18

  2. Configure the flow process from the XOR gateway to the service task "Execution result "Excerpt not generated"" by creating a Connect using sequence (branch).

    And create the business process completion event.

    • In the Name field, enter the Excerpt document not generated value.

    bp modeling excerpt csv docx 19

5.2. Successful result of business process execution

  1. Create the "Execution result "Excerpt generated"" service task.

    Choose the Define business process status configured template.

    In the settings panel, set the following values:

    • In the Name field, enter the Execution result "Excerpt generated" value.

    • In the Status field, enter the Excerpt generated value. This status is displayed after process completion.

  2. Create the business process completion event.

    • In the Name field, enter the Excerpt document generated value.

    bp modeling excerpt csv docx 21

6. Modeling forms

Model the forms in accordance with the instructions at the link.

6.1. Modeling the starting form

Modeling the starting form involves creation of a form for searching a laboratory by its name.

  • In the Form business name field, enter the Start form lab report value.

  • In the Form service name field, enter the add-startform-zvit value (which is used at the previous step as the value of the Form Key parameter).

bp modeling excerpt csv docx 22

The configured form can be downloaded from the following link:

6.2. Modeling the personnel data display form

Modeling the personnel data display form involves creation of a form for generating the data of the called laboratory.

  • In the Business name of the form field, enter the Display personnel data report value.

  • In the Form service name field, enter the read-personnel-data-zvit value (which is used at the previous step as the value of the Form Key parameter).

bp modeling excerpt csv docx 23

The configured form can be downloaded from the following link:

7. An example of using the business process by a user

You can learn more about the process of creating excerpts by users based on the result of the modeled business process by the following links: