From e65c1df09fc16a27bb387e39f39f251a07430860 Mon Sep 17 00:00:00 2001 From: Jakub Skoczen Date: Thu, 9 Apr 2026 15:13:35 +0200 Subject: [PATCH 1/3] Drop PrefixAttr and NS-aware wrappers --- broker/api/sse_broker.go | 4 +- broker/client/client.go | 48 ++++----- broker/client/client_test.go | 24 ++--- broker/events/eventmodels.go | 16 +-- broker/handler/iso18626-handler.go | 62 ++++++------ broker/handler/iso18626-handler_test.go | 8 +- broker/patron_request/service/action.go | 10 +- broker/patron_request/service/action_test.go | 12 +-- .../patron_request/service/message-handler.go | 58 +++++------ .../service/message-handler_test.go | 30 +++--- broker/service/workflow.go | 2 +- broker/service/workflow_test.go | 10 +- broker/shim/shim.go | 22 ++--- broker/shim/shim_test.go | 62 ++++++------ broker/test/api/sse_broker_test.go | 2 +- broker/test/client/client_test.go | 18 ++-- broker/test/handler/iso18626-handler_test.go | 6 +- broker/test/service/e2e_test.go | 10 +- broker/test/service/supplierlocator_test.go | 4 +- illmock/app/app.go | 29 +++--- illmock/app/app_test.go | 22 ++--- illmock/app/requester.go | 18 ++-- illmock/app/supplier.go | 8 +- illmock/flows/flows.go | 6 +- illmock/flows/flows_test.go | 14 +-- illmock/reqform/reqform_test.go | 2 +- iso18626/Makefile | 8 +- iso18626/models_ns.go | 37 +------ iso18626/models_ns_test.go | 99 +++++++------------ ncip/ncip_gen_test.go | 12 ++- ncip/testdata/ncip_sample.xml | 4 +- 31 files changed, 306 insertions(+), 361 deletions(-) diff --git a/broker/api/sse_broker.go b/broker/api/sse_broker.go index 76f621f5..7b084f10 100644 --- a/broker/api/sse_broker.go +++ b/broker/api/sse_broker.go @@ -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) { diff --git a/broker/client/client.go b/broker/client/client.go index eacc4ca3..a6874c2a 100644 --- a/broker/client/client.go +++ b/broker/client/client.go @@ -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 + ":" + @@ -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{} } @@ -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{} @@ -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 { @@ -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) @@ -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 { @@ -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") } @@ -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()) @@ -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 { @@ -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 @@ -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 @@ -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) @@ -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, @@ -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) @@ -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 diff --git a/broker/client/client_test.go b/broker/client/client_test.go index 4cbf47b4..43c3d40d 100644 --- a/broker/client/client_test.go +++ b/broker/client/client_test.go @@ -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) @@ -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, @@ -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{ @@ -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", @@ -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", @@ -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{ @@ -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"}}, @@ -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") @@ -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{ @@ -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", } @@ -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{} @@ -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", diff --git a/broker/events/eventmodels.go b/broker/events/eventmodels.go index b1f9155b..7fc86b98 100644 --- a/broker/events/eventmodels.go +++ b/broker/events/eventmodels.go @@ -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 { diff --git a/broker/handler/iso18626-handler.go b/broker/handler/iso18626-handler.go index 8cf0d9fd..64279e54 100644 --- a/broker/handler/iso18626-handler.go +++ b/broker/handler/iso18626-handler.go @@ -67,9 +67,9 @@ var ErrInvalidReason = errors.New(string(InvalidReason)) var waitingReqs = map[string]RequestWait{} type Iso18626HandlerInterface interface { - HandleRequest(ctx common.ExtendedContext, illMessage *iso18626.Iso18626MessageNS, w http.ResponseWriter) - HandleRequestingAgencyMessage(ctx common.ExtendedContext, illMessage *iso18626.Iso18626MessageNS, w http.ResponseWriter) - HandleSupplyingAgencyMessage(ctx common.ExtendedContext, illMessage *iso18626.Iso18626MessageNS, w http.ResponseWriter) + HandleRequest(ctx common.ExtendedContext, illMessage *iso18626.ISO18626Message, w http.ResponseWriter) + HandleRequestingAgencyMessage(ctx common.ExtendedContext, illMessage *iso18626.ISO18626Message, w http.ResponseWriter) + HandleSupplyingAgencyMessage(ctx common.ExtendedContext, illMessage *iso18626.ISO18626Message, w http.ResponseWriter) } type Iso18626Handler struct { @@ -115,7 +115,7 @@ func Iso18626PostHandler(repo ill_db.IllRepo, eventBus events.EventBus, dirAdapt http.Error(w, "failure reading request", http.StatusBadRequest) return } - illMessage := iso18626.NewIso18626MessageNS() + illMessage := iso18626.NewISO18626Message() err = xml.Unmarshal(byteReq, illMessage) if err != nil { ctx.Logger().Error("failure parsing request", "error", err, "body", string(byteReq)) @@ -220,11 +220,11 @@ func handleRetryRequest(ctx common.ExtendedContext, request *iso18626.Request, r return id, err } -func (h *Iso18626Handler) HandleRequest(ctx common.ExtendedContext, illMessage *iso18626.Iso18626MessageNS, w http.ResponseWriter) { +func (h *Iso18626Handler) HandleRequest(ctx common.ExtendedContext, illMessage *iso18626.ISO18626Message, w http.ResponseWriter) { handleRequest(ctx, illMessage, w, h.illRepo, h.eventBus, h.dirAdapter) } -func handleRequest(ctx common.ExtendedContext, illMessage *iso18626.Iso18626MessageNS, w http.ResponseWriter, repo ill_db.IllRepo, eventBus events.EventBus, dirAdapter adapter.DirectoryLookupAdapter) { +func handleRequest(ctx common.ExtendedContext, illMessage *iso18626.ISO18626Message, w http.ResponseWriter, repo ill_db.IllRepo, eventBus events.EventBus, dirAdapter adapter.DirectoryLookupAdapter) { request := illMessage.Request if request.Header.RequestingAgencyRequestId == "" { handleRequestError(ctx, w, request, iso18626.TypeErrorTypeUnrecognisedDataValue, ReqIdIsEmpty) @@ -287,7 +287,7 @@ func handleRequest(ctx common.ExtendedContext, illMessage *iso18626.Iso18626Mess writeResponse(ctx, resmsg, w) } -func writeResponse(ctx common.ExtendedContext, resmsg *iso18626.Iso18626MessageNS, w http.ResponseWriter) { +func writeResponse(ctx common.ExtendedContext, resmsg *iso18626.ISO18626Message, w http.ResponseWriter) { output, err := xml.MarshalIndent(resmsg, " ", " ") if err != nil { ctx.Logger().Error("failed to produce response", "error", err, "body", string(output)) @@ -319,8 +319,8 @@ func createPgText(value string) pgtype.Text { return textValue } -func createRequestResponse(request *iso18626.Request, messageStatus iso18626.TypeMessageStatus, errorType *iso18626.TypeErrorType, errorValue ErrorValue) *iso18626.Iso18626MessageNS { - var resmsg = iso18626.NewIso18626MessageNS() +func createRequestResponse(request *iso18626.Request, messageStatus iso18626.TypeMessageStatus, errorType *iso18626.TypeErrorType, errorValue ErrorValue) *iso18626.ISO18626Message { + var resmsg = iso18626.NewISO18626Message() header := createConfirmationHeader(&request.Header, messageStatus) errorData := createErrorData(errorType, errorValue) resmsg.RequestConfirmation = &iso18626.RequestConfirmation{ @@ -360,11 +360,11 @@ func createConfirmationHeader(inHeader *iso18626.Header, messageStatus iso18626. return header } -func (h *Iso18626Handler) HandleRequestingAgencyMessage(ctx common.ExtendedContext, illMessage *iso18626.Iso18626MessageNS, w http.ResponseWriter) { +func (h *Iso18626Handler) HandleRequestingAgencyMessage(ctx common.ExtendedContext, illMessage *iso18626.ISO18626Message, w http.ResponseWriter) { handleRequestingAgencyMessage(ctx, illMessage, w, h.illRepo, h.eventBus) } -func handleRequestingAgencyMessage(ctx common.ExtendedContext, illMessage *iso18626.Iso18626MessageNS, w http.ResponseWriter, repo ill_db.IllRepo, eventBus events.EventBus) { +func handleRequestingAgencyMessage(ctx common.ExtendedContext, illMessage *iso18626.ISO18626Message, w http.ResponseWriter, repo ill_db.IllRepo, eventBus events.EventBus) { var requestingRequestId = illMessage.RequestingAgencyMessage.Header.RequestingAgencyRequestId if requestingRequestId == "" { handleRequestingAgencyError(ctx, w, illMessage, iso18626.TypeErrorTypeUnrecognisedDataValue, ReqIdIsEmpty) @@ -456,7 +456,7 @@ func handleRequestingAgencyMessage(ctx common.ExtendedContext, illMessage *iso18 wg.Wait() } -func applyRequesterShim(ctx common.ExtendedContext, repo ill_db.IllRepo, reqId string, illMessage *iso18626.Iso18626MessageNS, eventData *events.EventData, supplier *ill_db.LocatedSupplier) error { +func applyRequesterShim(ctx common.ExtendedContext, repo ill_db.IllRepo, reqId string, illMessage *iso18626.ISO18626Message, eventData *events.EventData, supplier *ill_db.LocatedSupplier) error { requester, err := repo.GetPeerById(ctx, reqId) if err != nil { return err @@ -486,8 +486,8 @@ func validateAction(eventData events.EventData) (iso18626.TypeAction, error) { return valid, nil } -func createRequestingAgencyResponse(illMessage *iso18626.Iso18626MessageNS, messageStatus iso18626.TypeMessageStatus, errorType *iso18626.TypeErrorType, errorValue ErrorValue) *iso18626.Iso18626MessageNS { - var resmsg = iso18626.NewIso18626MessageNS() +func createRequestingAgencyResponse(illMessage *iso18626.ISO18626Message, messageStatus iso18626.TypeMessageStatus, errorType *iso18626.TypeErrorType, errorValue ErrorValue) *iso18626.ISO18626Message { + var resmsg = iso18626.NewISO18626Message() header := createConfirmationHeader(&illMessage.RequestingAgencyMessage.Header, messageStatus) errorData := createErrorData(errorType, errorValue) resmsg.RequestingAgencyMessageConfirmation = &iso18626.RequestingAgencyMessageConfirmation{ @@ -498,7 +498,7 @@ func createRequestingAgencyResponse(illMessage *iso18626.Iso18626MessageNS, mess return resmsg } -func handleRequestingAgencyError(ctx common.ExtendedContext, w http.ResponseWriter, illMessage *iso18626.Iso18626MessageNS, errorType iso18626.TypeErrorType, errorValue ErrorValue) { +func handleRequestingAgencyError(ctx common.ExtendedContext, w http.ResponseWriter, illMessage *iso18626.ISO18626Message, errorType iso18626.TypeErrorType, errorValue ErrorValue) { ctx.Logger().Warn("requester message confirmation error", "errorType", errorType, "errorValue", errorValue, "requesterSymbol", illMessage.RequestingAgencyMessage.Header.RequestingAgencyId.AgencyIdValue, "supplierSymbol", illMessage.RequestingAgencyMessage.Header.SupplyingAgencyId.AgencyIdValue, @@ -507,7 +507,7 @@ func handleRequestingAgencyError(ctx common.ExtendedContext, w http.ResponseWrit writeResponse(ctx, resmsg, w) } -func handleRequestingAgencyErrorWithNotice(ctx common.ExtendedContext, w http.ResponseWriter, illMessage *iso18626.Iso18626MessageNS, +func handleRequestingAgencyErrorWithNotice(ctx common.ExtendedContext, w http.ResponseWriter, illMessage *iso18626.ISO18626Message, errorType iso18626.TypeErrorType, errorValue ErrorValue, eventBus events.EventBus, illTransId string) { ctx.Logger().Warn("requester message confirmation error", "errorType", errorType, "errorValue", errorValue, "transactionId", illTransId, @@ -532,10 +532,10 @@ func handleRequestingAgencyErrorWithNotice(ctx common.ExtendedContext, w http.Re } } -func (h *Iso18626Handler) HandleSupplyingAgencyMessage(ctx common.ExtendedContext, illMessage *iso18626.Iso18626MessageNS, w http.ResponseWriter) { +func (h *Iso18626Handler) HandleSupplyingAgencyMessage(ctx common.ExtendedContext, illMessage *iso18626.ISO18626Message, w http.ResponseWriter) { handleSupplyingAgencyMessage(ctx, illMessage, w, h.illRepo, h.eventBus) } -func handleSupplyingAgencyMessage(ctx common.ExtendedContext, illMessage *iso18626.Iso18626MessageNS, w http.ResponseWriter, repo ill_db.IllRepo, eventBus events.EventBus) { +func handleSupplyingAgencyMessage(ctx common.ExtendedContext, illMessage *iso18626.ISO18626Message, w http.ResponseWriter, repo ill_db.IllRepo, eventBus events.EventBus) { var requestingRequestId = illMessage.SupplyingAgencyMessage.Header.RequestingAgencyRequestId if requestingRequestId == "" { handleSupplyingAgencyError(ctx, w, illMessage, iso18626.TypeErrorTypeUnrecognisedDataValue, ReqIdIsEmpty) @@ -657,7 +657,7 @@ func handleSupplyingAgencyMessage(ctx common.ExtendedContext, illMessage *iso186 wg.Wait() } -func validateStatusAndReasonForMessage(ctx common.ExtendedContext, illMessage *iso18626.Iso18626MessageNS, w http.ResponseWriter, eventData events.EventData, eventBus events.EventBus, illTrans ill_db.IllTransaction) (iso18626.TypeStatus, iso18626.TypeReasonForMessage, error) { +func validateStatusAndReasonForMessage(ctx common.ExtendedContext, illMessage *iso18626.ISO18626Message, w http.ResponseWriter, eventData events.EventData, eventBus events.EventBus, illTrans ill_db.IllTransaction) (iso18626.TypeStatus, iso18626.TypeReasonForMessage, error) { status := illMessage.SupplyingAgencyMessage.StatusInfo.Status // suppliers like Alma/Rapido, may send an empty status to indicate no status change if len(status) > 0 { @@ -742,8 +742,8 @@ func updatePeerBorrowCount(ctx common.ExtendedContext, repo ill_db.IllRepo, illT } } -func createSupplyingAgencyResponse(illMessage *iso18626.Iso18626MessageNS, messageStatus iso18626.TypeMessageStatus, errorType *iso18626.TypeErrorType, errorValue ErrorValue) *iso18626.Iso18626MessageNS { - var resmsg = iso18626.NewIso18626MessageNS() +func createSupplyingAgencyResponse(illMessage *iso18626.ISO18626Message, messageStatus iso18626.TypeMessageStatus, errorType *iso18626.TypeErrorType, errorValue ErrorValue) *iso18626.ISO18626Message { + var resmsg = iso18626.NewISO18626Message() header := createConfirmationHeader(&illMessage.SupplyingAgencyMessage.Header, messageStatus) errorData := createErrorData(errorType, errorValue) resmsg.SupplyingAgencyMessageConfirmation = &iso18626.SupplyingAgencyMessageConfirmation{ @@ -753,7 +753,7 @@ func createSupplyingAgencyResponse(illMessage *iso18626.Iso18626MessageNS, messa return resmsg } -func handleSupplyingAgencyError(ctx common.ExtendedContext, w http.ResponseWriter, illMessage *iso18626.Iso18626MessageNS, errorType iso18626.TypeErrorType, errorValue ErrorValue) { +func handleSupplyingAgencyError(ctx common.ExtendedContext, w http.ResponseWriter, illMessage *iso18626.ISO18626Message, errorType iso18626.TypeErrorType, errorValue ErrorValue) { ctx.Logger().Warn("supplier message confirmation error", "errorType", errorType, "errorValue", errorValue, "requesterSymbol", illMessage.SupplyingAgencyMessage.Header.RequestingAgencyId.AgencyIdValue, "supplierSymbol", illMessage.SupplyingAgencyMessage.Header.SupplyingAgencyId.AgencyIdValue, @@ -762,7 +762,7 @@ func handleSupplyingAgencyError(ctx common.ExtendedContext, w http.ResponseWrite writeResponse(ctx, resmsg, w) } -func handleSupplyingAgencyErrorWithNotice(ctx common.ExtendedContext, w http.ResponseWriter, illMessage *iso18626.Iso18626MessageNS, +func handleSupplyingAgencyErrorWithNotice(ctx common.ExtendedContext, w http.ResponseWriter, illMessage *iso18626.ISO18626Message, errorType iso18626.TypeErrorType, errorValue ErrorValue, eventBus events.EventBus, illTransId string) { ctx.Logger().Warn("supplier message confirmation error", "errorType", errorType, "errorValue", errorValue, "transactionId", illTransId, @@ -861,8 +861,8 @@ func (h *Iso18626Handler) ConfirmSupplierMsg(ctx common.ExtendedContext, event e }) } -func suppMsgOkConfirmation() *iso18626.Iso18626MessageNS { - var message = iso18626.NewIso18626MessageNS() +func suppMsgOkConfirmation() *iso18626.ISO18626Message { + var message = iso18626.NewISO18626Message() message.SupplyingAgencyMessageConfirmation = &iso18626.SupplyingAgencyMessageConfirmation{ ConfirmationHeader: iso18626.ConfirmationHeader{ MessageStatus: iso18626.TypeMessageStatusOK, @@ -884,7 +884,7 @@ func handleConfirmSuppMsgMissingAncestor(ctx common.ExtendedContext, event event } func (h *Iso18626Handler) handleConfirmSupplierMsgTask(ctx common.ExtendedContext, event events.Event, - waitRequestId string, supplierIllMsg *iso18626.Iso18626MessageNS, supplierResult events.EventResult) (events.EventStatus, *events.EventResult) { + waitRequestId string, supplierIllMsg *iso18626.ISO18626Message, supplierResult events.EventResult) (events.EventStatus, *events.EventResult) { status := events.EventStatusSuccess resData := events.EventResult{} cResp, err := h.confirmRequesterResponse(ctx, event.IllTransactionID, waitRequestId, supplierIllMsg, supplierResult) @@ -901,7 +901,7 @@ func (h *Iso18626Handler) handleConfirmSupplierMsgTask(ctx common.ExtendedContex } func (h *Iso18626Handler) handleConfirmRequesterMsgTask(ctx common.ExtendedContext, event events.Event, - waitRequestId string, requesterIllMsg *iso18626.Iso18626MessageNS, supplierResult events.EventResult) (events.EventStatus, *events.EventResult) { + waitRequestId string, requesterIllMsg *iso18626.ISO18626Message, supplierResult events.EventResult) (events.EventStatus, *events.EventResult) { status := events.EventStatusSuccess resData := events.EventResult{} cResp, err := h.confirmSupplierResponse(ctx, event.IllTransactionID, waitRequestId, requesterIllMsg, supplierResult) @@ -917,8 +917,8 @@ func (h *Iso18626Handler) handleConfirmRequesterMsgTask(ctx common.ExtendedConte return status, &resData } -func (c *Iso18626Handler) confirmSupplierResponse(ctx common.ExtendedContext, illTransId string, waitRequestId string, requesterIllMsg *iso18626.Iso18626MessageNS, - supplierResult events.EventResult) (*iso18626.Iso18626MessageNS, error) { +func (c *Iso18626Handler) confirmSupplierResponse(ctx common.ExtendedContext, illTransId string, waitRequestId string, requesterIllMsg *iso18626.ISO18626Message, + supplierResult events.EventResult) (*iso18626.ISO18626Message, error) { wait, ok := waitingReqs[waitRequestId] if !ok { return nil, fmt.Errorf("waiting request '%s' not found", waitRequestId) @@ -981,8 +981,8 @@ func (c *Iso18626Handler) confirmSupplierResponse(ctx common.ExtendedContext, il return resmsg, nil } -func (c *Iso18626Handler) confirmRequesterResponse(ctx common.ExtendedContext, illTransId string, waitRequestId string, supplierIllMsg *iso18626.Iso18626MessageNS, - requesterResult events.EventResult) (*iso18626.Iso18626MessageNS, error) { +func (c *Iso18626Handler) confirmRequesterResponse(ctx common.ExtendedContext, illTransId string, waitRequestId string, supplierIllMsg *iso18626.ISO18626Message, + requesterResult events.EventResult) (*iso18626.ISO18626Message, error) { wait, ok := waitingReqs[waitRequestId] if !ok { return nil, fmt.Errorf("waiting request '%s' not found", waitRequestId) diff --git a/broker/handler/iso18626-handler_test.go b/broker/handler/iso18626-handler_test.go index 01ef5694..dae871f9 100644 --- a/broker/handler/iso18626-handler_test.go +++ b/broker/handler/iso18626-handler_test.go @@ -38,7 +38,7 @@ func TestApplyRequesterShimError(t *testing.T) { appCtx := common.CreateExtCtxWithArgs(context.Background(), nil) mockRepo := new(mocks.MockIllRepositoryError) eventData := events.EventData{} - err := applyRequesterShim(appCtx, mockRepo, "1", iso18626.NewIso18626MessageNS(), &eventData, nil) + err := applyRequesterShim(appCtx, mockRepo, "1", iso18626.NewISO18626Message(), &eventData, nil) assert.Equal(t, "DB error", err.Error()) } @@ -46,7 +46,7 @@ func TestApplyRequesterShim(t *testing.T) { appCtx := common.CreateExtCtxWithArgs(context.Background(), nil) mockRepo := new(mocks.MockIllRepositorySuccess) eventData := events.EventData{} - err := applyRequesterShim(appCtx, mockRepo, "1", iso18626.NewIso18626MessageNS(), &eventData, nil) + err := applyRequesterShim(appCtx, mockRepo, "1", iso18626.NewISO18626Message(), &eventData, nil) assert.NoError(t, err, "should not have DB error") assert.NotNil(t, eventData.IncomingMessage) assert.NotNil(t, eventData.CustomData[ORIGINAL_INCOMING_MESSAGE]) @@ -56,7 +56,7 @@ func TestApplyRequesterShimAlma(t *testing.T) { appCtx := common.CreateExtCtxWithArgs(context.Background(), nil) mockRepo := new(MockIllRepositorySuccessAlma) eventData := events.EventData{} - message := iso18626.NewIso18626MessageNS() + message := iso18626.NewISO18626Message() message.RequestingAgencyMessage = &iso18626.RequestingAgencyMessage{ Header: iso18626.Header{ SupplyingAgencyId: iso18626.TypeAgencyId{ @@ -74,7 +74,7 @@ func TestApplyRequesterShimAlma(t *testing.T) { assert.NotNil(t, eventData.IncomingMessage) assert.Equal(t, "SUP1", eventData.IncomingMessage.RequestingAgencyMessage.Header.SupplyingAgencyId.AgencyIdValue) assert.NotNil(t, eventData.CustomData[ORIGINAL_INCOMING_MESSAGE]) - assert.Equal(t, "BROKER", eventData.CustomData[ORIGINAL_INCOMING_MESSAGE].(*iso18626.Iso18626MessageNS).RequestingAgencyMessage.Header.SupplyingAgencyId.AgencyIdValue) + assert.Equal(t, "BROKER", eventData.CustomData[ORIGINAL_INCOMING_MESSAGE].(*iso18626.ISO18626Message).RequestingAgencyMessage.Header.SupplyingAgencyId.AgencyIdValue) } type MockIllRepositorySuccessAlma struct { diff --git a/broker/patron_request/service/action.go b/broker/patron_request/service/action.go index 3610ded2..b372a76f 100644 --- a/broker/patron_request/service/action.go +++ b/broker/patron_request/service/action.go @@ -376,7 +376,7 @@ func (a *PatronRequestActionService) sendBorrowingRequest(ctx common.ExtendedCon } illRequest.PatronInfo.PatronId = pr.Patron.String - var illMessage = iso18626.NewIso18626MessageNS() + var illMessage = iso18626.NewISO18626Message() illMessage.Request = &illRequest w := NewResponseCaptureWriter() a.iso18626Handler.HandleRequest(ctx, illMessage, w) @@ -531,7 +531,7 @@ func (a *PatronRequestActionService) sendRequestingAgencyMessage(ctx common.Exte status, eventResult := a.logErrorAndReturnResult(ctx, "invalid supplier symbol", nil) return status, eventResult, nil } - var illMessage = iso18626.NewIso18626MessageNS() + var illMessage = iso18626.NewISO18626Message() illMessage.RequestingAgencyMessage = &iso18626.RequestingAgencyMessage{ Header: iso18626.Header{ RequestingAgencyId: iso18626.TypeAgencyId{ @@ -835,7 +835,7 @@ func (a *PatronRequestActionService) sendSupplyingAgencyMessage(ctx common.Exten // pr.SupplierSymbol is validated earlier in handleLenderAction requesterSymbol := strings.SplitN(pr.RequesterSymbol.String, ":", 2) supplierSymbol := strings.SplitN(pr.SupplierSymbol.String, ":", 2) - var illMessage = iso18626.NewIso18626MessageNS() + var illMessage = iso18626.NewISO18626Message() illMessage.SupplyingAgencyMessage = &iso18626.SupplyingAgencyMessage{ Header: iso18626.Header{ RequestingAgencyId: iso18626.TypeAgencyId{ @@ -908,7 +908,7 @@ func (a *PatronRequestActionService) markActionChainFailure(ctx common.ExtendedC } type ResponseCaptureWriter struct { - IllMessage *iso18626.Iso18626MessageNS + IllMessage *iso18626.ISO18626Message StatusCode int } @@ -918,7 +918,7 @@ func NewResponseCaptureWriter() *ResponseCaptureWriter { } } func (rcw *ResponseCaptureWriter) Write(b []byte) (int, error) { - rcw.IllMessage = iso18626.NewIso18626MessageNS() + rcw.IllMessage = iso18626.NewISO18626Message() err := xml.Unmarshal(b, rcw.IllMessage) return 1, err } diff --git a/broker/patron_request/service/action_test.go b/broker/patron_request/service/action_test.go index f992a233..2f4aa8ec 100644 --- a/broker/patron_request/service/action_test.go +++ b/broker/patron_request/service/action_test.go @@ -1578,12 +1578,12 @@ type MockIso18626Handler struct { lastSupplyingAgencyMessage *iso18626.SupplyingAgencyMessage } -func (h *MockIso18626Handler) HandleRequest(ctx common.ExtendedContext, illMessage *iso18626.Iso18626MessageNS, w http.ResponseWriter) { +func (h *MockIso18626Handler) HandleRequest(ctx common.ExtendedContext, illMessage *iso18626.ISO18626Message, w http.ResponseWriter) { status := iso18626.TypeMessageStatusOK if illMessage.Request.Header.RequestingAgencyRequestId == "error" { status = iso18626.TypeMessageStatusERROR } - var resmsg = iso18626.NewIso18626MessageNS() + var resmsg = iso18626.NewISO18626Message() resmsg.RequestConfirmation = &iso18626.RequestConfirmation{ ConfirmationHeader: iso18626.ConfirmationHeader{ MessageStatus: status, @@ -1599,13 +1599,13 @@ func (h *MockIso18626Handler) HandleRequest(ctx common.ExtendedContext, illMessa w.Write(output) } -func (h *MockIso18626Handler) HandleRequestingAgencyMessage(ctx common.ExtendedContext, illMessage *iso18626.Iso18626MessageNS, w http.ResponseWriter) { +func (h *MockIso18626Handler) HandleRequestingAgencyMessage(ctx common.ExtendedContext, illMessage *iso18626.ISO18626Message, w http.ResponseWriter) { h.lastRequestingAgencyMessage = illMessage.RequestingAgencyMessage status := iso18626.TypeMessageStatusOK if illMessage.RequestingAgencyMessage.Header.RequestingAgencyRequestId == "error" { status = iso18626.TypeMessageStatusERROR } - var resmsg = iso18626.NewIso18626MessageNS() + var resmsg = iso18626.NewISO18626Message() resmsg.RequestingAgencyMessageConfirmation = &iso18626.RequestingAgencyMessageConfirmation{ ConfirmationHeader: iso18626.ConfirmationHeader{ MessageStatus: status, @@ -1620,13 +1620,13 @@ func (h *MockIso18626Handler) HandleRequestingAgencyMessage(ctx common.ExtendedC w.WriteHeader(http.StatusOK) w.Write(output) } -func (h *MockIso18626Handler) HandleSupplyingAgencyMessage(ctx common.ExtendedContext, illMessage *iso18626.Iso18626MessageNS, w http.ResponseWriter) { +func (h *MockIso18626Handler) HandleSupplyingAgencyMessage(ctx common.ExtendedContext, illMessage *iso18626.ISO18626Message, w http.ResponseWriter) { h.lastSupplyingAgencyMessage = illMessage.SupplyingAgencyMessage status := iso18626.TypeMessageStatusOK if illMessage.SupplyingAgencyMessage.Header.RequestingAgencyRequestId == "error" { status = iso18626.TypeMessageStatusERROR } - var resmsg = iso18626.NewIso18626MessageNS() + var resmsg = iso18626.NewISO18626Message() resmsg.SupplyingAgencyMessageConfirmation = &iso18626.SupplyingAgencyMessageConfirmation{ ConfirmationHeader: iso18626.ConfirmationHeader{ MessageStatus: status, diff --git a/broker/patron_request/service/message-handler.go b/broker/patron_request/service/message-handler.go index 58690266..20358e49 100644 --- a/broker/patron_request/service/message-handler.go +++ b/broker/patron_request/service/message-handler.go @@ -79,7 +79,7 @@ func (m *PatronRequestMessageHandler) applyEventTransition(pr pr_db.PatronReques return pr, false, true, nil } -func (m *PatronRequestMessageHandler) HandleMessage(ctx common.ExtendedContext, msg *iso18626.Iso18626MessageNS) (*iso18626.Iso18626MessageNS, error) { +func (m *PatronRequestMessageHandler) HandleMessage(ctx common.ExtendedContext, msg *iso18626.ISO18626Message) (*iso18626.ISO18626Message, error) { ctx = ctx.WithArgs(ctx.LoggerArgs().WithComponent(COMP_MESSAGE)) if msg == nil { return nil, errors.New("cannot process nil message") @@ -100,9 +100,9 @@ func (m *PatronRequestMessageHandler) getPatronRequestForRequestingAgencyMessage func (m *PatronRequestMessageHandler) processPatronRequestMessageTask( ctx common.ExtendedContext, prID string, - incoming *iso18626.Iso18626MessageNS, - handler func(execCtx common.ExtendedContext, parentEventID *string) (events.EventStatus, *iso18626.Iso18626MessageNS, error), -) (events.EventStatus, *iso18626.Iso18626MessageNS, error) { + incoming *iso18626.ISO18626Message, + handler func(execCtx common.ExtendedContext, parentEventID *string) (events.EventStatus, *iso18626.ISO18626Message, error), +) (events.EventStatus, *iso18626.ISO18626Message, error) { data := events.EventData{CommonEventData: events.CommonEventData{IncomingMessage: incoming}} eventID, err := m.eventBus.CreateTask(prID, events.EventNamePatronRequestMessage, data, events.EventDomainPatronRequest, nil) if err != nil { @@ -111,7 +111,7 @@ func (m *PatronRequestMessageHandler) processPatronRequestMessageTask( var ( handlerStatus events.EventStatus - response *iso18626.Iso18626MessageNS + response *iso18626.ISO18626Message handleErr error ) @@ -146,13 +146,13 @@ func taskParentID(task *events.Event) *string { return &task.ID } -func (m *PatronRequestMessageHandler) handlePatronRequestMessage(ctx common.ExtendedContext, msg *iso18626.Iso18626MessageNS) (events.EventStatus, *iso18626.Iso18626MessageNS, pr_db.PatronRequest, error) { +func (m *PatronRequestMessageHandler) handlePatronRequestMessage(ctx common.ExtendedContext, msg *iso18626.ISO18626Message) (events.EventStatus, *iso18626.ISO18626Message, pr_db.PatronRequest, error) { if msg.SupplyingAgencyMessage != nil { pr, err := m.prRepo.GetPatronRequestByIdAndSide(ctx, msg.SupplyingAgencyMessage.Header.RequestingAgencyRequestId, SideBorrowing) if err != nil { return events.EventStatusError, nil, pr_db.PatronRequest{}, err } - status, response, err := m.processPatronRequestMessageTask(ctx, pr.ID, msg, func(execCtx common.ExtendedContext, parentEventID *string) (events.EventStatus, *iso18626.Iso18626MessageNS, error) { + status, response, err := m.processPatronRequestMessageTask(ctx, pr.ID, msg, func(execCtx common.ExtendedContext, parentEventID *string) (events.EventStatus, *iso18626.ISO18626Message, error) { return m.handleSupplyingAgencyMessageWithParent(execCtx, *msg.SupplyingAgencyMessage, pr, parentEventID) }) return status, response, pr, err @@ -161,7 +161,7 @@ func (m *PatronRequestMessageHandler) handlePatronRequestMessage(ctx common.Exte if err != nil { return events.EventStatusError, nil, pr_db.PatronRequest{}, err } - status, response, err := m.processPatronRequestMessageTask(ctx, pr.ID, msg, func(execCtx common.ExtendedContext, parentEventID *string) (events.EventStatus, *iso18626.Iso18626MessageNS, error) { + status, response, err := m.processPatronRequestMessageTask(ctx, pr.ID, msg, func(execCtx common.ExtendedContext, parentEventID *string) (events.EventStatus, *iso18626.ISO18626Message, error) { return m.handleRequestingAgencyMessageWithParent(execCtx, *msg.RequestingAgencyMessage, pr, parentEventID) }) return status, response, pr, err @@ -173,26 +173,26 @@ func (m *PatronRequestMessageHandler) handlePatronRequestMessage(ctx common.Exte } } -func (m *PatronRequestMessageHandler) handleSupplyingAgencyMessage(ctx common.ExtendedContext, sam iso18626.SupplyingAgencyMessage, pr pr_db.PatronRequest) (events.EventStatus, *iso18626.Iso18626MessageNS, error) { +func (m *PatronRequestMessageHandler) handleSupplyingAgencyMessage(ctx common.ExtendedContext, sam iso18626.SupplyingAgencyMessage, pr pr_db.PatronRequest) (events.EventStatus, *iso18626.ISO18626Message, error) { return m.handleSupplyingAgencyMessageWithParent(ctx, sam, pr, nil) } -func (m *PatronRequestMessageHandler) handleSupplyingAgencyMessageWithParent(ctx common.ExtendedContext, sam iso18626.SupplyingAgencyMessage, pr pr_db.PatronRequest, parentEventID *string) (events.EventStatus, *iso18626.Iso18626MessageNS, error) { - unsupportedReason := func() (events.EventStatus, *iso18626.Iso18626MessageNS, error) { +func (m *PatronRequestMessageHandler) handleSupplyingAgencyMessageWithParent(ctx common.ExtendedContext, sam iso18626.SupplyingAgencyMessage, pr pr_db.PatronRequest, parentEventID *string) (events.EventStatus, *iso18626.ISO18626Message, error) { + unsupportedReason := func() (events.EventStatus, *iso18626.ISO18626Message, error) { err := fmt.Errorf("unsupported reason for message: %s", sam.MessageInfo.ReasonForMessage) return createSAMResponse(sam, iso18626.TypeMessageStatusERROR, &iso18626.ErrorData{ ErrorType: iso18626.TypeErrorTypeUnsupportedReasonForMessageType, ErrorValue: err.Error(), }, err) } - statusChangeNotAllowed := func() (events.EventStatus, *iso18626.Iso18626MessageNS, error) { + statusChangeNotAllowed := func() (events.EventStatus, *iso18626.ISO18626Message, error) { err := fmt.Errorf("status change not allowed: %s", sam.StatusInfo.Status) return createSAMResponse(sam, iso18626.TypeMessageStatusERROR, &iso18626.ErrorData{ ErrorType: iso18626.TypeErrorTypeUnrecognisedDataValue, ErrorValue: err.Error(), }, err) } - contradictoryCancelResponse := func() (events.EventStatus, *iso18626.Iso18626MessageNS, error) { + contradictoryCancelResponse := func() (events.EventStatus, *iso18626.ISO18626Message, error) { err := fmt.Errorf("contradictory cancel response: status=%s answerYesNo=%v", sam.StatusInfo.Status, sam.MessageInfo.AnswerYesNo) return createSAMResponse(sam, iso18626.TypeMessageStatusERROR, &iso18626.ErrorData{ ErrorType: iso18626.TypeErrorTypeUnrecognisedDataValue, @@ -279,7 +279,7 @@ func (m *PatronRequestMessageHandler) handleSupplyingAgencyMessageWithParent(ctx return m.updatePatronRequestAndCreateSamResponse(ctx, updatedPr, sam, stateChanged, parentEventID) } -func (m *PatronRequestMessageHandler) updatePatronRequestAndCreateSamResponse(ctx common.ExtendedContext, pr pr_db.PatronRequest, sam iso18626.SupplyingAgencyMessage, stateChanged bool, parentEventID *string) (events.EventStatus, *iso18626.Iso18626MessageNS, error) { +func (m *PatronRequestMessageHandler) updatePatronRequestAndCreateSamResponse(ctx common.ExtendedContext, pr pr_db.PatronRequest, sam iso18626.SupplyingAgencyMessage, stateChanged bool, parentEventID *string) (events.EventStatus, *iso18626.ISO18626Message, error) { _, err := m.prRepo.UpdatePatronRequest(ctx, pr_db.UpdatePatronRequestParams(pr)) if err != nil { return createSAMResponse(sam, iso18626.TypeMessageStatusERROR, &iso18626.ErrorData{ @@ -303,12 +303,12 @@ func (m *PatronRequestMessageHandler) updatePatronRequestAndCreateSamResponse(ct return createSAMResponse(sam, iso18626.TypeMessageStatusOK, nil, nil) } -func createSAMResponse(sam iso18626.SupplyingAgencyMessage, messageStatus iso18626.TypeMessageStatus, errorData *iso18626.ErrorData, err error) (events.EventStatus, *iso18626.Iso18626MessageNS, error) { +func createSAMResponse(sam iso18626.SupplyingAgencyMessage, messageStatus iso18626.TypeMessageStatus, errorData *iso18626.ErrorData, err error) (events.EventStatus, *iso18626.ISO18626Message, error) { eventStatus := events.EventStatusSuccess if messageStatus != iso18626.TypeMessageStatusOK { eventStatus = events.EventStatusProblem } - var message = iso18626.NewIso18626MessageNS() + var message = iso18626.NewISO18626Message() message.SupplyingAgencyMessageConfirmation = &iso18626.SupplyingAgencyMessageConfirmation{ ConfirmationHeader: iso18626.ConfirmationHeader{ SupplyingAgencyId: &sam.Header.SupplyingAgencyId, @@ -324,12 +324,12 @@ func createSAMResponse(sam iso18626.SupplyingAgencyMessage, messageStatus iso186 return eventStatus, message, err } -func createRequestResponse(request iso18626.Request, messageStatus iso18626.TypeMessageStatus, errorData *iso18626.ErrorData, err error) (events.EventStatus, *iso18626.Iso18626MessageNS, error) { +func createRequestResponse(request iso18626.Request, messageStatus iso18626.TypeMessageStatus, errorData *iso18626.ErrorData, err error) (events.EventStatus, *iso18626.ISO18626Message, error) { eventStatus := events.EventStatusSuccess if messageStatus != iso18626.TypeMessageStatusOK { eventStatus = events.EventStatusProblem } - var message = iso18626.NewIso18626MessageNS() + var message = iso18626.NewISO18626Message() message.RequestConfirmation = &iso18626.RequestConfirmation{ ConfirmationHeader: iso18626.ConfirmationHeader{ SupplyingAgencyId: &request.Header.SupplyingAgencyId, @@ -344,7 +344,7 @@ func createRequestResponse(request iso18626.Request, messageStatus iso18626.Type return eventStatus, message, err } -func (m *PatronRequestMessageHandler) handleRequestMessage(ctx common.ExtendedContext, request iso18626.Request) (events.EventStatus, *iso18626.Iso18626MessageNS, pr_db.PatronRequest, error) { +func (m *PatronRequestMessageHandler) handleRequestMessage(ctx common.ExtendedContext, request iso18626.Request) (events.EventStatus, *iso18626.ISO18626Message, pr_db.PatronRequest, error) { raRequestId := request.Header.RequestingAgencyRequestId if raRequestId == "" { status, response, err := createRequestResponse(request, iso18626.TypeMessageStatusERROR, &iso18626.ErrorData{ @@ -365,10 +365,10 @@ func (m *PatronRequestMessageHandler) handleRequestMessage(ctx common.ExtendedCo return status, response, pr_db.PatronRequest{}, handleErr } } else { - var message = iso18626.NewIso18626MessageNS() + var message = iso18626.NewISO18626Message() message.Request = &request status, response, handleErr := m.processPatronRequestMessageTask(ctx, existingPr.ID, message, - func(_ common.ExtendedContext, _ *string) (events.EventStatus, *iso18626.Iso18626MessageNS, error) { + func(_ common.ExtendedContext, _ *string) (events.EventStatus, *iso18626.ISO18626Message, error) { return createRequestResponse(request, iso18626.TypeMessageStatusERROR, &iso18626.ErrorData{ ErrorType: iso18626.TypeErrorTypeBadlyFormedMessage, ErrorValue: "there is already request with this id " + raRequestId, @@ -401,10 +401,10 @@ func (m *PatronRequestMessageHandler) handleRequestMessage(ctx common.ExtendedCo if err != nil { ctx.Logger().Error("failed to save request notifications", "error", err) } - var message = iso18626.NewIso18626MessageNS() + var message = iso18626.NewISO18626Message() message.Request = &request status, response, handleErr := m.processPatronRequestMessageTask(ctx, pr.ID, message, - func(execCtx common.ExtendedContext, parentEventID *string) (events.EventStatus, *iso18626.Iso18626MessageNS, error) { + func(execCtx common.ExtendedContext, parentEventID *string) (events.EventStatus, *iso18626.ISO18626Message, error) { err = m.runAutoActionsOnStateEntry(execCtx, pr, parentEventID) if err != nil { return createRequestResponse(request, iso18626.TypeMessageStatusERROR, &iso18626.ErrorData{ @@ -436,12 +436,12 @@ func getDbTextPtr(value *string) pgtype.Text { return getDbText(*value) } -func (m *PatronRequestMessageHandler) handleRequestingAgencyMessage(ctx common.ExtendedContext, ram iso18626.RequestingAgencyMessage, pr pr_db.PatronRequest) (events.EventStatus, *iso18626.Iso18626MessageNS, error) { +func (m *PatronRequestMessageHandler) handleRequestingAgencyMessage(ctx common.ExtendedContext, ram iso18626.RequestingAgencyMessage, pr pr_db.PatronRequest) (events.EventStatus, *iso18626.ISO18626Message, error) { return m.handleRequestingAgencyMessageWithParent(ctx, ram, pr, nil) } -func (m *PatronRequestMessageHandler) handleRequestingAgencyMessageWithParent(ctx common.ExtendedContext, ram iso18626.RequestingAgencyMessage, pr pr_db.PatronRequest, parentEventID *string) (events.EventStatus, *iso18626.Iso18626MessageNS, error) { - unsupported := func() (events.EventStatus, *iso18626.Iso18626MessageNS, error) { +func (m *PatronRequestMessageHandler) handleRequestingAgencyMessageWithParent(ctx common.ExtendedContext, ram iso18626.RequestingAgencyMessage, pr pr_db.PatronRequest, parentEventID *string) (events.EventStatus, *iso18626.ISO18626Message, error) { + unsupported := func() (events.EventStatus, *iso18626.ISO18626Message, error) { err := errors.New("unsupported action: " + string(ram.Action)) return createRAMResponse(ram, iso18626.TypeMessageStatusERROR, &ram.Action, &iso18626.ErrorData{ ErrorType: iso18626.TypeErrorTypeUnsupportedActionType, @@ -492,12 +492,12 @@ func (m *PatronRequestMessageHandler) handleRequestingAgencyMessageWithParent(ct return m.updatePatronRequestAndCreateRamResponse(ctx, updatedPr, ram, &ram.Action, stateChanged, parentEventID) } -func createRAMResponse(ram iso18626.RequestingAgencyMessage, messageStatus iso18626.TypeMessageStatus, action *iso18626.TypeAction, errorData *iso18626.ErrorData, err error) (events.EventStatus, *iso18626.Iso18626MessageNS, error) { +func createRAMResponse(ram iso18626.RequestingAgencyMessage, messageStatus iso18626.TypeMessageStatus, action *iso18626.TypeAction, errorData *iso18626.ErrorData, err error) (events.EventStatus, *iso18626.ISO18626Message, error) { eventStatus := events.EventStatusSuccess if messageStatus != iso18626.TypeMessageStatusOK { eventStatus = events.EventStatusProblem } - var message = iso18626.NewIso18626MessageNS() + var message = iso18626.NewISO18626Message() message.RequestingAgencyMessageConfirmation = &iso18626.RequestingAgencyMessageConfirmation{ ConfirmationHeader: iso18626.ConfirmationHeader{ SupplyingAgencyId: &ram.Header.SupplyingAgencyId, @@ -513,7 +513,7 @@ func createRAMResponse(ram iso18626.RequestingAgencyMessage, messageStatus iso18 return eventStatus, message, err } -func (m *PatronRequestMessageHandler) updatePatronRequestAndCreateRamResponse(ctx common.ExtendedContext, pr pr_db.PatronRequest, ram iso18626.RequestingAgencyMessage, action *iso18626.TypeAction, stateChanged bool, parentEventID *string) (events.EventStatus, *iso18626.Iso18626MessageNS, error) { +func (m *PatronRequestMessageHandler) updatePatronRequestAndCreateRamResponse(ctx common.ExtendedContext, pr pr_db.PatronRequest, ram iso18626.RequestingAgencyMessage, action *iso18626.TypeAction, stateChanged bool, parentEventID *string) (events.EventStatus, *iso18626.ISO18626Message, error) { _, err := m.prRepo.UpdatePatronRequest(ctx, pr_db.UpdatePatronRequestParams(pr)) if err != nil { return createRAMResponse(ram, iso18626.TypeMessageStatusERROR, action, &iso18626.ErrorData{ diff --git a/broker/patron_request/service/message-handler_test.go b/broker/patron_request/service/message-handler_test.go index d1ff7a0d..ab39d6af 100644 --- a/broker/patron_request/service/message-handler_test.go +++ b/broker/patron_request/service/message-handler_test.go @@ -32,7 +32,7 @@ func TestHandleMessageFetchPRError(t *testing.T) { handler := CreatePatronRequestMessageHandler(mockPrRepo, *new(events.EventRepo), *new(ill_db.IllRepo), *new(events.EventBus)) - var message = iso18626.NewIso18626MessageNS() + var message = iso18626.NewISO18626Message() message.SupplyingAgencyMessage = &iso18626.SupplyingAgencyMessage{ Header: iso18626.Header{ RequestingAgencyRequestId: patronRequestId, @@ -51,7 +51,7 @@ func TestHandleMessageFetchEventError(t *testing.T) { handler := CreatePatronRequestMessageHandler(mockPrRepo, *new(events.EventRepo), *new(ill_db.IllRepo), mockEventBus) - var message = iso18626.NewIso18626MessageNS() + var message = iso18626.NewISO18626Message() message.SupplyingAgencyMessage = &iso18626.SupplyingAgencyMessage{ Header: iso18626.Header{ RequestingAgencyRequestId: patronRequestId, @@ -70,7 +70,7 @@ func TestHandleMessageRequestCreatesTaskForCreatedPatronRequest(t *testing.T) { handler := CreatePatronRequestMessageHandler(mockPrRepo, *new(events.EventRepo), *new(ill_db.IllRepo), mockEventBus) inTimestamp := utils.XSDDateTime{Time: time.Date(2026, 3, 26, 10, 0, 0, 0, time.UTC)} - var message = iso18626.NewIso18626MessageNS() + var message = iso18626.NewISO18626Message() message.Request = &iso18626.Request{ Header: iso18626.Header{ RequestingAgencyId: iso18626.TypeAgencyId{ @@ -107,7 +107,7 @@ func TestHandleMessageRequestCreatesTaskBeforeAutoActions(t *testing.T) { handler := CreatePatronRequestMessageHandler(mockPrRepo, *new(events.EventRepo), *new(ill_db.IllRepo), mockEventBus) handler.SetAutoActionRunner(mockAutoActionRunner) - var message = iso18626.NewIso18626MessageNS() + var message = iso18626.NewISO18626Message() message.Request = &iso18626.Request{ Header: iso18626.Header{ RequestingAgencyId: iso18626.TypeAgencyId{ @@ -148,7 +148,7 @@ func TestHandleMessageSupplyingAgencyCreatesTaskBeforeAutoActions(t *testing.T) handler.SetAutoActionRunner(mockAutoActionRunner) inTimestamp := utils.XSDDateTime{Time: time.Date(2026, 3, 26, 10, 1, 0, 0, time.UTC)} - var message = iso18626.NewIso18626MessageNS() + var message = iso18626.NewISO18626Message() message.SupplyingAgencyMessage = &iso18626.SupplyingAgencyMessage{ Header: iso18626.Header{ Timestamp: inTimestamp, @@ -189,7 +189,7 @@ func TestHandleMessageRequestingAgencyCreatesTaskBeforeAutoActions(t *testing.T) handler.SetAutoActionRunner(mockAutoActionRunner) inTimestamp := utils.XSDDateTime{Time: time.Date(2026, 3, 26, 10, 2, 0, 0, time.UTC)} - var message = iso18626.NewIso18626MessageNS() + var message = iso18626.NewISO18626Message() message.RequestingAgencyMessage = &iso18626.RequestingAgencyMessage{ Header: iso18626.Header{ Timestamp: inTimestamp, @@ -220,7 +220,7 @@ func TestHandleMessageSupplyingAgencyTaskResultIncludesOutgoingAndNoErrorOnSucce }, nil) handler := CreatePatronRequestMessageHandler(mockPrRepo, *new(events.EventRepo), *new(ill_db.IllRepo), mockEventBus) - var message = iso18626.NewIso18626MessageNS() + var message = iso18626.NewISO18626Message() message.SupplyingAgencyMessage = &iso18626.SupplyingAgencyMessage{ Header: iso18626.Header{ RequestingAgencyRequestId: patronRequestId, @@ -252,7 +252,7 @@ func TestHandleMessageRequestingAgencyTaskResultIncludesOutgoingAndErrorOnFailur }, nil) handler := CreatePatronRequestMessageHandler(mockPrRepo, *new(events.EventRepo), *new(ill_db.IllRepo), mockEventBus) - var message = iso18626.NewIso18626MessageNS() + var message = iso18626.NewISO18626Message() message.RequestingAgencyMessage = &iso18626.RequestingAgencyMessage{ Header: iso18626.Header{ SupplyingAgencyRequestId: "lender-pr-id-2", @@ -283,7 +283,7 @@ func TestHandleMessageDuplicateRequestCreatesTaskOnExistingPatronRequest(t *test mockPrRepo.On("GetLendingRequestBySupplierSymbolAndRequesterReqId", "ISIL:SUP1", "req-id-1").Return(existingPr, nil) handler := CreatePatronRequestMessageHandler(mockPrRepo, *new(events.EventRepo), *new(ill_db.IllRepo), mockEventBus) - var message = iso18626.NewIso18626MessageNS() + var message = iso18626.NewISO18626Message() message.Request = &iso18626.Request{ Header: iso18626.Header{ RequestingAgencyId: iso18626.TypeAgencyId{ @@ -327,7 +327,7 @@ func TestHandleMessageRequestTaskStatusUsesHandlerStatusWhenAutoActionFails(t *t handler := CreatePatronRequestMessageHandler(mockPrRepo, *new(events.EventRepo), *new(ill_db.IllRepo), mockEventBus) handler.SetAutoActionRunner(mockAutoActionRunner) - var message = iso18626.NewIso18626MessageNS() + var message = iso18626.NewISO18626Message() message.Request = &iso18626.Request{ Header: iso18626.Header{ RequestingAgencyId: iso18626.TypeAgencyId{AgencyIdType: iso18626.TypeSchemeValuePair{Text: "ISIL"}, AgencyIdValue: "REQ1"}, @@ -349,19 +349,19 @@ func TestHandlePatronRequestMessage(t *testing.T) { mockEventBus := new(MockEventBus) handler := CreatePatronRequestMessageHandler(mockPrRepo, *new(events.EventRepo), *new(ill_db.IllRepo), mockEventBus) - status, resp, _, err := handler.handlePatronRequestMessage(appCtx, iso18626.NewIso18626MessageNS()) + status, resp, _, err := handler.handlePatronRequestMessage(appCtx, iso18626.NewISO18626Message()) assert.Equal(t, events.EventStatusError, status) assert.Nil(t, resp) assert.Equal(t, "cannot process message without content", err.Error()) - var message = iso18626.NewIso18626MessageNS() + var message = iso18626.NewISO18626Message() message.Request = &iso18626.Request{} status, resp, _, err = handler.handlePatronRequestMessage(appCtx, message) assert.Equal(t, events.EventStatusProblem, status) assert.Equal(t, "missing RequestingAgencyRequestId", resp.RequestConfirmation.ErrorData.ErrorValue) assert.Nil(t, err) - message = iso18626.NewIso18626MessageNS() + message = iso18626.NewISO18626Message() message.RequestingAgencyMessage = &iso18626.RequestingAgencyMessage{ Header: iso18626.Header{ SupplyingAgencyRequestId: "sam-id-1", @@ -374,7 +374,7 @@ func TestHandlePatronRequestMessage(t *testing.T) { assert.Equal(t, "unsupported action: ", err.Error()) mockPrRepo.On("GetPatronRequestByIdAndSide", patronRequestId, SideBorrowing).Return(pr_db.PatronRequest{ID: patronRequestId, Side: SideBorrowing}, nil) - message = iso18626.NewIso18626MessageNS() + message = iso18626.NewISO18626Message() message.SupplyingAgencyMessage = &iso18626.SupplyingAgencyMessage{Header: iso18626.Header{RequestingAgencyRequestId: patronRequestId}} status, resp, _, err = handler.handlePatronRequestMessage(appCtx, message) assert.Equal(t, events.EventStatusProblem, status) @@ -389,7 +389,7 @@ func TestHandlePatronRequestMessageRequestingAgencyMessageFallbackLookup(t *test lendingPr := pr_db.PatronRequest{ID: "lend-id-1", State: LenderStateWillSupply, Side: SideLending} mockPrRepo.On("GetLendingRequestBySupplierSymbolAndRequesterReqId", "ISIL:SUP1", "req-id-1").Return(lendingPr, nil) - var message = iso18626.NewIso18626MessageNS() + var message = iso18626.NewISO18626Message() message.RequestingAgencyMessage = &iso18626.RequestingAgencyMessage{ Header: iso18626.Header{ SupplyingAgencyId: iso18626.TypeAgencyId{ diff --git a/broker/service/workflow.go b/broker/service/workflow.go index 8f1c6a42..99cfed26 100644 --- a/broker/service/workflow.go +++ b/broker/service/workflow.go @@ -238,7 +238,7 @@ func (w *WorkflowManager) skipAllSuppliersByStatus(ctx common.ExtendedContext, i } } -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 + ":" + diff --git a/broker/service/workflow_test.go b/broker/service/workflow_test.go index 550d5f85..2a2cee66 100644 --- a/broker/service/workflow_test.go +++ b/broker/service/workflow_test.go @@ -144,7 +144,7 @@ func TestRequesterMessageReceived_BrokerCancelSkipsNewSuppliers(t *testing.T) { })).Return() manager := CreateWorkflowManager(eventBus, mockIllRepo, WorkflowConfig{}) - var message = iso18626.NewIso18626MessageNS() + var message = iso18626.NewISO18626Message() message.RequestingAgencyMessage = &iso18626.RequestingAgencyMessage{ Action: iso18626.TypeActionCancel, Header: iso18626.Header{ @@ -175,7 +175,7 @@ func TestRequesterMessageReceived_SupplierCancelDoesNotSkipNewSuppliers(t *testi mockIllRepo.On("GetLocatedSuppliersByIllTransactionAndStatus", mock.Anything, mock.Anything).Return() manager := CreateWorkflowManager(eventBus, mockIllRepo, WorkflowConfig{}) - var message = iso18626.NewIso18626MessageNS() + var message = iso18626.NewISO18626Message() message.RequestingAgencyMessage = &iso18626.RequestingAgencyMessage{ Action: iso18626.TypeActionCancel, Header: iso18626.Header{ @@ -198,8 +198,8 @@ func TestRequesterMessageReceived_SupplierCancelDoesNotSkipNewSuppliers(t *testi mockIllRepo.AssertNumberOfCalls(t, "GetLocatedSuppliersByIllTransactionAndStatus", 0) assert.Equal(t, 1, eventBus.TasksCreated) } -func messageFromSam(sam *iso18626.SupplyingAgencyMessage) *iso18626.Iso18626MessageNS { - var message = iso18626.NewIso18626MessageNS() +func messageFromSam(sam *iso18626.SupplyingAgencyMessage) *iso18626.ISO18626Message { + var message = iso18626.NewISO18626Message() message.SupplyingAgencyMessage = sam return message } @@ -339,7 +339,7 @@ func (r *MockEventRepositoryCorrect) GetLatestRequestEventByAction(ctx common.Ex if illTransId == "2" { supId = "BROKER" } - var message = iso18626.NewIso18626MessageNS() + var message = iso18626.NewISO18626Message() message.RequestingAgencyMessage = &iso18626.RequestingAgencyMessage{ Header: iso18626.Header{ SupplyingAgencyId: iso18626.TypeAgencyId{ diff --git a/broker/shim/shim.go b/broker/shim/shim.go index 9baf9cae..130eacec 100644 --- a/broker/shim/shim.go +++ b/broker/shim/shim.go @@ -40,9 +40,9 @@ var edgeNonWord = regexp.MustCompile(`^\W+|\W+$`) var reshareItemRegex = regexp.MustCompile(`(.*),(.*),(.*)`) type Iso18626Shim interface { - ApplyToOutgoingRequest(message *iso18626.Iso18626MessageNS) ([]byte, error) - ApplyToIncomingResponse(bytes []byte, message *iso18626.Iso18626MessageNS) error - ApplyToIncomingRequest(message *iso18626.Iso18626MessageNS, requester *ill_db.Peer, supplier *ill_db.LocatedSupplier) *iso18626.Iso18626MessageNS + ApplyToOutgoingRequest(message *iso18626.ISO18626Message) ([]byte, error) + ApplyToIncomingResponse(bytes []byte, message *iso18626.ISO18626Message) error + ApplyToIncomingRequest(message *iso18626.ISO18626Message, requester *ill_db.Peer, supplier *ill_db.LocatedSupplier) *iso18626.ISO18626Message } // factory method @@ -62,15 +62,15 @@ func GetShim(vendor string) Iso18626Shim { type Iso18626DefaultShim struct { } -func (i *Iso18626DefaultShim) ApplyToOutgoingRequest(message *iso18626.Iso18626MessageNS) ([]byte, error) { +func (i *Iso18626DefaultShim) ApplyToOutgoingRequest(message *iso18626.ISO18626Message) ([]byte, error) { return xml.Marshal(message) } -func (i *Iso18626DefaultShim) ApplyToIncomingResponse(bytes []byte, message *iso18626.Iso18626MessageNS) error { +func (i *Iso18626DefaultShim) ApplyToIncomingResponse(bytes []byte, message *iso18626.ISO18626Message) error { if message == nil { return fmt.Errorf("message is nil") } - parsed := iso18626.NewIso18626MessageNS() + parsed := iso18626.NewISO18626Message() if err := xml.Unmarshal(bytes, parsed); err != nil { return err } @@ -78,7 +78,7 @@ func (i *Iso18626DefaultShim) ApplyToIncomingResponse(bytes []byte, message *iso return nil } -func (i *Iso18626DefaultShim) ApplyToIncomingRequest(message *iso18626.Iso18626MessageNS, requester *ill_db.Peer, supplier *ill_db.LocatedSupplier) *iso18626.Iso18626MessageNS { +func (i *Iso18626DefaultShim) ApplyToIncomingRequest(message *iso18626.ISO18626Message, requester *ill_db.Peer, supplier *ill_db.LocatedSupplier) *iso18626.ISO18626Message { return message } @@ -86,7 +86,7 @@ type Iso18626AlmaShim struct { Iso18626DefaultShim } -func (i *Iso18626AlmaShim) ApplyToIncomingRequest(message *iso18626.Iso18626MessageNS, requester *ill_db.Peer, supplier *ill_db.LocatedSupplier) *iso18626.Iso18626MessageNS { +func (i *Iso18626AlmaShim) ApplyToIncomingRequest(message *iso18626.ISO18626Message, requester *ill_db.Peer, supplier *ill_db.LocatedSupplier) *iso18626.ISO18626Message { if message == nil { return message } @@ -111,7 +111,7 @@ func (i *Iso18626AlmaShim) ApplyToIncomingRequest(message *iso18626.Iso18626Mess return ©Message } -func (i *Iso18626AlmaShim) ApplyToOutgoingRequest(message *iso18626.Iso18626MessageNS) ([]byte, error) { +func (i *Iso18626AlmaShim) ApplyToOutgoingRequest(message *iso18626.ISO18626Message) ([]byte, error) { if message != nil { if message.SupplyingAgencyMessage != nil { suppMsg := message.SupplyingAgencyMessage @@ -581,7 +581,7 @@ type Iso18626ReShareShim struct { Iso18626DefaultShim } -func (i *Iso18626ReShareShim) ApplyToOutgoingRequest(message *iso18626.Iso18626MessageNS) ([]byte, error) { +func (i *Iso18626ReShareShim) ApplyToOutgoingRequest(message *iso18626.ISO18626Message) ([]byte, error) { if message.SupplyingAgencyMessage != nil { i.transferDeliveryCostsToOfferedCosts(message.SupplyingAgencyMessage) i.setItemId(message.SupplyingAgencyMessage) @@ -609,7 +609,7 @@ func (i *Iso18626ReShareShim) transferDeliveryCostsToOfferedCosts(suppMsg *iso18 } } -func (i *Iso18626ReShareShim) ApplyToIncomingRequest(message *iso18626.Iso18626MessageNS, requester *ill_db.Peer, supplier *ill_db.LocatedSupplier) *iso18626.Iso18626MessageNS { +func (i *Iso18626ReShareShim) ApplyToIncomingRequest(message *iso18626.ISO18626Message, requester *ill_db.Peer, supplier *ill_db.LocatedSupplier) *iso18626.ISO18626Message { if message == nil { return message } diff --git a/broker/shim/shim_test.go b/broker/shim/shim_test.go index 9b7e21e1..19d7efe5 100644 --- a/broker/shim/shim_test.go +++ b/broker/shim/shim_test.go @@ -13,18 +13,18 @@ import ( "github.com/stretchr/testify/assert" ) -func newSAM(sam *iso18626.SupplyingAgencyMessage) *iso18626.Iso18626MessageNS { - var message = iso18626.NewIso18626MessageNS() +func newSAM(sam *iso18626.SupplyingAgencyMessage) *iso18626.ISO18626Message { + var message = iso18626.NewISO18626Message() message.SupplyingAgencyMessage = sam return message } -func newRAM(ram *iso18626.RequestingAgencyMessage) *iso18626.Iso18626MessageNS { - var message = iso18626.NewIso18626MessageNS() +func newRAM(ram *iso18626.RequestingAgencyMessage) *iso18626.ISO18626Message { + var message = iso18626.NewISO18626Message() message.RequestingAgencyMessage = ram return message } -func newReq(request *iso18626.Request) *iso18626.Iso18626MessageNS { - var message = iso18626.NewIso18626MessageNS() +func newReq(request *iso18626.Request) *iso18626.ISO18626Message { + var message = iso18626.NewISO18626Message() message.Request = request return message } @@ -42,7 +42,7 @@ func TestIso18626AlmaShimLoanCompleted(t *testing.T) { shim := GetShim(string(directory.Alma)) bytes, err := shim.ApplyToOutgoingRequest(msg) assert.Nil(t, err, "failed to apply outgoing") - var resmsg iso18626.Iso18626MessageNS + var resmsg iso18626.ISO18626Message err = xml.Unmarshal(bytes, &resmsg) assert.Nil(t, err, "failed to parse xml") assert.Equal(t, iso18626.TypeReasonForMessageRequestResponse, resmsg.SupplyingAgencyMessage.MessageInfo.ReasonForMessage) @@ -68,7 +68,7 @@ func TestIso18626AlmaShimCopyCompleted(t *testing.T) { shim := GetShim(string(directory.Alma)) bytes, err := shim.ApplyToOutgoingRequest(msg) assert.Nil(t, err, "failed to apply outgoing") - var resmsg iso18626.Iso18626MessageNS + var resmsg iso18626.ISO18626Message err = xml.Unmarshal(bytes, &resmsg) assert.Nil(t, err, "failed to parse xml") assert.Equal(t, iso18626.TypeStatusCopyCompleted, resmsg.SupplyingAgencyMessage.StatusInfo.Status) @@ -78,7 +78,7 @@ func TestIso18626AlmaShimCopyCompleted(t *testing.T) { //apply again that URL is added once bytes, err = shim.ApplyToOutgoingRequest(&resmsg) assert.Nil(t, err, "failed to apply outgoing") - var resmsg2 iso18626.Iso18626MessageNS + var resmsg2 iso18626.ISO18626Message err = xml.Unmarshal(bytes, &resmsg2) assert.Nil(t, err, "failed to parse xml") assert.Equal(t, URL_PRE+"http://example.com/item/12345678"+NOTE_FIELD_SEP+ @@ -103,7 +103,7 @@ func TestIso18626AlmaShimCopyCompletedEmail(t *testing.T) { shim := GetShim(string(directory.Alma)) bytes, err := shim.ApplyToOutgoingRequest(msg) assert.Nil(t, err, "failed to apply outgoing") - var resmsg iso18626.Iso18626MessageNS + var resmsg iso18626.ISO18626Message err = xml.Unmarshal(bytes, &resmsg) assert.Nil(t, err, "failed to parse xml") assert.Equal(t, iso18626.TypeStatusCopyCompleted, resmsg.SupplyingAgencyMessage.StatusInfo.Status) @@ -144,7 +144,7 @@ func TestIso18626AlmaShimLoanLoaned(t *testing.T) { shim := GetShim(string(directory.Alma)) bytes, err := shim.ApplyToOutgoingRequest(msg) assert.Nil(t, err, "failed to apply outgoing") - var resmsg iso18626.Iso18626MessageNS + var resmsg iso18626.ISO18626Message err = xml.Unmarshal(bytes, &resmsg) assert.Nil(t, err, "failed to parse xml") assert.Equal(t, iso18626.TypeReasonForMessageStatusChange, @@ -195,7 +195,7 @@ func TestIso18626AlmaShimIncoming(t *testing.T) { assert.Equal(t, 2, msg.SupplyingAgencyMessage.DeliveryInfo.DeliveryCosts.MonetaryValue.Exp, "DeliveryCosts.Exp should be 2") assert.Nil(t, msg.SupplyingAgencyMessage.MessageInfo.OfferedCosts, "OfferedCosts should be nil") - var resmsg iso18626.Iso18626MessageNS + var resmsg iso18626.ISO18626Message shim := GetShim(string(directory.Alma)) err = shim.ApplyToIncomingResponse(bytes, &resmsg) if err != nil { @@ -222,7 +222,7 @@ func TestIso18626AlmaShimWillSupply(t *testing.T) { shim := GetShim(string(directory.Alma)) bytes, err := shim.ApplyToOutgoingRequest(msg) assert.Nil(t, err, "failed to apply outgoing") - var resmsg iso18626.Iso18626MessageNS + var resmsg iso18626.ISO18626Message err = xml.Unmarshal(bytes, &resmsg) assert.Nil(t, err, "failed to parse xml") assert.Equal(t, iso18626.TypeStatusWillSupply, resmsg.SupplyingAgencyMessage.StatusInfo.Status) @@ -299,7 +299,7 @@ func TestIso18626AlmaShimExpectToSupply(t *testing.T) { shim := GetShim(string(directory.Alma)) bytes, err := shim.ApplyToOutgoingRequest(msg) assert.Nil(t, err, "failed to apply outgoing") - var resmsg iso18626.Iso18626MessageNS + var resmsg iso18626.ISO18626Message err = xml.Unmarshal(bytes, &resmsg) assert.Nil(t, err, "failed to parse xml") assert.Equal(t, iso18626.TypeStatusWillSupply, resmsg.SupplyingAgencyMessage.StatusInfo.Status) @@ -318,7 +318,7 @@ func TestIso18626AlmaShimNotificationRequestReceived(t *testing.T) { shim := GetShim(string(directory.Alma)) bytes, err := shim.ApplyToOutgoingRequest(msg) assert.Nil(t, err, "failed to apply outgoing") - var resmsg iso18626.Iso18626MessageNS + var resmsg iso18626.ISO18626Message err = xml.Unmarshal(bytes, &resmsg) assert.Nil(t, err, "failed to parse xml") assert.Equal(t, iso18626.TypeStatusRequestReceived, resmsg.SupplyingAgencyMessage.StatusInfo.Status) @@ -339,7 +339,7 @@ func TestIso18626DefaultShim(t *testing.T) { if err != nil { t.Errorf("failed to apply outgoing") } - var resmsg iso18626.Iso18626MessageNS + var resmsg iso18626.ISO18626Message err = shim.ApplyToIncomingResponse(bytes, &resmsg) if err != nil { t.Errorf("failed to apply incoming") @@ -429,7 +429,7 @@ func TestIso18626AlmaShimRequest(t *testing.T) { if err != nil { t.Errorf("failed to apply outgoing") } - var resmsg iso18626.Iso18626MessageNS + var resmsg iso18626.ISO18626Message err = shim.ApplyToIncomingResponse(bytes, &resmsg) if err != nil { t.Errorf("failed to apply incoming") @@ -461,7 +461,7 @@ func TestIso18626AlmaShimStripReqSeqMsg(t *testing.T) { msgBytes, err := GetShim(string(directory.Alma)).ApplyToOutgoingRequest(msg) assert.Nil(t, err) - var resmsg iso18626.Iso18626MessageNS + var resmsg iso18626.ISO18626Message err = GetShim("default").ApplyToIncomingResponse(msgBytes, &resmsg) assert.Nil(t, err) @@ -476,7 +476,7 @@ func TestIso18626AlmaShimHumanizeReShareRequesterNote(t *testing.T) { msgBytes, err := GetShim(string(directory.Alma)).ApplyToOutgoingRequest(msg) assert.Nil(t, err) - var resmsg iso18626.Iso18626MessageNS + var resmsg iso18626.ISO18626Message err = GetShim("default").ApplyToIncomingResponse(msgBytes, &resmsg) assert.Nil(t, err) @@ -492,7 +492,7 @@ func TestIso18626AlmaShimSupplyingMessageLoanConditions(t *testing.T) { msgBytes, err := GetShim(string(directory.Alma)).ApplyToOutgoingRequest(msg) assert.Nil(t, err) - var resmsg iso18626.Iso18626MessageNS + var resmsg iso18626.ISO18626Message err = GetShim("default").ApplyToIncomingResponse(msgBytes, &resmsg) assert.Nil(t, err) @@ -513,7 +513,7 @@ func TestIso18626AlmaShimSupplyingMessageAddLoanCondition(t *testing.T) { msgBytes, err := GetShim(string(directory.Alma)).ApplyToOutgoingRequest(msg) assert.Nil(t, err) - var resmsg iso18626.Iso18626MessageNS + var resmsg iso18626.ISO18626Message err = GetShim("default").ApplyToIncomingResponse(msgBytes, &resmsg) assert.Nil(t, err) assert.Equal(t, LOAN_CONDITION_PRE+string(iso18626.LoanConditionLibraryUseOnly), resmsg.SupplyingAgencyMessage.MessageInfo.Note) @@ -541,7 +541,7 @@ func TestIso18626AlmaShimSupplyingMessageAddLoanConditionWithNote(t *testing.T) msgBytes, err := GetShim(string(directory.Alma)).ApplyToOutgoingRequest(msg) assert.Nil(t, err) - var resmsg iso18626.Iso18626MessageNS + var resmsg iso18626.ISO18626Message err = GetShim("default").ApplyToIncomingResponse(msgBytes, &resmsg) assert.Nil(t, err) @@ -559,7 +559,7 @@ func TestIso18626AlmaShimSupplyingMessageLoanConditionsAssumedAgreed(t *testing. msgBytes, err := GetShim(string(directory.Alma)).ApplyToOutgoingRequest(msg) assert.Nil(t, err) - var resmsg iso18626.Iso18626MessageNS + var resmsg iso18626.ISO18626Message err = GetShim("default").ApplyToIncomingResponse(msgBytes, &resmsg) assert.Nil(t, err) @@ -670,7 +670,7 @@ func TestIso18626AReShareShimSupplyingOutgoing(t *testing.T) { if err != nil { t.Errorf("failed to apply outgoing") } - var resmsg iso18626.Iso18626MessageNS + var resmsg iso18626.ISO18626Message err = xml.Unmarshal(bytes, &resmsg) if err != nil { t.Errorf("failed to unmarshal outgoing") @@ -715,7 +715,7 @@ func TestIso18626AReShareShimSupplyingOutgoingZeroCost(t *testing.T) { if err != nil { t.Errorf("failed to apply outgoing") } - var resmsg iso18626.Iso18626MessageNS + var resmsg iso18626.ISO18626Message err = xml.Unmarshal(bytes, &resmsg) if err != nil { t.Errorf("failed to unmarshal outgoing") @@ -813,7 +813,7 @@ func TestProcessItemIdOneItemSimpleReShare(t *testing.T) { result.SupplyingAgencyMessage.DeliveryInfo.ItemId = "" mesBytes, err := shimR.ApplyToOutgoingRequest(result) assert.NoError(t, err) - var resmsg iso18626.Iso18626MessageNS + var resmsg iso18626.ISO18626Message err = new(Iso18626DefaultShim).ApplyToIncomingResponse(mesBytes, &resmsg) assert.NoError(t, err) assert.Equal(t, "1|23\\", resmsg.SupplyingAgencyMessage.DeliveryInfo.ItemId) @@ -878,7 +878,7 @@ func TestProcessItemIdOneItemReShare(t *testing.T) { result.SupplyingAgencyMessage.DeliveryInfo.ItemId = "" mesBytes, err := shimR.ApplyToOutgoingRequest(result) assert.NoError(t, err) - var resmsg iso18626.Iso18626MessageNS + var resmsg iso18626.ISO18626Message err = new(Iso18626DefaultShim).ApplyToIncomingResponse(mesBytes, &resmsg) assert.NoError(t, err) assert.Equal(t, "name1|2,3\\,c|123,id|123", resmsg.SupplyingAgencyMessage.DeliveryInfo.ItemId) @@ -909,7 +909,7 @@ func TestProcessItemIdMultipleItemsReShare(t *testing.T) { result.SupplyingAgencyMessage.DeliveryInfo.ItemId = "" mesBytes, err := shimR.ApplyToOutgoingRequest(result) assert.NoError(t, err) - var resmsg iso18626.Iso18626MessageNS + var resmsg iso18626.ISO18626Message err = new(Iso18626DefaultShim).ApplyToIncomingResponse(mesBytes, &resmsg) assert.NoError(t, err) assert.Equal(t, "multivol:name1|2,3\\,c|123,id|123,multivol:name1|2,4\\,c|124,id|124,multivol:name1|2,5\\,c|125,id|125", resmsg.SupplyingAgencyMessage.DeliveryInfo.ItemId) @@ -936,7 +936,7 @@ func TestProcessItemIdMultipleItemsReShareNoNote(t *testing.T) { result.SupplyingAgencyMessage.DeliveryInfo.ItemId = "" mesBytes, err := shimR.ApplyToOutgoingRequest(result) assert.NoError(t, err) - var resmsg iso18626.Iso18626MessageNS + var resmsg iso18626.ISO18626Message err = new(Iso18626DefaultShim).ApplyToIncomingResponse(mesBytes, &resmsg) assert.NoError(t, err) assert.Equal(t, "multivol:name1|2,3\\,c|123,id|123,multivol:name1|2,4\\,c|124,id|124,multivol:name1|2,5\\,c|125,id|125", resmsg.SupplyingAgencyMessage.DeliveryInfo.ItemId) @@ -965,7 +965,7 @@ func TestProcessItemIdOneItemAlma(t *testing.T) { result.SupplyingAgencyMessage.DeliveryInfo.ItemId = "" mesBytes, err := shimA.ApplyToOutgoingRequest(result) assert.NoError(t, err) - var resmsg iso18626.Iso18626MessageNS + var resmsg iso18626.ISO18626Message err = new(Iso18626DefaultShim).ApplyToIncomingResponse(mesBytes, &resmsg) assert.NoError(t, err) assert.Equal(t, "1|23\\", resmsg.SupplyingAgencyMessage.DeliveryInfo.ItemId) @@ -996,7 +996,7 @@ func TestProcessItemIdMultipleItemsAlma(t *testing.T) { result.SupplyingAgencyMessage.DeliveryInfo.ItemId = "" mesBytes, err := shimA.ApplyToOutgoingRequest(result) assert.NoError(t, err) - var resmsg iso18626.Iso18626MessageNS + var resmsg iso18626.ISO18626Message err = new(Iso18626DefaultShim).ApplyToIncomingResponse(mesBytes, &resmsg) assert.NoError(t, err) assert.Equal(t, "1|23\\,1|24\\,1|25\\", resmsg.SupplyingAgencyMessage.DeliveryInfo.ItemId) diff --git a/broker/test/api/sse_broker_test.go b/broker/test/api/sse_broker_test.go index fd10a3cb..629b9e60 100644 --- a/broker/test/api/sse_broker_test.go +++ b/broker/test/api/sse_broker_test.go @@ -115,7 +115,7 @@ func TestSseEndpointNoSymbol(t *testing.T) { func executeTask(t time.Time) { ctx := common.CreateExtCtxWithArgs(context.Background(), nil) - var message = iso18626.NewIso18626MessageNS() + var message = iso18626.NewISO18626Message() message.SupplyingAgencyMessage = &iso18626.SupplyingAgencyMessage{ Header: iso18626.Header{ RequestingAgencyId: iso18626.TypeAgencyId{ diff --git a/broker/test/client/client_test.go b/broker/test/client/client_test.go index 1a66f246..4d49ad5f 100644 --- a/broker/test/client/client_test.go +++ b/broker/test/client/client_test.go @@ -438,7 +438,7 @@ func (m *MockRoundTripper) RoundTrip(req *http.Request) (*http.Response, error) func TestSendHttpPost(t *testing.T) { // Define test cases - var requestM = iso18626.NewIso18626MessageNS() + var requestM = iso18626.NewISO18626Message() requestM.Request = &iso18626.Request{ Header: iso18626.Header{ SupplyingAgencyRequestId: "test\x00\x1Fdata\"<>&", @@ -447,31 +447,31 @@ func TestSendHttpPost(t *testing.T) { tests := []struct { name string url string - msg *iso18626.Iso18626MessageNS + msg *iso18626.ISO18626Message mockResponse *http.Response mockError error - expectedResult *iso18626.Iso18626MessageNS + expectedResult *iso18626.ISO18626Message expectedError string }{ { name: "successful post request", url: "https://test.com", - msg: iso18626.NewIso18626MessageNS(), + msg: iso18626.NewISO18626Message(), mockResponse: &http.Response{ StatusCode: http.StatusOK, Header: http.Header{"Content-Type": []string{"application/xml"}}, - Body: io.NopCloser(bytes.NewBufferString(` + Body: io.NopCloser(bytes.NewBufferString(` `)), }, mockError: nil, - expectedResult: iso18626.NewIso18626MessageNS(), + expectedResult: iso18626.NewISO18626Message(), expectedError: "", }, { name: "server error", url: "https://test.com", - msg: iso18626.NewIso18626MessageNS(), + msg: iso18626.NewISO18626Message(), mockResponse: &http.Response{ StatusCode: http.StatusInternalServerError, Body: io.NopCloser(bytes.NewBufferString("Internal Server Error")), @@ -483,7 +483,7 @@ func TestSendHttpPost(t *testing.T) { { name: "request error", url: "https://test.com", - msg: iso18626.NewIso18626MessageNS(), + msg: iso18626.NewISO18626Message(), mockResponse: nil, mockError: fmt.Errorf("mock request error"), expectedResult: nil, @@ -615,7 +615,7 @@ func TestRequestLocallyAvailableRequesterMessage(t *testing.T) { func TestRequestLocallyAvailableSupplierMessage(t *testing.T) { appCtx := common.CreateExtCtxWithArgs(context.Background(), nil) illTrans := requestLocallyAvailableSetup(t, appCtx, common.BrokerModeOpaque) - var message = iso18626.NewIso18626MessageNS() + var message = iso18626.NewISO18626Message() message.SupplyingAgencyMessage = &iso18626.SupplyingAgencyMessage{ StatusInfo: iso18626.StatusInfo{ Status: iso18626.TypeStatusLoaned, diff --git a/broker/test/handler/iso18626-handler_test.go b/broker/test/handler/iso18626-handler_test.go index 4ce24aea..e8f354ed 100644 --- a/broker/test/handler/iso18626-handler_test.go +++ b/broker/test/handler/iso18626-handler_test.go @@ -241,8 +241,8 @@ func createErrorData(errorMessage *string, errorType *iso18626.TypeErrorType) *i } // largely copied from illmock/app/requester.go -func createSupplyingAgencyResponse(supplyingAgencyMessage *iso18626.SupplyingAgencyMessage, messageStatus iso18626.TypeMessageStatus, errorMessage *string, errorType *iso18626.TypeErrorType) *iso18626.Iso18626MessageNS { - var resmsg = iso18626.NewIso18626MessageNS() +func createSupplyingAgencyResponse(supplyingAgencyMessage *iso18626.SupplyingAgencyMessage, messageStatus iso18626.TypeMessageStatus, errorMessage *string, errorType *iso18626.TypeErrorType) *iso18626.ISO18626Message { + var resmsg = iso18626.NewISO18626Message() header := createConfirmationHeader(&supplyingAgencyMessage.Header, messageStatus) errorData := createErrorData(errorMessage, errorType) resmsg.SupplyingAgencyMessageConfirmation = &iso18626.SupplyingAgencyMessageConfirmation{ @@ -269,7 +269,7 @@ func TestIso18626PostSupplyingMessageConfirm(t *testing.T) { http.Error(w, err.Error(), http.StatusBadRequest) return } - var illMessage iso18626.Iso18626MessageNS + var illMessage iso18626.ISO18626Message err = xml.Unmarshal(byteReq, &illMessage) assert.NoError(t, err) supplyingAgencyMessage := illMessage.SupplyingAgencyMessage diff --git a/broker/test/service/e2e_test.go b/broker/test/service/e2e_test.go index 6c6ccd2a..6f2f8622 100644 --- a/broker/test/service/e2e_test.go +++ b/broker/test/service/e2e_test.go @@ -164,7 +164,7 @@ func TestRequestUNFILLED(t *testing.T) { assert.Equal(t, http.StatusOK, res.StatusCode) body, err := io.ReadAll(res.Body) assert.Nil(t, err) - var msg iso18626.Iso18626MessageNS + var msg iso18626.ISO18626Message err = xml.Unmarshal(body, &msg) assert.Nil(t, err) assert.NotNil(t, msg.RequestConfirmation) @@ -223,7 +223,7 @@ func TestMessageAfterUNFILLED(t *testing.T) { assert.Equal(t, http.StatusOK, res.StatusCode) body, err := io.ReadAll(res.Body) assert.Nil(t, err) - var msg iso18626.Iso18626MessageNS + var msg iso18626.ISO18626Message err = xml.Unmarshal(body, &msg) assert.Nil(t, err) assert.NotNil(t, msg.SupplyingAgencyMessageConfirmation) @@ -296,7 +296,7 @@ func TestMessageSkipped(t *testing.T) { assert.Equal(t, http.StatusOK, res.StatusCode) body, err := io.ReadAll(res.Body) assert.Nil(t, err) - var msg iso18626.Iso18626MessageNS + var msg iso18626.ISO18626Message err = xml.Unmarshal(body, &msg) assert.Nil(t, err) assert.NotNil(t, msg.SupplyingAgencyMessageConfirmation) @@ -640,7 +640,7 @@ func TestRequestRETRY_NON_EXISTING(t *testing.T) { assert.Equal(t, http.StatusOK, res.StatusCode) body, err := io.ReadAll(res.Body) assert.Nil(t, err) - var msg iso18626.Iso18626MessageNS + var msg iso18626.ISO18626Message err = xml.Unmarshal(body, &msg) assert.Nil(t, err) assert.NotNil(t, msg.RequestConfirmation) @@ -661,7 +661,7 @@ func TestRequestREMINDER(t *testing.T) { assert.Equal(t, http.StatusOK, res.StatusCode) body, err := io.ReadAll(res.Body) assert.Nil(t, err) - var msg iso18626.Iso18626MessageNS + var msg iso18626.ISO18626Message err = xml.Unmarshal(body, &msg) assert.Nil(t, err) assert.NotNil(t, msg.RequestConfirmation) diff --git a/broker/test/service/supplierlocator_test.go b/broker/test/service/supplierlocator_test.go index 4b9ef33e..63d5e40c 100644 --- a/broker/test/service/supplierlocator_test.go +++ b/broker/test/service/supplierlocator_test.go @@ -548,7 +548,7 @@ func TestUnfilledMessageWithReason(t *testing.T) { completedTask = append(completedTask, event) } }) - var message = iso18626.NewIso18626MessageNS() + var message = iso18626.NewISO18626Message() message.SupplyingAgencyMessage = &iso18626.SupplyingAgencyMessage{ Header: iso18626.Header{ SupplyingAgencyId: iso18626.TypeAgencyId{ @@ -629,7 +629,7 @@ func TestUnfilledMessageWithReason_BrokerModeOpaque(t *testing.T) { completedTask = append(completedTask, event) } }) - var message = iso18626.NewIso18626MessageNS() + var message = iso18626.NewISO18626Message() message.SupplyingAgencyMessage = &iso18626.SupplyingAgencyMessage{ Header: iso18626.Header{ SupplyingAgencyId: iso18626.TypeAgencyId{ diff --git a/illmock/app/app.go b/illmock/app/app.go index 07cd604a..41214333 100644 --- a/illmock/app/app.go +++ b/illmock/app/app.go @@ -54,7 +54,7 @@ func validateHeader(header *iso18626.Header) error { return nil } -func (app *MockApp) writeIso18626Response(resmsg *iso18626.Iso18626MessageNS, w http.ResponseWriter, role role.Role, header *iso18626.Header) { +func (app *MockApp) writeIso18626Response(resmsg *iso18626.ISO18626Message, w http.ResponseWriter, role role.Role, header *iso18626.Header) { buf := utils.Must(xml.MarshalIndent(resmsg, " ", " ")) if buf == nil { http.Error(w, "marshal failed", http.StatusInternalServerError) @@ -96,8 +96,8 @@ func createErrorData(errorMessage *string, errorType *iso18626.TypeErrorType) *i return nil } -func createRequestResponse(requestHeader *iso18626.Header, messageStatus iso18626.TypeMessageStatus, errorMessage *string, errorType *iso18626.TypeErrorType) *iso18626.Iso18626MessageNS { - var resmsg = iso18626.NewIso18626MessageNS() +func createRequestResponse(requestHeader *iso18626.Header, messageStatus iso18626.TypeMessageStatus, errorMessage *string, errorType *iso18626.TypeErrorType) *iso18626.ISO18626Message { + var resmsg = iso18626.NewISO18626Message() header := createConfirmationHeader(requestHeader, messageStatus) errorData := createErrorData(errorMessage, errorType) resmsg.RequestConfirmation = &iso18626.RequestConfirmation{ @@ -112,8 +112,8 @@ func (app *MockApp) handleRequestError(requestHeader *iso18626.Header, role role app.writeIso18626Response(resmsg, w, role, requestHeader) } -func createRequestingAgencyConfirmation(iheader *iso18626.Header, messageStatus iso18626.TypeMessageStatus, errorMessage *string, errorType *iso18626.TypeErrorType) *iso18626.Iso18626MessageNS { - var resmsg = iso18626.NewIso18626MessageNS() +func createRequestingAgencyConfirmation(iheader *iso18626.Header, messageStatus iso18626.TypeMessageStatus, errorMessage *string, errorType *iso18626.TypeErrorType) *iso18626.ISO18626Message { + var resmsg = iso18626.NewISO18626Message() header := createConfirmationHeader(iheader, messageStatus) errorData := createErrorData(errorMessage, errorType) resmsg.RequestingAgencyMessageConfirmation = &iso18626.RequestingAgencyMessageConfirmation{ @@ -123,12 +123,12 @@ func createRequestingAgencyConfirmation(iheader *iso18626.Header, messageStatus return resmsg } -func (app *MockApp) sendReceive(url string, msg *iso18626.Iso18626MessageNS, role role.Role, header *iso18626.Header) (*iso18626.Iso18626MessageNS, error) { +func (app *MockApp) sendReceive(url string, msg *iso18626.ISO18626Message, role role.Role, header *iso18626.Header) (*iso18626.ISO18626Message, error) { if url == "" { return nil, fmt.Errorf("url cannot be empty") } app.logOutgoingReq(role, header, msg, url) - var response iso18626.Iso18626MessageNS + var response iso18626.ISO18626Message err := app.client.PostXml(http.DefaultClient, url, msg, &response) if err != nil { status := 0 @@ -142,7 +142,7 @@ func (app *MockApp) sendReceive(url string, msg *iso18626.Iso18626MessageNS, rol return &response, nil } -func logMessage(lead string, illMessage *iso18626.Iso18626MessageNS) bool { +func logMessage(lead string, illMessage *iso18626.ISO18626Message) bool { buf := utils.Must(xml.MarshalIndent(illMessage, " ", " ")) if buf == nil { return false @@ -151,7 +151,7 @@ func logMessage(lead string, illMessage *iso18626.Iso18626MessageNS) bool { return true } -func (app *MockApp) logIso18626Message(role role.Role, kind string, header *iso18626.Header, illMessage *iso18626.Iso18626MessageNS, extra string) { +func (app *MockApp) logIso18626Message(role role.Role, kind string, header *iso18626.Header, illMessage *iso18626.ISO18626Message, extra string) { logmsg := fmt.Sprintf("%s role:%s id:%s req:%s sup:%s%s", kind, role, header.RequestingAgencyRequestId, header.RequestingAgencyId.AgencyIdValue, header.SupplyingAgencyId.AgencyIdValue, extra) if logMessage(logmsg, illMessage) { @@ -161,11 +161,11 @@ func (app *MockApp) logIso18626Message(role role.Role, kind string, header *iso1 } } -func (app *MockApp) logIncomingReq(role role.Role, header *iso18626.Header, illMessage *iso18626.Iso18626MessageNS) { +func (app *MockApp) logIncomingReq(role role.Role, header *iso18626.Header, illMessage *iso18626.ISO18626Message) { app.logIso18626Message(role, "incoming-request", header, illMessage, "") } -func (app *MockApp) logOutgoingReq(role role.Role, header *iso18626.Header, illMessage *iso18626.Iso18626MessageNS, +func (app *MockApp) logOutgoingReq(role role.Role, header *iso18626.Header, illMessage *iso18626.ISO18626Message, url string) { app.logIso18626Message(role, "outgoing-request", header, illMessage, fmt.Sprintf(" url:%s", url)) } @@ -175,12 +175,12 @@ func (app *MockApp) logOutgoingErr(role role.Role, header *iso18626.Header, url header.RequestingAgencyId.AgencyIdValue, header.SupplyingAgencyId.AgencyIdValue, url, status, error)) } -func (app *MockApp) logIncomingRes(role role.Role, header *iso18626.Header, illMessage *iso18626.Iso18626MessageNS, +func (app *MockApp) logIncomingRes(role role.Role, header *iso18626.Header, illMessage *iso18626.ISO18626Message, url string) { app.logIso18626Message(role, "incoming-response", header, illMessage, fmt.Sprintf(" url:%s", url)) } -func (app *MockApp) logOutgoingRes(role role.Role, header *iso18626.Header, illMessage *iso18626.Iso18626MessageNS) { +func (app *MockApp) logOutgoingRes(role role.Role, header *iso18626.Header, illMessage *iso18626.ISO18626Message) { app.logIso18626Message(role, "outgoing-response", header, illMessage, "") } @@ -222,7 +222,7 @@ func iso18626Handler(app *MockApp) http.HandlerFunc { http.Error(w, err.Error(), http.StatusBadRequest) return } - var illMessage iso18626.Iso18626MessageNS + var illMessage iso18626.ISO18626Message err = xml.Unmarshal(byteReq, &illMessage) if err != nil { http.Error(w, "unmarshal: "+err.Error(), http.StatusBadRequest) @@ -321,7 +321,6 @@ func (app *MockApp) Run() error { if app.headers != nil { app.client = *app.client.WithHeaders(app.headers...) } - iso18626.InitNs() log.Info("Mock starting") if app.agencyType == "" { app.agencyType = "MOCK" diff --git a/illmock/app/app_test.go b/illmock/app/app_test.go index 03ae6e8c..ecae449e 100644 --- a/illmock/app/app_test.go +++ b/illmock/app/app_test.go @@ -24,7 +24,7 @@ import ( "github.com/stretchr/testify/assert" ) -func createPatronRequest() *iso18626.Iso18626MessageNS { +func createPatronRequest() *iso18626.ISO18626Message { var msg = createRequest() msg.Request = &iso18626.Request{} msg.Request.ServiceInfo = &iso18626.ServiceInfo{} @@ -34,7 +34,7 @@ func createPatronRequest() *iso18626.Iso18626MessageNS { return msg } -func addPhysicalAddress(msg *iso18626.Iso18626MessageNS, sortOrder int64) { +func addPhysicalAddress(msg *iso18626.ISO18626Message, sortOrder int64) { deliveryInfo := iso18626.RequestedDeliveryInfo{} deliveryInfo.Address = &iso18626.Address{} deliveryInfo.Address.PhysicalAddress = &iso18626.PhysicalAddress{} @@ -43,7 +43,7 @@ func addPhysicalAddress(msg *iso18626.Iso18626MessageNS, sortOrder int64) { msg.Request.RequestedDeliveryInfo = append(msg.Request.RequestedDeliveryInfo, deliveryInfo) } -func addElectronicAddress(msg *iso18626.Iso18626MessageNS, addrType iso18626.ElectronicAddressType, addrValue string, sortOrder int64) { +func addElectronicAddress(msg *iso18626.ISO18626Message, addrType iso18626.ElectronicAddressType, addrValue string, sortOrder int64) { electronicDelivery := iso18626.RequestedDeliveryInfo{} electronicDelivery.Address = &iso18626.Address{} emailAddr := iso18626.ElectronicAddress{} @@ -148,7 +148,7 @@ func TestSendReceiveUnmarshalFailed(t *testing.T) { defer server.Close() app.peerUrl = server.URL + "/iso18626" - msg := iso18626.NewIso18626MessageNS() + msg := iso18626.NewISO18626Message() msg.Request = &iso18626.Request{Header: iso18626.Header{ SupplyingAgencyId: iso18626.TypeAgencyId{AgencyIdValue: "S1"}, RequestingAgencyId: iso18626.TypeAgencyId{AgencyIdValue: "R1"}, @@ -220,7 +220,7 @@ func TestFlowsApiParseEnvFailed(t *testing.T) { assert.NoError(t, err, "failed to set env") } -func runScenario(t *testing.T, isoUrl string, apiUrl string, msg *iso18626.Iso18626MessageNS, +func runScenario(t *testing.T, isoUrl string, apiUrl string, msg *iso18626.ISO18626Message, scenario string, expectedLen int) []flows.FlowMessage { f := runScenario2(t, isoUrl, apiUrl, msg, scenario, expectedLen) if f == nil { @@ -229,7 +229,7 @@ func runScenario(t *testing.T, isoUrl string, apiUrl string, msg *iso18626.Iso18 return f[0].Message } -func runScenario2(t *testing.T, isoUrl string, apiUrl string, msg *iso18626.Iso18626MessageNS, +func runScenario2(t *testing.T, isoUrl string, apiUrl string, msg *iso18626.ISO18626Message, scenario string, expectedLen int) []flows.Flow { requesterId := uuid.NewString() @@ -425,7 +425,7 @@ func TestService(t *testing.T) { }) t.Run("iso18626 handler: Invalid message", func(t *testing.T) { - var msg = iso18626.NewIso18626MessageNS() + var msg = iso18626.NewISO18626Message() msg.SupplyingAgencyMessageConfirmation = &iso18626.SupplyingAgencyMessageConfirmation{} buf := utils.Must(xml.Marshal(msg)) resp, err := http.Post(isoUrl, "text/xml", bytes.NewReader(buf)) @@ -1311,7 +1311,7 @@ func TestService(t *testing.T) { w.Header().Set("Content-Type", "text/xml") w.WriteHeader(http.StatusOK) // create supplyingagency response - response := iso18626.NewIso18626MessageNS() + response := iso18626.NewISO18626Message() response.SupplyingAgencyMessageConfirmation = &iso18626.SupplyingAgencyMessageConfirmation{ ConfirmationHeader: iso18626.ConfirmationHeader{ MessageStatus: iso18626.TypeMessageStatusOK, @@ -1533,7 +1533,7 @@ func TestSendRequestingAgencyUnexpectedISO18626Message(t *testing.T) { var app MockApp app.flowsApi = flows.CreateFlowsApi() handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - var resmsg = iso18626.NewIso18626MessageNS() + var resmsg = iso18626.NewISO18626Message() header := &iso18626.Header{} header.RequestingAgencyRequestId = uuid.NewString() header.SupplyingAgencyId.AgencyIdValue = "S1" @@ -1557,7 +1557,7 @@ func TestSendRequestingAgencyActionMismatch(t *testing.T) { var app MockApp app.flowsApi = flows.CreateFlowsApi() handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - var resmsg = iso18626.NewIso18626MessageNS() + var resmsg = iso18626.NewISO18626Message() resmsg.RequestingAgencyMessageConfirmation = &iso18626.RequestingAgencyMessageConfirmation{} act := iso18626.TypeActionReceived resmsg.RequestingAgencyMessageConfirmation.Action = &act @@ -1584,7 +1584,7 @@ func TestSendRequestingAgencyActionNil(t *testing.T) { var app MockApp app.flowsApi = flows.CreateFlowsApi() handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - var resmsg = iso18626.NewIso18626MessageNS() + var resmsg = iso18626.NewISO18626Message() resmsg.RequestingAgencyMessageConfirmation = &iso18626.RequestingAgencyMessageConfirmation{} header := &iso18626.Header{} header.RequestingAgencyRequestId = uuid.NewString() diff --git a/illmock/app/requester.go b/illmock/app/requester.go index 78b93c78..9d130bda 100644 --- a/illmock/app/requester.go +++ b/illmock/app/requester.go @@ -49,13 +49,13 @@ func (s *Requester) delete(header *iso18626.Header) { s.requests.Delete(s.getKey(header)) } -func createRequest() *iso18626.Iso18626MessageNS { - var msg = iso18626.NewIso18626MessageNS() +func createRequest() *iso18626.ISO18626Message { + var msg = iso18626.NewISO18626Message() msg.Request = &iso18626.Request{} return msg } -func (app *MockApp) handlePatronRequest(illMessage *iso18626.Iso18626MessageNS, w http.ResponseWriter) { +func (app *MockApp) handlePatronRequest(illMessage *iso18626.ISO18626Message, w http.ResponseWriter) { illRequest := illMessage.Request requester := &app.requester @@ -184,8 +184,8 @@ func (app *MockApp) sendRequestingAgencyMessage(header *iso18626.Header, action } } -func createSupplyingAgencyResponse(supplyingAgencyMessage *iso18626.SupplyingAgencyMessage, messageStatus iso18626.TypeMessageStatus, errorMessage *string, errorType *iso18626.TypeErrorType) *iso18626.Iso18626MessageNS { - var resmsg = iso18626.NewIso18626MessageNS() +func createSupplyingAgencyResponse(supplyingAgencyMessage *iso18626.SupplyingAgencyMessage, messageStatus iso18626.TypeMessageStatus, errorMessage *string, errorType *iso18626.TypeErrorType) *iso18626.ISO18626Message { + var resmsg = iso18626.NewISO18626Message() header := createConfirmationHeader(&supplyingAgencyMessage.Header, messageStatus) errorData := createErrorData(errorMessage, errorType) resmsg.SupplyingAgencyMessageConfirmation = &iso18626.SupplyingAgencyMessageConfirmation{ @@ -200,14 +200,14 @@ func (app *MockApp) handleSupplyingAgencyError(illMessage *iso18626.SupplyingAge app.writeIso18626Response(resmsg, w, role.Requester, &illMessage.Header) } -func createRequestingAgencyMessage() *iso18626.Iso18626MessageNS { - var msg = iso18626.NewIso18626MessageNS() +func createRequestingAgencyMessage() *iso18626.ISO18626Message { + var msg = iso18626.NewISO18626Message() msg.RequestingAgencyMessage = &iso18626.RequestingAgencyMessage{} return msg } func (app *MockApp) sendRetryRequest(illRequest *iso18626.Request, supplierUrl string, messageInfo *iso18626.MessageInfo, prevId string, newId string) { - msg := &iso18626.Iso18626MessageNS{} + msg := &iso18626.ISO18626Message{} msg.Request = &iso18626.Request{} *msg.Request = *illRequest msg.Request.ServiceInfo = &iso18626.ServiceInfo{} @@ -231,7 +231,7 @@ func (app *MockApp) sendRetryRequest(illRequest *iso18626.Request, supplierUrl s } } -func (app *MockApp) handleIso18626SupplyingAgencyMessage(illMessage *iso18626.Iso18626MessageNS, w http.ResponseWriter) { +func (app *MockApp) handleIso18626SupplyingAgencyMessage(illMessage *iso18626.ISO18626Message, w http.ResponseWriter) { requester := &app.requester supplyingAgencyMessage := illMessage.SupplyingAgencyMessage header := &supplyingAgencyMessage.Header diff --git a/illmock/app/supplier.go b/illmock/app/supplier.go index 649b1573..370ede4c 100644 --- a/illmock/app/supplier.go +++ b/illmock/app/supplier.go @@ -202,14 +202,14 @@ func (app *MockApp) handleSupplierRequest(illRequest *iso18626.Request, w http.R } } -func createSupplyingAgencyMessage() *iso18626.Iso18626MessageNS { - var msg = iso18626.NewIso18626MessageNS() +func createSupplyingAgencyMessage() *iso18626.ISO18626Message { + var msg = iso18626.NewISO18626Message() msg.SupplyingAgencyMessage = &iso18626.SupplyingAgencyMessage{} msg.SupplyingAgencyMessage.StatusInfo.LastChange = utils.XSDDateTime{Time: time.Now()} return msg } -func (app *MockApp) sendSupplyingAgencyMessage(header *iso18626.Header, state *supplierInfo, msg *iso18626.Iso18626MessageNS) bool { +func (app *MockApp) sendSupplyingAgencyMessage(header *iso18626.Header, state *supplierInfo, msg *iso18626.ISO18626Message) bool { msg.SupplyingAgencyMessage.Header = *header msg.SupplyingAgencyMessage.Header.SupplyingAgencyRequestId = state.supplierRequestId msg.SupplyingAgencyMessage.Header.Timestamp = utils.XSDDateTime{Time: time.Now()} @@ -357,7 +357,7 @@ func (app *MockApp) handleRequestingAgencyMessageError(request *iso18626.Request app.writeIso18626Response(resmsg, w, role, &request.Header) } -func (app *MockApp) handleIso18626RequestingAgencyMessage(illMessage *iso18626.Iso18626MessageNS, w http.ResponseWriter) { +func (app *MockApp) handleIso18626RequestingAgencyMessage(illMessage *iso18626.ISO18626Message, w http.ResponseWriter) { requestingAgencyMessage := illMessage.RequestingAgencyMessage app.logIncomingReq(role.Supplier, &requestingAgencyMessage.Header, illMessage) err := validateHeader(&requestingAgencyMessage.Header) diff --git a/illmock/flows/flows.go b/illmock/flows/flows.go index b1733d66..6d468f03 100644 --- a/illmock/flows/flows.go +++ b/illmock/flows/flows.go @@ -27,9 +27,9 @@ type FlowsApi struct { } type FlowMessage struct { - Kind string `xml:"kind,attr"` - Timestamp utils.XSDDateTime `xml:"timestamp,attr"` - Message iso18626.Iso18626MessageNS `xml:"ISO18626Message"` + Kind string `xml:"kind,attr"` + Timestamp utils.XSDDateTime `xml:"timestamp,attr"` + Message iso18626.ISO18626Message `xml:"ISO18626Message"` } type FlowError struct { diff --git a/illmock/flows/flows_test.go b/illmock/flows/flows_test.go index 69c52478..7f2c51c7 100644 --- a/illmock/flows/flows_test.go +++ b/illmock/flows/flows_test.go @@ -38,7 +38,7 @@ func TestFlowApiBadMethod(t *testing.T) { } func TestMarshalRequest(t *testing.T) { - illMessage := iso18626.NewIso18626MessageNS() + illMessage := iso18626.NewISO18626Message() illMessage.Request = &iso18626.Request{} illMessage.Request.Header.RequestingAgencyRequestId = "rid" flowMessage := FlowMessage{Kind: "incoming", Timestamp: utils.XSDDateTime{Time: time.Now().UTC().Round(time.Millisecond)}, Message: *illMessage} @@ -112,7 +112,7 @@ func TestGetFlows(t *testing.T) { assert.NotNil(t, flows) assert.Equal(t, 0, len(flows.Flows)) - illMessage1 := iso18626.NewIso18626MessageNS() + illMessage1 := iso18626.NewISO18626Message() flowMessage := FlowMessage{Kind: "incoming", Timestamp: utils.XSDDateTime{Time: time.Now().UTC().Round(time.Millisecond)}, Message: *illMessage1} flow1 := Flow{Message: []FlowMessage{flowMessage}, Id: "rid", Role: role.Requester, Supplier: "S1", Requester: "R1"} api.AddFlow(flow1) @@ -122,7 +122,7 @@ func TestGetFlows(t *testing.T) { assert.Equal(t, []Flow{flow1}, flowsR.Flows) assert.Len(t, flowsR.Flows[0].Message, 1) - illMessage2 := iso18626.NewIso18626MessageNS() + illMessage2 := iso18626.NewISO18626Message() flowMessage = FlowMessage{Kind: "outgoing", Timestamp: utils.XSDDateTime{Time: time.Now().UTC().Round(time.Millisecond)}, Message: *illMessage2} flow2 := Flow{Message: []FlowMessage{flowMessage}, Id: "rid", Role: role.Supplier, Supplier: "S2", Requester: "R2"} api.AddFlow(flow2) @@ -132,7 +132,7 @@ func TestGetFlows(t *testing.T) { assert.Equal(t, []Flow{flow1, flow2}, flowsR.Flows) assert.Len(t, flowsR.Flows[0].Message, 1) - illMessage3 := iso18626.NewIso18626MessageNS() + illMessage3 := iso18626.NewISO18626Message() flowMessage = FlowMessage{Kind: "incoming", Timestamp: utils.XSDDateTime{Time: time.Now().UTC().Round(time.Millisecond)}, Message: *illMessage3} flow3 := Flow{Message: []FlowMessage{flowMessage}, Id: "rid2", Role: role.Supplier, Supplier: "S3", Requester: "R3"} api.AddFlow(flow3) @@ -163,7 +163,7 @@ func TestGetFlows(t *testing.T) { assert.Equal(t, []Flow(nil), flowsR.Flows) // merged with flow1 - illMessage4 := iso18626.NewIso18626MessageNS() + illMessage4 := iso18626.NewISO18626Message() flowMessage = FlowMessage{Kind: "outgoing", Timestamp: utils.XSDDateTime{Time: time.Now().UTC().Round(time.Millisecond)}, Message: *illMessage4} flow4 := Flow{Message: []FlowMessage{flowMessage}, Id: "rid", Role: role.Requester, Supplier: "S1", Requester: "R1"} api.AddFlow(flow4) @@ -186,7 +186,7 @@ func TestCleanerExpire(t *testing.T) { server := httptest.NewServer(api.HttpHandler()) defer server.Close() - illMessage1 := iso18626.NewIso18626MessageNS() + illMessage1 := iso18626.NewISO18626Message() flowMessage := FlowMessage{Kind: "incoming", Timestamp: utils.XSDDateTime{Time: time.Now().UTC().Round(time.Millisecond)}, Message: *illMessage1} flow1 := Flow{Message: []FlowMessage{flowMessage}, Id: "rid", Role: role.Requester, Supplier: "S1", Requester: "R1"} api.AddFlow(flow1) @@ -219,7 +219,7 @@ func TestCleanerKeep(t *testing.T) { server := httptest.NewServer(api.HttpHandler()) defer server.Close() - illMessage1 := iso18626.NewIso18626MessageNS() + illMessage1 := iso18626.NewISO18626Message() flowMessage := FlowMessage{Kind: "incoming", Timestamp: utils.XSDDateTime{Time: time.Now().UTC().Round(time.Millisecond)}, Message: *illMessage1} flow1 := Flow{Message: []FlowMessage{flowMessage}, Id: "rid", Role: role.Requester, Supplier: "S1", Requester: "R1"} api.AddFlow(flow1) diff --git a/illmock/reqform/reqform_test.go b/illmock/reqform/reqform_test.go index 728b8566..7b0c4af0 100644 --- a/illmock/reqform/reqform_test.go +++ b/illmock/reqform/reqform_test.go @@ -47,7 +47,7 @@ func TestReqForm(t *testing.T) { http.Error(w, err.Error(), http.StatusBadRequest) return } - var illMessage iso18626.Iso18626MessageNS + var illMessage iso18626.ISO18626Message err = xml.Unmarshal(byteReq, &illMessage) if err != nil { http.Error(w, "unmarshal: "+err.Error(), http.StatusBadRequest) diff --git a/iso18626/Makefile b/iso18626/Makefile index 6101fb28..62cbdb2b 100644 --- a/iso18626/Makefile +++ b/iso18626/Makefile @@ -15,13 +15,15 @@ generate: generate-schema generate-schema: $(GEN_SCHEMA_OUT) $(GEN_SCHEMA_OUT): $(GEN_SCHEMA_IN) - $(GO) run github.com/indexdata/xsd2goxsl@v1.4.0 $(GEN_SCHEMA_IN) $(GEN_SCHEMA_OUT) \ + $(GO) run github.com/indexdata/xsd2goxsl@v1.5.1 $(GEN_SCHEMA_IN) $(GEN_SCHEMA_OUT) \ 'qAttrImport=utils "github.com/indexdata/go-utils/utils"' \ - qAttrType=utils.PrefixAttr \ dateTimeType=utils.XSDDateTime \ decimalType=utils.XSDDecimal \ json=yes \ - validate=yes + validate=yes \ + namespaced=yes \ + root=ISO18626Message \ + schemaLocation=http://illtransactions.org/schemas/ISO-18626-v1_2.xsd $(GO) fmt $(GEN_SCHEMA_OUT) clean: diff --git a/iso18626/models_ns.go b/iso18626/models_ns.go index 95a582e4..364d2a08 100644 --- a/iso18626/models_ns.go +++ b/iso18626/models_ns.go @@ -1,39 +1,12 @@ package iso18626 -import ( - "fmt" +import "encoding/xml" - utils "github.com/indexdata/go-utils/utils" -) - -const IllNs = "http://illtransactions.org/2013/iso18626" -const XsiNs = "http://www.w3.org/2001/XMLSchema-instance" -const IllSl = "http://illtransactions.org/schemas/ISO-18626-v1_2.xsd" const IllV1_2 = "1.2" -func InitNs() { - utils.NSDefault(IllNs) - utils.NSPrefix("ill", IllNs) - utils.NSPrefix("xsi", XsiNs) - utils.AttrDefault("schemaLocation", fmt.Sprintf("%s %s", IllNs, IllSl)) - utils.AttrDefault("version", IllV1_2) -} - -type Iso18626MessageNS struct { - Namespace *utils.PrefixAttr `xml:"xmlns,attr" json:"@xmlns,omitempty"` - ISO18626Message - NsIllPx *utils.PrefixAttr `xml:"xmlns ill,attr" json:"@xmlns:ill,omitempty"` - NsXsiPx *utils.PrefixAttr `xml:"xmlns xsi,attr" json:"@xmlns:xsi,omitempty"` - XsiSchemaLoc *utils.PrefixAttr `xml:"http://www.w3.org/2001/XMLSchema-instance schemaLocation,attr" json:"@xsi:schemaLocation,omitempty"` -} - -func NewIso18626MessageNS() *Iso18626MessageNS { - InitNs() - msg := Iso18626MessageNS{} - msg.Namespace = utils.NewPrefixAttr("xmlns", IllNs) - msg.NsIllPx = utils.NewPrefixAttrNS("xmlns", "ill", IllNs) - msg.NsXsiPx = utils.NewPrefixAttrNS("xmlns", "xsi", XsiNs) - msg.XsiSchemaLoc = utils.NewPrefixAttrNS(XsiNs, "schemaLocation", fmt.Sprintf("%s %s", IllNs, IllSl)) - msg.Version = *utils.NewPrefixAttrNS(IllNs, "version", IllV1_2) +func NewISO18626Message() *ISO18626Message { + msg := ISO18626Message{} + msg.XMLName = xml.Name{Space: TARGET_NAMESPACE, Local: "ISO18626Message"} + msg.Version = IllV1_2 return &msg } diff --git a/iso18626/models_ns_test.go b/iso18626/models_ns_test.go index ced8fbb2..f771a15b 100644 --- a/iso18626/models_ns_test.go +++ b/iso18626/models_ns_test.go @@ -11,47 +11,45 @@ import ( utils "github.com/indexdata/go-utils/utils" ) -func TestIso18626MessageNSMarshalUnmarshal(t *testing.T) { - msg := NewIso18626MessageNS() +const IllNs = "http://illtransactions.org/2013/iso18626" +const XsiNs = "http://www.w3.org/2001/XMLSchema-instance" +const IllSl = "http://illtransactions.org/schemas/ISO-18626-v1_2.xsd" + +func TestISO18626MessageMarshalUnmarshal(t *testing.T) { + msg := NewISO18626Message() buf, err := xml.Marshal(msg) if err != nil { t.Fatalf("marshal failed: %v", err) } - expected := fmt.Sprintf( - ``, - IllNs, IllV1_2, IllNs, XsiNs, IllNs, IllSl, - ) - if diff := diffXML(expected, string(buf)); diff != "" { - t.Fatalf("marshal output differs from sample XML (-sample +actual):\n%s", diff) + xmlText := string(buf) + required := []string{ + ` - + toAgency @@ -14,4 +14,4 @@ 2025-10-06T11:14:00.592Z - \ No newline at end of file + From c0a8f9581e43544fe454d14b340e7ede6475d64c Mon Sep 17 00:00:00 2001 From: Jakub Skoczen Date: Thu, 9 Apr 2026 15:15:11 +0200 Subject: [PATCH 2/3] Cleanup --- iso18626/models_ns_test.go | 34 ---------------------------------- 1 file changed, 34 deletions(-) diff --git a/iso18626/models_ns_test.go b/iso18626/models_ns_test.go index f771a15b..4dc12b5a 100644 --- a/iso18626/models_ns_test.go +++ b/iso18626/models_ns_test.go @@ -3,7 +3,6 @@ package iso18626 import ( "encoding/json" "encoding/xml" - "fmt" "strings" "testing" "time" @@ -136,36 +135,3 @@ func TestISO18626MessageMarshalAfterJSONRoundtrip(t *testing.T) { t.Fatalf("unexpected serviceLevel scheme value: %+v", scheme) } } - -func diffXML(sampleXML, actualXML string) string { - if sampleXML == actualXML { - return "" - } - return lineDiff(sampleXML, actualXML) -} - -func lineDiff(sampleXML, actualXML string) string { - sampleLines := strings.Split(sampleXML, "\n") - actualLines := strings.Split(actualXML, "\n") - maxLines := len(sampleLines) - if len(actualLines) > maxLines { - maxLines = len(actualLines) - } - - var b strings.Builder - b.WriteString("--- sample\n+++ actual\n") - for i := 0; i < maxLines; i++ { - var s, a string - if i < len(sampleLines) { - s = sampleLines[i] - } - if i < len(actualLines) { - a = actualLines[i] - } - if s == a { - continue - } - fmt.Fprintf(&b, "-%d %s\n+%d %s\n", i+1, s, i+1, a) - } - return strings.TrimRight(b.String(), "\n") -} From 5e4e09019d17f4400dc54fecd3912a06a772dd58 Mon Sep 17 00:00:00 2001 From: Jakub Skoczen Date: Thu, 9 Apr 2026 16:15:30 +0200 Subject: [PATCH 3/3] Use ROOT_TAG const --- iso18626/Makefile | 2 +- iso18626/models_ns.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/iso18626/Makefile b/iso18626/Makefile index 62cbdb2b..bcff2571 100644 --- a/iso18626/Makefile +++ b/iso18626/Makefile @@ -15,7 +15,7 @@ generate: generate-schema generate-schema: $(GEN_SCHEMA_OUT) $(GEN_SCHEMA_OUT): $(GEN_SCHEMA_IN) - $(GO) run github.com/indexdata/xsd2goxsl@v1.5.1 $(GEN_SCHEMA_IN) $(GEN_SCHEMA_OUT) \ + $(GO) run github.com/indexdata/xsd2goxsl@v1.6.0 $(GEN_SCHEMA_IN) $(GEN_SCHEMA_OUT) \ 'qAttrImport=utils "github.com/indexdata/go-utils/utils"' \ dateTimeType=utils.XSDDateTime \ decimalType=utils.XSDDecimal \ diff --git a/iso18626/models_ns.go b/iso18626/models_ns.go index 364d2a08..ccc68033 100644 --- a/iso18626/models_ns.go +++ b/iso18626/models_ns.go @@ -6,7 +6,7 @@ const IllV1_2 = "1.2" func NewISO18626Message() *ISO18626Message { msg := ISO18626Message{} - msg.XMLName = xml.Name{Space: TARGET_NAMESPACE, Local: "ISO18626Message"} + msg.XMLName = xml.Name{Space: TARGET_NAMESPACE, Local: ROOT_TAG} msg.Version = IllV1_2 return &msg }