Skip to content

Commit

Permalink
Merge pull request #362 from camunda-community-hub/339-escalation-record
Browse files Browse the repository at this point in the history
feat: Add escalation record
  • Loading branch information
saig0 authored May 7, 2024
2 parents 3a09b40 + 154d6d9 commit 434e3a4
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/main/java/io/zeebe/exporter/proto/RecordTransformer.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ public final class RecordTransformer {
TRANSFORMERS.put(ValueType.RESOURCE_DELETION, RecordTransformer::toResourceDeletionRecord);
TRANSFORMERS.put(ValueType.USER_TASK, RecordTransformer::toUserTaskRecord);
TRANSFORMERS.put(ValueType.COMPENSATION_SUBSCRIPTION, RecordTransformer::toCompensationSubscriptionRecord);
TRANSFORMERS.put(ValueType.ESCALATION, RecordTransformer::toEscalationRecord);

VALUE_TYPE_MAPPING.put(ValueType.DEPLOYMENT, RecordMetadata.ValueType.DEPLOYMENT);
VALUE_TYPE_MAPPING.put(
Expand Down Expand Up @@ -842,6 +843,18 @@ private static Schema.CompensationSubscriptionRecord toCompensationSubscriptionR
.build();
}

private static Schema.EscalationRecord toEscalationRecord(Record<EscalationRecordValue> record) {
final var value = record.getValue();

return Schema.EscalationRecord.newBuilder()
.setMetadata(toMetadata(record))
.setProcessInstanceKey(value.getProcessInstanceKey())
.setEscalationCode(value.getEscalationCode())
.setThrowElementId(value.getThrowElementId())
.setCatchElementId(value.getCatchElementId())
.build();
}

private static Struct toStruct(Map<?, ?> map) {
final Struct.Builder builder = Struct.newBuilder();

Expand Down
8 changes: 8 additions & 0 deletions src/main/proto/schema.proto
Original file line number Diff line number Diff line change
Expand Up @@ -531,4 +531,12 @@ message CompensationSubscriptionRecord {
int64 compensableActivityScopeKey = 10;
int64 compensableActivityInstanceKey = 11;
google.protobuf.Struct variables = 12;
}

message EscalationRecord {
RecordMetadata metadata = 1;
int64 processInstanceKey = 2;
string escalationCode = 3;
string throwElementId = 4;
string catchElementId = 5;
}
31 changes: 31 additions & 0 deletions src/test/java/io/zeebe/exporter/proto/RecordTransformTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -1005,6 +1005,27 @@ public void shouldTransformCompensationSubscriptionRecord() {
assertStruct(transformedRecord.getVariables(), recordValue.getVariables());
}

@Test
public void shouldTransformEscalationRecord() {
// given
final var recordValue = mockEscalationRecordValue();
final Record<EscalationRecordValue> mockedRecord =
mockRecord(recordValue, ValueType.ESCALATION, EscalationIntent.ESCALATED);

// when
final var transformedRecord =
(Schema.EscalationRecord) RecordTransformer.toProtobufMessage(mockedRecord);

// then
assertMetadata(transformedRecord.getMetadata(), "ESCALATION", "ESCALATED");

assertThat(transformedRecord.getProcessInstanceKey())
.isEqualTo(recordValue.getProcessInstanceKey());
assertThat(transformedRecord.getEscalationCode()).isEqualTo(recordValue.getEscalationCode());
assertThat(transformedRecord.getThrowElementId()).isEqualTo(recordValue.getThrowElementId());
assertThat(transformedRecord.getCatchElementId()).isEqualTo(recordValue.getCatchElementId());
}

private void assertEvaluatedDecision(
final Schema.DecisionEvaluationRecord.EvaluatedDecision transformedRecord,
final EvaluatedDecisionValue recordValue) {
Expand Down Expand Up @@ -1495,6 +1516,16 @@ private CompensationSubscriptionRecordValue mockCompensationSubscriptionRecordVa
return value;
}

private EscalationRecordValue mockEscalationRecordValue() {
final var value = mock(EscalationRecordValue.class);
when(value.getTenantId()).thenReturn(TENANT_ID);
when(value.getProcessInstanceKey()).thenReturn(1L);
when(value.getEscalationCode()).thenReturn("escalation-code");
when(value.getThrowElementId()).thenReturn("throw-element-id");
when(value.getCatchElementId()).thenReturn("catch-element-id");
return value;
}

private void assertVariables(final Struct variables) {
assertStruct(variables, VARIABLES);
}
Expand Down

0 comments on commit 434e3a4

Please sign in to comment.