Skip to content

Commit c92f73d

Browse files
CROSSLINK-188 Add supplier info for all notifications in Opaque mode (#344)
* CROSSLINK-188 Add supplier info for all notifications in Opaque mode * CROSSLINK-188 Add env var to prepend supplier symbol * Rephrase --------- Co-authored-by: Jakub Skoczen <jakub@indexdata.com>
1 parent 02b8c7d commit c92f73d

File tree

3 files changed

+30
-25
lines changed

3 files changed

+30
-25
lines changed

broker/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ Configuration is provided via environment variables:
6363
| `SUPPLIER_INFO` | Should `request/supplierInfo` be populated from Directory | `true` |
6464
| `RETURN_INFO` | Should `returnInfo` be populated from Directory for supplier `Loaned` message | `true` |
6565
| `VENDOR_INFO` | Should `note` be prepended with `Vendor: xxx` note | `true` |
66+
| `SUPPLIER_SYMBOL_NOTE` | Should `note` field be prepended with a `Supplier: {symbol}` note | `true` |
6667
| `OFFERED_COSTS` | Should `deliveryCosts` be transferred to `offeredCosts` for ReShare requesters | `false` |
6768
| `NOTE_FIELD_SEP` | Separator for fields (e.g. Vendor) prepended to the note | `, ` |
6869
| `CLIENT_DELAY` | Delay duration for outgoing ISO18626 messages | `0ms` |

broker/client/client.go

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ var appendSupplierInfo, _ = utils.GetEnvBool("SUPPLIER_INFO", true)
4242
var appendRequestingAgencyInfo, _ = utils.GetEnvBool("REQ_AGENCY_INFO", true)
4343
var appendReturnInfo, _ = utils.GetEnvBool("RETURN_INFO", true)
4444
var prependVendor, _ = utils.GetEnvBool("VENDOR_INFO", true)
45+
var supplierSymbolNote, _ = utils.GetEnvBool("SUPPLIER_SYMBOL_NOTE", true)
4546

4647
type Iso18626Client struct {
4748
eventBus events.EventBus
@@ -140,7 +141,7 @@ func populateReturnAddress(message *iso18626.ISO18626Message, name string, agenc
140141
}
141142
}
142143

143-
func populateVendor(message *iso18626.SupplyingAgencyMessage, vendor string) {
144+
func prependVendorNote(message *iso18626.SupplyingAgencyMessage, vendor string) {
144145
if message.MessageInfo.Note != "" {
145146
sep := shim.NOTE_FIELD_SEP
146147
if strings.HasPrefix(message.MessageInfo.Note, "#") {
@@ -675,24 +676,27 @@ func createSupplyingAgencyMessage(trCtx transactionContext, target *messageTarge
675676
name, agencyId, address, _ := getPeerInfo(target.peer, target.supplier.SupplierSymbol)
676677
populateReturnAddress(message, name, agencyId, address)
677678
}
679+
if supplierSymbolNote {
680+
prependSupplierSymbolNote(trCtx, sam)
681+
}
678682
if prependVendor && target.firstMessage && target.peer != nil && target.peer.Vendor != trCtx.requester.Vendor {
679-
populateVendor(sam, target.peer.Vendor)
683+
prependVendorNote(sam, target.peer.Vendor)
680684
}
681-
682-
updateSupplierNote(trCtx, sam)
683-
684685
return message
685686
}
686687

687-
func updateSupplierNote(trCtx transactionContext, sam *iso18626.SupplyingAgencyMessage) {
688+
func prependSupplierSymbolNote(trCtx transactionContext, sam *iso18626.SupplyingAgencyMessage) {
688689
if trCtx.requester != nil && trCtx.requester.BrokerMode == string(common.BrokerModeOpaque) &&
689-
(sam.StatusInfo.Status == iso18626.TypeStatusExpectToSupply || sam.StatusInfo.Status == iso18626.TypeStatusUnfilled) &&
690690
trCtx.selectedSupplier != nil {
691691
symbol := strings.SplitN(trCtx.selectedSupplier.SupplierSymbol, ":", 2)
692-
note := sam.MessageInfo.Note
693-
sam.MessageInfo.Note = "Supplier: " + symbol[1]
694-
if note != "" {
695-
sam.MessageInfo.Note += ", " + note
692+
if sam.MessageInfo.Note != "" {
693+
sep := shim.NOTE_FIELD_SEP
694+
if strings.HasPrefix(sam.MessageInfo.Note, "#") {
695+
sep = ""
696+
}
697+
sam.MessageInfo.Note = "Supplier: " + symbol[1] + sep + sam.MessageInfo.Note
698+
} else {
699+
sam.MessageInfo.Note = "Supplier: " + symbol[1]
696700
}
697701
}
698702
}

broker/client/client_test.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -351,18 +351,18 @@ func TestValidateReason(t *testing.T) {
351351
assert.Equal(t, iso18626.TypeReasonForMessageStatusRequestResponse, reason)
352352
}
353353

354-
func TestPopulateVendorInNote(t *testing.T) {
354+
func TestPrependVendorInNote(t *testing.T) {
355355
message := iso18626.ISO18626Message{
356356
SupplyingAgencyMessage: &iso18626.SupplyingAgencyMessage{},
357357
}
358358
message.SupplyingAgencyMessage.MessageInfo.Note = ""
359-
populateVendor(message.SupplyingAgencyMessage, "Alma")
359+
prependVendorNote(message.SupplyingAgencyMessage, "Alma")
360360
assert.Equal(t, message.SupplyingAgencyMessage.MessageInfo.Note, "Vendor: Alma")
361361
message.SupplyingAgencyMessage.MessageInfo.Note = "some note"
362-
populateVendor(message.SupplyingAgencyMessage, "Alma")
362+
prependVendorNote(message.SupplyingAgencyMessage, "Alma")
363363
assert.Equal(t, message.SupplyingAgencyMessage.MessageInfo.Note, "Vendor: Alma, some note")
364364
message.SupplyingAgencyMessage.MessageInfo.Note = "#special note#"
365-
populateVendor(message.SupplyingAgencyMessage, "ReShare")
365+
prependVendorNote(message.SupplyingAgencyMessage, "ReShare")
366366
assert.Equal(t, message.SupplyingAgencyMessage.MessageInfo.Note, "Vendor: ReShare#special note#")
367367
}
368368

@@ -816,38 +816,38 @@ func TestBlockUnfilled(t *testing.T) {
816816
assert.False(t, blockUnfilled(trCtx))
817817
}
818818

819-
func TestUpdateSupplierNote(t *testing.T) {
819+
func TestPrependSupplierSymbolNote(t *testing.T) {
820820
sam := iso18626.SupplyingAgencyMessage{}
821821
trCtx := transactionContext{}
822-
updateSupplierNote(trCtx, &sam)
822+
prependSupplierSymbolNote(trCtx, &sam)
823823
assert.Equal(t, "", sam.MessageInfo.Note)
824824

825825
requester := ill_db.Peer{BrokerMode: string(common.BrokerModeTransparent)}
826826
trCtx.requester = &requester
827-
updateSupplierNote(trCtx, &sam)
827+
prependSupplierSymbolNote(trCtx, &sam)
828828
assert.Equal(t, "", sam.MessageInfo.Note)
829829

830830
requester.BrokerMode = string(common.BrokerModeOpaque)
831-
updateSupplierNote(trCtx, &sam)
831+
prependSupplierSymbolNote(trCtx, &sam)
832832
assert.Equal(t, "", sam.MessageInfo.Note)
833833

834834
sam.StatusInfo.Status = iso18626.TypeStatusExpectToSupply
835-
updateSupplierNote(trCtx, &sam)
835+
prependSupplierSymbolNote(trCtx, &sam)
836836
assert.Equal(t, "", sam.MessageInfo.Note)
837837

838838
supplier := ill_db.LocatedSupplier{SupplierSymbol: "ISIL:SUP1"}
839839
trCtx.selectedSupplier = &supplier
840-
updateSupplierNote(trCtx, &sam)
840+
prependSupplierSymbolNote(trCtx, &sam)
841841
assert.Equal(t, "Supplier: SUP1", sam.MessageInfo.Note)
842842

843843
sam.MessageInfo.Note = "Original note"
844-
updateSupplierNote(trCtx, &sam)
844+
prependSupplierSymbolNote(trCtx, &sam)
845845
assert.Equal(t, "Supplier: SUP1, Original note", sam.MessageInfo.Note)
846846

847847
sam.StatusInfo.Status = iso18626.TypeStatusUnfilled
848-
sam.MessageInfo.Note = "Original note 2"
849-
updateSupplierNote(trCtx, &sam)
850-
assert.Equal(t, "Supplier: SUP1, Original note 2", sam.MessageInfo.Note)
848+
sam.MessageInfo.Note = "#special note#"
849+
prependSupplierSymbolNote(trCtx, &sam)
850+
assert.Equal(t, "Supplier: SUP1#special note#", sam.MessageInfo.Note)
851851
}
852852

853853
func TestHandleIllMessage(t *testing.T) {

0 commit comments

Comments
 (0)