Skip to content

Commit

Permalink
code: Added generation of "Alle.json" containing whole object model t…
Browse files Browse the repository at this point in the history
…o JSON and web data export
  • Loading branch information
YourMJK committed Oct 11, 2024
1 parent 2925063 commit 5cb4793
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
2 changes: 2 additions & 0 deletions code/dreimetadaten/CollectionType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ enum CollectionType: String, ArgumentEnum {
case die_dr3i
case kids

static let allCasesJSONFile = "Alle.json"

var name: String {
switch self {
case .serie: return "Serie"
Expand Down
8 changes: 6 additions & 2 deletions code/dreimetadaten/Export/JSONExporter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,16 @@ struct JSONExporter {
let webDataURL: URL

func export(to outputDir: URL) throws {
let objectModels = try MetadataObjectModel(fromDatabase: db, withBaseURL: webDataURL).separateByCollectionType(withDBInfo: true)
let objectModel = try MetadataObjectModel(fromDatabase: db, withBaseURL: webDataURL)

for (objectModel, collectionType) in objectModels {
for (objectModel, collectionType) in objectModel.separateByCollectionType(withDBInfo: true) {
let jsonURL = outputDir.appendingPathComponent(collectionType.jsonFile)
let jsonString = try objectModel.jsonString()
try jsonString.write(to: jsonURL, atomically: true, encoding: .utf8)
}

let jsonURL = outputDir.appendingPathComponent(CollectionType.allCasesJSONFile)
let jsonString = try objectModel.jsonString()
try jsonString.write(to: jsonURL, atomically: true, encoding: .utf8)
}
}
6 changes: 6 additions & 0 deletions code/dreimetadaten/Export/WebDataExporter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ struct WebDataExporter {
}
}

// Export metadata of whole object model as JSON
let jsonURL = outputDir.appendingPathComponent(CollectionType.allCasesJSONFile)
referencedFilePaths.insert(jsonURL.relativePath)
let jsonString = try objectModel.jsonString()
try jsonString.write(to: jsonURL, atomically: true, encoding: .utf8)

// Check referenced files and existing files
var existingFilePaths = Set<String>()
guard let enumerator = FileManager.default.enumerator(at: outputDir, includingPropertiesForKeys: [.isRegularFileKey], options: [.skipsHiddenFiles, .producesRelativePathURLs]) else {
Expand Down

0 comments on commit 5cb4793

Please sign in to comment.