-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…-to-headers feat(common) #62: Message routing headers
- Loading branch information
Showing
6 changed files
with
213 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
....1/src/main/kotlin/com/izivia/ocpi/toolkit/common/context/RequestMessageRoutingHeaders.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package com.izivia.ocpi.toolkit.common.context | ||
|
||
import kotlin.coroutines.AbstractCoroutineContextElement | ||
import kotlin.coroutines.CoroutineContext | ||
import kotlin.coroutines.coroutineContext | ||
|
||
/** | ||
* Contains context about the current MessageRoutingHeaders | ||
*/ | ||
data class RequestMessageRoutingHeaders( | ||
val toPartyId: String? = null, | ||
val toCountryCode: String? = null, | ||
val fromPartyId: String? = null, | ||
val fromCountryCode: String? = null | ||
) : AbstractCoroutineContextElement(RequestMessageRoutingHeaders) { | ||
companion object Key : CoroutineContext.Key<RequestMessageRoutingHeaders> | ||
} | ||
|
||
/** | ||
* Retrieves MessageRoutingHeaders in the current coroutine if it is found. | ||
*/ | ||
suspend fun currentRequestMessageRoutingHeadersOrNull(): RequestMessageRoutingHeaders? = | ||
coroutineContext[RequestMessageRoutingHeaders] | ||
|
||
/** | ||
* Retrieves MessageRoutingHeaders in the current coroutine, and throws IllegalStateException | ||
* if it could not be found. | ||
*/ | ||
suspend fun currentRequestMessageRoutingHeaders(): RequestMessageRoutingHeaders = | ||
coroutineContext[RequestMessageRoutingHeaders] | ||
?: throw IllegalStateException("No MessageRoutingHeaders object in current coroutine context") |
43 changes: 43 additions & 0 deletions
43
...1/src/main/kotlin/com/izivia/ocpi/toolkit/common/context/ResponseMessageRoutingHeaders.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package com.izivia.ocpi.toolkit.common.context | ||
|
||
import kotlin.coroutines.AbstractCoroutineContextElement | ||
import kotlin.coroutines.CoroutineContext | ||
import kotlin.coroutines.coroutineContext | ||
|
||
/** | ||
* Contains context about the current MessageRoutingHeaders | ||
*/ | ||
data class ResponseMessageRoutingHeaders( | ||
var toPartyId: String? = null, | ||
var toCountryCode: String? = null, | ||
var fromPartyId: String? = null, | ||
var fromCountryCode: String? = null | ||
) : AbstractCoroutineContextElement(ResponseMessageRoutingHeaders) { | ||
companion object Key : CoroutineContext.Key<ResponseMessageRoutingHeaders> { | ||
/** | ||
* Creates [ResponseMessageRoutingHeaders] by inverting "from" and "to" headers of | ||
* the [RequestMessageRoutingHeaders]. | ||
*/ | ||
fun invertFromRequest(requestMessageRoutingHeaders: RequestMessageRoutingHeaders) = | ||
ResponseMessageRoutingHeaders( | ||
toPartyId = requestMessageRoutingHeaders.fromPartyId, | ||
toCountryCode = requestMessageRoutingHeaders.fromCountryCode, | ||
fromPartyId = requestMessageRoutingHeaders.toPartyId, | ||
fromCountryCode = requestMessageRoutingHeaders.toCountryCode | ||
) | ||
} | ||
} | ||
|
||
/** | ||
* Retrieves MessageRoutingHeaders in the current coroutine if it is found. | ||
*/ | ||
suspend fun currentResponseMessageRoutingHeadersOrNull(): ResponseMessageRoutingHeaders? = | ||
coroutineContext[ResponseMessageRoutingHeaders] | ||
|
||
/** | ||
* Retrieves MessageRoutingHeaders in the current coroutine, and throws IllegalStateException | ||
* if it could not be found. | ||
*/ | ||
suspend fun currentResponseMessageRoutingHeaders(): ResponseMessageRoutingHeaders = | ||
coroutineContext[ResponseMessageRoutingHeaders] | ||
?: throw IllegalStateException("No MessageRoutingHeaders object in current coroutine context") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters