Skip to content

Commit 18d1bd0

Browse files
authored
chore(migrator): add new properties to AuditLogEntity (#1026)
#1014
1 parent bee672e commit 18d1bd0

File tree

4 files changed

+91
-48
lines changed

4 files changed

+91
-48
lines changed

data-migrator/core/src/main/java/io/camunda/migration/data/impl/interceptor/history/entity/AuditLogTransformer.java

Lines changed: 71 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
import static io.camunda.migration.data.impl.logging.HistoryMigratorLogs.UNSUPPORTED_AUDIT_LOG_ENTITY_TYPE;
1414
import static io.camunda.migration.data.impl.util.ConverterUtil.getTenantId;
1515
import static io.camunda.migration.data.impl.util.ConverterUtil.prefixDefinitionId;
16+
import static org.camunda.bpm.engine.EntityTypes.*;
17+
import static org.camunda.bpm.engine.history.UserOperationLogEntry.*;
1618

1719
import io.camunda.db.rdbms.write.domain.AuditLogDbModel;
1820
import io.camunda.db.rdbms.write.domain.AuditLogDbModel.Builder;
@@ -21,7 +23,6 @@
2123
import io.camunda.migration.data.interceptor.EntityInterceptor;
2224
import io.camunda.search.entities.AuditLogEntity;
2325
import java.util.Set;
24-
import org.camunda.bpm.engine.EntityTypes;
2526
import org.camunda.bpm.engine.history.UserOperationLogEntry;
2627
import org.jspecify.annotations.NonNull;
2728
import org.springframework.core.annotation.Order;
@@ -78,13 +79,17 @@ public void execute(UserOperationLogEntry userOperationLog, Builder builder) {
7879
.annotation(userOperationLog.getAnnotation())
7980
.tenantId(tenantId)
8081
.tenantScope(getAuditLogTenantScope(tenantId))
81-
.category(convertCategory(userOperationLog.getCategory()));
82+
.category(convertCategory(userOperationLog.getCategory()))
83+
.entityDescription(convertEntityDescription(userOperationLog))
84+
.agentElementId(null)
85+
.relatedEntityKey(null)
86+
.relatedEntityType(null);
87+
8288
// Note: auditLogKey, processInstanceKey, rootProcessInstanceKey, processDefinitionKey, userTaskKey, entityKey, timestamp, historyCleanupDate
8389
// are set externally in AuditLogMigrator
8490
// not setting entityValueType and entityOperationIntent as they internal properties meant for future-proofing purposes
8591

8692
updateEntityTypesThatDontMatchBetweenC7andC8(userOperationLog, builder);
87-
8893
}
8994

9095
/**
@@ -124,12 +129,13 @@ public void execute(UserOperationLogEntry userOperationLog, Builder builder) {
124129
*/
125130
protected AuditLogEntity.AuditLogOperationCategory convertCategory(String category) {
126131
return switch (category) {
127-
case UserOperationLogEntry.CATEGORY_ADMIN -> AuditLogEntity.AuditLogOperationCategory.ADMIN;
128-
case UserOperationLogEntry.CATEGORY_OPERATOR -> AuditLogEntity.AuditLogOperationCategory.DEPLOYED_RESOURCES;
129-
case UserOperationLogEntry.CATEGORY_TASK_WORKER -> AuditLogEntity.AuditLogOperationCategory.USER_TASKS;
132+
case CATEGORY_ADMIN -> AuditLogEntity.AuditLogOperationCategory.ADMIN;
133+
case CATEGORY_OPERATOR -> AuditLogEntity.AuditLogOperationCategory.DEPLOYED_RESOURCES;
134+
case CATEGORY_TASK_WORKER -> AuditLogEntity.AuditLogOperationCategory.USER_TASKS;
130135
default -> AuditLogEntity.AuditLogOperationCategory.UNKNOWN;
131136
};
132137
}
138+
133139
/**
134140
* Converts a Camunda 7 entity type to a Camunda 8 AuditLogEntityType.
135141
* <p>
@@ -161,24 +167,22 @@ protected AuditLogEntity.AuditLogOperationCategory convertCategory(String catego
161167
*/
162168
protected AuditLogEntity.AuditLogEntityType convertEntityType(UserOperationLogEntry userOperationLog) {
163169
return switch (userOperationLog.getEntityType()) {
164-
case EntityTypes.PROCESS_INSTANCE -> AuditLogEntity.AuditLogEntityType.PROCESS_INSTANCE;
165-
case EntityTypes.VARIABLE -> AuditLogEntity.AuditLogEntityType.VARIABLE;
166-
case EntityTypes.TASK -> AuditLogEntity.AuditLogEntityType.USER_TASK;
167-
case EntityTypes.DECISION_INSTANCE, EntityTypes.DECISION_DEFINITION, EntityTypes.DECISION_REQUIREMENTS_DEFINITION -> AuditLogEntity.AuditLogEntityType.DECISION;
168-
case EntityTypes.USER -> AuditLogEntity.AuditLogEntityType.USER;
169-
case EntityTypes.GROUP -> AuditLogEntity.AuditLogEntityType.GROUP;
170-
case EntityTypes.TENANT -> AuditLogEntity.AuditLogEntityType.TENANT;
171-
case EntityTypes.AUTHORIZATION -> AuditLogEntity.AuditLogEntityType.AUTHORIZATION;
172-
case EntityTypes.INCIDENT -> AuditLogEntity.AuditLogEntityType.INCIDENT;
173-
case EntityTypes.PROCESS_DEFINITION, EntityTypes.DEPLOYMENT -> AuditLogEntity.AuditLogEntityType.RESOURCE;
174-
case EntityTypes.GROUP_MEMBERSHIP -> AuditLogEntity.AuditLogEntityType.GROUP;
175-
case EntityTypes.TENANT_MEMBERSHIP -> AuditLogEntity.AuditLogEntityType.TENANT;
170+
case PROCESS_INSTANCE -> AuditLogEntity.AuditLogEntityType.PROCESS_INSTANCE;
171+
case VARIABLE -> AuditLogEntity.AuditLogEntityType.VARIABLE;
172+
case TASK -> AuditLogEntity.AuditLogEntityType.USER_TASK;
173+
case DECISION_INSTANCE, DECISION_DEFINITION, DECISION_REQUIREMENTS_DEFINITION -> AuditLogEntity.AuditLogEntityType.DECISION;
174+
case USER -> AuditLogEntity.AuditLogEntityType.USER;
175+
case GROUP, GROUP_MEMBERSHIP -> AuditLogEntity.AuditLogEntityType.GROUP;
176+
case TENANT, TENANT_MEMBERSHIP -> AuditLogEntity.AuditLogEntityType.TENANT;
177+
case AUTHORIZATION -> AuditLogEntity.AuditLogEntityType.AUTHORIZATION;
178+
case INCIDENT -> AuditLogEntity.AuditLogEntityType.INCIDENT;
179+
case PROCESS_DEFINITION, DEPLOYMENT -> AuditLogEntity.AuditLogEntityType.RESOURCE;
176180

177181
// Camunda 7 entity types that are currently NOT converted:
178-
// EntityTypes.BATCH, EntityTypes.IDENTITY_LINK, EntityTypes.ATTACHMENT, EntityTypes.JOB_DEFINITION,
179-
// EntityTypes.JOB, EntityTypes.EXTERNAL_TASK, EntityTypes.CASE_DEFINITION, EntityTypes.CASE_INSTANCE,
180-
// EntityTypes.METRICS, EntityTypes.TASK_METRICS, EntityTypes.OPERATION_LOG, EntityTypes.FILTER,
181-
// EntityTypes.COMMENT, EntityTypes.PROPERTY
182+
// BATCH, IDENTITY_LINK, ATTACHMENT, JOB_DEFINITION,
183+
// JOB, EXTERNAL_TASK, CASE_DEFINITION, CASE_INSTANCE,
184+
// METRICS, TASK_METRICS, OPERATION_LOG, FILTER,
185+
// COMMENT, PROPERTY
182186

183187
default -> throw new EntityInterceptorException(UNSUPPORTED_AUDIT_LOG_ENTITY_TYPE + userOperationLog.getEntityType());
184188
};
@@ -231,55 +235,55 @@ protected AuditLogEntity.AuditLogOperationType convertOperationType(UserOperatio
231235

232236
return switch (operationType) {
233237
// Task operations
234-
case UserOperationLogEntry.OPERATION_TYPE_ASSIGN,
235-
UserOperationLogEntry.OPERATION_TYPE_CLAIM,
236-
UserOperationLogEntry.OPERATION_TYPE_DELEGATE ->
238+
case OPERATION_TYPE_ASSIGN,
239+
OPERATION_TYPE_CLAIM,
240+
OPERATION_TYPE_DELEGATE ->
237241
AuditLogEntity.AuditLogOperationType.ASSIGN;
238-
case UserOperationLogEntry.OPERATION_TYPE_COMPLETE ->
242+
case OPERATION_TYPE_COMPLETE ->
239243
AuditLogEntity.AuditLogOperationType.COMPLETE;
240-
case UserOperationLogEntry.OPERATION_TYPE_SET_PRIORITY,
241-
UserOperationLogEntry.OPERATION_TYPE_SET_OWNER,
242-
UserOperationLogEntry.OPERATION_TYPE_UPDATE ->
244+
case OPERATION_TYPE_SET_PRIORITY,
245+
OPERATION_TYPE_SET_OWNER,
246+
OPERATION_TYPE_UPDATE ->
243247
AuditLogEntity.AuditLogOperationType.UPDATE;
244248

245249
// ProcessInstance operations
246-
case UserOperationLogEntry.OPERATION_TYPE_CREATE -> {
247-
if (EntityTypes.GROUP_MEMBERSHIP.equals(userOperationLog.getEntityType()) ||
248-
EntityTypes.TENANT_MEMBERSHIP.equals(userOperationLog.getEntityType())) {
250+
case OPERATION_TYPE_CREATE -> {
251+
if (GROUP_MEMBERSHIP.equals(userOperationLog.getEntityType()) ||
252+
TENANT_MEMBERSHIP.equals(userOperationLog.getEntityType())) {
249253
yield AuditLogEntity.AuditLogOperationType.ASSIGN;
250254
} else {
251255
yield AuditLogEntity.AuditLogOperationType.CREATE;
252256
}
253257
}
254-
case UserOperationLogEntry.OPERATION_TYPE_DELETE -> {
255-
if (EntityTypes.PROCESS_INSTANCE.equals(userOperationLog.getEntityType())) {
258+
case OPERATION_TYPE_DELETE -> {
259+
if (PROCESS_INSTANCE.equals(userOperationLog.getEntityType())) {
256260
yield AuditLogEntity.AuditLogOperationType.CANCEL;
257-
} else if (EntityTypes.GROUP_MEMBERSHIP.equals(userOperationLog.getEntityType()) ||
258-
EntityTypes.TENANT_MEMBERSHIP.equals(userOperationLog.getEntityType())) {
261+
} else if (GROUP_MEMBERSHIP.equals(userOperationLog.getEntityType()) ||
262+
TENANT_MEMBERSHIP.equals(userOperationLog.getEntityType())) {
259263
yield AuditLogEntity.AuditLogOperationType.UNASSIGN;
260264
} else {
261265
yield AuditLogEntity.AuditLogOperationType.DELETE;
262266
}
263267
}
264-
case UserOperationLogEntry.OPERATION_TYPE_MODIFY_PROCESS_INSTANCE ->
268+
case OPERATION_TYPE_MODIFY_PROCESS_INSTANCE ->
265269
AuditLogEntity.AuditLogOperationType.MODIFY;
266-
case UserOperationLogEntry.OPERATION_TYPE_MIGRATE ->
270+
case OPERATION_TYPE_MIGRATE ->
267271
AuditLogEntity.AuditLogOperationType.MIGRATE;
268-
case UserOperationLogEntry.OPERATION_TYPE_DELETE_HISTORY, UserOperationLogEntry.OPERATION_TYPE_REMOVE_VARIABLE ->
272+
case OPERATION_TYPE_DELETE_HISTORY, OPERATION_TYPE_REMOVE_VARIABLE ->
269273
AuditLogEntity.AuditLogOperationType.DELETE;
270274

271275
// Variable operations
272-
case UserOperationLogEntry.OPERATION_TYPE_MODIFY_VARIABLE, UserOperationLogEntry.OPERATION_TYPE_SET_VARIABLE,
273-
UserOperationLogEntry.OPERATION_TYPE_SET_VARIABLES ->
276+
case OPERATION_TYPE_MODIFY_VARIABLE, OPERATION_TYPE_SET_VARIABLE,
277+
OPERATION_TYPE_SET_VARIABLES ->
274278
AuditLogEntity.AuditLogOperationType.UPDATE;
275279

276280
// DecisionDefinition operations
277-
case UserOperationLogEntry.OPERATION_TYPE_EVALUATE ->
281+
case OPERATION_TYPE_EVALUATE ->
278282
AuditLogEntity.AuditLogOperationType.EVALUATE;
279283

280284
// Incident operations
281-
case UserOperationLogEntry.OPERATION_TYPE_RESOLVE -> {
282-
if (EntityTypes.PROCESS_INSTANCE.equals(userOperationLog.getEntityType())) {
285+
case OPERATION_TYPE_RESOLVE -> {
286+
if (PROCESS_INSTANCE.equals(userOperationLog.getEntityType())) {
283287
yield AuditLogEntity.AuditLogOperationType.RESOLVE;
284288
} else {
285289
yield AuditLogEntity.AuditLogOperationType.UPDATE;
@@ -291,6 +295,25 @@ protected AuditLogEntity.AuditLogOperationType convertOperationType(UserOperatio
291295
};
292296
}
293297

298+
/**
299+
* Converts the entity description for certain entity types based on the user operation log entry.
300+
* @param userOperationLog the Camunda 7 user operation log entry to extract the entity description from
301+
* @return the converted entity description, or null if not applicable
302+
*/
303+
protected String convertEntityDescription(UserOperationLogEntry userOperationLog) {
304+
return switch (userOperationLog.getEntityType()) {
305+
case VARIABLE -> {
306+
if (OPERATION_TYPE_DELETE_HISTORY.equals(userOperationLog.getOperationType())) {
307+
yield userOperationLog.getNewValue();
308+
} else {
309+
yield null; // for rest of the operations, the variable name is not stored
310+
}
311+
}
312+
case USER, GROUP, TENANT -> userOperationLog.getNewValue();
313+
default -> null;
314+
};
315+
}
316+
294317
/**
295318
* Updates entity types for special cases where C7 and C8 handle them differently.
296319
* <p>
@@ -309,11 +332,11 @@ protected AuditLogEntity.AuditLogOperationType convertOperationType(UserOperatio
309332
* @param builder the audit log builder to update
310333
*/
311334
protected void updateEntityTypesThatDontMatchBetweenC7andC8(UserOperationLogEntry userOperationLog, Builder builder) {
312-
if (UserOperationLogEntry.OPERATION_TYPE_RESOLVE.equals(userOperationLog.getOperationType())
313-
&& EntityTypes.PROCESS_INSTANCE.equals(userOperationLog.getEntityType())) {
335+
if (OPERATION_TYPE_RESOLVE.equals(userOperationLog.getOperationType())
336+
&& PROCESS_INSTANCE.equals(userOperationLog.getEntityType())) {
314337
builder.entityType(AuditLogEntity.AuditLogEntityType.INCIDENT);
315-
} else if (UserOperationLogEntry.OPERATION_TYPE_SET_VARIABLE.equals(userOperationLog.getOperationType())
316-
|| UserOperationLogEntry.OPERATION_TYPE_SET_VARIABLES.equals(userOperationLog.getOperationType())) {
338+
} else if (OPERATION_TYPE_SET_VARIABLE.equals(userOperationLog.getOperationType())
339+
|| OPERATION_TYPE_SET_VARIABLES.equals(userOperationLog.getOperationType())) {
317340
builder.entityType(AuditLogEntity.AuditLogEntityType.VARIABLE);
318341
}
319342
}

data-migrator/qa/integration-tests/src/test/java/io/camunda/migration/data/qa/history/entity/HistoryAuditLogAdminTest.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ public void shouldMigrateAuditLogsForUser() {
8383
assertThat(log.entityType()).isEqualTo(AuditLogEntity.AuditLogEntityType.USER);
8484
assertThat(log.operationType()).isEqualTo(AuditLogEntity.AuditLogOperationType.CREATE);
8585
assertThat(log.result()).isEqualTo(AuditLogEntity.AuditLogOperationResult.SUCCESS);
86+
assertThat(log.agentElementId()).isNull();
87+
assertThat(log.relatedEntityKey()).isNull();
88+
assertThat(log.relatedEntityType()).isNull();
8689
}
8790

8891
@Test
@@ -106,6 +109,7 @@ public void shouldMigrateAuditLogsForCreateUser() {
106109
assertThat(logs).extracting(AuditLogEntity::entityType).containsOnly(AuditLogEntity.AuditLogEntityType.USER);
107110
assertThat(logs).extracting(AuditLogEntity::operationType)
108111
.containsOnly(AuditLogEntity.AuditLogOperationType.CREATE);
112+
assertThat(logs).extracting(AuditLogEntity::entityDescription).contains("newUserId");
109113
}
110114

111115
@Test
@@ -133,6 +137,7 @@ public void shouldMigrateAuditLogsForUpdateUser() {
133137
assertThat(logs).extracting(AuditLogEntity::entityType).containsOnly(AuditLogEntity.AuditLogEntityType.USER);
134138
assertThat(logs).extracting(AuditLogEntity::operationType)
135139
.containsOnly(AuditLogEntity.AuditLogOperationType.UPDATE);
140+
assertThat(logs).extracting(AuditLogEntity::entityDescription).contains("newUserId");
136141
}
137142

138143
@Test
@@ -158,6 +163,7 @@ public void shouldMigrateAuditLogsForDeleteUser() {
158163
assertThat(logs).extracting(AuditLogEntity::entityType).containsOnly(AuditLogEntity.AuditLogEntityType.USER);
159164
assertThat(logs).extracting(AuditLogEntity::operationType)
160165
.containsOnly(AuditLogEntity.AuditLogOperationType.DELETE);
166+
assertThat(logs).extracting(AuditLogEntity::entityDescription).contains("newUserId");
161167
}
162168

163169
@Test
@@ -180,6 +186,7 @@ public void shouldMigrateAuditLogsForCreateGroup() {
180186

181187
assertThat(logs).extracting(AuditLogEntity::entityType).containsOnly(AuditLogEntity.AuditLogEntityType.GROUP);
182188
assertThat(logs).extracting(AuditLogEntity::operationType).containsOnly(AuditLogEntity.AuditLogOperationType.CREATE);
189+
assertThat(logs).extracting(AuditLogEntity::entityDescription).contains("newGroupId");
183190
}
184191

185192
@Test
@@ -207,6 +214,7 @@ public void shouldMigrateAuditLogsForUpdateGroup() {
207214
assertThat(logs).extracting(AuditLogEntity::entityType).containsOnly(AuditLogEntity.AuditLogEntityType.GROUP);
208215
assertThat(logs).extracting(AuditLogEntity::operationType)
209216
.containsOnly(AuditLogEntity.AuditLogOperationType.UPDATE);
217+
assertThat(logs).extracting(AuditLogEntity::entityDescription).contains("newGroupId");
210218
}
211219

212220
@Test
@@ -233,6 +241,7 @@ public void shouldMigrateAuditLogsForDeleteGroup() {
233241
assertThat(logs).extracting(AuditLogEntity::entityType).containsOnly(AuditLogEntity.AuditLogEntityType.GROUP);
234242
assertThat(logs).extracting(AuditLogEntity::operationType)
235243
.containsOnly(AuditLogEntity.AuditLogOperationType.DELETE);
244+
assertThat(logs).extracting(AuditLogEntity::entityDescription).contains("newGroupId");
236245
}
237246

238247
@Test
@@ -256,6 +265,7 @@ public void shouldMigrateAuditLogsForCreateTenant() {
256265

257266
assertThat(logs).extracting(AuditLogEntity::entityType).containsOnly(AuditLogEntity.AuditLogEntityType.TENANT);
258267
assertThat(logs).extracting(AuditLogEntity::operationType).containsOnly(AuditLogEntity.AuditLogOperationType.CREATE);
268+
assertThat(logs).extracting(AuditLogEntity::entityDescription).contains("newTenantId");
259269
}
260270

261271
@Test
@@ -283,6 +293,7 @@ public void shouldMigrateAuditLogsForUpdateTenant() {
283293
assertThat(logs).extracting(AuditLogEntity::entityType).containsOnly(AuditLogEntity.AuditLogEntityType.TENANT);
284294
assertThat(logs).extracting(AuditLogEntity::operationType)
285295
.containsOnly(AuditLogEntity.AuditLogOperationType.UPDATE);
296+
assertThat(logs).extracting(AuditLogEntity::entityDescription).contains("newTenantId");
286297
}
287298

288299
@Test
@@ -309,6 +320,7 @@ public void shouldMigrateAuditLogsForDeleteTenant() {
309320
assertThat(logs).extracting(AuditLogEntity::entityType).containsOnly(AuditLogEntity.AuditLogEntityType.TENANT);
310321
assertThat(logs).extracting(AuditLogEntity::operationType)
311322
.containsOnly(AuditLogEntity.AuditLogOperationType.DELETE);
323+
assertThat(logs).extracting(AuditLogEntity::entityDescription).contains("newTenantId");
312324
}
313325

314326
@Test

data-migrator/qa/integration-tests/src/test/java/io/camunda/migration/data/qa/history/entity/HistoryAuditLogTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,10 @@ public void shouldMigrateAuditLogs() {
8686
assertThat(log.tenantId()).isEqualTo(C8_DEFAULT_TENANT);
8787
assertThat(log.tenantScope()).isEqualTo(AuditLogEntity.AuditLogTenantScope.GLOBAL);
8888
assertThat(log.result()).isEqualTo(AuditLogEntity.AuditLogOperationResult.SUCCESS);
89+
assertThat(log.agentElementId()).isNull();
90+
assertThat(log.relatedEntityKey()).isNull();
91+
assertThat(log.relatedEntityType()).isNull();
92+
8993
}
9094

9195
@Test
@@ -449,6 +453,7 @@ public void shouldMigrateAuditLogsForDeleteVariableHistory() {
449453
assertThat(logs).hasSize(1);
450454
assertThat(logs).extracting(AuditLogEntity::entityType).contains(AuditLogEntity.AuditLogEntityType.VARIABLE);
451455
assertThat(logs).extracting(AuditLogEntity::operationType).contains(AuditLogEntity.AuditLogOperationType.DELETE);
456+
assertThat(logs).extracting(AuditLogEntity::entityDescription).contains("testVar");
452457
}
453458

454459
@Test

data-migrator/qa/integration-tests/src/test/java/io/camunda/migration/data/qa/history/entity/HistoryAuditLogUserTaskTest.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@ public void shouldMigrateAuditLogsForTask() {
8989
assertThat(log.tenantId()).isEqualTo(C8_DEFAULT_TENANT);
9090
assertThat(log.tenantScope()).isEqualTo(AuditLogEntity.AuditLogTenantScope.GLOBAL);
9191
assertThat(log.result()).isEqualTo(AuditLogEntity.AuditLogOperationResult.SUCCESS);
92+
assertThat(log.agentElementId()).isNull();
93+
assertThat(log.relatedEntityKey()).isNull();
94+
assertThat(log.relatedEntityType()).isNull();
9295
}
9396

9497
@Test

0 commit comments

Comments
 (0)