Skip to content

Commit 4efd908

Browse files
committed
Keys for batch action defaults CROSSLINK-297
1 parent bd5553a commit 4efd908

5 files changed

Lines changed: 33 additions & 5 deletions

File tree

broker/oapi/open-api.yaml

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1218,6 +1218,19 @@ components:
12181218
- actionName
12191219
- batchQuery
12201220

1221+
BatchActionDefault:
1222+
title: Batch Action Default
1223+
description: A built-in batch action that clients can offer as a starting point
1224+
allOf:
1225+
- $ref: '#/components/schemas/CreateBatchAction'
1226+
- type: object
1227+
properties:
1228+
titleKey:
1229+
type: string
1230+
description: Stable identifier for this default, for clients to look up a localized title
1231+
required:
1232+
- titleKey
1233+
12211234
UpdateBatchAction:
12221235
type: object
12231236
title: Update Batch Action
@@ -2340,7 +2353,7 @@ paths:
23402353
schema:
23412354
type: array
23422355
items:
2343-
$ref: '#/components/schemas/CreateBatchAction'
2356+
$ref: '#/components/schemas/BatchActionDefault'
23442357
'500':
23452358
description: Internal Server Error
23462359
content:

broker/patron_request/api/api-handler_test.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -974,10 +974,17 @@ func TestGetStateModelBatchActions(t *testing.T) {
974974
rr := httptest.NewRecorder()
975975
handler.GetStateModelBatchActions(rr, req, proapi.GetStateModelBatchActionsParams{})
976976
assert.Equal(t, http.StatusOK, rr.Code)
977-
var actions []proapi.CreateBatchAction
977+
var actions []proapi.BatchActionDefault
978978
err := json.Unmarshal(rr.Body.Bytes(), &actions)
979979
assert.NoError(t, err)
980980
assert.Len(t, actions, 4)
981+
// Clients key translated titles off titleKey, so each default needs a distinct one.
982+
seen := map[string]bool{}
983+
for _, action := range actions {
984+
assert.NotEmpty(t, action.TitleKey)
985+
assert.False(t, seen[action.TitleKey], "duplicate titleKey %s", action.TitleKey)
986+
seen[action.TitleKey] = true
987+
}
981988
}
982989

983990
type PrRepoError struct {

broker/patron_request/service/statemodel.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ type StateModelService struct {
2121

2222
type StateModelsConfig struct {
2323
StateModels map[string]proapi.StateModel `json:"stateModels"`
24-
BatchActionDefaults []proapi.CreateBatchAction `json:"batchActionDefaults"`
24+
BatchActionDefaults []proapi.BatchActionDefault `json:"batchActionDefaults"`
2525
}
2626

2727
func (s *StateModelService) GetStateModel(modelName string) (*proapi.StateModel, error) {
@@ -240,13 +240,13 @@ func hasTransitionTarget(allowedTransitionTargets map[string]struct{}, name stri
240240
return ok
241241
}
242242

243-
func GetStateModelBatchActionDefaults() []proapi.CreateBatchAction {
243+
func GetStateModelBatchActionDefaults() []proapi.BatchActionDefault {
244244
// Return a defensive deep copy so callers can't mutate embedded defaults.
245245
data, err := json.Marshal(stateModelsConfig.BatchActionDefaults)
246246
if err != nil {
247247
return slices.Clone(stateModelsConfig.BatchActionDefaults)
248248
}
249-
var out []proapi.CreateBatchAction
249+
var out []proapi.BatchActionDefault
250250
if err := json.Unmarshal(data, &out); err != nil {
251251
return slices.Clone(stateModelsConfig.BatchActionDefaults)
252252
}

broker/patron_request/service/statemodels/state-models.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -698,6 +698,7 @@
698698
"batchActionDefaults": [
699699
{
700700
"actionName": "email-pullslips",
701+
"titleKey": "email-pullslips",
701702
"title": "Email pull slips ready to ship",
702703
"batchQuery": "side = lending and state = WILL_SUPPLY",
703704
"schedule": "FREQ=WEEKLY;BYDAY=MO,TU,WE,TH,FR;BYHOUR=6;BYMINUTE=0",
@@ -713,6 +714,7 @@
713714
},
714715
{
715716
"actionName": "request-aging",
717+
"titleKey": "request-aging-express",
716718
"title": "Request aging of express requests",
717719
"batchQuery": "(state = VALIDATED or state = WILL_SUPPLY or state = CONDITION_PENDING or state = NEEDS_REVIEW) and service_level = Express",
718720
"schedule": "FREQ=MINUTELY;INTERVAL=15",
@@ -722,6 +724,7 @@
722724
},
723725
{
724726
"actionName": "request-aging",
727+
"titleKey": "request-aging-rush",
725728
"title": "Request aging of rush requests",
726729
"batchQuery": "(state = VALIDATED or state = WILL_SUPPLY or state = CONDITION_PENDING or state = NEEDS_REVIEW) and service_level = Rush",
727730
"schedule": "FREQ=HOURLY;BYMINUTE=0",
@@ -731,6 +734,7 @@
731734
},
732735
{
733736
"actionName": "request-aging",
737+
"titleKey": "request-aging-all",
734738
"title": "Request aging of all requests",
735739
"batchQuery": "state = VALIDATED or state = WILL_SUPPLY or state = CONDITION_PENDING or state = NEEDS_REVIEW",
736740
"schedule": "FREQ=DAILY;BYHOUR=5;BYMINUTE=0",

misc/state-models.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,7 @@ stateModels:
474474

475475
batchActionDefaults:
476476
- actionName: email-pullslips
477+
titleKey: email-pullslips
477478
title: Email pull slips ready to ship
478479
batchQuery: side = lending and state = WILL_SUPPLY
479480
schedule: "FREQ=WEEKLY;BYDAY=MO,TU,WE,TH,FR;BYHOUR=6;BYMINUTE=0"
@@ -486,20 +487,23 @@ batchActionDefaults:
486487
isHtml: true
487488

488489
- actionName: request-aging
490+
titleKey: request-aging-express
489491
title: Request aging of express requests
490492
batchQuery: "(state = VALIDATED or state = WILL_SUPPLY or state = CONDITION_PENDING or state = NEEDS_REVIEW) and service_level = Express"
491493
schedule: "FREQ=MINUTELY;INTERVAL=15"
492494
actionParams:
493495
interval: 2h
494496

495497
- actionName: request-aging
498+
titleKey: request-aging-rush
496499
title: Request aging of rush requests
497500
batchQuery: "(state = VALIDATED or state = WILL_SUPPLY or state = CONDITION_PENDING or state = NEEDS_REVIEW) and service_level = Rush"
498501
schedule: "FREQ=HOURLY;BYMINUTE=0"
499502
actionParams:
500503
interval: 24h
501504

502505
- actionName: request-aging
506+
titleKey: request-aging-all
503507
title: Request aging of all requests
504508
batchQuery: state = VALIDATED or state = WILL_SUPPLY or state = CONDITION_PENDING or state = NEEDS_REVIEW
505509
schedule: "FREQ=DAILY;BYHOUR=5;BYMINUTE=0"

0 commit comments

Comments
 (0)