export method
Implementation
Future<DVExportArchive> export({
required Object subject,
String? requestedBy,
String? runBy,
}) async {
final DVPrivacySubjectRef ref = _ref(subject);
final List<String> codes = <String>[];
final Map<String, List<Map<String, Object?>>> records =
<String, List<Map<String, Object?>>>{};
int redacted = 0;
final Map<String, List<DVRecord>> walk = await _walk(subject);
for (final DVPrivacyModel model in models) {
final List<DVRecord> rows = walk[model.name] ?? const <DVRecord>[];
if (rows.isEmpty) continue;
records[model.name] = <Map<String, Object?>>[
for (final DVRecord row in rows)
<String, Object?>{
for (final String column in model.table.columns)
column:
model.otherSubjects.contains(column) &&
row.values[column] != null &&
'${row.values[column]}' != '$subject'
? () {
redacted++;
return null;
}()
: row.values[column],
},
];
}
if (redacted > 0) {
_report(
codes,
'DV-PRIVACY-006',
'$redacted fields naming another subject were left out of the '
'export; only the requesting subject\'s contribution is included.',
DVLogLevel.info,
ref,
);
}
final Map<String, Map<String, Object?>> fromAdapters =
<String, Map<String, Object?>>{};
final List<String> unreached = <String>[];
for (final DVPrivacyAdapter adapter in adapters) {
try {
fromAdapters[adapter.name] = await adapter.export(ref);
} on Object {
unreached.add(adapter.name);
}
}
await _record(
'export',
ref,
requestedAt: _now(),
completedAt: _now(),
requestedBy: requestedBy,
runBy: runBy,
covered: <String>[...records.keys, ...fromAdapters.keys],
kept: 0,
complete: unreached.isEmpty,
);
return DVExportArchive._(
records: records,
adapters: fromAdapters,
unreached: unreached,
codes: codes,
);
}