IDs: string -> int

This commit is contained in:
Simon Martens
2025-02-19 22:03:40 +01:00
parent aa7c5f4d6c
commit 107a9d9f70
21 changed files with 94 additions and 63 deletions

25
; Normal file
View File

@@ -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"`
}

View File

@@ -92,11 +92,11 @@ func (a *Agent) SetAnnotation(annotation string) {
a.Set(ANNOTATION_FIELD, annotation) a.Set(ANNOTATION_FIELD, annotation)
} }
func (a *Agent) MusenalmID() string { func (a *Agent) MusenalmID() int {
return a.GetString(MUSENALMID_FIELD) return a.GetInt(MUSENALMID_FIELD)
} }
func (a *Agent) SetMusenalmID(id string) { func (a *Agent) SetMusenalmID(id int) {
a.Set(MUSENALMID_FIELD, id) a.Set(MUSENALMID_FIELD, id)
} }

View File

@@ -173,11 +173,11 @@ func (c *Content) SetEntry(entry string) {
c.Set(ENTRIES_TABLE, entry) c.Set(ENTRIES_TABLE, entry)
} }
func (c *Content) MusenalmID() string { func (c *Content) MusenalmID() int {
return c.GetString(MUSENALMID_FIELD) return c.GetInt(MUSENALMID_FIELD)
} }
func (c *Content) SetMusenalmID(musenalmID string) { func (c *Content) SetMusenalmID(musenalmID int) {
c.Set(MUSENALMID_FIELD, musenalmID) c.Set(MUSENALMID_FIELD, musenalmID)
} }

View File

@@ -200,11 +200,11 @@ func (e *Entry) SetDeprecated(deprecated Deprecated) {
e.Set(MUSENALM_DEPRECATED_FIELD, deprecated) e.Set(MUSENALM_DEPRECATED_FIELD, deprecated)
} }
func (e *Entry) MusenalmID() string { func (e *Entry) MusenalmID() int {
return e.GetString(MUSENALMID_FIELD) return e.GetInt(MUSENALMID_FIELD)
} }
func (e *Entry) SetMusenalmID(musenalmID string) { func (e *Entry) SetMusenalmID(musenalmID int) {
e.Set(MUSENALMID_FIELD, musenalmID) e.Set(MUSENALMID_FIELD, musenalmID)
} }

View File

@@ -220,7 +220,6 @@ func FTS5ValuesContent(content *Content, entry *Entry, agents []*Agent) []string
entrystring += "; [o.J.]" entrystring += "; [o.J.]"
} }
strconv.Itoa(entry.Year())
return []string{ return []string{
content.PreferredTitle(), content.PreferredTitle(),
content.VariantTitle(), content.VariantTitle(),
@@ -237,7 +236,7 @@ func FTS5ValuesContent(content *Content, entry *Entry, agents []*Agent) []string
strconv.FormatFloat(content.Numbering(), 'f', 3, 64), strconv.FormatFloat(content.Numbering(), 'f', 3, 64),
entrystring, entrystring,
agentstring, agentstring,
content.MusenalmID(), strconv.Itoa(content.MusenalmID()),
datatypes.DeleteTags(content.Annotation()), datatypes.DeleteTags(content.Annotation()),
datatypes.DeleteTags(content.Comment()), datatypes.DeleteTags(content.Comment()),
} }
@@ -291,7 +290,7 @@ func FTS5ValuesEntry(entry *Entry, places []*Place, agents []*Agent, series []*S
placestring, placestring,
agentstring, agentstring,
seriesstring, seriesstring,
entry.MusenalmID(), strconv.Itoa(entry.MusenalmID()),
datatypes.DeleteTags(entry.Annotation()), datatypes.DeleteTags(entry.Annotation()),
datatypes.DeleteTags(entry.Comment()), datatypes.DeleteTags(entry.Comment()),
} }

View File

