Skip to content

Commit

Permalink
Merge pull request #29 from DEXPRO-Solutions-GmbH/feat/xml-minor-fixups
Browse files Browse the repository at this point in the history
Fix minor inconsistencies in XML rewrite
  • Loading branch information
fabiante authored Feb 2, 2024
2 parents 553dfc2 + 4e6dde4 commit 4bdc968
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 55 deletions.
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"`
}

0 comments on commit 4bdc968

Please sign in to comment.