Skip to content

Commit

Permalink
fixup! feat: rename partnerUrl parameter to partnerId in search metho…
Browse files Browse the repository at this point in the history
…d to allow the usage of another field as identifier
  • Loading branch information
DeborahPereira4sh committed Sep 12, 2024
1 parent 1442cae commit 478385c
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,14 @@ interface PartnerRepository {
*/
suspend fun isCredentialsServerTokenValid(credentialsServerToken: String): Boolean

/**
* Used to find a partner url by its identifier.
*
* @param partnerId, identifies uniquely the partner
* @return the partner url
*/
suspend fun getPartnerUrl(partnerId: String): String?

/**
* Used to find a partner url by its server token. Basically used to retrieve all the partner information
* from the token in a request.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import com.izivia.ocpi.toolkit.transport.TransportClientBuilder
* @property clientPartnerRepository client's repository to store and retrieve tokens and information about partners
* @property clientVersionsRepository client's repository to retrieve available versions on the client
* @property clientCredentialsRoleRepository client's repository to retrieve its role
* @property serverVersionsEndpointUrl the versions endpoint url of the server (for the client to retrieve endpoints)
* @property partnerId a value that identifies uniquely the partner
* @property transportClientBuilder used to build a transport (will be used to create CredentialClient to make calls)
* @property requiredEndpoints the endpoints this client expects from the other part to provide
Expand All @@ -36,7 +35,6 @@ open class CredentialsClientService(
private val clientPartnerRepository: PartnerRepository,
private val clientVersionsRepository: VersionsRepository,
private val clientCredentialsRoleRepository: CredentialsRoleRepository,
private val serverVersionsEndpointUrl: String,
private val partnerId: String,
private val transportClientBuilder: TransportClientBuilder,
private val requiredEndpoints: RequiredEndpoints?
Expand Down Expand Up @@ -196,7 +194,6 @@ open class CredentialsClientService(
private suspend fun findLatestMutualVersionAndSaveInformation(): List<Endpoint> {
val availableServerVersions = VersionsClient(
transportClientBuilder = transportClientBuilder,
serverVersionsEndpointUrl = serverVersionsEndpointUrl,
partnerId = partnerId,
partnerRepository = clientPartnerRepository
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,6 @@ open class CredentialsServerService(
// A partner can use a valid serverToken on registration.
// It can happen when a partner unregister, then registers with its clientToken (which is the serverToken
// for us)
partnerRepository.getPartnerUrlByCredentialsServerToken(token)
// If we could not find a partner with this serverToken, then, it means that it's probably a tokenA
?: partnerRepository.savePartnerUrlForTokenA(tokenA = token, partnerUrl = credentials.url)
?: throw OcpiClientInvalidParametersException(
"Invalid token ($token) - should be either a TokenA or a ServerToken"
)
val partnerId = partnerRepository.getPartnerIdByCredentialsServerToken(token)
// If we could not find a partner with this serverToken, then, it means that it's probably a tokenA
?: partnerRepository.getPartnerIdByCredentialsTokenA(credentialsTokenA = token)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,23 @@ import com.izivia.ocpi.toolkit.transport.domain.*
/**
* Used to get the versions of a partner
* @property transportClientBuilder used to build transport client
* @property serverVersionsEndpointUrl used to know which partner to communicate with
* @property partnerId used to know which partner to communicate with
* @property partnerRepository used to get information about the partner (token)
*/
class VersionsClient(
private val transportClientBuilder: TransportClientBuilder,
private val serverVersionsEndpointUrl: String,
private val partnerId: String,
private val partnerRepository: PartnerRepository
) : VersionsInterface {

override suspend fun getVersions(): OcpiResponseBody<List<Version>> =
with(
transportClientBuilder
.build(baseUrl = serverVersionsEndpointUrl)
.build(
baseUrl = partnerRepository
.getPartnerUrl(partnerId = partnerId)
?: throw OcpiToolkitUnknownEndpointException("version with no url")
)
) {
send(
HttpRequest(method = HttpMethod.GET)
Expand All @@ -43,7 +46,7 @@ class VersionsClient(
this.parseBody<OcpiResponseBody<List<Version>>>()
}
.onFailure {
throw OcpiToolkitResponseParsingException(serverVersionsEndpointUrl, it)
throw OcpiToolkitResponseParsingException(partnerId, it)
}
.getOrThrow()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ class DummyPartnerCacheRepository : PartnerCacheRepository() {
override suspend fun isCredentialsServerTokenValid(credentialsServerToken: String): Boolean =
true

override suspend fun getPartnerUrl(partnerId: String): String = partnerId

override suspend fun getCredentialsClientToken(partnerId: String): String =
"*"
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ open class PartnerCacheRepository : PartnerRepository {
override suspend fun isCredentialsServerTokenValid(credentialsServerToken: String): Boolean = partners
.any { it.serverToken == credentialsServerToken }

override suspend fun getPartnerUrl(partnerId: String): String? = partners
.firstOrNull { it.url == partnerId }?.url

override suspend fun getPartnerUrlByCredentialsServerToken(credentialsServerToken: String): String? = partners
.firstOrNull { it.serverToken == credentialsServerToken }?.url

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ fun main() {
)
)
},
serverVersionsEndpointUrl = receiverVersionsUrl,
partnerId = receiverVersionsUrl,
transportClientBuilder = Http4kTransportClientBuilder(),
requiredEndpoints = RequiredEndpoints(receiver = listOf(ModuleID.credentials))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@ class CredentialsIntegrationTests : BaseServerIntegrationTest() {
)
)
},
serverVersionsEndpointUrl = receiverServerSetupResult.versionsEndpoint,
partnerId = receiverServerSetupResult.versionsEndpoint,
transportClientBuilder = Http4kTransportClientBuilder(),
requiredEndpoints = requiredEndpoints
Expand Down Expand Up @@ -223,7 +222,6 @@ class CredentialsIntegrationTests : BaseServerIntegrationTest() {

val versionsClient = VersionsClient(
transportClientBuilder = Http4kTransportClientBuilder(),
serverVersionsEndpointUrl = receiverServer.versionsEndpoint,
partnerId = receiverServer.versionsEndpoint,
partnerRepository = PartnerMongoRepository(collection = senderServer.partnerCollection)
)
Expand Down Expand Up @@ -447,7 +445,6 @@ class CredentialsIntegrationTests : BaseServerIntegrationTest() {

val versionsClient = VersionsClient(
transportClientBuilder = Http4kTransportClientBuilder(),
serverVersionsEndpointUrl = receiverServer.versionsEndpoint,
partnerId = receiverServer.versionsEndpoint,
partnerRepository = PartnerMongoRepository(collection = senderServer.partnerCollection)
)
Expand Down Expand Up @@ -498,13 +495,11 @@ class CredentialsIntegrationTests : BaseServerIntegrationTest() {

val senderVersionsClient = VersionsClient(
transportClientBuilder = Http4kTransportClientBuilder(),
serverVersionsEndpointUrl = receiverServer.versionsEndpoint,
partnerId = receiverServer.versionsEndpoint,
partnerRepository = PartnerMongoRepository(collection = senderServer.partnerCollection)
)
val receiverVersionsClient = VersionsClient(
transportClientBuilder = Http4kTransportClientBuilder(),
serverVersionsEndpointUrl = senderServer.versionsEndpoint,
partnerId = senderServer.versionsEndpoint,
partnerRepository = PartnerMongoRepository(collection = receiverServer.partnerCollection)
)
Expand Down Expand Up @@ -617,13 +612,11 @@ class CredentialsIntegrationTests : BaseServerIntegrationTest() {

val senderVersionsClient = VersionsClient(
transportClientBuilder = Http4kTransportClientBuilder(),
serverVersionsEndpointUrl = receiverServer.versionsEndpoint,
partnerId = receiverServer.versionsEndpoint,
partnerRepository = PartnerMongoRepository(collection = senderServer.partnerCollection)
)
val receiverVersionsClient = VersionsClient(
transportClientBuilder = Http4kTransportClientBuilder(),
serverVersionsEndpointUrl = senderServer.versionsEndpoint,
partnerId = senderServer.versionsEndpoint,
partnerRepository = PartnerMongoRepository(collection = receiverServer.partnerCollection)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ class PartnerMongoRepository(
override suspend fun isCredentialsServerTokenValid(credentialsServerToken: String): Boolean = collection
.findOne(Partner::serverToken eq credentialsServerToken) != null

override suspend fun getPartnerUrl(partnerId: String): String? = collection
.findOne(Partner::url eq partnerId)?.url

override suspend fun getPartnerUrlByCredentialsServerToken(credentialsServerToken: String): String? = collection
.findOne(Partner::serverToken eq credentialsServerToken)?.url

Expand Down

0 comments on commit 478385c

Please sign in to comment.