Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix minor inconsistencies in XML rewrite #29

Merged
merged 6 commits into from
Feb 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 8 additions & 18 deletions r_get_record.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,23 @@ package easclient

import (
"context"
"time"
"encoding/xml"

"github.com/google/uuid"
)

type RecordAttachment struct {
Body string `json:"body"`
Name string `json:"name"`
Size string `json:"size"`
Register string `json:"register"`
Author string `json:"author"`
Type string `json:"type"`
DocumentType string `json:"documentType"`
Id uuid.UUID `json:"id"`
FileId uuid.UUID `json:"fileId"`
MasterId uuid.UUID `json:"masterId"`
Version string `json:"version"`
ArchiveDateTime time.Time `json:"archiveDateTime"`
}

func (c *StoreClient) GetRecord(ctx context.Context, id uuid.UUID) (*Record, error) {
req, err := c.newRequestXML(ctx)
if err != nil {
return nil, err
}

var result Record
type RecordResponse struct {
XMLName xml.Name `xml:"records"`
Record *Record `xml:"record"`
}

var result RecordResponse

req.SetResult(&result)
res, err := req.Get("/record/" + id.String())
Expand All @@ -40,5 +30,5 @@ func (c *StoreClient) GetRecord(ctx context.Context, id uuid.UUID) (*Record, err
return nil, err
}

return &result, nil
return result.Record, nil
}
10 changes: 5 additions & 5 deletions r_store_search.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@ type SearchResponseChannel struct {
Title string `xml:"title"`
Link string `xml:"link"`
Description string `xml:"description"`
TotalResults int `xml:"totalResults"` // TODO: Assert in unmarshal test
ItemsPerPage int `xml:"itemsPerPage"` // TODO: Assert in unmarshal test
StartIndex int `xml:"startIndex"` // TODO: Assert in unmarshal test
TotalResults int `xml:"totalResults"`
ItemsPerPage int `xml:"itemsPerPage"`
StartIndex int `xml:"startIndex"`
Query struct {
Role string `xml:"role,attr"`
SearchTerms string `xml:"searchTerms,attr"`
Expand All @@ -114,10 +114,10 @@ type SearchResponseItem struct {
HistoryLink Link `xml:"historyLink"`
VerifyLink Link `xml:"verifyLink"`
DocumentType string `xml:"documentType"`
Fields []*RecordField `xml:"field"` // TODO: Assert and check in get attachment response if this is the correct way to handle recurring fields
Fields []*RecordField `xml:"field"`
MasterId uuid.UUID `xml:"masterId"`
ArchiveDateTime time.Time `xml:"archiveDateTime"`
ID uuid.UUID `xml:"id"`
Id uuid.UUID `xml:"id"`
Version string `xml:"version"`
ArchiverLogin string `xml:"archiverLogin"`
Archiver string `xml:"archiver"`
Expand Down
2 changes: 2 additions & 0 deletions r_store_search_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ func TestStoreClient_Search(t *testing.T) {
// assert search result in general
assert.Equal(t, "Amazo*", response.Query.SearchTerms)
assert.Greater(t, response.TotalResults, 0)
assert.Greater(t, response.ItemsPerPage, 0)
assert.Greater(t, response.EffectiveResults, 0)

// assert single hit
Expand All @@ -55,6 +56,7 @@ func TestStoreClient_Search(t *testing.T) {
// assert search result in general
assert.Equal(t, "Amazo*", response.Query.SearchTerms)
assert.Greater(t, response.TotalResults, 0)
assert.Greater(t, response.ItemsPerPage, 0)
assert.Greater(t, response.EffectiveResults, 0)

// assert single hit
Expand Down
60 changes: 28 additions & 32 deletions record.go
Original file line number Diff line number Diff line change
@@ -1,48 +1,44 @@
package easclient

import (
"encoding/xml"
"time"

"github.com/google/uuid"
)

type HeaderFields struct {
DocumentType string `json:"_documentType"`
MasterId uuid.UUID `json:"_masterId"`
ArchiveDateTime time.Time `json:"_archiveDateTime"`
Id uuid.UUID `json:"_id"`
Version string `json:"_version"`
ArchiverLogin string `json:"_archiverLogin"`
InitialArchiverLogin string `json:"_initialArchiverLogin"`
InitialArchiveDateTime time.Time `json:"_initialArchiveDateTime"`
type Record struct {
DocumentType string `xml:"documentType"`
MasterId uuid.UUID `xml:"masterId"`
ArchiveDateTime time.Time `xml:"archiveDateTime"`
ID uuid.UUID `xml:"id"`
Version string `xml:"version"`
ArchiverLogin string `xml:"archiverLogin"`
Archiver string `xml:"archiver"`
InitialArchiver string `xml:"initialArchiver"`
InitialArchiverLogin string `xml:"initialArchiverLogin"`
InitialArchiveDateTime time.Time `xml:"initialArchiveDateTime"`
Fields []*RecordField `xml:"field"`
Attachments []*RecordAttachment `xml:"attachment"`
}

func (r *Record) GetHeaderFieldVal(name string) string {
for _, field := range r.Fields {
if field.Name == name {
return field.Value
}
}
return ""
}

type RecordField struct {
Name string `xml:"name,attr"`
Value string `xml:",chardata"`
}

type Record struct {
XMLName xml.Name `xml:"records"`
Record struct {
DocumentType string `xml:"documentType"`
MasterId uuid.UUID `xml:"masterId"`
ArchiveDateTime time.Time `xml:"archiveDateTime"`
ID uuid.UUID `xml:"id"`
Version string `xml:"version"`
ArchiverLogin string `xml:"archiverLogin"`
Archiver string `xml:"archiver"`
InitialArchiver string `xml:"initialArchiver"`
InitialArchiverLogin string `xml:"initialArchiverLogin"`
InitialArchiveDateTime time.Time `xml:"initialArchiveDateTime"`
Field []*RecordField `xml:"field"`
Attachment struct {
Name string `xml:"name"`
Size string `xml:"size"`
Register string `xml:"register"`
Author string `xml:"author"`
ID string `xml:"id"`
} `xml:"attachment"`
} `xml:"record"`
type RecordAttachment struct {
Name string `xml:"name"`
Size int `xml:"size"`
Register string `xml:"register"`
Author string `xml:"author"`
ID uuid.UUID `xml:"id"`
}
Loading