package jnpf.dmsIntegration.audit; import jnpf.audit.AuditConsts; import jnpf.audit.model.AuditEventDTO; import jnpf.audit.sdk.AuditClient; import org.springframework.beans.factory.ObjectProvider; import org.springframework.stereotype.Component; @Component public class DmsAuditAdapter { private final ObjectProvider auditClient; public DmsAuditAdapter(ObjectProvider auditClient) { this.auditClient = auditClient; } public void dataChange(String actionCode, String actionLabel, String table, String id, String reason, String extra) { record(AuditConsts.TYPE_DATA_CHANGE, actionCode, actionLabel, table, id, reason, extra); } public void permissionDecision(boolean allowed, String actionLabel, String resourceId, String extra) { record(AuditConsts.TYPE_BIZ_ACTION, allowed ? "PERMISSION_ALLOW" : "PERMISSION_DENY", actionLabel, "dms_permission_resources", resourceId, null, extra); } private void record(String eventType, String actionCode, String actionLabel, String table, String id, String reason, String extra) { auditClient.ifAvailable(client -> client.record(AuditEventDTO.builder() .eventType(eventType) .actionCode(actionCode) .actionLabel(actionLabel) .bizModule("DMS_PERMISSION") .bizType("DMS_PERMISSION") .targetTable(table) .targetId(id) .reason(reason) .extra(extra) .sourceLayer(3) .build())); } }