-
Notifications
You must be signed in to change notification settings - Fork 8
/
service.go
386 lines (345 loc) · 12.2 KB
/
service.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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
// Code generated by goa v3.4.3, DO NOT EDIT.
//
// collection service
//
// Command:
// $ goa-v3.4.3 gen github.com/artefactual-labs/enduro/internal/api/design -o
// internal/api
package collection
import (
"context"
collectionviews "github.com/artefactual-labs/enduro/internal/api/gen/collection/views"
goa "goa.design/goa/v3/pkg"
)
// The collection service manages packages being transferred to Archivematica.
type Service interface {
// List all stored collections
List(context.Context, *ListPayload) (res *ListResult, err error)
// Show collection by ID
Show(context.Context, *ShowPayload) (res *EnduroStoredCollection, err error)
// Delete collection by ID
Delete(context.Context, *DeletePayload) (err error)
// Cancel collection processing by ID
Cancel(context.Context, *CancelPayload) (err error)
// Retry collection processing by ID
Retry(context.Context, *RetryPayload) (err error)
// Retrieve workflow status by ID
Workflow(context.Context, *WorkflowPayload) (res *EnduroCollectionWorkflowStatus, err error)
// Download collection by ID
Download(context.Context, *DownloadPayload) (res []byte, err error)
// Make decision for a pending collection by ID
Decide(context.Context, *DecidePayload) (err error)
// Bulk operations (retry, cancel...).
Bulk(context.Context, *BulkPayload) (res *BulkResult, err error)
// Retrieve status of current bulk operation.
BulkStatus(context.Context) (res *BulkStatusResult, err error)
}
// ServiceName is the name of the service as defined in the design. This is the
// same value that is set in the endpoint request contexts under the ServiceKey
// key.
const ServiceName = "collection"
// MethodNames lists the service method names as defined in the design. These
// are the same values that are set in the endpoint request contexts under the
// MethodKey key.
var MethodNames = [10]string{"list", "show", "delete", "cancel", "retry", "workflow", "download", "decide", "bulk", "bulk_status"}
// ListPayload is the payload type of the collection service list method.
type ListPayload struct {
Name *string
OriginalID *string
TransferID *string
AipID *string
PipelineID *string
EarliestCreatedTime *string
LatestCreatedTime *string
Status *string
// Pagination cursor
Cursor *string
}
// ListResult is the result type of the collection service list method.
type ListResult struct {
Items EnduroStoredCollectionCollection
NextCursor *string
}
// ShowPayload is the payload type of the collection service show method.
type ShowPayload struct {
// Identifier of collection to show
ID uint
}
// EnduroStoredCollection is the result type of the collection service show
// method.
type EnduroStoredCollection struct {
// Identifier of collection
ID uint
// Name of the collection
Name *string
// Status of the collection
Status string
// Identifier of processing workflow
WorkflowID *string
// Identifier of latest processing workflow run
RunID *string
// Identifier of Archivematica transfer
TransferID *string
// Identifier of Archivematica AIP
AipID *string
// Identifier provided by the client
OriginalID *string
// Identifier of Archivematica pipeline
PipelineID *string
// Creation datetime
CreatedAt string
// Start datetime
StartedAt *string
// Completion datetime
CompletedAt *string
}
// DeletePayload is the payload type of the collection service delete method.
type DeletePayload struct {
// Identifier of collection to delete
ID uint
}
// CancelPayload is the payload type of the collection service cancel method.
type CancelPayload struct {
// Identifier of collection to remove
ID uint
}
// RetryPayload is the payload type of the collection service retry method.
type RetryPayload struct {
// Identifier of collection to retry
ID uint
}
// WorkflowPayload is the payload type of the collection service workflow
// method.
type WorkflowPayload struct {
// Identifier of collection to look up
ID uint
}
// EnduroCollectionWorkflowStatus is the result type of the collection service
// workflow method.
type EnduroCollectionWorkflowStatus struct {
Status *string
History EnduroCollectionWorkflowHistoryCollection
}
// DownloadPayload is the payload type of the collection service download
// method.
type DownloadPayload struct {
// Identifier of collection to look up
ID uint
}
// DecidePayload is the payload type of the collection service decide method.
type DecidePayload struct {
// Identifier of collection to look up
ID uint
// Decision option to proceed with
Option string
}
// BulkPayload is the payload type of the collection service bulk method.
type BulkPayload struct {
Operation string
Status string
Size uint
}
// BulkResult is the result type of the collection service bulk method.
type BulkResult struct {
WorkflowID string
RunID string
}
// BulkStatusResult is the result type of the collection service bulk_status
// method.
type BulkStatusResult struct {
Running bool
StartedAt *string
ClosedAt *string
Status *string
WorkflowID *string
RunID *string
}
type EnduroStoredCollectionCollection []*EnduroStoredCollection
type EnduroCollectionWorkflowHistoryCollection []*EnduroCollectionWorkflowHistory
// WorkflowHistoryEvent describes a history event in Cadence.
type EnduroCollectionWorkflowHistory struct {
// Identifier of collection
ID *uint
// Type of the event
Type *string
// Contents of the event
Details interface{}
}
// NotFound is the type returned when attempting to operate with a collection
// that does not exist.
type NotFound struct {
// Message of error
Message string
// Identifier of missing collection
ID uint
}
// Error returns an error description.
func (e *NotFound) Error() string {
return "NotFound is the type returned when attempting to operate with a collection that does not exist."
}
// ErrorName returns "NotFound".
func (e *NotFound) ErrorName() string {
return e.Message
}
// MakeNotRunning builds a goa.ServiceError from an error.
func MakeNotRunning(err error) *goa.ServiceError {
return &goa.ServiceError{
Name: "not_running",
ID: goa.NewErrorID(),
Message: err.Error(),
}
}
// MakeNotValid builds a goa.ServiceError from an error.
func MakeNotValid(err error) *goa.ServiceError {
return &goa.ServiceError{
Name: "not_valid",
ID: goa.NewErrorID(),
Message: err.Error(),
}
}
// MakeNotAvailable builds a goa.ServiceError from an error.
func MakeNotAvailable(err error) *goa.ServiceError {
return &goa.ServiceError{
Name: "not_available",
ID: goa.NewErrorID(),
Message: err.Error(),
}
}
// NewEnduroStoredCollection initializes result type EnduroStoredCollection
// from viewed result type EnduroStoredCollection.
func NewEnduroStoredCollection(vres *collectionviews.EnduroStoredCollection) *EnduroStoredCollection {
return newEnduroStoredCollection(vres.Projected)
}
// NewViewedEnduroStoredCollection initializes viewed result type
// EnduroStoredCollection from result type EnduroStoredCollection using the
// given view.
func NewViewedEnduroStoredCollection(res *EnduroStoredCollection, view string) *collectionviews.EnduroStoredCollection {
p := newEnduroStoredCollectionView(res)
return &collectionviews.EnduroStoredCollection{Projected: p, View: "default"}
}
// NewEnduroCollectionWorkflowStatus initializes result type
// EnduroCollectionWorkflowStatus from viewed result type
// EnduroCollectionWorkflowStatus.
func NewEnduroCollectionWorkflowStatus(vres *collectionviews.EnduroCollectionWorkflowStatus) *EnduroCollectionWorkflowStatus {
return newEnduroCollectionWorkflowStatus(vres.Projected)
}
// NewViewedEnduroCollectionWorkflowStatus initializes viewed result type
// EnduroCollectionWorkflowStatus from result type
// EnduroCollectionWorkflowStatus using the given view.
func NewViewedEnduroCollectionWorkflowStatus(res *EnduroCollectionWorkflowStatus, view string) *collectionviews.EnduroCollectionWorkflowStatus {
p := newEnduroCollectionWorkflowStatusView(res)
return &collectionviews.EnduroCollectionWorkflowStatus{Projected: p, View: "default"}
}
// newEnduroStoredCollection converts projected type EnduroStoredCollection to
// service type EnduroStoredCollection.
func newEnduroStoredCollection(vres *collectionviews.EnduroStoredCollectionView) *EnduroStoredCollection {
res := &EnduroStoredCollection{
Name: vres.Name,
WorkflowID: vres.WorkflowID,
RunID: vres.RunID,
TransferID: vres.TransferID,
AipID: vres.AipID,
OriginalID: vres.OriginalID,
PipelineID: vres.PipelineID,
StartedAt: vres.StartedAt,
CompletedAt: vres.CompletedAt,
}
if vres.ID != nil {
res.ID = *vres.ID
}
if vres.Status != nil {
res.Status = *vres.Status
}
if vres.CreatedAt != nil {
res.CreatedAt = *vres.CreatedAt
}
if vres.Status == nil {
res.Status = "new"
}
return res
}
// newEnduroStoredCollectionView projects result type EnduroStoredCollection to
// projected type EnduroStoredCollectionView using the "default" view.
func newEnduroStoredCollectionView(res *EnduroStoredCollection) *collectionviews.EnduroStoredCollectionView {
vres := &collectionviews.EnduroStoredCollectionView{
ID: &res.ID,
Name: res.Name,
Status: &res.Status,
WorkflowID: res.WorkflowID,
RunID: res.RunID,
TransferID: res.TransferID,
AipID: res.AipID,
OriginalID: res.OriginalID,
PipelineID: res.PipelineID,
CreatedAt: &res.CreatedAt,
StartedAt: res.StartedAt,
CompletedAt: res.CompletedAt,
}
return vres
}
// newEnduroCollectionWorkflowStatus converts projected type
// EnduroCollectionWorkflowStatus to service type
// EnduroCollectionWorkflowStatus.
func newEnduroCollectionWorkflowStatus(vres *collectionviews.EnduroCollectionWorkflowStatusView) *EnduroCollectionWorkflowStatus {
res := &EnduroCollectionWorkflowStatus{
Status: vres.Status,
}
if vres.History != nil {
res.History = newEnduroCollectionWorkflowHistoryCollection(vres.History)
}
return res
}
// newEnduroCollectionWorkflowStatusView projects result type
// EnduroCollectionWorkflowStatus to projected type
// EnduroCollectionWorkflowStatusView using the "default" view.
func newEnduroCollectionWorkflowStatusView(res *EnduroCollectionWorkflowStatus) *collectionviews.EnduroCollectionWorkflowStatusView {
vres := &collectionviews.EnduroCollectionWorkflowStatusView{
Status: res.Status,
}
if res.History != nil {
vres.History = newEnduroCollectionWorkflowHistoryCollectionView(res.History)
}
return vres
}
// newEnduroCollectionWorkflowHistoryCollection converts projected type
// EnduroCollectionWorkflowHistoryCollection to service type
// EnduroCollectionWorkflowHistoryCollection.
func newEnduroCollectionWorkflowHistoryCollection(vres collectionviews.EnduroCollectionWorkflowHistoryCollectionView) EnduroCollectionWorkflowHistoryCollection {
res := make(EnduroCollectionWorkflowHistoryCollection, len(vres))
for i, n := range vres {
res[i] = newEnduroCollectionWorkflowHistory(n)
}
return res
}
// newEnduroCollectionWorkflowHistoryCollectionView projects result type
// EnduroCollectionWorkflowHistoryCollection to projected type
// EnduroCollectionWorkflowHistoryCollectionView using the "default" view.
func newEnduroCollectionWorkflowHistoryCollectionView(res EnduroCollectionWorkflowHistoryCollection) collectionviews.EnduroCollectionWorkflowHistoryCollectionView {
vres := make(collectionviews.EnduroCollectionWorkflowHistoryCollectionView, len(res))
for i, n := range res {
vres[i] = newEnduroCollectionWorkflowHistoryView(n)
}
return vres
}
// newEnduroCollectionWorkflowHistory converts projected type
// EnduroCollectionWorkflowHistory to service type
// EnduroCollectionWorkflowHistory.
func newEnduroCollectionWorkflowHistory(vres *collectionviews.EnduroCollectionWorkflowHistoryView) *EnduroCollectionWorkflowHistory {
res := &EnduroCollectionWorkflowHistory{
ID: vres.ID,
Type: vres.Type,
Details: vres.Details,
}
return res
}
// newEnduroCollectionWorkflowHistoryView projects result type
// EnduroCollectionWorkflowHistory to projected type
// EnduroCollectionWorkflowHistoryView using the "default" view.
func newEnduroCollectionWorkflowHistoryView(res *EnduroCollectionWorkflowHistory) *collectionviews.EnduroCollectionWorkflowHistoryView {
vres := &collectionviews.EnduroCollectionWorkflowHistoryView{
ID: res.ID,
Type: res.Type,
Details: res.Details,
}
return vres
}