diff --git a/; b/; new file mode 100644 index 0000000..2c06117 --- /dev/null +++ b/; @@ -0,0 +1,25 @@ +package xmlmodels + +import "encoding/xml" + +type Inhalte struct { + XMLName xml.Name `xml:"dataroot"` + Inhalte []Inhalt `xml:"Inhalte"` +} + +type Inhalt struct { + ID int `xml:"ID"` + Titelangabe string `xml:"TITEL"` + Urheberangabe string `xml:"AUTOR"` + Band int `xml:"BAND"` + Objektnummer string `xml:"OBJEKTNUMMER"` + Incipit string `xml:"INCIPIT"` + Paginierung string `xml:"PAGINIERUNG"` + Typ Typ `xml:"TYP"` + Anmerkungen string `xml:"ANMERKUNGEN"` + Seite string `xml:"SEITE"` +} + +type Typ struct { + Value []string `xml:"Value"` +} diff --git a/dbmodels/agent.go b/dbmodels/agent.go index f380285..fa19deb 100644 --- a/dbmodels/agent.go +++ b/dbmodels/agent.go @@ -92,11 +92,11 @@ func (a *Agent) SetAnnotation(annotation string) { a.Set(ANNOTATION_FIELD, annotation) } -func (a *Agent) MusenalmID() string { - return a.GetString(MUSENALMID_FIELD) +func (a *Agent) MusenalmID() int { + return a.GetInt(MUSENALMID_FIELD) } -func (a *Agent) SetMusenalmID(id string) { +func (a *Agent) SetMusenalmID(id int) { a.Set(MUSENALMID_FIELD, id) } diff --git a/dbmodels/content.go b/dbmodels/content.go index 4ba02f1..3fe9d8a 100644 --- a/dbmodels/content.go +++ b/dbmodels/content.go @@ -173,11 +173,11 @@ func (c *Content) SetEntry(entry string) { c.Set(ENTRIES_TABLE, entry) } -func (c *Content) MusenalmID() string { - return c.GetString(MUSENALMID_FIELD) +func (c *Content) MusenalmID() int { + return c.GetInt(MUSENALMID_FIELD) } -func (c *Content) SetMusenalmID(musenalmID string) { +func (c *Content) SetMusenalmID(musenalmID int) { c.Set(MUSENALMID_FIELD, musenalmID) } diff --git a/dbmodels/entry.go b/dbmodels/entry.go index d0a799f..45e749b 100644 --- a/dbmodels/entry.go +++ b/dbmodels/entry.go @@ -200,11 +200,11 @@ func (e *Entry) SetDeprecated(deprecated Deprecated) { e.Set(MUSENALM_DEPRECATED_FIELD, deprecated) } -func (e *Entry) MusenalmID() string { - return e.GetString(MUSENALMID_FIELD) +func (e *Entry) MusenalmID() int { + return e.GetInt(MUSENALMID_FIELD) } -func (e *Entry) SetMusenalmID(musenalmID string) { +func (e *Entry) SetMusenalmID(musenalmID int) { e.Set(MUSENALMID_FIELD, musenalmID) } diff --git a/dbmodels/fts5.go b/dbmodels/fts5.go index e3cb6e3..704e8b2 100644 --- a/dbmodels/fts5.go +++ b/dbmodels/fts5.go @@ -220,7 +220,6 @@ func FTS5ValuesContent(content *Content, entry *Entry, agents []*Agent) []string entrystring += "; [o.J.]" } - strconv.Itoa(entry.Year()) return []string{ content.PreferredTitle(), content.VariantTitle(), @@ -237,7 +236,7 @@ func FTS5ValuesContent(content *Content, entry *Entry, agents []*Agent) []string strconv.FormatFloat(content.Numbering(), 'f', 3, 64), entrystring, agentstring, - content.MusenalmID(), + strconv.Itoa(content.MusenalmID()), datatypes.DeleteTags(content.Annotation()), datatypes.DeleteTags(content.Comment()), } @@ -291,7 +290,7 @@ func FTS5ValuesEntry(entry *Entry, places []*Place, agents []*Agent, series []*S placestring, agentstring, seriesstring, - entry.MusenalmID(), + strconv.Itoa(entry.MusenalmID()), datatypes.DeleteTags(entry.Annotation()), datatypes.DeleteTags(entry.Comment()), } diff --git a/dbmodels/functions.go b/dbmodels/functions.go index 09ad1cf..70459a2 100644 --- a/dbmodels/functions.go +++ b/dbmodels/functions.go @@ -13,7 +13,7 @@ func SetCreatedUpdatedFields(fieldlist *core.FieldsList) { } func SetMusenalmIDField(fieldlist *core.FieldsList) { - fieldlist.Add(&core.TextField{Name: MUSENALMID_FIELD, Max: 64, Required: false}) + fieldlist.Add(&core.NumberField{Name: MUSENALMID_FIELD, Required: true}) } func SetEditorStateField(fieldlist *core.FieldsList) { diff --git a/dbmodels/place.go b/dbmodels/place.go index 79b42d8..9f0f9bb 100644 --- a/dbmodels/place.go +++ b/dbmodels/place.go @@ -58,11 +58,11 @@ func (p *Place) SetAnnotation(annotation string) { p.Set(ANNOTATION_FIELD, annotation) } -func (p *Place) MusenalmID() string { - return p.GetString(MUSENALMID_FIELD) +func (p *Place) MusenalmID() int { + return p.GetInt(MUSENALMID_FIELD) } -func (p *Place) SetMusenalmID(id string) { +func (p *Place) SetMusenalmID(id int) { p.Set(MUSENALMID_FIELD, id) } diff --git a/dbmodels/series.go b/dbmodels/series.go index 18fe0fa..de1c003 100644 --- a/dbmodels/series.go +++ b/dbmodels/series.go @@ -56,11 +56,11 @@ func (s *Series) SetAnnotation(annotation string) { s.Set(ANNOTATION_FIELD, annotation) } -func (s *Series) MusenalmID() string { - return s.GetString(MUSENALMID_FIELD) +func (s *Series) MusenalmID() int { + return s.GetInt(MUSENALMID_FIELD) } -func (s *Series) SetMusenalmID(id string) { +func (s *Series) SetMusenalmID(id int) { s.Set(MUSENALMID_FIELD, id) } diff --git a/migrations/1739007272_insert_data.go b/migrations/1739007272_insert_data.go index f387061..a9aa017 100644 --- a/migrations/1739007272_insert_data.go +++ b/migrations/1739007272_insert_data.go @@ -21,15 +21,15 @@ func init() { adb.Reihen = xmlmodels.SanitizeReihen(adb.Reihen, adb.Relationen_Bände_Reihen) - var agentsmap map[string]*dbmodels.Agent + var agentsmap map[int]*dbmodels.Agent var placesmap map[string]*dbmodels.Place var placesmapid map[string]*dbmodels.Place - var seriesmap map[string]*dbmodels.Series - var entriesmap map[string]*dbmodels.Entry + var seriesmap map[int]*dbmodels.Series + var entriesmap map[int]*dbmodels.Entry var entriesmapid map[string]*dbmodels.Entry var seriesmapid map[string]*dbmodels.Series var agentsmapid map[string]*dbmodels.Agent - var contentsmap map[string]*dbmodels.Content + var contentsmap map[int]*dbmodels.Content var r_entries_series map[string][]*dbmodels.REntriesSeries var r_entries_agents map[string][]*dbmodels.REntriesAgents var r_contents_agents map[string][]*dbmodels.RContentsAgents @@ -50,7 +50,7 @@ func init() { } else { panic(err) } - agentsmap = datatypes.MakeMap(agents, func(record *dbmodels.Agent) string { return record.MusenalmID() }) + agentsmap = datatypes.MakeMap(agents, func(record *dbmodels.Agent) int { return record.MusenalmID() }) agentsmapid = datatypes.MakeMap(agents, func(record *dbmodels.Agent) string { return record.Id }) wg.Done() }() @@ -79,7 +79,7 @@ func init() { app.Logger().Error("Error saving record", "error", err, "record", record) } } - seriesmap = datatypes.MakeMap(series, func(record *dbmodels.Series) string { return record.MusenalmID() }) + seriesmap = datatypes.MakeMap(series, func(record *dbmodels.Series) int { return record.MusenalmID() }) seriesmapid = datatypes.MakeMap(series, func(record *dbmodels.Series) string { return record.Id }) wg.Done() }() @@ -96,7 +96,7 @@ func init() { } } - entriesmap = datatypes.MakeMap(entries, func(record *dbmodels.Entry) string { return record.MusenalmID() }) + entriesmap = datatypes.MakeMap(entries, func(record *dbmodels.Entry) int { return record.MusenalmID() }) entriesmapid = datatypes.MakeMap(entries, func(record *dbmodels.Entry) string { return record.Id }) wg.Add(2) @@ -125,7 +125,7 @@ func init() { app.Logger().Error("Error saving record", "error", err, "record", record) } } - contentsmap = datatypes.MakeMap(contents, func(record *dbmodels.Content) string { return record.MusenalmID() }) + contentsmap = datatypes.MakeMap(contents, func(record *dbmodels.Content) int { return record.MusenalmID() }) wg.Done() }() diff --git a/migrations/seed/contents.go b/migrations/seed/contents.go index e564ce3..c1d48e3 100644 --- a/migrations/seed/contents.go +++ b/migrations/seed/contents.go @@ -3,6 +3,7 @@ package seed import ( "fmt" "log" + "log/slog" "os" "path/filepath" "strconv" @@ -19,7 +20,7 @@ const NO_TITLE = "[No Title]" func RecordsFromInhalte( app core.App, inhalte xmlmodels.Inhalte, - entries map[string]*dbmodels.Entry, + entries map[int]*dbmodels.Entry, ) ([]*dbmodels.Content, error) { collection, err := app.FindCollectionByNameOrId(dbmodels.CONTENTS_TABLE) records := make([]*dbmodels.Content, 0, len(inhalte.Inhalte)) @@ -127,9 +128,9 @@ func commatizeArray(array []string) string { return array[0] } -func getImages(path string) map[string][]string { +func getImages(path string) map[int][]string { /// FIXED: there is a bug somewhere, where files ending with numbers after a comma (",001") etc dont get added - ret := make(map[string][]string) + ret := make(map[int][]string) if _, err := os.Stat(path); os.IsNotExist(err) { return ret } @@ -142,10 +143,15 @@ func getImages(path string) map[string][]string { if len(basesplit) >= 3 { commaseperatorsplit := strings.Split(basesplit[2], ",") id := commaseperatorsplit[0] - if _, ok := ret[id]; !ok { - ret[id] = make([]string, 0) + no, err := strconv.Atoi(id) + if err != nil { + slog.Error("Error parsing id", "error", err, "id", id) + return nil } - ret[id] = append(ret[id], path) + if _, ok := ret[no]; !ok { + ret[no] = make([]string, 0) + } + ret[no] = append(ret[no], path) } } return nil diff --git a/migrations/seed/entries.go b/migrations/seed/entries.go index f6deff7..6457448 100644 --- a/migrations/seed/entries.go +++ b/migrations/seed/entries.go @@ -15,6 +15,7 @@ import ( func RecordsFromBände( app core.App, adb xmlmodels.AccessDB, + // INFO: this is a string map, bc it's not by ID but by place name places map[string]*dbmodels.Place, ) ([]*dbmodels.Entry, error) { collection, err := app.FindCollectionByNameOrId(dbmodels.ENTRIES_TABLE) @@ -31,12 +32,12 @@ func RecordsFromBände( } // INFO: lets make some maps to speed this up - omap := datatypes.MakeMap(adb.Orte.Orte, func(o xmlmodels.Ort) string { return o.ID }) + omap := datatypes.MakeMap(adb.Orte.Orte, func(o xmlmodels.Ort) int { return o.ID }) relmap := datatypes.MakeMultiMap( adb.Relationen_Bände_Reihen.Relationen, - func(r xmlmodels.Relation_Band_Reihe) string { return r.Band }, + func(r xmlmodels.Relation_Band_Reihe) int { return r.Band }, ) - rmap := datatypes.MakeMap(adb.Reihen.Reihen, func(r xmlmodels.Reihe) string { return r.ID }) + rmap := datatypes.MakeMap(adb.Reihen.Reihen, func(r xmlmodels.Reihe) int { return r.ID }) for i := 0; i < len(adb.Bände.Bände); i++ { band := adb.Bände.Bände[i] @@ -86,8 +87,8 @@ func RecordsFromBände( func handlePreferredTitleEntry( record *dbmodels.Entry, band xmlmodels.Band, - rmap map[string]xmlmodels.Reihe, - rrelmap map[string][]xmlmodels.Relation_Band_Reihe, + rmap map[int]xmlmodels.Reihe, + rrelmap map[int][]xmlmodels.Relation_Band_Reihe, ) { rels := rrelmap[band.ID] if len(rels) == 0 { @@ -120,7 +121,7 @@ func handlePreferredTitleEntry( func handleOrte( record *dbmodels.Entry, band xmlmodels.Band, - orte map[string]xmlmodels.Ort, + orte map[int]xmlmodels.Ort, app core.App, ocollection *core.Collection, places map[string]*dbmodels.Place, diff --git a/migrations/seed/items.go b/migrations/seed/items.go index e3f9600..4adbdb5 100644 --- a/migrations/seed/items.go +++ b/migrations/seed/items.go @@ -16,7 +16,7 @@ func ItemsFromBändeAndBIBLIO( app core.App, entries xmlmodels.Bände, biblio map[int]xmlmodels.BIBLIOEintrag, - entriesmap map[string]*dbmodels.Entry, + entriesmap map[int]*dbmodels.Entry, ) ([]*dbmodels.Item, error) { collection, err := app.FindCollectionByNameOrId(dbmodels.ITEMS_TABLE) records := make([]*dbmodels.Item, 0, len(entries.Bände)) diff --git a/migrations/seed/r_contents_agents.go b/migrations/seed/r_contents_agents.go index 35f7e2c..235229d 100644 --- a/migrations/seed/r_contents_agents.go +++ b/migrations/seed/r_contents_agents.go @@ -12,8 +12,8 @@ import ( func RecordsFromRelationInhalteAkteure( app core.App, relations xmlmodels.Relationen_Inhalte_Akteure, - contents map[string]*dbmodels.Content, - agents map[string]*dbmodels.Agent, + contents map[int]*dbmodels.Content, + agents map[int]*dbmodels.Agent, ) ([]*dbmodels.RContentsAgents, error) { records := make([]*dbmodels.RContentsAgents, 0, len(relations.Relationen)) collection, err := app.FindCollectionByNameOrId(dbmodels.RelationTableName(dbmodels.CONTENTS_TABLE, dbmodels.AGENTS_TABLE)) diff --git a/migrations/seed/r_entries_agents.go b/migrations/seed/r_entries_agents.go index b7e24be..226fdc4 100644 --- a/migrations/seed/r_entries_agents.go +++ b/migrations/seed/r_entries_agents.go @@ -11,8 +11,8 @@ import ( func RecordsFromRelationBändeAkteure( app core.App, relations xmlmodels.Relationen_Bände_Akteure, - entries map[string]*dbmodels.Entry, - agents map[string]*dbmodels.Agent, + entries map[int]*dbmodels.Entry, + agents map[int]*dbmodels.Agent, ) ([]*dbmodels.REntriesAgents, error) { records := make([]*dbmodels.REntriesAgents, 0, len(relations.Relationen)) collection, err := app.FindCollectionByNameOrId(dbmodels.RelationTableName(dbmodels.ENTRIES_TABLE, dbmodels.AGENTS_TABLE)) diff --git a/migrations/seed/r_entries_series.go b/migrations/seed/r_entries_series.go index 77cac6b..dab962c 100644 --- a/migrations/seed/r_entries_series.go +++ b/migrations/seed/r_entries_series.go @@ -11,8 +11,8 @@ import ( func RecordsFromRelationBändeReihen( app core.App, relations xmlmodels.Relationen_Bände_Reihen, - series map[string]*dbmodels.Series, - entries map[string]*dbmodels.Entry, + series map[int]*dbmodels.Series, + entries map[int]*dbmodels.Entry, ) ([]*dbmodels.REntriesSeries, error) { records := make([]*dbmodels.REntriesSeries, 0, len(relations.Relationen)) collection, err := app.FindCollectionByNameOrId(dbmodels.RelationTableName(dbmodels.ENTRIES_TABLE, dbmodels.SERIES_TABLE)) diff --git a/xmlmodels/akteure.go b/xmlmodels/akteure.go index 5fe8812..805d36e 100644 --- a/xmlmodels/akteure.go +++ b/xmlmodels/akteure.go @@ -8,7 +8,7 @@ type Akteure struct { } type Akteur struct { - ID string `xml:"ID"` + ID int `xml:"ID"` Name string `xml:"NAME"` Körperschaft bool `xml:"ORGANISATION"` Beruf string `xml:"BERUF"` diff --git a/xmlmodels/baende.go b/xmlmodels/baende.go index 64fc3b8..affcc71 100644 --- a/xmlmodels/baende.go +++ b/xmlmodels/baende.go @@ -8,7 +8,7 @@ type Bände struct { } type Band struct { - ID string `xml:"ID"` + ID int `xml:"ID"` BiblioID int `xml:"BIBLIO-ID"` Titelangabe string `xml:"TITEL"` Ortsangabe string `xml:"ORT-ALT"` @@ -26,7 +26,7 @@ type Band struct { } type Ortverweis struct { - Value string `xml:"Value"` + Value int `xml:"Value"` } type Status struct { diff --git a/xmlmodels/inhalte.go b/xmlmodels/inhalte.go index 61b5515..2c06117 100644 --- a/xmlmodels/inhalte.go +++ b/xmlmodels/inhalte.go @@ -8,10 +8,10 @@ type Inhalte struct { } type Inhalt struct { - ID string `xml:"ID"` + ID int `xml:"ID"` Titelangabe string `xml:"TITEL"` Urheberangabe string `xml:"AUTOR"` - Band string `xml:"BAND"` + Band int `xml:"BAND"` Objektnummer string `xml:"OBJEKTNUMMER"` Incipit string `xml:"INCIPIT"` Paginierung string `xml:"PAGINIERUNG"` diff --git a/xmlmodels/orte.go b/xmlmodels/orte.go index f91261c..0a35706 100644 --- a/xmlmodels/orte.go +++ b/xmlmodels/orte.go @@ -8,7 +8,7 @@ type Orte struct { } type Ort struct { - ID string `xml:"ID"` + ID int `xml:"ID"` Name string `xml:"NAME"` Fiktiv bool `xml:"FIKTIV"` Anmerkungen string `xml:"Anmerkungen"` diff --git a/xmlmodels/reihen.go b/xmlmodels/reihen.go index 94468f2..637581f 100644 --- a/xmlmodels/reihen.go +++ b/xmlmodels/reihen.go @@ -8,7 +8,7 @@ type Reihentitel struct { } type Reihe struct { - ID string `xml:"ID"` + ID int `xml:"ID"` Titel string `xml:"NAME"` Sortiername string `xml:"SORTIERNAME"` Nachweis string `xml:"NACHWEIS"` @@ -16,7 +16,7 @@ type Reihe struct { } func SanitizeReihen(reihentitel Reihentitel, relationen Relationen_Bände_Reihen) Reihentitel { - m := make(map[string]bool) + m := make(map[int]bool) o := Reihentitel{ Reihen: []Reihe{}, } diff --git a/xmlmodels/relationen.go b/xmlmodels/relationen.go index 200b6ce..468dd83 100644 --- a/xmlmodels/relationen.go +++ b/xmlmodels/relationen.go @@ -8,10 +8,10 @@ type Relationen_Bände_Reihen struct { } type Relation_Band_Reihe struct { - ID string `xml:"ID"` - Band string `xml:"BAND"` + ID int `xml:"ID"` + Band int `xml:"BAND"` Relation string `xml:"BEZIEHUNG"` - Reihe string `xml:"REIHE"` + Reihe int `xml:"REIHE"` } type Relationen_Inhalte_Akteure struct { @@ -20,10 +20,10 @@ type Relationen_Inhalte_Akteure struct { } type Relation_Inhalt_Akteur struct { - ID string `xml:"ID"` - Inhalt string `xml:"INHALT"` + ID int `xml:"ID"` + Inhalt int `xml:"INHALT"` Relation string `xml:"BEZIEHUNG"` - Akteur string `xml:"AKTEUR"` + Akteur int `xml:"AKTEUR"` } type Relationen_Bände_Akteure struct { @@ -32,8 +32,8 @@ type Relationen_Bände_Akteure struct { } type Relation_Band_Akteur struct { - ID string `xml:"ID"` - Band string `xml:"BAND"` + ID int `xml:"ID"` + Band int `xml:"BAND"` Relation string `xml:"BEZIEHUNG"` - Akteur string `xml:"AKTEUR"` + Akteur int `xml:"AKTEUR"` }