@@ -13,7 +13,7 @@ func SetCreatedUpdatedFields(fieldlist *core.FieldsList) {
} }
func SetMusenalmIDField(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) { func SetEditorStateField(fieldlist *core.FieldsList) {

View File

@@ -58,11 +58,11 @@ func (p *Place) SetAnnotation(annotation string) {
p.Set(ANNOTATION_FIELD, annotation) p.Set(ANNOTATION_FIELD, annotation)
} }
func (p *Place) MusenalmID() string { func (p *Place) MusenalmID() int {
return p.GetString(MUSENALMID_FIELD) return p.GetInt(MUSENALMID_FIELD)
} }
func (p *Place) SetMusenalmID(id string) { func (p *Place) SetMusenalmID(id int) {
p.Set(MUSENALMID_FIELD, id) p.Set(MUSENALMID_FIELD, id)
} }

View File

@@ -56,11 +56,11 @@ func (s *Series) SetAnnotation(annotation string) {
s.Set(ANNOTATION_FIELD, annotation) s.Set(ANNOTATION_FIELD, annotation)
} }
func (s *Series) MusenalmID() string { func (s *Series) MusenalmID() int {
return s.GetString(MUSENALMID_FIELD) return s.GetInt(MUSENALMID_FIELD)
} }
func (s *Series) SetMusenalmID(id string) { func (s *Series) SetMusenalmID(id int) {
s.Set(MUSENALMID_FIELD, id) s.Set(MUSENALMID_FIELD, id)
} }

View File

@@ -21,15 +21,15 @@ func init() {
adb.Reihen = xmlmodels.SanitizeReihen(adb.Reihen, adb.Relationen_Bände_Reihen) 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 placesmap map[string]*dbmodels.Place
var placesmapid map[string]*dbmodels.Place var placesmapid map[string]*dbmodels.Place
var seriesmap map[string]*dbmodels.Series var seriesmap map[int]*dbmodels.Series
var entriesmap map[string]*dbmodels.Entry var entriesmap map[int]*dbmodels.Entry
var entriesmapid map[string]*dbmodels.Entry var entriesmapid map[string]*dbmodels.Entry
var seriesmapid map[string]*dbmodels.Series var seriesmapid map[string]*dbmodels.Series
var agentsmapid map[string]*dbmodels.Agent 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_series map[string][]*dbmodels.REntriesSeries
var r_entries_agents map[string][]*dbmodels.REntriesAgents var r_entries_agents map[string][]*dbmodels.REntriesAgents
var r_contents_agents map[string][]*dbmodels.RContentsAgents var r_contents_agents map[string][]*dbmodels.RContentsAgents
@@ -50,7 +50,7 @@ func init() {
} else { } else {
panic(err) 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 }) agentsmapid = datatypes.MakeMap(agents, func(record *dbmodels.Agent) string { return record.Id })
wg.Done() wg.Done()
}() }()
@@ -79,7 +79,7 @@ func init() {
app.Logger().Error("Error saving record", "error", err, "record", record) 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 }) seriesmapid = datatypes.MakeMap(series, func(record *dbmodels.Series) string { return record.Id })
wg.Done() 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 }) entriesmapid = datatypes.MakeMap(entries, func(record *dbmodels.Entry) string { return record.Id })
wg.Add(2) wg.Add(2)
@@ -125,7 +125,7 @@ func init() {
app.Logger().Error("Error saving record", "error", err, "record", record) 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() wg.Done()
}() }()

View File

