All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.camunda.exporter.handlers.EventFromProcessInstanceHandler Maven / Gradle / Ivy

There is a newer version: 8.7.0-alpha2
Show newest version
/*
 * Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH under
 * one or more contributor license agreements. See the NOTICE file distributed
 * with this work for additional information regarding copyright ownership.
 * Licensed under the Camunda License 1.0. You may not use this file
 * except in compliance with the Camunda License 1.0.
 */
package io.camunda.exporter.handlers;

import static io.camunda.exporter.utils.ExporterUtil.tenantOrDefault;
import static io.camunda.webapps.schema.descriptors.operate.template.EventTemplate.*;

import io.camunda.exporter.store.BatchRequest;
import io.camunda.webapps.schema.descriptors.operate.template.EventTemplate;
import io.camunda.webapps.schema.entities.operate.EventEntity;
import io.camunda.zeebe.protocol.record.Record;
import io.camunda.zeebe.protocol.record.ValueType;
import io.camunda.zeebe.protocol.record.intent.Intent;
import io.camunda.zeebe.protocol.record.intent.ProcessInstanceIntent;
import io.camunda.zeebe.protocol.record.value.ProcessInstanceRecordValue;
import java.util.List;
import java.util.Set;

public class EventFromProcessInstanceHandler
    extends AbstractEventHandler {

  protected static final Set PROCESS_INSTANCE_STATES =
      Set.of(
          ProcessInstanceIntent.ELEMENT_ACTIVATING,
          ProcessInstanceIntent.ELEMENT_ACTIVATED,
          ProcessInstanceIntent.ELEMENT_COMPLETING,
          ProcessInstanceIntent.ELEMENT_COMPLETED,
          ProcessInstanceIntent.ELEMENT_TERMINATED);

  public EventFromProcessInstanceHandler(final String indexName, final boolean concurrencyMode) {
    super(indexName, concurrencyMode);
  }

  @Override
  public ValueType getHandledValueType() {
    return ValueType.PROCESS_INSTANCE;
  }

  @Override
  public boolean handlesRecord(final Record record) {
    return PROCESS_INSTANCE_STATES.contains(record.getIntent());
  }

  @Override
  public List generateIds(final Record record) {
    return List.of(
        String.format(ID_PATTERN, record.getValue().getProcessInstanceKey(), record.getKey()));
  }

  @Override
  public void updateEntity(
      final Record record, final EventEntity entity) {

    final ProcessInstanceRecordValue recordValue = record.getValue();
    entity
        .setId(String.format(ID_PATTERN, recordValue.getProcessInstanceKey(), record.getKey()))
        .setPosition(record.getPosition());

    loadEventGeneralData(record, entity);

    entity
        .setProcessDefinitionKey(recordValue.getProcessDefinitionKey())
        .setProcessInstanceKey(recordValue.getProcessInstanceKey())
        .setBpmnProcessId(recordValue.getBpmnProcessId())
        .setTenantId(tenantOrDefault(recordValue.getTenantId()));

    if (recordValue.getElementId() != null) {
      entity.setFlowNodeId(recordValue.getElementId());
    }

    if (record.getKey() != recordValue.getProcessInstanceKey()) {
      entity.setFlowNodeInstanceKey(record.getKey());
    }
  }

  @Override
  public void flush(final EventEntity entity, final BatchRequest batchRequest) {
    persistEvent(entity, EventTemplate.POSITION, entity.getPosition(), batchRequest);
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy