Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions broker/api/sse_broker.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ type SseMessage struct {
}

type SseIsoMessageEvent struct {
Event events.EventName `json:"event,omitempty"`
Data iso18626.Iso18626MessageNS `json:"data,omitempty"`
Event events.EventName `json:"event,omitempty"`
Data iso18626.ISO18626Message `json:"data,omitempty"`
}

func (b *SseBroker) IncomingIsoMessage(ctx common.ExtendedContext, event events.Event) {
Expand Down
48 changes: 24 additions & 24 deletions broker/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,12 @@ func (c *Iso18626Client) getSkippedSupplierAndPeer(ctx common.ExtendedContext, i
return &skipped, &skippedPeer, nil
}

func isNotification(msg *iso18626.Iso18626MessageNS) bool {
func isNotification(msg *iso18626.ISO18626Message) bool {
return msg != nil && msg.SupplyingAgencyMessage != nil &&
msg.SupplyingAgencyMessage.MessageInfo.ReasonForMessage == iso18626.TypeReasonForMessageNotification
}

func getSymbol(msg *iso18626.Iso18626MessageNS) string {
func getSymbol(msg *iso18626.ISO18626Message) string {
symbol := ""
if msg != nil && msg.SupplyingAgencyMessage != nil {
symbol = msg.SupplyingAgencyMessage.Header.SupplyingAgencyId.AgencyIdType.Text + ":" +
Expand All @@ -128,7 +128,7 @@ func getSymbol(msg *iso18626.Iso18626MessageNS) string {
return symbol
}

func populateReturnAddress(message *iso18626.Iso18626MessageNS, name string, agencyId iso18626.TypeAgencyId, address iso18626.PhysicalAddress) {
func populateReturnAddress(message *iso18626.ISO18626Message, name string, agencyId iso18626.TypeAgencyId, address iso18626.PhysicalAddress) {
if message.SupplyingAgencyMessage.ReturnInfo == nil {
message.SupplyingAgencyMessage.ReturnInfo = &iso18626.ReturnInfo{}
}
Expand Down Expand Up @@ -172,7 +172,7 @@ func (c *Iso18626Client) updateSupplierStatus(ctx common.ExtendedContext, id str
return err
}

func populateRequesterInfo(message *iso18626.Iso18626MessageNS, name string, address iso18626.PhysicalAddress, email iso18626.ElectronicAddress) {
func populateRequesterInfo(message *iso18626.ISO18626Message, name string, address iso18626.PhysicalAddress, email iso18626.ElectronicAddress) {
if message.Request.RequestingAgencyInfo == nil || message.Request.RequestingAgencyInfo.Name == "" {
if message.Request.RequestingAgencyInfo == nil {
message.Request.RequestingAgencyInfo = &iso18626.RequestingAgencyInfo{}
Expand Down Expand Up @@ -200,7 +200,7 @@ func populateRequesterInfo(message *iso18626.Iso18626MessageNS, name string, add
}
}

func populateDeliveryAddress(message *iso18626.Iso18626MessageNS, address iso18626.PhysicalAddress, email iso18626.ElectronicAddress) {
func populateDeliveryAddress(message *iso18626.ISO18626Message, address iso18626.PhysicalAddress, email iso18626.ElectronicAddress) {
var hasAddress, hasEmail bool
for _, di := range message.Request.RequestedDeliveryInfo {
if di.Address != nil {
Expand Down Expand Up @@ -243,7 +243,7 @@ func populateDeliveryAddress(message *iso18626.Iso18626MessageNS, address iso186
}
}

func populateSupplierInfo(message *iso18626.Iso18626MessageNS, name string, agencyId iso18626.TypeAgencyId, address iso18626.PhysicalAddress) {
func populateSupplierInfo(message *iso18626.ISO18626Message, name string, agencyId iso18626.TypeAgencyId, address iso18626.PhysicalAddress) {
if isEmptySupplierInfo(message.Request.SupplierInfo) {
var sb strings.Builder
shim.MarshalReturnLabel(&sb, name, &address)
Expand Down Expand Up @@ -357,7 +357,7 @@ func guessReason(reason iso18626.TypeReasonForMessage, requesterAction string, p
return expectedReason
}

func (c *Iso18626Client) checkConfirmationError(ctx common.ExtendedContext, response *iso18626.Iso18626MessageNS, defaultStatus events.EventStatus, result *events.EventResult) events.EventStatus {
func (c *Iso18626Client) checkConfirmationError(ctx common.ExtendedContext, response *iso18626.ISO18626Message, defaultStatus events.EventStatus, result *events.EventResult) events.EventStatus {
status := defaultStatus
if response.RequestConfirmation != nil &&
response.RequestConfirmation.ConfirmationHeader.MessageStatus == iso18626.TypeMessageStatusERROR {
Expand Down Expand Up @@ -454,7 +454,7 @@ func (c *Iso18626Client) checkConfirmationError(ctx common.ExtendedContext, resp
return status
}

func (c *Iso18626Client) HandleIllMessage(ctx common.ExtendedContext, peer *ill_db.Peer, msg *iso18626.Iso18626MessageNS) (*iso18626.Iso18626MessageNS, error) {
func (c *Iso18626Client) HandleIllMessage(ctx common.ExtendedContext, peer *ill_db.Peer, msg *iso18626.ISO18626Message) (*iso18626.ISO18626Message, error) {
if peer == nil {
return nil, fmt.Errorf("peer is nil")
}
Expand All @@ -464,7 +464,7 @@ func (c *Iso18626Client) HandleIllMessage(ctx common.ExtendedContext, peer *ill_
return c.SendHttpPost(peer, msg)
}

func (c *Iso18626Client) SendHttpPost(peer *ill_db.Peer, msg *iso18626.Iso18626MessageNS) (*iso18626.Iso18626MessageNS, error) {
func (c *Iso18626Client) SendHttpPost(peer *ill_db.Peer, msg *iso18626.ISO18626Message) (*iso18626.ISO18626Message, error) {
httpClient := httpclient.NewClient().
WithMaxSize(int64(c.maxMsgSize)).
WithHeaders("User-Agent", vcs.GetSignature())
Expand All @@ -473,20 +473,20 @@ func (c *Iso18626Client) SendHttpPost(peer *ill_db.Peer, msg *iso18626.Iso18626M
}
time.Sleep(c.sendDelay)
iso18626Shim := shim.GetShim(peer.Vendor)
var resmsg iso18626.Iso18626MessageNS
var resmsg iso18626.ISO18626Message
err := httpClient.RequestResponse(c.client, http.MethodPost,
[]string{httpclient.ContentTypeApplicationXml, httpclient.ContentTypeTextXml},
peer.Url, msg, &resmsg, func(v any) ([]byte, error) {
if isoM, ok := v.(*iso18626.Iso18626MessageNS); ok {
if isoM, ok := v.(*iso18626.ISO18626Message); ok {
return iso18626Shim.ApplyToOutgoingRequest(isoM)
} else {
return []byte{}, fmt.Errorf("v is not a *iso18626.Iso18626MessageNS: %v", v)
return []byte{}, fmt.Errorf("v is not a *iso18626.ISO18626Message: %v", v)
}
}, func(b []byte, v any) error {
if isoM, ok := v.(*iso18626.Iso18626MessageNS); ok {
if isoM, ok := v.(*iso18626.ISO18626Message); ok {
return iso18626Shim.ApplyToIncomingResponse(b, isoM)
} else {
return fmt.Errorf("v is not a *iso18626.Iso18626MessageNS: %v", v)
return fmt.Errorf("v is not a *iso18626.ISO18626Message: %v", v)
}
})
if err != nil {
Expand Down Expand Up @@ -652,12 +652,12 @@ func handleSelectedSupplier(trCtx transactionContext) (*messageTarget, error) {
return nil, fmt.Errorf(FailedToResolveStatus, lastReceivedStatus.String)
}

func createSupplyingAgencyMessage(trCtx transactionContext, target *messageTarget) *iso18626.Iso18626MessageNS {
var message *iso18626.Iso18626MessageNS
func createSupplyingAgencyMessage(trCtx transactionContext, target *messageTarget) *iso18626.ISO18626Message {
var message *iso18626.ISO18626Message
if trCtx.event.EventData.IncomingMessage != nil && trCtx.event.EventData.IncomingMessage.SupplyingAgencyMessage != nil {
message = trCtx.event.EventData.IncomingMessage
} else {
message = iso18626.NewIso18626MessageNS()
message = iso18626.NewISO18626Message()
message.SupplyingAgencyMessage = &iso18626.SupplyingAgencyMessage{}
if trCtx.requester.BrokerMode == string(common.BrokerModeOpaque) && target.brokerMessage {
message.SupplyingAgencyMessage.MessageInfo.ReasonForMessage = iso18626.TypeReasonForMessageNotification
Expand Down Expand Up @@ -705,7 +705,7 @@ func prependSupplierSymbolNote(trCtx transactionContext, sam *iso18626.Supplying
}
}

func (c *Iso18626Client) sendAndUpdateStatus(ctx common.ExtendedContext, trCtx transactionContext, message *iso18626.Iso18626MessageNS) (events.EventStatus, *events.EventResult) {
func (c *Iso18626Client) sendAndUpdateStatus(ctx common.ExtendedContext, trCtx transactionContext, message *iso18626.ISO18626Message) (events.EventStatus, *events.EventResult) {
resData := &events.EventResult{}
resData.OutgoingMessage = message

Expand Down Expand Up @@ -746,7 +746,7 @@ func (c *Iso18626Client) createAndSendRequestOrRequestingAgencyMessage(ctx commo
// the action on the transaction is not relevant and we need to look at the new supplier's last action
// however, if requester sends a retry request it is captured on the transaction
var isRequest = trCtx.selectedSupplier.LastAction.String == "" || trCtx.transaction.LastRequesterAction.String == string(ill_db.RequestAction)
var message *iso18626.Iso18626MessageNS
var message *iso18626.ISO18626Message
var action iso18626.TypeAction
if isRequest {
message, action = createRequestMessage(trCtx)
Expand All @@ -759,8 +759,8 @@ func (c *Iso18626Client) createAndSendRequestOrRequestingAgencyMessage(ctx commo
return c.sendAndUpdateSupplier(ctx, trCtx, message, action)
}

func createRequestMessage(trCtx transactionContext) (*iso18626.Iso18626MessageNS, iso18626.TypeAction) {
var message = iso18626.NewIso18626MessageNS()
func createRequestMessage(trCtx transactionContext) (*iso18626.ISO18626Message, iso18626.TypeAction) {
var message = iso18626.NewISO18626Message()
message.Request = &iso18626.Request{
Header: createMessageHeader(*trCtx.transaction, trCtx.selectedSupplier, true, trCtx.selectedPeer.BrokerMode),
BibliographicInfo: trCtx.transaction.IllTransactionData.BibliographicInfo,
Expand All @@ -785,8 +785,8 @@ func createRequestMessage(trCtx transactionContext) (*iso18626.Iso18626MessageNS
return message, ill_db.RequestAction
}

func createRequestingAgencyMessage(trCtx transactionContext) (*iso18626.Iso18626MessageNS, iso18626.TypeAction, error) {
var message = iso18626.NewIso18626MessageNS()
func createRequestingAgencyMessage(trCtx transactionContext) (*iso18626.ISO18626Message, iso18626.TypeAction, error) {
var message = iso18626.NewISO18626Message()
found, ok := iso18626.ActionMap[trCtx.transaction.LastRequesterAction.String]
if !ok {
return message, "", fmt.Errorf("failed to resolve action for value: %s", trCtx.transaction.LastRequesterAction.String)
Expand All @@ -803,7 +803,7 @@ func createRequestingAgencyMessage(trCtx transactionContext) (*iso18626.Iso18626
return message, found, nil
}

func (c *Iso18626Client) sendAndUpdateSupplier(ctx common.ExtendedContext, trCtx transactionContext, message *iso18626.Iso18626MessageNS, action iso18626.TypeAction) (events.EventStatus, *events.EventResult) {
func (c *Iso18626Client) sendAndUpdateSupplier(ctx common.ExtendedContext, trCtx transactionContext, message *iso18626.ISO18626Message, action iso18626.TypeAction) (events.EventStatus, *events.EventResult) {
eventStatus := events.EventStatusSuccess
resData := events.EventResult{}
resData.OutgoingMessage = message
Expand Down
24 changes: 12 additions & 12 deletions broker/client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func TestSendHttpPost(t *testing.T) {
for k, v := range headers {
assert.Equal(t, v, r.Header.Get(k))
}
msg := iso18626.NewIso18626MessageNS()
msg := iso18626.NewISO18626Message()
buf, err := xml.Marshal(msg)
assert.NoError(t, err)
_, err = w.Write(buf)
Expand All @@ -77,7 +77,7 @@ func TestSendHttpPost(t *testing.T) {

var client = CreateIso18626Client(new(events.PostgresEventBus), new(ill_db.PgIllRepo), *new(prservice.PatronRequestMessageHandler), 0, 0*time.Second)

msg := iso18626.NewIso18626MessageNS()
msg := iso18626.NewISO18626Message()
peer := ill_db.Peer{
Url: server.URL,
HttpHeaders: headers,
Expand Down Expand Up @@ -115,7 +115,7 @@ func TestGetPeerNameAndAddress(t *testing.T) {
}

func TestPopulateRequesterInfo(t *testing.T) {
message := iso18626.NewIso18626MessageNS()
message := iso18626.NewISO18626Message()
message.Request = &iso18626.Request{}
name := "Requester 1"
address := iso18626.PhysicalAddress{
Expand All @@ -140,7 +140,7 @@ func TestPopulateRequesterInfo(t *testing.T) {
}

func TestPopulateDeliveryAddress(t *testing.T) {
message := iso18626.NewIso18626MessageNS()
message := iso18626.NewISO18626Message()
message.Request = &iso18626.Request{}
address := iso18626.PhysicalAddress{
Line1: "Home 1",
Expand All @@ -164,7 +164,7 @@ func TestPopulateDeliveryAddress(t *testing.T) {

func TestPopulateDeliveryAddressPatron(t *testing.T) {
yes := iso18626.TypeYesNoY
message := iso18626.NewIso18626MessageNS()
message := iso18626.NewISO18626Message()
message.Request = &iso18626.Request{
PatronInfo: &iso18626.PatronInfo{
GivenName: "Patron 1",
Expand Down Expand Up @@ -202,7 +202,7 @@ func TestPopulateDeliveryAddressPatron(t *testing.T) {
}

func TestPopulateSupplierAddress(t *testing.T) {
message := iso18626.NewIso18626MessageNS()
message := iso18626.NewISO18626Message()
message.SupplyingAgencyMessage = &iso18626.SupplyingAgencyMessage{}
name := "Requester 1"
address := iso18626.PhysicalAddress{
Expand Down Expand Up @@ -239,7 +239,7 @@ func TestPopulateSupplierAddress(t *testing.T) {
}

func TestPopulateSupplierInfo(t *testing.T) {
message := iso18626.NewIso18626MessageNS()
message := iso18626.NewISO18626Message()
message.Request = &iso18626.Request{
SupplierInfo: []iso18626.SupplierInfo{
{XMLName: xml.Name{Local: "supplierInfo"}},
Expand Down Expand Up @@ -355,7 +355,7 @@ func TestValidateReason(t *testing.T) {
}

func TestPrependVendorInNote(t *testing.T) {
message := iso18626.NewIso18626MessageNS()
message := iso18626.NewISO18626Message()
message.SupplyingAgencyMessage = &iso18626.SupplyingAgencyMessage{}
message.SupplyingAgencyMessage.MessageInfo.Note = ""
prependVendorNote(message.SupplyingAgencyMessage, "Alma")
Expand Down Expand Up @@ -399,7 +399,7 @@ func createSupplyingAgencyMessageEvent(notification bool) events.Event {
if notification {
reason = iso18626.TypeReasonForMessageNotification
}
var iMessage = iso18626.NewIso18626MessageNS()
var iMessage = iso18626.NewISO18626Message()
iMessage.SupplyingAgencyMessage = &iso18626.SupplyingAgencyMessage{
Header: iso18626.Header{
SupplyingAgencyId: iso18626.TypeAgencyId{
Expand Down Expand Up @@ -728,7 +728,7 @@ func TestCreateRequestingAgencyMessage(t *testing.T) {
Name: "isil:sup1",
Vendor: string(directory.Alma),
}
var iMessage = iso18626.NewIso18626MessageNS()
var iMessage = iso18626.NewISO18626Message()
iMessage.RequestingAgencyMessage = &iso18626.RequestingAgencyMessage{
Note: "This is note",
}
Expand Down Expand Up @@ -796,7 +796,7 @@ func TestBlockUnfilled(t *testing.T) {
}, requester: &requester}
assert.False(t, blockUnfilled(trCtx))

trCtx.event.EventData.IncomingMessage = iso18626.NewIso18626MessageNS()
trCtx.event.EventData.IncomingMessage = iso18626.NewISO18626Message()
assert.False(t, blockUnfilled(trCtx))

trCtx.event.EventData.IncomingMessage.SupplyingAgencyMessage = &iso18626.SupplyingAgencyMessage{}
Expand Down Expand Up @@ -860,7 +860,7 @@ func TestHandleIllMessage(t *testing.T) {
appCtx := common.CreateExtCtxWithArgs(context.Background(), nil)

client := CreateIso18626Client(new(events.PostgresEventBus), new(MockIllRepositorySkippedSup), mockPrMessageHandler, 1, 0*time.Second)
sam := iso18626.NewIso18626MessageNS()
sam := iso18626.NewISO18626Message()
sam.SupplyingAgencyMessage = &iso18626.SupplyingAgencyMessage{
Header: iso18626.Header{
RequestingAgencyRequestId: "req-1",
Expand Down
16 changes: 8 additions & 8 deletions broker/events/eventmodels.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,14 @@ type EventData struct {
}

type CommonEventData struct {
IncomingMessage *iso18626.Iso18626MessageNS `json:"incomingMessage,omitempty"`
OutgoingMessage *iso18626.Iso18626MessageNS `json:"outgoingMessage,omitempty"`
Problem *Problem `json:"problem,omitempty"`
HttpFailure *httpclient.HttpError `json:"httpFailure,omitempty"`
EventError *EventError `json:"eventError,omitempty"`
Note string `json:"note,omitempty"`
Action *pr_db.PatronRequestAction `json:"action,omitempty"`
ActionResult *ActionResult `json:"actionResult,omitempty"`
IncomingMessage *iso18626.ISO18626Message `json:"incomingMessage,omitempty"`
OutgoingMessage *iso18626.ISO18626Message `json:"outgoingMessage,omitempty"`
Problem *Problem `json:"problem,omitempty"`
HttpFailure *httpclient.HttpError `json:"httpFailure,omitempty"`
EventError *EventError `json:"eventError,omitempty"`
Note string `json:"note,omitempty"`
Action *pr_db.PatronRequestAction `json:"action,omitempty"`
ActionResult *ActionResult `json:"actionResult,omitempty"`
}

type ActionResult struct {
Expand Down
Loading
Loading