mirror of
https://github.com/Theodor-Springmann-Stiftung/musenalm.git
synced 2025-10-28 16:55:32 +00:00
Relationen, fehlt -PreferredTitle für Entries -Überflüssige Felder in Contents
This commit is contained in:
@@ -4,24 +4,26 @@ import (
|
||||
"encoding/xml"
|
||||
"fmt"
|
||||
"io"
|
||||
"log/slog"
|
||||
"os"
|
||||
"sync"
|
||||
|
||||
"github.com/Theodor-Springmann-Stiftung/musenalm/helpers/datatypes"
|
||||
)
|
||||
|
||||
type AccessDB struct {
|
||||
Orte *Orte
|
||||
Akteure *Akteure
|
||||
Reihen *Reihentitel
|
||||
Bände *Bände
|
||||
Inhalte *Inhalte
|
||||
Relationen_Bände_Akteure *Relationen_Bände_Akteure
|
||||
Relationen_Inhalte_Akteure *Relationen_Inhalte_Akteure
|
||||
Relationen_Bände_Reihen *Relationen_Bände_Reihen
|
||||
BIBLIO *map[int]BIBLIOEintrag
|
||||
Orte Orte
|
||||
Akteure Akteure
|
||||
Reihen Reihentitel
|
||||
Bände Bände
|
||||
Inhalte Inhalte
|
||||
Relationen_Bände_Akteure Relationen_Bände_Akteure
|
||||
Relationen_Inhalte_Akteure Relationen_Inhalte_Akteure
|
||||
Relationen_Bände_Reihen Relationen_Bände_Reihen
|
||||
BIBLIO map[int]BIBLIOEintrag
|
||||
}
|
||||
|
||||
func ReadAccessDB(path string) (*AccessDB, error) {
|
||||
func ReadAccessDB(path string, logger *slog.Logger) (*AccessDB, error) {
|
||||
var Akteure Akteure
|
||||
var Reihentitel Reihentitel
|
||||
var Bände Bände
|
||||
@@ -32,57 +34,89 @@ func ReadAccessDB(path string) (*AccessDB, error) {
|
||||
var Relationen_Inhalte_Akteure Relationen_Inhalte_Akteure
|
||||
var BIBLIO BIBLIOEinträge
|
||||
|
||||
if err := unmarshalFile(path+"Akteure.xml", &Akteure); err != nil {
|
||||
return nil, err
|
||||
var DB AccessDB
|
||||
wg := sync.WaitGroup{}
|
||||
wg.Add(9)
|
||||
|
||||
go func() {
|
||||
if err := unmarshalFile(path+"GM-BIBLIO.xml", &BIBLIO); err != nil {
|
||||
logger.Error("Error while unmarshalling GM-BIBLIO.xml: ", "error", err, "path", path+"GM-BIBLIO.xml")
|
||||
}
|
||||
DB.BIBLIO = datatypes.MakeMap(BIBLIO.Einträge, func(e BIBLIOEintrag) int { return e.Nummer })
|
||||
wg.Done()
|
||||
}()
|
||||
|
||||
go func() {
|
||||
if err := unmarshalFile(path+"Akteure.xml", &Akteure); err != nil {
|
||||
logger.Error("Error while unmarshalling Akteure.xml: ", "error", err, "path", path+"Akteure.xml")
|
||||
}
|
||||
DB.Akteure = Akteure
|
||||
wg.Done()
|
||||
}()
|
||||
|
||||
go func() {
|
||||
if err := unmarshalFile(path+"Orte.xml", &Orte); err != nil {
|
||||
logger.Error("Error while unmarshalling Orte.xml: ", "error", err, "path", path+"Orte.xml")
|
||||
}
|
||||
DB.Orte = Orte
|
||||
wg.Done()
|
||||
}()
|
||||
|
||||
go func() {
|
||||
if err := unmarshalFile(path+"Reihen.xml", &Reihentitel); err != nil {
|
||||
logger.Error("Error while unmarshalling Reihen.xml: ", "error", err, "path", path+"Reihen.xml")
|
||||
}
|
||||
DB.Reihen = Reihentitel
|
||||
wg.Done()
|
||||
}()
|
||||
|
||||
go func() {
|
||||
if err := unmarshalFile(path+"Baende.xml", &Bände); err != nil {
|
||||
logger.Error("Error while unmarshalling Baende.xml: ", "error", err, "path", path+"Baende.xml")
|
||||
}
|
||||
DB.Bände = Bände
|
||||
wg.Done()
|
||||
}()
|
||||
|
||||
go func() {
|
||||
if err := unmarshalFile(path+"Inhalte.xml", &Inhalte); err != nil {
|
||||
logger.Error("Error while unmarshalling Inhalte.xml: ", "error", err, "path", path+"Inhalte.xml")
|
||||
}
|
||||
DB.Inhalte = Inhalte
|
||||
wg.Done()
|
||||
}()
|
||||
|
||||
go func() {
|
||||
if err := unmarshalFile(path+"_RELATION_BaendeAkteure.xml", &Relationen_Bände_Akteure); err != nil {
|
||||
logger.Error("Error while unmarshalling RELATION_BaendeAkteure.xml: ", "error", err, "path", path+"_RELATION_BaendeAkteure.xml")
|
||||
}
|
||||
DB.Relationen_Bände_Akteure = Relationen_Bände_Akteure
|
||||
wg.Done()
|
||||
}()
|
||||
|
||||
go func() {
|
||||
if err := unmarshalFile(path+"_RELATION_BaendeReihen.xml", &Relationen_Bände_Reihen); err != nil {
|
||||
logger.Error("Error while unmarshalling RELATION_BaendeReihen.xml: ", "error", err, "path", path+"_RELATION_BaendeReihen.xml")
|
||||
}
|
||||
DB.Relationen_Bände_Reihen = Relationen_Bände_Reihen
|
||||
wg.Done()
|
||||
}()
|
||||
|
||||
go func() {
|
||||
if err := unmarshalFile(path+"_RELATION_InhalteAkteure.xml", &Relationen_Inhalte_Akteure); err != nil {
|
||||
logger.Error("Error while unmarshalling RELATION_InhalteAkteure.xml: ", "error", err, "path", path+"_RELATION_InhalteAkteure.xml")
|
||||
}
|
||||
DB.Relationen_Inhalte_Akteure = Relationen_Inhalte_Akteure
|
||||
wg.Done()
|
||||
}()
|
||||
|
||||
wg.Wait()
|
||||
|
||||
if len(DB.BIBLIO) == 0 || len(DB.Akteure.Akteure) == 0 || len(DB.Orte.Orte) == 0 || len(DB.Reihen.Reihen) == 0 || len(DB.Bände.Bände) == 0 || len(DB.Inhalte.Inhalte) == 0 || len(DB.Relationen_Bände_Akteure.Relationen) == 0 || len(DB.Relationen_Bände_Reihen.Relationen) == 0 || len(DB.Relationen_Inhalte_Akteure.Relationen) == 0 {
|
||||
return nil, fmt.Errorf("Source files could not be read")
|
||||
}
|
||||
|
||||
if err := unmarshalFile(path+"Orte.xml", &Orte); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if err := unmarshalFile(path+"Reihen.xml", &Reihentitel); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if err := unmarshalFile(path+"Baende.xml", &Bände); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if err := unmarshalFile(path+"Inhalte.xml", &Inhalte); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if err := unmarshalFile(path+"_RELATION_BaendeAkteure.xml", &Relationen_Bände_Akteure); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if err := unmarshalFile(path+"_RELATION_BaendeReihen.xml", &Relationen_Bände_Reihen); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if err := unmarshalFile(path+"_RELATION_InhalteAkteure.xml", &Relationen_Inhalte_Akteure); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if err := unmarshalFile(path+"GM-BIBLIO.xml", &BIBLIO); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var BIBLIOM = datatypes.MakeMap(BIBLIO.Einträge, func(e BIBLIOEintrag) int { return e.Nummer })
|
||||
|
||||
lib := AccessDB{
|
||||
Orte: &Orte,
|
||||
Akteure: &Akteure,
|
||||
Reihen: &Reihentitel,
|
||||
Bände: &Bände,
|
||||
Inhalte: &Inhalte,
|
||||
Relationen_Bände_Akteure: &Relationen_Bände_Akteure,
|
||||
Relationen_Bände_Reihen: &Relationen_Bände_Reihen,
|
||||
Relationen_Inhalte_Akteure: &Relationen_Inhalte_Akteure,
|
||||
BIBLIO: &BIBLIOM,
|
||||
}
|
||||
|
||||
return &lib, nil
|
||||
return &DB, nil
|
||||
}
|
||||
|
||||
func unmarshalFile[T any](filename string, data *T) error {
|
||||
|
||||
@@ -16,12 +16,12 @@ type Relation_Band_Reihe struct {
|
||||
|
||||
type Relationen_Inhalte_Akteure struct {
|
||||
XMLName xml.Name `xml:"dataroot"`
|
||||
Relationen []Relation_Inhalt_akteur `xml:"_x002A_RELATION_InhalteAkteure"`
|
||||
Relationen []Relation_Inhalt_Akteur `xml:"_x002A_RELATION_InhalteAkteure"`
|
||||
}
|
||||
|
||||
type Relation_Inhalt_akteur struct {
|
||||
type Relation_Inhalt_Akteur struct {
|
||||
ID string `xml:"ID"`
|
||||
Band string `xml:"INHALT"`
|
||||
Inhalt string `xml:"INHALT"`
|
||||
Relation string `xml:"BEZIEHUNG"`
|
||||
Akteur string `xml:"AKTEUR"`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user