mirror of
https://github.com/Theodor-Springmann-Stiftung/kgpz_web.git
synced 2025-12-15 11:35:30 +00:00
Parselog & Issue start
This commit is contained in:
67
app/kgpz.go
67
app/kgpz.go
@@ -85,7 +85,7 @@ func (k *KGPZ) Enrich() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// INFO: We pass agents by value since we don't want to block the library
|
// INFO: We pass agents by value since we don't want to block the library
|
||||||
agents := k.Library.Agents.All()
|
agents := k.Library.Agents.Everything()
|
||||||
go func(agents []xmlprovider.Agent) {
|
go func(agents []xmlprovider.Agent) {
|
||||||
k.GND.FetchPersons(agents)
|
k.GND.FetchPersons(agents)
|
||||||
k.GND.WriteCache(k.Config.GNDPath)
|
k.GND.WriteCache(k.Config.GNDPath)
|
||||||
@@ -103,56 +103,43 @@ func (k *KGPZ) Serialize() {
|
|||||||
k.gmu.Lock()
|
k.gmu.Lock()
|
||||||
defer k.gmu.Unlock()
|
defer k.gmu.Unlock()
|
||||||
|
|
||||||
|
commit := "staticfile"
|
||||||
|
if k.Repo != nil {
|
||||||
|
commit = k.Repo.Commit
|
||||||
|
}
|
||||||
|
|
||||||
issues, err := getXMLFiles(filepath.Join(k.Config.FolderPath, ISSUES_DIR))
|
issues, err := getXMLFiles(filepath.Join(k.Config.FolderPath, ISSUES_DIR))
|
||||||
helpers.Assert(err, "Error getting issues")
|
helpers.Assert(err, "Error getting issues")
|
||||||
|
|
||||||
pieces, err := getXMLFiles(filepath.Join(k.Config.FolderPath, PIECES_DIR))
|
pieces, err := getXMLFiles(filepath.Join(k.Config.FolderPath, PIECES_DIR))
|
||||||
helpers.Assert(err, "Error getting pieces")
|
helpers.Assert(err, "Error getting pieces")
|
||||||
|
|
||||||
lib := xmlprovider.NewLibrary(
|
|
||||||
[]string{filepath.Join(k.Config.FolderPath, AGENTS_PATH)},
|
|
||||||
[]string{filepath.Join(k.Config.FolderPath, PLACES_PATH)},
|
|
||||||
[]string{filepath.Join(k.Config.FolderPath, WORKS_PATH)},
|
|
||||||
[]string{filepath.Join(k.Config.FolderPath, CATEGORIES_PATH)},
|
|
||||||
*issues,
|
|
||||||
*pieces)
|
|
||||||
|
|
||||||
lib.Serialize()
|
|
||||||
|
|
||||||
// TODO: is it neccessary to lock here, sice gmu lock prevents concurrent locking of the library?
|
|
||||||
k.lmu.Lock()
|
k.lmu.Lock()
|
||||||
defer k.lmu.Unlock()
|
defer k.lmu.Unlock()
|
||||||
|
|
||||||
if k.Library == nil {
|
if k.Library == nil {
|
||||||
|
lib := xmlprovider.NewLibrary(
|
||||||
|
[]string{filepath.Join(k.Config.FolderPath, AGENTS_PATH)},
|
||||||
|
[]string{filepath.Join(k.Config.FolderPath, PLACES_PATH)},
|
||||||
|
[]string{filepath.Join(k.Config.FolderPath, WORKS_PATH)},
|
||||||
|
[]string{filepath.Join(k.Config.FolderPath, CATEGORIES_PATH)},
|
||||||
|
*issues,
|
||||||
|
*pieces)
|
||||||
|
|
||||||
|
lib.Serialize(commit)
|
||||||
|
|
||||||
k.Library = lib
|
k.Library = lib
|
||||||
return
|
} else {
|
||||||
|
// TODO: where to clear the old data?
|
||||||
|
// How to differentiate between deleted data points and stale data points bc of parse errors?
|
||||||
|
k.Library.SetPaths(
|
||||||
|
[]string{filepath.Join(k.Config.FolderPath, AGENTS_PATH)},
|
||||||
|
[]string{filepath.Join(k.Config.FolderPath, PLACES_PATH)},
|
||||||
|
[]string{filepath.Join(k.Config.FolderPath, WORKS_PATH)},
|
||||||
|
[]string{filepath.Join(k.Config.FolderPath, CATEGORIES_PATH)},
|
||||||
|
*issues,
|
||||||
|
*pieces)
|
||||||
|
k.Library.Serialize(commit)
|
||||||
}
|
}
|
||||||
|
|
||||||
if lib.Agents == nil {
|
|
||||||
lib.Agents = k.Library.Agents
|
|
||||||
}
|
|
||||||
|
|
||||||
if lib.Places == nil {
|
|
||||||
lib.Places = k.Library.Places
|
|
||||||
}
|
|
||||||
|
|
||||||
if lib.Works == nil {
|
|
||||||
lib.Works = k.Library.Works
|
|
||||||
}
|
|
||||||
|
|
||||||
if lib.Categories == nil {
|
|
||||||
lib.Categories = k.Library.Categories
|
|
||||||
}
|
|
||||||
|
|
||||||
if lib.Issues == nil {
|
|
||||||
lib.Issues = k.Library.Issues
|
|
||||||
}
|
|
||||||
|
|
||||||
if lib.Pieces == nil {
|
|
||||||
lib.Pieces = k.Library.Pieces
|
|
||||||
}
|
|
||||||
|
|
||||||
k.Library = lib
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (k *KGPZ) IsDebug() bool {
|
func (k *KGPZ) IsDebug() bool {
|
||||||
|
|||||||
200
helpers/logging/parselog.go
Normal file
200
helpers/logging/parselog.go
Normal file
@@ -0,0 +1,200 @@
|
|||||||
|
package logging
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"log/slog"
|
||||||
|
"sync"
|
||||||
|
)
|
||||||
|
|
||||||
|
// WARNING: do not attempt to set this anywhere besides the init function of this module
|
||||||
|
var ParseMessages ParseLogger
|
||||||
|
|
||||||
|
type XMLEntityType int64
|
||||||
|
|
||||||
|
const (
|
||||||
|
Agent XMLEntityType = iota
|
||||||
|
Place
|
||||||
|
Worke
|
||||||
|
Category
|
||||||
|
Issue
|
||||||
|
Piece
|
||||||
|
)
|
||||||
|
|
||||||
|
type ParseErrorLevel int64
|
||||||
|
|
||||||
|
const (
|
||||||
|
Clean ParseErrorLevel = iota
|
||||||
|
ObjectMessage
|
||||||
|
InfoMessage
|
||||||
|
WarningMessage
|
||||||
|
ErrorMessage
|
||||||
|
FatalMessage
|
||||||
|
)
|
||||||
|
|
||||||
|
type ParseMessage struct {
|
||||||
|
XMLType XMLEntityType
|
||||||
|
XMLPath string
|
||||||
|
Object fmt.Stringer
|
||||||
|
Message string
|
||||||
|
MessageType ParseErrorLevel
|
||||||
|
}
|
||||||
|
|
||||||
|
func (pm ParseMessage) String() string {
|
||||||
|
if pm.Object != nil {
|
||||||
|
return fmt.Sprintf("%s: %s\n%s\n%s", pm.XMLType, pm.XMLPath, pm.Object.String(), pm.Message)
|
||||||
|
}
|
||||||
|
return fmt.Sprintf("%s: %s\n%s", pm.XMLType, pm.XMLPath, pm.Message)
|
||||||
|
}
|
||||||
|
|
||||||
|
type ParseLogger struct {
|
||||||
|
mu sync.Mutex
|
||||||
|
ParseInfo chan ParseMessage
|
||||||
|
ParseErrors chan ParseMessage
|
||||||
|
ParseObjects chan fmt.Stringer
|
||||||
|
messages []ParseMessage
|
||||||
|
objects []fmt.Stringer
|
||||||
|
State ParseErrorLevel
|
||||||
|
subs []func(ParseMessage)
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
ParseMessages = ParseLogger{
|
||||||
|
ParseInfo: make(chan ParseMessage, 100),
|
||||||
|
ParseErrors: make(chan ParseMessage, 100),
|
||||||
|
}
|
||||||
|
ParseMessages.Start()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (pl *ParseLogger) Start() {
|
||||||
|
go func() {
|
||||||
|
for {
|
||||||
|
select {
|
||||||
|
case msg, ok := <-pl.ParseObjects:
|
||||||
|
pl.mu.Lock()
|
||||||
|
pl.objects = append(pl.objects, msg)
|
||||||
|
pl.mu.Unlock()
|
||||||
|
if !ok {
|
||||||
|
pl.ParseObjects = nil
|
||||||
|
}
|
||||||
|
case msg, ok := <-pl.ParseInfo:
|
||||||
|
pl.mu.Lock()
|
||||||
|
pl.messages = append(pl.messages, msg)
|
||||||
|
pl.setState(InfoMessage)
|
||||||
|
pl.mu.Unlock()
|
||||||
|
if !ok {
|
||||||
|
pl.ParseInfo = nil
|
||||||
|
}
|
||||||
|
case msg, ok := <-pl.ParseErrors:
|
||||||
|
pl.mu.Lock()
|
||||||
|
pl.messages = append(pl.messages, msg)
|
||||||
|
pl.setState(msg.MessageType)
|
||||||
|
pl.mu.Unlock()
|
||||||
|
if !ok {
|
||||||
|
pl.ParseErrors = nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if pl.ParseInfo == nil && pl.ParseInfo == nil && pl.ParseObjects == nil {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (pl *ParseLogger) GetMessages() []ParseMessage {
|
||||||
|
res := make([]ParseMessage, len(pl.messages))
|
||||||
|
pl.mu.Lock()
|
||||||
|
defer pl.mu.Unlock()
|
||||||
|
copy(res, pl.messages)
|
||||||
|
return res
|
||||||
|
}
|
||||||
|
|
||||||
|
func (pl *ParseLogger) ClearMessages() {
|
||||||
|
pl.mu.Lock()
|
||||||
|
defer pl.mu.Unlock()
|
||||||
|
pl.State = Clean
|
||||||
|
pl.messages = []ParseMessage{}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (pl *ParseLogger) LogInfo(xmlType XMLEntityType, xmlPath string, object fmt.Stringer, message string) {
|
||||||
|
pl.ParseInfo <- ParseMessage{
|
||||||
|
XMLType: xmlType,
|
||||||
|
XMLPath: xmlPath,
|
||||||
|
Object: object,
|
||||||
|
Message: message,
|
||||||
|
MessageType: InfoMessage,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (pl *ParseLogger) LogError(xmlType XMLEntityType, xmlPath string, object fmt.Stringer, message string) {
|
||||||
|
pl.ParseErrors <- ParseMessage{
|
||||||
|
XMLType: xmlType,
|
||||||
|
XMLPath: xmlPath,
|
||||||
|
Object: object,
|
||||||
|
Message: message,
|
||||||
|
MessageType: ErrorMessage,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (pl *ParseLogger) LogWarning(xmlType XMLEntityType, xmlPath string, object fmt.Stringer, message string) {
|
||||||
|
pl.ParseErrors <- ParseMessage{
|
||||||
|
XMLType: xmlType,
|
||||||
|
XMLPath: xmlPath,
|
||||||
|
Object: object,
|
||||||
|
Message: message,
|
||||||
|
MessageType: WarningMessage,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (pl *ParseLogger) LogFatal(xmlType XMLEntityType, xmlPath string, object fmt.Stringer, message string) {
|
||||||
|
pl.ParseErrors <- ParseMessage{
|
||||||
|
XMLType: xmlType,
|
||||||
|
XMLPath: xmlPath,
|
||||||
|
Object: object,
|
||||||
|
Message: message,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (pl *ParseLogger) setState(state ParseErrorLevel) {
|
||||||
|
if state > pl.State {
|
||||||
|
pl.State = state
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (pl *ParseLogger) GetState() ParseErrorLevel {
|
||||||
|
return pl.State
|
||||||
|
}
|
||||||
|
|
||||||
|
func (pl *ParseLogger) Len() int {
|
||||||
|
pl.mu.Lock()
|
||||||
|
defer pl.mu.Unlock()
|
||||||
|
return len(pl.messages)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (pl *ParseLogger) Subscribe(fn func(ParseMessage)) {
|
||||||
|
pl.mu.Lock()
|
||||||
|
defer pl.mu.Unlock()
|
||||||
|
pl.subs = append(pl.subs, fn)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (pl *ParseLogger) ResetSubscriptions() {
|
||||||
|
pl.mu.Lock()
|
||||||
|
defer pl.mu.Unlock()
|
||||||
|
pl.subs = []func(ParseMessage){}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (pl *ParseLogger) PrintObjects() {
|
||||||
|
pl.mu.Lock()
|
||||||
|
defer pl.mu.Unlock()
|
||||||
|
for _, o := range pl.objects {
|
||||||
|
ObjDebug(&o, "Object")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (pl *ParseLogger) PrintMessages() {
|
||||||
|
pl.mu.Lock()
|
||||||
|
defer pl.mu.Unlock()
|
||||||
|
for _, m := range pl.messages {
|
||||||
|
slog.Debug(m.String())
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -14,6 +14,7 @@ type Agent struct {
|
|||||||
Org bool `xml:"org,attr"`
|
Org bool `xml:"org,attr"`
|
||||||
Identifier
|
Identifier
|
||||||
AnnotationNote
|
AnnotationNote
|
||||||
|
SerializedItem
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a Agent) String() string {
|
func (a Agent) String() string {
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ type Category struct {
|
|||||||
SortName string `xml:"sortiername"`
|
SortName string `xml:"sortiername"`
|
||||||
Identifier
|
Identifier
|
||||||
AnnotationNote
|
AnnotationNote
|
||||||
|
SerializedItem
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c Category) String() string {
|
func (c Category) String() string {
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ type Issue struct {
|
|||||||
Additionals []Additional `xml:"beilage"`
|
Additionals []Additional `xml:"beilage"`
|
||||||
Identifier
|
Identifier
|
||||||
AnnotationNote
|
AnnotationNote
|
||||||
|
SerializedItem
|
||||||
}
|
}
|
||||||
|
|
||||||
type Nummer struct {
|
type Nummer struct {
|
||||||
|
|||||||
19
providers/xmlprovider/item.go
Normal file
19
providers/xmlprovider/item.go
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
package xmlprovider
|
||||||
|
|
||||||
|
type SerializedItem struct {
|
||||||
|
Source string
|
||||||
|
Date string
|
||||||
|
Commit string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (si SerializedItem) SetSource(s string) {
|
||||||
|
si.Source = s
|
||||||
|
}
|
||||||
|
|
||||||
|
func (si SerializedItem) SetDate(d string) {
|
||||||
|
si.Date = d
|
||||||
|
}
|
||||||
|
|
||||||
|
func (si SerializedItem) SetCommit(c string) {
|
||||||
|
si.Commit = c
|
||||||
|
}
|
||||||
@@ -21,6 +21,7 @@ type Piece struct {
|
|||||||
Title []string `xml:"titel"`
|
Title []string `xml:"titel"`
|
||||||
Identifier
|
Identifier
|
||||||
AnnotationNote
|
AnnotationNote
|
||||||
|
SerializedItem
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p Piece) String() string {
|
func (p Piece) String() string {
|
||||||
@@ -35,6 +36,43 @@ func (p Piece) GetIDs() []string {
|
|||||||
|
|
||||||
// TODO: sensible IDs
|
// TODO: sensible IDs
|
||||||
uid := uuid.New()
|
uid := uuid.New()
|
||||||
ret = append(ret, uid.String())
|
|
||||||
|
for _, i := range p.IssueRefs {
|
||||||
|
ret = append(ret, i.Datum+"-"+i.Nr+"-"+uid.String())
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, i := range p.AdditionalRef {
|
||||||
|
ret = append(ret, i.Datum+"-"+i.Nr+"-"+uid.String())
|
||||||
|
}
|
||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: We can make this fast depending on which category to look for
|
||||||
|
// but we'll have to define rules for every single category (~35 of them)
|
||||||
|
func (p Piece) IsCat(k string) bool {
|
||||||
|
for _, c := range p.CategoryRefs {
|
||||||
|
if c.Category == k {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, c := range p.WorkRefs {
|
||||||
|
if c.Category == k {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, c := range p.AgentRefs {
|
||||||
|
if c.Category == k {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, c := range p.PieceRefs {
|
||||||
|
if c.Category == k {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ type Place struct {
|
|||||||
Geo string `xml:"geonames"`
|
Geo string `xml:"geonames"`
|
||||||
Identifier
|
Identifier
|
||||||
AnnotationNote
|
AnnotationNote
|
||||||
|
SerializedItem
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p Place) String() string {
|
func (p Place) String() string {
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ type Work struct {
|
|||||||
Akteur []AgentRef `xml:"akteur"`
|
Akteur []AgentRef `xml:"akteur"`
|
||||||
Identifier
|
Identifier
|
||||||
AnnotationNote
|
AnnotationNote
|
||||||
|
SerializedItem
|
||||||
}
|
}
|
||||||
|
|
||||||
type Citation struct {
|
type Citation struct {
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"sync"
|
"sync"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/Theodor-Springmann-Stiftung/kgpz_web/helpers/logging"
|
"github.com/Theodor-Springmann-Stiftung/kgpz_web/helpers/logging"
|
||||||
)
|
)
|
||||||
@@ -13,13 +14,20 @@ import (
|
|||||||
type XMLItem interface {
|
type XMLItem interface {
|
||||||
fmt.Stringer
|
fmt.Stringer
|
||||||
GetIDs() []string
|
GetIDs() []string
|
||||||
|
SetSource(string)
|
||||||
|
SetDate(string)
|
||||||
|
SetCommit(string)
|
||||||
|
}
|
||||||
|
|
||||||
|
type Collection[T XMLItem] struct {
|
||||||
|
Collection []T
|
||||||
|
lock sync.Mutex
|
||||||
}
|
}
|
||||||
|
|
||||||
type XMLProvider[T XMLItem] struct {
|
type XMLProvider[T XMLItem] struct {
|
||||||
Paths []string
|
Paths []string
|
||||||
|
// INFO: map is type [string]T
|
||||||
Items sync.Map
|
Items sync.Map
|
||||||
|
|
||||||
mu sync.Mutex
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type Library struct {
|
type Library struct {
|
||||||
@@ -47,90 +55,87 @@ func NewLibrary(agentpaths, placepaths, workpaths, categorypaths, issuepaths, pi
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *Library) Serialize() {
|
func (l *Library) SetPaths(agentpaths, placepaths, workpaths, categorypaths, issuepaths, piecepaths []string) {
|
||||||
|
l.Agents.Paths = agentpaths
|
||||||
|
l.Places.Paths = placepaths
|
||||||
|
l.Works.Paths = workpaths
|
||||||
|
l.Categories.Paths = categorypaths
|
||||||
|
l.Issues.Paths = issuepaths
|
||||||
|
l.Pieces.Paths = piecepaths
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *Library) Serialize(commit string) {
|
||||||
wg := sync.WaitGroup{}
|
wg := sync.WaitGroup{}
|
||||||
wg.Add(6)
|
|
||||||
|
|
||||||
go func() {
|
for _, path := range l.Places.Paths {
|
||||||
defer wg.Done()
|
wg.Add(1)
|
||||||
lwg := sync.WaitGroup{}
|
go func() {
|
||||||
for _, path := range l.Places.Paths {
|
l.Places.Serialize(NewPlaceRoot(), path, commit)
|
||||||
lwg.Add(1)
|
wg.Done()
|
||||||
go l.Places.Serialize(NewPlaceRoot(), path, &lwg)
|
}()
|
||||||
}
|
}
|
||||||
lwg.Wait()
|
|
||||||
}()
|
|
||||||
|
|
||||||
go func() {
|
for _, path := range l.Agents.Paths {
|
||||||
defer wg.Done()
|
wg.Add(1)
|
||||||
lwg := sync.WaitGroup{}
|
go func() {
|
||||||
for _, path := range l.Agents.Paths {
|
l.Agents.Serialize(NewAgentRoot(), path, commit)
|
||||||
lwg.Add(1)
|
wg.Done()
|
||||||
go l.Agents.Serialize(NewAgentRoot(), path, &lwg)
|
}()
|
||||||
}
|
}
|
||||||
lwg.Wait()
|
|
||||||
}()
|
|
||||||
|
|
||||||
go func() {
|
for _, path := range l.Categories.Paths {
|
||||||
defer wg.Done()
|
wg.Add(1)
|
||||||
lwg := sync.WaitGroup{}
|
go func() {
|
||||||
for _, path := range l.Categories.Paths {
|
l.Categories.Serialize(NewCategoryRoot(), path, commit)
|
||||||
lwg.Add(1)
|
wg.Done()
|
||||||
go l.Categories.Serialize(NewCategoryRoot(), path, &lwg)
|
}()
|
||||||
}
|
}
|
||||||
lwg.Wait()
|
|
||||||
}()
|
|
||||||
|
|
||||||
go func() {
|
for _, path := range l.Works.Paths {
|
||||||
defer wg.Done()
|
wg.Add(1)
|
||||||
lwg := sync.WaitGroup{}
|
go func() {
|
||||||
for _, path := range l.Works.Paths {
|
l.Works.Serialize(NewWorkRoot(), path, commit)
|
||||||
lwg.Add(1)
|
wg.Done()
|
||||||
go l.Works.Serialize(NewWorkRoot(), path, &lwg)
|
}()
|
||||||
}
|
}
|
||||||
lwg.Wait()
|
|
||||||
}()
|
|
||||||
|
|
||||||
go func() {
|
for _, path := range l.Issues.Paths {
|
||||||
defer wg.Done()
|
wg.Add(1)
|
||||||
lwg := sync.WaitGroup{}
|
go func() {
|
||||||
for _, path := range l.Issues.Paths {
|
l.Issues.Serialize(NewIssueRoot(), path, commit)
|
||||||
lwg.Add(1)
|
wg.Done()
|
||||||
go l.Issues.Serialize(NewIssueRoot(), path, &lwg)
|
}()
|
||||||
}
|
}
|
||||||
lwg.Wait()
|
|
||||||
}()
|
|
||||||
|
|
||||||
go func() {
|
for _, path := range l.Pieces.Paths {
|
||||||
defer wg.Done()
|
wg.Add(1)
|
||||||
lwg := sync.WaitGroup{}
|
go func() {
|
||||||
for _, path := range l.Pieces.Paths {
|
l.Pieces.Serialize(NewPieceRoot(), path, commit)
|
||||||
lwg.Add(1)
|
wg.Done()
|
||||||
go l.Pieces.Serialize(NewPieceRoot(), path, &lwg)
|
}()
|
||||||
}
|
}
|
||||||
lwg.Wait()
|
|
||||||
}()
|
|
||||||
|
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *XMLProvider[T]) Serialize(dataholder XMLRootElement[T], path string, wg *sync.WaitGroup) error {
|
func (p *XMLProvider[T]) Serialize(dataholder XMLRootElement[T], path, commit string) error {
|
||||||
|
date := time.Now().Format("2006-01-02")
|
||||||
// Introduce goroutine for every path, locking on append:
|
// Introduce goroutine for every path, locking on append:
|
||||||
if err := UnmarshalFile(path, dataholder); err != nil {
|
if err := UnmarshalFile(path, dataholder); err != nil {
|
||||||
logging.Error(err, "Could not unmarshal file: "+path)
|
logging.Error(err, "Could not unmarshal file: "+path)
|
||||||
|
logging.ParseMessages.ParseErrors <- logging.ParseMessage{MessageType: logging.ErrorMessage, Message: "Could not unmarshal file: " + path}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
for _, item := range dataholder.Children() {
|
for _, item := range dataholder.Children() {
|
||||||
|
item.SetSource(path)
|
||||||
|
item.SetDate(date)
|
||||||
|
item.SetCommit(commit)
|
||||||
// INFO: Mostly it's just one ID, so the double loop is not that bad.
|
// INFO: Mostly it's just one ID, so the double loop is not that bad.
|
||||||
for _, id := range item.GetIDs() {
|
for _, id := range item.GetIDs() {
|
||||||
p.Items.Store(id, item)
|
p.Items.Store(id, item)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if wg != nil {
|
|
||||||
wg.Done()
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -199,7 +204,9 @@ func (p *XMLProvider[T]) FindKey(fn func(string) bool) []T {
|
|||||||
return items
|
return items
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *XMLProvider[T]) All() []T {
|
// INFO: Do not use this, except when iterating over a collection multiple times (three times or more).
|
||||||
|
// Maps are slow to iterate, but many of the Iterations can only be done once.
|
||||||
|
func (p *XMLProvider[T]) Everything() []T {
|
||||||
var items []T
|
var items []T
|
||||||
p.Items.Range(func(key, value interface{}) bool {
|
p.Items.Range(func(key, value interface{}) bool {
|
||||||
items = append(items, value.(T))
|
items = append(items, value.(T))
|
||||||
|
|||||||
@@ -40,6 +40,14 @@ func (e *Engine) MapFuncs(app *app.KGPZ) error {
|
|||||||
e.AddFunc("GetDate", functions.GetDate)
|
e.AddFunc("GetDate", functions.GetDate)
|
||||||
e.AddFunc("MonthName", functions.MonthName)
|
e.AddFunc("MonthName", functions.MonthName)
|
||||||
e.AddFunc("MonthNameShort", functions.MonthNameShort)
|
e.AddFunc("MonthNameShort", functions.MonthNameShort)
|
||||||
|
|
||||||
|
e.AddFunc("GetAgent", app.Library.Agents.Item)
|
||||||
|
e.AddFunc("GetPlace", app.Library.Places.Item)
|
||||||
|
e.AddFunc("GetWork", app.Library.Works.Item)
|
||||||
|
e.AddFunc("GetCategory", app.Library.Categories.Item)
|
||||||
|
e.AddFunc("GetIssue", app.Library.Issues.Item)
|
||||||
|
e.AddFunc("GetPiece", app.Library.Pieces.Item)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package viewmodels
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/Theodor-Springmann-Stiftung/kgpz_web/helpers/logging"
|
"github.com/Theodor-Springmann-Stiftung/kgpz_web/helpers/logging"
|
||||||
"github.com/Theodor-Springmann-Stiftung/kgpz_web/providers/xmlprovider"
|
"github.com/Theodor-Springmann-Stiftung/kgpz_web/providers/xmlprovider"
|
||||||
@@ -24,30 +25,19 @@ func NewSingleIssueView(y string, No string, lib *xmlprovider.Library) (*SingleI
|
|||||||
}
|
}
|
||||||
|
|
||||||
sivm := SingleIssueViewModel{IssueViewModel: *ivm}
|
sivm := SingleIssueViewModel{IssueViewModel: *ivm}
|
||||||
logging.Info(strconv.Itoa(len(lib.Pieces.All())) + "pieces in library")
|
logging.Info(strconv.Itoa(len(lib.Pieces.Everything())) + "pieces in library")
|
||||||
|
|
||||||
|
lookfor := y + "-" + No
|
||||||
lib.Pieces.Items.Range(func(key, value interface{}) bool {
|
lib.Pieces.Items.Range(func(key, value interface{}) bool {
|
||||||
a := value.(xmlprovider.Piece)
|
k := key.(string)
|
||||||
for _, r := range a.IssueRefs {
|
if strings.HasPrefix(k, lookfor) {
|
||||||
if r.Datum == y && r.Nr == No {
|
a := value.(xmlprovider.Piece)
|
||||||
p, err := NewPieceView(a)
|
p, err := NewPieceView(a)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logging.ObjErr(&a, err)
|
logging.ObjErr(&a, err)
|
||||||
continue
|
return true
|
||||||
}
|
|
||||||
sivm.Pieces = append(sivm.Pieces, p)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, r := range a.AdditionalRef {
|
|
||||||
if r.Datum == y && r.Nr == No {
|
|
||||||
p, err := NewPieceView(a)
|
|
||||||
if err != nil {
|
|
||||||
logging.ObjErr(&a, err)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
sivm.Additionals = append(sivm.Additionals, p)
|
|
||||||
}
|
}
|
||||||
|
sivm.Pieces = append(sivm.Pieces, p)
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -23,18 +23,19 @@ func YearView(year string, lib *xmlprovider.Library) (*YearViewModel, error) {
|
|||||||
last := ""
|
last := ""
|
||||||
|
|
||||||
lib.Issues.Items.Range(func(key, value interface{}) bool {
|
lib.Issues.Items.Range(func(key, value interface{}) bool {
|
||||||
issue := value.(xmlprovider.Issue)
|
k := key.(string)
|
||||||
if len(issue.Datum.When) < 4 {
|
if len(k) < 4 {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
date := issue.Datum.When[0:4]
|
date := k[0:4]
|
||||||
if date != last {
|
if date != last {
|
||||||
res.PushAvailable(date)
|
res.PushAvailable(date)
|
||||||
last = date
|
last = date
|
||||||
}
|
}
|
||||||
|
|
||||||
if date == year {
|
if date == year {
|
||||||
|
issue := value.(xmlprovider.Issue)
|
||||||
res.PushIssue(issue)
|
res.PushIssue(issue)
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
|
|||||||
@@ -1 +1,33 @@
|
|||||||
Hello from an issue!
|
Issue found!
|
||||||
|
|
||||||
|
{{ $model := .model }}
|
||||||
|
|
||||||
|
{{ range $piece := .model.Pieces }}
|
||||||
|
<div>
|
||||||
|
Piece!
|
||||||
|
|
||||||
|
{{ if gt (len $piece.IssueRefs) 1 }}
|
||||||
|
{{ len $piece.IssueRefs }} Teile
|
||||||
|
<ol>
|
||||||
|
{{ range $issue := $piece.IssueRefs }}
|
||||||
|
<li>
|
||||||
|
<a href="/{{- $issue.Datum -}}/{{- $issue.Nr -}}" >
|
||||||
|
{{- $issue.Datum }} Nr. {{ $issue.Nr -}}
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
{{ end }}
|
||||||
|
</ol>
|
||||||
|
{{ end }}
|
||||||
|
|
||||||
|
{{ range $agentref := $piece.AgentRefs }}
|
||||||
|
{{ $agent := GetAgent $agentref.Ref }}
|
||||||
|
{{ if gt (len $agent.Names) 0 }}
|
||||||
|
{{ index $agent.Names 0 }}
|
||||||
|
{{ end }}
|
||||||
|
{{ if (or (eq $agentref.Category "") (eq $agentref.Category "autor")) }}
|
||||||
|
<span>Author</span>
|
||||||
|
{{ end }}
|
||||||
|
{{ end }}
|
||||||
|
|
||||||
|
</div>
|
||||||
|
{{ end }}
|
||||||
|
|||||||
Reference in New Issue
Block a user