mirror of
https://github.com/Theodor-Springmann-Stiftung/musenalm.git
synced 2026-02-04 02:25:30 +00:00
BUGFIX: double entries for almanachse
This commit is contained in:
@@ -86,7 +86,8 @@ func init() {
|
||||
|
||||
wg.Wait()
|
||||
|
||||
entries, err := seed.RecordsFromBände(app, *adb, placesmap)
|
||||
contentCounts := seed.ContentCountsAfterFilter(adb.Inhalte)
|
||||
entries, err := seed.RecordsFromBände(app, *adb, placesmap, contentCounts)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
52
migrations/seed/content_filters.go
Normal file
52
migrations/seed/content_filters.go
Normal file
@@ -0,0 +1,52 @@
|
||||
package seed
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/Theodor-Springmann-Stiftung/musenalm/xmlmodels"
|
||||
)
|
||||
|
||||
func CountContentsByBand(inhalte xmlmodels.Inhalte) map[int]int {
|
||||
counts := make(map[int]int)
|
||||
for _, inhalt := range inhalte.Inhalte {
|
||||
counts[inhalt.Band]++
|
||||
}
|
||||
return counts
|
||||
}
|
||||
|
||||
func ContentCountsAfterFilter(inhalte xmlmodels.Inhalte) map[int]int {
|
||||
images := getImages(xmlmodels.IMG_PATH)
|
||||
filteredCounts := make(map[int]int)
|
||||
for _, inhalt := range inhalte.Inhalte {
|
||||
if shouldSkipDummyContent(inhalt, images) {
|
||||
continue
|
||||
}
|
||||
filteredCounts[inhalt.Band]++
|
||||
}
|
||||
return filteredCounts
|
||||
}
|
||||
|
||||
func shouldSkipDummyContent(inhalt xmlmodels.Inhalt, images map[int][]string) bool {
|
||||
if len(inhalt.Typ.Value) != 1 || strings.TrimSpace(inhalt.Typ.Value[0]) != "Gedicht/Lied" {
|
||||
return false
|
||||
}
|
||||
|
||||
author := strings.TrimSpace(NormalizeString(inhalt.Urheberangabe))
|
||||
if !strings.EqualFold(author, "unbezeichnet") {
|
||||
return false
|
||||
}
|
||||
|
||||
if strings.TrimSpace(NormalizeString(inhalt.Titelangabe)) != "" {
|
||||
return false
|
||||
}
|
||||
|
||||
if strings.TrimSpace(NormalizeString(inhalt.Incipit)) != "" {
|
||||
return false
|
||||
}
|
||||
|
||||
if len(images[inhalt.ID]) > 0 {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
@@ -34,6 +34,9 @@ func RecordsFromInhalte(
|
||||
for i := 0; i < len(inhalte.Inhalte); i++ {
|
||||
record := dbmodels.NewContent(core.NewRecord(collection))
|
||||
inhalt := inhalte.Inhalte[i]
|
||||
if shouldSkipDummyContent(inhalt, images) {
|
||||
continue
|
||||
}
|
||||
band, ok := entries[inhalt.Band]
|
||||
if !ok {
|
||||
app.Logger().Error("Band not found", "band", inhalt.Band)
|
||||
|
||||
@@ -17,6 +17,7 @@ func RecordsFromBände(
|
||||
adb xmlmodels.AccessDB,
|
||||
// INFO: this is a string map, bc it's not by ID but by place name
|
||||
places map[string]*dbmodels.Place,
|
||||
contentCounts map[int]int,
|
||||
) ([]*dbmodels.Entry, error) {
|
||||
collection, err := app.FindCollectionByNameOrId(dbmodels.ENTRIES_TABLE)
|
||||
records := make([]*dbmodels.Entry, 0, len(adb.Bände.Bände))
|
||||
@@ -64,16 +65,28 @@ func RecordsFromBände(
|
||||
record.SetYear(band.Jahr)
|
||||
}
|
||||
|
||||
if band.Erfasst {
|
||||
record.SetEditState(dbmodels.EDITORSTATE_VALUES[len(dbmodels.EDITORSTATE_VALUES)-1])
|
||||
} else if band.Gesichtet {
|
||||
contentCount := contentCounts[band.ID]
|
||||
hasAutopsieFromData := entryHasAutopsieFromData(band)
|
||||
if band.Erfasst && contentCount == 0 {
|
||||
record.SetEditState(dbmodels.EDITORSTATE_VALUES[2])
|
||||
} else if band.Erfasst {
|
||||
record.SetEditState(dbmodels.EDITORSTATE_VALUES[len(dbmodels.EDITORSTATE_VALUES)-1])
|
||||
} else if band.Gesichtet || hasAutopsieFromData {
|
||||
record.SetEditState(dbmodels.EDITORSTATE_VALUES[2])
|
||||
} else if band.BiblioID != 0 {
|
||||
record.SetEditState(dbmodels.EDITORSTATE_VALUES[1])
|
||||
} else {
|
||||
record.SetEditState(dbmodels.EDITORSTATE_VALUES[0])
|
||||
}
|
||||
|
||||
if band.BiblioID != 0 && !band.Erfasst && !(band.Gesichtet || hasAutopsieFromData) {
|
||||
appendEntryComment(record, "Weder erfasst noch autopsiert, obwohl eine Biblio-ID vergeben wurde; bitte überprüfen.")
|
||||
}
|
||||
if band.BiblioID == 0 && len(band.Status.Value) > 0 && !band.Erfasst && !(band.Gesichtet || hasAutopsieFromData) {
|
||||
appendEntryComment(record, "Band ist als vorhanden markiert aber nicht autospiert.")
|
||||
}
|
||||
if band.BiblioID == 0 && len(band.Status.Value) == 0 && (band.Erfasst || band.Gesichtet || hasAutopsieFromData) {
|
||||
appendEntryComment(record, "Quelle für autopsiert oder Erfassung fehlt.")
|
||||
}
|
||||
|
||||
handlePreferredTitleEntry(record, band, rmap, relmap)
|
||||
handleDeprecated(record, band)
|
||||
handleOrte(record, band, omap, app, ocoll, places)
|
||||
@@ -93,7 +106,7 @@ func handlePreferredTitleEntry(
|
||||
rels := rrelmap[band.ID]
|
||||
if len(rels) == 0 {
|
||||
record.SetPreferredTitle(NormalizeString(band.ReihentitelALT))
|
||||
record.SetEditState(dbmodels.EDITORSTATE_VALUES[len(dbmodels.EDITORSTATE_VALUES)-2])
|
||||
appendEntryComment(record, "Kein Reihentitel-Bezug; Reihentitel ALT verwendet.")
|
||||
return
|
||||
}
|
||||
|
||||
@@ -118,6 +131,19 @@ func handlePreferredTitleEntry(
|
||||
record.SetPreferredTitle(NormalizeString(rmap[rels[0].Reihe].Titel) + jahr)
|
||||
}
|
||||
|
||||
func entryHasAutopsieFromData(band xmlmodels.Band) bool {
|
||||
title := strings.TrimSpace(NormalizeString(band.Titelangabe))
|
||||
if title == "" {
|
||||
return false
|
||||
}
|
||||
|
||||
responsibility := strings.TrimSpace(NormalizeString(band.Verantwortlichkeitsangabe))
|
||||
place := strings.TrimSpace(NormalizeString(band.Ortsangabe))
|
||||
notes := strings.TrimSpace(NormalizeString(band.Anmerkungen))
|
||||
|
||||
return responsibility != "" || place != "" || notes != ""
|
||||
}
|
||||
|
||||
func handleOrte(
|
||||
record *dbmodels.Entry,
|
||||
band xmlmodels.Band,
|
||||
|
||||
26
migrations/seed/entry_comments.go
Normal file
26
migrations/seed/entry_comments.go
Normal file
@@ -0,0 +1,26 @@
|
||||
package seed
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/Theodor-Springmann-Stiftung/musenalm/dbmodels"
|
||||
)
|
||||
|
||||
func appendEntryComment(entry *dbmodels.Entry, note string) {
|
||||
note = strings.TrimSpace(note)
|
||||
if note == "" {
|
||||
return
|
||||
}
|
||||
|
||||
current := strings.TrimSpace(entry.Comment())
|
||||
if current == "" {
|
||||
entry.SetComment(note)
|
||||
return
|
||||
}
|
||||
|
||||
if strings.Contains(current, note) {
|
||||
return
|
||||
}
|
||||
|
||||
entry.SetComment(current + "\n" + note)
|
||||
}
|
||||
@@ -78,7 +78,7 @@ func ItemsFromBändeAndBIBLIO(
|
||||
message = appendMessage(e.NotizÄusseres, message)
|
||||
message = appendMessage(e.NotizInhalt, message)
|
||||
message = appendMessage(e.Anmerkungen, message)
|
||||
exem.SetAnnotation(message)
|
||||
exem.SetAnnotation(formatItemAnnotation(message))
|
||||
}
|
||||
|
||||
records = append(records, exem)
|
||||
@@ -100,7 +100,7 @@ func ItemsFromBändeAndBIBLIO(
|
||||
message = appendMessage(e.Anmerkungen, message)
|
||||
}
|
||||
}
|
||||
exem.SetAnnotation(message)
|
||||
exem.SetAnnotation(formatItemAnnotation(message))
|
||||
|
||||
if exem.Identifier() != "" {
|
||||
records = append(records, exem)
|
||||
@@ -144,3 +144,10 @@ func appendMessage(message string, toAppend string) string {
|
||||
}
|
||||
return message
|
||||
}
|
||||
|
||||
func formatItemAnnotation(message string) string {
|
||||
if message == "" {
|
||||
return message
|
||||
}
|
||||
return strings.ReplaceAll(message, "/)", "<br>")
|
||||
}
|
||||
|
||||
@@ -54,7 +54,7 @@ func RecordsFromRelationBändeAkteure(
|
||||
ser := record.Agent()
|
||||
|
||||
if strings.TrimSpace(rel) == "" || strings.TrimSpace(ent) == "" || strings.TrimSpace(ser) == "" {
|
||||
entry.SetEditState(dbmodels.EDITORSTATE_VALUES[len(dbmodels.EDITORSTATE_VALUES)-2])
|
||||
appendEntryComment(entry, "Unvollständige Relation Band–Akteur; bitte prüfen.")
|
||||
_ = app.Save(entry)
|
||||
}
|
||||
records = append(records, record)
|
||||
|
||||
@@ -15,6 +15,7 @@ func RecordsFromRelationBändeReihen(
|
||||
entries map[int]*dbmodels.Entry,
|
||||
) ([]*dbmodels.REntriesSeries, error) {
|
||||
records := make([]*dbmodels.REntriesSeries, 0, len(relations.Relationen))
|
||||
seen := make(map[string]int)
|
||||
collection, err := app.FindCollectionByNameOrId(dbmodels.RelationTableName(dbmodels.ENTRIES_TABLE, dbmodels.SERIES_TABLE))
|
||||
if err != nil {
|
||||
app.Logger().Error("Error finding collection", "error", err, "collection", dbmodels.RelationTableName(dbmodels.ENTRIES_TABLE, dbmodels.SERIES_TABLE))
|
||||
@@ -62,10 +63,30 @@ func RecordsFromRelationBändeReihen(
|
||||
ser := record.Series()
|
||||
|
||||
if strings.TrimSpace(rel) == "" || strings.TrimSpace(ent) == "" || strings.TrimSpace(ser) == "" {
|
||||
entry.SetEditState(dbmodels.EDITORSTATE_VALUES[len(dbmodels.EDITORSTATE_VALUES)-2])
|
||||
appendEntryComment(entry, "Unvollständige Relation Band–Reihe; bitte prüfen.")
|
||||
_ = app.Save(entry)
|
||||
}
|
||||
|
||||
key := entry.Id + "|" + series.Id
|
||||
if idx, ok := seen[key]; ok {
|
||||
existing := records[idx]
|
||||
if existing.Type() == "Bevorzugter Reihentitel" {
|
||||
appendEntryComment(entry, "Doppelte Relation Band–Reihe entfernt; bitte prüfen.")
|
||||
_ = app.Save(entry)
|
||||
continue
|
||||
}
|
||||
if record.Type() == "Bevorzugter Reihentitel" {
|
||||
records[idx] = record
|
||||
appendEntryComment(entry, "Doppelte Relation Band–Reihe entfernt; bitte prüfen.")
|
||||
_ = app.Save(entry)
|
||||
continue
|
||||
}
|
||||
appendEntryComment(entry, "Doppelte Relation Band–Reihe entfernt; bitte prüfen.")
|
||||
_ = app.Save(entry)
|
||||
continue
|
||||
}
|
||||
|
||||
seen[key] = len(records)
|
||||
records = append(records, record)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user