@@ -3,6 +3,7 @@ package seed
import ( import (
"fmt" "fmt"
"log" "log"
"log/slog"
"os" "os"
"path/filepath" "path/filepath"
"strconv" "strconv"
@@ -19,7 +20,7 @@ const NO_TITLE = "[No Title]"
func RecordsFromInhalte( func RecordsFromInhalte(
app core.App, app core.App,
inhalte xmlmodels.Inhalte, inhalte xmlmodels.Inhalte,
entries map[string]*dbmodels.Entry, entries map[int]*dbmodels.Entry,
) ([]*dbmodels.Content, error) { ) ([]*dbmodels.Content, error) {
collection, err := app.FindCollectionByNameOrId(dbmodels.CONTENTS_TABLE) collection, err := app.FindCollectionByNameOrId(dbmodels.CONTENTS_TABLE)
records := make([]*dbmodels.Content, 0, len(inhalte.Inhalte)) records := make([]*dbmodels.Content, 0, len(inhalte.Inhalte))
@@ -127,9 +128,9 @@ func commatizeArray(array []string) string {
return array[0] 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 /// 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) { if _, err := os.Stat(path); os.IsNotExist(err) {
return ret return ret
} }
@@ -142,10 +143,15 @@ func getImages(path string) map[string][]string {
if len(basesplit) >= 3 { if len(basesplit) >= 3 {
commaseperatorsplit := strings.Split(basesplit[2], ",") commaseperatorsplit := strings.Split(basesplit[2], ",")
id := commaseperatorsplit[0] id := commaseperatorsplit[0]
if _, ok := ret[id]; !ok { no, err := strconv.Atoi(id)
ret[id] = make([]string, 0) 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 return nil

View File

@@ -15,6 +15,7 @@ import (
func RecordsFromBände( func RecordsFromBände(
app core.App, app core.App,
adb xmlmodels.AccessDB, adb xmlmodels.AccessDB,
// INFO: this is a string map, bc it's not by ID but by place name
places map[string]*dbmodels.Place, places map[string]*dbmodels.Place,
) ([]*dbmodels.Entry, error) { ) ([]*dbmodels.Entry, error) {
collection, err := app.FindCollectionByNameOrId(dbmodels.ENTRIES_TABLE) collection, err := app.FindCollectionByNameOrId(dbmodels.ENTRIES_TABLE)
@@ -31,12 +32,12 @@ func RecordsFromBände(
} }
// INFO: lets make some maps to speed this up // 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( relmap := datatypes.MakeMultiMap(
adb.Relationen_Bände_Reihen.Relationen, 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++ { for i := 0; i < len(adb.Bände.Bände); i++ {
band := adb.Bände.Bände[i] band := adb.Bände.Bände[i]
@@ -86,8 +87,8 @@ func RecordsFromBände(
func handlePreferredTitleEntry( func handlePreferredTitleEntry(
record *dbmodels.Entry, record *dbmodels.Entry,
band xmlmodels.Band, band xmlmodels.Band,
rmap map[string]xmlmodels.Reihe, rmap map[int]xmlmodels.Reihe,
rrelmap map[string][]xmlmodels.Relation_Band_Reihe, rrelmap map[int][]xmlmodels.Relation_Band_Reihe,
) { ) {
rels := rrelmap[band.ID] rels := rrelmap[band.ID]
if len(rels) == 0 { if len(rels) == 0 {
@@ -120,7 +121,7 @@ func handlePreferredTitleEntry(
func handleOrte( func handleOrte(
record *dbmodels.Entry, record *dbmodels.Entry,
band xmlmodels.Band, band xmlmodels.Band,
orte map[string]xmlmodels.Ort, orte map[int]xmlmodels.Ort,
app core.App, app core.App,
ocollection *core.Collection, ocollection *core.Collection,
places map[string]*dbmodels.Place, places map[string]*dbmodels.Place,

View File

@@ -16,7 +16,7 @@ func ItemsFromBändeAndBIBLIO(
app core.App, app core.App,
entries xmlmodels.Bände, entries xmlmodels.Bände,
biblio map[int]xmlmodels.BIBLIOEintrag, biblio map[int]xmlmodels.BIBLIOEintrag,
entriesmap map[string]*dbmodels.Entry, entriesmap map[int]*dbmodels.Entry,
) ([]*dbmodels.Item, error) { ) ([]*dbmodels.Item, error) {
collection, err := app.FindCollectionByNameOrId(dbmodels.ITEMS_TABLE) collection, err := app.FindCollectionByNameOrId(dbmodels.ITEMS_TABLE)
records := make([]*dbmodels.Item, 0, len(entries.Bände)) records := make([]*dbmodels.Item, 0, len(entries.Bände))

View File

@@ -12,8 +12,8 @@ import (
func RecordsFromRelationInhalteAkteure( func RecordsFromRelationInhalteAkteure(
app core.App, app core.App,
relations xmlmodels.Relationen_Inhalte_Akteure, relations xmlmodels.Relationen_Inhalte_Akteure,
contents map[string]*dbmodels.Content, contents map[int]*dbmodels.Content,
agents map[string]*dbmodels.Agent, agents map[int]*dbmodels.Agent,
) ([]*dbmodels.RContentsAgents, error) { ) ([]*dbmodels.RContentsAgents, error) {
records := make([]*dbmodels.RContentsAgents, 0, len(relations.Relationen)) records := make([]*dbmodels.RContentsAgents, 0, len(relations.Relationen))
collection, err := app.FindCollectionByNameOrId(dbmodels.RelationTableName(dbmodels.CONTENTS_TABLE, dbmodels.AGENTS_TABLE)) collection, err := app.FindCollectionByNameOrId(dbmodels.RelationTableName(dbmodels.CONTENTS_TABLE, dbmodels.AGENTS_TABLE))

View File

@@ -11,8 +11,8 @@ import (
func RecordsFromRelationBändeAkteure( func RecordsFromRelationBändeAkteure(
app core.App, app core.App,
relations xmlmodels.Relationen_Bände_Akteure, relations xmlmodels.Relationen_Bände_Akteure,
entries map[string]*dbmodels.Entry, entries map[int]*dbmodels.Entry,
agents map[string]*dbmodels.Agent, agents map[int]*dbmodels.Agent,
) ([]*dbmodels.REntriesAgents, error) { ) ([]*dbmodels.REntriesAgents, error) {
records := make([]*dbmodels.REntriesAgents, 0, len(relations.Relationen)) records := make([]*dbmodels.REntriesAgents, 0, len(relations.Relationen))
collection, err := app.FindCollectionByNameOrId(dbmodels.RelationTableName(dbmodels.ENTRIES_TABLE, dbmodels.AGENTS_TABLE)) collection, err := app.FindCollectionByNameOrId(dbmodels.RelationTableName(dbmodels.ENTRIES_TABLE, dbmodels.AGENTS_TABLE))

View File

@@ -11,8 +11,8 @@ import (
func RecordsFromRelationBändeReihen( func RecordsFromRelationBändeReihen(
app core.App, app core.App,
relations xmlmodels.Relationen_Bände_Reihen, relations xmlmodels.Relationen_Bände_Reihen,
series map[string]*dbmodels.Series, series map[int]*dbmodels.Series,
entries map[string]*dbmodels.Entry, entries map[int]*dbmodels.Entry,
) ([]*dbmodels.REntriesSeries, error) { ) ([]*dbmodels.REntriesSeries, error) {
records := make([]*dbmodels.REntriesSeries, 0, len(relations.Relationen)) records := make([]*dbmodels.REntriesSeries, 0, len(relations.Relationen))
collection, err := app.FindCollectionByNameOrId(dbmodels.RelationTableName(dbmodels.ENTRIES_TABLE, dbmodels.SERIES_TABLE)) collection, err := app.FindCollectionByNameOrId(dbmodels.RelationTableName(dbmodels.ENTRIES_TABLE, dbmodels.SERIES_TABLE))

View File

@@ -8,7 +8,7 @@ type Akteure struct {
} }
type Akteur struct { type Akteur struct {
ID string `xml:"ID"` ID int `xml:"ID"`
Name string `xml:"NAME"` Name string `xml:"NAME"`
Körperschaft bool `xml:"ORGANISATION"` Körperschaft bool `xml:"ORGANISATION"`
Beruf string `xml:"BERUF"` Beruf string `xml:"BERUF"`

View File

@@ -8,7 +8,7 @@ type Bände struct {
} }
type Band struct { type Band struct {
ID string `xml:"ID"` ID int `xml:"ID"`
BiblioID int `xml:"BIBLIO-ID"` BiblioID int `xml:"BIBLIO-ID"`
Titelangabe string `xml:"TITEL"` Titelangabe string `xml:"TITEL"`
Ortsangabe string `xml:"ORT-ALT"` Ortsangabe string `xml:"ORT-ALT"`
@@ -26,7 +26,7 @@ type Band struct {
} }
type Ortverweis struct { type Ortverweis struct {
Value string `xml:"Value"` Value int `xml:"Value"`
} }
type Status struct { type Status struct {

View File

@@ -8,10 +8,10 @@ type Inhalte struct {
} }
type Inhalt struct { type Inhalt struct {
ID string `xml:"ID"` ID int `xml:"ID"`
Titelangabe string `xml:"TITEL"` Titelangabe string `xml:"TITEL"`
Urheberangabe string `xml:"AUTOR"` Urheberangabe string `xml:"AUTOR"`
Band string `xml:"BAND"` Band int `xml:"BAND"`
Objektnummer string `xml:"OBJEKTNUMMER"` Objektnummer string `xml:"OBJEKTNUMMER"`
Incipit string `xml:"INCIPIT"` Incipit string `xml:"INCIPIT"`
Paginierung string `xml:"PAGINIERUNG"` Paginierung string `xml:"PAGINIERUNG"`

View File

@@ -8,7 +8,7 @@ type Orte struct {
} }
type Ort struct { type Ort struct {
ID string `xml:"ID"` ID int `xml:"ID"`
Name string `xml:"NAME"` Name string `xml:"NAME"`
Fiktiv bool `xml:"FIKTIV"` Fiktiv bool `xml:"FIKTIV"`
Anmerkungen string `xml:"Anmerkungen"` Anmerkungen string `xml:"Anmerkungen"`

View File

@@ -8,7 +8,7 @@ type Reihentitel struct {
} }
type Reihe struct { type Reihe struct {
ID string `xml:"ID"` ID int `xml:"ID"`
Titel string `xml:"NAME"` Titel string `xml:"NAME"`
Sortiername string `xml:"SORTIERNAME"` Sortiername string `xml:"SORTIERNAME"`
Nachweis string `xml:"NACHWEIS"` Nachweis string `xml:"NACHWEIS"`
@@ -16,7 +16,7 @@ type Reihe struct {
} }
func SanitizeReihen(reihentitel Reihentitel, relationen Relationen_Bände_Reihen) Reihentitel { func SanitizeReihen(reihentitel Reihentitel, relationen Relationen_Bände_Reihen) Reihentitel {
m := make(map[string]bool) m := make(map[int]bool)
o := Reihentitel{ o := Reihentitel{
Reihen: []Reihe{}, Reihen: []Reihe{},
} }

View File

@@ -8,10 +8,10 @@ type Relationen_Bände_Reihen struct {
} }
type Relation_Band_Reihe struct { type Relation_Band_Reihe struct {
ID string `xml:"ID"` ID int `xml:"ID"`
Band string `xml:"BAND"` Band int `xml:"BAND"`
Relation string `xml:"BEZIEHUNG"` Relation string `xml:"BEZIEHUNG"`
Reihe string `xml:"REIHE"` Reihe int `xml:"REIHE"`
} }
type Relationen_Inhalte_Akteure struct { type Relationen_Inhalte_Akteure struct {
@@ -20,10 +20,10 @@ type Relationen_Inhalte_Akteure struct {
} }
type Relation_Inhalt_Akteur struct { type Relation_Inhalt_Akteur struct {
ID string `xml:"ID"` ID int `xml:"ID"`
Inhalt string `xml:"INHALT"` Inhalt int `xml:"INHALT"`
Relation string `xml:"BEZIEHUNG"` Relation string `xml:"BEZIEHUNG"`
Akteur string `xml:"AKTEUR"` Akteur int `xml:"AKTEUR"`
} }
type Relationen_Bände_Akteure struct { type Relationen_Bände_Akteure struct {
@@ -32,8 +32,8 @@ type Relationen_Bände_Akteure struct {
} }
type Relation_Band_Akteur struct { type Relation_Band_Akteur struct {
ID string `xml:"ID"` ID int `xml:"ID"`
Band string `xml:"BAND"` Band int `xml:"BAND"`
Relation string `xml:"BEZIEHUNG"` Relation string `xml:"BEZIEHUNG"`
Akteur string `xml:"AKTEUR"` Akteur int `xml:"AKTEUR"`
} }