Add import metadata

This commit is contained in:
Daniel 2024-11-13 18:50:26 -05:00
parent fb1b6a475c
commit 4f18747255

View file

@ -9,6 +9,7 @@ import (
"regexp" "regexp"
"strconv" "strconv"
"strings" "strings"
"time"
"dynatron.me/x/stillbox/internal/jsontypes" "dynatron.me/x/stillbox/internal/jsontypes"
"dynatron.me/x/stillbox/pkg/database" "dynatron.me/x/stillbox/pkg/database"
@ -41,10 +42,11 @@ func (ij *ImportJob) Import(ctx context.Context) ([]Talkgroup, error) {
switch ij.Type { switch ij.Type {
case ImportSrcRadioReference: case ImportSrcRadioReference:
ij.importer = &radioReferenceImporter{} ij.importer = new(radioReferenceImporter)
default: default:
return nil, ErrBadImportType return nil, ErrBadImportType
} }
return ij.importTalkgroups(ctx, ij.SystemID, r) return ij.importTalkgroups(ctx, ij.SystemID, r)
} }
@ -69,6 +71,11 @@ func (rr *radioReferenceImporter) importTalkgroups(ctx context.Context, sys int,
return nil, ErrNoSuchSystem return nil, ErrNoSuchSystem
} }
importedFrom := jsontypes.Metadata{
"from": "RadioReference",
"time": time.Now(),
}
var groupName string var groupName string
state := rrsInitial state := rrsInitial
for sc.Scan() { for sc.Scan() {
@ -88,7 +95,7 @@ func (rr *radioReferenceImporter) importTalkgroups(ctx context.Context, sys int,
} }
case rrsTG: case rrsTG:
fields := strings.Split(ln, "\t") fields := strings.Split(ln, "\t")
if len(fields) < 6 { if len(fields) != 6 {
state = rrsGroupDesc state = rrsGroupDesc
groupName = ln groupName = ln
continue continue
@ -97,13 +104,13 @@ func (rr *radioReferenceImporter) importTalkgroups(ctx context.Context, sys int,
if err != nil { if err != nil {
continue continue
} }
var metadata jsontypes.Metadata metadata := jsontypes.Metadata{
"imported": importedFrom,
}
tgt := TG(sys, tgid) tgt := TG(sys, tgid)
mode := fields[2] mode := fields[2]
if strings.Contains(mode, "E") { if strings.Contains(mode, "E") {
metadata = jsontypes.Metadata{ metadata["encrypted"] = true
"encrypted": true,
}
} }
tags := []string{fields[5]} tags := []string{fields[5]}
gn := groupName // must take a copy gn := groupName // must take a copy