-
Notifications
You must be signed in to change notification settings - Fork 0
#202 Registrere meldingsdetaljer for innkommende meldinger #135
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,107 @@ | ||
| package no.nav.emottak.ebms.util | ||
|
|
||
| import no.nav.emottak.ebms.log | ||
| import no.nav.emottak.message.model.EbMSDocument | ||
| import no.nav.emottak.message.model.PartyId | ||
| import no.nav.emottak.utils.common.parseOrGenerateUuid | ||
| import no.nav.emottak.utils.kafka.model.EbmsMessageDetails | ||
| import no.nav.emottak.utils.kafka.model.Event | ||
| import no.nav.emottak.utils.kafka.model.EventType | ||
| import no.nav.emottak.utils.kafka.service.EventLoggingService | ||
|
|
||
| interface EventRegistrationService { | ||
| suspend fun registerEvent( | ||
| eventType: EventType, | ||
| ebMSDocument: EbMSDocument, | ||
| eventData: String = "{}" | ||
| ) | ||
|
|
||
| suspend fun registerEventMessageDetails(ebMSDocument: EbMSDocument) | ||
|
|
||
| companion object { | ||
| fun serializePartyId(partyIDs: List<PartyId>): String { | ||
| val partyId = partyIDs.firstOrNull { it.type == "orgnummer" } | ||
| ?: partyIDs.firstOrNull { it.type == "HER" } | ||
| ?: partyIDs.firstOrNull { it.type == "ENH" } | ||
| ?: partyIDs.first() | ||
|
|
||
| return "${partyId.type}:${partyId.value}" | ||
| } | ||
| } | ||
| } | ||
|
|
||
| class EventRegistrationServiceImpl( | ||
| private val eventLoggingService: EventLoggingService | ||
| ) : EventRegistrationService { | ||
| override suspend fun registerEvent( | ||
| eventType: EventType, | ||
| ebMSDocument: EbMSDocument, | ||
| eventData: String | ||
| ) { | ||
| log.debug("Registering event for requestId: ${ebMSDocument.requestId}") | ||
|
|
||
| try { | ||
| val requestId = ebMSDocument.requestId.parseOrGenerateUuid() | ||
|
|
||
| val event = Event( | ||
| eventType = eventType, | ||
| requestId = requestId, | ||
| contentId = "", | ||
| messageId = ebMSDocument.transform().messageId, | ||
| eventData = eventData | ||
| ) | ||
| log.debug("Event reg. test: Publishing event: $event") | ||
|
|
||
| eventLoggingService.logEvent(event) | ||
| log.debug("Event reg. test: Event published successfully") | ||
| } catch (e: Exception) { | ||
| log.error("Event reg. test: Error while registering event: ${e.message}", e) | ||
| } | ||
| } | ||
|
|
||
| override suspend fun registerEventMessageDetails(ebMSDocument: EbMSDocument) { | ||
| log.debug("Registering message with requestId: ${ebMSDocument.requestId}") | ||
|
|
||
| try { | ||
| val ebmsMessage = ebMSDocument.transform() | ||
| val requestId = ebmsMessage.requestId.parseOrGenerateUuid() | ||
|
|
||
| val ebmsMessageDetails = EbmsMessageDetails( | ||
| requestId = requestId, | ||
| cpaId = ebmsMessage.cpaId, | ||
| conversationId = ebmsMessage.conversationId, | ||
| messageId = ebmsMessage.messageId, | ||
| refToMessageId = ebmsMessage.refToMessageId, | ||
| fromPartyId = EventRegistrationService.serializePartyId(ebmsMessage.addressing.from.partyId), | ||
| fromRole = ebmsMessage.addressing.from.role, | ||
| toPartyId = EventRegistrationService.serializePartyId(ebmsMessage.addressing.to.partyId), | ||
| toRole = ebmsMessage.addressing.to.role, | ||
| service = ebmsMessage.addressing.service, | ||
| action = ebmsMessage.addressing.action, | ||
| refParam = null, | ||
| sender = null, | ||
| sentAt = ebmsMessage.sentAt | ||
| ) | ||
| log.debug("Publishing message details: $ebmsMessageDetails") | ||
|
|
||
| eventLoggingService.logMessageDetails(ebmsMessageDetails) | ||
| log.debug("Message details published successfully") | ||
| } catch (e: Exception) { | ||
| log.error("Error while registering message details: ${e.message}", e) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| class EventRegistrationServiceFake : EventRegistrationService { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Litt nitpicky, men navngivningen bør være Her kan du også implementere dette som en funksjon som beskrevet ovenfor. Du får da:
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hvordan er
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. MyService, FooService, BarService er jo typisk et pattern vi vil følge.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hvorfor har vi slike viljer?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hva mener du ? Dette er helt STANDARD navngivning.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hver gang når jeg prøvde å bruke noe standard i eMottak, så fikk jeg avslag og flere klager fordi
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Kort fortalt så ser det litt rart ut. Hvis det hadde vært konsistent, dvs ALLE service-implementasjoner hadde blitt post-fixet med implementasjon, ala: MyServiceFoo, MyServiceBar, MyServiceFake hadde det hvertfall vært gjennomført og konsistent.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Og det er akkurat slik akkurat nå.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Det ser fortsatt rart ut og
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Takk for at du er konstruktiv! 🙌 |
||
| override suspend fun registerEvent( | ||
| eventType: EventType, | ||
| ebMSDocument: EbMSDocument, | ||
| eventData: String | ||
| ) { | ||
| log.debug("Registering event $eventType for ebMSDocument: $ebMSDocument and eventData: $eventData") | ||
| } | ||
|
|
||
| override suspend fun registerEventMessageDetails(ebMSDocument: EbMSDocument) { | ||
| log.debug("Registering message details for ebMSDocument: $ebMSDocument") | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.