1313import static io .camunda .migration .data .impl .logging .HistoryMigratorLogs .UNSUPPORTED_AUDIT_LOG_ENTITY_TYPE ;
1414import static io .camunda .migration .data .impl .util .ConverterUtil .getTenantId ;
1515import 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
1719import io .camunda .db .rdbms .write .domain .AuditLogDbModel ;
1820import io .camunda .db .rdbms .write .domain .AuditLogDbModel .Builder ;
2123import io .camunda .migration .data .interceptor .EntityInterceptor ;
2224import io .camunda .search .entities .AuditLogEntity ;
2325import java .util .Set ;
24- import org .camunda .bpm .engine .EntityTypes ;
2526import org .camunda .bpm .engine .history .UserOperationLogEntry ;
2627import org .jspecify .annotations .NonNull ;
2728import 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 }
0 commit comments