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

io.camunda.exporter.handlers.PostImporterQueueFromIncidentHandler 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 io.camunda.exporter.store.BatchRequest;
import io.camunda.webapps.schema.entities.operate.post.PostImporterActionType;
import io.camunda.webapps.schema.entities.operate.post.PostImporterQueueEntity;
import io.camunda.zeebe.protocol.record.Record;
import io.camunda.zeebe.protocol.record.ValueType;
import io.camunda.zeebe.protocol.record.intent.IncidentIntent;
import io.camunda.zeebe.protocol.record.intent.Intent;
import io.camunda.zeebe.protocol.record.value.IncidentRecordValue;
import java.time.OffsetDateTime;
import java.util.List;

public class PostImporterQueueFromIncidentHandler
    implements ExportHandler {

  private final String indexName;

  public PostImporterQueueFromIncidentHandler(final String indexName) {
    this.indexName = indexName;
  }

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

  @Override
  public Class getEntityType() {
    return PostImporterQueueEntity.class;
  }

  @Override
  public boolean handlesRecord(final Record record) {
    return true;
  }

  @Override
  public List generateIds(final Record record) {
    Intent intent = record.getIntent();
    if (intent.equals(IncidentIntent.MIGRATED)) {
      intent = IncidentIntent.CREATED;
    }
    return List.of(String.format("%d-%s", record.getKey(), intent));
  }

  @Override
  public PostImporterQueueEntity createNewEntity(final String id) {
    return new PostImporterQueueEntity().setId(id);
  }

  @Override
  public void updateEntity(
      final Record record, final PostImporterQueueEntity entity) {
    final IncidentRecordValue recordValue = record.getValue();
    Intent intent = record.getIntent();
    if (intent.equals(IncidentIntent.MIGRATED)) {
      intent = IncidentIntent.CREATED;
    }
    entity
        .setId(String.format("%d-%s", record.getKey(), intent))
        .setActionType(PostImporterActionType.INCIDENT)
        .setIntent(intent.name())
        .setKey(record.getKey())
        .setPosition(record.getPosition())
        .setCreationTime(OffsetDateTime.now())
        .setPartitionId(record.getPartitionId())
        .setProcessInstanceKey(recordValue.getProcessInstanceKey());
  }

  @Override
  public void flush(final PostImporterQueueEntity entity, final BatchRequest batchRequest) {
    batchRequest.add(indexName, entity);
  }

  @Override
  public String getIndexName() {
    return indexName;
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy