This repository has been archived by the owner on Dec 1, 2022. It is now read-only.
/
pharos_special_models.go
187 lines (174 loc) · 6.95 KB
/
pharos_special_models.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
package models
import (
"strings"
"time"
)
// IntellectualObject in the format that Pharos accepts for
// POST/create.
type IntellectualObjectForPharos struct {
Identifier string `json:"identifier"`
BagName string `json:"bag_name"`
BagGroupIdentifier string `json:"bag_group_identifier"`
InstitutionId int `json:"institution_id"`
Title string `json:"title"`
Description string `json:"description"`
AltIdentifier string `json:"alt_identifier"`
Access string `json:"access"`
DPNUUID string `json:"dpn_uuid"`
ETag string `json:"etag"`
State string `json:"state"`
StorageOption string `json:"storage_option"`
}
func NewIntellectualObjectForPharos(obj *IntellectualObject) *IntellectualObjectForPharos {
return &IntellectualObjectForPharos{
Identifier: obj.Identifier,
BagName: obj.BagName,
BagGroupIdentifier: obj.BagGroupIdentifier,
InstitutionId: obj.InstitutionId,
Title: obj.Title,
Description: obj.Description,
AltIdentifier: obj.AltIdentifier,
Access: strings.ToLower(obj.Access), // Note that Pharos wants lowercase
DPNUUID: obj.DPNUUID,
ETag: obj.ETag,
State: obj.State,
StorageOption: obj.StorageOption,
}
}
// This struct is a special subset of GenericFile, with special JSON
// serialization rules that conform to Rails 4 nested strong paramaters
// naming conventions. When we create GenericFiles in batches, we need
// to send them in this format.
type GenericFileForPharos struct {
Identifier string `json:"identifier"`
IntellectualObjectId int `json:"intellectual_object_id"`
FileFormat string `json:"file_format"`
URI string `json:"uri"`
Size int64 `json:"size"`
StorageOption string `json:"storage_option"`
// TODO: Next two items are not part of Pharos model, but they should be.
// We need to add these to the Rails schema.
// FileCreated time.Time `json:"file_created"`
// FileModified time.Time `json:"file_modified"`
Checksums []*ChecksumForPharos `json:"checksums_attributes"`
PremisEvents []*PremisEventForPharos `json:"premis_events_attributes"`
}
func NewGenericFileForPharos(gf *GenericFile) *GenericFileForPharos {
checksums := make([]*ChecksumForPharos, len(gf.Checksums))
for i, cs := range gf.Checksums {
checksums[i] = NewChecksumForPharos(cs)
}
events := make([]*PremisEventForPharos, len(gf.PremisEvents))
for i, event := range gf.PremisEvents {
events[i] = NewPremisEventForPharos(event)
}
return &GenericFileForPharos{
Identifier: gf.Identifier,
IntellectualObjectId: gf.IntellectualObjectId,
FileFormat: gf.FileFormat,
URI: gf.URI,
Size: gf.Size,
StorageOption: gf.StorageOption,
// TODO: See note above. Add these to Rails!
// FileCreated: gf.FileCreated,
// FileModified: gf.FileModified,
Checksums: checksums,
PremisEvents: events,
}
}
// Same as PremisEvent, but omits CreatedAt and UpdatedAt
type PremisEventForPharos struct {
Id int `json:"id,omitempty"`
Identifier string `json:"identifier"`
EventType string `json:"event_type"`
DateTime time.Time `json:"date_time"`
Detail string `json:"detail"`
Outcome string `json:"outcome"`
OutcomeDetail string `json:"outcome_detail"`
Object string `json:"object"`
Agent string `json:"agent"`
OutcomeInformation string `json:"outcome_information"`
IntellectualObjectId int `json:"intellectual_object_id"`
IntellectualObjectIdentifier string `json:"intellectual_object_identifier"`
GenericFileId int `json:"generic_file_id"`
GenericFileIdentifier string `json:"generic_file_identifier"`
}
func NewPremisEventForPharos(event *PremisEvent) *PremisEventForPharos {
return &PremisEventForPharos{
Id: event.Id,
Identifier: event.Identifier,
EventType: event.EventType,
DateTime: event.DateTime,
Detail: event.Detail,
Outcome: event.Outcome,
OutcomeDetail: event.OutcomeDetail,
Object: event.Object,
Agent: event.Agent,
OutcomeInformation: event.OutcomeInformation,
IntellectualObjectId: event.IntellectualObjectId,
IntellectualObjectIdentifier: event.IntellectualObjectIdentifier,
GenericFileId: event.GenericFileId,
GenericFileIdentifier: event.GenericFileIdentifier,
}
}
// Same as Checksum, but without CreatedAt and UpdatedAt
type ChecksumForPharos struct {
Id int `json:"id,omitempty"` // Do not serialize zero to JSON!
GenericFileId int `json:"generic_file_id"`
Algorithm string `json:"algorithm"`
DateTime time.Time `json:"datetime"`
Digest string `json:"digest"`
}
func NewChecksumForPharos(cs *Checksum) *ChecksumForPharos {
return &ChecksumForPharos{
Id: cs.Id,
GenericFileId: cs.GenericFileId,
Algorithm: cs.Algorithm,
DateTime: cs.DateTime,
Digest: cs.Digest,
}
}
type DPNWorkItemForPharos struct {
RemoteNode string `json:"remote_node"`
Task string `json:"task"`
Identifier string `json:"identifier"`
QueuedAt *time.Time `json:"queued_at"`
CompletedAt *time.Time `json:"completed_at"`
ProcessingNode *string `json:"processing_node"`
Pid int `json:"pid"`
Note *string `json:"note"`
State *string `json:"state"`
Retry bool `json:"retry"`
Stage string `json:"stage"`
Status string `json:"status"`
}
func NewDPNWorkItemForPharos(item *DPNWorkItem) *DPNWorkItemForPharos {
return &DPNWorkItemForPharos{
RemoteNode: item.RemoteNode,
Task: item.Task,
Identifier: item.Identifier,
QueuedAt: item.QueuedAt,
CompletedAt: item.CompletedAt,
ProcessingNode: item.ProcessingNode,
Pid: item.Pid,
Note: item.Note,
State: item.State,
Retry: item.Retry,
Stage: item.Stage,
Status: item.Status,
}
}
type WorkItemStateForPharos struct {
Id int `json:"id"`
WorkItemId int `json:"work_item_id"`
Action string `json:"action"`
State string `json:"state"`
}
func NewWorkItemStateForPharos(workItemState *WorkItemState) *WorkItemStateForPharos {
return &WorkItemStateForPharos{
Id: workItemState.Id,
WorkItemId: workItemState.WorkItemId,
Action: workItemState.Action,
State: workItemState.State,
}
}