diff --git a/.editorconfig b/.editorconfig index 305ee89f..996b5df0 100644 --- a/.editorconfig +++ b/.editorconfig @@ -1023,7 +1023,9 @@ ij_groovy_while_on_new_line = false ij_groovy_wrap_long_lines = false [{*.gradle.kts,*.kt,*.kts,*.main.kts}] -ktlint_disabled_rules = no-wildcard-imports, package-name, filename +ktlint_standard_no-wildcard-imports = disabled +ktlint_standard_filename = disabled +ktlint_standard_enum-entry-name-case = disabled ij_kotlin_align_in_columns_case_branch = false ij_kotlin_align_multiline_binary_operation = false ij_kotlin_align_multiline_extends_list = false diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2357dbed..828af19e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -26,16 +26,15 @@ jobs: - name: Checkout IZIVIA OCPI toolkit library code from GH uses: actions/checkout@v3 - - name: Publish annotation processor to maven local - uses: gradle/gradle-build-action@v2.8.1 + - name: Setup gradle action + uses: gradle/gradle-build-action@v2.10.0 with: gradle-version: wrapper - arguments: :annotation-processor:publishToMavenLocal - cache-read-only: ${{ github.ref != 'refs/heads/develop' && github.ref != 'refs/heads/main' }} + cache-read-only: ${{ github.ref != 'refs/heads/main' }} + gradle-home-cache-cleanup: true + + - name: Ktlint check OCPI toolkit + run: ./gradlew ktlintCheck - name: Build OCPI toolkit - uses: gradle/gradle-build-action@v2.8.1 - with: - gradle-version: wrapper - arguments: build - cache-read-only: ${{ github.ref != 'refs/heads/develop' && github.ref != 'refs/heads/main' }} + run: ./gradlew build diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index bc0e6ab2..e6b078cc 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -25,24 +25,18 @@ jobs: - name: Checkout IZIVIA OCPI toolkit library code from GH uses: actions/checkout@v3 - - name: Publish OCPI annotation processor to maven local - uses: gradle/gradle-build-action@v2.8.1 - env: - VERSION: ${{ github.ref }} + - name: Setup gradle action + uses: gradle/gradle-build-action@v2.10.0 with: gradle-version: wrapper - arguments: :annotation-processor:publishToMavenLocal - cache-read-only: ${{ github.ref != 'refs/heads/develop' && github.ref != 'refs/heads/main' }} + cache-read-only: ${{ github.ref != 'refs/heads/main' }} + gradle-home-cache-cleanup: true - name: Build OCPI toolkit - uses: gradle/gradle-build-action@v2.8.1 env: VERSION: ${{ github.ref }} SONATYPE_USERNAME: ${{ secrets.DELIVERY_SONATYPE_USERNAME }} SONATYPE_PASSWORD: ${{ secrets.DELIVERY_SONATYPE_PASSWORD }} GPG_PRIVATE_KEY: ${{ secrets.DELIVERY_GPG_SECRET_KEY }} GPG_PASSPHRASE: ${{ secrets.DELIVERY_GPG_KEY_PASSPHRASE }} - with: - gradle-version: wrapper - arguments: publishToSonatype closeAndReleaseSonatypeStagingRepository - cache-read-only: ${{ github.ref != 'refs/heads/develop' && github.ref != 'refs/heads/main' }} + run: ./gradlew publishToSonatype closeAndReleaseSonatypeStagingRepository diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 00000000..751dbb60 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,94 @@ +# Contributing + +First off, thanks for taking the time to contribute! + +All types of contributions are encouraged and valued. +Please make sure to read the relevant section before +making your contribution. + +> And if you like the project, but just don't have time +> to contribute, that's fine. There are other easy ways +> to support the project and show your appreciation, +> which we would also be very happy about: +> - Tweet about it +> - Refer this project in your project's readme +> - Mention the project at local meetups and tell your +> friends/colleagues + +## Code of Conduct + +Be kind + +## I Have a Question + +Before you ask a question, it is best to search for +existing [Issues](/issues) that might help you. In case +you have found a suitable issue and still need clarification, +you can write your question in this issue. + +If you then still feel the need to ask a question and need +clarification, we recommend the following: + +- Open an [Issue](/issues/new). +- Provide as much context as you can about what you're running +into. + +We will then take care of the issue as soon as possible. + +## I want to suggest an enhancement + +Enhancement suggestions are tracked as [GitHub issues](/issues). + +- Open an [Issue](/issues/new). +- Use a **clear and descriptive title** for the issue to +identify the suggestion. +- Provide a **step-by-step description of the suggested enhancement** +in as many details as possible. +- **Describe the current behavior** and **explain which behavior you +expected to see instead** and why. At this point you can also tell +which alternatives do not work for you. + +## I found a bug + +You must never report security related issues, vulnerabilities +or bugs including sensitive information to the issue tracker, +or elsewhere in public. Instead sensitive bugs must be sent by +email to `lilian@gallon.dev`. + +- Open an [Issue](/issues/new). (Since we can't be sure at this +point whether it is a bug or not, we ask you not to talk about a +bug yet and not to label the issue.) +- Explain the behavior you would expect and the actual behavior. +- Please provide as much context as possible and describe the +*reproduction steps* that someone else can follow to recreate the +issue on their own. This usually includes your code. For good bug +reports you should isolate the problem and create a reduced test +case. +- Provide the information you collected in the previous section. + +## I Want To Contribute + +When contributing to this project, you must agree that you +have authored 100% of the content, that you have the necessary +rights to the content and that the content you contribute may +be provided under the project license. + +**Commits:** + +Please follow this format: + +``` +feat|fix|chore|doc(impact) #issueId: small description +``` + +Examples: +- `feat(credentials) #1: implemented /POST endpoint` +- `fix(versions) #2: /GET endpoint not returning the correct versions` +- `doc(readme) #3: updated code examples with last changes` +- `doc(contributing): init CONTRIBUTING.md` + +**Code style:** + +Code style is enforced by ktlint. You can run `./gradlew ktlintCheck` +to make sure your code follows our code style. The CI will check this +anyway. diff --git a/README.md b/README.md index 09523eee..ef942d76 100644 --- a/README.md +++ b/README.md @@ -1,18 +1,19 @@ # Ocpi Toolkit -[![OCPI CI](https://github.com/IZIVIA/ocpi-toolkit/actions/workflows/ci.yml/badge.svg)](https://github.com/IZIVIA/ocpi-toolkit/actions/workflows/ci.yml) +![CI](https://img.shields.io/github/actions/workflow/status/izivia/ocpi-toolkit/ci.yml?style=for-the-badge) ![Latest Release](https://img.shields.io/github/v/tag/izivia/ocpi-toolkit?style=for-the-badge&label=latest%20version) -Open Charge Point Interface (OCPI) java / kotlin library +Open Charge Point Interface (OCPI) kotlin library. + +> ⚠️ Currently in active development. Not ready for production yet. See https://github.com/IZIVIA/ocpi-toolkit/issues/33 for details. ## Setup In your `build.gradle.kts`, add: + ```kts dependencies { - implementation("com.izivia:ocpi-2-2-1:0.0.13") - implementation("com.izivia:ocpi-transport:0.0.13") - - // ... other dependencies + implementation("com.izivia:ocpi-2-2-1:0.0.15") + implementation("com.izivia:ocpi-transport:0.0.15") } ``` @@ -20,31 +21,34 @@ To see all available artifacts, go to: https://central.sonatype.com/search?names ## Usage +**You have the following updated code samples in [ocpi-toolkit-2.2.1/src/test](https://github.com/IZIVIA/ocpi-toolkit/tree/main/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/samples).** + ### Server (CPO or eMSP) Examples: - [Http4kTransportServer](ocpi-toolkit-2.1.1/src/test/kotlin/com/izivia/ocpi/toolkit/samples/common/Http4kTransportServer.kt): `TransportServer` implementation example -- [PlatformMongoRepository](ocpi-toolkit-2.1.1/src/test/kotlin/com/izivia/ocpi/toolkit/tests/integration/mock/PlatformMongoRepository.kt): `PlatformRepository` implementation example +- [PartnerMongoRepository](ocpi-toolkit-2.1.1/src/test/kotlin/com/izivia/ocpi/toolkit/tests/integration/mock/PartnerMongoRepository.kt): `PartnerRepository` implementation example - [VersionsCacheRepository](ocpi-toolkit-2.1.1/src/test/kotlin/com/izivia/ocpi/toolkit/samples/common/VersionsCacheRepository.kt): `VersionsRepository` implementation example - [VersionDetailsCacheRepository](ocpi-toolkit-2.1.1/src/test/kotlin/com/izivia/ocpi/toolkit/samples/common/VersionDetailsCacheRepository.kt): `VersionsDetailsRepository` implementation example **Common code (CPO / eMSP):** ```kotlin +// PartnerMongoRepository is an implementation of PartnerRepository using mongo +// It will be used to store information about partners with whom the server is communicating: +// A partner has: Tokens (A, serverToken, clientToken), Endpoints, Versions, Roles +// You can see an example in the list above +val partnerRepository = PartnerMongoRepository( + collection = mongoDatabase.getCollection(config.partnerCollection) +) + // Http4kTransportServer is an implementation of TransportServer using htt4k. You have to code your own implementation. // It defines the HTTP server, and how to handle requests. // You can see an example in the list above val server = Http4kTransportServer( baseUrl = config.baseUrl, // Example: http://localhost:8080, only used for pagination - port = config.port // Example: 8080, used to know on which port the server will run -) - -// PlatformMongoRepository is an implementation of PlatformRepository using mongo -// It will be used to store information about platforms with whom the server is communicating: -// A platform has: Tokens (A, B, C), Endpoints, Versions -// You can see an example in the list above -val platformRepository = PlatformMongoRepository( - collection = mongoDatabase.getCollection(config.platformCollection) + port = config.port, // Example: 8080, used to know on which port the server will run + secureFilter = senderPartnerRepository::checkToken // The filter called on secured routes ) // VersionsCacheRepository is an implementation of VersionsRepository @@ -59,34 +63,27 @@ val versionDetailsRepository = VersionDetailsCacheRepository() // Required: defines /versions endpoint VersionsServer( - transportServer = server, - platformRepository = platformRepository, validationService = VersionsValidationService( repository = versionsRepository ) -) +).registerOn(server) // Required: defines /2.1.1, /2.2.1, whatever version endpoint VersionDetailsServer( - transportServer = server, - platformRepository = platformRepository, validationService = VersionDetailsValidationService( repository = versionDetailsRepository ) -) +).registerOn(server) // Required: defines /{version}/credentials endpoint for any client to register following OCPI protocol CredentialsServer( - transportServer = server, service = CredentialsServerService( - platformRepository = platformRepository, - serverBusinessDetails = cpoBusinessDetails, - serverPartyId = cpoPartyId, - serverCountryCode = cpoCountryCode, + partnerRepository = partnerRepository, + credentialsRoleRepository = object : CredentialsRoleRepository { ... }, transportClientBuilder = Http4kTransportClientBuilder(), - serverVersionsUrl = versionsUrl + serverVersionsUrl = { versionsUrl } ) -) +).registerOn(server) ``` **CPO code:** @@ -102,8 +99,8 @@ LocationsCpoServer( service = LocationsCpoValidationService( service = locationsService ), - platformRepository = platformRepository -) + partnerRepository = partnerRepository +).registerOn(server) // Once that all the modules are defined, you need to start the server server.start() @@ -119,14 +116,12 @@ val locationsService = LocationsEmspMongoService() // Defines /{version}/locations endpoint for any registered client to retrieve locations (and also create / update / // delete) LocationsEmspServer( - transportServer = server, service = LocationsEmspValidationService( service = LocationsApiClient( channel = chargingInfrastructureChannel ) - ), - platformRepository = platformRepository -) + ) +).registerOn(server) // Once that all the modules are defined, you need to start the server server.start() @@ -138,11 +133,9 @@ It is possible to change the default path of a module using `basePath` argument: ```kotlin LocationsEmspServer( - transportServer = server, service = service, - platformRepository = platformRepository, basePath = "/2.1.1/cpo/locations" -) +).registerOn(server) ``` Make sure that `VersionDetailsRepository` points to the right endpoint (in that case `/2.1.1/cpo/locations`) @@ -165,12 +158,12 @@ Examples: // sender: the one that wants to register // receiver: the one that receives the registration request -// PlatformMongoRepository is an implementation of PlatformRepository using mongo -// It will be used to store information about platforms with whom the client is communicating: -// A platform has: Tokens (A, B, C), Endpoints, Versions +// PartnerMongoRepository is an implementation of PartnerRepository using mongo +// It will be used to store information about partners with whom the client is communicating: +// A partner has: Tokens (A, B, C), Endpoints, Versions // You can see an example in the list above -val senderPlatformRepository = PlatformMongoRepository( - collection = mongoDatabase.getCollection(config.platformCollection) +val senderPartnerRepository = PartnerMongoRepository( + collection = mongoDatabase.getCollection(config.partnerCollection) ) // VersionsCacheRepository is an implementation of VersionsRepository @@ -192,12 +185,10 @@ val receiverVersionsEndpoint = "https://receiver.com/versions" val credentialsClientService = CredentialsClientService( clientVersionsEndpointUrl = senderVersionsEndpint, - clientPlatformRepository = senderPlatformRepository, + partnerRepository = senderPartnerRepository, clientVersionsRepository = senderVersionsRepository, - clientBusinessDetails = BusinessDetails(name = "Sender", website = null, logo = null), - clientPartyId = "ABC", - clientCountryCode = "FR", - serverVersionsEndpointUrl = receiverVersionsEndpoint, + credentialsRoleRepository = object : CredentialsRoleRepository { ... }, + serverVersionsUrlProvider = { receiverVersionsEndpoint }, transportClientBuilder = Http4kTransportClientBuilder() ) @@ -208,12 +199,12 @@ credentialsClientService.register() ```kotlin // Now that the CPO is registered with the eMSP, all the information (tokens & endpoints) is stored in -// platformRepository. It is now possible to access the locations module of the eMSP using LocationsCpoClient. +// partnerRepository. It is now possible to access the locations module of the eMSP using LocationsCpoClient. val locationsCpoClient = LocationsCpoClient( transportClientBuilder = Http4kTransportClientBuilder(), - serverVersionsEndpointUrl = "https://emsp.com/versions", // Used as ID for the platform (to retrieve information) - platformRepository = platformRepository + serverVersionsEndpointUrl = "https://emsp.com/versions", // Used as ID for the partner (to retrieve information) + partnerRepository = partnerRepository ) // Example on how to get a specific location @@ -224,40 +215,14 @@ locationsCpoClient.getLocation(countryCode = "fr", partyId = "abc", locationId = ```kotlin // Now that the eMSP is registered with the CPO, all the information (tokens & endpoints) is stored in -// platformRepository. It is now possible to access the locations module of the CPO using LocationsEmspClient. +// partnerRepository. It is now possible to access the locations module of the CPO using LocationsEmspClient. val locationsEmspClient = LocationsEmspClient( transportClientBuilder = Http4kTransportClientBuilder(), serverVersionsEndpointUrl = "https://cpo.com/versions", - platformRepository = platformRepository + partnerRepository = partnerRepository ) // Example on how to get a specific location locationsEmspClient.getLocation(locationId = "location1") ``` - -## Differences - -### ocpi-lib-2.1.1 -> ocpi-lib-2.2.1 - -Also see: -- OCPI 2.1.1 -> OCPI 2.2 -> OCPI 2.2.1: [official doc](https://github.com/ocpi/ocpi/blob/2.2.1/changelog.asciidoc#changelog_changelog) - -What actually changed in the lib: - -| Module | Changements | -|-------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| -| Common | - Added hub exceptions
- Added CiString type | -| Versions | - Added V_2_2 and V_2_2_1 in VersionNumber enum
- Added role in Endpoint | -| Credentials | - Credentials object has a list of CredentialRoles instead of only business_details, party_id & country_code. Also added CredentialsRoleRepository for the user to specify the roles of the platform they are implementing. In 2.1.1, the user had to pass business_details, party_id, country_code to CredentialsClientService and CredentialsServerService. | -| Locations | - Too many changements, see [this commit for details](https://github.com/4sh/ocpi-lib/commit/dfbbd8bf2741788582e087a5921b099c07129788) | | - -### ocpi-lib-2.1.1 -> ocpi-lib-2.1.1-gireve - -| Module | Changements | -|-------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| -| Common | nothing changed | -| Versions | - Removed V_2_0 and V_2_1 in VersionNumber enum | -| Credentials | - Removed PUT (the user has to first delete() then register() to update (so token A has to be exchanged outside OCPI protocol between delete and register) | -| Locations | - evse_id is now required (added doc to explain that in Locations object) | -| Tokens | - Too many changements, see [this commit for an insight (things may have changed since then)](https://github.com/4sh/ocpi-lib/commit/4f664247a888dcc475270f92855a191e13b42342) | diff --git a/annotation-processor/build.gradle.kts b/annotation-processor/build.gradle.kts index 73ac3d94..ec15d649 100644 --- a/annotation-processor/build.gradle.kts +++ b/annotation-processor/build.gradle.kts @@ -1,10 +1,10 @@ plugins { - base - `java-library` - kotlin("kapt") + kotlin("jvm") } -kotlinProject() +repositories { + mavenCentral() +} java { withJavadocJar() @@ -22,7 +22,10 @@ publishing { pom { name.set("OCPI Annotation processor") artifactId = "ocpi-annotation-processor" - description.set("This module processes annotations during compilation time in order to generate some code (partial representation, etc ...)") + description.set( + "This module processes annotations during compilation time in order to generate some code " + + "(partial representation, etc ...)" + ) } } } @@ -30,8 +33,9 @@ publishing { dependencies { implementation("com.squareup:kotlinpoet:${Versions.kotlinPoet}") - compileOnly("org.jetbrains.kotlin:kotlin-compiler-embeddable") - implementation("de.jensklingenberg:mpapt-runtime:${Versions.mpapt}") + implementation("com.squareup:kotlinpoet-ksp:${Versions.kotlinPoet}") + implementation("com.google.devtools.ksp:symbol-processing-api:${Versions.ksp}") + implementation(project(":common")) } tasks.build { diff --git a/annotation-processor/src/main/kotlin/com/izivia/ocpi/toolkit/processor/CommonComponentRegistrar.kt b/annotation-processor/src/main/kotlin/com/izivia/ocpi/toolkit/processor/CommonComponentRegistrar.kt deleted file mode 100644 index 5b468b16..00000000 --- a/annotation-processor/src/main/kotlin/com/izivia/ocpi/toolkit/processor/CommonComponentRegistrar.kt +++ /dev/null @@ -1,22 +0,0 @@ -package com.izivia.ocpi.toolkit.processor - -import de.jensklingenberg.mpapt.common.MpAptProject -import org.jetbrains.kotlin.codegen.extensions.ClassBuilderInterceptorExtension -import org.jetbrains.kotlin.com.intellij.mock.MockProject -import org.jetbrains.kotlin.compiler.plugin.ComponentRegistrar -import org.jetbrains.kotlin.compiler.plugin.ExperimentalCompilerApi -import org.jetbrains.kotlin.config.CompilerConfiguration -import org.jetbrains.kotlin.extensions.StorageComponentContainerContributor -import org.jetbrains.kotlin.js.translate.extensions.JsSyntheticTranslateExtension - -@OptIn(ExperimentalCompilerApi::class) -open class CommonComponentRegistrar : ComponentRegistrar { - - override fun registerProjectComponents(project: MockProject, configuration: CompilerConfiguration) { - val processor = PartialAnnotationProcessor() - val apt = MpAptProject(processor, configuration) - StorageComponentContainerContributor.registerExtension(project, apt) - ClassBuilderInterceptorExtension.registerExtension(project, apt) - JsSyntheticTranslateExtension.registerExtension(project, apt) - } -} diff --git a/annotation-processor/src/main/kotlin/com/izivia/ocpi/toolkit/processor/PartialAnnotationProcessor.kt b/annotation-processor/src/main/kotlin/com/izivia/ocpi/toolkit/processor/PartialProcessor.kt similarity index 51% rename from annotation-processor/src/main/kotlin/com/izivia/ocpi/toolkit/processor/PartialAnnotationProcessor.kt rename to annotation-processor/src/main/kotlin/com/izivia/ocpi/toolkit/processor/PartialProcessor.kt index 90f57d15..aab42056 100644 --- a/annotation-processor/src/main/kotlin/com/izivia/ocpi/toolkit/processor/PartialAnnotationProcessor.kt +++ b/annotation-processor/src/main/kotlin/com/izivia/ocpi/toolkit/processor/PartialProcessor.kt @@ -1,50 +1,65 @@ package com.izivia.ocpi.toolkit.processor +import com.google.devtools.ksp.getConstructors +import com.google.devtools.ksp.processing.* +import com.google.devtools.ksp.symbol.* +import com.google.devtools.ksp.validate +import com.izivia.ocpi.toolkit.annotations.Partial import com.squareup.kotlinpoet.* import com.squareup.kotlinpoet.ParameterizedTypeName.Companion.parameterizedBy -import de.jensklingenberg.mpapt.common.canonicalFilePath -import de.jensklingenberg.mpapt.model.* -import org.jetbrains.kotlin.descriptors.ClassDescriptor -import org.jetbrains.kotlin.descriptors.FunctionDescriptor -import org.jetbrains.kotlin.descriptors.containingPackage -import org.jetbrains.kotlin.platform.TargetPlatform -import java.io.File - -class PartialAnnotationProcessor : AbstractProcessor() { - - private val annotationFqdn = "com.izivia.ocpi.toolkit.annotations.Partial" - private val partialClasses: MutableList = mutableListOf() - private val toPartialMethodName = "toPartial" +import com.squareup.kotlinpoet.ksp.writeTo - override fun getSupportedAnnotationTypes(): Set = setOf(annotationFqdn) +class PartialProcessor( + private val codeGenerator: CodeGenerator, + private val logger: KSPLogger +) : SymbolProcessor { - override fun isTargetPlatformSupported(platform: TargetPlatform): Boolean = true + private val toPartialMethodName = "toPartial" + private val partialClasses: MutableList = mutableListOf() - override fun process(roundEnvironment: RoundEnvironment) { - partialClasses.addAll( - roundEnvironment.getElementsAnnotatedWith(annotationFqdn) - .filterIsInstance() - .filter { it.classDescriptor.isData } - .map { it.classDescriptor } - ) + override fun process(resolver: Resolver): List { + // partialClasses.isEmpty() is a hack to make sure process is only called once. + // According to the documentation, ksp supports multiple rounds. And if we want + // multiple rounds, we need to return Symbols that need to be processed in the + // next round. Here as you can see, we return an emptyList, but ksp still calls + // process two times. When called on the second time, it crashes because the files + // are already created. I do not understand how it works, but this workaround does + // the job for now. + if (partialClasses.isEmpty()) { + partialClasses.addAll(resolver.getPartialAnnotatedClasses()) + genPartialClasses(partialClasses.toSet()) + .forEach { (input, output) -> + output.writeTo( + codeGenerator, + Dependencies(true, input.containingFile!!) + ) + } + } + + return emptyList() } - override fun processingOver() { - partialClasses.forEach { classDescriptor -> - val packageName = classDescriptor.containingPackage().toString() - val className = classDescriptor.name.asString() - val classFilePath = classDescriptor.canonicalFilePath().toString() - val classFile = File(classFilePath) + private fun Resolver.getPartialAnnotatedClasses(): Set = + getSymbolsWithAnnotation(Partial::class.qualifiedName.orEmpty()) + .filterIsInstance() + .filter(KSNode::validate) + .toSet() + + private fun genPartialClasses( + partialAnnotatedClasses: Set + ): List> = + partialAnnotatedClasses.map { classDeclaration -> + val packageName = classDeclaration.packageName.asString() + val className = classDeclaration.simpleName.asString() val partialClassName = className.toPartial() - val partialClassType = buildPartialDataClassType(classDescriptor, partialClassName) - val partialBuilderFun = buildPartialDataClassBuilderFunction(classDescriptor) - val partialListBuilderFun = buildPartialDataClassListBuilderFunction(classDescriptor) - val partialGenFolder = classFile.parent - .replace("/src/main/kotlin", "/src/main/kotlinGen") - .replace(packageName.replace(".", "/"), "") - - FileSpec + val partialClassType = buildPartialDataClassType(classDeclaration, partialClassName) + val partialBuilderFun = buildPartialDataClassBuilderFunction(classDeclaration) + val partialListBuilderFun = buildPartialDataClassListBuilderFunction(classDeclaration) + + logger.info("Generate $packageName.$partialClassName") + + classDeclaration to FileSpec .builder(packageName, partialClassName) .generateComments() .addType(partialClassType) @@ -55,13 +70,14 @@ class PartialAnnotationProcessor : AbstractProcessor() { .forEach { addImport(it.packageName, toPartialMethodName) } } .build() - .writeTo(File(partialGenFolder)) } - } - private fun buildPartialDataClassType(classDescriptor: ClassDescriptor, partialClassName: String): TypeSpec { - val baseClassConstructorParameters = classDescriptor.constructors.first() + private fun buildPartialDataClassType(classDescriptor: KSClassDeclaration, partialClassName: String): TypeSpec { + val baseClassConstructorParameters = classDescriptor + .getConstructors() + .first() .getFunctionParameters() + val partialClassConstructorParameters = baseClassConstructorParameters .map { param -> ParameterSpec @@ -76,7 +92,8 @@ class PartialAnnotationProcessor : AbstractProcessor() { .map { param -> PropertySpec .builder( - param.parameterName, param.type.copy(nullable = true) + param.parameterName, + param.type.copy(nullable = true) ) .initializer(param.parameterName) .build() @@ -87,8 +104,8 @@ class PartialAnnotationProcessor : AbstractProcessor() { .addModifiers(KModifier.DATA) .addKdoc( "Partial representation of [${ - classDescriptor.containingPackage().toString() - }.${classDescriptor.name.asString()}]" + classDescriptor.packageName.asString() + }.${classDescriptor.simpleName.asString()}]" ) .primaryConstructor( FunSpec.constructorBuilder() @@ -99,16 +116,17 @@ class PartialAnnotationProcessor : AbstractProcessor() { .build() } - private fun buildPartialDataClassBuilderFunction(classDescriptor: ClassDescriptor): FunSpec { - val packageName = classDescriptor.containingPackage().toString() - val className = classDescriptor.name.asString() - val baseClassConstructorParameters = classDescriptor.constructors.first() - .getFunctionParameters() + private fun buildPartialDataClassBuilderFunction(classDescriptor: KSClassDeclaration): FunSpec { + val packageName = classDescriptor.packageName.asString() + val className = classDescriptor.simpleName.asString() + val baseClassConstructorParameters = classDescriptor.getConstructors().first().getFunctionParameters() val partialClassConstructorParameters = baseClassConstructorParameters .joinToString(separator = ",\n ") { param -> "${param.parameterName} = ${ findPartialClassByName(param.type.asString()!!.toBase()) - ?.let { "${param.parameterName}${if (param.nullable) "?" else ""}.${toPartialMethodName}()" } ?: param.parameterName + ?.let { + "${param.parameterName}${if (param.nullable) "?" else ""}.$toPartialMethodName()" + } ?: param.parameterName }" } return FunSpec.builder(toPartialMethodName) @@ -145,9 +163,9 @@ class PartialAnnotationProcessor : AbstractProcessor() { .toSet() } - private fun buildPartialDataClassListBuilderFunction(classDescriptor: ClassDescriptor): FunSpec { - val packageName = classDescriptor.containingPackage().toString() - val className = classDescriptor.name.asString() + private fun buildPartialDataClassListBuilderFunction(classDescriptor: KSClassDeclaration): FunSpec { + val packageName = classDescriptor.packageName.asString() + val className = classDescriptor.simpleName.asString() return FunSpec.builder(toPartialMethodName) .receiver( ClassName("kotlin.collections", "List") @@ -159,50 +177,46 @@ class PartialAnnotationProcessor : AbstractProcessor() { ) .addCode( """ - | return mapNotNull { it.${toPartialMethodName}() } + | return mapNotNull { it.$toPartialMethodName() } """.trimMargin() ) .build() } - private fun FunctionDescriptor.getFunctionParameters(): List { - return if (valueParameters.isNotEmpty()) { - this.valueParameters.map { parameter -> - val fullPackage = parameter.toString() - .substringAfter(": ") - .substringBefore(" defined") - .substringBefore(" /* =") - .substringBefore("=") - .trim() - - val typeName = if (fullPackage.contains("<")) { - val type = fullPackage.substringBefore("<") - .split(".").last().replace("?", "") - .wireWithExistingPartial() - val packageName = fullPackage.substringBefore("<").split(".") - .dropLast(1).joinToString(".") - val parameterType = fullPackage.substringAfter("<").substringBefore(">") - .split(".").last().replace("?", "") - .wireWithExistingPartial() - val parameterTypePackage = fullPackage.substringAfter("<").substringBefore(">") - .split(".").dropLast(1).joinToString(".") + private fun KSFunctionDeclaration.getFunctionParameters(): List { + return if (parameters.toList().isNotEmpty()) { + parameters.map { parameter -> + val resolvedType = parameter.type.resolve() + val typeName = if (resolvedType.arguments.isNotEmpty()) { + // It's a type with generics, example: List ClassName( - packageName, - type + packageName = resolvedType.declaration.packageName.asString(), + simpleNames = listOf( + resolvedType.declaration.simpleName.asString() + ) + ).parameterizedBy( + resolvedType.arguments.map { generic -> + val genericResolved = generic.type!!.resolve() + ClassName( + packageName = genericResolved.declaration.packageName.asString(), + simpleNames = listOf( + genericResolved.declaration.simpleName.asString().wireWithExistingPartial() + ) + ) + } ) - .parameterizedBy(ClassName(parameterTypePackage, parameterType)) } else { - val packageName = fullPackage.split(".").dropLast(1).joinToString(".") - val typeName = fullPackage.split(".").last().replace("?", "") - .wireWithExistingPartial() ClassName( - packageName, - typeName + packageName = resolvedType.declaration.packageName.asString(), + simpleNames = listOf( + resolvedType.declaration.simpleName.asString().wireWithExistingPartial() + ) ) } + FunctionParameter( - parameter.name.asString(), - parameter.type.toString().endsWith("?"), + parameter.name?.asString() ?: throw IllegalStateException("null param name $parameter"), + resolvedType.isMarkedNullable, typeName ) }.toList() @@ -216,23 +230,23 @@ class PartialAnnotationProcessor : AbstractProcessor() { ?.toPartial() ?: this - private fun findPartialClassByName(name: String) = + private fun findPartialClassByName(name: String): String? = partialClasses - .map { it.name.asString() } + .map { it.simpleName.asString() } .find { it == name } - private fun TypeName.asString(): String? = when (this) { - is ClassName -> simpleName - is ParameterizedTypeName -> this.typeArguments.first().asString() - else -> null - } - private fun String.toPartial() = "${this}Partial" private fun ClassName.isPartialType() = simpleName.contains("Partial") private fun String.toBase() = replace("Partial", "") + private fun TypeName.asString(): String? = when (this) { + is ClassName -> simpleName + is ParameterizedTypeName -> this.typeArguments.first().asString() + else -> null + } + private fun FileSpec.Builder.generateComments() = addFileComment( """ diff --git a/annotation-processor/src/main/kotlin/com/izivia/ocpi/toolkit/processor/PartialProcessorProvider.kt b/annotation-processor/src/main/kotlin/com/izivia/ocpi/toolkit/processor/PartialProcessorProvider.kt new file mode 100644 index 00000000..16ee9177 --- /dev/null +++ b/annotation-processor/src/main/kotlin/com/izivia/ocpi/toolkit/processor/PartialProcessorProvider.kt @@ -0,0 +1,8 @@ +package com.izivia.ocpi.toolkit.processor + +import com.google.devtools.ksp.processing.* + +class PartialProcessorProvider : SymbolProcessorProvider { + override fun create(environment: SymbolProcessorEnvironment): SymbolProcessor = + PartialProcessor(environment.codeGenerator, environment.logger) +} diff --git a/annotation-processor/src/main/resources/META-INF/services/com.google.devtools.ksp.processing.SymbolProcessorProvider b/annotation-processor/src/main/resources/META-INF/services/com.google.devtools.ksp.processing.SymbolProcessorProvider new file mode 100644 index 00000000..d100b421 --- /dev/null +++ b/annotation-processor/src/main/resources/META-INF/services/com.google.devtools.ksp.processing.SymbolProcessorProvider @@ -0,0 +1 @@ +com.izivia.ocpi.toolkit.processor.PartialProcessorProvider diff --git a/annotation-processor/src/main/resources/META-INF/services/org.jetbrains.kotlin.compiler.plugin.ComponentRegistrar b/annotation-processor/src/main/resources/META-INF/services/org.jetbrains.kotlin.compiler.plugin.ComponentRegistrar deleted file mode 100644 index cde67014..00000000 --- a/annotation-processor/src/main/resources/META-INF/services/org.jetbrains.kotlin.compiler.plugin.ComponentRegistrar +++ /dev/null @@ -1 +0,0 @@ -com.izivia.ocpi.toolkit.processor.CommonComponentRegistrar diff --git a/build.gradle.kts b/build.gradle.kts index 839185e7..2b3016a9 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,15 +1,21 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile +import org.jlleitschuh.gradle.ktlint.reporter.ReporterType import java.util.Base64 +buildscript { + dependencies { + classpath(kotlin("gradle-plugin", version = Versions.kotlin)) + } +} + plugins { - base - java - kotlin("jvm") apply false - kotlin("kapt") apply false - id("io.github.gradle-nexus.publish-plugin") version "1.1.0" + kotlin("jvm") version Versions.kotlin apply false + id("com.google.devtools.ksp") version Versions.ksp apply false + id("org.jlleitschuh.gradle.ktlint") version Versions.ktlintPlugin apply false + id("io.github.gradle-nexus.publish-plugin") version Versions.nexus } -val versionNumber = System.getenv("VERSION")?.substringAfter("R-") ?: "0.0.6" +val versionNumber = System.getenv("VERSION")?.substringAfter("R-") ?: "0.0.15" println("building current version: $versionNumber") @@ -43,6 +49,19 @@ subprojects { plugin("org.jetbrains.kotlin.jvm") plugin("maven-publish") plugin("signing") + plugin("org.jlleitschuh.gradle.ktlint") + } + + configure { + version.set(Versions.ktlint) + verbose.set(true) + outputToConsole.set(true) + reporters { + reporter(ReporterType.JSON) + } + filter { + exclude { element -> element.file.path.contains("generated") } + } } extensions.getByType().publications { diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts index 0861c0a6..d317042e 100644 --- a/buildSrc/build.gradle.kts +++ b/buildSrc/build.gradle.kts @@ -1,29 +1,7 @@ -buildscript { - repositories { - mavenCentral() - } - dependencies { - classpath(kotlin("gradle-plugin", version = "1.8.20")) - } -} - -plugins { - `kotlin-dsl` -} - repositories { mavenCentral() } -dependencies { - implementation(kotlin("gradle-plugin", version = "1.8.20")) -} - -gradlePlugin { - plugins { - create("simplePlugin") { - id = "com.izivia.ocpi.toolkit.processor" - implementationClass = "com.izivia.ocpi.toolkit.processor.AptGradlePlugin" - } - } +plugins { + `kotlin-dsl` } diff --git a/buildSrc/src/main/kotlin/Base.kt b/buildSrc/src/main/kotlin/Base.kt index 815b4887..326fdef8 100644 --- a/buildSrc/src/main/kotlin/Base.kt +++ b/buildSrc/src/main/kotlin/Base.kt @@ -1,16 +1,3 @@ -import org.gradle.api.Project -import org.gradle.kotlin.dsl.dependencies -import org.gradle.kotlin.dsl.kotlin -import org.gradle.kotlin.dsl.repositories -fun http4k(module:String) = "org.http4k:http4k-${module}:${Versions.http4k}" -fun Project.kotlinProject() { - dependencies { - "implementation"(kotlin("stdlib-jdk8")) - "implementation"(kotlin("reflect")) - } - repositories { - mavenCentral() - } -} +fun http4k(module: String) = "org.http4k:http4k-$module:${Versions.http4k}" diff --git a/buildSrc/src/main/kotlin/Versions.kt b/buildSrc/src/main/kotlin/Versions.kt index dcb66931..3a787d60 100644 --- a/buildSrc/src/main/kotlin/Versions.kt +++ b/buildSrc/src/main/kotlin/Versions.kt @@ -1,15 +1,24 @@ object Versions { - const val http4k = "4.25.10.1" - const val jackson = "2.13.2" - const val logback = "1.3.0-alpha14" + // Used by core + const val jackson = "2.16.0" + const val log4j = "2.22.0" const val valiktor = "0.12.0" - const val junit = "5.8.2" - const val strikt = "0.34.0" - const val kotlinPoet = "1.11.0" - const val mpapt = "0.8.8" - const val mockk = "1.12.3" - const val log4j = "2.17.2" - const val testcontainers = "1.16.3" - const val kmongo = "4.5.1" const val coroutines = "1.7.3" + const val kotlin = "1.9.20" + + // Used to build / gradle + const val ksp = "1.9.20-1.0.14" + const val kotlinPoet = "1.15.3" + const val nexus = "1.3.0" + const val ktlintPlugin = "12.0.2" + const val ktlint = "0.50.0" + + // Used only for tests + const val logback = "1.4.14" + const val junit = "5.10.1" + const val http4k = "4.48.0.0" + const val strikt = "0.34.1" + const val mockk = "1.13.8" + const val testcontainers = "1.19.3" + const val kmongo = "4.11.0" } diff --git a/buildSrc/src/main/kotlin/com/izivia/ocpi/toolkit/processor/AptGradlePlugin.kt b/buildSrc/src/main/kotlin/com/izivia/ocpi/toolkit/processor/AptGradlePlugin.kt deleted file mode 100644 index ba8cd1fd..00000000 --- a/buildSrc/src/main/kotlin/com/izivia/ocpi/toolkit/processor/AptGradlePlugin.kt +++ /dev/null @@ -1,31 +0,0 @@ -package com.izivia.ocpi.toolkit.processor - -import org.gradle.api.provider.Provider -import org.jetbrains.kotlin.gradle.plugin.KotlinCompilation -import org.jetbrains.kotlin.gradle.plugin.KotlinCompilerPluginSupportPlugin -import org.jetbrains.kotlin.gradle.plugin.SubpluginArtifact -import org.jetbrains.kotlin.gradle.plugin.SubpluginOption - -class AptGradlePlugin : KotlinCompilerPluginSupportPlugin { - - private var version: String? = null - - override fun applyToCompilation(kotlinCompilation: KotlinCompilation<*>): Provider> { - version = kotlinCompilation.target.project.version.toString() - return kotlinCompilation.target.project.provider { - emptyList() - } - } - - override fun getCompilerPluginId(): String = "AptGradlePlugin" - - override fun getPluginArtifact(): SubpluginArtifact = - SubpluginArtifact( - groupId = "com.izivia", - artifactId = "ocpi-annotation-processor", - version = System.getenv("VERSION")?.substringAfter("R-") ?: "1.0.0" - ) - - override fun isApplicable(kotlinCompilation: KotlinCompilation<*>): Boolean = true - -} diff --git a/common/src/main/kotlin/com/izivia/ocpi/toolkit/annotations/Partial.kt b/common/src/main/kotlin/com/izivia/ocpi/toolkit/annotations/Partial.kt index a2c7f2d5..38511d41 100644 --- a/common/src/main/kotlin/com/izivia/ocpi/toolkit/annotations/Partial.kt +++ b/common/src/main/kotlin/com/izivia/ocpi/toolkit/annotations/Partial.kt @@ -1,3 +1,7 @@ package com.izivia.ocpi.toolkit.annotations +@Target(AnnotationTarget.CLASS) +// It defines the lifecycle of the annotation, we do not need it +// after compile, so we set it to source +@Retention(AnnotationRetention.SOURCE) annotation class Partial diff --git a/gradle.properties b/gradle.properties new file mode 100644 index 00000000..c00acdea --- /dev/null +++ b/gradle.properties @@ -0,0 +1,6 @@ +org.gradle.caching=true +org.gradle.configuration-cache=true +org.gradle.warning.mode=all +# ksp2.0 will have this set at false by default. It makes sure ksp only applies on the main sourceSet +# https://stackoverflow.com/questions/75660972/disable-task-for-code-generation-in-test-for-googles-ksp +ksp.allow.all.target.configuration=false diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index 41d9927a..033e24c4 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 84a0b92f..3fa8f862 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,7 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.2.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip +networkTimeout=10000 +validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew index 1b6c7873..fcb6fca1 100755 --- a/gradlew +++ b/gradlew @@ -55,7 +55,7 @@ # Darwin, MinGW, and NonStop. # # (3) This script is generated from the Groovy template -# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt # within the Gradle project. # # You can find Gradle at https://github.com/gradle/gradle/. @@ -80,13 +80,10 @@ do esac done -APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit - -APP_NAME="Gradle" +# This is normally unused +# shellcheck disable=SC2034 APP_BASE_NAME=${0##*/} - -# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' +APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit # Use the maximum available, or set MAX_FD != -1 to use that value. MAX_FD=maximum @@ -133,22 +130,29 @@ location of your Java installation." fi else JAVACMD=java - which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + if ! command -v java >/dev/null 2>&1 + then + die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. Please set the JAVA_HOME variable in your environment to match the location of your Java installation." + fi fi # Increase the maximum file descriptors if we can. if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then case $MAX_FD in #( max*) + # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC3045 MAX_FD=$( ulimit -H -n ) || warn "Could not query maximum file descriptor limit" esac case $MAX_FD in #( '' | soft) :;; #( *) + # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC3045 ulimit -n "$MAX_FD" || warn "Could not set maximum file descriptor limit to $MAX_FD" esac @@ -193,6 +197,10 @@ if "$cygwin" || "$msys" ; then done fi + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + # Collect all arguments for the java command; # * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of # shell script including quotes and variable substitutions, so put them in @@ -205,6 +213,12 @@ set -- \ org.gradle.wrapper.GradleWrapperMain \ "$@" +# Stop when "xargs" is not available. +if ! command -v xargs >/dev/null 2>&1 +then + die "xargs is not available" +fi + # Use "xargs" to parse quoted args. # # With -n1 it outputs one arg per line, with the quotes and backslashes removed. diff --git a/gradlew.bat b/gradlew.bat old mode 100644 new mode 100755 index 107acd32..93e3f59f --- a/gradlew.bat +++ b/gradlew.bat @@ -14,7 +14,7 @@ @rem limitations under the License. @rem -@if "%DEBUG%" == "" @echo off +@if "%DEBUG%"=="" @echo off @rem ########################################################################## @rem @rem Gradle startup script for Windows @@ -25,7 +25,8 @@ if "%OS%"=="Windows_NT" setlocal set DIRNAME=%~dp0 -if "%DIRNAME%" == "" set DIRNAME=. +if "%DIRNAME%"=="" set DIRNAME=. +@rem This is normally unused set APP_BASE_NAME=%~n0 set APP_HOME=%DIRNAME% @@ -40,7 +41,7 @@ if defined JAVA_HOME goto findJavaFromJavaHome set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto execute +if %ERRORLEVEL% equ 0 goto execute echo. echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. @@ -75,13 +76,15 @@ set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar :end @rem End local scope for the variables with windows NT shell -if "%ERRORLEVEL%"=="0" goto mainEnd +if %ERRORLEVEL% equ 0 goto mainEnd :fail rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of rem the _cmd.exe /c_ return code! -if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 -exit /b 1 +set EXIT_CODE=%ERRORLEVEL% +if %EXIT_CODE% equ 0 set EXIT_CODE=1 +if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% +exit /b %EXIT_CODE% :mainEnd if "%OS%"=="Windows_NT" endlocal diff --git a/ocpi-toolkit-2.1.1-gireve/build.gradle.kts b/ocpi-toolkit-2.1.1-gireve/build.gradle.kts deleted file mode 100644 index 61a80a8e..00000000 --- a/ocpi-toolkit-2.1.1-gireve/build.gradle.kts +++ /dev/null @@ -1,63 +0,0 @@ -plugins { - id("com.izivia.ocpi.toolkit.processor") -} - -dependencies { - implementation(project(":common")) - api(project(":transport")) - - api("org.apache.logging.log4j:log4j-api:${Versions.log4j}") - api("org.apache.logging.log4j:log4j-core:${Versions.log4j}") - - implementation("com.fasterxml.jackson.module:jackson-module-kotlin:${Versions.jackson}") - implementation("com.fasterxml.jackson.datatype:jackson-datatype-jsr310:${Versions.jackson}") - implementation("org.valiktor:valiktor-core:${Versions.valiktor}") - implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:${Versions.coroutines}") - - testImplementation(http4k("core")) - testImplementation(http4k("contract")) - testImplementation(http4k("client-jetty")) - testImplementation(http4k("server-netty")) - - testImplementation("org.junit.jupiter:junit-jupiter:${Versions.junit}") - testImplementation("io.strikt:strikt-core:${Versions.strikt}") - testImplementation("io.mockk:mockk:${Versions.mockk}") - - testImplementation("org.testcontainers:testcontainers:${Versions.testcontainers}") - testImplementation("org.testcontainers:junit-jupiter:${Versions.testcontainers}") - testImplementation("org.testcontainers:mongodb:${Versions.testcontainers}") - testImplementation("org.litote.kmongo:kmongo:${Versions.kmongo}") - - testRuntimeOnly("ch.qos.logback:logback-classic:${Versions.logback}") -} - -tasks.test { - useJUnitPlatform() - testLogging { - events("passed", "skipped", "failed") - } -} - -sourceSets.main { - java.srcDirs("src/main/kotlinGen") -} - -java { - withJavadocJar() - withSourcesJar() -} - -publishing { - publications { - named("maven") { - artifactId = "ocpi-2-1-1-gireve" - from(components["java"]) - - pom { - name.set("OCPI 2.1.1-gireve") - artifactId = "ocpi-2-1-1-gireve" - description.set("This module implements the v2.1.1 of the GIREVE OCPI spec") - } - } - } -} diff --git a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/common/HttpUtils.kt b/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/common/HttpUtils.kt deleted file mode 100644 index 21eaddfe..00000000 --- a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/common/HttpUtils.kt +++ /dev/null @@ -1,151 +0,0 @@ -package com.izivia.ocpi.toolkit.common - -import com.fasterxml.jackson.core.type.TypeReference -import com.izivia.ocpi.toolkit.modules.credentials.repositories.PlatformRepository -import com.izivia.ocpi.toolkit.modules.versions.domain.ModuleID -import com.izivia.ocpi.toolkit.transport.TransportClientBuilder -import com.izivia.ocpi.toolkit.transport.domain.HttpException -import com.izivia.ocpi.toolkit.transport.domain.HttpRequest -import com.izivia.ocpi.toolkit.transport.domain.HttpResponse -import com.izivia.ocpi.toolkit.transport.domain.HttpStatus -import java.util.* - -typealias AuthenticatedHttpRequest = HttpRequest - -/** - * Parse body of a paginated request. The result will be stored in a SearchResult which contains all pagination - * information. - * @param offset - */ -inline fun HttpResponse.parsePaginatedBody(offset: Int): OcpiResponseBody> = - mapper.readValue(body, object : TypeReference>>() {}) - .let { parsedBody -> - OcpiResponseBody( - data = parsedBody.data?.toSearchResult( - totalCount = headers["X-Total-Count"]!!.toInt(), - limit = headers["X-Limit"]!!.toInt(), - offset = offset, - nextPageUrl = headers["Link"]?.split("<")?.get(1)?.split(">")?.first() - ), - status_code = parsedBody.status_code, - status_message = parsedBody.status_message, - timestamp = parsedBody.timestamp - ) - } - -/** - * Parses the body of the given HttpResponse to the specified type - * - * @throws StreamReadException – if underlying input contains invalid content of type JsonParser supports (JSON for - * default case) - * @throws DatabindException – if the input JSON structure does not match structure expected for result type (or has - * other mismatch issues) - */ -inline fun HttpResponse.parseBody(): T = mapper.readValue(body!!, object: TypeReference() {}) - -/** - * Encode a string in base64, also @see String#decodeBase64() - */ -fun String.encodeBase64(): String = this // Base64.getEncoder().encodeToString(this.encodeToByteArray()) - -/** - * Decodes a base64-encoded string, also @see String#encodeBase64() - */ -fun String.decodeBase64(): String = this // Base64.getDecoder().decode(this).decodeToString() - -/** - * Creates the authorization header from the given token - */ -fun authorizationHeader(token: String): Pair = "Authorization" to "Token ${token.encodeBase64()}" - -/** - * Creates the authorization header by taking the right token in the platform repository - */ -fun PlatformRepository.buildAuthorizationHeader(baseUrl: String, allowTokenAOrTokenB: Boolean = false) = - if (allowTokenAOrTokenB) { - getCredentialsTokenC(platformUrl = baseUrl) - ?: getCredentialsTokenB(platformUrl = baseUrl) - ?: getCredentialsTokenA(platformUrl = baseUrl) - ?: throw throw OcpiClientGenericException( - "Could not find CREDENTIALS TOKEN A OR B OR C associated with platform $baseUrl" - ) - } else { - getCredentialsTokenC(platformUrl = baseUrl) - ?: throw throw OcpiClientGenericException( - "Could not find CREDENTIALS TOKEN C associated with platform $baseUrl" - ) - }.let { token -> authorizationHeader(token = token) } - -/** - * Adds the authentification header to the request. - * - * @param platformRepository use to retrieve tokens - * @param baseUrl used to know what platform is being requested - * @param allowTokenAOrTokenB true if we can authenticate using token A - */ -fun HttpRequest.authenticate( - platformRepository: PlatformRepository, - baseUrl: String, - allowTokenAOrTokenB: Boolean = false -): AuthenticatedHttpRequest = - copy( - headers = headers.plus( - platformRepository.buildAuthorizationHeader( - baseUrl = baseUrl, - allowTokenAOrTokenB = allowTokenAOrTokenB - ) - ) - ) - -/** - * Adds the authentification header to the request. - * - * @param token the token to use to authenticate - */ -fun HttpRequest.authenticate(token: String): AuthenticatedHttpRequest = - copy(headers = headers.plus(authorizationHeader(token = token))) - -/** - * Parses authorization header from the HttpRequest - * - * @throws OcpiClientNotEnoughInformationException if the token is missing - * @throws HttpException if the authorization header is missing - */ -fun HttpRequest.parseAuthorizationHeader() = (headers["Authorization"] ?: headers["authorization"]) - ?.let { - if (it.startsWith("Token ")) it - else throw OcpiClientInvalidParametersException("Unkown token format: $it") - } - ?.removePrefix("Token ") - ?.decodeBase64() - ?: throw HttpException(HttpStatus.UNAUTHORIZED, "Authorization header missing") - -/** - * Throws an exception if the token is invalid. Does nothing otherwise. - * - * TODO: is it the good behaviour given: - * - tokenA: Valid in receiver context, during sender registration (only for sender -> receiver calls) - * - tokenB: Valid in sender context, during sender registration (only for receiver -> sender calls) - * - tokenC: Valid when the sender is registered with the receiver (only for sender -> receiver) - * - * @throws OcpiClientInvalidParametersException if the token is invalid, otherwise does nothing - * @throws OcpiClientNotEnoughInformationException if the token is missing - * @throws HttpException if the authorization header is missing - */ -fun PlatformRepository.checkToken(httpRequest: HttpRequest) { - val token = httpRequest.parseAuthorizationHeader() - - if (!platformExistsWithTokenA(token) && - !platformExistsWithTokenB(token) && - getPlatformUrlByTokenC(token) == null - ) { - throw OcpiClientInvalidParametersException("Invalid token: $token") - } -} - -fun TransportClientBuilder.buildFor(module: ModuleID, platformUrl: String, platformRepository: PlatformRepository) = - platformRepository - .getEndpoints(platformUrl = platformUrl) - .find { it.identifier == module } - ?.let { build(baseUrl = it.url) } - ?: throw OcpiToolkitUnknownEndpointException(endpointName = module.name) diff --git a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/common/Mapper.kt b/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/common/Mapper.kt deleted file mode 100644 index 7653a447..00000000 --- a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/common/Mapper.kt +++ /dev/null @@ -1,24 +0,0 @@ -package com.izivia.ocpi.toolkit.common - -import com.fasterxml.jackson.annotation.JsonInclude -import com.fasterxml.jackson.databind.ObjectMapper -import com.fasterxml.jackson.databind.SerializationFeature -import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule -import com.fasterxml.jackson.module.kotlin.KotlinFeature -import com.fasterxml.jackson.module.kotlin.KotlinModule -import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper - -val mapper: ObjectMapper = jacksonObjectMapper() - .registerModule( - KotlinModule.Builder() - .withReflectionCacheSize(512) - .configure(KotlinFeature.NullToEmptyCollection, false) - .configure(KotlinFeature.NullToEmptyMap, false) - .configure(KotlinFeature.NullIsSameAsDefault, false) - .configure(KotlinFeature.SingletonSupport, false) - .configure(KotlinFeature.StrictNullChecks, false) - .build() - ) - .registerModule(JavaTimeModule()) - .configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false) - .setSerializationInclusion(JsonInclude.Include.NON_NULL) \ No newline at end of file diff --git a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/common/OcpiExceptions.kt b/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/common/OcpiExceptions.kt deleted file mode 100644 index 47132071..00000000 --- a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/common/OcpiExceptions.kt +++ /dev/null @@ -1,64 +0,0 @@ -package com.izivia.ocpi.toolkit.common - -import com.izivia.ocpi.toolkit.transport.domain.HttpStatus - -sealed class OcpiException( - message: String, - open val httpStatus: HttpStatus, - open val ocpiStatus: OcpiStatus -): Exception(message) - -class OcpiResponseException( - val statusCode: Int, - val statusMessage: String -): Exception("Ocpi error: ${statusCode.toOcpiStatus()} $statusCode ($statusMessage)") - -// 2xxx: Client errors -class OcpiClientGenericException( - message: String, - override val httpStatus: HttpStatus = HttpStatus.BAD_REQUEST, - override val ocpiStatus: OcpiStatus = OcpiStatus.CLIENT_ERROR -) : OcpiException(message, httpStatus, ocpiStatus) - -class OcpiClientInvalidParametersException( - message: String = "Invalid or missing parameters", - override val httpStatus: HttpStatus = HttpStatus.BAD_REQUEST, - override val ocpiStatus: OcpiStatus = OcpiStatus.CLIENT_INVALID_PARAMETERS -) : OcpiException(message, httpStatus, ocpiStatus) - -class OcpiClientNotEnoughInformationException( - message: String = "Not enough information", - override val httpStatus: HttpStatus = HttpStatus.BAD_REQUEST, - override val ocpiStatus: OcpiStatus = OcpiStatus.CLIENT_NOT_ENOUGH_INFORMATION -) : OcpiException(message, httpStatus, ocpiStatus) - -class OcpiClientUnknownLocationException( - message: String = "Unknown location", - override val httpStatus: HttpStatus = HttpStatus.NOT_FOUND, - override val ocpiStatus: OcpiStatus = OcpiStatus.CLIENT_UNKNOWN_LOCATION -) : OcpiException(message, httpStatus, ocpiStatus) - -// 3xxx: Server errors -class OcpiServerGenericException( - message: String, - override val httpStatus: HttpStatus = HttpStatus.OK, - override val ocpiStatus: OcpiStatus = OcpiStatus.SERVER_ERROR -) : OcpiException(message, httpStatus, ocpiStatus) - -class OcpiServerUnusableApiException( - message: String = "Unable to use client's API", - override val httpStatus: HttpStatus = HttpStatus.OK, - override val ocpiStatus: OcpiStatus = OcpiStatus.SERVER_UNUSABLE_API -) : OcpiException(message, httpStatus, ocpiStatus) - -class OcpiServerUnsupportedVersionException( - message: String = "Unsupported version", - override val httpStatus: HttpStatus = HttpStatus.OK, - override val ocpiStatus: OcpiStatus = OcpiStatus.SERVER_UNSUPPORTED_VERSION -) : OcpiException(message, httpStatus, ocpiStatus) - -class OcpiServerNoMatchingEndpointsException( - message: String = "No matching endpoints or expected endpoints missing between parties", - override val httpStatus: HttpStatus = HttpStatus.OK, - override val ocpiStatus: OcpiStatus = OcpiStatus.SERVER_NO_MATCHING_ENDPOINTS -) : OcpiException(message, httpStatus, ocpiStatus) \ No newline at end of file diff --git a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/common/OcpiResponseBody.kt b/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/common/OcpiResponseBody.kt deleted file mode 100644 index be91a2be..00000000 --- a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/common/OcpiResponseBody.kt +++ /dev/null @@ -1,158 +0,0 @@ -package com.izivia.ocpi.toolkit.common - -import com.fasterxml.jackson.core.JsonProcessingException -import com.izivia.ocpi.toolkit.common.validation.toReadableString -import com.izivia.ocpi.toolkit.transport.domain.HttpException -import com.izivia.ocpi.toolkit.transport.domain.HttpRequest -import com.izivia.ocpi.toolkit.transport.domain.HttpResponse -import com.izivia.ocpi.toolkit.transport.domain.HttpStatus -import org.apache.logging.log4j.LogManager -import org.valiktor.ConstraintViolationException -import java.time.Instant - -/** - * When the status code is in the success range (1xxx), the data field in the response message should contain the - * information as specified in the protocol. Otherwise the data field is unspecified and may be omitted, null or - * something else that could help to debug the problem from a programmer's perspective. For example, it could specify - * which fields contain an error or are missing. - * - * The content that is sent with all the response messages is an 'application/json' type and contains a JSON object with - * the following properties: - * - * @property data Contains the actual response data object or list of objects from each request, depending on the - * cardinality of the response data, this is an array (card. * or +), or a single object (card. 1 or ?) - * @property status_code Response code, as listed in Status Codes, indicates how the request was handled. To avoid - * confusion with HTTP codes, at least four digits are used. - * @property status_message An optional status message which may help when debugging. - * @property timestamp The time this message was generated. - */ -data class OcpiResponseBody( - val data: T?, - val status_code: Int, - val status_message: String?, - val timestamp: Instant -) { - companion object { - fun success(data: T) = OcpiResponseBody( - data = data, - status_code = OcpiStatus.SUCCESS.code, - status_message = null, - timestamp = Instant.now() - ) - - fun invalid(message: String) = OcpiResponseBody( - data = null, - status_code = OcpiStatus.CLIENT_INVALID_PARAMETERS.code, - status_message = message, - timestamp = Instant.now() - ) - - fun notEnoughInformation(message: String) = OcpiResponseBody( - data = null, - status_code = OcpiStatus.CLIENT_NOT_ENOUGH_INFORMATION.code, - status_message = message, - timestamp = Instant.now() - ) - - fun of(data: () -> T) = - try { - success(data = data()) - } catch (e: ConstraintViolationException) { - invalid(message = e.toReadableString()) - } - } -} - -private val logger = LogManager.getLogger(OcpiResponseBody::class.java) - -/** - * Generates all required headers for a paginated response from a OcpiBody with a searchResult. - * @param request the request that generated the body. - * @return Map the headers required for pagination - */ -fun OcpiResponseBody>.getPaginatedHeaders(request: HttpRequest) = - if (data != null) { - val nextPageOffset = (data.offset + data.limit).takeIf { it <= data.totalCount } - - val queries = request - .queryParams - .filter { it.key != "offset" && it.value != null } - .plus("offset" to (data.limit + data.offset)) - .map { "${it.key}=${it.value}" } - .joinToString("&", "?") - - listOfNotNull( - nextPageOffset?.let { "Link" to "<${request.baseUrl}${request.path}$queries>; rel=\"next\"" }, - "X-Total-Count" to data.totalCount.toString(), - "X-Limit" to data.limit.toString() - ).toMap() - } else { - emptyMap() - } - -/** - * Transforms an OcpiException to an HttpResponse. May be used in TransportServer implementation to handle - * OCPI exceptions. - */ -fun OcpiException.toHttpResponse(): HttpResponse = - HttpResponse( - status = httpStatus, - body = mapper.writeValueAsString( - OcpiResponseBody( - data = null, - status_code = ocpiStatus.code, - status_message = message, - timestamp = Instant.now() - ) - ), - headers = if (httpStatus == HttpStatus.UNAUTHORIZED) mapOf("WWW-Authenticate" to "Token") else emptyMap() - ) - -/** - * Used to handle errors & paginated responses when handling a request. fn() should contain the code generating the - * body. If an error is caught, everything will be handled here. If it's a paginated response, it will be automatically - * be handled too. - * - * @return the HttpResponse properly formatted according to the body generated by fn() - */ -@Suppress("UNCHECKED_CAST") -fun HttpRequest.httpResponse(fn: () -> OcpiResponseBody): HttpResponse = - try { - val ocpiResponseBody = fn() - val isPaginated = ocpiResponseBody.data is SearchResult<*> - - HttpResponse( - status = when (ocpiResponseBody.status_code) { - OcpiStatus.SUCCESS.code -> if (ocpiResponseBody.data != null) HttpStatus.OK else HttpStatus.NOT_FOUND - OcpiStatus.CLIENT_INVALID_PARAMETERS.code -> HttpStatus.BAD_REQUEST - else -> HttpStatus.INTERNAL_SERVER_ERROR - }, - body = mapper.writeValueAsString( - if (isPaginated) OcpiResponseBody( - data = (ocpiResponseBody.data as SearchResult<*>?)?.list, - status_code = ocpiResponseBody.status_code, - status_message = ocpiResponseBody.status_message, - timestamp = ocpiResponseBody.timestamp - ) - else ocpiResponseBody - ) - ).let { - if (isPaginated) it.copy( - headers = (ocpiResponseBody as OcpiResponseBody>) - .getPaginatedHeaders(request = this) - ) - else it - } - } catch (e: OcpiException) { - e.toHttpResponse() - } catch (e: HttpException) { - logger.error(e) - HttpResponse( - status = e.status - ) - } catch (e: JsonProcessingException) { - logger.error(e) - HttpResponse( - status = HttpStatus.BAD_REQUEST - ) - } diff --git a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/common/OcpiStatus.kt b/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/common/OcpiStatus.kt deleted file mode 100644 index 8651a321..00000000 --- a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/common/OcpiStatus.kt +++ /dev/null @@ -1,60 +0,0 @@ -package com.izivia.ocpi.toolkit.common - -/** - * - 1xxx: Success - * - 2xxx: Client errors - Errors detected by a server in the message sent by a client: The client did something wrong - * - 3xxx: Server errors - Error during processing of the OCPI payload in the server. The message was syntactically - * correct but could not be processed by the server. - */ -enum class OcpiStatus(val code: Int) { - /** - * Generic success code - */ - SUCCESS(1000), - - /** - * Generic client error - */ - CLIENT_ERROR(2000), - - /** - * Invalid or missing parameters - */ - CLIENT_INVALID_PARAMETERS(2001), - - /** - * Not enough information, for example: Authorization request with too little information. - */ - CLIENT_NOT_ENOUGH_INFORMATION(2002), - - /** - * Unknown Location, for example: Command: START_SESSION with unknown location. - */ - CLIENT_UNKNOWN_LOCATION(2003), - - /** - * Generic server error - */ - SERVER_ERROR(3000), - - /** - * Unable to use the client's API. For example during the credentials registration: When the initializing party - * requests data from the other party during the open POST call to its credentials endpoint. If one of the GETs can - * not be processed, the party should return this error in the POST response. - */ - SERVER_UNUSABLE_API(3001), - - /** - * Unsupported version. - */ - SERVER_UNSUPPORTED_VERSION(3002), - - /** - * No matching endpoints or expected endpoints missing between parties. Used during the registration process if the - * two parties do not have any mutual modules or endpoints available, or the minimum expected by the other party - * implementation. - */ - SERVER_NO_MATCHING_ENDPOINTS(3003) -} - -fun Int.toOcpiStatus(): OcpiStatus? = OcpiStatus.values().firstOrNull { it.code == this } \ No newline at end of file diff --git a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/common/OcpiToolkitExceptions.kt b/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/common/OcpiToolkitExceptions.kt deleted file mode 100644 index 59667cfa..00000000 --- a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/common/OcpiToolkitExceptions.kt +++ /dev/null @@ -1,11 +0,0 @@ -package com.izivia.ocpi.toolkit.common - -class OcpiToolkitUnknownEndpointException( - endpointName: String -) : Exception( - """ - Endpoint '$endpointName' is unknown. Make sure you registered (credentialClient#register) first. During - registration process, the available endpoints are saved in platformRepository to be used later on. If you - already registered, make sure that the platformRepository works properly. - """.trimIndent() -) \ No newline at end of file diff --git a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/common/SearchResult.kt b/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/common/SearchResult.kt deleted file mode 100644 index 19b6272b..00000000 --- a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/common/SearchResult.kt +++ /dev/null @@ -1,17 +0,0 @@ -package com.izivia.ocpi.toolkit.common - -data class SearchResult( - val list: List, - val totalCount: Int, - val limit: Int, - val offset: Int, - val nextPageUrl: String? -) - -fun List.toSearchResult(totalCount: Int, limit: Int, offset: Int, nextPageUrl: String? = null) = SearchResult( - list = this, - totalCount = totalCount, - limit = limit, - offset = offset, - nextPageUrl = nextPageUrl -) \ No newline at end of file diff --git a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/common/Utils.kt b/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/common/Utils.kt deleted file mode 100644 index d232b13b..00000000 --- a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/common/Utils.kt +++ /dev/null @@ -1,7 +0,0 @@ -package com.izivia.ocpi.toolkit.common - -import java.util.* - -fun generateUUIDv4Token(): String { - return UUID.randomUUID().toString() -} \ No newline at end of file diff --git a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/common/validation/Iso639Alpha2.kt b/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/common/validation/Iso639Alpha2.kt deleted file mode 100644 index 94da8fd3..00000000 --- a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/common/validation/Iso639Alpha2.kt +++ /dev/null @@ -1,194 +0,0 @@ -package com.izivia.ocpi.toolkit.common.validation - -/** - * ISO 639-1 language codes - */ -enum class Iso639Alpha2 { - aa, - ab, - ae, - af, - ak, - am, - an, - ar, - `as`, - av, - ay, - az, - ba, - be, - bg, - bh, - bi, - bm, - bn, - bo, - br, - bs, - ca, - ce, - ch, - co, - cr, - cs, - cu, - cv, - cy, - da, - de, - dv, - dz, - ee, - el, - en, - eo, - es, - et, - eu, - fa, - ff, - fi, - fj, - fo, - fr, - fy, - ga, - gd, - gl, - gn, - gu, - gv, - ha, - he, - hi, - ho, - hr, - ht, - hu, - hy, - hz, - ia, - id, - ie, - ig, - ii, - ik, - io, - `is`, - it, - iu, - ja, - jv, - ka, - kg, - ki, - kj, - kk, - kl, - km, - kn, - ko, - kr, - ks, - ku, - kv, - kw, - ky, - la, - lb, - lg, - li, - ln, - lo, - lt, - lu, - lv, - mg, - mh, - mi, - mk, - ml, - mn, - mo, - mr, - ms, - mt, - my, - na, - nb, - nd, - ne, - ng, - nl, - nn, - no, - nr, - nv, - ny, - oc, - oj, - om, - or, - os, - pa, - pi, - pl, - ps, - pt, - qu, - rc, - rm, - rn, - ro, - ru, - rw, - sa, - sc, - sd, - se, - sg, - sh, - si, - sk, - sl, - sm, - sn, - so, - sq, - sr, - ss, - st, - su, - sv, - sw, - ta, - te, - tg, - th, - ti, - tk, - tl, - tn, - to, - tr, - ts, - tt, - tw, - ty, - ug, - uk, - ur, - uz, - ve, - vi, - vo, - wa, - wo, - xh, - yi, - yo, - za, - zh, - zu -} \ No newline at end of file diff --git a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/common/validation/Validation.kt b/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/common/validation/Validation.kt deleted file mode 100644 index 7d191549..00000000 --- a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/common/validation/Validation.kt +++ /dev/null @@ -1,60 +0,0 @@ -package com.izivia.ocpi.toolkit.common.validation - -import org.valiktor.ConstraintViolation -import org.valiktor.ConstraintViolationException -import org.valiktor.DefaultConstraintViolation -import org.valiktor.constraints.Greater -import org.valiktor.constraints.Less -import java.time.Instant - -data class ValidationContext( - val violations: MutableSet = mutableSetOf() -) - -fun validate(fn: ValidationContext.() -> T) = with(ValidationContext()) { - fn() - - if (violations.isNotEmpty()) { - throw ConstraintViolationException(violations) - } -} - -fun ValidationContext.validateLength(propertyName: String, property: String, maxLength: Int) { - if (property.length > maxLength) { - violations.add( - DefaultConstraintViolation( - property = property, - constraint = Greater(maxLength) - ) - ) - } -} - -fun ValidationContext.validateDates(fromPropertyName: String, from: Instant, toPropertyName: String, to: Instant) { - if (from.isAfter(to)) { - violations.add( - DefaultConstraintViolation( - property = "from", - constraint = Greater(to) - ) - ) - } -} - -fun ValidationContext.validateInt(propertyName: String, property: Int, min: Int?, max: Int?) { - if (min != null && property < min) { - violations.add( - DefaultConstraintViolation( - property = "value", - constraint = Less(min) - ) - ) - } else if (max != null && property > max) { - violations.add( - DefaultConstraintViolation( - property = "value", - constraint = Greater(min) - ) - ) - } -} diff --git a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/common/validation/Validators.kt b/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/common/validation/Validators.kt deleted file mode 100644 index f05e5f4e..00000000 --- a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/common/validation/Validators.kt +++ /dev/null @@ -1,131 +0,0 @@ -package com.izivia.ocpi.toolkit.common.validation - -import org.valiktor.Constraint -import org.valiktor.ConstraintViolationException -import org.valiktor.Validator -import org.valiktor.i18n.toMessage -import java.net.URL -import java.util.* - -fun ConstraintViolationException.toReadableString(): String = constraintViolations - .map { it.toMessage(baseName = "messages", locale = Locale.ENGLISH) } - .joinToString(",") { "${it.property}: ${it.message}" } - -class PrintableAsciiConstraint : Constraint -class MaxLengthContraint(val length: Int) : Constraint -class CountryCodeConstraint : Constraint -class UrlConstraint : Constraint -class TimeZoneConstraint : Constraint -class LatitudeConstraint : Constraint -class LongitudeConstraint : Constraint -class LanguageConstraint : Constraint -class TimeConstraint : Constraint -class EvseIdConstraint : Constraint -class NoHtmlConstraint : Constraint - -/** - * Valid if the given string only has printable ASCII characters and is smaller or has the same length as the given one. - */ -fun Validator.Property.isPrintableAscii() = - this.validate(PrintableAsciiConstraint()) { - it == null || it.matches("[\\x20-\\x7E]*".toRegex()) - } - - -fun Validator.Property.hasNoHtml() = - this.validate(NoHtmlConstraint()) { - it == null || !it.matches(".*<(\"[^\"]*\"|'[^']*'|[^'\">])*>.*".toRegex()) - } - -/** - * Valid if the string has a max length of the given one - */ -fun Validator.Property.hasMaxLengthOf(length: Int) = - this.validate(MaxLengthContraint(length)) { it == null || it.length <= length } - -/** - * Valid if the string correspond is a ISO 3166-1 alpha-3 code - */ -fun Validator.Property.isCountryCode() = - this.validate(CountryCodeConstraint()) { - it == null || Locale.getISOCountries(Locale.IsoCountryCode.PART1_ALPHA3).contains(it) - } - -/** - * Valid if the string is an URL following the w3.org spec - */ -fun Validator.Property.isUrl() = - this.validate(UrlConstraint()) { - it == null || try { URL(it).toURI().let { true } } catch (e: Exception) { false } - }.hasMaxLengthOf(255) - - -/** - * Valid if the string is one of IANA tzdata's TZ-values representing the time zone. - * Examples: "Europe/Oslo", "Europe/Zurich". (http://www.iana.org/time-zones) - */ -fun Validator.Property.isTimeZone() = - this.validate(TimeZoneConstraint()) { - it == null || TimeZone.getAvailableIDs().contains(it) - } - -/** - * Valid if the string is a latitude in decimal degree. Regex: -?[0-9]{1,2}\.[0-9]{6} - */ -fun Validator.Property.isLatitude() = - this.validate(LatitudeConstraint()) { - it == null || it.matches("-?\\d{1,2}\\.\\d{6}".toRegex()) - } - -/** - * Valid if the string is a longitude in decimal degree. Regex: -?[0-9]{1,3}\.[0-9]{6} - */ -fun Validator.Property.isLongitude() = - this.validate(LongitudeConstraint()) { - it == null || it.matches("-?\\d{1,3}\\.\\d{6}".toRegex()) - } - -/** - * Valid if the string is a language Code ISO 639-1 - */ -fun Validator.Property.isLanguage() = - this.validate(LanguageConstraint()) { - it == null || Iso639Alpha2.values().map { code -> code.name }.contains(it) - }.hasMaxLengthOf(2) - -/** - * Valid if the string is a time from 00:00 to 23:59 - */ -fun Validator.Property.isTime() = - this.validate(TimeConstraint()) { - it == null || it.matches("([0-1]\\d|2[0-3]):[0-5]\\d".toRegex()) - } - -/** - * Compliant with the following specification for EVSE ID from "eMI3 standard version V1.0" - * (http://emi3group.com/documents-links/) "Part 2: business objects." Optional because: if an EVSE ID is to be re-used - * the EVSE ID can be removed from an EVSE that is removed (status: REMOVED) - * - * Extracted from the doc: - * - {EVSE ID} = {Country Code} {S} {Spot Operator ID} {S} {ID Type} {Power Outlet ID} - * - Example: FR*A23*E45B*78C - * - * With: - * - Country Code: two character country code according to ISO-3166-1 (Alpha-2-Code). Country Code SHALL represent the - * country where the EVSE is installed. - * - Spot Operator ID: three alphanumeric characters, defined and listed by eMI3 group, referring to the EVSE operator - * - ID Type: one character “E” indicating that this ID represents an “EVSE” - * - Power Outlet ID: between 1 and 31 sequence of alphanumeric characters or separators, including additional optional - * separators start with alphanumeric character, internal number allowing the EVSE Operator to identify one specific - * EVSE - * - S: optional separator - * - * An example for, a valid EVSE ID is “FR*A23*E45B*78C” with “FR” indicating France, “A23” representing a particular - * EVSE Operator, “E” indicating that it is of type “EVSE” and “45B*78C” representing the power outlet ID, that is to - * say one of its EVSEs.NOTE: In contrast to the eMA ID, no check digit is specified for the EVSE ID in this document. - * Alpha characters SHALL be interpreted case insensitively. - */ -fun Validator.Property.isEvseId() = - this.validate(EvseIdConstraint()) { - it == null || it.matches("(?i)[a-z]{2}\\*?[a-z\\d]{3}\\*?E[a-z\\d*]{1,31}".toRegex()) - } \ No newline at end of file diff --git a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/credentials/CredentialsClient.kt b/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/credentials/CredentialsClient.kt deleted file mode 100644 index 43ba7193..00000000 --- a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/credentials/CredentialsClient.kt +++ /dev/null @@ -1,49 +0,0 @@ -package com.izivia.ocpi.toolkit.modules.credentials - -import com.izivia.ocpi.toolkit.common.OcpiResponseBody -import com.izivia.ocpi.toolkit.common.authenticate -import com.izivia.ocpi.toolkit.common.mapper -import com.izivia.ocpi.toolkit.common.parseBody -import com.izivia.ocpi.toolkit.modules.credentials.domain.Credentials -import com.izivia.ocpi.toolkit.transport.TransportClient -import com.izivia.ocpi.toolkit.transport.domain.HttpMethod -import com.izivia.ocpi.toolkit.transport.domain.HttpRequest - -/** - * Use this class only if you know what you are doing. Instead, use CredentialsClientService. - * @property transportClient TransportClient - */ -class CredentialsClient( - private val transportClient: TransportClient -): com.izivia.ocpi.toolkit.modules.credentials.CredentialsInterface { - - override fun get(tokenC: String): OcpiResponseBody = - transportClient - .send( - HttpRequest( - method = HttpMethod.GET - ).authenticate(token = tokenC) - ) - .parseBody() - - - override fun post(tokenA: String, credentials: Credentials): OcpiResponseBody = - transportClient - .send( - HttpRequest( - method = HttpMethod.POST, - body = mapper.writeValueAsString(credentials) - ).authenticate(token = tokenA) - ) - .parseBody() - - override fun delete(tokenC: String): OcpiResponseBody = - transportClient - .send( - HttpRequest( - method = HttpMethod.DELETE, - path = "/" - ).authenticate(token = tokenC) - ) - .parseBody() -} \ No newline at end of file diff --git a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/credentials/CredentialsInterface.kt b/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/credentials/CredentialsInterface.kt deleted file mode 100644 index 3858e919..00000000 --- a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/credentials/CredentialsInterface.kt +++ /dev/null @@ -1,40 +0,0 @@ -package com.izivia.ocpi.toolkit.modules.credentials - -import com.izivia.ocpi.toolkit.common.OcpiResponseBody -import com.izivia.ocpi.toolkit.modules.credentials.domain.Credentials - -/** - * The Credentials module is different from all other OCPI modules. This module is symmetric, it has to be implemented - * by all OCPI implementations, and all implementations need to be able call this module on any other platform, and have - * to be able the handle receiving the request from another party. - */ -interface CredentialsInterface { - /** - * Retrieves the credentials object to access the server’s platform. The request body is empty, the response - * contains the credentials object to access the server’s platform. This credentials object also contains extra - * information about the server such as its business details. - */ - fun get(tokenC: String): OcpiResponseBody - - /** - * Provides the server with credentials to access the client's system. This credentials object also contains extra - * information about the client such as its business details. - * - * A POST initiates the registration process for this endpoint's version. The server must also fetch the client's - * endpoints for this version. If successful, the server must generate a new credentials token and respond with the - * client's new credentials to access the server's system. The credentials object in the response also contains - * extra information about the server such as its business details. - * - * This method MUST return a HTTP status code 405: method not allowed if the client has already been registered - * before. - */ - fun post(tokenA: String, credentials: Credentials): OcpiResponseBody - - /** - * Informs the server that its credentials to access the client’s system are now invalid and can no longer be used. - * Both parties must end any automated communication. This is the unregistration process. - * - * This method MUST return a HTTP status code 405: method not allowed if the client has not been registered before. - */ - fun delete(tokenC: String): OcpiResponseBody -} \ No newline at end of file diff --git a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/credentials/CredentialsServer.kt b/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/credentials/CredentialsServer.kt deleted file mode 100644 index 85d0170e..00000000 --- a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/credentials/CredentialsServer.kt +++ /dev/null @@ -1,57 +0,0 @@ -package com.izivia.ocpi.toolkit.modules.credentials - -import com.izivia.ocpi.toolkit.common.httpResponse -import com.izivia.ocpi.toolkit.common.mapper -import com.izivia.ocpi.toolkit.common.parseAuthorizationHeader -import com.izivia.ocpi.toolkit.modules.credentials.domain.Credentials -import com.izivia.ocpi.toolkit.modules.credentials.services.CredentialsServerService -import com.izivia.ocpi.toolkit.transport.TransportServer -import com.izivia.ocpi.toolkit.transport.domain.FixedPathSegment -import com.izivia.ocpi.toolkit.transport.domain.HttpMethod -import kotlinx.coroutines.runBlocking - -class CredentialsServer( - transportServer: TransportServer, - service: CredentialsServerService, - basePath: List = listOf( - FixedPathSegment("/2.1.1/credentials") - ) -) { - init { - runBlocking { - transportServer.handle( - method = HttpMethod.GET, - path = basePath - ) { req -> - req.httpResponse { - service.get( - tokenC = req.parseAuthorizationHeader() - ) - } - } - - transportServer.handle( - method = HttpMethod.POST, - path = basePath - ) { req -> - req.httpResponse { - service.post( - tokenA = req.parseAuthorizationHeader(), - credentials = mapper.readValue(req.body!!, Credentials::class.java) - ) - } - } - - transportServer.handle( - method = HttpMethod.DELETE, - path = basePath - ) { req -> - req.httpResponse { - service.delete( - tokenC = req.parseAuthorizationHeader() - ) - } - } - } - } -} diff --git a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/credentials/domain/Credentials.kt b/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/credentials/domain/Credentials.kt deleted file mode 100644 index 1e5a3ec0..00000000 --- a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/credentials/domain/Credentials.kt +++ /dev/null @@ -1,29 +0,0 @@ -package com.izivia.ocpi.toolkit.modules.credentials.domain - -import com.izivia.ocpi.toolkit.modules.locations.domain.BusinessDetails - -/** - * The party_id and country_code are provided here to inform a server about the party_id and country_code a client will - * use when pushing client owned objects. This helps a server determine the URLs a client will use when pushing a client - * owned object. The country_code is added the make certain the URL used when pushing a client owned object is unique, - * there might be multiple parties in the world with the same party_id, but the combination should always be unique. A - * party operating in multiple countries can always use the home country of the company for all connections. For - * example: an OCPI implementation might push EVSE IDs from a company for different countries, preventing an OCPI - * connection per country a company is operating in. The party_id and country_code give here, have no direct link with - * the eMI3 EVSE IDs and Contract IDs that might be used in the different OCPI modules. For example: an implementation - * OCPI might push EVSE IDs with an eMI3 spot operator different from the OCPI party_id and/or the country_code. - * - * @property token (max-length=64) Case Sensitive, ASCII only. The credentials token for the other party to authenticate - * in your system. Not encoded in Base64 or any other encoding. - * @property url The URL to your API versions endpoint. - * @property business_details Details of this party. - * @property party_id (max-length=3) CPO or eMSP ID of this party. (following the 15118 ISO standard). - * @property country_code(max-length=2) Country code of the country this party is operating in. - */ -data class Credentials( - val token: String, - val url: String, - val business_details: BusinessDetails, - val party_id: String, - val country_code: String -) diff --git a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/credentials/repositories/PlatformRepository.kt b/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/credentials/repositories/PlatformRepository.kt deleted file mode 100644 index 749c4027..00000000 --- a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/credentials/repositories/PlatformRepository.kt +++ /dev/null @@ -1,31 +0,0 @@ -package com.izivia.ocpi.toolkit.modules.credentials.repositories - -import com.izivia.ocpi.toolkit.modules.versions.domain.Endpoint -import com.izivia.ocpi.toolkit.modules.versions.domain.Version - -/** - * - CREDENTIALS_TOKEN_A: used by the client to communicate with the server (when initiating registration). - * - CREDENTIALS_TOKEN_B: used by the server to communicate with the client (during registration). - * - CREDENTIALS_TOKEN_C: used by the client to communicate with the server (once registered). - */ -interface PlatformRepository { - fun getCredentialsTokenA(platformUrl: String): String? - fun getCredentialsTokenB(platformUrl: String): String? - fun getCredentialsTokenC(platformUrl: String): String? - fun platformExistsWithTokenA(token: String): Boolean - fun platformExistsWithTokenB(token: String): Boolean - fun getPlatformUrlByTokenC(token: String): String? - fun getEndpoints(platformUrl: String): List - fun getVersion(platformUrl: String): Version? - fun saveVersion(platformUrl: String, version: Version): Version - fun savePlatformUrlForTokenA(tokenA: String, platformUrl: String): String? - fun saveEndpoints(platformUrl: String, endpoints: List): List - fun saveCredentialsTokenA(platformUrl: String, credentialsTokenA: String): String - fun saveCredentialsTokenB(platformUrl: String, credentialsTokenB: String): String - fun saveCredentialsTokenC(platformUrl: String, credentialsTokenC: String): String - fun removeCredentialsTokenA(platformUrl: String) - fun removeCredentialsTokenB(platformUrl: String) - fun removeCredentialsTokenC(platformUrl: String) - fun removeVersion(platformUrl: String) - fun removeEndpoints(platformUrl: String) -} diff --git a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/credentials/services/CredentialsClientService.kt b/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/credentials/services/CredentialsClientService.kt deleted file mode 100644 index 4f08b9db..00000000 --- a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/credentials/services/CredentialsClientService.kt +++ /dev/null @@ -1,185 +0,0 @@ -package com.izivia.ocpi.toolkit.modules.credentials.services - -import com.izivia.ocpi.toolkit.common.* -import com.izivia.ocpi.toolkit.modules.credentials.domain.Credentials -import com.izivia.ocpi.toolkit.modules.credentials.repositories.PlatformRepository -import com.izivia.ocpi.toolkit.modules.locations.domain.BusinessDetails -import com.izivia.ocpi.toolkit.modules.versions.VersionDetailsClient -import com.izivia.ocpi.toolkit.modules.versions.VersionsClient -import com.izivia.ocpi.toolkit.modules.versions.domain.Endpoint -import com.izivia.ocpi.toolkit.modules.versions.domain.ModuleID -import com.izivia.ocpi.toolkit.modules.versions.domain.parseVersionNumber -import com.izivia.ocpi.toolkit.modules.versions.repositories.VersionsRepository -import com.izivia.ocpi.toolkit.transport.TransportClientBuilder - -/** - * Automates authentification process - * - * Note: credentialsClient & versionsClient must target the same platform since the automated process will check the - * versions of the receiver before performing registration. - * - * - Client: the one doing the registration process - * - Server: the one receiving the registration process - * - * @property clientVersionsEndpointUrl the versions endpoints url of the client (for the server to use) - * @property clientPlatformRepository client's repository to store and retrieve tokens and information about platforms - * @property clientVersionsRepository client's repository to retrieve available versions on the client - * @property clientBusinessDetails Details of this party. - * @property clientPartyId (max-length=3) CPO or eMSP ID of this party. (following the 15118 ISO standard). - * @property clientCountryCode(max-length=2) Country code of the country this party is operating in. - * @property serverVersionsEndpointUrl the versions endpoint url of the server (for the client to retrieve endpoints) - * @property transportClientBuilder used to build a transport (will be used to create CredentialClient to make calls) - */ -class CredentialsClientService( - private val clientVersionsEndpointUrl: String, - private val clientPlatformRepository: PlatformRepository, - private val clientVersionsRepository: VersionsRepository, - private val clientBusinessDetails: BusinessDetails, - private val clientPartyId: String, - private val clientCountryCode: String, - private val serverVersionsEndpointUrl: String, - private val transportClientBuilder: TransportClientBuilder -) { - fun get(): Credentials = clientPlatformRepository - .getCredentialsTokenC(platformUrl = serverVersionsEndpointUrl) - ?.let { tokenC -> - buildCredentialClient() - .get(tokenC = tokenC) - .let { it.data ?: throw OcpiResponseException(it.status_code, it.status_message ?: "unknown") } - } - ?: throw OcpiClientGenericException("Could not find CREDENTIALS_TOKEN_C associated with platform $serverVersionsEndpointUrl") - - /** - * To start using OCPI, the Platforms will need to exchange credentials tokens. - * - * To start the exchange of credentials tokens, one platform has to be selected as Sender for the Credentials - * module. This has to be decided between the Platforms (outside of OCPI) before they first connect. - * - * To start the credentials exchange, the Receiver Platform must create a unique credentials token: - * CREDENTIALS_TOKEN_A that has to be used to authorize the Sender until the credentials exchange is finished. This - * credentials token along with the versions endpoint SHOULD be sent to the Sender in a secure way that is outside - * the scope of this protocol. - * - * The Sender starts the registration process, retrieves the version information and details (using - * CREDENTIALS_TOKEN_A in the HTTP Authorization header). The Sender generates a unique credentials token: - * CREDENTIALS_TOKEN_B, sends it to the Receiver in a POST request to the credentials module of the Receiver. The - * Receiver stores CREDENTIALS_TOKEN_B and uses it for any requests to the Sender Platform, including the version - * information and details. - * - * The Receiver generates a unique credentials token: CREDENTIALS_TOKEN_C and returns it to the Sender in the - * response to the POST request from the Sender. - * - * After the credentials exchange has finished, the Sender SHALL use CREDENTIALS_TOKEN_C in future OCPI request to - * the Receiver Platform. The CREDENTIALS_TOKEN_A can then be thrown away, it MAY no longer be used. - * - * @return the credentials to use when communicating with the server (receiver) - */ - fun register(): Credentials { - // Get token provided by receiver outside the OCPI protocol (for example by an admin) - val credentialsTokenA = clientPlatformRepository.getCredentialsTokenA(platformUrl = serverVersionsEndpointUrl) - ?: throw OcpiClientInvalidParametersException("Could not find token A associated with platform $serverVersionsEndpointUrl") - - findLatestMutualVersionAndSaveInformation() - - // Generate token B - val credentialsTokenB = clientPlatformRepository.saveCredentialsTokenB( - platformUrl = serverVersionsEndpointUrl, - credentialsTokenB = generateUUIDv4Token() - ) - - // Initiate registration process - val credentials = buildCredentialClient().post( - tokenA = credentialsTokenA, - credentials = Credentials( - token = credentialsTokenB, - url = clientVersionsEndpointUrl, - business_details = clientBusinessDetails, - party_id = clientPartyId, - country_code = clientCountryCode - ) - ).let { - it.data ?: throw OcpiResponseException(it.status_code, it.status_message ?: "unknown") - } - - // Store token C - clientPlatformRepository.saveCredentialsTokenC( - platformUrl = serverVersionsEndpointUrl, - credentialsTokenC = credentials.token - ) - - // Remove token A and B because it is useless from now on - clientPlatformRepository.removeCredentialsTokenA(platformUrl = serverVersionsEndpointUrl) - clientPlatformRepository.removeCredentialsTokenB(platformUrl = serverVersionsEndpointUrl) - - return credentials - } - - fun delete() = clientPlatformRepository - .getCredentialsTokenC(platformUrl = serverVersionsEndpointUrl) - ?.let { tokenC -> - buildCredentialClient() - .delete(tokenC = tokenC) - .also { - clientPlatformRepository.removeCredentialsTokenC(platformUrl = serverVersionsEndpointUrl) - } - .also { - if (it.status_code != OcpiStatus.SUCCESS.code) - throw OcpiResponseException(it.status_code, it.status_message ?: "unknown") - } - } - ?: throw OcpiClientGenericException("Could not find CREDENTIALS_TOKEN_C associated with platform $serverVersionsEndpointUrl") - - private fun findLatestMutualVersionAndSaveInformation(): List { - val availableServerVersions = VersionsClient( - transportClientBuilder = transportClientBuilder, - serverVersionsEndpointUrl = serverVersionsEndpointUrl, - platformRepository = clientPlatformRepository - ) - .getVersions() - .let { - it.data ?: throw OcpiResponseException(it.status_code, it.status_message ?: "unknown") - } - val availableClientVersions = clientVersionsRepository.getVersions() - - // Get available versions and pick latest mutual - val latestMutualVersion = availableServerVersions - .sortedByDescending { clientVersion -> parseVersionNumber(clientVersion.version)!!.index } - .firstOrNull { serverVersion -> - availableClientVersions - .any { clientVersion -> serverVersion.version == clientVersion.version } - } - ?: throw OcpiServerUnsupportedVersionException("Could not find mutual version with platform $serverVersionsEndpointUrl") - - // Store version that will be used - clientPlatformRepository.saveVersion(platformUrl = serverVersionsEndpointUrl, version = latestMutualVersion) - - // Get available endpoints for the used version - val versionDetails = VersionDetailsClient( - transportClientBuilder = transportClientBuilder, - serverVersionsEndpointUrl = serverVersionsEndpointUrl, - platformRepository = clientPlatformRepository - ) - .getVersionDetails() - .let { - it.data ?: throw OcpiResponseException(it.status_code, it.status_message ?: "unknown") - } - - return clientPlatformRepository.saveEndpoints(platformUrl = serverVersionsEndpointUrl, endpoints = versionDetails.endpoints) - } - - private fun getOrFindEndpoints(): List = clientPlatformRepository - .getEndpoints(platformUrl = serverVersionsEndpointUrl) - .takeIf { it.isNotEmpty() } - ?: findLatestMutualVersionAndSaveInformation() - - private fun buildCredentialClient(): com.izivia.ocpi.toolkit.modules.credentials.CredentialsClient = - com.izivia.ocpi.toolkit.modules.credentials.CredentialsClient( - transportClient = transportClientBuilder - .build( - baseUrl = getOrFindEndpoints() - .find { it.identifier == ModuleID.credentials } - ?.url - ?: throw OcpiServerUnsupportedVersionException("No credentials endpoint for $serverVersionsEndpointUrl") - ) - ) -} diff --git a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/credentials/services/CredentialsServerService.kt b/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/credentials/services/CredentialsServerService.kt deleted file mode 100644 index bb6435e3..00000000 --- a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/credentials/services/CredentialsServerService.kt +++ /dev/null @@ -1,118 +0,0 @@ -package com.izivia.ocpi.toolkit.modules.credentials.services - -import com.izivia.ocpi.toolkit.common.* -import com.izivia.ocpi.toolkit.modules.credentials.domain.Credentials -import com.izivia.ocpi.toolkit.modules.credentials.repositories.PlatformRepository -import com.izivia.ocpi.toolkit.modules.locations.domain.BusinessDetails -import com.izivia.ocpi.toolkit.modules.versions.VersionDetailsClient -import com.izivia.ocpi.toolkit.modules.versions.VersionsClient -import com.izivia.ocpi.toolkit.modules.versions.domain.VersionNumber -import com.izivia.ocpi.toolkit.transport.TransportClientBuilder - -class CredentialsServerService( - private val platformRepository: PlatformRepository, - private val serverBusinessDetails: BusinessDetails, - private val serverPartyId: String, - private val serverCountryCode: String, - private val transportClientBuilder: TransportClientBuilder, - private val serverVersionsUrl: String -) : com.izivia.ocpi.toolkit.modules.credentials.CredentialsInterface { - - override fun get( - tokenC: String - ): OcpiResponseBody = OcpiResponseBody.of { - platformRepository - .getPlatformUrlByTokenC(tokenC) - ?.let { platformUrl -> - getCredentials( - token = platformRepository.getCredentialsTokenC(platformUrl) - ?: throw OcpiClientInvalidParametersException( - "Could not find CREDENTIALS_TOKEN_C associated with platform $platformUrl" - ) - ) - } - ?: throw OcpiClientInvalidParametersException("Invalid CREDENTIALS_TOKEN_C ($tokenC)") - } - - override fun post( - tokenA: String, - credentials: Credentials - ): OcpiResponseBody = OcpiResponseBody.of { - val platformUrl = platformRepository.savePlatformUrlForTokenA( - tokenA = tokenA, - platformUrl = credentials.url - ) ?: throw OcpiClientInvalidParametersException("Invalid CREDENTIALS_TOKEN_A ($tokenA)") - - platformRepository.saveCredentialsTokenB(platformUrl = credentials.url, credentialsTokenB = credentials.token) - - findLatestMutualVersionAndStoreInformation(credentials = credentials) - - platformRepository.removeCredentialsTokenA(platformUrl = platformUrl) - platformRepository.removeCredentialsTokenB(platformUrl = platformUrl) - - getCredentials( - token = platformRepository.saveCredentialsTokenC( - platformUrl = platformUrl, - credentialsTokenC = generateUUIDv4Token() - ) - ) - } - - override fun delete( - tokenC: String - ): OcpiResponseBody = OcpiResponseBody.of { - platformRepository - .getPlatformUrlByTokenC(tokenC) - ?.also { platformUrl -> - platformRepository.removeVersion(platformUrl = platformUrl) - platformRepository.removeEndpoints(platformUrl = platformUrl) - platformRepository.removeCredentialsTokenC(platformUrl = platformUrl) - } - ?: throw OcpiClientInvalidParametersException("Invalid CREDENTIALS_TOKEN_C ($tokenC)") - - null - } - - private fun findLatestMutualVersionAndStoreInformation(credentials: Credentials) { - val versions = VersionsClient( - transportClientBuilder = transportClientBuilder, - serverVersionsEndpointUrl = credentials.url, - platformRepository = platformRepository - ) - .getVersions() - .let { - it.data - ?: throw OcpiServerGenericException( - "Could not get versions of sender, there was an error during the call: '${it.status_message}'" - ) - } - - val matchingVersion = versions.firstOrNull { it.version == VersionNumber.V2_1_1.value } - ?: throw OcpiServerNoMatchingEndpointsException("Expected version 2.1.1 from $versions") - - platformRepository.saveVersion(platformUrl = credentials.url, version = matchingVersion) - - val versionDetail = VersionDetailsClient( - transportClientBuilder = transportClientBuilder, - serverVersionsEndpointUrl = credentials.url, - platformRepository = platformRepository - ) - .getVersionDetails() - .let { - it.data - ?: throw OcpiServerGenericException( - "Could not get version of sender, there was an error during the call: '${it.status_message}'" - ) - } - - platformRepository.saveEndpoints(platformUrl = credentials.url, endpoints = versionDetail.endpoints) - } - - private fun getCredentials(token: String): Credentials = Credentials( - token = token, - url = serverVersionsUrl, - business_details = serverBusinessDetails, - party_id = serverPartyId, - country_code = serverCountryCode - ) -} diff --git a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/LocationsCpoClient.kt b/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/LocationsCpoClient.kt deleted file mode 100644 index ccaa40d3..00000000 --- a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/LocationsCpoClient.kt +++ /dev/null @@ -1,177 +0,0 @@ -package com.izivia.ocpi.toolkit.modules.locations - -import com.izivia.ocpi.toolkit.common.* -import com.izivia.ocpi.toolkit.modules.credentials.repositories.PlatformRepository -import com.izivia.ocpi.toolkit.modules.locations.domain.* -import com.izivia.ocpi.toolkit.modules.versions.domain.ModuleID -import com.izivia.ocpi.toolkit.transport.TransportClient -import com.izivia.ocpi.toolkit.transport.TransportClientBuilder -import com.izivia.ocpi.toolkit.transport.domain.HttpMethod -import com.izivia.ocpi.toolkit.transport.domain.HttpRequest - -/** - * Sends calls to an eMSP server - * @property transportClientBuilder used to build transport client - * @property serverVersionsEndpointUrl used to know which platform to communicate with - * @property platformRepository used to get information about the platform (endpoint, token) - */ -class LocationsCpoClient( - private val transportClientBuilder: TransportClientBuilder, - private val serverVersionsEndpointUrl: String, - private val platformRepository: PlatformRepository -) : LocationsEmspInterface { - - private fun buildTransport(): TransportClient = transportClientBuilder - .buildFor( - module = ModuleID.locations, - platformUrl = serverVersionsEndpointUrl, - platformRepository = platformRepository - ) - - override fun getLocation( - countryCode: String, - partyId: String, - locationId: String - ): OcpiResponseBody = - buildTransport() - .send( - HttpRequest( - method = HttpMethod.GET, - path = "/$countryCode/$partyId/$locationId" - ).authenticate(platformRepository = platformRepository, baseUrl = serverVersionsEndpointUrl) - ) - .parseBody() - - override fun getEvse( - countryCode: String, - partyId: String, - locationId: String, - evseUid: String - ): OcpiResponseBody = - buildTransport() - .send( - HttpRequest( - method = HttpMethod.GET, - path = "/$countryCode/$partyId/$locationId/$evseUid" - ).authenticate(platformRepository = platformRepository, baseUrl = serverVersionsEndpointUrl) - ) - .parseBody() - - override fun getConnector( - countryCode: String, - partyId: String, - locationId: String, - evseUid: String, - connectorId: String - ): OcpiResponseBody = - buildTransport() - .send( - HttpRequest( - method = HttpMethod.GET, - path = "/$countryCode/$partyId/$locationId/$evseUid/$connectorId", - ).authenticate(platformRepository = platformRepository, baseUrl = serverVersionsEndpointUrl) - ) - .parseBody() - - override fun putLocation( - countryCode: String, - partyId: String, - locationId: String, - location: Location - ): OcpiResponseBody = - buildTransport() - .send( - HttpRequest( - method = HttpMethod.PUT, - path = "/$countryCode/$partyId/$locationId", - body = mapper.writeValueAsString(location) - ).authenticate(platformRepository = platformRepository, baseUrl = serverVersionsEndpointUrl) - ) - .parseBody() - - override fun putEvse( - countryCode: String, - partyId: String, - locationId: String, - evseUid: String, - evse: Evse - ): OcpiResponseBody = - buildTransport() - .send( - HttpRequest( - method = HttpMethod.PUT, - path = "/$countryCode/$partyId/$locationId/$evseUid", - body = mapper.writeValueAsString(evse) - ).authenticate(platformRepository = platformRepository, baseUrl = serverVersionsEndpointUrl) - ) - .parseBody() - - override fun putConnector( - countryCode: String, - partyId: String, - locationId: String, - evseUid: String, - connectorId: String, - connector: Connector - ): OcpiResponseBody = - buildTransport() - .send( - HttpRequest( - method = HttpMethod.PUT, - path = "/$countryCode/$partyId/$locationId/$evseUid/$connectorId", - body = mapper.writeValueAsString(connector) - ).authenticate(platformRepository = platformRepository, baseUrl = serverVersionsEndpointUrl) - ) - .parseBody() - - override fun patchLocation( - countryCode: String, - partyId: String, - locationId: String, - location: LocationPartial - ): OcpiResponseBody = - buildTransport() - .send( - HttpRequest( - method = HttpMethod.PATCH, - path = "/$countryCode/$partyId/$locationId", - body = mapper.writeValueAsString(location) - ).authenticate(platformRepository = platformRepository, baseUrl = serverVersionsEndpointUrl) - ) - .parseBody() - - override fun patchEvse( - countryCode: String, - partyId: String, - locationId: String, - evseUid: String, - evse: EvsePartial - ): OcpiResponseBody = - buildTransport() - .send( - HttpRequest( - method = HttpMethod.PATCH, - path = "/$countryCode/$partyId/$locationId", - body = mapper.writeValueAsString(evse) - ).authenticate(platformRepository = platformRepository, baseUrl = serverVersionsEndpointUrl) - ) - .parseBody() - - override fun patchConnector( - countryCode: String, - partyId: String, - locationId: String, - evseUid: String, - connectorId: String, - connector: ConnectorPartial - ): OcpiResponseBody = - buildTransport() - .send( - HttpRequest( - method = HttpMethod.PATCH, - path = "/$countryCode/$partyId/$locationId", - body = mapper.writeValueAsString(connector) - ).authenticate(platformRepository = platformRepository, baseUrl = serverVersionsEndpointUrl) - ) - .parseBody() -} diff --git a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/LocationsCpoInterface.kt b/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/LocationsCpoInterface.kt deleted file mode 100644 index 0dd98d2b..00000000 --- a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/LocationsCpoInterface.kt +++ /dev/null @@ -1,65 +0,0 @@ -package com.izivia.ocpi.toolkit.modules.locations - -import com.izivia.ocpi.toolkit.common.OcpiResponseBody -import com.izivia.ocpi.toolkit.common.SearchResult -import com.izivia.ocpi.toolkit.modules.locations.domain.Connector -import com.izivia.ocpi.toolkit.modules.locations.domain.Evse -import com.izivia.ocpi.toolkit.modules.locations.domain.Location -import java.time.Instant - -/** - * CPO Interface - * - * - GET: Fetch a list locations, last updated between the {date_from} and {date_to} (paginated), or get a specific - * location, EVSE or Connector. - * - POST: n/a - * - PUT: n/a - * - PATCH: n/a - * - DELETE: n/a - */ -interface LocationsCpoInterface { - - /** - * If additional parameters: {date_from} and/or {date_to} are provided, only Locations with - * (last_updated) between the given date_from and date_to will be returned. If an EVSE is - * updated, also the 'parent' Location's last_updated fields is updated. If a Connector is - * updated, the EVSE's last_updated and the Location's last_updated field are updated. - * - * This request is paginated, it supports the pagination related URL parameters. - * - * @param dateFrom Instant? Only return Locations that have last_updated after this Date/Time. - * @param dateTo Instant? Only return Locations that have last_updated before this Date/Time. - * @param offset Int? The offset of the first object returned. Default is 0. - * @param limit Int? Maximum number of objects to GET. - * @return List The endpoint returns a list of Location objects The header will - * contain the pagination related headers. - */ - fun getLocations( - dateFrom: Instant?, - dateTo: Instant?, - offset: Int = 0, - limit: Int? - ): OcpiResponseBody> - - /** - * @param locationId String max-length = 39 - */ - fun getLocation(locationId: String): OcpiResponseBody - - /** - * @param locationId String max-length = 39 - * @param evseUid String? max-length = 39 - */ - fun getEvse(locationId: String, evseUid: String): OcpiResponseBody - - /** - * @param locationId String max-length = 39 - * @param evseUid max-length = 39 - * @param connectorId max-length = 36 - */ - fun getConnector( - locationId: String, - evseUid: String, - connectorId: String - ): OcpiResponseBody -} \ No newline at end of file diff --git a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/LocationsCpoServer.kt b/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/LocationsCpoServer.kt deleted file mode 100644 index ddbd8732..00000000 --- a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/LocationsCpoServer.kt +++ /dev/null @@ -1,97 +0,0 @@ -package com.izivia.ocpi.toolkit.modules.locations - -import com.izivia.ocpi.toolkit.common.httpResponse -import com.izivia.ocpi.toolkit.common.checkToken -import com.izivia.ocpi.toolkit.modules.credentials.repositories.PlatformRepository -import com.izivia.ocpi.toolkit.transport.TransportServer -import com.izivia.ocpi.toolkit.transport.domain.FixedPathSegment -import com.izivia.ocpi.toolkit.transport.domain.HttpMethod -import com.izivia.ocpi.toolkit.transport.domain.VariablePathSegment -import kotlinx.coroutines.runBlocking -import java.time.Instant - -/** - * Receives calls from a CPO - * @property transportServer - */ -class LocationsCpoServer( - private val transportServer: TransportServer, - private val platformRepository: PlatformRepository, - private val service: LocationsCpoInterface, - basePath: List = listOf( - FixedPathSegment("/2.1.1/locations") - ) -) { - init { - runBlocking { - transportServer.handle( - method = HttpMethod.GET, - path = basePath, - queryParams = listOf("date_from", "date_to", "offset", "limit"), - filters = listOf(platformRepository::checkToken) - ) { req -> - req.httpResponse { - val dateFrom = req.queryParams["date_from"] - val dateTo = req.queryParams["date_to"] - - service - .getLocations( - dateFrom = dateFrom?.let { Instant.parse(it) }, - dateTo = dateTo?.let { Instant.parse(it) }, - offset = req.queryParams["offset"]?.toInt() ?: 0, - limit = req.queryParams["limit"]?.toInt() - ) - } - } - - transportServer.handle( - method = HttpMethod.GET, - path = basePath + VariablePathSegment("locationId"), - filters = listOf(platformRepository::checkToken) - ) { req -> - req.httpResponse { - service - .getLocation( - locationId = req.pathParams["locationId"]!! - ) - } - } - - transportServer.handle( - method = HttpMethod.GET, - path = basePath + listOf( - VariablePathSegment("locationId"), - VariablePathSegment("evseUid") - ), - filters = listOf(platformRepository::checkToken) - ) { req -> - req.httpResponse { - service - .getEvse( - locationId = req.pathParams["locationId"]!!, - evseUid = req.pathParams["evseUid"]!! - ) - } - } - - transportServer.handle( - method = HttpMethod.GET, - path = basePath + listOf( - VariablePathSegment("locationId"), - VariablePathSegment("evseUid"), - VariablePathSegment("connectorId") - ), - filters = listOf(platformRepository::checkToken) - ) { req -> - req.httpResponse { - service - .getConnector( - locationId = req.pathParams["locationId"]!!, - evseUid = req.pathParams["evseUid"]!!, - connectorId = req.pathParams["connectorId"]!! - ) - } - } - } - } -} diff --git a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/LocationsEmspClient.kt b/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/LocationsEmspClient.kt deleted file mode 100644 index e669338e..00000000 --- a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/LocationsEmspClient.kt +++ /dev/null @@ -1,87 +0,0 @@ -package com.izivia.ocpi.toolkit.modules.locations - -import com.izivia.ocpi.toolkit.common.* -import com.izivia.ocpi.toolkit.modules.credentials.repositories.PlatformRepository -import com.izivia.ocpi.toolkit.modules.locations.domain.Connector -import com.izivia.ocpi.toolkit.modules.locations.domain.Evse -import com.izivia.ocpi.toolkit.modules.locations.domain.Location -import com.izivia.ocpi.toolkit.modules.versions.domain.ModuleID -import com.izivia.ocpi.toolkit.transport.TransportClient -import com.izivia.ocpi.toolkit.transport.TransportClientBuilder -import com.izivia.ocpi.toolkit.transport.domain.HttpMethod -import com.izivia.ocpi.toolkit.transport.domain.HttpRequest -import java.time.Instant - -/** - * Sends calls to the CPO - * @property transportClientBuilder used to build transport client - * @property serverVersionsEndpointUrl used to know which platform to communicate with - * @property platformRepository used to get information about the platform (endpoint, token) - */ -class LocationsEmspClient( - private val transportClientBuilder: TransportClientBuilder, - private val serverVersionsEndpointUrl: String, - private val platformRepository: PlatformRepository -) : LocationsCpoInterface { - - private fun buildTransport(): TransportClient = transportClientBuilder - .buildFor( - module = ModuleID.locations, - platformUrl = serverVersionsEndpointUrl, - platformRepository = platformRepository - ) - - override fun getLocations( - dateFrom: Instant?, - dateTo: Instant?, - offset: Int, - limit: Int? - ): OcpiResponseBody> = - buildTransport() - .send( - HttpRequest( - method = HttpMethod.GET, - queryParams = listOfNotNull( - dateFrom?.let { "date_from" to dateFrom.toString() }, - dateTo?.let { "date_to" to dateTo.toString() }, - "offset" to offset.toString(), - limit?.let { "limit" to limit.toString() } - ).toMap() - ).authenticate(platformRepository = platformRepository, baseUrl = serverVersionsEndpointUrl) - ) - .parsePaginatedBody(offset) - - override fun getLocation(locationId: String): OcpiResponseBody = - buildTransport() - .send( - HttpRequest( - method = HttpMethod.GET, - path = "/$locationId" - ).authenticate(platformRepository = platformRepository, baseUrl = serverVersionsEndpointUrl) - ) - .parseBody() - - override fun getEvse(locationId: String, evseUid: String): OcpiResponseBody = - buildTransport() - .send( - HttpRequest( - method = HttpMethod.GET, - path = "/$locationId/$evseUid" - ).authenticate(platformRepository = platformRepository, baseUrl = serverVersionsEndpointUrl) - ) - .parseBody() - - override fun getConnector( - locationId: String, - evseUid: String, - connectorId: String - ): OcpiResponseBody = - buildTransport() - .send( - HttpRequest( - method = HttpMethod.GET, - path = "/$locationId/$evseUid/$connectorId" - ).authenticate(platformRepository = platformRepository, baseUrl = serverVersionsEndpointUrl) - ) - .parseBody() -} diff --git a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/LocationsEmspInterface.kt b/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/LocationsEmspInterface.kt deleted file mode 100644 index 4568cde6..00000000 --- a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/LocationsEmspInterface.kt +++ /dev/null @@ -1,180 +0,0 @@ -package com.izivia.ocpi.toolkit.modules.locations - -import com.izivia.ocpi.toolkit.common.OcpiResponseBody -import com.izivia.ocpi.toolkit.modules.locations.domain.* - -/** - * Locations is a client owned object, so the end-points need to contain the required extra fields: {party_id} and - * {country_code}. Example endpoint structures: - * - /ocpi/emsp/2.1.1/locations/{country_code}/{party_id}/{location_id} - * - /ocpi/emsp/2.1.1/locations/{country_code}/{party_id}/{location_id}/{evse_uid} - * - /ocpi/emsp/2.1.1/locations/{country_code}/{party_id}/{location_id}/{evse_uid}/{connector_id} - * - * Method: Description - * - GET: Retrieve a Location as it is stored in the eMSP system. - * - POST: n/a (use PUT) - * - PUT: Push new/updated Location, EVSE and/or Connectors to the eMSP - * - PATCH: Notify the eMSP of partial updates to a Location, EVSEs or Connector (such as the status). - * - DELETE: n/a (use PATCH) - */ -interface LocationsEmspInterface { - - /** - * If the CPO wants to check the status of a Location, EVSE or Connector object in the eMSP system, it might GET the - * object from the eMSP system for validation purposes. The CPO is the owner of the objects, so it would be - * illogical if the eMSP system had a different status or was missing an object. If a discrepancy is found, the CPO - * might push an update to the eMSP via a PUT or PATCH call. - * - * @param countryCode (max-length=2) Country code of the CPO requesting this PUT to the eMSP system. - * @param partyId (max-length=3) Party ID (Provider ID) of the CPO requesting this PUT to the eMSP system. - * @param locationId (max-length=39) Location.id of the Location object to retrieve. - */ - fun getLocation( - countryCode: String, - partyId: String, - locationId: String - ): OcpiResponseBody - - /** - * If the CPO wants to check the status of a Location, EVSE or Connector object in the eMSP system, it might GET the - * object from the eMSP system for validation purposes. The CPO is the owner of the objects, so it would be - * illogical if the eMSP system had a different status or was missing an object. If a discrepancy is found, the CPO - * might push an update to the eMSP via a PUT or PATCH call. - * - * @param countryCode (max-length=2) Country code of the CPO requesting this PUT to the eMSP system. - * @param partyId (max-length=3) Party ID (Provider ID) of the CPO requesting this PUT to the eMSP system. - * @param locationId (max-length=39) Location.id of the Location object to retrieve. - * @param evseUid (max-length=39) Evse.uid, required when requesting an EVSE or Connector object. - */ - fun getEvse( - countryCode: String, - partyId: String, - locationId: String, - evseUid: String - ): OcpiResponseBody - - /** - * If the CPO wants to check the status of a Location, EVSE or Connector object in the eMSP system, it might GET the - * object from the eMSP system for validation purposes. The CPO is the owner of the objects, so it would be - * illogical if the eMSP system had a different status or was missing an object. If a discrepancy is found, the CPO - * might push an update to the eMSP via a PUT or PATCH call. - * - * @param countryCode (max-length=2) Country code of the CPO requesting this PUT to the eMSP system. - * @param partyId (max-length=3) Party ID (Provider ID) of the CPO requesting this PUT to the eMSP system. - * @param locationId (max-length=39) Location.id of the Location object to retrieve. - * @param evseUid (max-length=39) Evse.uid, required when requesting an EVSE or Connector object. - * @param connectorId (max-length=36) Connector.id, required when requesting a Connector object. - */ - fun getConnector( - countryCode: String, - partyId: String, - locationId: String, - evseUid: String, - connectorId: String - ): OcpiResponseBody - - /** - * The CPO pushes available Location/EVSE or Connector objects to the eMSP. PUT is used to send new Location objects - * to the eMSP, or to replace existing Locations. - * - * @param countryCode (max-length=2) Country code of the CPO requesting this PUT to the eMSP system. - * @param partyId (max-length=3) Party ID (Provider ID) of the CPO requesting this PUT to the eMSP system. - * @param locationId (max-length=39) Location.id of the new Location object, or the Location of which an EVSE or - * Location object is send - */ - fun putLocation( - countryCode: String, - partyId: String, - locationId: String, - location: Location - ): OcpiResponseBody - - /** - * The CPO pushes available Location/EVSE or Connector objects to the eMSP. PUT is used to send new Location objects - * to the eMSP, or to replace existing Locations. - * - * @param countryCode (max-length=2) Country code of the CPO requesting this PUT to the eMSP system. - * @param partyId (max-length=3) Party ID (Provider ID) of the CPO requesting this PUT to the eMSP system. - * @param locationId (max-length=39) Location.id of the new Location object, or the Location of which an EVSE or - * Location object is send - * @param evseUid (max-length=39) Evse.uid, required when an EVSE or Connector object is send/replaced. - */ - fun putEvse( - countryCode: String, - partyId: String, - locationId: String, - evseUid: String, - evse: Evse - ): OcpiResponseBody - - /** - * The CPO pushes available Location/EVSE or Connector objects to the eMSP. PUT is used to send new Location objects - * to the eMSP, or to replace existing Locations. - * - * @param countryCode (max-length=2) Country code of the CPO requesting this PUT to the eMSP system. - * @param partyId (max-length=3) Party ID (Provider ID) of the CPO requesting this PUT to the eMSP system. - * @param locationId (max-length=39) Location.id of the new Location object, or the Location of which an EVSE or - * Location object is send - * @param evseUid (max-length=39) Evse.uid, required when an EVSE or Connector object is send/replaced. - * @param connectorId (max-length=36) Connector.id, required when a Connector object is send/replaced. - */ - fun putConnector( - countryCode: String, - partyId: String, - locationId: String, - evseUid: String, - connectorId: String, - connector: Connector - ): OcpiResponseBody - - /** - * Same as the PUT method, but only the fields/objects that have to be updated have to be present, other - * fields/objects that are not specified are considered unchanged. - * - * @param countryCode (max-length=2) Country code of the CPO requesting this PUT to the eMSP system. - * @param partyId (max-length=3) Party ID (Provider ID) of the CPO requesting this PUT to the eMSP system. - * @param locationId (max-length=39) Location.id of the new Location object - */ - fun patchLocation( - countryCode: String, - partyId: String, - locationId: String, - location: LocationPartial - ): OcpiResponseBody - - /** - * Same as the PUT method, but only the fields/objects that have to be updated have to be present, other - * fields/objects that are not specified are considered unchanged. - * - * @param countryCode (max-length=2) Country code of the CPO requesting this PUT to the eMSP system. - * @param partyId (max-length=3) Party ID (Provider ID) of the CPO requesting this PUT to the eMSP system. - * @param locationId (max-length=39) Location.id of the Location of which an EVSE or Location object is send - * @param evseUid (max-length=39) Evse.uid, required when an EVSE or Connector object is send/replaced. - */ - fun patchEvse( - countryCode: String, - partyId: String, - locationId: String, - evseUid: String, - evse: EvsePartial - ): OcpiResponseBody - - /** - * Same as the PUT method, but only the fields/objects that have to be updated have to be present, other - * fields/objects that are not specified are considered unchanged. - * - * @param countryCode (max-length=2) Country code of the CPO requesting this PUT to the eMSP system. - * @param partyId (max-length=3) Party ID (Provider ID) of the CPO requesting this PUT to the eMSP system. - * @param locationId (max-length=39) Location.id of the Location of which an EVSE or Location object is send - * @param evseUid (max-length=39) Evse.uid, required when an EVSE or Connector object is send/replaced. - * @param connectorId (max-length=36) Connector.id, required when a Connector object is send/replaced. - */ - fun patchConnector( - countryCode: String, - partyId: String, - locationId: String, - evseUid: String, - connectorId: String, - connector: ConnectorPartial - ): OcpiResponseBody -} \ No newline at end of file diff --git a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/LocationsEmspServer.kt b/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/LocationsEmspServer.kt deleted file mode 100644 index c8469991..00000000 --- a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/LocationsEmspServer.kt +++ /dev/null @@ -1,224 +0,0 @@ -package com.izivia.ocpi.toolkit.modules.locations - -import com.izivia.ocpi.toolkit.common.httpResponse -import com.izivia.ocpi.toolkit.common.mapper -import com.izivia.ocpi.toolkit.common.checkToken -import com.izivia.ocpi.toolkit.modules.credentials.repositories.PlatformRepository -import com.izivia.ocpi.toolkit.modules.locations.domain.* -import com.izivia.ocpi.toolkit.transport.TransportServer -import com.izivia.ocpi.toolkit.transport.domain.FixedPathSegment -import com.izivia.ocpi.toolkit.transport.domain.HttpMethod -import com.izivia.ocpi.toolkit.transport.domain.VariablePathSegment -import kotlinx.coroutines.runBlocking - -/** - * Receives calls from a CPO - * @property transportServer - */ -class LocationsEmspServer( - private val transportServer: TransportServer, - private val platformRepository: PlatformRepository, - private val service: LocationsEmspInterface, - basePath: List = listOf( - FixedPathSegment("/2.1.1/locations") - ) -) { - init { - runBlocking { - transportServer.handle( - method = HttpMethod.GET, - path = basePath + listOf( - VariablePathSegment("countryCode"), - VariablePathSegment("partyId"), - VariablePathSegment("locationId") - ), - filters = listOf(platformRepository::checkToken) - ) { req -> - req.httpResponse { - service - .getLocation( - countryCode = req.pathParams["countryCode"]!!, - partyId = req.pathParams["partyId"]!!, - locationId = req.pathParams["locationId"]!! - ) - } - } - - transportServer.handle( - method = HttpMethod.GET, - path = basePath + listOf( - VariablePathSegment("countryCode"), - VariablePathSegment("partyId"), - VariablePathSegment("locationId"), - VariablePathSegment("evseUid") - ), - filters = listOf(platformRepository::checkToken) - ) { req -> - req.httpResponse { - service - .getEvse( - countryCode = req.pathParams["countryCode"]!!, - partyId = req.pathParams["partyId"]!!, - locationId = req.pathParams["locationId"]!!, - evseUid = req.pathParams["evseUid"]!! - ) - } - } - - transportServer.handle( - method = HttpMethod.GET, - path = basePath + listOf( - VariablePathSegment("countryCode"), - VariablePathSegment("partyId"), - VariablePathSegment("locationId"), - VariablePathSegment("evseUid"), - VariablePathSegment("connectorId") - ), - filters = listOf(platformRepository::checkToken) - ) { req -> - req.httpResponse { - service - .getConnector( - countryCode = req.pathParams["countryCode"]!!, - partyId = req.pathParams["partyId"]!!, - locationId = req.pathParams["locationId"]!!, - evseUid = req.pathParams["evseUid"]!!, - connectorId = req.pathParams["connectorId"]!! - ) - } - } - - transportServer.handle( - method = HttpMethod.PUT, - path = basePath + listOf( - VariablePathSegment("countryCode"), - VariablePathSegment("partyId"), - VariablePathSegment("locationId") - ), - filters = listOf(platformRepository::checkToken) - ) { req -> - req.httpResponse { - service - .putLocation( - countryCode = req.pathParams["countryCode"]!!, - partyId = req.pathParams["partyId"]!!, - locationId = req.pathParams["locationId"]!!, - location = mapper.readValue(req.body, Location::class.java) - ) - } - } - - transportServer.handle( - method = HttpMethod.PUT, - path = basePath + listOf( - VariablePathSegment("countryCode"), - VariablePathSegment("partyId"), - VariablePathSegment("locationId"), - VariablePathSegment("evseUid") - ), - filters = listOf(platformRepository::checkToken) - ) { req -> - req.httpResponse { - service - .putEvse( - countryCode = req.pathParams["countryCode"]!!, - partyId = req.pathParams["partyId"]!!, - locationId = req.pathParams["locationId"]!!, - evseUid = req.pathParams["evseUid"]!!, - evse = mapper.readValue(req.body!!, Evse::class.java) - ) - } - } - - transportServer.handle( - method = HttpMethod.PUT, - path = basePath + listOf( - VariablePathSegment("countryCode"), - VariablePathSegment("partyId"), - VariablePathSegment("locationId"), - VariablePathSegment("evseUid"), - VariablePathSegment("connectorId") - ), - filters = listOf(platformRepository::checkToken) - ) { req -> - req.httpResponse { - service - .putConnector( - countryCode = req.pathParams["countryCode"]!!, - partyId = req.pathParams["partyId"]!!, - locationId = req.pathParams["locationId"]!!, - evseUid = req.pathParams["evseUid"]!!, - connectorId = req.pathParams["connectorId"]!!, - connector = mapper.readValue(req.body!!, Connector::class.java) - ) - } - } - - transportServer.handle( - method = HttpMethod.PATCH, - path = basePath + listOf( - VariablePathSegment("countryCode"), - VariablePathSegment("partyId"), - VariablePathSegment("locationId") - ), - filters = listOf(platformRepository::checkToken) - ) { req -> - req.httpResponse { - service - .patchLocation( - countryCode = req.pathParams["countryCode"]!!, - partyId = req.pathParams["partyId"]!!, - locationId = req.pathParams["locationId"]!!, - location = mapper.readValue(req.body!!, LocationPartial::class.java) - ) - } - } - - transportServer.handle( - method = HttpMethod.PATCH, - path = basePath + listOf( - VariablePathSegment("countryCode"), - VariablePathSegment("partyId"), - VariablePathSegment("locationId"), - VariablePathSegment("evseUid") - ), - filters = listOf(platformRepository::checkToken) - ) { req -> - req.httpResponse { - service - .patchEvse( - countryCode = req.pathParams["countryCode"]!!, - partyId = req.pathParams["partyId"]!!, - locationId = req.pathParams["locationId"]!!, - evseUid = req.pathParams["evseUid"]!!, - evse = mapper.readValue(req.body!!, EvsePartial::class.java) - ) - } - } - - transportServer.handle( - method = HttpMethod.PATCH, - path = basePath + listOf( - VariablePathSegment("countryCode"), - VariablePathSegment("partyId"), - VariablePathSegment("locationId"), - VariablePathSegment("evseUid"), - VariablePathSegment("connectorId") - ), - filters = listOf(platformRepository::checkToken) - ) { req -> - req.httpResponse { - service - .patchConnector( - countryCode = req.pathParams["countryCode"]!!, - partyId = req.pathParams["partyId"]!!, - locationId = req.pathParams["locationId"]!!, - evseUid = req.pathParams["evseUid"]!!, - connectorId = req.pathParams["connectorId"]!!, - connector = mapper.readValue(req.body!!, ConnectorPartial::class.java) - ) - } - } - } - } -} diff --git a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/AdditionalGeoLocation.kt b/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/AdditionalGeoLocation.kt deleted file mode 100644 index b1ee5c47..00000000 --- a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/AdditionalGeoLocation.kt +++ /dev/null @@ -1,22 +0,0 @@ -package com.izivia.ocpi.toolkit.modules.locations.domain - -import com.izivia.ocpi.toolkit.annotations.Partial -import com.izivia.ocpi.toolkit.modules.types.DisplayText - -/** - * This class defines an additional geolocation that is relevant for the Charge Point. The geodetic system to be used - * is WGS 84. - * - * @property latitude String (max-length=10) Latitude of the point in decimal degree. Example: 50.770774. Decimal - * separator: "." Regex: -?[0-9]{1,2}\.[0-9]{6} - * @property longitude String (max-length=11) Longitude of the point in decimal degree. Example: -126.104965. Decimal - * separator: "." Regex: -?[0-9]{1,3}\.[0-9]{6} - * @property name DisplayText? Name of the point in local language or as written at the location. For example the street - * name of a parking lot entrance, or its number. - */ -@Partial -data class AdditionalGeoLocation( - val latitude: String, - val longitude: String, - val name: DisplayText? -) diff --git a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/BusinessDetails.kt b/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/BusinessDetails.kt deleted file mode 100644 index 647fa96e..00000000 --- a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/BusinessDetails.kt +++ /dev/null @@ -1,16 +0,0 @@ -package com.izivia.ocpi.toolkit.modules.locations.domain - -import com.izivia.ocpi.toolkit.annotations.Partial - -/** - * @property name (max-length=100) Name of the operator. - * @property website Link (string(255) type following the w3.org spec. to the operator's website. - * @property logo Image link to the operator's logo. - * @constructor - */ -@Partial -data class BusinessDetails( - val name: String, - val website: String?, - val logo: Image? -) \ No newline at end of file diff --git a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/Capability.kt b/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/Capability.kt deleted file mode 100644 index 77193eb5..00000000 --- a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/Capability.kt +++ /dev/null @@ -1,36 +0,0 @@ -package com.izivia.ocpi.toolkit.modules.locations.domain - -/** - * The capabilities of an EVSE. - */ -enum class Capability { - /** - * The EVSE supports charging profiles. Sending Charging Profiles is not yet supported by OCPI. - */ - CHARGING_PROFILE_CAPABLE, - - /** - * Charging at this EVSE can be payed with credit card. - */ - CREDIT_CARD_PAYABLE, - - /** - * The EVSE can remotely be started/stopped. - */ - REMOTE_START_STOP_CAPABLE, - - /** - * The EVSE can be reserved. - */ - RESERVABLE, - - /** - * Charging at this EVSE can be authorized with an RFID token - */ - RFID_READER, - - /** - * Connectors have mechanical lock that can be requested by the eMSP to be unlocked. - */ - UNLOCK_CAPABLE -} diff --git a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/Connector.kt b/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/Connector.kt deleted file mode 100644 index 236ff947..00000000 --- a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/Connector.kt +++ /dev/null @@ -1,34 +0,0 @@ -package com.izivia.ocpi.toolkit.modules.locations.domain - -import com.izivia.ocpi.toolkit.annotations.Partial -import java.time.Instant - -/** - * A connector is the socket or cable available for the EV to use. A single EVSE may provide multiple connectors but - * only one of them can be in use at the same time. A connector always belongs to an EVSE object. - * - * @property id (max-length=36) Identifier of the connector within the EVSE. Two connectors may have the same id as long - * as they do not belong to the same EVSE object. - * @property standard The standard of the installed connector. - * @property format The format (socket/cable) of the installed connector. - * @property power_type - * @property voltage Voltage of the connector (line to neutral for AC_3_PHASE), in volt V. - * @property amperage maximum amperage of the connector, in ampere A. - * @property tariff_id (max-length=36) Identifier of the current charging tariff structure. For a "Free of Charge" - * tariff this field should be set, and point to a defined "Free of Charge" tariff. - * @property terms_and_conditions URL (string(255) type following the w3.org spec. to the operator's terms and - * conditions - * @property last_updated Timestamp when this Connectors was last updated (or created). - */ -@Partial -data class Connector( - val id: String, - val standard: ConnectorType, - val format: ConnectorFormat, - val power_type: PowerType, - val voltage: Int, - val amperage: Int, - val tariff_id: String?, - val terms_and_conditions: String?, - val last_updated: Instant -) \ No newline at end of file diff --git a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/ConnectorFormat.kt b/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/ConnectorFormat.kt deleted file mode 100644 index 0b0f38bc..00000000 --- a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/ConnectorFormat.kt +++ /dev/null @@ -1,16 +0,0 @@ -package com.izivia.ocpi.toolkit.modules.locations.domain - -/** - * The format of the connector, whether it is a socket or a plug. - */ -enum class ConnectorFormat { - /** - * The connector is a socket; the EV user needs to bring a fitting plug. - */ - SOCKET, - - /** - * The connector is an attached cable; the EV users car needs to have a fitting inlet. - */ - CABLE -} \ No newline at end of file diff --git a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/ConnectorType.kt b/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/ConnectorType.kt deleted file mode 100644 index 1d1a3ba2..00000000 --- a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/ConnectorType.kt +++ /dev/null @@ -1,131 +0,0 @@ -package com.izivia.ocpi.toolkit.modules.locations.domain - -/** - * The socket or plug standard of the charging point. - */ -enum class ConnectorType { - /** - * The connector type is CHAdeMO, DC - */ - CHADEMO, - - /** - * Standard/Domestic household, type "A", NEMA 1-15, 2 pins - */ - DOMESTIC_A, - - /** - * Standard/Domestic household, type "B", NEMA 5-15, 3 pins - */ - DOMESTIC_B, - - /** - * Standard/Domestic household, type "C", CEE 7/17, 2 pins - */ - DOMESTIC_C, - - /** - * Standard/Domestic household, type "D", 3 pin - */ - DOMESTIC_D, - - /** - * Standard/Domestic household, type "E", CEE 7/5 3 pins - */ - DOMESTIC_E, - - /** - * Standard/Domestic household, type "F", CEE 7/4, Schuko, 3 pins - */ - DOMESTIC_F, - - /** - * Standard/Domestic household, type "G", BS 1363, Commonwealth, 3 pins - */ - DOMESTIC_G, - - /** - * Standard/Domestic household, type "H", SI-32, 3 pins - */ - DOMESTIC_H, - - /** - * Standard/Domestic household, type "I", AS 3112, 3 pins - */ - DOMESTIC_I, - - /** - * Standard/Domestic household, type "J", SEV 1011, 3 pins - */ - DOMESTIC_J, - - /** - * Standard/Domestic household, type "K", DS 60884-2-D1, 3 pins - */ - DOMESTIC_K, - - /** - * Standard/Domestic household, type "L", CEI 23-16-VII, 3 pins - */ - DOMESTIC_L, - - /** - * IEC 60309-2 Industrial Connector single phase 16 Amperes (usually blue) - */ - IEC_60309_2_single_16, - - /** - * IEC 60309-2 Industrial Connector three phase 16 Amperes (usually red) - */ - IEC_60309_2_three_16, - - /** - * IEC 60309-2 Industrial Connector three phase 32 Amperes (usually red) - */ - IEC_60309_2_three_32, - - /** - * IEC 60309-2 Industrial Connector three phase 64 Amperes (usually red) - */ - IEC_60309_2_three_64, - - /** - * IEC 62196 Type 1 "SAE J1772" - */ - IEC_62196_T1, - - /** - * Combo Type 1 based, DC - */ - IEC_62196_T1_COMBO, - - /** - * IEC 62196 Type 2 "Mennekes" - */ - IEC_62196_T2, - - /** - * Combo Type 2 based, DC - */ - IEC_62196_T2_COMBO, - - /** - * IEC 62196 Type 3A - */ - IEC_62196_T3A, - - /** - * IEC 62196 Type 3C "Scame" - */ - IEC_62196_T3C, - - /** - * Tesla Connector "Roadster"-type (round, 4 pin) - */ - TESLA_R, - - /** - * Tesla Connector "Model-S"-type (oval, 5 pin) - */ - TESLA_S -} \ No newline at end of file diff --git a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/EnergyMix.kt b/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/EnergyMix.kt deleted file mode 100644 index b4e2c481..00000000 --- a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/EnergyMix.kt +++ /dev/null @@ -1,28 +0,0 @@ -package com.izivia.ocpi.toolkit.modules.locations.domain - -import com.izivia.ocpi.toolkit.annotations.Partial - -/** - * This type is used to specify the energy mix and environmental impact of the supplied energy at a location or in a - * tariff. - * - * @property is_green_energy True if 100% from regenerative sources. (CO2 and nuclear waste is zero) - * @property energy_sources Key-value pairs (enum + percentage) of energy sources of this location's tariff. - * @property environ_impact Key-value pairs (enum + percentage) of nuclear waste and CO2 exhaust of this location's - * tariff. - * @property supplier_name (max-length=64) Name of the energy supplier, delivering the energy for this location or - * tariff. ** - * @property energy_product_name (max-length=64) Name of the energy suppliers product/tariff plan used at this - * location. ** - * - * ** These fields can be used to look-up energy qualification or to show it directly to the customer (for well-known - * brands like Greenpeace Energy, etc.) - */ -@Partial -data class EnergyMix( - val is_green_energy: Boolean, - val energy_sources: List?, - val environ_impact: List?, - val supplier_name: String?, - val energy_product_name: String? -) \ No newline at end of file diff --git a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/EnergySource.kt b/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/EnergySource.kt deleted file mode 100644 index de37b4a9..00000000 --- a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/EnergySource.kt +++ /dev/null @@ -1,16 +0,0 @@ -package com.izivia.ocpi.toolkit.modules.locations.domain - -import com.izivia.ocpi.toolkit.annotations.Partial -import java.math.BigDecimal - -/** - * Key-value pairs (enum + percentage) of energy sources. All given values should add up to 100 percent per category. - * - * @property source The type of energy source. - * @property percentage Percentage of this source (0-100) in the mix. - */ -@Partial -data class EnergySource( - val source: EnergySourceCategory, - val percentage: BigDecimal -) diff --git a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/EnergySourceCategory.kt b/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/EnergySourceCategory.kt deleted file mode 100644 index 2df3e7ed..00000000 --- a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/EnergySourceCategory.kt +++ /dev/null @@ -1,46 +0,0 @@ -package com.izivia.ocpi.toolkit.modules.locations.domain - -/** - * Categories of energy sources. - */ -enum class EnergySourceCategory { - /** - * Nuclear power sources. - */ - NUCLEAR, - - /** - * All kinds of fossil power sources. - */ - GENERAL_FOSSIL, - - /** - * Fossil power from coal. - */ - COAL, - - /** - * Fossil power from gas. - */ - GAS, - - /** - * All kinds of regenerative power sources. - */ - GENERAL_GREEN, - - /** - * Regenerative power from PV. - */ - SOLAR, - - /** - * Regenerative power from wind turbines. - */ - WIND, - - /** - * Regenerative power from water turbines. - */ - WATER -} \ No newline at end of file diff --git a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/EnvironmentalImpact.kt b/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/EnvironmentalImpact.kt deleted file mode 100644 index e1755b85..00000000 --- a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/EnvironmentalImpact.kt +++ /dev/null @@ -1,15 +0,0 @@ -package com.izivia.ocpi.toolkit.modules.locations.domain - -import com.izivia.ocpi.toolkit.annotations.Partial -import java.math.BigDecimal - -/** - * Key-value pairs (enum + amount) of waste and carbon dioxide emittion per kWh. - * @property source The category of this value. - * @property amount Amount of this portion in g/kWh. - */ -@Partial -data class EnvironmentalImpact( - val source: EnvironmentalImpactCategory, - val amount: BigDecimal -) \ No newline at end of file diff --git a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/EnvironmentalImpactCategory.kt b/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/EnvironmentalImpactCategory.kt deleted file mode 100644 index 715274c5..00000000 --- a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/EnvironmentalImpactCategory.kt +++ /dev/null @@ -1,16 +0,0 @@ -package com.izivia.ocpi.toolkit.modules.locations.domain - -/** - * Categories of environmental impact values. - */ -enum class EnvironmentalImpactCategory { - /** - * Produced nuclear waste in gramms per kilowatthour - */ - NUCLEAR_WASTE, - - /** - * Exhausted carbon dioxide in gramms per kilowarrhour - */ - CARBON_DIOXIDE -} diff --git a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/Evse.kt b/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/Evse.kt deleted file mode 100644 index 9a16f88b..00000000 --- a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/Evse.kt +++ /dev/null @@ -1,56 +0,0 @@ -package com.izivia.ocpi.toolkit.modules.locations.domain - -import com.izivia.ocpi.toolkit.annotations.Partial -import com.izivia.ocpi.toolkit.modules.types.DisplayText -import java.time.Instant - -/** - * The EVSE object describes the part that controls the power supply to a single EV in a single session. It always - * belongs to a Location object. It will only contain directions to get from the location to the EVSE (i.e. floor, - * physical_reference or directions). When these properties are insufficient to reach the EVSE from the Location point, - * then it typically indicates that this EVSE should be put in a different Location object (sometimes with the same - * address but with different coordinates/directions). - * - * An EVSE object has a list of connectors which can not be used simultaneously: only one connector per EVSE can be used - * at the time. - * - * @property uid (max-length=39) Uniquely identifies the EVSE within the CPOs platform (and suboperator platforms). For - * example a database unique ID or the "EVSE ID". This field can never be changed, modified or renamed. This is the - * 'technical' identification of the EVSE, not to be used as 'human readable' identification, use the field: evse_id for - * that. - * @property evse_id Compliant with the following specification for EVSE ID from "eMI3 standard version V1.0" - * (http://emi3group.com/documents-links/) "Part 2: business objects." Optional for OCPI because: if an EVSE ID is to be - * re-used the EVSE ID can be removed from an EVSE that is removed (status: REMOVED). BUT REQUIRED for gireve: required - * by GIREVE to ensure seamless compatibility with operators connected via other protocols (eMIP, ...). In addition, the - * eMI3 standard requires that the eMI3 Id of an EVSE begins by the eMI3 Id of the CPO. - * @property status Indicates the current status of the EVSE. - * @property status_schedule Indicates a planned status in the future of the EVSE. - * @property capabilities List of functionalities that the EVSE is capable of. - * @property connectors (at least one in the list) List of available connectors on the EVSE. - * @property floor_level (max-length=4) Level on which the charging station is located (in garage buildings) in the - * locally displayed numbering scheme. - * @property coordinates Coordinates of the EVSE. - * @property physical_reference (max-length=16) A number/string printed on the outside of the EVSE for visual - * identification. - * @property directions Multi-language human-readable directions when more detailed information on how to reach the EVSE - * from the Location is required. - * @property parking_restrictions The restrictions that apply to the parking spot. - * @property images Links to images related to the EVSE such as photos or logos. - * @property last_updated Instant Timestamp when this EVSE or one of its Connectors was last updated (or created). - */ -@Partial -data class Evse( - val uid: String, - val evse_id: String, - val status: Status, - val status_schedule: List?, - val capabilities: List?, - val connectors: List, - val floor_level: String?, - val coordinates: GeoLocation?, - val physical_reference: String?, - val directions: List?, - val parking_restrictions: List?, - val images: List?, - val last_updated: Instant -) diff --git a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/ExceptionalPeriod.kt b/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/ExceptionalPeriod.kt deleted file mode 100644 index edf1eb97..00000000 --- a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/ExceptionalPeriod.kt +++ /dev/null @@ -1,16 +0,0 @@ -package com.izivia.ocpi.toolkit.modules.locations.domain - -import com.izivia.ocpi.toolkit.annotations.Partial -import java.time.Instant - -/** - * Specifies one exceptional period for opening or access hours. - * - * @property period_begin Begin of the exception. - * @property period_end End of the exception. - */ -@Partial -data class ExceptionalPeriod( - val period_begin: Instant, - val period_end: Instant -) \ No newline at end of file diff --git a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/Facility.kt b/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/Facility.kt deleted file mode 100644 index f62a7983..00000000 --- a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/Facility.kt +++ /dev/null @@ -1,83 +0,0 @@ -package com.izivia.ocpi.toolkit.modules.locations.domain - -enum class Facility { - /** - * A hotel. - */ - HOTEL, - - /** - * A restaurant. - */ - RESTAURANT, - - /** - * A cafe. - */ - CAFE, - - /** - * A mall or shopping center. - */ - MALL, - - /** - * A supermarket. - */ - SUPERMARKET, - - /** - * Sport facilities: gym, field etc. - */ - SPORT, - - /** - * A Recreation area. - */ - RECREATION_AREA, - - /** - * Located in, or close to, a park, nature reserve/park etc. - */ - NATURE, - - /** - * A museum. - */ - MUSEUM, - - /** - * A bus stop. - */ - BUS_STOP, - - /** - * A taxi stand. - */ - TAXI_STAND, - - /** - * A train station. - */ - TRAIN_STATION, - - /** - * An airport. - */ - AIRPORT, - - /** - * A carpool parking. - */ - CARPOOL_PARKING, - - /** - * A Fuel station. - */ - FUEL_STATION, - - /** - * Wifi or other type of internet available. - */ - WIFI -} diff --git a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/GeoLocation.kt b/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/GeoLocation.kt deleted file mode 100644 index b4c90033..00000000 --- a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/GeoLocation.kt +++ /dev/null @@ -1,17 +0,0 @@ -package com.izivia.ocpi.toolkit.modules.locations.domain - -import com.izivia.ocpi.toolkit.annotations.Partial - -/** - * This class defines the geolocation of the Charge Point. The geodetic system to be used is WGS 84. - * - * @property latitude (max-length=10) Latitude of the point in decimal degree. Example: 50.770774. Decimal - * separator: "." Regex: -?[0-9]{1,2}\.[0-9]{6} - * @property longitude (max-length=11) Longitude of the point in decimal degree. Example: -126.104965. Decimal - * separator: "." Regex: -?[0-9]{1,3}\.[0-9]{6} - */ -@Partial -data class GeoLocation( - val latitude: String, - val longitude: String -) \ No newline at end of file diff --git a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/Hours.kt b/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/Hours.kt deleted file mode 100644 index c04d460d..00000000 --- a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/Hours.kt +++ /dev/null @@ -1,23 +0,0 @@ -package com.izivia.ocpi.toolkit.modules.locations.domain - -import com.izivia.ocpi.toolkit.annotations.Partial - -/** - * Opening and access hours of the location. - * Either regularHours or twentyFourSeven is set. Both cannot be null and both cannot be set. - * - * @property regular_hours Regular hours, weekday based. Should not be set for representing 24/7 as this is the most - * common case. - * @property twenty_four_seven True to represent 24 hours a day and 7 days a week, except the given exceptions. - * @property exceptional_openings Exceptions for specified calendar dates, time-range based. Periods the station is - * operating/accessible. Additional to regular hours. May overlap regular rules. - * @property exceptional_closings Exceptions for specified calendar dates, time-range based. Periods the station is not - * operating/accessible. Overwriting regularHours and exceptionalOpenings. Should not overlap exceptionalOpenings. - */ -@Partial -data class Hours( - val regular_hours: List?, - val twenty_four_seven: Boolean?, - val exceptional_openings: List?, - val exceptional_closings: List? -) \ No newline at end of file diff --git a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/Image.kt b/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/Image.kt deleted file mode 100644 index e8aec7c4..00000000 --- a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/Image.kt +++ /dev/null @@ -1,39 +0,0 @@ -package com.izivia.ocpi.toolkit.modules.locations.domain - -import com.izivia.ocpi.toolkit.annotations.Partial - -/** - * This class references images related to a EVSE in terms of a file name or url. According to the roaming connection - * between one EVSE Operator and one or more Navigation Service Providers the hosting or file exchange of image payload - * data has to be defined. The exchange of this content data is out of scope of OCHP. However, the recommended setup is - * a public available web server hosted and updated by the EVSE Operator. Per charge point an unlimited number of images - * of each type is allowed. Recommended are at least two images where one is a network or provider logo and the second - * is a station photo. If two images of the same type are defined they should be displayed additionally, not optionally. - * - * Photo Dimensions: The recommended dimensions for all photos is a minimum of 800 pixels wide and 600 pixels height. - * Thumbnail representations for photos should always have the same orientation as the original with a size of 200 to - * 200 pixels. - * - * Logo Dimensions: The recommended dimensions for logos are exactly 512 pixels wide and 512 pixels height. Thumbnail - * representations for logos should be exactly 128 pixels in width and height. If not squared, thumbnails should have - * the same orientation as the original. - * - * @property url URL (string(255) type following the w3.org spec. from where the image data can be fetched through a - * web browser. - * @property thumbnail URL (string(255) type following the w3.org spec. from where a thumbnail of the image can - * be fetched through a web browser. - * @property category Describes what the image is used for. - * @property type (max-length=4) Image type like: gif, jpeg, png, svg - * @property width (max-length=5) - * @property height (max-length=5) - * @constructor - */ -@Partial -data class Image( - val url: String, - val thumbnail: String?, - val category: ImageCategory, - val type: String, - val width: Int?, - val height: Int? -) \ No newline at end of file diff --git a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/ImageCategory.kt b/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/ImageCategory.kt deleted file mode 100644 index 2bcb4f82..00000000 --- a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/ImageCategory.kt +++ /dev/null @@ -1,45 +0,0 @@ -package com.izivia.ocpi.toolkit.modules.locations.domain - -/** - * The category of an image to obtain the correct usage in a user presentation. The category has to be set accordingly - * to the image content in order to guarantee the right usage. - */ -enum class ImageCategory { - /** - * Photo of the physical device that contains one or more EVSEs. - */ - CHARGER, - - /** - * Location entrance photo. Should show the car entrance to the location from street side. - */ - ENTRANCE, - - /** - * Location overview photo. - */ - LOCATION, - - /** - * Logo of an associated roaming network to be displayed with the EVSE for example in lists, maps and detailed - * information view - */ - NETWORK, - - /** - * Logo of the charge points operator, for example a municipality, to be displayed with the EVSEs detailed - * information view or in lists and maps, if no networkLogo is present - */ - OPERATOR, - - /** - * Other - */ - OTHER, - - /** - * Logo of the charge points owner, for example a local store, to be displayed with the EVSEs detailed information - * view - */ - OWNER, -} \ No newline at end of file diff --git a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/Location.kt b/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/Location.kt deleted file mode 100644 index 644d81ba..00000000 --- a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/Location.kt +++ /dev/null @@ -1,63 +0,0 @@ -package com.izivia.ocpi.toolkit.modules.locations.domain - -import com.izivia.ocpi.toolkit.annotations.Partial -import com.izivia.ocpi.toolkit.modules.types.DisplayText -import java.time.Instant - -/** - * The Location object describes the location and its properties where a group of EVSEs that belong together are - * installed. Typically, the Location object is the exact location of the group of EVSEs, but it can also be the entrance - * of a parking garage which contains these EVSEs. The exact way to reach each EVSE can be further specified by its own - * properties. - * - * @property id (max-length=39) Uniquely identifies the location within the CPOs platform (and suboperator platforms). - * This field can never be changed, modified or renamed. - * @property type The general type of the charge point location. - * @property name (max-length=255) Display name of the location. - * @property address (max-length=45) Street/block name and house number if available. - * @property city (max-length=45) City or town. - * @property postal_code (max-length=10) Postal code of the location. - * @property country (max-length=3) ISO 3166-1 alpha-3 code for the country of this location. - * @property coordinates Coordinates of the location. - * @property related_locations Geographical location of related points relevant to the user. - * @property evses List of EVSEs that belong to this Location. - * @property directions Human-readable directions on how to reach the location. - * @property operator Information of the operator. When not specified, the information retrieved from the api_info - * endpoint should be used instead. - * @property suboperator Information of the suboperator if available. - * @property owner Information of the owner if available. - * @property facilities Optional list of facilities this charge location directly belongs to. - * @property time_zone (max-length=255) One of IANA tzdata's TZ-values representing the time zone of the location. - * Examples: "Europe/Oslo", "Europe/Zurich". (http://www.iana.org/time-zones) - * @property opening_times The times when the EVSEs at the location can be accessed for charging. - * @property charging_when_closed Indicates if the EVSEs are still charging outside the opening hours of the location. - * E.g. when the parking garage closes its barriers overnight, is it allowed to charge till the next morning? - * Default: true - * @property images Links to images related to the location such as photos or logos. - * @property energy_mix Details on the energy supplied at this location. - * @property last_updated Timestamp when this Location or one of its EVSEs or Connectors were last updated (or created). - */ -@Partial -data class Location( - val id: String, - val type: LocationType, - val name: String?, - val address: String, - val city: String, - val postal_code: String, - val country: String, - val coordinates: GeoLocation, - val related_locations: List?, - val evses: List?, - val directions: List?, - val operator: BusinessDetails?, - val suboperator: BusinessDetails?, - val owner: BusinessDetails?, - val facilities: List?, - val time_zone: String?, - val opening_times: Hours?, - val charging_when_closed: Boolean?, - val images: List?, - val energy_mix: EnergyMix?, - val last_updated: Instant -) diff --git a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/LocationType.kt b/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/LocationType.kt deleted file mode 100644 index 8a5e06de..00000000 --- a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/LocationType.kt +++ /dev/null @@ -1,36 +0,0 @@ -package com.izivia.ocpi.toolkit.modules.locations.domain - -/** - * Reflects the general type of the charge points location. May be used for user information. - */ -enum class LocationType { - /** - * Parking in public space. - */ - ON_STREET, - - /** - * Multistory car park. - */ - PARKING_GARAGE, - - /** - * Multistory car park, mainly underground. - */ - UNDERGROUND_GARAGE, - - /** - * A cleared area that is intended for parking vehicles, i.e. at super markets, bars, etc. - */ - PARKING_LOT, - - /** - * None of the given possibilities. - */ - OTHER, - - /** - * Parking location type is not known by the operator (default). - */ - UNKNOWN -} \ No newline at end of file diff --git a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/ParkingRestriction.kt b/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/ParkingRestriction.kt deleted file mode 100644 index 9eb7bc9e..00000000 --- a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/ParkingRestriction.kt +++ /dev/null @@ -1,31 +0,0 @@ -package com.izivia.ocpi.toolkit.modules.locations.domain - -/** - * This value, if provided, represents the restriction to the parking spot for different purposes. - */ -enum class ParkingRestriction { - /** - * Reserved parking spot for electric vehicles. - */ - EV_ONLY, - - /** - * Parking is only allowed while plugged in (charging). - */ - PLUGGED, - - /** - * Reserved parking spot for disabled people with valid ID. - */ - DISABLED, - - /** - * Parking spot for customers/guests only, for example in case of a hotel or shop. - */ - CUSTOMERS, - - /** - * Parking spot only suitable for (electric) motorcycles or scooters. - */ - MOTORCYCLES -} \ No newline at end of file diff --git a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/PowerType.kt b/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/PowerType.kt deleted file mode 100644 index ed733fae..00000000 --- a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/PowerType.kt +++ /dev/null @@ -1,18 +0,0 @@ -package com.izivia.ocpi.toolkit.modules.locations.domain - -enum class PowerType { - /** - * AC mono phase. - */ - AC_1_PHASE, - - /** - * AC 3 phase. - */ - AC_3_PHASE, - - /** - * Direct Current. - */ - DC -} \ No newline at end of file diff --git a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/RegularHours.kt b/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/RegularHours.kt deleted file mode 100644 index 0a41058a..00000000 --- a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/RegularHours.kt +++ /dev/null @@ -1,19 +0,0 @@ -package com.izivia.ocpi.toolkit.modules.locations.domain - -import com.izivia.ocpi.toolkit.annotations.Partial - -/** - * Regular recurring operation or access hours - * - * @property weekday (max-length=1) Number of day in the week, from Monday (1) till Sunday (7) - * @property period_begin (max-length=5) Begin of the regular period given in hours and minutes. Must be in 24h format - * with leading zeros. Example: "18:15". Hour/Minute separator: ":" Regex: ([0-1][0-9]|2[0-3]):[0-5][0-9] - * @property period_end (max-length=5) End of the regular period, syntax as for periodBegin. Must be later than - * periodBegin. - */ -@Partial -data class RegularHours( - val weekday: Int, - val period_begin: String, - val period_end: String -) \ No newline at end of file diff --git a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/Status.kt b/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/Status.kt deleted file mode 100644 index 0fd0ed9e..00000000 --- a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/Status.kt +++ /dev/null @@ -1,51 +0,0 @@ -package com.izivia.ocpi.toolkit.modules.locations.domain - -/** - * The status of an EVSE. - */ -enum class Status { - /** - * The EVSE/Connector is able to start a new charging session. - */ - AVAILABLE, - - /** - * The EVSE/Connector is not accessible because of a physical barrier, i.e. a car. - */ - BLOCKED, - - /** - * The EVSE/Connector is in use. - */ - CHARGING, - - /** - * The EVSE/Connector is not yet active, or it is no longer available (deleted). - */ - INOPERATIVE, - - /** - * The EVSE/Connector is currently out of order. - */ - OUTOFORDER, - - /** - * The EVSE/Connector is planned, will be operating soon - */ - PLANNED, - - /** - * The EVSE/Connector/charge point is discontinued/removed. - */ - REMOVED, - - /** - * The EVSE/Connector is reserved for a particular EV driver and is unavailable for other drivers. - */ - RESERVED, - - /** - * No status information available. (Also used when offline) - */ - UNKNOWN -} diff --git a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/StatusSchedule.kt b/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/StatusSchedule.kt deleted file mode 100644 index abcc3653..00000000 --- a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/StatusSchedule.kt +++ /dev/null @@ -1,23 +0,0 @@ -package com.izivia.ocpi.toolkit.modules.locations.domain - -import com.izivia.ocpi.toolkit.annotations.Partial -import java.time.Instant - -/** - * This type is used to schedule status periods in the future. The eMSP can provide this information to the EV user for - * trip planning purpose. A period MAY have no end. Example: "This station will be running as of tomorrow. Today it is - * still planned and under construction." - * - * Note that the scheduled status is purely informational. When the status actually changes, the CPO must push an update - * to the EVSEs `status` field itself. - * - * @property period_begin Begin of the scheduled period. - * @property period_end End of the scheduled period, if known. - * @property status Status value during the scheduled period. - */ -@Partial -data class StatusSchedule( - val period_begin: Instant, - val period_end: Instant?, - val status: Status -) \ No newline at end of file diff --git a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/services/LocationsCpoService.kt b/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/services/LocationsCpoService.kt deleted file mode 100644 index e9baa713..00000000 --- a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/services/LocationsCpoService.kt +++ /dev/null @@ -1,52 +0,0 @@ -package com.izivia.ocpi.toolkit.modules.locations.services - -import com.izivia.ocpi.toolkit.common.SearchResult -import com.izivia.ocpi.toolkit.modules.locations.domain.Connector -import com.izivia.ocpi.toolkit.modules.locations.domain.Evse -import com.izivia.ocpi.toolkit.modules.locations.domain.Location -import java.time.Instant - -/** - * - GET: Fetch a list locations, last updated between the {date_from} and {date_to} (paginated), or get a specific - * location, EVSE or Connector. - * - POST: n/a - * - PUT: n/a - * - PATCH: n/a - * - DELETE: n/a - */ -interface LocationsCpoService { - /** - * If additional parameters: {date_from} and/or {date_to} are provided, only Locations with - * (last_updated) between the given date_from and date_to will be returned. If an EVSE is - * updated, also the 'parent' Location's last_updated fields is updated. If a Connector is - * updated, the EVSE's last_updated and the Location's last_updated field are updated. - * - * This request is paginated, it supports the pagination related URL parameters. - * - * @param dateFrom Instant? Only return Locations that have last_updated after this Date/Time. - * @param dateTo Instant? Only return Locations that have last_updated before this Date/Time. - * @param offset Int? The offset of the first object returned. Default is 0. - * @param limit Int? Maximum number of objects to GET. - * @return List The endpoint returns a list of Location objects The header will - * contain the pagination related headers. - */ - fun getLocations(dateFrom: Instant?, dateTo: Instant?, offset: Int = 0, limit: Int?): SearchResult - - /** - * @param locationId String max-length = 39 - */ - fun getLocation(locationId: String): Location? - - /** - * @param locationId String max-length = 39 - * @param evseUid String? max-length = 39 - */ - fun getEvse(locationId: String, evseUid: String): Evse? - - /** - * @param locationId String max-length = 39 - * @param evseUid max-length = 39 - * @param connectorId max-length = 39 - */ - fun getConnector(locationId: String, evseUid: String, connectorId: String): Connector? -} diff --git a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/services/LocationsEmspService.kt b/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/services/LocationsEmspService.kt deleted file mode 100644 index c4c7c1c8..00000000 --- a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/services/LocationsEmspService.kt +++ /dev/null @@ -1,170 +0,0 @@ -package com.izivia.ocpi.toolkit.modules.locations.services - -import com.izivia.ocpi.toolkit.modules.locations.domain.* - - -/** - * Locations is a client owned object, so the end-points need to contain the required extra fields: {party_id} and - * {country_code}. Example endpoint structures: - * - /ocpi/emsp/2.1.1/locations/{country_code}/{party_id}/{location_id} - * - /ocpi/emsp/2.1.1/locations/{country_code}/{party_id}/{location_id}/{evse_uid} - * - /ocpi/emsp/2.1.1/locations/{country_code}/{party_id}/{location_id}/{evse_uid}/{connector_id} - * - * Method: Description - * - GET: Retrieve a Location as it is stored in the eMSP system. - * - POST: n/a (use PUT) - * - PUT: Push new/updated Location, EVSE and/or Connectors to the eMSP - * - PATCH: Notify the eMSP of partial updates to a Location, EVSEs or Connector (such as the status). - * - DELETE: n/a (use PATCH) - */ -interface LocationsEmspService { - /** - * If the CPO wants to check the status of a Location, EVSE or Connector object in the eMSP system, it might GET the - * object from the eMSP system for validation purposes. The CPO is the owner of the objects, so it would be - * illogical if the eMSP system had a different status or was missing an object. If a discrepancy is found, the CPO - * might push an update to the eMSP via a PUT or PATCH call. - * - * @param countryCode (max-length=2) Country code of the CPO requesting this PUT to the eMSP system. - * @param partyId (max-length=3) Party ID (Provider ID) of the CPO requesting this PUT to the eMSP system. - * @param locationId (max-length=39) Location.id of the Location object to retrieve. - */ - fun getLocation(countryCode: String, partyId: String, locationId: String): Location? - - /** - * If the CPO wants to check the status of a Location, EVSE or Connector object in the eMSP system, it might GET the - * object from the eMSP system for validation purposes. The CPO is the owner of the objects, so it would be - * illogical if the eMSP system had a different status or was missing an object. If a discrepancy is found, the CPO - * might push an update to the eMSP via a PUT or PATCH call. - * - * @param countryCode (max-length=2) Country code of the CPO requesting this PUT to the eMSP system. - * @param partyId (max-length=3) Party ID (Provider ID) of the CPO requesting this PUT to the eMSP system. - * @param locationId (max-length=39) Location.id of the Location object to retrieve. - * @param evseUid (max-length=39) Evse.uid, required when requesting an EVSE or Connector object. - */ - fun getEvse(countryCode: String, partyId: String, locationId: String, evseUid: String): Evse? - - /** - * If the CPO wants to check the status of a Location, EVSE or Connector object in the eMSP system, it might GET the - * object from the eMSP system for validation purposes. The CPO is the owner of the objects, so it would be - * illogical if the eMSP system had a different status or was missing an object. If a discrepancy is found, the CPO - * might push an update to the eMSP via a PUT or PATCH call. - * - * @param countryCode (max-length=2) Country code of the CPO requesting this PUT to the eMSP system. - * @param partyId (max-length=3) Party ID (Provider ID) of the CPO requesting this PUT to the eMSP system. - * @param locationId (max-length=39) Location.id of the Location object to retrieve. - * @param evseUid (max-length=39) Evse.uid, required when requesting an EVSE or Connector object. - * @param connectorId (max-length=36) Connector.id, required when requesting a Connector object. - */ - fun getConnector( - countryCode: String, - partyId: String, - locationId: String, - evseUid: String, - connectorId: String - ): Connector? - - /** - * The CPO pushes available Location/EVSE or Connector objects to the eMSP. PUT is used to send new Location objects - * to the eMSP, or to replace existing Locations. - * - * @param countryCode (max-length=2) Country code of the CPO requesting this PUT to the eMSP system. - * @param partyId (max-length=3) Party ID (Provider ID) of the CPO requesting this PUT to the eMSP system. - * @param locationId (max-length=39) Location.id of the new Location object, or the Location of which an EVSE or - * Location object is send - */ - fun putLocation( - countryCode: String, - partyId: String, - locationId: String, - location: Location - ): Location - - /** - * The CPO pushes available Location/EVSE or Connector objects to the eMSP. PUT is used to send new Location objects - * to the eMSP, or to replace existing Locations. - * - * @param countryCode (max-length=2) Country code of the CPO requesting this PUT to the eMSP system. - * @param partyId (max-length=3) Party ID (Provider ID) of the CPO requesting this PUT to the eMSP system. - * @param locationId (max-length=39) Location.id of the new Location object, or the Location of which an EVSE or - * Location object is send - * @param evseUid (max-length=39) Evse.uid, required when an EVSE or Connector object is send/replaced. - */ - fun putEvse( - countryCode: String, - partyId: String, - locationId: String, - evseUid: String, - evse: Evse - ): Evse - - /** - * The CPO pushes available Location/EVSE or Connector objects to the eMSP. PUT is used to send new Location objects - * to the eMSP, or to replace existing Locations. - * - * @param countryCode (max-length=2) Country code of the CPO requesting this PUT to the eMSP system. - * @param partyId (max-length=3) Party ID (Provider ID) of the CPO requesting this PUT to the eMSP system. - * @param locationId (max-length=39) Location.id of the new Location object, or the Location of which an EVSE or - * Location object is send - * @param evseUid (max-length=39) Evse.uid, required when an EVSE or Connector object is send/replaced. - * @param connectorId (max-length=36) Connector.id, required when a Connector object is send/replaced. - */ - fun putConnector( - countryCode: String, - partyId: String, - locationId: String, - evseUid: String, - connectorId: String, - connector: Connector - ): Connector - - /** - * Same as the PUT method, but only the fields/objects that have to be updated have to be present, other - * fields/objects that are not specified are considered unchanged. - * - * @param countryCode (max-length=2) Country code of the CPO requesting this PUT to the eMSP system. - * @param partyId (max-length=3) Party ID (Provider ID) of the CPO requesting this PUT to the eMSP system. - * @param locationId (max-length=39) Location.id of the new Location object - */ - fun patchLocation( - countryCode: String, - partyId: String, - locationId: String, - location: LocationPartial - ): Location? - - /** - * Same as the PUT method, but only the fields/objects that have to be updated have to be present, other - * fields/objects that are not specified are considered unchanged. - * - * @param countryCode (max-length=2) Country code of the CPO requesting this PUT to the eMSP system. - * @param partyId (max-length=3) Party ID (Provider ID) of the CPO requesting this PUT to the eMSP system. - * @param locationId (max-length=39) Location.id of the Location of which an EVSE or Location object is send - * @param evseUid (max-length=39) Evse.uid, required when an EVSE or Connector object is send/replaced. - */ - fun patchEvse( - countryCode: String, - partyId: String, - locationId: String, - evseUid: String, - evse: EvsePartial - ): Evse? - - /** - * Same as the PUT method, but only the fields/objects that have to be updated have to be present, other - * fields/objects that are not specified are considered unchanged. - * - * @param countryCode (max-length=2) Country code of the CPO requesting this PUT to the eMSP system. - * @param partyId (max-length=3) Party ID (Provider ID) of the CPO requesting this PUT to the eMSP system. - * @param locationId (max-length=39) Location.id of the Location of which an EVSE or Location object is send - * @param evseUid (max-length=39) Evse.uid, required when an EVSE or Connector object is send/replaced. - * @param connectorId (max-length=36) Connector.id, required when a Connector object is send/replaced. - */ - fun patchConnector( - countryCode: String, - partyId: String, - locationId: String, - evseUid: String, - connectorId: String, - connector: ConnectorPartial - ): Connector? -} \ No newline at end of file diff --git a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/validation/LocationValidators.kt b/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/validation/LocationValidators.kt deleted file mode 100644 index 6865a90f..00000000 --- a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/validation/LocationValidators.kt +++ /dev/null @@ -1,228 +0,0 @@ -package com.izivia.ocpi.toolkit.modules.locations.validation - -import com.izivia.ocpi.toolkit.common.validation.* -import com.izivia.ocpi.toolkit.modules.locations.domain.* -import com.izivia.ocpi.toolkit.modules.types.DisplayText -import com.izivia.ocpi.toolkit.modules.types.DisplayTextPartial -import com.izivia.ocpi.toolkit.modules.types.toPartial -import org.valiktor.DefaultConstraintViolation -import org.valiktor.constraints.Greater -import org.valiktor.constraints.NotNull -import org.valiktor.constraints.Null -import org.valiktor.functions.isGreaterThanOrEqualTo -import org.valiktor.functions.isLessThanOrEqualTo -import org.valiktor.functions.isNotEmpty -import org.valiktor.validate -import java.math.BigDecimal - -fun LocationPartial.validate(): LocationPartial = validate(this) { - validate(LocationPartial::id).isPrintableAscii().hasMaxLengthOf(39) - validate(LocationPartial::name).isPrintableAscii().hasMaxLengthOf(255) - validate(LocationPartial::address).isPrintableAscii().hasMaxLengthOf(45) - validate(LocationPartial::city).isPrintableAscii().hasMaxLengthOf(45) - validate(LocationPartial::postal_code).isPrintableAscii().hasMaxLengthOf(10) - validate(LocationPartial::country).isCountryCode() - coordinates?.validate() - related_locations?.forEach { it.validate() } - evses?.forEach { it.validate() } - directions?.forEach { it.validate() } - operator?.validate() - suboperator?.validate() - owner?.validate() - // facilities: nothing to validate - validate(LocationPartial::time_zone).isTimeZone() - opening_times?.validate() - // charging_when_closed: nothing to validate - images?.forEach { it.validate() } - energy_mix?.validate() - // last_updated: nothing to validate -} - -fun EnvironmentalImpactPartial.validate(): EnvironmentalImpactPartial = validate(this) { - // source: nothing to validate - validate(EnvironmentalImpactPartial::amount) - .isGreaterThanOrEqualTo(BigDecimal.valueOf(0)) -} - -fun EnergySourcePartial.validate(): EnergySourcePartial = validate(this) { - // source: nothing to validate - validate(EnergySourcePartial::percentage) - .isGreaterThanOrEqualTo(BigDecimal.valueOf(0)) - .isLessThanOrEqualTo(BigDecimal.valueOf(100)) -} - -fun EnergyMixPartial.validate(): EnergyMixPartial = validate(this) { - // is_green_energy: nothing to validate - energy_sources?.forEach { it.validate() } - environ_impact?.forEach { it.validate() } - validate(EnergyMixPartial::supplier_name).isPrintableAscii().hasMaxLengthOf(64) - validate(EnergyMixPartial::energy_product_name).isPrintableAscii().hasMaxLengthOf(64) -} - -fun ExceptionalPeriodPartial.validate(): ExceptionalPeriodPartial = validate(this) { - if (it.period_end != null) { - validate(ExceptionalPeriodPartial::period_begin).isLessThanOrEqualTo(it.period_end) - } -} - -fun RegularHoursPartial.validate(): RegularHoursPartial = validate(this) { regularHours -> - validate(RegularHoursPartial::weekday).isGreaterThanOrEqualTo(1).isLessThanOrEqualTo(7) - validate(RegularHoursPartial::period_begin).isTime() - validate(RegularHoursPartial::period_end).isTime() - - val beginInMinutes = regularHours.period_begin?.split(":") - ?.mapIndexed { index, time -> time.toInt() * (1 - index) * 60 } - ?.sum() - val endInMinutes = regularHours.period_end?.split(":") - ?.mapIndexed { index, time -> time.toInt() * (1 - index) * 60 } - ?.sum() - - if (beginInMinutes != null && endInMinutes != null && beginInMinutes > endInMinutes) { - constraintViolations.add( - DefaultConstraintViolation( - property = "period_begin ($period_begin) is after period_end ($period_end)", - constraint = Greater(endInMinutes) - ) - ) - } -} - -fun HoursPartial.validate(): HoursPartial = validate(this) { hours -> - if (hours.regular_hours != null && hours.twenty_four_seven != null) { - constraintViolations.add( - DefaultConstraintViolation( - property = "regular_hours and twenty_four_seven are both set (only one must be set)", - constraint = NotNull - ) - ) - } - - regular_hours?.forEach { it.validate() } - /// twenty_four_seven: nothing to validate - exceptional_openings?.forEach { it.validate() } - exceptional_closings?.forEach { it.validate() } -} - -fun ImagePartial.validate(): ImagePartial = validate(this) { - validate(ImagePartial::url).isUrl() - validate(ImagePartial::thumbnail).isUrl() - // category: nothing to validate - validate(ImagePartial::type).isPrintableAscii().hasMaxLengthOf(4) - validate(ImagePartial::width).isLessThanOrEqualTo(99999) - validate(ImagePartial::height).isLessThanOrEqualTo(99999) -} - -fun BusinessDetailsPartial.validate(): BusinessDetailsPartial = validate(this) { - validate(BusinessDetailsPartial::name).isPrintableAscii().hasMaxLengthOf(100) - validate(BusinessDetailsPartial::website).isUrl() - logo?.validate() -} - -fun GeoLocationPartial.validate(): GeoLocationPartial = validate(this) { - validate(GeoLocationPartial::latitude).isLatitude() - validate(GeoLocationPartial::longitude).isLongitude() -} - -fun AdditionalGeoLocationPartial.validate(): AdditionalGeoLocationPartial = validate(this) { - validate(AdditionalGeoLocationPartial::latitude).isLatitude() - validate(AdditionalGeoLocationPartial::longitude).isLongitude() - name?.validate() -} - -fun DisplayTextPartial.validate(): DisplayTextPartial = validate(this) { - validate(DisplayTextPartial::language).isLanguage() - validate(DisplayTextPartial::text) - .isPrintableAscii() - .hasNoHtml() - .hasMaxLengthOf(512) -} - -fun StatusSchedulePartial.validate(): StatusSchedulePartial = validate(this) { - if (it.period_end != null) { - validate(StatusSchedulePartial::period_begin).isLessThanOrEqualTo(it.period_end) - } -} - -fun EvsePartial.validate(): EvsePartial = validate(this) { - validate(EvsePartial::uid).isPrintableAscii().hasMaxLengthOf(39) - validate(EvsePartial::evse_id).isEvseId() - // status: nothing to validate - status_schedule?.forEach { it.validate() } - // capabilities: nothing to validate - validate(EvsePartial::connectors).isNotEmpty() - connectors?.forEach { it.validate() } - validate(EvsePartial::floor_level).isPrintableAscii().hasMaxLengthOf(4) - coordinates?.validate() - validate(EvsePartial::physical_reference).isPrintableAscii().hasMaxLengthOf(16) - directions?.forEach { it.validate() } - // parking_restrictions: nothing to validate - images?.forEach { it.validate() } - // last_updated: nothing to validate -} - -fun ConnectorPartial.validate(): ConnectorPartial = validate(this) { - validate(ConnectorPartial::id).isPrintableAscii().hasMaxLengthOf(36) - // standard: nothing to validate - // format: nothing to validate - // power_type: nothing to validate - validate(ConnectorPartial::voltage).isGreaterThanOrEqualTo(0) - validate(ConnectorPartial::amperage).isGreaterThanOrEqualTo(0) - validate(ConnectorPartial::tariff_id).isPrintableAscii().hasMaxLengthOf(36) - validate(ConnectorPartial::terms_and_conditions).isUrl() - // last_updated: nothing to validate -} - -fun Location.validate(): Location = validate(this) { - toPartial().validate() -} -fun EnvironmentalImpact.validate(): EnvironmentalImpact = validate(this) { - toPartial().validate() -} -fun EnergySource.validate(): EnergySource = validate(this) { - toPartial().validate() -} -fun EnergyMix.validate(): EnergyMix = validate(this) { - toPartial().validate() -} -fun ExceptionalPeriod.validate(): ExceptionalPeriod = validate(this) { - toPartial().validate() -} -fun RegularHours.validate(): RegularHours = validate(this) { - toPartial().validate() -} -fun Hours.validate(): Hours = validate(this) { hours -> - if (hours.regular_hours == null && hours.twenty_four_seven == null) { - constraintViolations.add( - DefaultConstraintViolation( - property = "regular_hours or twenty_four_seven must be set (both are null)", - constraint = Null - ) - ) - } - - toPartial().validate() -} -fun Image.validate(): Image = validate(this) { - toPartial().validate() -} -fun BusinessDetails.validate(): BusinessDetails = validate(this) { - toPartial().validate() -} -fun GeoLocation.validate(): GeoLocation = validate(this) { - toPartial().validate() -} -fun AdditionalGeoLocation.validate(): AdditionalGeoLocation = validate(this) { - toPartial().validate() -} -fun DisplayText.validate(): DisplayText = validate(this) { - toPartial().validate() -} -fun StatusSchedule.validate(): StatusSchedule = validate(this) { - toPartial().validate() -} -fun Evse.validate(): Evse = validate(this) { - toPartial().validate() -} -fun Connector.validate(): Connector = validate(this) { - toPartial().validate() -} diff --git a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/validation/LocationsCpoValidationService.kt b/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/validation/LocationsCpoValidationService.kt deleted file mode 100644 index 4e917676..00000000 --- a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/validation/LocationsCpoValidationService.kt +++ /dev/null @@ -1,80 +0,0 @@ -package com.izivia.ocpi.toolkit.modules.locations.validation - -import com.izivia.ocpi.toolkit.common.OcpiResponseBody -import com.izivia.ocpi.toolkit.common.SearchResult -import com.izivia.ocpi.toolkit.common.validation.validate -import com.izivia.ocpi.toolkit.common.validation.validateDates -import com.izivia.ocpi.toolkit.common.validation.validateInt -import com.izivia.ocpi.toolkit.common.validation.validateLength -import com.izivia.ocpi.toolkit.modules.locations.LocationsCpoInterface -import com.izivia.ocpi.toolkit.modules.locations.domain.Connector -import com.izivia.ocpi.toolkit.modules.locations.domain.Evse -import com.izivia.ocpi.toolkit.modules.locations.domain.Location -import com.izivia.ocpi.toolkit.modules.locations.services.LocationsCpoService -import java.time.Instant - -class LocationsCpoValidationService( - private val service: LocationsCpoService -) : LocationsCpoInterface { - - override fun getLocations( - dateFrom: Instant?, - dateTo: Instant?, - offset: Int, - limit: Int? - ): OcpiResponseBody> = OcpiResponseBody.of { - validate { - if (dateFrom != null && dateTo != null) validateDates("dateFrom", dateFrom, "dateTo", dateTo) - if (limit != null) validateInt("limit", limit, 0, null) - validateInt("offset", offset, 0, null) - } - - service - .getLocations(dateFrom, dateTo, offset, limit) - .also { searchResult -> - searchResult.list.forEach { location -> location.validate() } - } - } - - override fun getLocation( - locationId: String - ): OcpiResponseBody = OcpiResponseBody.of { - validate { - validateLength("locationId", locationId, 39) - } - - service - .getLocation(locationId) - ?.validate() - } - - override fun getEvse( - locationId: String, - evseUid: String - ): OcpiResponseBody = OcpiResponseBody.of { - validate { - validateLength("locationId", locationId, 39) - validateLength("evseUid", evseUid, 39) - } - - service - .getEvse(locationId, evseUid) - ?.validate() - } - - override fun getConnector( - locationId: String, - evseUid: String, - connectorId: String - ): OcpiResponseBody = OcpiResponseBody.of { - validate { - validateLength("locationId", locationId, 39) - validateLength("evseUid", evseUid, 39) - validateLength("connectorId", connectorId, 36) - } - - service - .getConnector(locationId, evseUid, connectorId) - ?.validate() - } -} diff --git a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/validation/LocationsEmspValidationService.kt b/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/validation/LocationsEmspValidationService.kt deleted file mode 100644 index fb993093..00000000 --- a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/validation/LocationsEmspValidationService.kt +++ /dev/null @@ -1,225 +0,0 @@ -package com.izivia.ocpi.toolkit.modules.locations.validation - -import com.izivia.ocpi.toolkit.common.OcpiResponseBody -import com.izivia.ocpi.toolkit.common.validation.validate -import com.izivia.ocpi.toolkit.common.validation.validateLength -import com.izivia.ocpi.toolkit.modules.locations.LocationsEmspInterface -import com.izivia.ocpi.toolkit.modules.locations.domain.* -import com.izivia.ocpi.toolkit.modules.locations.services.LocationsEmspService - -class LocationsEmspValidationService( - private val service: LocationsEmspService -) : LocationsEmspInterface { - - override fun getLocation( - countryCode: String, - partyId: String, - locationId: String - ): OcpiResponseBody = OcpiResponseBody.of { - validate { - validateLength("countryCode", countryCode, 2) - validateLength("partyId", partyId, 3) - validateLength("locationId", locationId, 39) - } - - service - .getLocation(countryCode = countryCode, partyId = partyId, locationId = locationId) - ?.validate() - } - - - override fun getEvse( - countryCode: String, - partyId: String, - locationId: String, - evseUid: String - ): OcpiResponseBody = OcpiResponseBody.of { - validate { - validateLength("countryCode", countryCode, 2) - validateLength("partyId", partyId, 3) - validateLength("locationId", locationId, 39) - validateLength("evseUid", evseUid, 39) - } - - service - .getEvse(countryCode = countryCode, partyId = partyId, locationId = locationId, evseUid = evseUid) - ?.validate() - } - - override fun getConnector( - countryCode: String, - partyId: String, - locationId: String, - evseUid: String, - connectorId: String - ): OcpiResponseBody = OcpiResponseBody.of { - validate { - validateLength("countryCode", countryCode, 2) - validateLength("partyId", partyId, 3) - validateLength("locationId", locationId, 39) - validateLength("evseUid", evseUid, 39) - validateLength("connectorId", connectorId, 36) - } - - service - .getConnector( - countryCode = countryCode, - partyId = partyId, - locationId = locationId, - evseUid = evseUid, - connectorId = connectorId - ) - ?.validate() - } - - override fun putLocation( - countryCode: String, - partyId: String, - locationId: String, - location: Location - ): OcpiResponseBody = OcpiResponseBody.of { - validate { - validateLength("countryCode", countryCode, 2) - validateLength("partyId", partyId, 3) - validateLength("locationId", locationId, 39) - location.validate() - } - - service - .putLocation(countryCode = countryCode, partyId = partyId, locationId = locationId, location = location) - .validate() - } - - override fun putEvse( - countryCode: String, - partyId: String, - locationId: String, - evseUid: String, - evse: Evse - ): OcpiResponseBody = OcpiResponseBody.of { - validate { - validateLength("countryCode", countryCode, 2) - validateLength("partyId", partyId, 3) - validateLength("locationId", locationId, 39) - validateLength("evseUid", evseUid, 39) - evse.validate() - } - - service - .putEvse( - countryCode = countryCode, - partyId = partyId, - locationId = locationId, - evseUid = evseUid, - evse = evse - ) - .validate() - } - - override fun putConnector( - countryCode: String, - partyId: String, - locationId: String, - evseUid: String, - connectorId: String, - connector: Connector - ): OcpiResponseBody = OcpiResponseBody.of { - validate { - validateLength("countryCode", countryCode, 2) - validateLength("partyId", partyId, 3) - validateLength("locationId", locationId, 39) - validateLength("evseUid", evseUid, 39) - validateLength("connectorId", connectorId, 36) - connector.validate() - } - - service - .putConnector( - countryCode = countryCode, - partyId = partyId, - locationId = locationId, - evseUid = evseUid, - connectorId = connectorId, - connector = connector - ) - .validate() - } - - override fun patchLocation( - countryCode: String, - partyId: String, - locationId: String, - location: LocationPartial - ): OcpiResponseBody = OcpiResponseBody.of { - validate { - validateLength("countryCode", countryCode, 2) - validateLength("partyId", partyId, 3) - validateLength("locationId", locationId, 39) - location.validate() - } - - service - .patchLocation( - countryCode = countryCode, - partyId = partyId, - locationId = locationId, - location = location - ) - ?.validate() - } - - override fun patchEvse( - countryCode: String, - partyId: String, - locationId: String, - evseUid: String, - evse: EvsePartial - ): OcpiResponseBody = OcpiResponseBody.of { - validate { - validateLength("countryCode", countryCode, 2) - validateLength("partyId", partyId, 3) - validateLength("locationId", locationId, 39) - validateLength("evseUid", evseUid, 39) - evse.validate() - } - - service - .patchEvse( - countryCode = countryCode, - partyId = partyId, - locationId = locationId, - evseUid = evseUid, - evse = evse - ) - ?.validate() - } - - override fun patchConnector( - countryCode: String, - partyId: String, - locationId: String, - evseUid: String, - connectorId: String, - connector: ConnectorPartial - ): OcpiResponseBody = OcpiResponseBody.of { - validate { - validateLength("countryCode", countryCode, 2) - validateLength("partyId", partyId, 3) - validateLength("locationId", locationId, 39) - validateLength("evseUid", evseUid, 39) - validateLength("connectorId", connectorId, 36) - connector.validate() - } - - service - .patchConnector( - countryCode = countryCode, - partyId = partyId, - locationId = locationId, - evseUid = evseUid, - connectorId = connectorId, - connector = connector - ) - ?.validate() - } -} diff --git a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/TokensCpoClient.kt b/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/TokensCpoClient.kt deleted file mode 100644 index 9add5a4c..00000000 --- a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/TokensCpoClient.kt +++ /dev/null @@ -1,79 +0,0 @@ -package com.izivia.ocpi.toolkit.modules.tokens - -import com.izivia.ocpi.toolkit.common.* -import com.izivia.ocpi.toolkit.modules.credentials.repositories.PlatformRepository -import com.izivia.ocpi.toolkit.modules.tokens.domain.AuthorizationInfo -import com.izivia.ocpi.toolkit.modules.tokens.domain.LocationReferences -import com.izivia.ocpi.toolkit.modules.tokens.domain.Token -import com.izivia.ocpi.toolkit.modules.tokens.domain.TokenType -import com.izivia.ocpi.toolkit.modules.versions.domain.ModuleID -import com.izivia.ocpi.toolkit.transport.TransportClient -import com.izivia.ocpi.toolkit.transport.TransportClientBuilder -import com.izivia.ocpi.toolkit.transport.domain.HttpMethod -import com.izivia.ocpi.toolkit.transport.domain.HttpRequest -import java.time.Instant - -class TokensCpoClient( - private val transportClientBuilder: TransportClientBuilder, - private val serverVersionsEndpointUrl: String, - private val platformRepository: PlatformRepository -) : TokensEmspInterface { - - private fun buildTransport(): TransportClient = transportClientBuilder - .buildFor( - module = ModuleID.tokens, - platformUrl = serverVersionsEndpointUrl, - platformRepository = platformRepository - ) - - override fun getTokens( - dateFrom: Instant?, - dateTo: Instant?, - offset: Int, - limit: Int?, - countryCode: String?, - partyId: String? - ): OcpiResponseBody> = - buildTransport() - .send( - HttpRequest( - method = HttpMethod.GET, - queryParams = listOfNotNull( - dateFrom?.let { "date_from" to dateFrom.toString() }, - dateTo?.let { "date_to" to dateTo.toString() }, - "offset" to offset.toString(), - limit?.let { "limit" to limit.toString() }, - countryCode?.let { "ocpi-to-country-code" to countryCode }, - partyId?.let { "ocpi-to-party-id" to partyId } - ).toMap() - ).authenticate(platformRepository = platformRepository, baseUrl = serverVersionsEndpointUrl) - ) - .parsePaginatedBody(offset) - - override fun getToken(tokenUid: String, tokenType: TokenType): OcpiResponseBody = - buildTransport() - .send( - HttpRequest( - method = HttpMethod.GET, - path = "/$tokenUid", - queryParams = mapOf("type" to tokenType.name), - ).authenticate(platformRepository = platformRepository, baseUrl = serverVersionsEndpointUrl) - ) - .parseBody() - - override fun postToken( - tokenUid: String, - tokenType: TokenType, - locationReferences: LocationReferences - ): OcpiResponseBody = - buildTransport() - .send( - HttpRequest( - method = HttpMethod.POST, - path = "/$tokenUid/authorize", - queryParams = mapOf("type" to tokenType.name), - body = locationReferences.run(mapper::writeValueAsString) - ).authenticate(platformRepository = platformRepository, baseUrl = serverVersionsEndpointUrl) - ) - .parseBody() -} diff --git a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/TokensCpoInterface.kt b/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/TokensCpoInterface.kt deleted file mode 100644 index 0034efaa..00000000 --- a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/TokensCpoInterface.kt +++ /dev/null @@ -1,66 +0,0 @@ -package com.izivia.ocpi.toolkit.modules.tokens - -import com.izivia.ocpi.toolkit.common.OcpiResponseBody -import com.izivia.ocpi.toolkit.modules.tokens.domain.Token -import com.izivia.ocpi.toolkit.modules.tokens.domain.TokenPartial - -/** - * With this interface the eMSP can push the Token information to the CPO. Tokens is a client owned object, so the - * end-points need to contain the required extra fields: {party_id} and {country_code}. Example endpoint structure: - * /ocpi/cpo/2.0/tokens/{country_code}/{party_id}/{token_uid} - * - * - GET: Retrieve a Token as it is stored in the CPO system. - * - POST: n/a - * - PUT: Push new/updated Token object to the CPO. - * - PATCH: Notify the CPO of partial updates to a Token. - * - DELETE: n/a, (Use PUT, Tokens cannot be removed). - */ -interface TokensCpoInterface { - - /** - * If the eMSP wants to check the status of a Token in the CPO system it might GET the object from the CPO system - * for validation purposes. The eMSP is the owner of the objects, so it would be illogical if the CPO system had a - * different status or was missing an object. - * - * @param countryCode (max-length 2) Country code of the eMSP requesting this GET from the CPO system. - * @param partyId (max-length 3) Party ID (Provider ID) of the eMSP requesting this GET from the CPO system. - * @param tokenUid (max-length 36) Token.uid of the Token object to retrieve. - * @return The requested Token object. - */ - fun getToken( - countryCode: String, - partyId: String, - tokenUid: String - ): OcpiResponseBody - - /** - * New or updated Token objects are pushed from the eMSP to the CPO. - * - * @param countryCode (max-length 2) Country code of the eMSP sending this PUT request to the CPO system. - * @param partyId (max-length 3) Party ID (Provider ID) of the eMSP sending this PUT request to the CPO system. - * @param tokenUid (max-length 36) Token.uid of the (new) Token object (to replace). - * @param token New or updated Token object. - */ - fun putToken( - countryCode: String, - partyId: String, - tokenUid: String, - token: Token - ): OcpiResponseBody - - /** - * Same as the PUT method, but only the fields/objects that have to be updated have to be present, other - * fields/objects that are not specified are considered unchanged. - * - * @param countryCode (max-length 2) Country code of the eMSP sending this PUT request to the CPO system. - * @param partyId (max-length 3) Party ID (Provider ID) of the eMSP sending this PUT request to the CPO system. - * @param tokenUid (max-length 36) Token.uid of the (new) Token object (to replace). - * @param token New or updated Token object. - */ - fun patchToken( - countryCode: String, - partyId: String, - tokenUid: String, - token: TokenPartial - ): OcpiResponseBody -} diff --git a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/TokensCpoServer.kt b/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/TokensCpoServer.kt deleted file mode 100644 index a889d059..00000000 --- a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/TokensCpoServer.kt +++ /dev/null @@ -1,85 +0,0 @@ -package com.izivia.ocpi.toolkit.modules.tokens - -import com.izivia.ocpi.toolkit.common.httpResponse -import com.izivia.ocpi.toolkit.common.mapper -import com.izivia.ocpi.toolkit.common.checkToken -import com.izivia.ocpi.toolkit.modules.credentials.repositories.PlatformRepository -import com.izivia.ocpi.toolkit.modules.tokens.domain.Token -import com.izivia.ocpi.toolkit.modules.tokens.domain.TokenPartial -import com.izivia.ocpi.toolkit.transport.TransportServer -import com.izivia.ocpi.toolkit.transport.domain.FixedPathSegment -import com.izivia.ocpi.toolkit.transport.domain.HttpMethod -import com.izivia.ocpi.toolkit.transport.domain.VariablePathSegment -import kotlinx.coroutines.runBlocking - -class TokensCpoServer( - private val transportServer: TransportServer, - private val platformRepository: PlatformRepository, - private val service: TokensCpoInterface, - basePath: List = listOf( - FixedPathSegment("/2.1.1/tokens") - ) -) { - init { - runBlocking { - transportServer.handle( - method = HttpMethod.GET, - path = basePath + listOf( - VariablePathSegment("countryCode"), - VariablePathSegment("partyId"), - VariablePathSegment("tokenUid") - ), - filters = listOf(platformRepository::checkToken) - ) { req -> - req.httpResponse { - service - .getToken( - countryCode = req.pathParams["countryCode"]!!, - partyId = req.pathParams["partyId"]!!, - tokenUid = req.pathParams["tokenUid"]!! - ) - } - } - - transportServer.handle( - method = HttpMethod.PUT, - path = basePath + listOf( - VariablePathSegment("countryCode"), - VariablePathSegment("partyId"), - VariablePathSegment("tokenUid") - ), - filters = listOf(platformRepository::checkToken) - ) { req -> - req.httpResponse { - service - .putToken( - countryCode = req.pathParams["countryCode"]!!, - partyId = req.pathParams["partyId"]!!, - tokenUid = req.pathParams["tokenUid"]!!, - token = mapper.readValue(req.body, Token::class.java) - ) - } - } - - transportServer.handle( - method = HttpMethod.PATCH, - path = basePath + listOf( - VariablePathSegment("countryCode"), - VariablePathSegment("partyId"), - VariablePathSegment("tokenUid") - ), - filters = listOf(platformRepository::checkToken) - ) { req -> - req.httpResponse { - service - .patchToken( - countryCode = req.pathParams["countryCode"]!!, - partyId = req.pathParams["partyId"]!!, - tokenUid = req.pathParams["tokenUid"]!!, - token = mapper.readValue(req.body!!, TokenPartial::class.java) - ) - } - } - } - } -} diff --git a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/TokensEmspClient.kt b/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/TokensEmspClient.kt deleted file mode 100644 index 5ffafa30..00000000 --- a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/TokensEmspClient.kt +++ /dev/null @@ -1,71 +0,0 @@ -package com.izivia.ocpi.toolkit.modules.tokens - -import com.izivia.ocpi.toolkit.common.* -import com.izivia.ocpi.toolkit.modules.credentials.repositories.PlatformRepository -import com.izivia.ocpi.toolkit.modules.tokens.domain.Token -import com.izivia.ocpi.toolkit.modules.tokens.domain.TokenPartial -import com.izivia.ocpi.toolkit.modules.versions.domain.ModuleID -import com.izivia.ocpi.toolkit.transport.TransportClient -import com.izivia.ocpi.toolkit.transport.TransportClientBuilder -import com.izivia.ocpi.toolkit.transport.domain.HttpMethod -import com.izivia.ocpi.toolkit.transport.domain.HttpRequest - -class TokensEmspClient( - private val transportClientBuilder: TransportClientBuilder, - private val serverVersionsEndpointUrl: String, - private val platformRepository: PlatformRepository -) : TokensCpoInterface { - - private fun buildTransport(): TransportClient = transportClientBuilder - .buildFor( - module = ModuleID.tokens, - platformUrl = serverVersionsEndpointUrl, - platformRepository = platformRepository - ) - - override fun getToken( - countryCode: String, - partyId: String, - tokenUid: String - ): OcpiResponseBody = - buildTransport() - .send( - HttpRequest( - method = HttpMethod.GET, - path = "/$countryCode/$partyId/$tokenUid" - ).authenticate(platformRepository = platformRepository, baseUrl = serverVersionsEndpointUrl) - ) - .parseBody() - - override fun putToken( - countryCode: String, - partyId: String, - tokenUid: String, - token: Token - ): OcpiResponseBody = - buildTransport() - .send( - HttpRequest( - method = HttpMethod.PUT, - path = "/$countryCode/$partyId/$tokenUid", - body = mapper.writeValueAsString(token) - ).authenticate(platformRepository = platformRepository, baseUrl = serverVersionsEndpointUrl) - ) - .parseBody() - - override fun patchToken( - countryCode: String, - partyId: String, - tokenUid: String, - token: TokenPartial - ): OcpiResponseBody = - buildTransport() - .send( - HttpRequest( - method = HttpMethod.PATCH, - path = "/$countryCode/$partyId/$tokenUid", - body = mapper.writeValueAsString(token) - ).authenticate(platformRepository = platformRepository, baseUrl = serverVersionsEndpointUrl) - ) - .parseBody() -} diff --git a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/TokensEmspInterface.kt b/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/TokensEmspInterface.kt deleted file mode 100644 index 49b7534a..00000000 --- a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/TokensEmspInterface.kt +++ /dev/null @@ -1,117 +0,0 @@ -package com.izivia.ocpi.toolkit.modules.tokens - -import com.izivia.ocpi.toolkit.common.OcpiResponseBody -import com.izivia.ocpi.toolkit.common.SearchResult -import com.izivia.ocpi.toolkit.modules.tokens.domain.AuthorizationInfo -import com.izivia.ocpi.toolkit.modules.tokens.domain.LocationReferences -import com.izivia.ocpi.toolkit.modules.tokens.domain.Token -import com.izivia.ocpi.toolkit.modules.tokens.domain.TokenType -import java.time.Instant - -/** - * This interface enables the CPO to request the current list of Tokens, when needed. Via the POST method it is possible - * to authorize a single token. Example endpoint structure: /ocpi/emsp/2.0/tokens/?date_from=xxx&date_to=yyy - * - * - GET: Get the list of known Tokens, last updated between the {date_from} and {date_to} (paginated) - * - POST: Real-time authorization request - * - PUT: n/a - * - PATCH: n/a - * - DELETE: n/a - */ -interface TokensEmspInterface { - - /** - * Updated by Gireve from OCPI 2.1.1 (added countryCode / partyId) - * - * Fetch information about Tokens known in the eMSP systems. - * - * If additional parameters: {date_from} and/or {date_to} are provided, only Tokens with (last_updated) between the - * iven date_from and date_to will be returned. - * - * This request is paginated, it supports the pagination related URL parameters. - * - * Gireve notes: - * The standard OCPI 2.1.1 Tokens pulling allows CPOs to get Tokens of all eMSPs in contract with them. In some - * cases, CPOs need only Tokens of a specific given eMSP. For example, when the CPO initializes data of an eMSP - * after signature of a new roaming agreement. GIREVE provides a new OCPI 2.1.1 feature by allowing the CPO to get - * Tokens of a unique eMSP by filling two dedicated OCPI headers in their “GET Tokens” request to GIREVE: - * - ocpi-to-country-code: The country code of the targeted eMSP. - * - ocpi-to-party-id: The party id of the targeted eMSP. - * Therefore, CPOs can request GIREVE without these headers to get Tokens of all eMSPs or including these headers to - * get Tokens of a unique eMSP. For information, these headers have been included in the version 2.2 of the OCPI - * standard. - * - * @param dateFrom Only return Tokens that have last_updated after this Date/Time. - * @param dateTo Only return Tokens that have last_updated before this Date/Time. - * @param offset The offset of the first object returned. Default is 0. - * @param limit Maximum number of objects to GET. - * @param countryCode (max-length 2) The party id of the targeted eMSP. - * @param partyId (max-length 3) Party ID (Provider ID) of the eMSP requesting this GET from the CPO system. - * @return The endpoint response with list of valid Token objects, the header will contain the pagination related - * headers. - */ - fun getTokens( - dateFrom: Instant?, - dateTo: Instant?, - offset: Int = 0, - limit: Int?, - countryCode: String?, - partyId: String? - ): OcpiResponseBody> - - /** - * Gireve-unique feature - * - * IOP adds a new OCPI feature enabling a CPO to retrieve the full description of a Token through the Tokens.uid. - * - * If the CPO is allowed to get Tokens of the eMSP owner, the response includes the full description of the Token. - * - * Gireve notes: - * This new flow prevents CPOs to download all Tokens of all eMSPs. For more description, see 2.3.5 Custom OCPI flow - * to prevent eMSP Tokens download by CPOs - * - * @param tokenUid (max-length 36) Token.uid of the Token for which this authorization is. - * @param tokenType Token.type of the Token for which this authorization is. Default if omitted: RFID - * @return Standard OCPI response including the Token description in data field. In case of an unknown Token or - * Token not visible by the CPO, the status_code "2000" is returned - */ - fun getToken( - tokenUid: String, - tokenType: TokenType = TokenType.RFID - ): OcpiResponseBody - - /** - * Updated by Gireve, LocationReferences is mandatory and must contain one and only one EVSE. - * - * Do a 'real-time' authorization request to the eMSP system, validating if a Token might be used (at the optionally - * given Location). - * - * Example endpoint structure: /ocpi/emsp/2.0/tokens/{token_uid}/authorize?{type=token_type} The /authorize is - * required for the real-time authorize request. - * - * When the eMSP receives a 'real-time' authorization request from a CPO that contains too little information (no - * LocationReferences provided) to determine if the Token might be used, the eMSP SHOULD respond with the OCPI - * status: 2002 - * - * In the body an optional LocationReferences object can be given. The eMSP SHALL then validate if the Token is - * allowed to be used at this Location, and if applicable: which of the Locations EVSEs/Connectors. The object with - * valid Location and EVSEs/Connectors will be returned in the response. - * - * Gireve notes: - * If « LocationReferences » object contains 0 EVSE, IOP responds with a 2002 OCPI error (« Missing EVSEd »). - * If « LocationReferences » object contains more than 1 EVSE, IOP responds with a 2001 OCPI error (« Invalid or - * missing parameters: IOP does not support authorization request on multiple EVSE »). - * - * @param tokenUid (max-length 36) Token.uid of the Token for which this authorization is. - * @param tokenType Token.type of the Token for which this authorization is. Default if omitted: RFID - * @param locationReferences Location and EVSE/Connectors for which the Token is requested to be authorized. Must - * contain one and only one EVSE - * @return Contains information about the authorization, if the Token is allowed to charge and optionally which - * EVSEs/Connectors are allowed to be used. - */ - fun postToken( - tokenUid: String, - tokenType: TokenType = TokenType.RFID, - locationReferences: LocationReferences - ): OcpiResponseBody -} diff --git a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/TokensEmspServer.kt b/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/TokensEmspServer.kt deleted file mode 100644 index 8f181973..00000000 --- a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/TokensEmspServer.kt +++ /dev/null @@ -1,92 +0,0 @@ -package com.izivia.ocpi.toolkit.modules.tokens - -import com.izivia.ocpi.toolkit.common.httpResponse -import com.izivia.ocpi.toolkit.common.mapper -import com.izivia.ocpi.toolkit.common.checkToken -import com.izivia.ocpi.toolkit.modules.credentials.repositories.PlatformRepository -import com.izivia.ocpi.toolkit.modules.tokens.domain.LocationReferences -import com.izivia.ocpi.toolkit.modules.tokens.domain.TokenType -import com.izivia.ocpi.toolkit.transport.TransportServer -import com.izivia.ocpi.toolkit.transport.domain.FixedPathSegment -import com.izivia.ocpi.toolkit.transport.domain.HttpMethod -import com.izivia.ocpi.toolkit.transport.domain.VariablePathSegment -import kotlinx.coroutines.runBlocking -import java.time.Instant - -class TokensEmspServer( - private val transportServer: TransportServer, - private val platformRepository: PlatformRepository, - private val service: TokensEmspInterface, - basePath: List = listOf( - FixedPathSegment("/2.1.1/tokens") - ) -) { - init { - runBlocking { - transportServer.handle( - method = HttpMethod.GET, - path = basePath, - queryParams = listOf( - "date_from", - "date_to", - "offset", - "limit", - "ocpi-to-country-code", - "ocpi-to-party-id" - ), - filters = listOf(platformRepository::checkToken) - ) { req -> - req.httpResponse { - val dateFrom = req.queryParams["date_from"] - val dateTo = req.queryParams["date_to"] - - service - .getTokens( - dateFrom = dateFrom?.let { Instant.parse(it) }, - dateTo = dateTo?.let { Instant.parse(it) }, - offset = req.queryParams["offset"]?.toInt() ?: 0, - limit = req.queryParams["limit"]?.toInt(), - countryCode = req.queryParams["ocpi-to-country-code"], - partyId = req.queryParams["ocpi-to-party-id"], - ) - } - } - - transportServer.handle( - method = HttpMethod.GET, - path = basePath + listOf( - VariablePathSegment("tokenUid") - ), - queryParams = listOf("type"), - filters = listOf(platformRepository::checkToken) - ) { req -> - req.httpResponse { - service - .getToken( - tokenUid = req.pathParams["tokenUid"]!!, - tokenType = req.queryParams["type"]?.run(TokenType::valueOf) ?: TokenType.RFID, - ) - } - } - - transportServer.handle( - method = HttpMethod.POST, - path = basePath + listOf( - VariablePathSegment("tokenUid"), - FixedPathSegment("authorize") - ), - queryParams = listOf("type"), - filters = listOf(platformRepository::checkToken) - ) { req -> - req.httpResponse { - service - .postToken( - tokenUid = req.pathParams["tokenUid"]!!, - tokenType = req.queryParams["type"]?.run(TokenType::valueOf) ?: TokenType.RFID, - locationReferences = req.body.run { mapper.readValue(this, LocationReferences::class.java) } - ) - } - } - } - } -} diff --git a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/domain/Allowed.kt b/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/domain/Allowed.kt deleted file mode 100644 index f245c975..00000000 --- a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/domain/Allowed.kt +++ /dev/null @@ -1,28 +0,0 @@ -package com.izivia.ocpi.toolkit.modules.tokens.domain - -enum class Allowed { - /** - * This Token is allowed to charge at this location - */ - ALLOWED, - - /** - * This Token is blocked. - */ - BLOCKED, - - /** - * This Token has expired. - */ - EXPIRED, - - /** - * This Token belongs to an account that has not enough credits to charge at the given location. - */ - NOT_CREDIT, - - /** - * Token is valid, but is not allowed to charge at the given location. - */ - NOT_ALLOWED -} diff --git a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/domain/AuthorizationInfo.kt b/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/domain/AuthorizationInfo.kt deleted file mode 100644 index 330ab924..00000000 --- a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/domain/AuthorizationInfo.kt +++ /dev/null @@ -1,21 +0,0 @@ -package com.izivia.ocpi.toolkit.modules.tokens.domain - -import com.izivia.ocpi.toolkit.modules.types.DisplayText - -/** - * Updated by Gireve: added authorization_id - * - * @property allowed Status of the Token, and whether charging is allowed at the optionally given location. - * @property location Optional reference to the location if it was included in the request, and if the EV driver is - * allowed to charge at that location. Only the EVSEs/Connectors the EV driver is allowed to charge at are returned. - * @property info Optional display text, additional information to the EV driver. - * @property authorization_id Unique identifier of the authorization within the eMSP platform. The CPO must store this - * information to send it in Sessions and CDRs related to this Authorization. Please refer to paragraph 2.3.2 New - * attribute « authorization_id » - */ -data class AuthorizationInfo( - val allowed: Allowed, - val location: LocationReferences?, - val info: DisplayText?, - val authorization_id: String -) diff --git a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/domain/LocationReferences.kt b/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/domain/LocationReferences.kt deleted file mode 100644 index 670d913b..00000000 --- a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/domain/LocationReferences.kt +++ /dev/null @@ -1,15 +0,0 @@ -package com.izivia.ocpi.toolkit.modules.tokens.domain - -/** - * References to location details. - * @property location_id (max-length 39) Unique identifier for the location. - * @property evse_uids (list of string of max-length 39) Unique identifier for EVSEs within the CPO's platform for the - * EVSE within the the given location. - * @property connector_ids (list of string of max-length 39) Identifies the connectors within the given EVSEs. - * @constructor - */ -data class LocationReferences( - val location_id: String, - val evse_uids: List, - val connector_ids: List -) diff --git a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/domain/Token.kt b/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/domain/Token.kt deleted file mode 100644 index aa36e9ee..00000000 --- a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/domain/Token.kt +++ /dev/null @@ -1,34 +0,0 @@ -package com.izivia.ocpi.toolkit.modules.tokens.domain - -import com.izivia.ocpi.toolkit.annotations.Partial -import java.time.Instant - -/** - * @property uid (max-length 36) Identification used by CPO system to identify this token. Currently, in most cases, - * this is the RFID hidden ID as read by the RFID reader. - * @property type Type of the token - * @property auth_id (max-length 36) Uniquely identifies the EV Driver contract token within the eMSP's platform (and - * suboperator platforms). Recommended to follow the specification for eMA ID from "eMI3 standard version V1.0" - * (http://emi3group.com/documents-links/) "Part 2: business objects." - * @property visual_number (max-length 64) Visual readable number/identification as printed on the Token (RFID card), - * might be equal to the auth_id. - * @property issuer (max-length 64) Issuing company, most of the times the name of the company printed on the token - * (RFID card), not necessarily the eMSP. - * @property valid Is this Token valid - * @property whitelist Indicates what type of white-listing is allowed. - * @property language (max-length 2) Language Code ISO 639-1. This optional field indicates the Token owner's preferred - * interface language. If the language is not provided or not supported then the CPO is free to choose its own language. - * @property last_updated Timestamp when this Token was last updated (or created). - */ -@Partial -data class Token( - val uid: String, - val type: TokenType, - val auth_id: String, - val visual_number: String?, - val issuer: String, - val valid: Boolean, - val whitelist: WhitelistType, - val language: String?, - val last_updated: Instant -) diff --git a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/domain/TokenType.kt b/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/domain/TokenType.kt deleted file mode 100644 index d8888322..00000000 --- a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/domain/TokenType.kt +++ /dev/null @@ -1,13 +0,0 @@ -package com.izivia.ocpi.toolkit.modules.tokens.domain - -enum class TokenType { - /** - * Other type of token - */ - OTHER, - - /** - * RFID Token - */ - RFID -} diff --git a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/domain/WhitelistType.kt b/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/domain/WhitelistType.kt deleted file mode 100644 index bda97737..00000000 --- a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/domain/WhitelistType.kt +++ /dev/null @@ -1,26 +0,0 @@ -package com.izivia.ocpi.toolkit.modules.tokens.domain - -/** - * Defines when authorization of a Token by the CPO is allowed. - */ -enum class WhitelistType { - /** - * Token always has to be whitelisted, realtime authorization is not possible/allowed. - */ - ALWAYS, - - /** - * It is allowed to whitelist the token, realtime authorization is also allowed. - */ - ALLOWED, - - /** - * Whitelisting is only allowed when CPO cannot reach the eMSP (communication between CPO and eMSP is offline) - */ - ALLOWED_OFFLINE, - - /** - * Whitelisting is forbidden, only realtime authorization is allowed. Token should always be authorized by the eMSP. - */ - NEVER -} diff --git a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/services/TokensCpoService.kt b/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/services/TokensCpoService.kt deleted file mode 100644 index b1019864..00000000 --- a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/services/TokensCpoService.kt +++ /dev/null @@ -1,65 +0,0 @@ -package com.izivia.ocpi.toolkit.modules.tokens.services - -import com.izivia.ocpi.toolkit.modules.tokens.domain.Token -import com.izivia.ocpi.toolkit.modules.tokens.domain.TokenPartial - -/** - * With this interface the eMSP can push the Token information to the CPO. Tokens is a client owned object, so the - * end-points need to contain the required extra fields: {party_id} and {country_code}. Example endpoint structure: - * /ocpi/cpo/2.0/tokens/{country_code}/{party_id}/{token_uid} - * - * - GET: Retrieve a Token as it is stored in the CPO system. - * - POST: n/a - * - PUT: Push new/updated Token object to the CPO. - * - PATCH: Notify the CPO of partial updates to a Token. - * - DELETE: n/a, (Use PUT, Tokens cannot be removed). - */ -interface TokensCpoService { - - /** - * If the eMSP wants to check the status of a Token in the CPO system it might GET the object from the CPO system - * for validation purposes. The eMSP is the owner of the objects, so it would be illogical if the CPO system had a - * different status or was missing an object. - * - * @param countryCode (max-length 2) Country code of the eMSP requesting this GET from the CPO system. - * @param partyId (max-length 3) Party ID (Provider ID) of the eMSP requesting this GET from the CPO system. - * @param tokenUid (max-length 36) Token.uid of the Token object to retrieve. - * @return The requested Token object. - */ - fun getToken( - countryCode: String, - partyId: String, - tokenUid: String - ): Token? - - /** - * New or updated Token objects are pushed from the eMSP to the CPO. - * - * @param countryCode (max-length 2) Country code of the eMSP sending this PUT request to the CPO system. - * @param partyId (max-length 3) Party ID (Provider ID) of the eMSP sending this PUT request to the CPO system. - * @param tokenUid (max-length 36) Token.uid of the (new) Token object (to replace). - * @param token New or updated Token object. - */ - fun putToken( - countryCode: String, - partyId: String, - tokenUid: String, - token: Token - ): Token - - /** - * Same as the PUT method, but only the fields/objects that have to be updated have to be present, other - * fields/objects that are not specified are considered unchanged. - * - * @param countryCode (max-length 2) Country code of the eMSP sending this PUT request to the CPO system. - * @param partyId (max-length 3) Party ID (Provider ID) of the eMSP sending this PUT request to the CPO system. - * @param tokenUid (max-length 36) Token.uid of the (new) Token object (to replace). - * @param token New or updated Token object. - */ - fun patchToken( - countryCode: String, - partyId: String, - tokenUid: String, - token: TokenPartial - ): Token -} diff --git a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/services/TokensEmspService.kt b/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/services/TokensEmspService.kt deleted file mode 100644 index 1261dc40..00000000 --- a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/services/TokensEmspService.kt +++ /dev/null @@ -1,108 +0,0 @@ -package com.izivia.ocpi.toolkit.modules.tokens.services - -import com.izivia.ocpi.toolkit.common.SearchResult -import com.izivia.ocpi.toolkit.modules.tokens.domain.AuthorizationInfo -import com.izivia.ocpi.toolkit.modules.tokens.domain.LocationReferences -import com.izivia.ocpi.toolkit.modules.tokens.domain.Token -import com.izivia.ocpi.toolkit.modules.tokens.domain.TokenType -import java.time.Instant - -/** - * This interface enables the CPO to request the current list of Tokens, when needed. Via the POST method it is possible - * to authorize a single token. Example endpoint structure: /ocpi/emsp/2.0/tokens/?date_from=xxx&date_to=yyy - * - * - GET: Get the list of known Tokens, last updated between the {date_from} and {date_to} (paginated) - * - POST: Real-time authorization request - * - PUT: n/a - * - PATCH: n/a - * - DELETE: n/a - */ -interface TokensEmspService { - - /** - * Updated by Gireve from OCPI 2.1.1 (added countryCode / partyId) - * - * Fetch information about Tokens known in the eMSP systems. - * - * If additional parameters: {date_from} and/or {date_to} are provided, only Tokens with (last_updated) between the - * iven date_from and date_to will be returned. - * - * This request is paginated, it supports the pagination related URL parameters. - * - * Gireve notes: - * The standard OCPI 2.1.1 Tokens pulling allows CPOs to get Tokens of all eMSPs in contract with them. In some - * cases, CPOs need only Tokens of a specific given eMSP. For example, when the CPO initializes data of an eMSP - * after signature of a new roaming agreement. GIREVE provides a new OCPI 2.1.1 feature by allowing the CPO to get - * Tokens of a unique eMSP by filling two dedicated OCPI headers in their “GET Tokens” request to GIREVE: - * - ocpi-to-country-code: The country code of the targeted eMSP. - * - ocpi-to-party-id: The party id of the targeted eMSP. - * Therefore, CPOs can request GIREVE without these headers to get Tokens of all eMSPs or including these headers to - * get Tokens of a unique eMSP. For information, these headers have been included in the version 2.2 of the OCPI - * standard. - * - * @param dateFrom Only return Tokens that have last_updated after this Date/Time. - * @param dateTo Only return Tokens that have last_updated before this Date/Time. - * @param offset The offset of the first object returned. Default is 0. - * @param limit Maximum number of objects to GET. - * @param countryCode (max-length 2) The party id of the targeted eMSP. - * @param partyId (max-length 3) Party ID (Provider ID) of the eMSP requesting this GET from the CPO system. - * @return The endpoint response with list of valid Token objects, the header will contain the pagination related - * headers. - */ - fun getTokens( - dateFrom: Instant?, - dateTo: Instant?, - offset: Int = 0, - limit: Int?, - countryCode: String?, - partyId: String? - ): SearchResult - - /** - * Gireve-unique feature - * - * IOP adds a new OCPI feature enabling a CPO to retrieve the full description of a Token through the Tokens.uid. - * - * If the CPO is allowed to get Tokens of the eMSP owner, the response includes the full description of the Token. - * - * Gireve notes: - * This new flow prevents CPOs to download all Tokens of all eMSPs. For more description, see 2.3.5 Custom OCPI flow - * to prevent eMSP Tokens download by CPOs - * - * @param tokenUid (max-length 36) Token.uid of the Token for which this authorization is. - * @param tokenType Token.type of the Token for which this authorization is. Default if omitted: RFID - * @return Standard OCPI response including the Token description in data field. In case of an unknown Token or - * Token not visible by the CPO, the status_code "2000" is returned - */ - fun getToken( - tokenUid: String, - tokenType: TokenType = TokenType.RFID - ): Token? - - /** - * Do a 'real-time' authorization request to the eMSP system, validating if a Token might be used (at the optionally - * given Location). - * - * Example endpoint structure: /ocpi/emsp/2.0/tokens/{token_uid}/authorize?{type=token_type} The /authorize is - * required for the real-time authorize request. - * - * When the eMSP receives a 'real-time' authorization request from a CPO that contains too little information (no - * LocationReferences provided) to determine if the Token might be used, the eMSP SHOULD respond with the OCPI - * status: 2002 - * - * In the body an optional LocationReferences object can be given. The eMSP SHALL then validate if the Token is - * allowed to be used at this Location, and if applicable: which of the Locations EVSEs/Connectors. The object with - * valid Location and EVSEs/Connectors will be returned in the response. - * - * @param tokenUid (max-length 36) Token.uid of the Token for which this authorization is. - * @param tokenType Token.type of the Token for which this authorization is. Default if omitted: RFID - * @param locationReferences Location and EVSEs/Connectors for which the Token is requested to be authorized. - * @return Contains information about the authorization, if the Token is allowed to charge and optionally which - * EVSEs/Connectors are allowed to be used. - */ - fun postToken( - tokenUid: String, - tokenType: TokenType = TokenType.RFID, - locationReferences: LocationReferences - ): AuthorizationInfo -} diff --git a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/validation/TokensCpoValidationService.kt b/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/validation/TokensCpoValidationService.kt deleted file mode 100644 index 4ddbbf00..00000000 --- a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/validation/TokensCpoValidationService.kt +++ /dev/null @@ -1,67 +0,0 @@ -package com.izivia.ocpi.toolkit.modules.tokens.validation - -import com.izivia.ocpi.toolkit.common.OcpiResponseBody -import com.izivia.ocpi.toolkit.common.validation.validate -import com.izivia.ocpi.toolkit.common.validation.validateLength -import com.izivia.ocpi.toolkit.modules.tokens.TokensCpoInterface -import com.izivia.ocpi.toolkit.modules.tokens.domain.Token -import com.izivia.ocpi.toolkit.modules.tokens.domain.TokenPartial -import com.izivia.ocpi.toolkit.modules.tokens.services.TokensCpoService - -class TokensCpoValidationService( - private val service: TokensCpoService -): TokensCpoInterface { - - override fun getToken( - countryCode: String, - partyId: String, - tokenUid: String - ): OcpiResponseBody = OcpiResponseBody.of { - validate { - validateLength("countryCode", countryCode, 2) - validateLength("partyId", partyId, 3) - validateLength("tokenUid", tokenUid, 36) - } - - service - .getToken(countryCode = countryCode, partyId = partyId, tokenUid = tokenUid) - ?.validate() - } - - override fun putToken( - countryCode: String, - partyId: String, - tokenUid: String, - token: Token - ): OcpiResponseBody = OcpiResponseBody.of { - validate { - validateLength("countryCode", countryCode, 2) - validateLength("partyId", partyId, 3) - validateLength("tokenUid", tokenUid, 36) - token.validate() - } - - service - .putToken(countryCode = countryCode, partyId = partyId, tokenUid = tokenUid, token = token) - .validate() - } - - override fun patchToken( - countryCode: String, - partyId: String, - tokenUid: String, - token: TokenPartial - ): OcpiResponseBody = OcpiResponseBody.of { - validate { - validateLength("countryCode", countryCode, 2) - validateLength("partyId", partyId, 3) - validateLength("tokenUid", tokenUid, 36) - token.validate() - } - - service - .patchToken(countryCode = countryCode, partyId = partyId, tokenUid = tokenUid, token = token) - .validate() - } - -} diff --git a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/validation/TokensEmspValidationService.kt b/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/validation/TokensEmspValidationService.kt deleted file mode 100644 index f9d49dee..00000000 --- a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/validation/TokensEmspValidationService.kt +++ /dev/null @@ -1,78 +0,0 @@ -package com.izivia.ocpi.toolkit.modules.tokens.validation - -import com.izivia.ocpi.toolkit.common.OcpiResponseBody -import com.izivia.ocpi.toolkit.common.OcpiResponseBody.Companion.invalid -import com.izivia.ocpi.toolkit.common.OcpiResponseBody.Companion.notEnoughInformation -import com.izivia.ocpi.toolkit.common.SearchResult -import com.izivia.ocpi.toolkit.common.validation.validate -import com.izivia.ocpi.toolkit.common.validation.validateDates -import com.izivia.ocpi.toolkit.common.validation.validateInt -import com.izivia.ocpi.toolkit.common.validation.validateLength -import com.izivia.ocpi.toolkit.modules.tokens.TokensEmspInterface -import com.izivia.ocpi.toolkit.modules.tokens.domain.AuthorizationInfo -import com.izivia.ocpi.toolkit.modules.tokens.domain.LocationReferences -import com.izivia.ocpi.toolkit.modules.tokens.domain.Token -import com.izivia.ocpi.toolkit.modules.tokens.domain.TokenType -import com.izivia.ocpi.toolkit.modules.tokens.services.TokensEmspService -import java.time.Instant - -class TokensEmspValidationService( - private val service: TokensEmspService -) : TokensEmspInterface { - - override fun getTokens( - dateFrom: Instant?, - dateTo: Instant?, - offset: Int, - limit: Int?, - countryCode: String?, - partyId: String? - ): OcpiResponseBody> = OcpiResponseBody.of { - validate { - if (dateFrom != null && dateTo != null) validateDates("dateFrom", dateFrom, "dateTo", dateTo) - if (limit != null) validateInt("limit", limit, 0, null) - validateInt("offset", offset, 0, null) - if (countryCode != null) validateLength("countryCode", countryCode, 2) - if (partyId != null) validateLength("partyId", partyId, 3) - } - - service - .getTokens(dateFrom, dateTo, offset, limit, countryCode, partyId) - .also { searchResult -> - searchResult.list.forEach { token -> token.validate() } - } - } - - override fun getToken(tokenUid: String, tokenType: TokenType): OcpiResponseBody = - OcpiResponseBody.of { - validate { - validateLength("tokenUid", tokenUid, 36) - } - - service - .getToken(tokenUid = tokenUid, tokenType = tokenType) - ?.validate() - } - - override fun postToken( - tokenUid: String, - tokenType: TokenType, - locationReferences: LocationReferences - ): OcpiResponseBody = - if (locationReferences.evse_uids.isEmpty()) { - notEnoughInformation("Missing EVSE Id") - } else if (locationReferences.evse_uids.size > 1) { - invalid("Invalid or missing parameters: IOP does not support authorization request on multiple EVSE") - } else { - OcpiResponseBody.of { - validate { - validateLength("tokenUid", tokenUid, 36) - locationReferences.validate() - } - - service - .postToken(tokenUid = tokenUid, tokenType = tokenType, locationReferences = locationReferences) - .validate() - } - } -} diff --git a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/validation/TokensValidators.kt b/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/validation/TokensValidators.kt deleted file mode 100644 index 110e0c40..00000000 --- a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/validation/TokensValidators.kt +++ /dev/null @@ -1,50 +0,0 @@ -package com.izivia.ocpi.toolkit.modules.tokens.validation - -import com.izivia.ocpi.toolkit.common.validation.hasMaxLengthOf -import com.izivia.ocpi.toolkit.common.validation.isLanguage -import com.izivia.ocpi.toolkit.common.validation.isPrintableAscii -import com.izivia.ocpi.toolkit.modules.locations.validation.validate -import com.izivia.ocpi.toolkit.modules.tokens.domain.* -import org.valiktor.validate - -private data class StringWrapper(val str: String) - -fun TokenPartial.validate(): TokenPartial = validate(this) { - validate(TokenPartial::uid).isPrintableAscii().hasMaxLengthOf(36) - // type: nothing to validate - validate(TokenPartial::auth_id).isPrintableAscii().hasMaxLengthOf(36) - validate(TokenPartial::visual_number).isPrintableAscii().hasMaxLengthOf(64) - validate(TokenPartial::issuer).isPrintableAscii().hasMaxLengthOf(64) - // valid: nothing to validate - // whitelist: nothing to validate - validate(TokenPartial::language).isLanguage() - // last_updated: : nothing to validate -} - -fun LocationReferences.validate(): LocationReferences = validate(this) { - validate(LocationReferences::location_id).isPrintableAscii().hasMaxLengthOf(39) - evse_uids - .map { StringWrapper(it) } - .forEach { - validate(it) { - validate(StringWrapper::str).isPrintableAscii().hasMaxLengthOf(39) - } - } - connector_ids - .map { StringWrapper(it) } - .forEach { - validate(it) { - validate(StringWrapper::str).isPrintableAscii().hasMaxLengthOf(39) - } - } -} - -fun AuthorizationInfo.validate(): AuthorizationInfo = validate(this) { - // allowed: nothing to validate - location?.validate() - info?.validate() -} - -fun Token.validate(): Token = validate(this) { - toPartial().validate() -} diff --git a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/types/DisplayText.kt b/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/types/DisplayText.kt deleted file mode 100644 index acbf6c7c..00000000 --- a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/types/DisplayText.kt +++ /dev/null @@ -1,13 +0,0 @@ -package com.izivia.ocpi.toolkit.modules.types - -import com.izivia.ocpi.toolkit.annotations.Partial - -/** - * @property language (max-length=2) Language Code ISO 639-1 - * @property text (max-length=512) Text to be displayed to an end user. No markup, html etc. allowed. - */ -@Partial -data class DisplayText( - val language: String, - val text: String -) diff --git a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/versions/VersionDetailsClient.kt b/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/versions/VersionDetailsClient.kt deleted file mode 100644 index 088edc86..00000000 --- a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/versions/VersionDetailsClient.kt +++ /dev/null @@ -1,42 +0,0 @@ -package com.izivia.ocpi.toolkit.modules.versions - -import com.izivia.ocpi.toolkit.common.OcpiResponseBody -import com.izivia.ocpi.toolkit.common.OcpiToolkitUnknownEndpointException -import com.izivia.ocpi.toolkit.common.authenticate -import com.izivia.ocpi.toolkit.common.parseBody -import com.izivia.ocpi.toolkit.modules.credentials.repositories.PlatformRepository -import com.izivia.ocpi.toolkit.modules.versions.domain.VersionDetails -import com.izivia.ocpi.toolkit.transport.TransportClientBuilder -import com.izivia.ocpi.toolkit.transport.domain.HttpMethod -import com.izivia.ocpi.toolkit.transport.domain.HttpRequest - -/** - * Used to get the version details of a platform - * @property transportClientBuilder used to build transport client - * @property serverVersionsEndpointUrl used to know which platform to communicate with - * @property platformRepository used to get information about the platform (endpoint, token) - */ -class VersionDetailsClient( - private val transportClientBuilder: TransportClientBuilder, - private val serverVersionsEndpointUrl: String, - private val platformRepository: PlatformRepository -) : VersionDetailsInterface { - - override fun getVersionDetails(): OcpiResponseBody = - transportClientBuilder - .build(baseUrl = platformRepository - .getVersion(platformUrl = serverVersionsEndpointUrl) - ?.url - ?: throw OcpiToolkitUnknownEndpointException("version details") - ) - .send( - HttpRequest( - method = HttpMethod.GET - ).authenticate( - platformRepository = platformRepository, - baseUrl = serverVersionsEndpointUrl, - allowTokenAOrTokenB = true - ) - ) - .parseBody() -} diff --git a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/versions/VersionDetailsInterface.kt b/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/versions/VersionDetailsInterface.kt deleted file mode 100644 index 64d847db..00000000 --- a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/versions/VersionDetailsInterface.kt +++ /dev/null @@ -1,8 +0,0 @@ -package com.izivia.ocpi.toolkit.modules.versions - -import com.izivia.ocpi.toolkit.common.OcpiResponseBody -import com.izivia.ocpi.toolkit.modules.versions.domain.VersionDetails - -interface VersionDetailsInterface { - fun getVersionDetails(): OcpiResponseBody -} \ No newline at end of file diff --git a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/versions/VersionDetailsServer.kt b/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/versions/VersionDetailsServer.kt deleted file mode 100644 index 2aedbb59..00000000 --- a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/versions/VersionDetailsServer.kt +++ /dev/null @@ -1,36 +0,0 @@ -package com.izivia.ocpi.toolkit.modules.versions - -import com.izivia.ocpi.toolkit.common.httpResponse -import com.izivia.ocpi.toolkit.common.checkToken -import com.izivia.ocpi.toolkit.modules.credentials.repositories.PlatformRepository -import com.izivia.ocpi.toolkit.modules.versions.validation.VersionDetailsValidationService -import com.izivia.ocpi.toolkit.transport.TransportServer -import com.izivia.ocpi.toolkit.transport.domain.FixedPathSegment -import com.izivia.ocpi.toolkit.transport.domain.HttpMethod -import com.izivia.ocpi.toolkit.transport.domain.VariablePathSegment -import kotlinx.coroutines.runBlocking - -class VersionDetailsServer( - transportServer: TransportServer, - platformRepository: PlatformRepository, - validationService: VersionDetailsValidationService, - basePath: List = emptyList() -) { - init { - runBlocking { - transportServer.handle( - method = HttpMethod.GET, - path = basePath + listOf( - VariablePathSegment("versionNumber") - ), - filters = listOf(platformRepository::checkToken) - ) { req -> - req.httpResponse { - validationService.getVersionDetails( - versionNumber = req.pathParams["versionNumber"]!! - ) - } - } - } - } -} diff --git a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/versions/VersionsClient.kt b/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/versions/VersionsClient.kt deleted file mode 100644 index 2b42921d..00000000 --- a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/versions/VersionsClient.kt +++ /dev/null @@ -1,37 +0,0 @@ -package com.izivia.ocpi.toolkit.modules.versions - -import com.izivia.ocpi.toolkit.common.OcpiResponseBody -import com.izivia.ocpi.toolkit.common.authenticate -import com.izivia.ocpi.toolkit.common.parseBody -import com.izivia.ocpi.toolkit.modules.credentials.repositories.PlatformRepository -import com.izivia.ocpi.toolkit.modules.versions.domain.Version -import com.izivia.ocpi.toolkit.transport.TransportClientBuilder -import com.izivia.ocpi.toolkit.transport.domain.HttpMethod -import com.izivia.ocpi.toolkit.transport.domain.HttpRequest - -/** - * Used to get the versions of a platform - * @property transportClientBuilder used to build transport client - * @property serverVersionsEndpointUrl used to know which platform to communicate with - * @property platformRepository used to get information about the platform (token) - */ -class VersionsClient( - private val transportClientBuilder: TransportClientBuilder, - private val serverVersionsEndpointUrl: String, - private val platformRepository: PlatformRepository -) : VersionsInterface { - - override fun getVersions(): OcpiResponseBody> = - transportClientBuilder - .build(baseUrl = serverVersionsEndpointUrl) - .send( - HttpRequest( - method = HttpMethod.GET - ).authenticate( - platformRepository = platformRepository, - baseUrl = serverVersionsEndpointUrl, - allowTokenAOrTokenB = true - ) - ) - .parseBody() -} diff --git a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/versions/VersionsInterface.kt b/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/versions/VersionsInterface.kt deleted file mode 100644 index bb0883d7..00000000 --- a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/versions/VersionsInterface.kt +++ /dev/null @@ -1,8 +0,0 @@ -package com.izivia.ocpi.toolkit.modules.versions - -import com.izivia.ocpi.toolkit.common.OcpiResponseBody -import com.izivia.ocpi.toolkit.modules.versions.domain.Version - -interface VersionsInterface { - fun getVersions(): OcpiResponseBody> -} \ No newline at end of file diff --git a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/versions/VersionsServer.kt b/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/versions/VersionsServer.kt deleted file mode 100644 index b74c2911..00000000 --- a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/versions/VersionsServer.kt +++ /dev/null @@ -1,34 +0,0 @@ -package com.izivia.ocpi.toolkit.modules.versions - -import com.izivia.ocpi.toolkit.common.httpResponse -import com.izivia.ocpi.toolkit.common.checkToken -import com.izivia.ocpi.toolkit.modules.credentials.repositories.PlatformRepository -import com.izivia.ocpi.toolkit.modules.versions.validation.VersionsValidationService -import com.izivia.ocpi.toolkit.transport.TransportServer -import com.izivia.ocpi.toolkit.transport.domain.FixedPathSegment -import com.izivia.ocpi.toolkit.transport.domain.HttpMethod -import kotlinx.coroutines.runBlocking - -class VersionsServer( - transportServer: TransportServer, - platformRepository: PlatformRepository, - validationService: VersionsValidationService, - basePath: List = listOf( - FixedPathSegment("/versions") - ) -) { - - init { - runBlocking { - transportServer.handle( - method = HttpMethod.GET, - path = basePath, - filters = listOf(platformRepository::checkToken) - ) { req -> - req.httpResponse { - validationService.getVersions() - } - } - } - } -} diff --git a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/versions/domain/Endpoint.kt b/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/versions/domain/Endpoint.kt deleted file mode 100644 index 74942d54..00000000 --- a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/versions/domain/Endpoint.kt +++ /dev/null @@ -1,12 +0,0 @@ -package com.izivia.ocpi.toolkit.modules.versions.domain - -/** - * NOTE: for the credentials module, the role is not relevant as this module is the same for all roles - * - * @property identifier Endpoint identifie - * @property url URL to the endpoint - */ -data class Endpoint( - val identifier: ModuleID, - val url: String -) diff --git a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/versions/domain/InterfaceRole.kt b/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/versions/domain/InterfaceRole.kt deleted file mode 100644 index 099d8165..00000000 --- a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/versions/domain/InterfaceRole.kt +++ /dev/null @@ -1,15 +0,0 @@ -package com.izivia.ocpi.toolkit.modules.versions.domain - -enum class InterfaceRole { - /** - * Sender Interface implementation. Interface implemented by the owner of data, so the Receiver can Pull - * information from the data Sender/owner. - */ - SENDER, - - /** - * Receiver Interface implementation. Interface implemented by the receiver of data, so the Sender/owner can Push - * information to the Receiver. - */ - RECEIVER, -} \ No newline at end of file diff --git a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/versions/domain/ModuleID.kt b/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/versions/domain/ModuleID.kt deleted file mode 100644 index ab6c77ae..00000000 --- a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/versions/domain/ModuleID.kt +++ /dev/null @@ -1,30 +0,0 @@ -package com.izivia.ocpi.toolkit.modules.versions.domain - -/** - * The Module identifiers for each endpoint are described in the beginning of each Module chapter. The following table - * contains the list of modules in this version of OCPI. Most modules (except Credentials & Registration) are optional, - * but there might be dependencies between modules. If there are dependencies between modules, it will be mentioned in - * the affected module description. - */ -enum class ModuleID { - cdrs, - - chargingprofiles, - - commands, - - /** - * Required for all implementations. The role field has no function for this module - */ - credentials, - - hubclientinfo, - - locations, - - sessions, - - tariffs, - - tokens -} \ No newline at end of file diff --git a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/versions/domain/Version.kt b/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/versions/domain/Version.kt deleted file mode 100644 index 0da556d3..00000000 --- a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/versions/domain/Version.kt +++ /dev/null @@ -1,6 +0,0 @@ -package com.izivia.ocpi.toolkit.modules.versions.domain - -data class Version( - val version: String, - val url: String -) diff --git a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/versions/domain/VersionDetails.kt b/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/versions/domain/VersionDetails.kt deleted file mode 100644 index 5f368fb7..00000000 --- a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/versions/domain/VersionDetails.kt +++ /dev/null @@ -1,17 +0,0 @@ -package com.izivia.ocpi.toolkit.modules.versions.domain - -/** - * Via the version details, the parties can exchange which modules are implemented for a specific version of OCPI, which - * interface role is implemented, and what the endpoint URL is for this interface. - * - * Parties that are both CPO and eMSP (or a Hub) can implement one version endpoint that covers both roles. With the - * information that is available in the version details, parties don’t need to implement a separate endpoint per role - * (CPO or eMSP) anymore. In practice this means that when a company is both a CPO and an eMSP and it connects to - * another party that implements both interfaces, only one OCPI connection is needed. - * @property version The version number. - * @property endpoints A list of supported endpoints for this version. (at least one in the list) - */ -data class VersionDetails( - val version: String, - val endpoints: List -) diff --git a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/versions/domain/VersionNumber.kt b/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/versions/domain/VersionNumber.kt deleted file mode 100644 index 0e04998a..00000000 --- a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/versions/domain/VersionNumber.kt +++ /dev/null @@ -1,24 +0,0 @@ -package com.izivia.ocpi.toolkit.modules.versions.domain - -/** - * List of known versions. - */ -enum class VersionNumber(val value: String, val index: Int) { - /** - * OCPI version 2.1.1 - */ - V2_1_1("2.1.1", 2), - - /** - * OCPI version 2.2 (DEPRECATED, do not use, use 2.2.1 instead) - */ - V2_2("2.2", 3), - - /** - * OCPI version 2.2.1 (this version) - */ - V2_2_1("2.2.1", 4) -} - -fun parseVersionNumber(value: String): VersionNumber? = - VersionNumber.values().firstOrNull { it.value == value } \ No newline at end of file diff --git a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/versions/repositories/VersionDetailsRepository.kt b/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/versions/repositories/VersionDetailsRepository.kt deleted file mode 100644 index 8a5a3fd2..00000000 --- a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/versions/repositories/VersionDetailsRepository.kt +++ /dev/null @@ -1,8 +0,0 @@ -package com.izivia.ocpi.toolkit.modules.versions.repositories - -import com.izivia.ocpi.toolkit.modules.versions.domain.VersionDetails -import com.izivia.ocpi.toolkit.modules.versions.domain.VersionNumber - -interface VersionDetailsRepository { - fun getVersionDetails(versionNumber: VersionNumber): VersionDetails? -} \ No newline at end of file diff --git a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/versions/repositories/VersionsRepository.kt b/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/versions/repositories/VersionsRepository.kt deleted file mode 100644 index 565e308c..00000000 --- a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/versions/repositories/VersionsRepository.kt +++ /dev/null @@ -1,7 +0,0 @@ -package com.izivia.ocpi.toolkit.modules.versions.repositories - -import com.izivia.ocpi.toolkit.modules.versions.domain.Version - -interface VersionsRepository { - fun getVersions(): List -} \ No newline at end of file diff --git a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/versions/validation/VersionDetailsValidationService.kt b/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/versions/validation/VersionDetailsValidationService.kt deleted file mode 100644 index 4731b893..00000000 --- a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/versions/validation/VersionDetailsValidationService.kt +++ /dev/null @@ -1,21 +0,0 @@ -package com.izivia.ocpi.toolkit.modules.versions.validation - -import com.izivia.ocpi.toolkit.common.OcpiResponseBody -import com.izivia.ocpi.toolkit.common.OcpiServerUnsupportedVersionException -import com.izivia.ocpi.toolkit.modules.versions.domain.VersionDetails -import com.izivia.ocpi.toolkit.modules.versions.domain.parseVersionNumber -import com.izivia.ocpi.toolkit.modules.versions.repositories.VersionDetailsRepository - -class VersionDetailsValidationService( - private val repository: VersionDetailsRepository -) { - fun getVersionDetails( - versionNumber: String - ): OcpiResponseBody = OcpiResponseBody.of { - parseVersionNumber(versionNumber) - ?.let { parsedVersionNumber -> - repository.getVersionDetails(parsedVersionNumber) - } - ?: throw OcpiServerUnsupportedVersionException("Invalid version number: $versionNumber") - } -} \ No newline at end of file diff --git a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/versions/validation/VersionsValidationService.kt b/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/versions/validation/VersionsValidationService.kt deleted file mode 100644 index 699ebbb2..00000000 --- a/ocpi-toolkit-2.1.1-gireve/src/main/kotlin/com/izivia/ocpi/toolkit/modules/versions/validation/VersionsValidationService.kt +++ /dev/null @@ -1,15 +0,0 @@ -package com.izivia.ocpi.toolkit.modules.versions.validation - -import com.izivia.ocpi.toolkit.common.OcpiResponseBody -import com.izivia.ocpi.toolkit.modules.versions.VersionsInterface -import com.izivia.ocpi.toolkit.modules.versions.domain.Version -import com.izivia.ocpi.toolkit.modules.versions.repositories.VersionsRepository - -class VersionsValidationService( - private val repository: VersionsRepository -) : VersionsInterface { - - override fun getVersions(): OcpiResponseBody> = OcpiResponseBody.of { - repository.getVersions() - } -} \ No newline at end of file diff --git a/ocpi-toolkit-2.1.1-gireve/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/locations/domain/AdditionalGeoLocationPartial.kt b/ocpi-toolkit-2.1.1-gireve/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/locations/domain/AdditionalGeoLocationPartial.kt deleted file mode 100644 index 4e593072..00000000 --- a/ocpi-toolkit-2.1.1-gireve/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/locations/domain/AdditionalGeoLocationPartial.kt +++ /dev/null @@ -1,33 +0,0 @@ -// ---------- -// - WARNING - -// ---------- -// This code is generated AND MUST NOT BE EDITED -// ---------- -package com.izivia.ocpi.toolkit.modules.locations.domain - -import com.izivia.ocpi.toolkit.modules.types.DisplayTextPartial -import com.izivia.ocpi.toolkit.modules.types.toPartial -import kotlin.String -import kotlin.collections.List - -/** - * Partial representation of - * [com.izivia.ocpi.toolkit.modules.locations.domain.AdditionalGeoLocation] - */ -public data class AdditionalGeoLocationPartial( - public val latitude: String?, - public val longitude: String?, - public val name: DisplayTextPartial?, -) - -public fun AdditionalGeoLocation.toPartial(): AdditionalGeoLocationPartial { - return AdditionalGeoLocationPartial( - latitude = latitude, - longitude = longitude, - name = name?.toPartial() - ) -} - -public fun List.toPartial(): List { - return mapNotNull { it.toPartial() } -} diff --git a/ocpi-toolkit-2.1.1-gireve/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/locations/domain/BusinessDetailsPartial.kt b/ocpi-toolkit-2.1.1-gireve/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/locations/domain/BusinessDetailsPartial.kt deleted file mode 100644 index 3d3106b9..00000000 --- a/ocpi-toolkit-2.1.1-gireve/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/locations/domain/BusinessDetailsPartial.kt +++ /dev/null @@ -1,30 +0,0 @@ -// ---------- -// - WARNING - -// ---------- -// This code is generated AND MUST NOT BE EDITED -// ---------- -package com.izivia.ocpi.toolkit.modules.locations.domain - -import kotlin.String -import kotlin.collections.List - -/** - * Partial representation of [com.izivia.ocpi.toolkit.modules.locations.domain.BusinessDetails] - */ -public data class BusinessDetailsPartial( - public val name: String?, - public val website: String?, - public val logo: ImagePartial?, -) - -public fun BusinessDetails.toPartial(): BusinessDetailsPartial { - return BusinessDetailsPartial( - name = name, - website = website, - logo = logo?.toPartial() - ) -} - -public fun List.toPartial(): List { - return mapNotNull { it.toPartial() } -} diff --git a/ocpi-toolkit-2.1.1-gireve/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/locations/domain/ConnectorPartial.kt b/ocpi-toolkit-2.1.1-gireve/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/locations/domain/ConnectorPartial.kt deleted file mode 100644 index d294b8ca..00000000 --- a/ocpi-toolkit-2.1.1-gireve/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/locations/domain/ConnectorPartial.kt +++ /dev/null @@ -1,44 +0,0 @@ -// ---------- -// - WARNING - -// ---------- -// This code is generated AND MUST NOT BE EDITED -// ---------- -package com.izivia.ocpi.toolkit.modules.locations.domain - -import java.time.Instant -import kotlin.Int -import kotlin.String -import kotlin.collections.List - -/** - * Partial representation of [com.izivia.ocpi.toolkit.modules.locations.domain.Connector] - */ -public data class ConnectorPartial( - public val id: String?, - public val standard: ConnectorType?, - public val format: ConnectorFormat?, - public val power_type: PowerType?, - public val voltage: Int?, - public val amperage: Int?, - public val tariff_id: String?, - public val terms_and_conditions: String?, - public val last_updated: Instant?, -) - -public fun Connector.toPartial(): ConnectorPartial { - return ConnectorPartial( - id = id, - standard = standard, - format = format, - power_type = power_type, - voltage = voltage, - amperage = amperage, - tariff_id = tariff_id, - terms_and_conditions = terms_and_conditions, - last_updated = last_updated - ) -} - -public fun List.toPartial(): List { - return mapNotNull { it.toPartial() } -} diff --git a/ocpi-toolkit-2.1.1-gireve/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/locations/domain/EnergyMixPartial.kt b/ocpi-toolkit-2.1.1-gireve/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/locations/domain/EnergyMixPartial.kt deleted file mode 100644 index 178ec172..00000000 --- a/ocpi-toolkit-2.1.1-gireve/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/locations/domain/EnergyMixPartial.kt +++ /dev/null @@ -1,35 +0,0 @@ -// ---------- -// - WARNING - -// ---------- -// This code is generated AND MUST NOT BE EDITED -// ---------- -package com.izivia.ocpi.toolkit.modules.locations.domain - -import kotlin.Boolean -import kotlin.String -import kotlin.collections.List - -/** - * Partial representation of [com.izivia.ocpi.toolkit.modules.locations.domain.EnergyMix] - */ -public data class EnergyMixPartial( - public val is_green_energy: Boolean?, - public val energy_sources: List?, - public val environ_impact: List?, - public val supplier_name: String?, - public val energy_product_name: String?, -) - -public fun EnergyMix.toPartial(): EnergyMixPartial { - return EnergyMixPartial( - is_green_energy = is_green_energy, - energy_sources = energy_sources?.toPartial(), - environ_impact = environ_impact?.toPartial(), - supplier_name = supplier_name, - energy_product_name = energy_product_name - ) -} - -public fun List.toPartial(): List { - return mapNotNull { it.toPartial() } -} diff --git a/ocpi-toolkit-2.1.1-gireve/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/locations/domain/EnergySourcePartial.kt b/ocpi-toolkit-2.1.1-gireve/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/locations/domain/EnergySourcePartial.kt deleted file mode 100644 index 689ef406..00000000 --- a/ocpi-toolkit-2.1.1-gireve/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/locations/domain/EnergySourcePartial.kt +++ /dev/null @@ -1,28 +0,0 @@ -// ---------- -// - WARNING - -// ---------- -// This code is generated AND MUST NOT BE EDITED -// ---------- -package com.izivia.ocpi.toolkit.modules.locations.domain - -import java.math.BigDecimal -import kotlin.collections.List - -/** - * Partial representation of [com.izivia.ocpi.toolkit.modules.locations.domain.EnergySource] - */ -public data class EnergySourcePartial( - public val source: EnergySourceCategory?, - public val percentage: BigDecimal?, -) - -public fun EnergySource.toPartial(): EnergySourcePartial { - return EnergySourcePartial( - source = source, - percentage = percentage - ) -} - -public fun List.toPartial(): List { - return mapNotNull { it.toPartial() } -} diff --git a/ocpi-toolkit-2.1.1-gireve/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/locations/domain/EnvironmentalImpactPartial.kt b/ocpi-toolkit-2.1.1-gireve/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/locations/domain/EnvironmentalImpactPartial.kt deleted file mode 100644 index 3c4bd5dc..00000000 --- a/ocpi-toolkit-2.1.1-gireve/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/locations/domain/EnvironmentalImpactPartial.kt +++ /dev/null @@ -1,28 +0,0 @@ -// ---------- -// - WARNING - -// ---------- -// This code is generated AND MUST NOT BE EDITED -// ---------- -package com.izivia.ocpi.toolkit.modules.locations.domain - -import java.math.BigDecimal -import kotlin.collections.List - -/** - * Partial representation of [com.izivia.ocpi.toolkit.modules.locations.domain.EnvironmentalImpact] - */ -public data class EnvironmentalImpactPartial( - public val source: EnvironmentalImpactCategory?, - public val amount: BigDecimal?, -) - -public fun EnvironmentalImpact.toPartial(): EnvironmentalImpactPartial { - return EnvironmentalImpactPartial( - source = source, - amount = amount - ) -} - -public fun List.toPartial(): List { - return mapNotNull { it.toPartial() } -} diff --git a/ocpi-toolkit-2.1.1-gireve/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/locations/domain/EvsePartial.kt b/ocpi-toolkit-2.1.1-gireve/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/locations/domain/EvsePartial.kt deleted file mode 100644 index 11485b90..00000000 --- a/ocpi-toolkit-2.1.1-gireve/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/locations/domain/EvsePartial.kt +++ /dev/null @@ -1,53 +0,0 @@ -// ---------- -// - WARNING - -// ---------- -// This code is generated AND MUST NOT BE EDITED -// ---------- -package com.izivia.ocpi.toolkit.modules.locations.domain - -import com.izivia.ocpi.toolkit.modules.types.DisplayTextPartial -import com.izivia.ocpi.toolkit.modules.types.toPartial -import java.time.Instant -import kotlin.String -import kotlin.collections.List - -/** - * Partial representation of [com.izivia.ocpi.toolkit.modules.locations.domain.Evse] - */ -public data class EvsePartial( - public val uid: String?, - public val evse_id: String?, - public val status: Status?, - public val status_schedule: List?, - public val capabilities: List?, - public val connectors: List?, - public val floor_level: String?, - public val coordinates: GeoLocationPartial?, - public val physical_reference: String?, - public val directions: List?, - public val parking_restrictions: List?, - public val images: List?, - public val last_updated: Instant?, -) - -public fun Evse.toPartial(): EvsePartial { - return EvsePartial( - uid = uid, - evse_id = evse_id, - status = status, - status_schedule = status_schedule?.toPartial(), - capabilities = capabilities, - connectors = connectors.toPartial(), - floor_level = floor_level, - coordinates = coordinates?.toPartial(), - physical_reference = physical_reference, - directions = directions?.toPartial(), - parking_restrictions = parking_restrictions, - images = images?.toPartial(), - last_updated = last_updated - ) -} - -public fun List.toPartial(): List { - return mapNotNull { it.toPartial() } -} diff --git a/ocpi-toolkit-2.1.1-gireve/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/locations/domain/ExceptionalPeriodPartial.kt b/ocpi-toolkit-2.1.1-gireve/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/locations/domain/ExceptionalPeriodPartial.kt deleted file mode 100644 index cc44ed42..00000000 --- a/ocpi-toolkit-2.1.1-gireve/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/locations/domain/ExceptionalPeriodPartial.kt +++ /dev/null @@ -1,28 +0,0 @@ -// ---------- -// - WARNING - -// ---------- -// This code is generated AND MUST NOT BE EDITED -// ---------- -package com.izivia.ocpi.toolkit.modules.locations.domain - -import java.time.Instant -import kotlin.collections.List - -/** - * Partial representation of [com.izivia.ocpi.toolkit.modules.locations.domain.ExceptionalPeriod] - */ -public data class ExceptionalPeriodPartial( - public val period_begin: Instant?, - public val period_end: Instant?, -) - -public fun ExceptionalPeriod.toPartial(): ExceptionalPeriodPartial { - return ExceptionalPeriodPartial( - period_begin = period_begin, - period_end = period_end - ) -} - -public fun List.toPartial(): List { - return mapNotNull { it.toPartial() } -} diff --git a/ocpi-toolkit-2.1.1-gireve/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/locations/domain/GeoLocationPartial.kt b/ocpi-toolkit-2.1.1-gireve/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/locations/domain/GeoLocationPartial.kt deleted file mode 100644 index 49b0cd8a..00000000 --- a/ocpi-toolkit-2.1.1-gireve/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/locations/domain/GeoLocationPartial.kt +++ /dev/null @@ -1,28 +0,0 @@ -// ---------- -// - WARNING - -// ---------- -// This code is generated AND MUST NOT BE EDITED -// ---------- -package com.izivia.ocpi.toolkit.modules.locations.domain - -import kotlin.String -import kotlin.collections.List - -/** - * Partial representation of [com.izivia.ocpi.toolkit.modules.locations.domain.GeoLocation] - */ -public data class GeoLocationPartial( - public val latitude: String?, - public val longitude: String?, -) - -public fun GeoLocation.toPartial(): GeoLocationPartial { - return GeoLocationPartial( - latitude = latitude, - longitude = longitude - ) -} - -public fun List.toPartial(): List { - return mapNotNull { it.toPartial() } -} diff --git a/ocpi-toolkit-2.1.1-gireve/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/locations/domain/HoursPartial.kt b/ocpi-toolkit-2.1.1-gireve/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/locations/domain/HoursPartial.kt deleted file mode 100644 index c9d1cb3e..00000000 --- a/ocpi-toolkit-2.1.1-gireve/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/locations/domain/HoursPartial.kt +++ /dev/null @@ -1,32 +0,0 @@ -// ---------- -// - WARNING - -// ---------- -// This code is generated AND MUST NOT BE EDITED -// ---------- -package com.izivia.ocpi.toolkit.modules.locations.domain - -import kotlin.Boolean -import kotlin.collections.List - -/** - * Partial representation of [com.izivia.ocpi.toolkit.modules.locations.domain.Hours] - */ -public data class HoursPartial( - public val regular_hours: List?, - public val twenty_four_seven: Boolean?, - public val exceptional_openings: List?, - public val exceptional_closings: List?, -) - -public fun Hours.toPartial(): HoursPartial { - return HoursPartial( - regular_hours = regular_hours?.toPartial(), - twenty_four_seven = twenty_four_seven, - exceptional_openings = exceptional_openings?.toPartial(), - exceptional_closings = exceptional_closings?.toPartial() - ) -} - -public fun List.toPartial(): List { - return mapNotNull { it.toPartial() } -} diff --git a/ocpi-toolkit-2.1.1-gireve/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/locations/domain/ImagePartial.kt b/ocpi-toolkit-2.1.1-gireve/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/locations/domain/ImagePartial.kt deleted file mode 100644 index b5851cdf..00000000 --- a/ocpi-toolkit-2.1.1-gireve/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/locations/domain/ImagePartial.kt +++ /dev/null @@ -1,37 +0,0 @@ -// ---------- -// - WARNING - -// ---------- -// This code is generated AND MUST NOT BE EDITED -// ---------- -package com.izivia.ocpi.toolkit.modules.locations.domain - -import kotlin.Int -import kotlin.String -import kotlin.collections.List - -/** - * Partial representation of [com.izivia.ocpi.toolkit.modules.locations.domain.Image] - */ -public data class ImagePartial( - public val url: String?, - public val thumbnail: String?, - public val category: ImageCategory?, - public val type: String?, - public val width: Int?, - public val height: Int?, -) - -public fun Image.toPartial(): ImagePartial { - return ImagePartial( - url = url, - thumbnail = thumbnail, - category = category, - type = type, - width = width, - height = height - ) -} - -public fun List.toPartial(): List { - return mapNotNull { it.toPartial() } -} diff --git a/ocpi-toolkit-2.1.1-gireve/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/locations/domain/LocationPartial.kt b/ocpi-toolkit-2.1.1-gireve/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/locations/domain/LocationPartial.kt deleted file mode 100644 index f5cf64cb..00000000 --- a/ocpi-toolkit-2.1.1-gireve/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/locations/domain/LocationPartial.kt +++ /dev/null @@ -1,70 +0,0 @@ -// ---------- -// - WARNING - -// ---------- -// This code is generated AND MUST NOT BE EDITED -// ---------- -package com.izivia.ocpi.toolkit.modules.locations.domain - -import com.izivia.ocpi.toolkit.modules.types.DisplayTextPartial -import com.izivia.ocpi.toolkit.modules.types.toPartial -import java.time.Instant -import kotlin.Boolean -import kotlin.String -import kotlin.collections.List - -/** - * Partial representation of [com.izivia.ocpi.toolkit.modules.locations.domain.Location] - */ -public data class LocationPartial( - public val id: String?, - public val type: LocationType?, - public val name: String?, - public val address: String?, - public val city: String?, - public val postal_code: String?, - public val country: String?, - public val coordinates: GeoLocationPartial?, - public val related_locations: List?, - public val evses: List?, - public val directions: List?, - public val `operator`: BusinessDetailsPartial?, - public val suboperator: BusinessDetailsPartial?, - public val owner: BusinessDetailsPartial?, - public val facilities: List?, - public val time_zone: String?, - public val opening_times: HoursPartial?, - public val charging_when_closed: Boolean?, - public val images: List?, - public val energy_mix: EnergyMixPartial?, - public val last_updated: Instant?, -) - -public fun Location.toPartial(): LocationPartial { - return LocationPartial( - id = id, - type = type, - name = name, - address = address, - city = city, - postal_code = postal_code, - country = country, - coordinates = coordinates.toPartial(), - related_locations = related_locations?.toPartial(), - evses = evses?.toPartial(), - directions = directions?.toPartial(), - operator = operator?.toPartial(), - suboperator = suboperator?.toPartial(), - owner = owner?.toPartial(), - facilities = facilities, - time_zone = time_zone, - opening_times = opening_times?.toPartial(), - charging_when_closed = charging_when_closed, - images = images?.toPartial(), - energy_mix = energy_mix?.toPartial(), - last_updated = last_updated - ) -} - -public fun List.toPartial(): List { - return mapNotNull { it.toPartial() } -} diff --git a/ocpi-toolkit-2.1.1-gireve/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/locations/domain/RegularHoursPartial.kt b/ocpi-toolkit-2.1.1-gireve/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/locations/domain/RegularHoursPartial.kt deleted file mode 100644 index 1259b46b..00000000 --- a/ocpi-toolkit-2.1.1-gireve/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/locations/domain/RegularHoursPartial.kt +++ /dev/null @@ -1,31 +0,0 @@ -// ---------- -// - WARNING - -// ---------- -// This code is generated AND MUST NOT BE EDITED -// ---------- -package com.izivia.ocpi.toolkit.modules.locations.domain - -import kotlin.Int -import kotlin.String -import kotlin.collections.List - -/** - * Partial representation of [com.izivia.ocpi.toolkit.modules.locations.domain.RegularHours] - */ -public data class RegularHoursPartial( - public val weekday: Int?, - public val period_begin: String?, - public val period_end: String?, -) - -public fun RegularHours.toPartial(): RegularHoursPartial { - return RegularHoursPartial( - weekday = weekday, - period_begin = period_begin, - period_end = period_end - ) -} - -public fun List.toPartial(): List { - return mapNotNull { it.toPartial() } -} diff --git a/ocpi-toolkit-2.1.1-gireve/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/locations/domain/StatusSchedulePartial.kt b/ocpi-toolkit-2.1.1-gireve/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/locations/domain/StatusSchedulePartial.kt deleted file mode 100644 index 971f00a2..00000000 --- a/ocpi-toolkit-2.1.1-gireve/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/locations/domain/StatusSchedulePartial.kt +++ /dev/null @@ -1,30 +0,0 @@ -// ---------- -// - WARNING - -// ---------- -// This code is generated AND MUST NOT BE EDITED -// ---------- -package com.izivia.ocpi.toolkit.modules.locations.domain - -import java.time.Instant -import kotlin.collections.List - -/** - * Partial representation of [com.izivia.ocpi.toolkit.modules.locations.domain.StatusSchedule] - */ -public data class StatusSchedulePartial( - public val period_begin: Instant?, - public val period_end: Instant?, - public val status: Status?, -) - -public fun StatusSchedule.toPartial(): StatusSchedulePartial { - return StatusSchedulePartial( - period_begin = period_begin, - period_end = period_end, - status = status - ) -} - -public fun List.toPartial(): List { - return mapNotNull { it.toPartial() } -} diff --git a/ocpi-toolkit-2.1.1-gireve/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/tokens/domain/TokenPartial.kt b/ocpi-toolkit-2.1.1-gireve/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/tokens/domain/TokenPartial.kt deleted file mode 100644 index 5eb7c185..00000000 --- a/ocpi-toolkit-2.1.1-gireve/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/tokens/domain/TokenPartial.kt +++ /dev/null @@ -1,44 +0,0 @@ -// ---------- -// - WARNING - -// ---------- -// This code is generated AND MUST NOT BE EDITED -// ---------- -package com.izivia.ocpi.toolkit.modules.tokens.domain - -import java.time.Instant -import kotlin.Boolean -import kotlin.String -import kotlin.collections.List - -/** - * Partial representation of [com.izivia.ocpi.toolkit.modules.tokens.domain.Token] - */ -public data class TokenPartial( - public val uid: String?, - public val type: TokenType?, - public val auth_id: String?, - public val visual_number: String?, - public val issuer: String?, - public val valid: Boolean?, - public val whitelist: WhitelistType?, - public val language: String?, - public val last_updated: Instant?, -) - -public fun Token.toPartial(): TokenPartial { - return TokenPartial( - uid = uid, - type = type, - auth_id = auth_id, - visual_number = visual_number, - issuer = issuer, - valid = valid, - whitelist = whitelist, - language = language, - last_updated = last_updated - ) -} - -public fun List.toPartial(): List { - return mapNotNull { it.toPartial() } -} diff --git a/ocpi-toolkit-2.1.1-gireve/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/types/DisplayTextPartial.kt b/ocpi-toolkit-2.1.1-gireve/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/types/DisplayTextPartial.kt deleted file mode 100644 index 250eec77..00000000 --- a/ocpi-toolkit-2.1.1-gireve/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/types/DisplayTextPartial.kt +++ /dev/null @@ -1,28 +0,0 @@ -// ---------- -// - WARNING - -// ---------- -// This code is generated AND MUST NOT BE EDITED -// ---------- -package com.izivia.ocpi.toolkit.modules.types - -import kotlin.String -import kotlin.collections.List - -/** - * Partial representation of [com.izivia.ocpi.toolkit.modules.types.DisplayText] - */ -public data class DisplayTextPartial( - public val language: String?, - public val text: String?, -) - -public fun DisplayText.toPartial(): DisplayTextPartial { - return DisplayTextPartial( - language = language, - text = text - ) -} - -public fun List.toPartial(): List { - return mapNotNull { it.toPartial() } -} diff --git a/ocpi-toolkit-2.1.1-gireve/src/test/kotlin/com/izivia/ocpi/toolkit/samples/common/DummyPlatformCacheRepository.kt b/ocpi-toolkit-2.1.1-gireve/src/test/kotlin/com/izivia/ocpi/toolkit/samples/common/DummyPlatformCacheRepository.kt deleted file mode 100644 index 6223132b..00000000 --- a/ocpi-toolkit-2.1.1-gireve/src/test/kotlin/com/izivia/ocpi/toolkit/samples/common/DummyPlatformCacheRepository.kt +++ /dev/null @@ -1,10 +0,0 @@ -package com.izivia.ocpi.toolkit.samples.common - -class DummyPlatformCacheRepository(private val tokenC: String): com.izivia.ocpi.toolkit.samples.common.PlatformCacheRepository() { - - override fun getPlatformUrlByTokenC(token: String): String? = super.getPlatformUrlByTokenC(token) - ?: (if (token == tokenC) "*" else null) - - override fun getCredentialsTokenC(platformUrl: String): String = super.getCredentialsTokenC(platformUrl) - ?: tokenC -} diff --git a/ocpi-toolkit-2.1.1-gireve/src/test/kotlin/com/izivia/ocpi/toolkit/samples/common/Http4kTransportClient.kt b/ocpi-toolkit-2.1.1-gireve/src/test/kotlin/com/izivia/ocpi/toolkit/samples/common/Http4kTransportClient.kt deleted file mode 100644 index efa3f5be..00000000 --- a/ocpi-toolkit-2.1.1-gireve/src/test/kotlin/com/izivia/ocpi/toolkit/samples/common/Http4kTransportClient.kt +++ /dev/null @@ -1,49 +0,0 @@ -package com.izivia.ocpi.toolkit.samples.common - -import com.izivia.ocpi.toolkit.transport.TransportClient -import com.izivia.ocpi.toolkit.transport.domain.HttpRequest -import com.izivia.ocpi.toolkit.transport.domain.HttpResponse -import com.izivia.ocpi.toolkit.transport.domain.parseHttpStatus -import org.http4k.client.JettyClient -import org.http4k.core.Method -import org.http4k.core.Request -import org.http4k.core.Uri -import org.http4k.core.then -import org.http4k.filter.ClientFilters - -class Http4kTransportClient( - baseUrl: String -) : TransportClient { - - val client = ClientFilters.SetBaseUriFrom(Uri.of(baseUrl)).then(JettyClient()) - - override fun send(request: HttpRequest): HttpResponse { - val http4kRequest = Request( - method = Method.valueOf(request.method.name), - uri = request.path - ) - .run { - request.queryParams.toList().foldRight(this) { queryParam, r -> - r.query(queryParam.first, queryParam.second) - } - } - .run { - request.headers.toList().foldRight(this) { header, r -> - r.header(header.first, header.second) - } - } - .run { - request.body?.let { body -> body(body) } ?: this - } - - return client(http4kRequest).let { - HttpResponse( - status = parseHttpStatus(it.status.code), - body = it.bodyString(), - headers = it.headers - .filter { (_, value) -> value != null } - .associate { (key, value) -> key to value!! } - ) - } - } -} diff --git a/ocpi-toolkit-2.1.1-gireve/src/test/kotlin/com/izivia/ocpi/toolkit/samples/common/Http4kTransportClientBuilder.kt b/ocpi-toolkit-2.1.1-gireve/src/test/kotlin/com/izivia/ocpi/toolkit/samples/common/Http4kTransportClientBuilder.kt deleted file mode 100644 index 59bd0bf5..00000000 --- a/ocpi-toolkit-2.1.1-gireve/src/test/kotlin/com/izivia/ocpi/toolkit/samples/common/Http4kTransportClientBuilder.kt +++ /dev/null @@ -1,10 +0,0 @@ -package com.izivia.ocpi.toolkit.samples.common - -import com.izivia.ocpi.toolkit.transport.TransportClient -import com.izivia.ocpi.toolkit.transport.TransportClientBuilder - -class Http4kTransportClientBuilder : TransportClientBuilder { - override fun build(baseUrl: String): TransportClient = - Http4kTransportClient(baseUrl) -} - diff --git a/ocpi-toolkit-2.1.1-gireve/src/test/kotlin/com/izivia/ocpi/toolkit/samples/common/Http4kTransportServer.kt b/ocpi-toolkit-2.1.1-gireve/src/test/kotlin/com/izivia/ocpi/toolkit/samples/common/Http4kTransportServer.kt deleted file mode 100644 index d3d3c5ab..00000000 --- a/ocpi-toolkit-2.1.1-gireve/src/test/kotlin/com/izivia/ocpi/toolkit/samples/common/Http4kTransportServer.kt +++ /dev/null @@ -1,96 +0,0 @@ -package com.izivia.ocpi.toolkit.samples.common - -import com.izivia.ocpi.toolkit.common.OcpiException -import com.izivia.ocpi.toolkit.common.toHttpResponse -import com.izivia.ocpi.toolkit.transport.TransportServer -import com.izivia.ocpi.toolkit.transport.domain.* -import kotlinx.coroutines.runBlocking -import org.http4k.core.* -import org.http4k.filter.DebuggingFilters -import org.http4k.routing.RoutingHttpHandler -import org.http4k.routing.bind -import org.http4k.routing.path -import org.http4k.routing.routes -import org.http4k.server.Http4kServer -import org.http4k.server.Netty -import org.http4k.server.asServer - -class Http4kTransportServer( - val baseUrl: String, - val port: Int -) : TransportServer { - - private val serverRoutes: MutableList = mutableListOf() - private lateinit var server: Http4kServer - - override suspend fun handle( - method: HttpMethod, - path: List, - queryParams: List, - secured: Boolean, - filters: List<(request: HttpRequest) -> Unit>, - callback: suspend (request: HttpRequest) -> HttpResponse, - ) { - val pathParams = path - .filterIsInstance(VariablePathSegment::class.java) - .map { it.path } - - val route = path.joinToString("/") { segment -> - when (segment) { - is VariablePathSegment -> "{${segment.path}}" - is FixedPathSegment -> segment.path - } - } - - serverRoutes.add( - route bind Method.valueOf(method.name) to { req: Request -> - try { - HttpRequest( - baseUrl = baseUrl, - method = method, - path = route, - pathParams = pathParams.associateWith { param -> req.path(param)!! }, - queryParams = queryParams.associateWith { param -> req.query(param) }, - headers = req.headers - .filter { (_, value) -> value != null } - .associate { (key, value) -> key to value!! }, - body = req.bodyString() - ) - .also { httpRequest -> filters.forEach { filter -> filter(httpRequest) } } - .let { httpRequest -> - runBlocking { callback(httpRequest) } - } - .let { httpResponse -> - Response(Status(httpResponse.status.code, null)) - .body(httpResponse.body ?: "") - .headers(httpResponse.headers.toList()) - } - } catch (ocpiException: OcpiException) { - ocpiException.toHttpResponse().toHttp4kResponse() - } catch (httpException: HttpException) { - Response(Status(httpException.status.code, httpException.reason)) - } catch (exception: Exception) { - Response(Status.INTERNAL_SERVER_ERROR) - } - } - ) - } - - private fun HttpResponse.toHttp4kResponse() = - Response(Status(status.code, null)) - .body(body ?: "") - .headers(headers.toList()) - - override fun start() { - server = DebuggingFilters.PrintRequestAndResponse() - .then( - serverRoutes.reduce { a, b -> routes(a, b) } - ) - .asServer(Netty(port)) - .start() - } - - override fun stop() { - server.stop() - } -} diff --git a/ocpi-toolkit-2.1.1-gireve/src/test/kotlin/com/izivia/ocpi/toolkit/samples/common/Platform.kt b/ocpi-toolkit-2.1.1-gireve/src/test/kotlin/com/izivia/ocpi/toolkit/samples/common/Platform.kt deleted file mode 100644 index 86b36f3f..00000000 --- a/ocpi-toolkit-2.1.1-gireve/src/test/kotlin/com/izivia/ocpi/toolkit/samples/common/Platform.kt +++ /dev/null @@ -1,13 +0,0 @@ -package com.izivia.ocpi.toolkit.samples.common - -import com.izivia.ocpi.toolkit.modules.versions.domain.Endpoint -import com.izivia.ocpi.toolkit.modules.versions.domain.Version - -data class Platform( - val url: String? = null, - val version: Version? = null, - val endpoints: List? = null, - val tokenA: String? = null, - val tokenB: String? = null, - val tokenC: String? = null -) diff --git a/ocpi-toolkit-2.1.1-gireve/src/test/kotlin/com/izivia/ocpi/toolkit/samples/common/PlatformCacheRepository.kt b/ocpi-toolkit-2.1.1-gireve/src/test/kotlin/com/izivia/ocpi/toolkit/samples/common/PlatformCacheRepository.kt deleted file mode 100644 index e713ae08..00000000 --- a/ocpi-toolkit-2.1.1-gireve/src/test/kotlin/com/izivia/ocpi/toolkit/samples/common/PlatformCacheRepository.kt +++ /dev/null @@ -1,114 +0,0 @@ -package com.izivia.ocpi.toolkit.samples.common - -import com.izivia.ocpi.toolkit.modules.credentials.repositories.PlatformRepository -import com.izivia.ocpi.toolkit.modules.versions.domain.Endpoint -import com.izivia.ocpi.toolkit.modules.versions.domain.Version - -open class PlatformCacheRepository : PlatformRepository { - val platforms = mutableListOf() - - private fun List.getOrDefault(url: String, platform: Platform): Platform = - platforms[url] ?: platform - - private operator fun List.get(url: String): Platform? = - platforms.firstOrNull { it.url == url } - - private operator fun List.set(url: String, platform: Platform) { - platforms.removeAll { it.url == url } - platforms.add(platform) - } - - override fun savePlatformUrlForTokenA(tokenA: String, platformUrl: String): String? = platforms - .toList() - .firstOrNull { it.tokenA == tokenA } - ?.copy(url = platformUrl) - ?.also { platforms[it.url!!] = it } - ?.url - - override fun saveVersion(platformUrl: String, version: Version): Version = platforms - .getOrDefault(platformUrl, Platform(platformUrl)) - .copy(version = version) - .also { platforms[it.url!!] = it } - .let { it.version!! } - - override fun saveEndpoints(platformUrl: String, endpoints: List): List = platforms - .getOrDefault(platformUrl, Platform(platformUrl)) - .copy(endpoints = endpoints) - .also { platforms[it.url!!] = it } - .let { it.endpoints!! } - - override fun saveCredentialsTokenA(platformUrl: String, credentialsTokenA: String): String = platforms - .getOrDefault(platformUrl, Platform(platformUrl)) - .copy(tokenA = credentialsTokenA) - .also { platforms[it.url!!] = it } - .let { it.tokenA!! } - - override fun saveCredentialsTokenB(platformUrl: String, credentialsTokenB: String): String = platforms - .getOrDefault(platformUrl, Platform(platformUrl)) - .copy(tokenB = credentialsTokenB) - .also { platforms[it.url!!] = it } - .let { it.tokenB!! } - - override fun saveCredentialsTokenC(platformUrl: String, credentialsTokenC: String): String = platforms - .getOrDefault(platformUrl, Platform(platformUrl)) - .copy(tokenC = credentialsTokenC) - .also { platforms[it.url!!] = it } - .let { it.tokenC!! } - - override fun getCredentialsTokenC(platformUrl: String): String? = platforms[platformUrl]?.tokenC - - override fun getCredentialsTokenB(platformUrl: String): String? = platforms[platformUrl]?.tokenB - - override fun getCredentialsTokenA(platformUrl: String): String? = platforms[platformUrl]?.tokenA - - override fun platformExistsWithTokenA(token: String): Boolean = platforms - .any { it.tokenA == token } - - override fun platformExistsWithTokenB(token: String): Boolean = platforms - .any { it.tokenB == token } - - override fun getPlatformUrlByTokenC(token: String): String? = platforms - .firstOrNull { it.tokenC == token }?.url - - override fun getEndpoints(platformUrl: String): List = platforms - .firstOrNull { it.url == platformUrl }?.endpoints ?: emptyList() - - override fun getVersion(platformUrl: String): Version? = platforms - .firstOrNull { it.url == platformUrl }?.version - - override fun removeCredentialsTokenA(platformUrl: String) { - platforms - .getOrDefault(platformUrl, Platform(platformUrl)) - .copy(tokenA = null) - .also { platforms[it.url!!] = it } - } - - override fun removeCredentialsTokenB(platformUrl: String) { - platforms - .getOrDefault(platformUrl, Platform(platformUrl)) - .copy(tokenB = null) - .also { platforms[it.url!!] = it } - } - - override fun removeCredentialsTokenC(platformUrl: String) { - platforms - .getOrDefault(platformUrl, Platform(platformUrl)) - .copy(tokenC = null) - .also { platforms[it.url!!] = it } - } - - override fun removeVersion(platformUrl: String) { - platforms - .getOrDefault(platformUrl, Platform(platformUrl)) - .copy(version = null) - .also { platforms[it.url!!] = it } - } - - override fun removeEndpoints(platformUrl: String) { - platforms - .getOrDefault(platformUrl, Platform(platformUrl)) - .copy(endpoints = null) - .also { platforms[it.url!!] = it } - } -} - diff --git a/ocpi-toolkit-2.1.1-gireve/src/test/kotlin/com/izivia/ocpi/toolkit/samples/common/ValidDomainObjets.kt b/ocpi-toolkit-2.1.1-gireve/src/test/kotlin/com/izivia/ocpi/toolkit/samples/common/ValidDomainObjets.kt deleted file mode 100644 index 814f5f17..00000000 --- a/ocpi-toolkit-2.1.1-gireve/src/test/kotlin/com/izivia/ocpi/toolkit/samples/common/ValidDomainObjets.kt +++ /dev/null @@ -1,158 +0,0 @@ -package com.izivia.ocpi.toolkit.samples.common - -import com.izivia.ocpi.toolkit.common.validation.Iso639Alpha2 -import com.izivia.ocpi.toolkit.modules.locations.domain.* -import com.izivia.ocpi.toolkit.modules.tokens.domain.LocationReferences -import com.izivia.ocpi.toolkit.modules.tokens.domain.Token -import com.izivia.ocpi.toolkit.modules.tokens.domain.TokenType -import com.izivia.ocpi.toolkit.modules.tokens.domain.WhitelistType -import com.izivia.ocpi.toolkit.modules.types.DisplayText -import java.math.BigDecimal -import java.time.Instant - -val validUrl = "https://abc.com" -val validLatitude = "-15.234567" -val validLongitude = "23.234567" - -val validStatusSchedule = StatusSchedule( - period_begin = Instant.parse("2022-04-28T08:00:00.000Z"), - period_end = Instant.parse("2022-04-28T09:00:00.000Z"), - status = Status.AVAILABLE -) - -val validDisplayText = DisplayText( - language = "fr", - text = "abcdef" -) - -val validGeoLocation = GeoLocation( - latitude = validLatitude, - longitude = validLongitude -) - -val validAdditionalGeoLocation = AdditionalGeoLocation( - latitude = validLatitude, - longitude = validLongitude, - name = validDisplayText -) - -val validImage = Image( - url = validUrl, - thumbnail = validUrl, - category = ImageCategory.LOCATION, - type = "jpeg", - width = 12345, - height = 123 -) - -val validBusinessDetails = BusinessDetails( - name = "name", - website = validUrl, - logo = validImage -) - -val validRegularHours = RegularHours( - weekday = 1, - period_begin = "00:00", - period_end = "23:59", -) - -val validExceptionalPeriod = ExceptionalPeriod( - period_begin = Instant.parse("2022-04-28T08:00:00.000Z"), - period_end = Instant.parse("2022-04-28T09:00:00.000Z") -) - -val validHours = Hours( - regular_hours = listOf(validRegularHours), - twenty_four_seven = null, - exceptional_openings = listOf(validExceptionalPeriod), - exceptional_closings = emptyList() -) - -val validEnergySource = EnergySource( - source = EnergySourceCategory.NUCLEAR, - percentage = BigDecimal.ZERO -) - -val validEnvironmentalImpact = EnvironmentalImpact( - source = EnvironmentalImpactCategory.CARBON_DIOXIDE, - amount = BigDecimal.ZERO -) - -val validEnergyMix = EnergyMix( - is_green_energy = true, - energy_sources = listOf(validEnergySource), - environ_impact = listOf(validEnvironmentalImpact), - supplier_name = "supplier_name", - energy_product_name = "energy_product_name" -) - -val validLocation = Location( - id = "location1", - type = LocationType.ON_STREET, - name = "name", - address = "address", - city = "city", - postal_code = "33520", - country = "FRA", - coordinates = validGeoLocation, - related_locations = listOf(validAdditionalGeoLocation), - evses = emptyList(), - directions = listOf(validDisplayText), - operator = validBusinessDetails, - suboperator = null, - owner = null, - facilities = listOf(Facility.CARPOOL_PARKING), - time_zone = "Europe/Oslo", - opening_times = validHours, - charging_when_closed = false, - images = listOf(validImage), - energy_mix = validEnergyMix, - last_updated = Instant.now() -) - -val validConnector = Connector( - id = "id", - standard = ConnectorType.DOMESTIC_A, - format = ConnectorFormat.CABLE, - power_type = PowerType.AC_1_PHASE, - voltage = 12, - amperage = 8, - tariff_id = "tariff_id", - terms_and_conditions = "https://myspecs.com/me", - last_updated = Instant.now() -) - -val validEvse = Evse( - uid = "uid", - evse_id = "FR*A23*E45B*78C", - status = Status.AVAILABLE, - status_schedule = listOf(validStatusSchedule), - capabilities = listOf(Capability.CHARGING_PROFILE_CAPABLE), - connectors = listOf(validConnector), - floor_level = "5", - coordinates = validGeoLocation, - physical_reference = "visualid1", - directions = listOf(validDisplayText), - parking_restrictions = listOf(ParkingRestriction.CUSTOMERS), - images = listOf(validImage), - last_updated = Instant.now() -) - -val validToken = Token( - uid = "012345678", - type = TokenType.RFID, - auth_id = "DE8ACC12E46L89", - visual_number = "DF000-2001-8999", - issuer = "TheNewMotion", - valid = true, - whitelist = WhitelistType.ALLOWED, - last_updated = Instant.parse("2015-06-29T22:39:09Z"), - language = Iso639Alpha2.fr.name -) - -val validLocationReferences = LocationReferences( - location_id = validLocation.id, - evse_uids = listOf(validEvse.uid), - connector_ids = listOf(validConnector.id) -) diff --git a/ocpi-toolkit-2.1.1-gireve/src/test/kotlin/com/izivia/ocpi/toolkit/samples/common/VersionDetailsCacheRepository.kt b/ocpi-toolkit-2.1.1-gireve/src/test/kotlin/com/izivia/ocpi/toolkit/samples/common/VersionDetailsCacheRepository.kt deleted file mode 100644 index 317236ce..00000000 --- a/ocpi-toolkit-2.1.1-gireve/src/test/kotlin/com/izivia/ocpi/toolkit/samples/common/VersionDetailsCacheRepository.kt +++ /dev/null @@ -1,31 +0,0 @@ -package com.izivia.ocpi.toolkit.samples.common - -import com.izivia.ocpi.toolkit.modules.versions.domain.Endpoint -import com.izivia.ocpi.toolkit.modules.versions.domain.ModuleID -import com.izivia.ocpi.toolkit.modules.versions.domain.VersionDetails -import com.izivia.ocpi.toolkit.modules.versions.domain.VersionNumber -import com.izivia.ocpi.toolkit.modules.versions.repositories.VersionDetailsRepository - -class VersionDetailsCacheRepository( - private val baseUrl: String -): VersionDetailsRepository { - - override fun getVersionDetails(versionNumber: VersionNumber): VersionDetails? = - VersionDetails( - version = VersionNumber.V2_1_1.value, - endpoints = listOf( - Endpoint( - identifier = ModuleID.credentials, - url = "$baseUrl/${VersionNumber.V2_1_1.value}/credentials" - ), - Endpoint( - identifier = ModuleID.locations, - url = "$baseUrl/${VersionNumber.V2_1_1.value}/locations" - ), - Endpoint( - identifier = ModuleID.tokens, - url = "$baseUrl/${VersionNumber.V2_1_1.value}/tokens" - ) - ) - ).takeIf { versionNumber.value == it.version } -} diff --git a/ocpi-toolkit-2.1.1-gireve/src/test/kotlin/com/izivia/ocpi/toolkit/samples/common/VersionsCacheRepository.kt b/ocpi-toolkit-2.1.1-gireve/src/test/kotlin/com/izivia/ocpi/toolkit/samples/common/VersionsCacheRepository.kt deleted file mode 100644 index 1ff116b1..00000000 --- a/ocpi-toolkit-2.1.1-gireve/src/test/kotlin/com/izivia/ocpi/toolkit/samples/common/VersionsCacheRepository.kt +++ /dev/null @@ -1,17 +0,0 @@ -package com.izivia.ocpi.toolkit.samples.common - -import com.izivia.ocpi.toolkit.modules.versions.domain.Version -import com.izivia.ocpi.toolkit.modules.versions.domain.VersionNumber -import com.izivia.ocpi.toolkit.modules.versions.repositories.VersionsRepository - -class VersionsCacheRepository( - private val baseUrl: String -): VersionsRepository { - - override fun getVersions(): List = listOf( - Version( - version = VersionNumber.V2_1_1.value, - url = "$baseUrl/${VersionNumber.V2_1_1.value}" - ) - ) -} \ No newline at end of file diff --git a/ocpi-toolkit-2.1.1-gireve/src/test/kotlin/com/izivia/ocpi/toolkit/samples/credentials/CredentialsReceiver.kt b/ocpi-toolkit-2.1.1-gireve/src/test/kotlin/com/izivia/ocpi/toolkit/samples/credentials/CredentialsReceiver.kt deleted file mode 100644 index 5a410a2d..00000000 --- a/ocpi-toolkit-2.1.1-gireve/src/test/kotlin/com/izivia/ocpi/toolkit/samples/credentials/CredentialsReceiver.kt +++ /dev/null @@ -1,52 +0,0 @@ -package com.izivia.ocpi.toolkit.samples.credentials - -import com.izivia.ocpi.toolkit.modules.credentials.services.CredentialsServerService -import com.izivia.ocpi.toolkit.modules.locations.domain.BusinessDetails -import com.izivia.ocpi.toolkit.modules.versions.VersionDetailsServer -import com.izivia.ocpi.toolkit.modules.versions.VersionsServer -import com.izivia.ocpi.toolkit.modules.versions.validation.VersionDetailsValidationService -import com.izivia.ocpi.toolkit.modules.versions.validation.VersionsValidationService -import com.izivia.ocpi.toolkit.samples.common.* - -const val receiverPort = 8080 -const val receiverUrl = "http://localhost:$receiverPort" -const val receiverVersionsUrl = "http://localhost:$receiverPort/versions" -const val tokenA = "06f7967e-65c3-4def-a966-701ffb362b3c" - -fun main() { - // Add token A associated with the sender - val receiverPlatformRepository = PlatformCacheRepository() - receiverPlatformRepository.platforms.add(Platform(tokenA = tokenA)) - - val receiverServer = Http4kTransportServer( - baseUrl = receiverUrl, - port = receiverPort - ) - - com.izivia.ocpi.toolkit.modules.credentials.CredentialsServer( - transportServer = receiverServer, - service = CredentialsServerService( - platformRepository = receiverPlatformRepository, - serverBusinessDetails = BusinessDetails(name = "Receiver", website = null, logo = null), - serverPartyId = "DEF", - serverCountryCode = "FR", - transportClientBuilder = Http4kTransportClientBuilder(), - serverVersionsUrl = receiverVersionsUrl - ) - ) - VersionsServer( - transportServer = receiverServer, - platformRepository = receiverPlatformRepository, - validationService = VersionsValidationService( - repository = VersionsCacheRepository(baseUrl = receiverUrl) - ) - ) - VersionDetailsServer( - transportServer = receiverServer, - platformRepository = receiverPlatformRepository, - validationService = VersionDetailsValidationService( - repository = VersionDetailsCacheRepository(baseUrl = receiverUrl) - ) - ) - receiverServer.start() -} diff --git a/ocpi-toolkit-2.1.1-gireve/src/test/kotlin/com/izivia/ocpi/toolkit/samples/credentials/CredentialsSender.kt b/ocpi-toolkit-2.1.1-gireve/src/test/kotlin/com/izivia/ocpi/toolkit/samples/credentials/CredentialsSender.kt deleted file mode 100644 index 21ecdc66..00000000 --- a/ocpi-toolkit-2.1.1-gireve/src/test/kotlin/com/izivia/ocpi/toolkit/samples/credentials/CredentialsSender.kt +++ /dev/null @@ -1,65 +0,0 @@ -package com.izivia.ocpi.toolkit.samples.credentials - -import com.izivia.ocpi.toolkit.modules.credentials.services.CredentialsClientService -import com.izivia.ocpi.toolkit.modules.locations.domain.BusinessDetails -import com.izivia.ocpi.toolkit.modules.versions.VersionDetailsServer -import com.izivia.ocpi.toolkit.modules.versions.VersionsServer -import com.izivia.ocpi.toolkit.modules.versions.validation.VersionDetailsValidationService -import com.izivia.ocpi.toolkit.modules.versions.validation.VersionsValidationService -import com.izivia.ocpi.toolkit.samples.common.* - -const val senderPort = 8081 -const val senderUrl = "http://localhost:$senderPort" -const val senderVersionsUrl = "http://localhost:$senderPort/versions" - -fun main() { - // Server - val senderServer = Http4kTransportServer(baseUrl = senderUrl, port = senderPort) - - // Add token A associated with the sender - val senderVersionsRepository = VersionsCacheRepository(baseUrl = senderUrl) - val senderVersionDetailsRepository = VersionDetailsCacheRepository(baseUrl = senderUrl) - val senderPlatformRepository = PlatformCacheRepository() - senderPlatformRepository.platforms.add(Platform(url = receiverVersionsUrl, tokenA = tokenA)) - - VersionsServer( - transportServer = senderServer, - platformRepository = senderPlatformRepository, - validationService = VersionsValidationService( - repository = senderVersionsRepository - ) - ) - VersionDetailsServer( - transportServer = senderServer, - platformRepository = senderPlatformRepository, - validationService = VersionDetailsValidationService( - repository = senderVersionDetailsRepository - ) - ) - senderServer.start() - - // Client - - val credentialsClientService = CredentialsClientService( - clientVersionsEndpointUrl = senderVersionsUrl, - clientPlatformRepository = senderPlatformRepository, - clientVersionsRepository = senderVersionsRepository, - clientBusinessDetails = BusinessDetails(name = "Sender", website = null, logo = null), - clientPartyId = "ABC", - clientCountryCode = "FR", - serverVersionsEndpointUrl = receiverVersionsUrl, - transportClientBuilder = Http4kTransportClientBuilder() - ) - - println("Registering $senderUrl to $receiverUrl") - var credentials = credentialsClientService.register() - println("Success. Credentials after register : $credentials") - - println("Retrieving credentials from $receiverUrl...") - credentials = credentialsClientService.get() - println("Success. Credentials : $credentials") - - println("Deleting credentials of $senderUrl on $receiverUrl...") - credentialsClientService.delete() - println("Success.") -} diff --git a/ocpi-toolkit-2.1.1-gireve/src/test/kotlin/com/izivia/ocpi/toolkit/samples/locations/LocationsCommon.kt b/ocpi-toolkit-2.1.1-gireve/src/test/kotlin/com/izivia/ocpi/toolkit/samples/locations/LocationsCommon.kt deleted file mode 100644 index 329e2845..00000000 --- a/ocpi-toolkit-2.1.1-gireve/src/test/kotlin/com/izivia/ocpi/toolkit/samples/locations/LocationsCommon.kt +++ /dev/null @@ -1,21 +0,0 @@ -package com.izivia.ocpi.toolkit.samples.locations - -import com.izivia.ocpi.toolkit.modules.versions.domain.VersionNumber -import com.izivia.ocpi.toolkit.samples.common.VersionDetailsCacheRepository - -const val CREDENTIALS_TOKEN_C = "e0748bbe-d535-4a6b-8f80-94f2457d5b9d" -val DUMMY_PLATFORM_REPOSITORY = com.izivia.ocpi.toolkit.samples.common.DummyPlatformCacheRepository(tokenC = CREDENTIALS_TOKEN_C) - .also { - val versionDetailsEmsp = VersionDetailsCacheRepository(baseUrl = emspServerUrl) - val versionDetailsCpo = VersionDetailsCacheRepository(baseUrl = cpoServerUrl) - - it.saveEndpoints( - emspServerVersionsUrl, - versionDetailsEmsp.getVersionDetails(VersionNumber.V2_1_1)!!.endpoints - ) - - it.saveEndpoints( - cpoServerVersionsUrl, - versionDetailsCpo.getVersionDetails(VersionNumber.V2_1_1)!!.endpoints - ) -} \ No newline at end of file diff --git a/ocpi-toolkit-2.1.1-gireve/src/test/kotlin/com/izivia/ocpi/toolkit/samples/locations/LocationsCpoClient.kt b/ocpi-toolkit-2.1.1-gireve/src/test/kotlin/com/izivia/ocpi/toolkit/samples/locations/LocationsCpoClient.kt deleted file mode 100644 index 6e62d23e..00000000 --- a/ocpi-toolkit-2.1.1-gireve/src/test/kotlin/com/izivia/ocpi/toolkit/samples/locations/LocationsCpoClient.kt +++ /dev/null @@ -1,21 +0,0 @@ -package com.izivia.ocpi.toolkit.samples.locations - -import com.izivia.ocpi.toolkit.modules.locations.LocationsCpoClient -import com.izivia.ocpi.toolkit.samples.common.Http4kTransportClientBuilder - -/** - * Example on how to use the CPO client - */ -fun main() { - // We instantiate the clients that we want to use - val locationsCpoClient = LocationsCpoClient( - transportClientBuilder = Http4kTransportClientBuilder(), - serverVersionsEndpointUrl = emspServerVersionsUrl, - platformRepository = DUMMY_PLATFORM_REPOSITORY - ) - - // We can use it - println( - locationsCpoClient.getLocation(countryCode = "fr", partyId = "abc", locationId = "location1") - ) -} \ No newline at end of file diff --git a/ocpi-toolkit-2.1.1-gireve/src/test/kotlin/com/izivia/ocpi/toolkit/samples/locations/LocationsCpoServer.kt b/ocpi-toolkit-2.1.1-gireve/src/test/kotlin/com/izivia/ocpi/toolkit/samples/locations/LocationsCpoServer.kt deleted file mode 100644 index fc360afc..00000000 --- a/ocpi-toolkit-2.1.1-gireve/src/test/kotlin/com/izivia/ocpi/toolkit/samples/locations/LocationsCpoServer.kt +++ /dev/null @@ -1,54 +0,0 @@ -package com.izivia.ocpi.toolkit.samples.locations - -import com.izivia.ocpi.toolkit.common.SearchResult -import com.izivia.ocpi.toolkit.modules.locations.LocationsCpoServer -import com.izivia.ocpi.toolkit.modules.locations.domain.Connector -import com.izivia.ocpi.toolkit.modules.locations.domain.Evse -import com.izivia.ocpi.toolkit.modules.locations.domain.Location -import com.izivia.ocpi.toolkit.modules.locations.services.LocationsCpoService -import com.izivia.ocpi.toolkit.modules.locations.validation.LocationsCpoValidationService -import com.izivia.ocpi.toolkit.samples.common.Http4kTransportServer -import java.time.Instant - -val cpoServerUrl = "http://localhost:8080" -val cpoServerVersionsUrl = "http://localhost:8080/versions" -val cpoServerPort = 8080 - -/** - * Example on how to serve a CPO server - */ -fun main() { - // We specify the transport to serve the cpo server - val transportServer = Http4kTransportServer(baseUrl = cpoServerUrl, port = cpoServerPort) - - // We specify service for the validation service - val service = CacheLocationsCpoService() - - // We implement callbacks for the server using the built-in service and our service implementation - LocationsCpoServer( - transportServer = transportServer, - platformRepository = DUMMY_PLATFORM_REPOSITORY, - service = LocationsCpoValidationService(service = service) - ) - - // It is recommended to start the server after setting up the routes to handle - transportServer.start() -} - -class CacheLocationsCpoService : LocationsCpoService { - override fun getLocations(dateFrom: Instant?, dateTo: Instant?, offset: Int, limit: Int?): SearchResult { - TODO("Not yet implemented") - } - - override fun getLocation(locationId: String): Location? { - TODO("Not yet implemented") - } - - override fun getEvse(locationId: String, evseUid: String): Evse? { - TODO("Not yet implemented") - } - - override fun getConnector(locationId: String, evseUid: String, connectorId: String): Connector? { - TODO("Not yet implemented") - } -} diff --git a/ocpi-toolkit-2.1.1-gireve/src/test/kotlin/com/izivia/ocpi/toolkit/samples/locations/LocationsEmspClient.kt b/ocpi-toolkit-2.1.1-gireve/src/test/kotlin/com/izivia/ocpi/toolkit/samples/locations/LocationsEmspClient.kt deleted file mode 100644 index c2c1e632..00000000 --- a/ocpi-toolkit-2.1.1-gireve/src/test/kotlin/com/izivia/ocpi/toolkit/samples/locations/LocationsEmspClient.kt +++ /dev/null @@ -1,21 +0,0 @@ -package com.izivia.ocpi.toolkit.samples.locations - -import com.izivia.ocpi.toolkit.modules.locations.LocationsEmspClient -import com.izivia.ocpi.toolkit.samples.common.Http4kTransportClientBuilder - -/** - * Example on how to use the eMSP client - */ -fun main() { - // We instantiate the clients that we want to use - val locationsEmspClient = LocationsEmspClient( - transportClientBuilder = Http4kTransportClientBuilder(), - serverVersionsEndpointUrl = cpoServerVersionsUrl, - platformRepository = DUMMY_PLATFORM_REPOSITORY - ) - - // We can use it - println( - locationsEmspClient.getConnector(locationId = "location1", evseUid = "evse1", connectorId = "connector1") - ) -} \ No newline at end of file diff --git a/ocpi-toolkit-2.1.1-gireve/src/test/kotlin/com/izivia/ocpi/toolkit/samples/locations/LocationsEmspServer.kt b/ocpi-toolkit-2.1.1-gireve/src/test/kotlin/com/izivia/ocpi/toolkit/samples/locations/LocationsEmspServer.kt deleted file mode 100644 index 19cbd15b..00000000 --- a/ocpi-toolkit-2.1.1-gireve/src/test/kotlin/com/izivia/ocpi/toolkit/samples/locations/LocationsEmspServer.kt +++ /dev/null @@ -1,124 +0,0 @@ -package com.izivia.ocpi.toolkit.samples.locations - -import com.izivia.ocpi.toolkit.modules.locations.LocationsEmspServer -import com.izivia.ocpi.toolkit.modules.locations.domain.* -import com.izivia.ocpi.toolkit.modules.locations.services.LocationsEmspService -import com.izivia.ocpi.toolkit.modules.locations.validation.LocationsEmspValidationService -import com.izivia.ocpi.toolkit.samples.common.Http4kTransportServer -import java.time.Instant - -val emspServerUrl = "http://localhost:8081" -val emspServerVersionsUrl = "http://localhost:8081/versions" -val emspServerPort = 8081 - -/** - * Example on how to server an eMSP server - */ -fun main() { - // We specify the transport to serve the eMSP server - val transportServer = Http4kTransportServer(baseUrl = emspServerUrl, port = emspServerPort) - - // We specify service for the validation service - val service = CacheLocationsEmspService() - - // We implement callbacks for the server using the built-in service and our repository implementation - LocationsEmspServer( - transportServer = transportServer, - platformRepository = DUMMY_PLATFORM_REPOSITORY, - service = LocationsEmspValidationService(service = service) - ) - - // It is recommended to start the server after setting up the routes to handle - transportServer.start() -} - -class CacheLocationsEmspService : LocationsEmspService { - override fun getLocation(countryCode: String, partyId: String, locationId: String): Location? { - return Location( - id = locationId, - type = LocationType.ON_STREET, - name = null, - address = "1 avenue des satellites", - city = "Bruges", - postal_code = "33520", - country = "FRA", - coordinates = GeoLocation(latitude = "-15.234567", longitude = "23.234567"), - related_locations = emptyList(), - evses = emptyList(), - directions = emptyList(), - operator = null, - suboperator = null, - owner = null, - facilities = emptyList(), - time_zone = null, - opening_times = null, - charging_when_closed = null, - images = emptyList(), - energy_mix = null, - last_updated = Instant.now() - ) - } - - override fun getEvse(countryCode: String, partyId: String, locationId: String, evseUid: String): Evse? { - TODO("Not yet implemented") - } - - override fun getConnector( - countryCode: String, - partyId: String, - locationId: String, - evseUid: String, - connectorId: String - ): Connector? { - TODO("Not yet implemented") - } - - override fun putLocation(countryCode: String, partyId: String, locationId: String, location: Location): Location { - TODO("Not yet implemented") - } - - override fun putEvse(countryCode: String, partyId: String, locationId: String, evseUid: String, evse: Evse): Evse { - TODO("Not yet implemented") - } - - override fun putConnector( - countryCode: String, - partyId: String, - locationId: String, - evseUid: String, - connectorId: String, - connector: Connector - ): Connector { - TODO("Not yet implemented") - } - - override fun patchLocation( - countryCode: String, - partyId: String, - locationId: String, - location: LocationPartial - ): Location? { - TODO("Not yet implemented") - } - - override fun patchEvse( - countryCode: String, - partyId: String, - locationId: String, - evseUid: String, - evse: EvsePartial - ): Evse? { - TODO("Not yet implemented") - } - - override fun patchConnector( - countryCode: String, - partyId: String, - locationId: String, - evseUid: String, - connectorId: String, - connector: ConnectorPartial - ): Connector? { - TODO("Not yet implemented") - } -} diff --git a/ocpi-toolkit-2.1.1-gireve/src/test/kotlin/com/izivia/ocpi/toolkit/tests/integration/CredentialsIntegrationTests.kt b/ocpi-toolkit-2.1.1-gireve/src/test/kotlin/com/izivia/ocpi/toolkit/tests/integration/CredentialsIntegrationTests.kt deleted file mode 100644 index 6b00d540..00000000 --- a/ocpi-toolkit-2.1.1-gireve/src/test/kotlin/com/izivia/ocpi/toolkit/tests/integration/CredentialsIntegrationTests.kt +++ /dev/null @@ -1,411 +0,0 @@ -package com.izivia.ocpi.toolkit.tests.integration - -import com.izivia.ocpi.toolkit.common.OcpiClientInvalidParametersException -import com.izivia.ocpi.toolkit.common.OcpiResponseException -import com.izivia.ocpi.toolkit.common.OcpiStatus -import com.izivia.ocpi.toolkit.modules.credentials.services.CredentialsClientService -import com.izivia.ocpi.toolkit.modules.credentials.services.CredentialsServerService -import com.izivia.ocpi.toolkit.modules.locations.domain.BusinessDetails -import com.izivia.ocpi.toolkit.modules.versions.VersionDetailsServer -import com.izivia.ocpi.toolkit.modules.versions.VersionsClient -import com.izivia.ocpi.toolkit.modules.versions.VersionsServer -import com.izivia.ocpi.toolkit.modules.versions.validation.VersionDetailsValidationService -import com.izivia.ocpi.toolkit.modules.versions.validation.VersionsValidationService -import com.izivia.ocpi.toolkit.samples.common.* -import com.izivia.ocpi.toolkit.tests.integration.common.BaseServerIntegrationTest -import com.izivia.ocpi.toolkit.tests.integration.mock.PlatformMongoRepository -import com.mongodb.client.MongoCollection -import com.mongodb.client.MongoDatabase -import org.junit.jupiter.api.Test -import org.litote.kmongo.eq -import org.litote.kmongo.getCollection -import org.litote.kmongo.set -import org.litote.kmongo.setTo -import strikt.api.expectCatching -import strikt.api.expectThat -import strikt.assertions.* -import java.util.* - -class CredentialsIntegrationTests : BaseServerIntegrationTest() { - - data class ServerSetupResult( - val transport: Http4kTransportServer, - val platformCollection: MongoCollection, - val versionsEndpoint: String - ) - - private var database: MongoDatabase? = null - - private fun setupReceiver(): ServerSetupResult { - if (database == null) database = buildDBClient().getDatabase("ocpi-2-1-1-tests") - val receiverPlatformCollection = database!! - .getCollection("receiver-server-${UUID.randomUUID()}") - - // Setup receiver (only server) - val receiverServer = buildTransportServer() - val receiverServerVersionsUrl = "${receiverServer.baseUrl}/versions" - val receiverPlatformRepo = PlatformMongoRepository(collection = receiverPlatformCollection) - val receiverVersionsCacheRepository = VersionsCacheRepository(baseUrl = receiverServer.baseUrl) - val receiverVersionDetailsCacheRepository = VersionDetailsCacheRepository(baseUrl = receiverServer.baseUrl) - com.izivia.ocpi.toolkit.modules.credentials.CredentialsServer( - transportServer = receiverServer, - service = CredentialsServerService( - platformRepository = receiverPlatformRepo, - serverBusinessDetails = BusinessDetails(name = "Receiver", website = null, logo = null), - serverPartyId = "DEF", - serverCountryCode = "FR", - transportClientBuilder = Http4kTransportClientBuilder(), - serverVersionsUrl = receiverServerVersionsUrl - ) - ) - VersionsServer( - transportServer = receiverServer, - platformRepository = receiverPlatformRepo, - validationService = VersionsValidationService( - repository = receiverVersionsCacheRepository - ) - ) - VersionDetailsServer( - transportServer = receiverServer, - platformRepository = receiverPlatformRepo, - validationService = VersionDetailsValidationService( - repository = receiverVersionDetailsCacheRepository - ) - ) - - return ServerSetupResult( - transport = receiverServer, - platformCollection = receiverPlatformCollection, - versionsEndpoint = receiverServerVersionsUrl - ) - } - - private fun setupSender(): ServerSetupResult { - if (database == null) database = buildDBClient().getDatabase("ocpi-2-1-1-tests") - val senderPlatformCollection = database!! - .getCollection("sender-server-${UUID.randomUUID()}") - - // Setup sender (server) - val senderServer = buildTransportServer() - val senderServerVersionsUrl = "${senderServer.baseUrl}/versions" - - VersionsServer( - transportServer = senderServer, - platformRepository = PlatformMongoRepository(collection = senderPlatformCollection), - validationService = VersionsValidationService( - repository = VersionsCacheRepository(baseUrl = senderServer.baseUrl) - ) - ) - VersionDetailsServer( - transportServer = senderServer, - platformRepository = PlatformMongoRepository(collection = senderPlatformCollection), - validationService = VersionDetailsValidationService( - repository = VersionDetailsCacheRepository(baseUrl = senderServer.baseUrl) - ) - ) - - return ServerSetupResult( - transport = senderServer, - platformCollection = senderPlatformCollection, - versionsEndpoint = senderServerVersionsUrl - ) - } - - private fun setupCredentialsSenderClient( - senderServerSetupResult: ServerSetupResult, - receiverServerSetupResult: ServerSetupResult - ): CredentialsClientService { - // Setup sender (client) - return CredentialsClientService( - clientVersionsEndpointUrl = senderServerSetupResult.versionsEndpoint, - clientPlatformRepository = PlatformMongoRepository(collection = senderServerSetupResult.platformCollection), - clientVersionsRepository = VersionsCacheRepository(baseUrl = senderServerSetupResult.transport.baseUrl), - clientBusinessDetails = BusinessDetails(name = "Sender", website = null, logo = null), - clientPartyId = "ABC", - clientCountryCode = "FR", - serverVersionsEndpointUrl = receiverServerSetupResult.versionsEndpoint, - transportClientBuilder = Http4kTransportClientBuilder() - ) - } - - @Test - fun `should not properly run registration because wrong setup of token A`() { - val receiverServer = setupReceiver() - val senderServer = setupSender() - - val credentialsClientService = setupCredentialsSenderClient( - senderServerSetupResult = senderServer, - receiverServerSetupResult = receiverServer - ) - - val tokenA = UUID.randomUUID().toString() - receiverServer.platformCollection.insertOne(Platform(url = senderServer.versionsEndpoint, tokenA = tokenA)) - - // Start the servers - receiverServer.transport.start() - senderServer.transport.start() - - // Fails because the senders does not know the TOKEN_A to send with the request - expectCatching { - credentialsClientService.register() - }.isFailure().isA() - - receiverServer.platformCollection.deleteOne(Platform::url eq senderServer.versionsEndpoint) - senderServer.platformCollection.insertOne(Platform(url = receiverServer.versionsEndpoint, tokenA = tokenA)) - - // Fails because the receiver does not know the TOKEN_A used by the sender - expectCatching { - credentialsClientService.register() - } - .isFailure() - .isA() - .get { statusCode } - .isEqualTo(OcpiStatus.CLIENT_INVALID_PARAMETERS.code) - - receiverServer.platformCollection.deleteOne(Platform::url eq senderServer.versionsEndpoint) - receiverServer.platformCollection.insertOne( - Platform( - url = receiverServer.versionsEndpoint, - tokenA = "!$tokenA" - ) - ) - - // Fails because the token sent by sender is not the same as the one in the receiver - expectCatching { - credentialsClientService.register() - } - .isFailure() - .isA() - .get { statusCode } - .isEqualTo(OcpiStatus.CLIENT_INVALID_PARAMETERS.code) - } - - @Test - fun `should access versions module properly with token A`() { - val receiverServer = setupReceiver() - val senderServer = setupSender() - - val tokenA = UUID.randomUUID().toString() - receiverServer.platformCollection.insertOne(Platform(url = senderServer.versionsEndpoint, tokenA = tokenA)) - senderServer.platformCollection.insertOne(Platform(url = receiverServer.versionsEndpoint, tokenA = tokenA)) - - receiverServer.transport.start() - senderServer.transport.start() - - // We don't need to register, we will use TOKEN_A for our requests - - val versionsClient = VersionsClient( - transportClientBuilder = Http4kTransportClientBuilder(), - serverVersionsEndpointUrl = receiverServer.versionsEndpoint, - platformRepository = PlatformMongoRepository(collection = senderServer.platformCollection) - ) - - expectThat( - versionsClient.getVersions() - ) { - get { data } - .isNotNull() - .isEqualTo(VersionsCacheRepository(baseUrl = receiverServer.transport.baseUrl).getVersions()) - - get { status_code } - .isEqualTo(OcpiStatus.SUCCESS.code) - } - } - - @Test - fun `should properly run registration process then correct get credentials from receiver`() { - val receiverServer = setupReceiver() - val senderServer = setupSender() - - val credentialsClientService = setupCredentialsSenderClient( - senderServerSetupResult = senderServer, - receiverServerSetupResult = receiverServer - ) - - // Store token A on the receiver side, that will be used by the sender to begin registration and store it as - // well in the client so that it knows what token to send - val tokenA = UUID.randomUUID().toString() - receiverServer.platformCollection.insertOne(Platform(url = senderServer.versionsEndpoint, tokenA = tokenA)) - senderServer.platformCollection.insertOne(Platform(url = receiverServer.versionsEndpoint, tokenA = tokenA)) - - // Start the servers - receiverServer.transport.start() - senderServer.transport.start() - - val credentials = credentialsClientService.register() - - expectThat( - credentialsClientService.get() - ).isEqualTo(credentials) - } - - @Test - fun `should properly run registration process then run update properly`() { - val receiverServer = setupReceiver() - val senderServer = setupSender() - - val credentialsClientService = setupCredentialsSenderClient( - senderServerSetupResult = senderServer, - receiverServerSetupResult = receiverServer - ) - - // Store token A on the receiver side, that will be used by the sender to begin registration and store it as - // well in the client so that it knows what token to send - val tokenA = UUID.randomUUID().toString() - receiverServer.platformCollection.insertOne(Platform(url = senderServer.versionsEndpoint, tokenA = tokenA)) - senderServer.platformCollection.insertOne(Platform(url = receiverServer.versionsEndpoint, tokenA = tokenA)) - - // Start the servers - receiverServer.transport.start() - senderServer.transport.start() - - credentialsClientService.register() - - val versionsClient = VersionsClient( - transportClientBuilder = Http4kTransportClientBuilder(), - serverVersionsEndpointUrl = receiverServer.versionsEndpoint, - platformRepository = PlatformMongoRepository(collection = senderServer.platformCollection) - ) - - expectThat( - versionsClient.getVersions() - ) { - get { data } - .isNotNull() - .isNotEmpty() - .isEqualTo( - VersionsCacheRepository(baseUrl = receiverServer.transport.baseUrl) - .getVersions() - ) - - get { status_code } - .isEqualTo(OcpiStatus.SUCCESS.code) - } - } - - @Test - fun `should properly run registration process then delete credentials properly`() { - val receiverServer = setupReceiver() - val senderServer = setupSender() - - val credentialsClientService = setupCredentialsSenderClient( - senderServerSetupResult = senderServer, - receiverServerSetupResult = receiverServer - ) - - // Store token A on the receiver side, that will be used by the sender to begin registration and store it as - // well in the client so that it knows what token to send - val tokenA = UUID.randomUUID().toString() - receiverServer.platformCollection.insertOne(Platform(url = senderServer.versionsEndpoint, tokenA = tokenA)) - senderServer.platformCollection.insertOne(Platform(url = receiverServer.versionsEndpoint, tokenA = tokenA)) - - // Start the servers - receiverServer.transport.start() - senderServer.transport.start() - - credentialsClientService.register() - - val versionsClient = VersionsClient( - transportClientBuilder = Http4kTransportClientBuilder(), - serverVersionsEndpointUrl = receiverServer.versionsEndpoint, - platformRepository = PlatformMongoRepository(collection = senderServer.platformCollection) - ) - - expectThat( - versionsClient.getVersions() - ) { - get { data } - .isNotNull() - .isNotEmpty() - .isEqualTo( - VersionsCacheRepository(baseUrl = receiverServer.transport.baseUrl) - .getVersions() - ) - - get { status_code } - .isEqualTo(OcpiStatus.SUCCESS.code) - } - - credentialsClientService.delete() - - expectCatching { - versionsClient.getVersions() - }.isFailure() - } - - @Test - fun `should properly run registration process then get, update, delete properly`() { - val receiverServer = setupReceiver() - val senderServer = setupSender() - - val credentialsClientService = setupCredentialsSenderClient( - senderServerSetupResult = senderServer, - receiverServerSetupResult = receiverServer - ) - - // Store token A on the receiver side, that will be used by the sender to begin registration and store it as - // well in the client so that it knows what token to send - val tokenA = UUID.randomUUID().toString() - receiverServer.platformCollection.insertOne(Platform(url = senderServer.versionsEndpoint, tokenA = tokenA)) - senderServer.platformCollection.insertOne(Platform(url = receiverServer.versionsEndpoint, tokenA = tokenA)) - - // Start the servers - receiverServer.transport.start() - senderServer.transport.start() - - val credentialsAfterRegistration = credentialsClientService.register() - - val versionsClient = VersionsClient( - transportClientBuilder = Http4kTransportClientBuilder(), - serverVersionsEndpointUrl = receiverServer.versionsEndpoint, - platformRepository = PlatformMongoRepository(collection = senderServer.platformCollection) - ) - - expectThat( - versionsClient.getVersions() - ) { - get { data } - .isNotNull() - .isNotEmpty() - .isEqualTo( - VersionsCacheRepository(baseUrl = receiverServer.transport.baseUrl) - .getVersions() - ) - - get { status_code } - .isEqualTo(OcpiStatus.SUCCESS.code) - } - - expectThat( - credentialsClientService.get() - ).isEqualTo(credentialsAfterRegistration) - - // Gireve update process (delete then register) - credentialsClientService.delete() - val newTokenA = UUID.randomUUID().toString() - receiverServer.platformCollection.updateOne(Platform::url eq senderServer.versionsEndpoint, set(Platform::tokenA setTo newTokenA)) - senderServer.platformCollection.updateOne(Platform::url eq receiverServer.versionsEndpoint, set(Platform::tokenA setTo newTokenA)) - credentialsClientService.register() - - expectThat( - versionsClient.getVersions() - ) { - get { data } - .isNotNull() - .isNotEmpty() - .isEqualTo( - VersionsCacheRepository(baseUrl = receiverServer.transport.baseUrl) - .getVersions() - ) - - get { status_code } - .isEqualTo(OcpiStatus.SUCCESS.code) - } - - credentialsClientService.delete() - - expectCatching { - versionsClient.getVersions() - }.isFailure() - } -} diff --git a/ocpi-toolkit-2.1.1-gireve/src/test/kotlin/com/izivia/ocpi/toolkit/tests/integration/LocationsIntegrationTest.kt b/ocpi-toolkit-2.1.1-gireve/src/test/kotlin/com/izivia/ocpi/toolkit/tests/integration/LocationsIntegrationTest.kt deleted file mode 100644 index 18217d62..00000000 --- a/ocpi-toolkit-2.1.1-gireve/src/test/kotlin/com/izivia/ocpi/toolkit/tests/integration/LocationsIntegrationTest.kt +++ /dev/null @@ -1,523 +0,0 @@ -package com.izivia.ocpi.toolkit.tests.integration - -import com.izivia.ocpi.toolkit.common.OcpiStatus -import com.izivia.ocpi.toolkit.modules.locations.LocationsCpoServer -import com.izivia.ocpi.toolkit.modules.locations.LocationsEmspClient -import com.izivia.ocpi.toolkit.modules.locations.domain.Location -import com.izivia.ocpi.toolkit.modules.locations.validation.LocationsCpoValidationService -import com.izivia.ocpi.toolkit.modules.versions.domain.VersionNumber -import com.izivia.ocpi.toolkit.samples.common.* -import com.izivia.ocpi.toolkit.tests.integration.common.BaseServerIntegrationTest -import com.izivia.ocpi.toolkit.tests.integration.mock.LocationsCpoMongoService -import com.mongodb.client.MongoDatabase -import org.junit.jupiter.api.Test -import org.litote.kmongo.getCollection -import strikt.api.expectThat -import strikt.assertions.* -import java.time.Instant -import java.util.* -import kotlin.math.min - - -class LocationsIntegrationTest : BaseServerIntegrationTest() { - - private val tokenC = UUID.randomUUID().toString() - private var database: MongoDatabase? = null - - private fun setupCpoServer(locations: List): Http4kTransportServer { - if (database == null) database = buildDBClient().getDatabase("ocpi-2-1-1-gireve-tests") - val collection = database!!.getCollection("cpo-server-locations-${UUID.randomUUID()}") - collection.insertMany(locations) - val server = buildTransportServer() - LocationsCpoServer( - server, - platformRepository = com.izivia.ocpi.toolkit.samples.common.DummyPlatformCacheRepository(tokenC = tokenC), - LocationsCpoValidationService( - service = LocationsCpoMongoService(collection), - ) - ) - return server - } - - @Test - fun `getLocations test (paginated)`() { - - // Start CPO server with dummy data - val numberOfLocations = 500 - val referenceDate = Instant.parse("2022-04-28T09:00:00.000Z") - val lastDate = referenceDate.plusSeconds(3600L * (numberOfLocations - 1)) - - val cpoServer = setupCpoServer( - locations = (0 until numberOfLocations).map { index -> - validLocation.copy( - evses = listOf(validEvse.copy(connectors = listOf(validConnector))), - last_updated = referenceDate.plusSeconds(3600L * index) - ) - } - ) - cpoServer.start() - - val cpoServerVersionsUrl = "${cpoServer.baseUrl}/versions" - - val platformRepo = com.izivia.ocpi.toolkit.samples.common.DummyPlatformCacheRepository(tokenC = tokenC).also { - val versionDetailsCpo = VersionDetailsCacheRepository(baseUrl = cpoServer.baseUrl) - - it.saveEndpoints( - cpoServerVersionsUrl, - versionDetailsCpo.getVersionDetails(VersionNumber.V2_1_1)!!.endpoints - ) - } - - val locationsEmspClient = LocationsEmspClient( - transportClientBuilder = Http4kTransportClientBuilder(), - serverVersionsEndpointUrl = cpoServerVersionsUrl, - platformRepository = platformRepo - ) - - // Tests - var limit = numberOfLocations + 1 - var offset = 0 - var dateFrom: Instant? = null - var dateTo: Instant? = null - - expectThat( - locationsEmspClient.getLocations( - dateFrom = dateFrom, - dateTo = dateTo, - offset = offset, - limit = limit - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.SUCCESS.code) - - get { data } - .isNotNull() - .and { - get { list } - .isNotEmpty() - .hasSize(min(limit, numberOfLocations)) - - get { list } - .first() - .isA() - } - .and { - get { limit } - .isEqualTo(limit) - } - .and { - get { offset } - .isEqualTo(offset) - } - .and { - get { totalCount } - .isEqualTo(numberOfLocations) - } - .and { - get { nextPageUrl } - .isNull() - } - } - - limit = 100 - offset = 100 - dateFrom = null - dateTo = null - - expectThat( - locationsEmspClient.getLocations( - dateFrom = dateFrom, - dateTo = dateTo, - offset = offset, - limit = limit - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.SUCCESS.code) - - get { data } - .isNotNull() - .and { - get { list } - .isNotEmpty() - .hasSize(min(limit, numberOfLocations)) - - get { list } - .first() - .isA() - } - .and { - get { limit } - .isEqualTo(limit) - } - .and { - get { offset } - .isEqualTo(offset) - } - .and { - get { totalCount } - .isEqualTo(numberOfLocations) - } - .and { - get { nextPageUrl } - .isEqualTo("${cpoServer.baseUrl}/2.1.1/locations?limit=$limit&offset=${offset + limit}") - } - } - - limit = 50 - offset = 50 - dateFrom = null - dateTo = null - - expectThat( - locationsEmspClient.getLocations( - dateFrom = dateFrom, - dateTo = dateTo, - offset = offset, - limit = limit - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.SUCCESS.code) - - get { data } - .isNotNull() - .and { - get { list } - .isNotEmpty() - .hasSize(min(limit, numberOfLocations)) - - get { list } - .first() - .isA() - } - .and { - get { limit } - .isEqualTo(limit) - } - .and { - get { offset } - .isEqualTo(offset) - } - .and { - get { totalCount } - .isEqualTo(numberOfLocations) - } - .and { - get { nextPageUrl } - .isEqualTo("${cpoServer.baseUrl}/2.1.1/locations?limit=$limit&offset=${offset + limit}") - } - } - - limit = numberOfLocations + 1 - offset = 0 - dateFrom = referenceDate - dateTo = lastDate - - expectThat( - locationsEmspClient.getLocations( - dateFrom = dateFrom, - dateTo = dateTo, - offset = offset, - limit = limit - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.SUCCESS.code) - - get { data } - .isNotNull() - .and { - get { list } - .isNotEmpty() - .hasSize(min(limit, numberOfLocations)) - - get { list } - .first() - .isA() - } - .and { - get { limit } - .isEqualTo(limit) - } - .and { - get { offset } - .isEqualTo(offset) - } - .and { - get { totalCount } - .isEqualTo(numberOfLocations) - } - .and { - get { nextPageUrl } - .isNull() - } - } - - limit = numberOfLocations + 1 - offset = 0 - dateFrom = referenceDate - dateTo = null - - expectThat( - locationsEmspClient.getLocations( - dateFrom = dateFrom, - dateTo = dateTo, - offset = offset, - limit = limit - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.SUCCESS.code) - - get { data } - .isNotNull() - .and { - get { list } - .isNotEmpty() - .hasSize(min(limit, numberOfLocations)) - - get { list } - .first() - .isA() - } - .and { - get { limit } - .isEqualTo(limit) - } - .and { - get { offset } - .isEqualTo(offset) - } - .and { - get { totalCount } - .isEqualTo(numberOfLocations) - } - .and { - get { nextPageUrl } - .isNull() - } - } - - limit = numberOfLocations + 1 - offset = 0 - dateFrom = null - dateTo = lastDate - - expectThat( - locationsEmspClient.getLocations( - dateFrom = dateFrom, - dateTo = dateTo, - offset = offset, - limit = limit - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.SUCCESS.code) - - get { data } - .isNotNull() - .and { - get { list } - .isNotEmpty() - .hasSize(min(limit, numberOfLocations)) - - get { list } - .first() - .isA() - } - .and { - get { limit } - .isEqualTo(limit) - } - .and { - get { offset } - .isEqualTo(offset) - } - .and { - get { totalCount } - .isEqualTo(numberOfLocations) - } - .and { - get { nextPageUrl } - .isNull() - } - } - - limit = numberOfLocations + 1 - offset = 0 - dateFrom = lastDate - dateTo = null - - expectThat( - locationsEmspClient.getLocations( - dateFrom = dateFrom, - dateTo = dateTo, - offset = offset, - limit = limit - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.SUCCESS.code) - - get { data } - .isNotNull() - .and { - get { list } - .isNotEmpty() - .hasSize(1) - - get { list } - .first() - .isA() - } - .and { - get { limit } - .isEqualTo(limit) - } - .and { - get { offset } - .isEqualTo(offset) - } - .and { - get { totalCount } - .isEqualTo(1) - } - .and { - get { nextPageUrl } - .isNull() - } - } - - limit = numberOfLocations + 1 - offset = 0 - dateFrom = null - dateTo = referenceDate - - expectThat( - locationsEmspClient.getLocations( - dateFrom = dateFrom, - dateTo = dateTo, - offset = offset, - limit = limit - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.SUCCESS.code) - - get { data } - .isNotNull() - .and { - get { list } - .isNotEmpty() - .hasSize(1) - - get { list } - .first() - .isA() - } - .and { - get { limit } - .isEqualTo(limit) - } - .and { - get { offset } - .isEqualTo(offset) - } - .and { - get { totalCount } - .isEqualTo(1) - } - .and { - get { nextPageUrl } - .isNull() - } - } - - limit = numberOfLocations + 1 - offset = 1 - dateFrom = null - dateTo = referenceDate - - expectThat( - locationsEmspClient.getLocations( - dateFrom = dateFrom, - dateTo = dateTo, - offset = offset, - limit = limit - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.SUCCESS.code) - - get { data } - .isNotNull() - .and { - get { list } - .isEmpty() - } - .and { - get { limit } - .isEqualTo(limit) - } - .and { - get { offset } - .isEqualTo(offset) - } - .and { - get { totalCount } - .isEqualTo(1) - } - .and { - get { nextPageUrl } - .isNull() - } - } - - limit = 1 - offset = 0 - dateFrom = null - dateTo = lastDate.minusSeconds(3600L) - - expectThat( - locationsEmspClient.getLocations( - dateFrom = dateFrom, - dateTo = dateTo, - offset = offset, - limit = limit - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.SUCCESS.code) - - get { data } - .isNotNull() - .and { - get { list } - .isNotEmpty() - .hasSize(1) - - get { list } - .first() - .isA() - } - .and { - get { limit } - .isEqualTo(limit) - } - .and { - get { offset } - .isEqualTo(offset) - } - .and { - get { totalCount } - .isEqualTo(numberOfLocations - 1) - } - .and { - get { nextPageUrl } - .isEqualTo("${cpoServer.baseUrl}/2.1.1/locations?date_to=${dateTo}&limit=$limit&offset=${offset + limit}") - } - } - } -} diff --git a/ocpi-toolkit-2.1.1-gireve/src/test/kotlin/com/izivia/ocpi/toolkit/tests/integration/TokensIntegrationTest.kt b/ocpi-toolkit-2.1.1-gireve/src/test/kotlin/com/izivia/ocpi/toolkit/tests/integration/TokensIntegrationTest.kt deleted file mode 100644 index b56c6127..00000000 --- a/ocpi-toolkit-2.1.1-gireve/src/test/kotlin/com/izivia/ocpi/toolkit/tests/integration/TokensIntegrationTest.kt +++ /dev/null @@ -1,545 +0,0 @@ -package com.izivia.ocpi.toolkit.tests.integration - -import com.izivia.ocpi.toolkit.common.OcpiStatus -import com.izivia.ocpi.toolkit.modules.tokens.TokensCpoClient -import com.izivia.ocpi.toolkit.modules.tokens.TokensEmspServer -import com.izivia.ocpi.toolkit.modules.tokens.domain.Token -import com.izivia.ocpi.toolkit.modules.tokens.validation.TokensEmspValidationService -import com.izivia.ocpi.toolkit.modules.versions.domain.VersionNumber -import com.izivia.ocpi.toolkit.samples.common.* -import com.izivia.ocpi.toolkit.tests.integration.common.BaseServerIntegrationTest -import com.izivia.ocpi.toolkit.tests.integration.mock.TokensEmspMongoRepository -import com.mongodb.client.MongoDatabase -import org.junit.jupiter.api.Test -import org.litote.kmongo.getCollection -import strikt.api.expectThat -import strikt.assertions.* -import java.time.Instant -import java.util.* -import kotlin.math.min - - -class TokensIntegrationTest : BaseServerIntegrationTest() { - - private val tokenC = UUID.randomUUID().toString() - private var database: MongoDatabase? = null - - private fun setupEmspServer(tokens: List): Http4kTransportServer { - if (database == null) database = buildDBClient().getDatabase("ocpi-2-1-1-tests") - val collection = database!!.getCollection("emsp-server-tokens-${UUID.randomUUID()}") - collection.insertMany(tokens) - val server = buildTransportServer() - TokensEmspServer( - server, - platformRepository = DummyPlatformCacheRepository(tokenC = tokenC), - TokensEmspValidationService( - service = TokensEmspMongoRepository(collection), - ) - ) - return server - } - - @Test - fun `getTokens test (paginated)`() { - - // Start EMSP server with dummy data - val numberOfTokens = 500 - val referenceDate = Instant.parse("2022-04-28T09:00:00.000Z") - val lastDate = referenceDate.plusSeconds(3600L * (numberOfTokens - 1)) - - val emspServer = setupEmspServer( - tokens = (0 until numberOfTokens).map { index -> - validToken.copy( - uid = UUID.randomUUID().toString(), - last_updated = referenceDate.plusSeconds(3600L * index) - ) - } - ) - emspServer.start() - - val emspServerVersionsUrl = "${emspServer.baseUrl}/versions" - - val platformRepo = DummyPlatformCacheRepository(tokenC = tokenC).also { - val versionDetailsEmsp = VersionDetailsCacheRepository(baseUrl = emspServer.baseUrl) - - it.saveEndpoints( - emspServerVersionsUrl, - versionDetailsEmsp.getVersionDetails(VersionNumber.V2_1_1)!!.endpoints - ) - } - - val tokensCpoClient = TokensCpoClient( - transportClientBuilder = Http4kTransportClientBuilder(), - serverVersionsEndpointUrl = emspServerVersionsUrl, - platformRepository = platformRepo - ) - - // Tests - var limit = numberOfTokens + 1 - var offset = 0 - var dateFrom: Instant? = null - var dateTo: Instant? = null - val countryCode: String = "fr" - val partyId: String = "abc" - - expectThat( - tokensCpoClient.getTokens( - dateFrom = dateFrom, - dateTo = dateTo, - offset = offset, - limit = limit, - countryCode = countryCode, - partyId = partyId - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.SUCCESS.code) - - get { data } - .isNotNull() - .and { - get { list } - .isNotEmpty() - .hasSize(min(limit, numberOfTokens)) - - get { list } - .first() - .isA() - } - .and { - get { limit } - .isEqualTo(limit) - } - .and { - get { offset } - .isEqualTo(offset) - } - .and { - get { totalCount } - .isEqualTo(numberOfTokens) - } - .and { - get { nextPageUrl } - .isNull() - } - } - - limit = 100 - offset = 100 - dateFrom = null - dateTo = null - - expectThat( - tokensCpoClient.getTokens( - dateFrom = dateFrom, - dateTo = dateTo, - offset = offset, - limit = limit, - countryCode = countryCode, - partyId = partyId - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.SUCCESS.code) - - get { data } - .isNotNull() - .and { - get { list } - .isNotEmpty() - .hasSize(min(limit, numberOfTokens)) - - get { list } - .first() - .isA() - } - .and { - get { limit } - .isEqualTo(limit) - } - .and { - get { offset } - .isEqualTo(offset) - } - .and { - get { totalCount } - .isEqualTo(numberOfTokens) - } - .and { - get { nextPageUrl } - .isEqualTo("${emspServer.baseUrl}/2.1.1/tokens?limit=$limit&ocpi-to-country-code=$countryCode&ocpi-to-party-id=$partyId&offset=${offset + limit}") - } - } - - limit = 50 - offset = 50 - dateFrom = null - dateTo = null - - expectThat( - tokensCpoClient.getTokens( - dateFrom = dateFrom, - dateTo = dateTo, - offset = offset, - limit = limit, - countryCode = countryCode, - partyId = partyId - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.SUCCESS.code) - - get { data } - .isNotNull() - .and { - get { list } - .isNotEmpty() - .hasSize(min(limit, numberOfTokens)) - - get { list } - .first() - .isA() - } - .and { - get { limit } - .isEqualTo(limit) - } - .and { - get { offset } - .isEqualTo(offset) - } - .and { - get { totalCount } - .isEqualTo(numberOfTokens) - } - .and { - get { nextPageUrl } - .isEqualTo("${emspServer.baseUrl}/2.1.1/tokens?limit=$limit&ocpi-to-country-code=$countryCode&ocpi-to-party-id=$partyId&offset=${offset + limit}") - } - } - - limit = numberOfTokens + 1 - offset = 0 - dateFrom = referenceDate - dateTo = lastDate - - expectThat( - tokensCpoClient.getTokens( - dateFrom = dateFrom, - dateTo = dateTo, - offset = offset, - limit = limit, - countryCode = countryCode, - partyId = partyId - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.SUCCESS.code) - - get { data } - .isNotNull() - .and { - get { list } - .isNotEmpty() - .hasSize(min(limit, numberOfTokens)) - - get { list } - .first() - .isA() - } - .and { - get { limit } - .isEqualTo(limit) - } - .and { - get { offset } - .isEqualTo(offset) - } - .and { - get { totalCount } - .isEqualTo(numberOfTokens) - } - .and { - get { nextPageUrl } - .isNull() - } - } - - limit = numberOfTokens + 1 - offset = 0 - dateFrom = referenceDate - dateTo = null - - expectThat( - tokensCpoClient.getTokens( - dateFrom = dateFrom, - dateTo = dateTo, - offset = offset, - limit = limit, - countryCode = countryCode, - partyId = partyId - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.SUCCESS.code) - - get { data } - .isNotNull() - .and { - get { list } - .isNotEmpty() - .hasSize(min(limit, numberOfTokens)) - - get { list } - .first() - .isA() - } - .and { - get { limit } - .isEqualTo(limit) - } - .and { - get { offset } - .isEqualTo(offset) - } - .and { - get { totalCount } - .isEqualTo(numberOfTokens) - } - .and { - get { nextPageUrl } - .isNull() - } - } - - limit = numberOfTokens + 1 - offset = 0 - dateFrom = null - dateTo = lastDate - - expectThat( - tokensCpoClient.getTokens( - dateFrom = dateFrom, - dateTo = dateTo, - offset = offset, - limit = limit, - countryCode = countryCode, - partyId = partyId - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.SUCCESS.code) - - get { data } - .isNotNull() - .and { - get { list } - .isNotEmpty() - .hasSize(min(limit, numberOfTokens)) - - get { list } - .first() - .isA() - } - .and { - get { limit } - .isEqualTo(limit) - } - .and { - get { offset } - .isEqualTo(offset) - } - .and { - get { totalCount } - .isEqualTo(numberOfTokens) - } - .and { - get { nextPageUrl } - .isNull() - } - } - - limit = numberOfTokens + 1 - offset = 0 - dateFrom = lastDate - dateTo = null - - expectThat( - tokensCpoClient.getTokens( - dateFrom = dateFrom, - dateTo = dateTo, - offset = offset, - limit = limit, - countryCode = countryCode, - partyId = partyId - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.SUCCESS.code) - - get { data } - .isNotNull() - .and { - get { list } - .isNotEmpty() - .hasSize(1) - - get { list } - .first() - .isA() - } - .and { - get { limit } - .isEqualTo(limit) - } - .and { - get { offset } - .isEqualTo(offset) - } - .and { - get { totalCount } - .isEqualTo(1) - } - .and { - get { nextPageUrl } - .isNull() - } - } - - limit = numberOfTokens + 1 - offset = 0 - dateFrom = null - dateTo = referenceDate - - expectThat( - tokensCpoClient.getTokens( - dateFrom = dateFrom, - dateTo = dateTo, - offset = offset, - limit = limit, - countryCode = countryCode, - partyId = partyId - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.SUCCESS.code) - - get { data } - .isNotNull() - .and { - get { list } - .isNotEmpty() - .hasSize(1) - - get { list } - .first() - .isA() - } - .and { - get { limit } - .isEqualTo(limit) - } - .and { - get { offset } - .isEqualTo(offset) - } - .and { - get { totalCount } - .isEqualTo(1) - } - .and { - get { nextPageUrl } - .isNull() - } - } - - limit = numberOfTokens + 1 - offset = 1 - dateFrom = null - dateTo = referenceDate - - expectThat( - tokensCpoClient.getTokens( - dateFrom = dateFrom, - dateTo = dateTo, - offset = offset, - limit = limit, - countryCode = countryCode, - partyId = partyId - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.SUCCESS.code) - - get { data } - .isNotNull() - .and { - get { list } - .isEmpty() - } - .and { - get { limit } - .isEqualTo(limit) - } - .and { - get { offset } - .isEqualTo(offset) - } - .and { - get { totalCount } - .isEqualTo(1) - } - .and { - get { nextPageUrl } - .isNull() - } - } - - limit = 1 - offset = 0 - dateFrom = null - dateTo = lastDate.minusSeconds(3600L) - - expectThat( - tokensCpoClient.getTokens( - dateFrom = dateFrom, - dateTo = dateTo, - offset = offset, - limit = limit, - countryCode = countryCode, - partyId = partyId - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.SUCCESS.code) - - get { data } - .isNotNull() - .and { - get { list } - .isNotEmpty() - .hasSize(1) - - get { list } - .first() - .isA() - } - .and { - get { limit } - .isEqualTo(limit) - } - .and { - get { offset } - .isEqualTo(offset) - } - .and { - get { totalCount } - .isEqualTo(numberOfTokens - 1) - } - .and { - get { nextPageUrl } - .isEqualTo("${emspServer.baseUrl}/2.1.1/tokens?date_to=${dateTo}&limit=$limit&ocpi-to-country-code=$countryCode&ocpi-to-party-id=$partyId&offset=${offset + limit}") - } - } - } -} diff --git a/ocpi-toolkit-2.1.1-gireve/src/test/kotlin/com/izivia/ocpi/toolkit/tests/integration/common/BaseDBIntegrationTest.kt b/ocpi-toolkit-2.1.1-gireve/src/test/kotlin/com/izivia/ocpi/toolkit/tests/integration/common/BaseDBIntegrationTest.kt deleted file mode 100644 index 6934c32e..00000000 --- a/ocpi-toolkit-2.1.1-gireve/src/test/kotlin/com/izivia/ocpi/toolkit/tests/integration/common/BaseDBIntegrationTest.kt +++ /dev/null @@ -1,17 +0,0 @@ -package com.izivia.ocpi.toolkit.tests.integration.common - -import org.litote.kmongo.KMongo -import org.testcontainers.containers.MongoDBContainer -import org.testcontainers.junit.jupiter.Container -import org.testcontainers.junit.jupiter.Testcontainers -import org.testcontainers.utility.DockerImageName - -@Testcontainers -abstract class BaseDBIntegrationTest { - - @Container - protected val mongoDBContainer = MongoDBContainer(DockerImageName.parse("mongo:5.0.8")) - - protected fun buildDBClient() = - KMongo.createClient(mongoDBContainer.replicaSetUrl) -} \ No newline at end of file diff --git a/ocpi-toolkit-2.1.1-gireve/src/test/kotlin/com/izivia/ocpi/toolkit/tests/integration/common/BaseServerIntegrationTest.kt b/ocpi-toolkit-2.1.1-gireve/src/test/kotlin/com/izivia/ocpi/toolkit/tests/integration/common/BaseServerIntegrationTest.kt deleted file mode 100644 index 39cbbd56..00000000 --- a/ocpi-toolkit-2.1.1-gireve/src/test/kotlin/com/izivia/ocpi/toolkit/tests/integration/common/BaseServerIntegrationTest.kt +++ /dev/null @@ -1,20 +0,0 @@ -package com.izivia.ocpi.toolkit.tests.integration.common - -import com.izivia.ocpi.toolkit.samples.common.Http4kTransportServer -import java.net.ServerSocket - -abstract class BaseServerIntegrationTest: BaseDBIntegrationTest() { - - private fun getFreeNetworkPort() = ServerSocket(0).use { it.localPort } - - protected fun buildTransportServer(): Http4kTransportServer { - val port = getFreeNetworkPort() - return Http4kTransportServer( - baseUrl = "http://localhost:$port", - port = port - ) - } - - protected fun Http4kTransportServer.getClient() = - com.izivia.ocpi.toolkit.samples.common.Http4kTransportClient(baseUrl) -} diff --git a/ocpi-toolkit-2.1.1-gireve/src/test/kotlin/com/izivia/ocpi/toolkit/tests/integration/mock/LocationsCpoMongoService.kt b/ocpi-toolkit-2.1.1-gireve/src/test/kotlin/com/izivia/ocpi/toolkit/tests/integration/mock/LocationsCpoMongoService.kt deleted file mode 100644 index 2616359a..00000000 --- a/ocpi-toolkit-2.1.1-gireve/src/test/kotlin/com/izivia/ocpi/toolkit/tests/integration/mock/LocationsCpoMongoService.kt +++ /dev/null @@ -1,51 +0,0 @@ -package com.izivia.ocpi.toolkit.tests.integration.mock - -import com.izivia.ocpi.toolkit.common.SearchResult -import com.izivia.ocpi.toolkit.common.toSearchResult -import com.izivia.ocpi.toolkit.modules.locations.domain.Connector -import com.izivia.ocpi.toolkit.modules.locations.domain.Evse -import com.izivia.ocpi.toolkit.modules.locations.domain.Location -import com.izivia.ocpi.toolkit.modules.locations.services.LocationsCpoService -import com.mongodb.client.MongoCollection -import org.litote.kmongo.and -import org.litote.kmongo.gte -import org.litote.kmongo.lte -import java.time.Instant - -class LocationsCpoMongoService( - private val collection: MongoCollection -) : LocationsCpoService { - - override fun getLocations(dateFrom: Instant?, dateTo: Instant?, offset: Int, limit: Int?): SearchResult = - collection - .run { - find( - and( - dateFrom?.let { Location::last_updated gte dateFrom }, - dateTo?.let { Location::last_updated lte dateTo } - ) - ) - } - .toList() - .let { - val actualLimit = limit ?: 10 - val size = it.size - - it - .filterIndexed { index: Int, _: Location -> index + 1 > offset } - .take(actualLimit) - .toSearchResult(totalCount = size, limit = actualLimit, offset = offset) - } - - override fun getLocation(locationId: String): Location? { - TODO("Not yet implemented") - } - - override fun getEvse(locationId: String, evseUid: String): Evse? { - TODO("Not yet implemented") - } - - override fun getConnector(locationId: String, evseUid: String, connectorId: String): Connector? { - TODO("Not yet implemented") - } -} diff --git a/ocpi-toolkit-2.1.1-gireve/src/test/kotlin/com/izivia/ocpi/toolkit/tests/integration/mock/PlatformMongoRepository.kt b/ocpi-toolkit-2.1.1-gireve/src/test/kotlin/com/izivia/ocpi/toolkit/tests/integration/mock/PlatformMongoRepository.kt deleted file mode 100644 index 6e65db84..00000000 --- a/ocpi-toolkit-2.1.1-gireve/src/test/kotlin/com/izivia/ocpi/toolkit/tests/integration/mock/PlatformMongoRepository.kt +++ /dev/null @@ -1,99 +0,0 @@ -package com.izivia.ocpi.toolkit.tests.integration.mock - -import com.izivia.ocpi.toolkit.modules.credentials.repositories.PlatformRepository -import com.izivia.ocpi.toolkit.modules.versions.domain.Endpoint -import com.izivia.ocpi.toolkit.modules.versions.domain.Version -import com.izivia.ocpi.toolkit.samples.common.Platform -import com.mongodb.client.MongoCollection -import com.mongodb.client.model.FindOneAndUpdateOptions -import com.mongodb.client.model.ReturnDocument -import org.litote.kmongo.eq -import org.litote.kmongo.findOne -import org.litote.kmongo.set -import org.litote.kmongo.setTo - -class PlatformMongoRepository( - private val collection: MongoCollection -) : PlatformRepository { - - override fun savePlatformUrlForTokenA(tokenA: String, platformUrl: String): String? = - collection - .findOneAndUpdate( - Platform::tokenA eq tokenA, - set(Platform::url setTo platformUrl), - FindOneAndUpdateOptions().returnDocument(ReturnDocument.AFTER) - ) - ?.url - - override fun saveVersion(platformUrl: String, version: Version): Version = version.also { - collection - .updateOne(Platform::url eq platformUrl, set(Platform::version setTo it)) - } - - override fun saveEndpoints(platformUrl: String, endpoints: List): List = endpoints.also { - collection - .updateOne(Platform::url eq platformUrl, set(Platform::endpoints setTo it)) - } - - override fun saveCredentialsTokenA(platformUrl: String, credentialsTokenA: String): String = - credentialsTokenA.also { - collection - .updateOne(Platform::url eq platformUrl, set(Platform::tokenA setTo it)) - } - - override fun saveCredentialsTokenB(platformUrl: String, credentialsTokenB: String): String = - credentialsTokenB.also { - collection - .updateOne(Platform::url eq platformUrl, set(Platform::tokenB setTo it)) - } - - override fun saveCredentialsTokenC(platformUrl: String, credentialsTokenC: String): String = - credentialsTokenC.also { - collection - .updateOne(Platform::url eq platformUrl, set(Platform::tokenC setTo it)) - } - - override fun getCredentialsTokenA(platformUrl: String): String? = collection - .findOne(Platform::url eq platformUrl)?.tokenA - - override fun getCredentialsTokenB(platformUrl: String): String? = collection - .findOne(Platform::url eq platformUrl)?.tokenB - - override fun getCredentialsTokenC(platformUrl: String): String? = collection - .findOne(Platform::url eq platformUrl)?.tokenC - - override fun platformExistsWithTokenA(token: String): Boolean = collection - .findOne(Platform::tokenA eq token) != null - - override fun platformExistsWithTokenB(token: String): Boolean = collection - .findOne(Platform::tokenB eq token) != null - - override fun getPlatformUrlByTokenC(token: String): String? = collection - .findOne(Platform::tokenC eq token)?.url - - override fun getEndpoints(platformUrl: String): List = collection - .findOne(Platform::url eq platformUrl)?.endpoints ?: emptyList() - - override fun getVersion(platformUrl: String): Version? = collection - .findOne(Platform::url eq platformUrl)?.version - - override fun removeCredentialsTokenA(platformUrl: String) { - collection.updateOne(Platform::url eq platformUrl, set(Platform::tokenA setTo null)) - } - - override fun removeCredentialsTokenB(platformUrl: String) { - collection.updateOne(Platform::url eq platformUrl, set(Platform::tokenB setTo null)) - } - - override fun removeCredentialsTokenC(platformUrl: String) { - collection.updateOne(Platform::url eq platformUrl, set(Platform::tokenC setTo null)) - } - - override fun removeVersion(platformUrl: String) { - collection.updateOne(Platform::url eq platformUrl, set(Platform::version setTo null)) - } - - override fun removeEndpoints(platformUrl: String) { - collection.updateOne(Platform::url eq platformUrl, set(Platform::endpoints setTo null)) - } -} diff --git a/ocpi-toolkit-2.1.1-gireve/src/test/kotlin/com/izivia/ocpi/toolkit/tests/integration/mock/TokensEmspMongoRepository.kt b/ocpi-toolkit-2.1.1-gireve/src/test/kotlin/com/izivia/ocpi/toolkit/tests/integration/mock/TokensEmspMongoRepository.kt deleted file mode 100644 index 4a989152..00000000 --- a/ocpi-toolkit-2.1.1-gireve/src/test/kotlin/com/izivia/ocpi/toolkit/tests/integration/mock/TokensEmspMongoRepository.kt +++ /dev/null @@ -1,59 +0,0 @@ -package com.izivia.ocpi.toolkit.tests.integration.mock - -import com.izivia.ocpi.toolkit.common.SearchResult -import com.izivia.ocpi.toolkit.common.toSearchResult -import com.izivia.ocpi.toolkit.modules.tokens.domain.AuthorizationInfo -import com.izivia.ocpi.toolkit.modules.tokens.domain.LocationReferences -import com.izivia.ocpi.toolkit.modules.tokens.domain.Token -import com.izivia.ocpi.toolkit.modules.tokens.domain.TokenType -import com.izivia.ocpi.toolkit.modules.tokens.services.TokensEmspService -import com.mongodb.client.MongoCollection -import org.litote.kmongo.and -import org.litote.kmongo.gte -import org.litote.kmongo.lte -import java.time.Instant - -class TokensEmspMongoRepository( - private val collection: MongoCollection -) : TokensEmspService { - - override fun getTokens( - dateFrom: Instant?, - dateTo: Instant?, - offset: Int, - limit: Int?, - countryCode: String?, - partyId: String? - ): SearchResult = - collection - .run { - find( - and( - dateFrom?.let { Token::last_updated gte dateFrom }, - dateTo?.let { Token::last_updated lte dateTo } - ) - ) - } - .toList() - .let { - val actualLimit = limit ?: 10 - val size = it.size - - it - .filterIndexed { index: Int, _: Token -> index + 1 > offset } - .take(actualLimit) - .toSearchResult(totalCount = size, limit = actualLimit, offset = offset) - } - - override fun getToken(tokenUid: String, tokenType: TokenType): Token? { - TODO("Not yet implemented") - } - - override fun postToken( - tokenUid: String, - tokenType: TokenType, - locationReferences: LocationReferences - ): AuthorizationInfo { - TODO("Not yet implemented") - } -} diff --git a/ocpi-toolkit-2.1.1-gireve/src/test/kotlin/com/izivia/ocpi/toolkit/tests/mock/LocationsCpoRepository.kt b/ocpi-toolkit-2.1.1-gireve/src/test/kotlin/com/izivia/ocpi/toolkit/tests/mock/LocationsCpoRepository.kt deleted file mode 100644 index cab6944f..00000000 --- a/ocpi-toolkit-2.1.1-gireve/src/test/kotlin/com/izivia/ocpi/toolkit/tests/mock/LocationsCpoRepository.kt +++ /dev/null @@ -1,57 +0,0 @@ -package com.izivia.ocpi.toolkit.tests.mock - -import com.izivia.ocpi.toolkit.common.toSearchResult -import com.izivia.ocpi.toolkit.modules.locations.domain.Location -import com.izivia.ocpi.toolkit.modules.locations.services.LocationsCpoService -import io.mockk.every -import io.mockk.mockk -import io.mockk.slot -import java.time.Instant - -fun locationsCpoService(locations: List): LocationsCpoService = mockk { - val locationId = slot() - val evseUid = slot() - val connectorId = slot() - val dateFrom = mutableListOf() - val dateTo = mutableListOf() - val offset = slot() - val limit = mutableListOf() - - every { getLocations(captureNullable(dateFrom), captureNullable(dateTo), capture(offset), captureNullable(limit)) } answers { - val capturedOffset = offset.captured - val capturedLimit = limit.captured() ?: 10 - - locations - .filter { loc -> - val dateFromFilterOk = dateFrom.captured()?.let { loc.last_updated.isAfter(it) } ?: true - val dateToFilterOk = dateTo.captured()?.let { loc.last_updated.isBefore(it) } ?: true - - dateFromFilterOk && dateToFilterOk - } - .filterIndexed { index: Int, _: Location -> - index >= capturedOffset - } - .take(capturedLimit) - .toSearchResult(totalCount = locations.size, limit = capturedLimit, offset = capturedOffset) - } - - every { getLocation(capture(locationId)) } answers { - locations.find { it.id == locationId.captured } - } - - every { getEvse(capture(locationId), capture(evseUid)) } answers { - locations - .find { it.id == locationId.captured } - ?.evses - ?.find { it.uid == evseUid.captured } - } - - every { getConnector(capture(locationId), capture(evseUid), capture(connectorId)) } answers { - locations - .find { it.id == locationId.captured } - ?.evses - ?.find { it.uid == evseUid.captured } - ?.connectors - ?.find { it.id == connectorId.captured } - } -} \ No newline at end of file diff --git a/ocpi-toolkit-2.1.1-gireve/src/test/kotlin/com/izivia/ocpi/toolkit/tests/mock/LocationsEmspRepository.kt b/ocpi-toolkit-2.1.1-gireve/src/test/kotlin/com/izivia/ocpi/toolkit/tests/mock/LocationsEmspRepository.kt deleted file mode 100644 index 865b09bb..00000000 --- a/ocpi-toolkit-2.1.1-gireve/src/test/kotlin/com/izivia/ocpi/toolkit/tests/mock/LocationsEmspRepository.kt +++ /dev/null @@ -1,92 +0,0 @@ -package com.izivia.ocpi.toolkit.tests.mock - -import com.izivia.ocpi.toolkit.modules.locations.domain.* -import com.izivia.ocpi.toolkit.modules.locations.services.LocationsEmspService -import io.mockk.every -import io.mockk.mockk -import io.mockk.slot - -fun locationsEmspService(locations: List): LocationsEmspService = mockk { - val countryCode = slot() - val partyId = slot() - val locationId = slot() - val evseUid = slot() - val connectorId = slot() - val location = slot() - val evse = slot() - val connector = slot() - val locationPartial = slot() - val evsePartial = slot() - val connectorPartial = slot() - - every { getLocation(capture(countryCode), capture(partyId), capture(locationId)) } answers { - locations.find { it.id == locationId.captured } - } - - every { getEvse(capture(countryCode), capture(partyId), capture(locationId), capture(evseUid)) } answers { - locations - .find { it.id == locationId.captured } - ?.evses - ?.find { it.uid == evseUid.captured } - } - - every { getConnector(capture(countryCode), capture(partyId), capture(locationId), capture(evseUid), capture(connectorId)) } answers { - locations - .find { it.id == locationId.captured } - ?.evses - ?.find { it.uid == evseUid.captured } - ?.connectors - ?.find { it.id == connectorId.captured } - } - - every { patchLocation(capture(countryCode), capture(partyId), capture(locationId), capture(locationPartial)) } answers { - // Patch logic is not implemented - locations - .find { it.id == locationId.captured } - } - - every { patchEvse(capture(countryCode), capture(partyId), capture(locationId), capture(evseUid), capture(evsePartial)) } answers { - // Patch logic is not implemented - locations - .find { it.id == locationId.captured } - ?.evses - ?.find { it.uid == evseUid.captured } - } - - every { patchConnector(capture(countryCode), capture(partyId), capture(locationId), capture(evseUid), capture(connectorId), capture(connectorPartial)) } answers { - // Patch logic is not implemented - locations - .find { it.id == locationId.captured } - ?.evses - ?.find { it.uid == evseUid.captured } - ?.connectors - ?.find { it.id == connectorId.captured } - } - - every { putLocation(capture(countryCode), capture(partyId), capture(locationId), capture(location)) } answers { - // Put logic is not implemented - locations - .find { it.id == locationId.captured } - ?: location.captured - } - - every { putEvse(capture(countryCode), capture(partyId), capture(locationId), capture(evseUid), capture(evse)) } answers { - // Put logic is not implemented - locations - .find { it.id == locationId.captured } - ?.evses - ?.find { it.uid == evseUid.captured } - ?: evse.captured - } - - every { putConnector(capture(countryCode), capture(partyId), capture(locationId), capture(evseUid), capture(connectorId), capture(connector)) } answers { - // Put logic is not implemented - locations - .find { it.id == locationId.captured } - ?.evses - ?.find { it.uid == evseUid.captured } - ?.connectors - ?.find { it.id == connectorId.captured } - ?: connector.captured - } -} \ No newline at end of file diff --git a/ocpi-toolkit-2.1.1-gireve/src/test/kotlin/com/izivia/ocpi/toolkit/tests/mock/TokensCoreRepository.kt b/ocpi-toolkit-2.1.1-gireve/src/test/kotlin/com/izivia/ocpi/toolkit/tests/mock/TokensCoreRepository.kt deleted file mode 100644 index 79d9b59c..00000000 --- a/ocpi-toolkit-2.1.1-gireve/src/test/kotlin/com/izivia/ocpi/toolkit/tests/mock/TokensCoreRepository.kt +++ /dev/null @@ -1,69 +0,0 @@ -package com.izivia.ocpi.toolkit.tests.mock - -import com.izivia.ocpi.toolkit.modules.tokens.domain.Token -import com.izivia.ocpi.toolkit.modules.tokens.domain.TokenPartial -import com.izivia.ocpi.toolkit.modules.tokens.services.TokensCpoService -import io.mockk.every -import io.mockk.mockk -import io.mockk.slot - -fun tokensCpoService(tokens: MutableList): TokensCpoService = mockk { - - val countryCode = slot() - val partyId = slot() - val tokenUid = slot() - val token = slot() - val tokenPartial = slot() - - every { - getToken( - capture(countryCode), - capture(partyId), - capture(tokenUid) - ) - } answers { - tokens.find { - it.uid == tokenUid.captured - } - } - - every { - putToken( - capture(countryCode), - capture(partyId), - capture(tokenUid), - capture(token) - ) - } answers { - tokens.add(token.captured) - tokens.find { it.uid == token.captured.uid }!! - } - - every { - patchToken( - capture(countryCode), - capture(partyId), - capture(tokenUid), - capture(tokenPartial) - ) - } answers { - tokens - .indexOfFirst { it.uid == tokenUid.captured } - .let { index -> - val existingToken = tokens[index] - existingToken.copy( - uid = tokenPartial.captured.uid ?: existingToken.uid, - type = tokenPartial.captured.type ?: existingToken.type, - auth_id = tokenPartial.captured.auth_id ?: existingToken.auth_id, - visual_number = tokenPartial.captured.visual_number ?: existingToken.visual_number, - issuer = tokenPartial.captured.issuer ?: existingToken.issuer, - valid = tokenPartial.captured.valid ?: existingToken.valid, - whitelist = tokenPartial.captured.whitelist ?: existingToken.whitelist, - language = tokenPartial.captured.language ?: existingToken.language, - last_updated = tokenPartial.captured.last_updated ?: existingToken.last_updated, - ).also { - tokens[index] = it - } - } - } -} diff --git a/ocpi-toolkit-2.1.1-gireve/src/test/kotlin/com/izivia/ocpi/toolkit/tests/mock/TokensEmspRepository.kt b/ocpi-toolkit-2.1.1-gireve/src/test/kotlin/com/izivia/ocpi/toolkit/tests/mock/TokensEmspRepository.kt deleted file mode 100644 index 6650b40e..00000000 --- a/ocpi-toolkit-2.1.1-gireve/src/test/kotlin/com/izivia/ocpi/toolkit/tests/mock/TokensEmspRepository.kt +++ /dev/null @@ -1,66 +0,0 @@ -package com.izivia.ocpi.toolkit.tests.mock - -import com.izivia.ocpi.toolkit.common.toSearchResult -import com.izivia.ocpi.toolkit.modules.tokens.domain.* -import com.izivia.ocpi.toolkit.modules.tokens.services.TokensEmspService -import io.mockk.every -import io.mockk.mockk -import io.mockk.slot -import java.time.Instant - -fun tokensEmspService(tokens: List): TokensEmspService = mockk { - val dateFrom = mutableListOf() - val dateTo = mutableListOf() - val offset = slot() - val limit = mutableListOf() - val countryCode = mutableListOf() - val partyId = mutableListOf() - - val tokenUid = slot() - val tokenType = slot() - val locationReferences = slot() - - every { - getTokens( - captureNullable(dateFrom), - captureNullable(dateTo), - capture(offset), - captureNullable(limit), - captureNullable(countryCode), - captureNullable(partyId), - ) - } answers { - val capturedOffset = offset.captured - val capturedLimit = limit.captured() ?: 10 - - tokens - .filter { token -> - val dateFromFilterOk = dateFrom.captured()?.let { token.last_updated.isAfter(it) } ?: true - val dateToFilterOk = dateTo.captured()?.let { token.last_updated.isBefore(it) } ?: true - - dateFromFilterOk && dateToFilterOk - } - .filterIndexed { index: Int, _: Token -> - index >= capturedOffset - } - .take(capturedLimit) - .toSearchResult(totalCount = tokens.size, limit = capturedLimit, offset = capturedOffset) - } - - every { getToken(capture(tokenUid), capture(tokenType)) } answers { - tokens.find { it.uid == tokenUid.captured } - } - - every { postToken(capture(tokenUid), capture(tokenType), capture(locationReferences)) } answers { - tokens - .find { it.uid == tokenUid.captured } - .let { - AuthorizationInfo( - allowed = Allowed.ALLOWED, - location = locationReferences.captured, - info = null, - authorization_id = "auth_id" - ) - } - } -} diff --git a/ocpi-toolkit-2.1.1-gireve/src/test/kotlin/com/izivia/ocpi/toolkit/tests/validation/LocationsCpoValidationServiceTest.kt b/ocpi-toolkit-2.1.1-gireve/src/test/kotlin/com/izivia/ocpi/toolkit/tests/validation/LocationsCpoValidationServiceTest.kt deleted file mode 100644 index 254f0a2d..00000000 --- a/ocpi-toolkit-2.1.1-gireve/src/test/kotlin/com/izivia/ocpi/toolkit/tests/validation/LocationsCpoValidationServiceTest.kt +++ /dev/null @@ -1,323 +0,0 @@ -package com.izivia.ocpi.toolkit.tests.validation - -import com.izivia.ocpi.toolkit.common.OcpiStatus -import com.izivia.ocpi.toolkit.common.SearchResult -import com.izivia.ocpi.toolkit.modules.locations.domain.Location -import com.izivia.ocpi.toolkit.modules.locations.validation.LocationsCpoValidationService -import com.izivia.ocpi.toolkit.tests.mock.locationsCpoService -import org.junit.jupiter.api.Test -import strikt.api.expectThat -import strikt.assertions.isEqualTo -import strikt.assertions.isNotNull -import strikt.assertions.isNull -import java.time.Instant -import java.util.* - -class LocationsCpoValidationServiceTest { - private lateinit var service: LocationsCpoValidationService - private val from = Instant.parse("2022-04-28T08:00:00.000Z") - private val to = Instant.parse("2022-04-28T09:00:00.000Z") - - @Test - fun getLocationsParamsValidationTest() { - service = LocationsCpoValidationService(service = locationsCpoService(emptyList())) - - expectThat(service.getLocations(dateFrom = from, dateTo = from, offset = 0, limit = null)) { - get { status_code } - .isEqualTo(OcpiStatus.SUCCESS.code) - - get { data } - .isNotNull() - .get(SearchResult::offset) - .isEqualTo(0) - } - - expectThat(service.getLocations(dateFrom = to, dateTo = from, offset = 0, limit = null)) { - get { status_code } - .isEqualTo(OcpiStatus.CLIENT_INVALID_PARAMETERS.code) - - get { data } - .isNull() - } - - expectThat(service.getLocations(dateFrom = from, dateTo = to, offset = 0, limit = null)) { - get { status_code } - .isEqualTo(OcpiStatus.SUCCESS.code) - - get { data } - .isNotNull() - .get(SearchResult::offset) - .isEqualTo(0) - } - - expectThat(service.getLocations(dateFrom = null, dateTo = to, offset = 0, limit = null)) { - get { status_code } - .isEqualTo(OcpiStatus.SUCCESS.code) - - get { data } - .isNotNull() - .get(SearchResult::offset) - .isEqualTo(0) - } - - expectThat(service.getLocations(dateFrom = from, dateTo = null, offset = 0, limit = null)) { - get { status_code } - .isEqualTo(OcpiStatus.SUCCESS.code) - - get { data } - .isNotNull() - .get(SearchResult::offset) - .isEqualTo(0) - } - - expectThat(service.getLocations(dateFrom = null, dateTo = null, offset = 0, limit = null)) { - get { status_code } - .isEqualTo(OcpiStatus.SUCCESS.code) - - get { data } - .isNotNull() - .get(SearchResult::offset) - .isEqualTo(0) - } - - expectThat(service.getLocations(dateFrom = null, dateTo = null, offset = -10, limit = null)) { - get { status_code } - .isEqualTo(OcpiStatus.CLIENT_INVALID_PARAMETERS.code) - - get { data } - .isNull() - } - - expectThat(service.getLocations(dateFrom = null, dateTo = null, offset = 0, limit = -10)) { - get { status_code } - .isEqualTo(OcpiStatus.CLIENT_INVALID_PARAMETERS.code) - - get { data } - .isNull() - } - - expectThat(service.getLocations(dateFrom = null, dateTo = null, offset = 0, limit = 100)) { - get { status_code } - .isEqualTo(OcpiStatus.SUCCESS.code) - - get { data } - .isNotNull() - .get(SearchResult::offset) - .isEqualTo(0) - - get { data } - .isNotNull() - .get(SearchResult::limit) - .isEqualTo(100) - } - - expectThat(service.getLocations(dateFrom = null, dateTo = null, offset = 100, limit = 100)) { - get { status_code } - .isEqualTo(OcpiStatus.SUCCESS.code) - - get { data } - .isNotNull() - .get(SearchResult::offset) - .isEqualTo(100) - - get { data } - .isNotNull() - .get(SearchResult::limit) - .isEqualTo(100) - } - - expectThat(service.getLocations(dateFrom = null, dateTo = null, offset = 0, limit = 0)) { - get { status_code } - .isEqualTo(OcpiStatus.SUCCESS.code) - - get { data } - .isNotNull() - .get(SearchResult::offset) - .isEqualTo(0) - - get { data } - .isNotNull() - .get(SearchResult::limit) - .isEqualTo(0) - } - } - - @Test - fun getLocationParamsValidationTest() { - service = - LocationsCpoValidationService(service = locationsCpoService(emptyList())) - - val str3chars = "abc" - val str39chars = "abababababababababababababababababababa" - val str40chars = "abababababababababababababababababababab" - - expectThat(service.getLocation(locationId = str3chars)) { - get { status_code } - .isEqualTo(OcpiStatus.SUCCESS.code) - } - - expectThat(service.getLocation(locationId = str39chars)) { - get { status_code } - .isEqualTo(OcpiStatus.SUCCESS.code) - } - - expectThat(service.getLocation(locationId = str40chars)) { - get { status_code } - .isEqualTo(OcpiStatus.CLIENT_INVALID_PARAMETERS.code) - } - } - - @Test - fun getEvseParamsValidationTest() { - service = LocationsCpoValidationService(service = locationsCpoService(emptyList())) - - val str3chars = "abc" - val str39chars = "abababababababababababababababababababa" - val str40chars = "abababababababababababababababababababab" - - expectThat(service.getEvse(locationId = str3chars, evseUid = str3chars)) { - get { status_code } - .isEqualTo(OcpiStatus.SUCCESS.code) - } - - expectThat(service.getEvse(locationId = str39chars, evseUid = str3chars)) { - get { status_code } - .isEqualTo(OcpiStatus.SUCCESS.code) - } - - expectThat(service.getEvse(locationId = str40chars, evseUid = str3chars)) { - get { status_code } - .isEqualTo(OcpiStatus.CLIENT_INVALID_PARAMETERS.code) - } - - expectThat(service.getEvse(locationId = str3chars, evseUid = str3chars)) { - get { status_code } - .isEqualTo(OcpiStatus.SUCCESS.code) - } - - expectThat(service.getEvse(locationId = str3chars, evseUid = str39chars)) { - get { status_code } - .isEqualTo(OcpiStatus.SUCCESS.code) - } - - expectThat(service.getEvse(locationId = str3chars, evseUid = str40chars)) { - get { status_code } - .isEqualTo(OcpiStatus.CLIENT_INVALID_PARAMETERS.code) - } - - expectThat(service.getEvse(locationId = str40chars, evseUid = str40chars)) { - get { status_code } - .isEqualTo(OcpiStatus.CLIENT_INVALID_PARAMETERS.code) - } - } - - @Test - fun getConnectorParamsValidationTest() { - service = - LocationsCpoValidationService(service = locationsCpoService(emptyList())) - - val str3chars = "abc" - val str37chars = "ababababababababababababababababababa" - val str39chars = "abababababababababababababababababababa" - val str40chars = "abababababababababababababababababababab" - - expectThat( - service.getConnector( - locationId = str3chars, - evseUid = str3chars, - connectorId = str3chars - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.SUCCESS.code) - } - - expectThat( - service.getConnector( - locationId = str39chars, - evseUid = str3chars, - connectorId = str3chars - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.SUCCESS.code) - } - - expectThat( - service.getConnector( - locationId = str40chars, - evseUid = str3chars, - connectorId = str3chars - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.CLIENT_INVALID_PARAMETERS.code) - } - - expectThat( - service.getConnector( - locationId = str3chars, - evseUid = str3chars, - connectorId = str3chars - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.SUCCESS.code) - } - - expectThat( - service.getConnector( - locationId = str3chars, - evseUid = str39chars, - connectorId = str3chars - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.SUCCESS.code) - } - - expectThat( - service.getConnector( - locationId = str3chars, - evseUid = str40chars, - connectorId = str3chars - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.CLIENT_INVALID_PARAMETERS.code) - } - - expectThat( - service.getConnector( - locationId = str40chars, - evseUid = str40chars, - connectorId = str3chars - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.CLIENT_INVALID_PARAMETERS.code) - } - - expectThat( - service.getConnector( - locationId = str3chars, - evseUid = str3chars, - connectorId = str37chars - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.CLIENT_INVALID_PARAMETERS.code) - } - - expectThat( - service.getConnector( - locationId = str40chars, - evseUid = str40chars, - connectorId = str37chars - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.CLIENT_INVALID_PARAMETERS.code) - } - } -} diff --git a/ocpi-toolkit-2.1.1-gireve/src/test/kotlin/com/izivia/ocpi/toolkit/tests/validation/LocationsEmspValidationServiceTest.kt b/ocpi-toolkit-2.1.1-gireve/src/test/kotlin/com/izivia/ocpi/toolkit/tests/validation/LocationsEmspValidationServiceTest.kt deleted file mode 100644 index e2f08000..00000000 --- a/ocpi-toolkit-2.1.1-gireve/src/test/kotlin/com/izivia/ocpi/toolkit/tests/validation/LocationsEmspValidationServiceTest.kt +++ /dev/null @@ -1,732 +0,0 @@ -package com.izivia.ocpi.toolkit.tests.validation - -import com.izivia.ocpi.toolkit.common.OcpiStatus -import com.izivia.ocpi.toolkit.modules.locations.domain.toPartial -import com.izivia.ocpi.toolkit.modules.locations.validation.LocationsEmspValidationService -import com.izivia.ocpi.toolkit.samples.common.validConnector -import com.izivia.ocpi.toolkit.samples.common.validEvse -import com.izivia.ocpi.toolkit.samples.common.validLocation -import com.izivia.ocpi.toolkit.tests.mock.locationsEmspService -import org.junit.jupiter.api.Test -import strikt.api.expectThat -import strikt.assertions.isEqualTo -import java.util.* - -class LocationsEmspValidationServiceTest { - private lateinit var service: LocationsEmspValidationService - - val token = UUID.randomUUID().toString() - val str1char = "a" - val str2chars = "ab" - val str3chars = "abc" - val str4chars = "abcd" - val str36chars = "abababababababababababababababababab" - val str37chars = "ababababababababababababababababababa" - val str39chars = "abababababababababababababababababababa" - val str40chars = "abababababababababababababababababababab" - - @Test - fun getLocationParamsValidationTest() { - service = LocationsEmspValidationService(service = locationsEmspService(emptyList())) - - expectThat(service.getLocation(countryCode = str1char, partyId = str2chars, locationId = str4chars)) { - get { status_code } - .isEqualTo(OcpiStatus.SUCCESS.code) - } - - expectThat(service.getLocation(countryCode = str2chars, partyId = str3chars, locationId = str39chars)) { - get { status_code } - .isEqualTo(OcpiStatus.SUCCESS.code) - } - - expectThat(service.getLocation(countryCode = str3chars, partyId = str3chars, locationId = str39chars)) { - get { status_code } - .isEqualTo(OcpiStatus.CLIENT_INVALID_PARAMETERS.code) - } - - expectThat(service.getLocation(countryCode = str2chars, partyId = str4chars, locationId = str39chars)) { - get { status_code } - .isEqualTo(OcpiStatus.CLIENT_INVALID_PARAMETERS.code) - } - - expectThat(service.getLocation(countryCode = str2chars, partyId = str3chars, locationId = str40chars)) { - get { status_code } - .isEqualTo(OcpiStatus.CLIENT_INVALID_PARAMETERS.code) - } - } - - @Test - fun getEvseParamsValidationTest() { - service = LocationsEmspValidationService(service = locationsEmspService(emptyList())) - - expectThat( - service.getEvse( - countryCode = str1char, - partyId = str2chars, - locationId = str4chars, - evseUid = str4chars - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.SUCCESS.code) - } - - expectThat( - service.getEvse( - countryCode = str2chars, - partyId = str3chars, - locationId = str39chars, - evseUid = str39chars - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.SUCCESS.code) - } - - expectThat( - service.getEvse( - countryCode = str3chars, - partyId = str3chars, - locationId = str39chars, - evseUid = str39chars - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.CLIENT_INVALID_PARAMETERS.code) - } - - expectThat( - service.getEvse( - countryCode = str2chars, - partyId = str4chars, - locationId = str39chars, - evseUid = str39chars - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.CLIENT_INVALID_PARAMETERS.code) - } - - expectThat( - service.getEvse( - countryCode = str2chars, - partyId = str3chars, - locationId = str40chars, - evseUid = str39chars - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.CLIENT_INVALID_PARAMETERS.code) - } - - expectThat( - service.getEvse( - countryCode = str2chars, - partyId = str3chars, - locationId = str39chars, - evseUid = str40chars - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.CLIENT_INVALID_PARAMETERS.code) - } - } - - @Test - fun getConnectorParamsValidationTest() { - service = LocationsEmspValidationService(service = locationsEmspService(emptyList())) - - expectThat( - service.getConnector( - countryCode = str1char, - partyId = str2chars, - locationId = str4chars, - evseUid = str4chars, - connectorId = str4chars - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.SUCCESS.code) - } - - expectThat( - service.getConnector( - countryCode = str2chars, - partyId = str3chars, - locationId = str39chars, - evseUid = str39chars, - connectorId = str36chars - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.SUCCESS.code) - } - - expectThat( - service.getConnector( - countryCode = str3chars, - partyId = str3chars, - locationId = str39chars, - evseUid = str39chars, - connectorId = str36chars - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.CLIENT_INVALID_PARAMETERS.code) - } - - expectThat( - service.getConnector( - countryCode = str2chars, - partyId = str4chars, - locationId = str39chars, - evseUid = str39chars, - connectorId = str36chars - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.CLIENT_INVALID_PARAMETERS.code) - } - - expectThat( - service.getConnector( - countryCode = str2chars, - partyId = str3chars, - locationId = str40chars, - evseUid = str39chars, - connectorId = str36chars - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.CLIENT_INVALID_PARAMETERS.code) - } - - expectThat( - service.getConnector( - countryCode = str2chars, - partyId = str3chars, - locationId = str39chars, - evseUid = str40chars, - connectorId = str36chars - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.CLIENT_INVALID_PARAMETERS.code) - } - - expectThat( - service.getConnector( - countryCode = str2chars, - partyId = str3chars, - locationId = str39chars, - evseUid = str39chars, - connectorId = str37chars - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.CLIENT_INVALID_PARAMETERS.code) - } - } - - @Test - fun patchLocationParamsValidationTest() { - service = LocationsEmspValidationService(service = locationsEmspService(emptyList())) - - expectThat( - service.patchLocation( - countryCode = str1char, - partyId = str2chars, - locationId = str4chars, - location = validLocation.toPartial() - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.SUCCESS.code) - } - - expectThat( - service.patchLocation( - countryCode = str2chars, - partyId = str3chars, - locationId = str39chars, - location = validLocation.toPartial() - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.SUCCESS.code) - } - - expectThat( - service.patchLocation( - countryCode = str3chars, - partyId = str3chars, - locationId = str39chars, - location = validLocation.toPartial() - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.CLIENT_INVALID_PARAMETERS.code) - } - - expectThat( - service.patchLocation( - countryCode = str2chars, - partyId = str4chars, - locationId = str39chars, - location = validLocation.toPartial() - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.CLIENT_INVALID_PARAMETERS.code) - } - - expectThat( - service.patchLocation( - countryCode = str2chars, - partyId = str3chars, - locationId = str40chars, - location = validLocation.toPartial() - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.CLIENT_INVALID_PARAMETERS.code) - } - } - - @Test - fun patchEvseParamsValidationTest() { - service = LocationsEmspValidationService(service = locationsEmspService(emptyList())) - - expectThat( - service.patchEvse( - countryCode = str1char, - partyId = str2chars, - locationId = str4chars, - evseUid = str4chars, - evse = validEvse.toPartial() - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.SUCCESS.code) - } - - expectThat( - service.patchEvse( - countryCode = str2chars, - partyId = str3chars, - locationId = str39chars, - evseUid = str39chars, - evse = validEvse.toPartial() - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.SUCCESS.code) - } - - expectThat( - service.patchEvse( - countryCode = str3chars, - partyId = str3chars, - locationId = str39chars, - evseUid = str39chars, - evse = validEvse.toPartial() - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.CLIENT_INVALID_PARAMETERS.code) - } - - expectThat( - service.patchEvse( - countryCode = str2chars, - partyId = str4chars, - locationId = str39chars, - evseUid = str39chars, - evse = validEvse.toPartial() - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.CLIENT_INVALID_PARAMETERS.code) - } - - expectThat( - service.patchEvse( - countryCode = str2chars, - partyId = str3chars, - locationId = str40chars, - evseUid = str39chars, - evse = validEvse.toPartial() - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.CLIENT_INVALID_PARAMETERS.code) - } - - expectThat( - service.patchEvse( - countryCode = str2chars, - partyId = str3chars, - locationId = str39chars, - evseUid = str40chars, - evse = validEvse.toPartial() - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.CLIENT_INVALID_PARAMETERS.code) - } - } - - @Test - fun patchConnectorParamsValidationTest() { - service = LocationsEmspValidationService(service = locationsEmspService(emptyList())) - - expectThat( - service.patchConnector( - countryCode = str1char, - partyId = str2chars, - locationId = str4chars, - evseUid = str4chars, - connectorId = str4chars, - connector = validConnector.toPartial() - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.SUCCESS.code) - } - - expectThat( - service.patchConnector( - countryCode = str2chars, - partyId = str3chars, - locationId = str39chars, - evseUid = str39chars, - connectorId = str36chars, - connector = validConnector.toPartial() - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.SUCCESS.code) - } - - expectThat( - service.patchConnector( - countryCode = str3chars, - partyId = str3chars, - locationId = str39chars, - evseUid = str39chars, - connectorId = str36chars, - connector = validConnector.toPartial() - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.CLIENT_INVALID_PARAMETERS.code) - } - - expectThat( - service.patchConnector( - countryCode = str2chars, - partyId = str4chars, - locationId = str39chars, - evseUid = str39chars, - connectorId = str36chars, - connector = validConnector.toPartial() - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.CLIENT_INVALID_PARAMETERS.code) - } - - expectThat( - service.patchConnector( - countryCode = str2chars, - partyId = str3chars, - locationId = str40chars, - evseUid = str39chars, - connectorId = str36chars, - connector = validConnector.toPartial() - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.CLIENT_INVALID_PARAMETERS.code) - } - - expectThat( - service.patchConnector( - countryCode = str2chars, - partyId = str3chars, - locationId = str39chars, - evseUid = str40chars, - connectorId = str36chars, - connector = validConnector.toPartial() - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.CLIENT_INVALID_PARAMETERS.code) - } - - expectThat( - service.patchConnector( - countryCode = str2chars, - partyId = str3chars, - locationId = str39chars, - evseUid = str39chars, - connectorId = str37chars, - connector = validConnector.toPartial() - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.CLIENT_INVALID_PARAMETERS.code) - } - } - - @Test - fun putLocationParamsValidationTest() { - service = LocationsEmspValidationService(service = locationsEmspService(emptyList())) - - expectThat( - service.putLocation( - countryCode = str1char, - partyId = str2chars, - locationId = str4chars, - location = validLocation - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.SUCCESS.code) - } - - expectThat( - service.putLocation( - countryCode = str2chars, - partyId = str3chars, - locationId = str39chars, - location = validLocation - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.SUCCESS.code) - } - - expectThat( - service.putLocation( - countryCode = str3chars, - partyId = str3chars, - locationId = str39chars, - location = validLocation - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.CLIENT_INVALID_PARAMETERS.code) - } - - expectThat( - service.putLocation( - countryCode = str2chars, - partyId = str4chars, - locationId = str39chars, - location = validLocation - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.CLIENT_INVALID_PARAMETERS.code) - } - - expectThat( - service.putLocation( - countryCode = str2chars, - partyId = str3chars, - locationId = str40chars, - location = validLocation - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.CLIENT_INVALID_PARAMETERS.code) - } - } - - @Test - fun putEvseParamsValidationTest() { - service = LocationsEmspValidationService(service = locationsEmspService(emptyList())) - - expectThat( - service.putEvse( - countryCode = str1char, - partyId = str2chars, - locationId = str4chars, - evseUid = str4chars, - evse = validEvse - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.SUCCESS.code) - } - - expectThat( - service.putEvse( - countryCode = str2chars, - partyId = str3chars, - locationId = str39chars, - evseUid = str39chars, - evse = validEvse - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.SUCCESS.code) - } - - expectThat( - service.putEvse( - countryCode = str3chars, - partyId = str3chars, - locationId = str39chars, - evseUid = str39chars, - evse = validEvse - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.CLIENT_INVALID_PARAMETERS.code) - } - - expectThat( - service.putEvse( - countryCode = str2chars, - partyId = str4chars, - locationId = str39chars, - evseUid = str39chars, - evse = validEvse - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.CLIENT_INVALID_PARAMETERS.code) - } - - expectThat( - service.putEvse( - countryCode = str2chars, - partyId = str3chars, - locationId = str40chars, - evseUid = str39chars, - evse = validEvse - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.CLIENT_INVALID_PARAMETERS.code) - } - - expectThat( - service.putEvse( - countryCode = str2chars, - partyId = str3chars, - locationId = str39chars, - evseUid = str40chars, - evse = validEvse - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.CLIENT_INVALID_PARAMETERS.code) - } - } - - @Test - fun putConnectorParamsValidationTest() { - service = LocationsEmspValidationService(service = locationsEmspService(emptyList())) - - expectThat( - service.putConnector( - countryCode = str1char, - partyId = str2chars, - locationId = str4chars, - evseUid = str4chars, - connectorId = str4chars, - connector = validConnector - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.SUCCESS.code) - } - - expectThat( - service.putConnector( - countryCode = str2chars, - partyId = str3chars, - locationId = str39chars, - evseUid = str39chars, - connectorId = str36chars, - connector = validConnector - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.SUCCESS.code) - } - - expectThat( - service.putConnector( - countryCode = str3chars, - partyId = str3chars, - locationId = str39chars, - evseUid = str39chars, - connectorId = str36chars, - connector = validConnector - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.CLIENT_INVALID_PARAMETERS.code) - } - - expectThat( - service.putConnector( - countryCode = str2chars, - partyId = str4chars, - locationId = str39chars, - evseUid = str39chars, - connectorId = str36chars, - connector = validConnector - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.CLIENT_INVALID_PARAMETERS.code) - } - - expectThat( - service.putConnector( - countryCode = str2chars, - partyId = str3chars, - locationId = str40chars, - evseUid = str39chars, - connectorId = str36chars, - connector = validConnector - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.CLIENT_INVALID_PARAMETERS.code) - } - - expectThat( - service.putConnector( - countryCode = str2chars, - partyId = str3chars, - locationId = str39chars, - evseUid = str40chars, - connectorId = str36chars, - connector = validConnector - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.CLIENT_INVALID_PARAMETERS.code) - } - - expectThat( - service.putConnector( - countryCode = str2chars, - partyId = str3chars, - locationId = str39chars, - evseUid = str39chars, - connectorId = str37chars, - connector = validConnector - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.CLIENT_INVALID_PARAMETERS.code) - } - } -} diff --git a/ocpi-toolkit-2.1.1-gireve/src/test/kotlin/com/izivia/ocpi/toolkit/tests/validation/LocationsValidatorTest.kt b/ocpi-toolkit-2.1.1-gireve/src/test/kotlin/com/izivia/ocpi/toolkit/tests/validation/LocationsValidatorTest.kt deleted file mode 100644 index caef6f1e..00000000 --- a/ocpi-toolkit-2.1.1-gireve/src/test/kotlin/com/izivia/ocpi/toolkit/tests/validation/LocationsValidatorTest.kt +++ /dev/null @@ -1,574 +0,0 @@ -package com.izivia.ocpi.toolkit.tests.validation - -import com.izivia.ocpi.toolkit.modules.locations.domain.* -import com.izivia.ocpi.toolkit.modules.locations.validation.validate -import com.izivia.ocpi.toolkit.samples.common.* -import org.junit.jupiter.api.Test -import strikt.api.expectCatching -import strikt.assertions.isFailure -import strikt.assertions.isSuccess -import java.math.BigDecimal -import kotlin.random.Random - -class LocationsValidatorTest { - - private fun generateRandomString(length: Int): String = (('a'..'z') + ('A'..'Z')) - .let { chars -> - (0 until length) - .map { chars[Random.nextInt(chars.size)] } - .joinToString("") - } - - @Test - fun `Location validator`() { - expectCatching { - validLocation.validate() - }.isSuccess() - - expectCatching { - validLocation.copy(id = generateRandomString(40)).validate() - }.isFailure() - - expectCatching { - validLocation.copy(name = generateRandomString(256)).validate() - }.isFailure() - - expectCatching { - validLocation.copy(address = generateRandomString(46)).validate() - }.isFailure() - - expectCatching { - validLocation.copy(city = generateRandomString(46)).validate() - }.isFailure() - - expectCatching { - validLocation.copy(postal_code = generateRandomString(11)).validate() - }.isFailure() - - expectCatching { - validLocation.copy(country = generateRandomString(4)).validate() - }.isFailure() - - expectCatching { - validLocation.copy(country = "fra").validate() - }.isFailure() - - expectCatching { - validLocation.copy(time_zone = generateRandomString(256)).validate() - }.isFailure() - - expectCatching { - validLocation.copy(time_zone = "EuropeOslo").validate() - }.isFailure() - } - - @Test - fun `Evse validator`() { - expectCatching { - validEvse.validate() - }.isSuccess() - - expectCatching { - validEvse.copy(evse_id = "FR*A23*E45B*78C").validate() - }.isSuccess() - - expectCatching { - validEvse.copy(evse_id = "fr*a23*e45b*78c").validate() - }.isSuccess() - - expectCatching { - validEvse.copy(evse_id = "FRA23E45B78C").validate() - }.isSuccess() - - expectCatching { - validEvse.copy(evse_id = "FRA23E45B*78C").validate() - }.isSuccess() - - expectCatching { - validEvse.copy(evse_id = "FR*A23*E${generateRandomString(31)}").validate() - }.isSuccess() - - expectCatching { - validEvse.copy(evse_id = "F*A23*E45B*78C").validate() - }.isFailure() - - expectCatching { - validEvse.copy(evse_id = "FR*A2*E45B*78C").validate() - }.isFailure() - - expectCatching { - validEvse.copy(evse_id = "FR*A23*A45B*78C").validate() - }.isFailure() - - expectCatching { - validEvse.copy(evse_id = "FR*A23*E").validate() - }.isFailure() - - expectCatching { - validEvse.copy(evse_id = "FR*A23*E${generateRandomString(32)}").validate() - }.isFailure() - - expectCatching { - validEvse.copy(uid = generateRandomString(40)).validate() - }.isFailure() - - expectCatching { - validEvse.copy(floor_level = generateRandomString(5)).validate() - }.isFailure() - - expectCatching { - validEvse.copy(physical_reference = generateRandomString(17)).validate() - }.isFailure() - } - - @Test - fun `Connector validator`() { - expectCatching { - validConnector.validate() - validConnector.copy(voltage = 0).validate() - validConnector.copy(amperage = 0).validate() - }.isSuccess() - - expectCatching { - validConnector.copy(id = generateRandomString(37)).validate() - }.isFailure() - - expectCatching { - validConnector.copy(voltage = -1).validate() - }.isFailure() - - expectCatching { - validConnector.copy(amperage = -1).validate() - }.isFailure() - - expectCatching { - validConnector.copy(tariff_id = generateRandomString(37)).validate() - }.isFailure() - - expectCatching { - validConnector.copy(terms_and_conditions = "not an url").validate() - }.isFailure() - } - - @Test - fun `GeoLocation validator`() { - expectCatching { - GeoLocation( - "1.55", - "2.15" - ).validate() - }.isFailure() - - expectCatching { - GeoLocation( - "1.123456", - "2111.123456" - ).validate() - }.isFailure() - - expectCatching { - GeoLocation( - "111.123456", - "21.123456" - ).validate() - }.isFailure() - - expectCatching { - GeoLocation( - "-111.123456", - "21.123456" - ).validate() - }.isFailure() - - expectCatching { - GeoLocation( - "1.123456", - ".123456" - ).validate() - }.isFailure() - - expectCatching { - GeoLocation( - "1.123456", - "-.123456" - ).validate() - }.isFailure() - - expectCatching { - GeoLocation( - "1.123456", - "-1111.123456" - ).validate() - }.isFailure() - - expectCatching { - GeoLocation( - "101.123456", - "2.123456" - ).validate() - }.isFailure() - - expectCatching { - validGeoLocation.validate() - - GeoLocation( - "1.123456", - "2.123456" - ).validate() - - GeoLocation( - "-5.123456", - "12.123456" - ).validate() - - GeoLocation( - "1.123456", - "-2.123456" - ).validate() - - GeoLocation( - "-1.123456", - "-2.123456" - ).validate() - - GeoLocation( - "-1.123456", - "-211.123456" - ).validate() - }.isSuccess() - } - - @Test - fun `EnvironmentalImpact validator`() { - expectCatching { - EnvironmentalImpact( - source = EnvironmentalImpactCategory.CARBON_DIOXIDE, - amount = BigDecimal(0.0) - ).validate() - - EnvironmentalImpact( - source = EnvironmentalImpactCategory.CARBON_DIOXIDE, - amount = BigDecimal(1.0) - ).validate() - - EnvironmentalImpact( - source = EnvironmentalImpactCategory.CARBON_DIOXIDE, - amount = BigDecimal(12.0) - ).validate() - - EnvironmentalImpact( - source = EnvironmentalImpactCategory.CARBON_DIOXIDE, - amount = BigDecimal(12.1234) - ).validate() - }.isSuccess() - - expectCatching { - EnvironmentalImpact( - source = EnvironmentalImpactCategory.CARBON_DIOXIDE, - amount = BigDecimal(-0.1) - ).validate() - }.isFailure() - - expectCatching { - EnvironmentalImpact( - source = EnvironmentalImpactCategory.CARBON_DIOXIDE, - amount = BigDecimal(-10) - ).validate() - }.isFailure() - } - - @Test - fun `EnergySource validator`() { - expectCatching { - EnergySource( - source = EnergySourceCategory.NUCLEAR, - percentage = BigDecimal(0.0) - ).validate() - - EnergySource( - source = EnergySourceCategory.NUCLEAR, - percentage = BigDecimal(1.0) - ).validate() - - EnergySource( - source = EnergySourceCategory.NUCLEAR, - percentage = BigDecimal(12.0) - ).validate() - - EnergySource( - source = EnergySourceCategory.NUCLEAR, - percentage = BigDecimal(12.1234) - ).validate() - - EnergySource( - source = EnergySourceCategory.NUCLEAR, - percentage = BigDecimal(100.00) - ).validate() - }.isSuccess() - - expectCatching { - EnergySource( - source = EnergySourceCategory.NUCLEAR, - percentage = BigDecimal(-0.1) - ).validate() - }.isFailure() - - expectCatching { - EnergySource( - source = EnergySourceCategory.NUCLEAR, - percentage = BigDecimal(-10) - ).validate() - }.isFailure() - - expectCatching { - EnergySource( - source = EnergySourceCategory.NUCLEAR, - percentage = BigDecimal(100.1) - ).validate() - }.isFailure() - - expectCatching { - EnergySource( - source = EnergySourceCategory.NUCLEAR, - percentage = BigDecimal(101) - ).validate() - }.isFailure() - } - - @Test - fun `EnergyMix validator`() { - expectCatching { - validEnergyMix.validate() - }.isSuccess() - - expectCatching { - validEnergyMix.copy(supplier_name = generateRandomString(65)).validate() - }.isFailure() - - expectCatching { - validEnergyMix.copy(energy_product_name = generateRandomString(65)).validate() - }.isFailure() - } - - @Test - fun `ExceptionalPeriod validator`() { - expectCatching { - validExceptionalPeriod.validate() - - validExceptionalPeriod.copy( - period_begin = validExceptionalPeriod.period_begin, - period_end = validExceptionalPeriod.period_begin - ).validate() - }.isSuccess() - - expectCatching { - validExceptionalPeriod.copy( - period_begin = validExceptionalPeriod.period_end, - period_end = validExceptionalPeriod.period_begin - ).validate() - }.isFailure() - } - - @Test - fun `RegularHours validator`() { - expectCatching { - validRegularHours.validate() - - validRegularHours.copy( - period_begin = validRegularHours.period_begin, - period_end = validRegularHours.period_begin - ).validate() - }.isSuccess() - - expectCatching { - validRegularHours.copy( - period_begin = validRegularHours.period_end, - period_end = validRegularHours.period_begin - ).validate() - }.isFailure() - - expectCatching { - validRegularHours.copy( - weekday = 0 - ).validate() - }.isFailure() - - expectCatching { - validRegularHours.copy( - weekday = 8 - ).validate() - }.isFailure() - - expectCatching { - validRegularHours.copy( - period_begin = "1:00" - ).validate() - }.isFailure() - - expectCatching { - validRegularHours.copy( - period_begin = "00:1" - ).validate() - }.isFailure() - - expectCatching { - validRegularHours.copy( - period_begin = "0010" - ).validate() - }.isFailure() - } - - @Test - fun `Hours validator`() { - expectCatching { - validHours.validate() - - validHours.copy( - regular_hours = null, - twenty_four_seven = true - ).validate() - - validHours.copy( - exceptional_openings = emptyList(), - exceptional_closings = emptyList() - ).validate() - }.isSuccess() - - expectCatching { - validHours.toPartial().validate() - - // This fails when not partial, but does not when partial - validHours.toPartial().copy(regular_hours = null, twenty_four_seven = null).validate() - }.isSuccess() - - expectCatching { - validHours.copy( - regular_hours = listOf(validRegularHours), - twenty_four_seven = true - ).toPartial().validate() - }.isFailure() - - expectCatching { - validHours.copy( - regular_hours = listOf(validRegularHours), - twenty_four_seven = true - ).validate() - }.isFailure() - - expectCatching { - validHours.copy( - regular_hours = null, - twenty_four_seven = null - ).validate() - }.isFailure() - } - - @Test - fun `Image validator`() { - expectCatching { - validImage.validate() - }.isSuccess() - - expectCatching { - validImage.copy(width = 123456).validate() - }.isFailure() - - expectCatching { - validImage.copy(height = 123456).validate() - }.isFailure() - - expectCatching { - validImage.copy(type = "abcde").validate() - }.isFailure() - - expectCatching { - validImage.copy(url = "not an url").validate() - }.isFailure() - - expectCatching { - validImage.copy(thumbnail = "not an url").validate() - }.isFailure() - } - - @Test - fun `BusinessDetails validator`() { - expectCatching { - validBusinessDetails.validate() - validBusinessDetails.copy(website = null).validate() - validBusinessDetails.copy(logo = null).validate() - }.isSuccess() - - expectCatching { - validBusinessDetails.copy(name = generateRandomString(101)).validate() - }.isFailure() - - expectCatching { - validBusinessDetails.copy(website = "not an url").validate() - }.isFailure() - } - - @Test - fun `AdditionalGeoLocation validator`() { - expectCatching { - validAdditionalGeoLocation.validate() - validAdditionalGeoLocation.copy(longitude = "123.123456").validate() - validAdditionalGeoLocation.copy(longitude = "-123.123456").validate() - validAdditionalGeoLocation.copy(latitude = "-13.123456").validate() - validAdditionalGeoLocation.copy(latitude = "13.123456").validate() - }.isSuccess() - - expectCatching { - validAdditionalGeoLocation.copy(latitude = "1.55").validate() - }.isFailure() - - expectCatching { - validAdditionalGeoLocation.copy(longitude = "1.55").validate() - }.isFailure() - - expectCatching { - validAdditionalGeoLocation.copy(longitude = "1111.55").validate() - }.isFailure() - - expectCatching { - validAdditionalGeoLocation.copy(latitude = "111.55").validate() - }.isFailure() - } - - @Test - fun `DisplayText validator`() { - expectCatching { - validDisplayText.validate() - }.isSuccess() - - expectCatching { - validDisplayText.copy(language = "fra").validate() - }.isFailure() - - expectCatching { - validDisplayText.copy(text = generateRandomString(513)).validate() - }.isFailure() - - expectCatching { - validDisplayText.copy(text = "no html!").validate() - }.isFailure() - } - - @Test - fun `StatusSchedule validator`() { - expectCatching { - validStatusSchedule.validate() - validStatusSchedule.copy( - period_begin = validStatusSchedule.period_begin, - period_end = validStatusSchedule.period_begin, - ).validate() - validStatusSchedule.copy(period_end = null).validate() - }.isSuccess() - - expectCatching { - validStatusSchedule.copy( - period_begin = validStatusSchedule.period_end!!, - period_end = validStatusSchedule.period_begin, - ).validate() - }.isFailure() - } -} \ No newline at end of file diff --git a/ocpi-toolkit-2.1.1-gireve/src/test/kotlin/com/izivia/ocpi/toolkit/tests/validation/TokensCpoValidationServiceTest.kt b/ocpi-toolkit-2.1.1-gireve/src/test/kotlin/com/izivia/ocpi/toolkit/tests/validation/TokensCpoValidationServiceTest.kt deleted file mode 100644 index 7e8d9350..00000000 --- a/ocpi-toolkit-2.1.1-gireve/src/test/kotlin/com/izivia/ocpi/toolkit/tests/validation/TokensCpoValidationServiceTest.kt +++ /dev/null @@ -1,170 +0,0 @@ -package com.izivia.ocpi.toolkit.tests.validation - -import com.izivia.ocpi.toolkit.common.OcpiStatus -import com.izivia.ocpi.toolkit.modules.tokens.domain.toPartial -import com.izivia.ocpi.toolkit.modules.tokens.validation.TokensCpoValidationService -import com.izivia.ocpi.toolkit.samples.common.validToken -import com.izivia.ocpi.toolkit.tests.mock.tokensCpoService -import org.junit.jupiter.api.Test -import strikt.api.expectThat -import strikt.assertions.isEqualTo - -class TokensCpoValidationServiceTest { - private lateinit var service: TokensCpoValidationService - private val str40chars = "abababababababababababababababababababab" - - @Test - fun getTokenParamsValidationTest() { - service = TokensCpoValidationService(service = tokensCpoService(mutableListOf())) - - expectThat( - service.getToken( - countryCode = "FR", - partyId = "ABC", - tokenUid = validToken.uid - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.SUCCESS.code) - } - - expectThat( - service.getToken( - countryCode = "FRx", - partyId = "ABC", - tokenUid = validToken.uid - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.CLIENT_INVALID_PARAMETERS.code) - } - - expectThat( - service.getToken( - countryCode = "FR", - partyId = "ABCx", - tokenUid = validToken.uid - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.CLIENT_INVALID_PARAMETERS.code) - } - - expectThat( - service.getToken( - countryCode = "FR", - partyId = "ABC", - tokenUid = str40chars - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.CLIENT_INVALID_PARAMETERS.code) - } - } - - @Test - fun putTokenParamsValidationTest() { - service = TokensCpoValidationService(service = tokensCpoService(mutableListOf())) - - expectThat( - service.putToken( - countryCode = "FR", - partyId = "ABC", - tokenUid = validToken.uid, - token = validToken - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.SUCCESS.code) - } - - expectThat( - service.putToken( - countryCode = "FRx", - partyId = "ABC", - tokenUid = validToken.uid, - token = validToken - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.CLIENT_INVALID_PARAMETERS.code) - } - - expectThat( - service.putToken( - countryCode = "FR", - partyId = "ABCx", - tokenUid = validToken.uid, - token = validToken - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.CLIENT_INVALID_PARAMETERS.code) - } - - expectThat( - service.putToken( - countryCode = "FR", - partyId = "ABC", - tokenUid = str40chars, - token = validToken - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.CLIENT_INVALID_PARAMETERS.code) - } - } - - @Test - fun patchTokenParamsValidationTest() { - service = TokensCpoValidationService(service = tokensCpoService(mutableListOf(validToken))) - - expectThat( - service.patchToken( - countryCode = "FR", - partyId = "ABC", - tokenUid = validToken.uid, - token = validToken.toPartial() - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.SUCCESS.code) - } - - expectThat( - service.patchToken( - countryCode = "FRx", - partyId = "ABC", - tokenUid = validToken.uid, - token = validToken.toPartial() - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.CLIENT_INVALID_PARAMETERS.code) - } - - expectThat( - service.patchToken( - countryCode = "FR", - partyId = "ABCx", - tokenUid = validToken.uid, - token = validToken.toPartial() - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.CLIENT_INVALID_PARAMETERS.code) - } - - expectThat( - service.patchToken( - countryCode = "FR", - partyId = "ABC", - tokenUid = str40chars, - token = validToken.toPartial() - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.CLIENT_INVALID_PARAMETERS.code) - } - } -} diff --git a/ocpi-toolkit-2.1.1-gireve/src/test/kotlin/com/izivia/ocpi/toolkit/tests/validation/TokensEmspValidationServiceTest.kt b/ocpi-toolkit-2.1.1-gireve/src/test/kotlin/com/izivia/ocpi/toolkit/tests/validation/TokensEmspValidationServiceTest.kt deleted file mode 100644 index af73501e..00000000 --- a/ocpi-toolkit-2.1.1-gireve/src/test/kotlin/com/izivia/ocpi/toolkit/tests/validation/TokensEmspValidationServiceTest.kt +++ /dev/null @@ -1,414 +0,0 @@ -package com.izivia.ocpi.toolkit.tests.validation - -import com.izivia.ocpi.toolkit.common.OcpiStatus -import com.izivia.ocpi.toolkit.common.SearchResult -import com.izivia.ocpi.toolkit.modules.tokens.domain.LocationReferences -import com.izivia.ocpi.toolkit.modules.tokens.domain.Token -import com.izivia.ocpi.toolkit.modules.tokens.domain.TokenType -import com.izivia.ocpi.toolkit.modules.tokens.validation.TokensEmspValidationService -import com.izivia.ocpi.toolkit.samples.common.* -import com.izivia.ocpi.toolkit.tests.mock.tokensEmspService -import org.junit.jupiter.api.Test -import strikt.api.expectThat -import strikt.assertions.isEqualTo -import strikt.assertions.isNotNull -import strikt.assertions.isNull -import java.time.Instant -import java.util.* - -class TokensEmspValidationServiceTest { - private lateinit var service: TokensEmspValidationService - private val from = Instant.parse("2022-04-28T08:00:00.000Z") - private val to = Instant.parse("2022-04-28T09:00:00.000Z") - private val str37chars = "ababababababababababababababababababa" - private val str40chars = "abababababababababababababababababababab" - - @Test - fun getTokensParamsValidationTest() { - service = TokensEmspValidationService(service = tokensEmspService(emptyList())) - - expectThat( - service.getTokens( - dateFrom = from, - dateTo = from, - offset = 0, - limit = null, - countryCode = null, - partyId = null - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.SUCCESS.code) - - get { data } - .isNotNull() - .get(SearchResult::offset) - .isEqualTo(0) - } - - expectThat( - service.getTokens( - dateFrom = to, - dateTo = from, - offset = 0, - limit = null, - countryCode = null, - partyId = null - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.CLIENT_INVALID_PARAMETERS.code) - - get { data } - .isNull() - } - - expectThat( - service.getTokens( - dateFrom = from, - dateTo = to, - offset = 0, - limit = null, - countryCode = null, - partyId = null - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.SUCCESS.code) - - get { data } - .isNotNull() - .get(SearchResult::offset) - .isEqualTo(0) - } - - expectThat( - service.getTokens( - dateFrom = null, - dateTo = to, - offset = 0, - limit = null, - countryCode = null, - partyId = null - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.SUCCESS.code) - - get { data } - .isNotNull() - .get(SearchResult::offset) - .isEqualTo(0) - } - - expectThat( - service.getTokens( - dateFrom = from, - dateTo = null, - offset = 0, - limit = null, - countryCode = null, - partyId = null - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.SUCCESS.code) - - get { data } - .isNotNull() - .get(SearchResult::offset) - .isEqualTo(0) - } - - expectThat( - service.getTokens( - dateFrom = null, - dateTo = null, - offset = 0, - limit = null, - countryCode = null, - partyId = null - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.SUCCESS.code) - - get { data } - .isNotNull() - .get(SearchResult::offset) - .isEqualTo(0) - } - - expectThat( - service.getTokens( - dateFrom = null, - dateTo = null, - offset = -10, - limit = null, - countryCode = null, - partyId = null - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.CLIENT_INVALID_PARAMETERS.code) - - get { data } - .isNull() - } - - expectThat( - service.getTokens( - dateFrom = null, - dateTo = null, - offset = 0, - limit = -10, - countryCode = null, - partyId = null - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.CLIENT_INVALID_PARAMETERS.code) - - get { data } - .isNull() - } - - expectThat( - service.getTokens( - dateFrom = null, - dateTo = null, - offset = 0, - limit = 100, - countryCode = null, - partyId = null - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.SUCCESS.code) - - get { data } - .isNotNull() - .get(SearchResult::offset) - .isEqualTo(0) - - get { data } - .isNotNull() - .get(SearchResult::limit) - .isEqualTo(100) - } - - expectThat( - service.getTokens( - dateFrom = null, - dateTo = null, - offset = 100, - limit = 100, - countryCode = null, - partyId = null - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.SUCCESS.code) - - get { data } - .isNotNull() - .get(SearchResult::offset) - .isEqualTo(100) - - get { data } - .isNotNull() - .get(SearchResult::limit) - .isEqualTo(100) - } - - expectThat( - service.getTokens( - dateFrom = null, - dateTo = null, - offset = 0, - limit = 0, - countryCode = "fr", - partyId = "abc" - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.SUCCESS.code) - - get { data } - .isNotNull() - .get(SearchResult::offset) - .isEqualTo(0) - - get { data } - .isNotNull() - .get(SearchResult::limit) - .isEqualTo(0) - } - - expectThat( - service.getTokens( - dateFrom = null, - dateTo = null, - offset = 0, - limit = 0, - countryCode = "frx", - partyId = "abc" - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.CLIENT_INVALID_PARAMETERS.code) - } - - expectThat( - service.getTokens( - dateFrom = null, - dateTo = null, - offset = 0, - limit = 0, - countryCode = "fr", - partyId = "abcx" - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.CLIENT_INVALID_PARAMETERS.code) - } - } - - @Test - fun getTokenParamsValidationTest() { - service = TokensEmspValidationService(service = tokensEmspService(emptyList())) - - expectThat( - service.getToken( - tokenUid = validToken.uid, - tokenType = TokenType.RFID - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.SUCCESS.code) - } - - expectThat( - service.getToken( - tokenUid = str37chars, - tokenType = TokenType.RFID - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.CLIENT_INVALID_PARAMETERS.code) - } - } - - @Test - fun postTokenParamsValidationTest() { - service = TokensEmspValidationService(service = tokensEmspService(emptyList())) - - expectThat( - service.postToken( - tokenUid = validToken.uid, - tokenType = TokenType.RFID, - locationReferences = validLocationReferences - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.SUCCESS.code) - } - - expectThat( - service.postToken( - tokenUid = validToken.uid, - tokenType = TokenType.RFID, - locationReferences = validLocationReferences - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.SUCCESS.code) - } - - expectThat( - service.postToken( - tokenUid = str37chars, - tokenType = TokenType.RFID, - locationReferences = validLocationReferences - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.CLIENT_INVALID_PARAMETERS.code) - } - - expectThat( - service.postToken( - tokenUid = validToken.uid, - tokenType = TokenType.RFID, - locationReferences = LocationReferences( - location_id = str40chars, - evse_uids = listOf(validEvse.uid), - connector_ids = emptyList() - ) - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.CLIENT_INVALID_PARAMETERS.code) - } - - expectThat( - service.postToken( - tokenUid = validToken.uid, - tokenType = TokenType.RFID, - locationReferences = LocationReferences( - location_id = validLocation.id, - evse_uids = listOf(str40chars), - connector_ids = emptyList() - ) - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.CLIENT_INVALID_PARAMETERS.code) - } - - expectThat( - service.postToken( - tokenUid = validToken.uid, - tokenType = TokenType.RFID, - locationReferences = LocationReferences( - location_id = validLocation.id, - evse_uids = listOf(validEvse.uid), - connector_ids = listOf(str40chars) - ) - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.CLIENT_INVALID_PARAMETERS.code) - } - - expectThat( - service.postToken( - tokenUid = validToken.uid, - tokenType = TokenType.RFID, - locationReferences = LocationReferences( - location_id = validLocation.id, - evse_uids = listOf(validEvse.uid, validEvse.uid), - connector_ids = listOf(validConnector.id) - ) - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.CLIENT_INVALID_PARAMETERS.code) - } - - expectThat( - service.postToken( - tokenUid = validToken.uid, - tokenType = TokenType.RFID, - locationReferences = LocationReferences( - location_id = validLocation.id, - evse_uids = emptyList(), - connector_ids = emptyList() - ) - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.CLIENT_NOT_ENOUGH_INFORMATION.code) - } - } -} diff --git a/ocpi-toolkit-2.1.1-gireve/src/test/kotlin/com/izivia/ocpi/toolkit/tests/validation/TokensValidatorTest.kt b/ocpi-toolkit-2.1.1-gireve/src/test/kotlin/com/izivia/ocpi/toolkit/tests/validation/TokensValidatorTest.kt deleted file mode 100644 index df8de816..00000000 --- a/ocpi-toolkit-2.1.1-gireve/src/test/kotlin/com/izivia/ocpi/toolkit/tests/validation/TokensValidatorTest.kt +++ /dev/null @@ -1,68 +0,0 @@ -package com.izivia.ocpi.toolkit.tests.validation - -import com.izivia.ocpi.toolkit.modules.tokens.validation.validate -import com.izivia.ocpi.toolkit.samples.common.validLocationReferences -import com.izivia.ocpi.toolkit.samples.common.validToken -import org.junit.jupiter.api.Test -import strikt.api.expectCatching -import strikt.assertions.isFailure -import strikt.assertions.isSuccess -import kotlin.random.Random - -class TokensValidatorTest { - - private fun generateRandomString(length: Int): String = (('a'..'z') + ('A'..'Z')) - .let { chars -> - (0 until length) - .map { chars[Random.nextInt(chars.size)] } - .joinToString("") - } - - @Test - fun `Token validator`() { - expectCatching { - validToken.validate() - }.isSuccess() - - expectCatching { - validToken.copy(uid = generateRandomString(37)).validate() - }.isFailure() - - expectCatching { - validToken.copy(auth_id = generateRandomString(37)).validate() - }.isFailure() - - expectCatching { - validToken.copy(visual_number = generateRandomString(65)).validate() - }.isFailure() - - expectCatching { - validToken.copy(issuer = generateRandomString(65)).validate() - }.isFailure() - } - - @Test - fun `LocationReferences validator`() { - expectCatching { - validLocationReferences.validate() - }.isSuccess() - - expectCatching { - validLocationReferences - .copy(location_id = generateRandomString(40)) - .validate() - }.isFailure() - - expectCatching { - validLocationReferences - .copy(evse_uids = listOf(generateRandomString(40))) - .validate() - }.isFailure() - - expectCatching { - validLocationReferences - .copy(connector_ids = listOf(generateRandomString(40))) - .validate() - }.isFailure() - } -} diff --git a/ocpi-toolkit-2.1.1/build.gradle.kts b/ocpi-toolkit-2.1.1/build.gradle.kts deleted file mode 100644 index 3961b8e7..00000000 --- a/ocpi-toolkit-2.1.1/build.gradle.kts +++ /dev/null @@ -1,63 +0,0 @@ -plugins { - id("com.izivia.ocpi.toolkit.processor") -} - -dependencies { - implementation(project(":common")) - api(project(":transport")) - - api("org.apache.logging.log4j:log4j-api:${Versions.log4j}") - api("org.apache.logging.log4j:log4j-core:${Versions.log4j}") - - implementation("com.fasterxml.jackson.module:jackson-module-kotlin:${Versions.jackson}") - implementation("com.fasterxml.jackson.datatype:jackson-datatype-jsr310:${Versions.jackson}") - implementation("org.valiktor:valiktor-core:${Versions.valiktor}") - implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:${Versions.coroutines}") - - testImplementation(http4k("core")) - testImplementation(http4k("contract")) - testImplementation(http4k("client-jetty")) - testImplementation(http4k("server-netty")) - - testImplementation("org.junit.jupiter:junit-jupiter:${Versions.junit}") - testImplementation("io.strikt:strikt-core:${Versions.strikt}") - testImplementation("io.mockk:mockk:${Versions.mockk}") - - testImplementation("org.testcontainers:testcontainers:${Versions.testcontainers}") - testImplementation("org.testcontainers:junit-jupiter:${Versions.testcontainers}") - testImplementation("org.testcontainers:mongodb:${Versions.testcontainers}") - testImplementation("org.litote.kmongo:kmongo:${Versions.kmongo}") - - testRuntimeOnly("ch.qos.logback:logback-classic:${Versions.logback}") -} - -tasks.test { - useJUnitPlatform() - testLogging { - events("passed", "skipped", "failed") - } -} - -sourceSets.main { - java.srcDirs("src/main/kotlinGen") -} - -java { - withJavadocJar() - withSourcesJar() -} - -publishing { - publications { - named("maven") { - artifactId = "ocpi-2-1-1" - from(components["java"]) - - pom { - name.set("OCPI 2.1.1") - artifactId = "ocpi-2-1-1" - description.set("This module implements the v2.1.1 of the OCPI spec") - } - } - } -} diff --git a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/common/HttpUtils.kt b/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/common/HttpUtils.kt deleted file mode 100644 index b41031f7..00000000 --- a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/common/HttpUtils.kt +++ /dev/null @@ -1,151 +0,0 @@ -package com.izivia.ocpi.toolkit.common - -import com.fasterxml.jackson.core.type.TypeReference -import com.izivia.ocpi.toolkit.modules.credentials.repositories.PlatformRepository -import com.izivia.ocpi.toolkit.modules.versions.domain.ModuleID -import com.izivia.ocpi.toolkit.transport.TransportClientBuilder -import com.izivia.ocpi.toolkit.transport.domain.HttpException -import com.izivia.ocpi.toolkit.transport.domain.HttpRequest -import com.izivia.ocpi.toolkit.transport.domain.HttpResponse -import com.izivia.ocpi.toolkit.transport.domain.HttpStatus -import java.util.* - -typealias AuthenticatedHttpRequest = HttpRequest - -/** - * Parse body of a paginated request. The result will be stored in a SearchResult which contains all pagination - * information. - * @param offset - */ -inline fun HttpResponse.parsePaginatedBody(offset: Int): OcpiResponseBody> = - mapper.readValue(body, object : TypeReference>>() {}) - .let { parsedBody -> - OcpiResponseBody( - data = parsedBody.data?.toSearchResult( - totalCount = headers["X-Total-Count"]!!.toInt(), - limit = headers["X-Limit"]!!.toInt(), - offset = offset, - nextPageUrl = headers["Link"]?.split("<")?.get(1)?.split(">")?.first() - ), - status_code = parsedBody.status_code, - status_message = parsedBody.status_message, - timestamp = parsedBody.timestamp - ) - } - -/** - * Parses the body of the given HttpResponse to the specified type - * - * @throws StreamReadException – if underlying input contains invalid content of type JsonParser supports (JSON for - * default case) - * @throws DatabindException – if the input JSON structure does not match structure expected for result type (or has - * other mismatch issues) - */ -inline fun HttpResponse.parseBody(): T = mapper.readValue(body!!, object: TypeReference() {}) - -/** - * Encode a string in base64, also @see String#decodeBase64() - */ -fun String.encodeBase64(): String = this // Base64.getEncoder().encodeToString(this.encodeToByteArray()) - -/** - * Decodes a base64-encoded string, also @see String#encodeBase64() - */ -fun String.decodeBase64(): String = this // Base64.getDecoder().decode(this).decodeToString() - -/** - * Creates the authorization header from the given token - */ -fun authorizationHeader(token: String): Pair = "Authorization" to "Token ${token.encodeBase64()}" - -/** - * Creates the authorization header by taking the right token in the platform repository - */ -fun PlatformRepository.buildAuthorizationHeader(baseUrl: String, allowTokenAOrTokenB: Boolean = false) = - if (allowTokenAOrTokenB) { - getCredentialsTokenC(platformUrl = baseUrl) - ?: getCredentialsTokenB(platformUrl = baseUrl) - ?: getCredentialsTokenA(platformUrl = baseUrl) - ?: throw throw OcpiClientGenericException( - "Could not find CREDENTIALS TOKEN A OR B OR C associated with platform $baseUrl" - ) - } else { - getCredentialsTokenC(platformUrl = baseUrl) - ?: throw throw OcpiClientGenericException( - "Could not find CREDENTIALS TOKEN C associated with platform $baseUrl" - ) - }.let { token -> authorizationHeader(token = token) } - -/** - * Adds the authentification header to the request. - * - * @param platformRepository use to retrieve tokens - * @param baseUrl used to know what platform is being requested - * @param allowTokenAOrTokenB true if we can authenticate using token A - */ -fun HttpRequest.authenticate( - platformRepository: PlatformRepository, - baseUrl: String, - allowTokenAOrTokenB: Boolean = false -): AuthenticatedHttpRequest = - copy( - headers = headers.plus( - platformRepository.buildAuthorizationHeader( - baseUrl = baseUrl, - allowTokenAOrTokenB = allowTokenAOrTokenB - ) - ) - ) - -/** - * Adds the authentification header to the request. - * - * @param token the token to use to authenticate - */ -fun HttpRequest.authenticate(token: String): AuthenticatedHttpRequest = - copy(headers = headers.plus(authorizationHeader(token = token))) - -/** - * Parses authorization header from the HttpRequest - * - * @throws OcpiClientNotEnoughInformationException if the token is missing - * @throws HttpException if the authorization header is missing - */ -fun HttpRequest.parseAuthorizationHeader() = (headers["Authorization"] ?: headers["authorization"]) - ?.let { - if (it.startsWith("Token ")) it - else throw OcpiClientInvalidParametersException("Unkown token format: $it") - } - ?.removePrefix("Token ") - ?.decodeBase64() - ?: throw HttpException(HttpStatus.UNAUTHORIZED, "Authorization header missing") - -/** - * Throws an exception if the token is invalid. Does nothing otherwise. - * - * TODO: is it the good behaviour given: - * - tokenA: Valid in receiver context, during sender registration (only for sender -> receiver calls) - * - tokenB: Valid in sender context, during sender registration (only for receiver -> sender calls) - * - tokenC: Valid when the sender is registered with the receiver (only for sender -> receiver) - * - * @throws OcpiClientInvalidParametersException if the token is invalid, otherwise does nothing - * @throws OcpiClientNotEnoughInformationException if the token is missing - * @throws HttpException if the authorization header is missing - */ -fun PlatformRepository.checkToken(httpRequest: HttpRequest) { - val token = httpRequest.parseAuthorizationHeader() - - if (!platformExistsWithTokenA(token) && - !platformExistsWithTokenB(token) && - getPlatformUrlByTokenC(token) == null) { - - throw OcpiClientInvalidParametersException("Invalid token: $token") - } -} - -fun TransportClientBuilder.buildFor(module: ModuleID, platformUrl: String, platformRepository: PlatformRepository) = - platformRepository - .getEndpoints(platformUrl = platformUrl) - .find { it.identifier == module } - ?.let { build(baseUrl = it.url) } - ?: throw OcpiToolkitUnknownEndpointException(endpointName = module.name) diff --git a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/common/Mapper.kt b/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/common/Mapper.kt deleted file mode 100644 index 7653a447..00000000 --- a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/common/Mapper.kt +++ /dev/null @@ -1,24 +0,0 @@ -package com.izivia.ocpi.toolkit.common - -import com.fasterxml.jackson.annotation.JsonInclude -import com.fasterxml.jackson.databind.ObjectMapper -import com.fasterxml.jackson.databind.SerializationFeature -import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule -import com.fasterxml.jackson.module.kotlin.KotlinFeature -import com.fasterxml.jackson.module.kotlin.KotlinModule -import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper - -val mapper: ObjectMapper = jacksonObjectMapper() - .registerModule( - KotlinModule.Builder() - .withReflectionCacheSize(512) - .configure(KotlinFeature.NullToEmptyCollection, false) - .configure(KotlinFeature.NullToEmptyMap, false) - .configure(KotlinFeature.NullIsSameAsDefault, false) - .configure(KotlinFeature.SingletonSupport, false) - .configure(KotlinFeature.StrictNullChecks, false) - .build() - ) - .registerModule(JavaTimeModule()) - .configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false) - .setSerializationInclusion(JsonInclude.Include.NON_NULL) \ No newline at end of file diff --git a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/common/OcpiExceptions.kt b/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/common/OcpiExceptions.kt deleted file mode 100644 index 47132071..00000000 --- a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/common/OcpiExceptions.kt +++ /dev/null @@ -1,64 +0,0 @@ -package com.izivia.ocpi.toolkit.common - -import com.izivia.ocpi.toolkit.transport.domain.HttpStatus - -sealed class OcpiException( - message: String, - open val httpStatus: HttpStatus, - open val ocpiStatus: OcpiStatus -): Exception(message) - -class OcpiResponseException( - val statusCode: Int, - val statusMessage: String -): Exception("Ocpi error: ${statusCode.toOcpiStatus()} $statusCode ($statusMessage)") - -// 2xxx: Client errors -class OcpiClientGenericException( - message: String, - override val httpStatus: HttpStatus = HttpStatus.BAD_REQUEST, - override val ocpiStatus: OcpiStatus = OcpiStatus.CLIENT_ERROR -) : OcpiException(message, httpStatus, ocpiStatus) - -class OcpiClientInvalidParametersException( - message: String = "Invalid or missing parameters", - override val httpStatus: HttpStatus = HttpStatus.BAD_REQUEST, - override val ocpiStatus: OcpiStatus = OcpiStatus.CLIENT_INVALID_PARAMETERS -) : OcpiException(message, httpStatus, ocpiStatus) - -class OcpiClientNotEnoughInformationException( - message: String = "Not enough information", - override val httpStatus: HttpStatus = HttpStatus.BAD_REQUEST, - override val ocpiStatus: OcpiStatus = OcpiStatus.CLIENT_NOT_ENOUGH_INFORMATION -) : OcpiException(message, httpStatus, ocpiStatus) - -class OcpiClientUnknownLocationException( - message: String = "Unknown location", - override val httpStatus: HttpStatus = HttpStatus.NOT_FOUND, - override val ocpiStatus: OcpiStatus = OcpiStatus.CLIENT_UNKNOWN_LOCATION -) : OcpiException(message, httpStatus, ocpiStatus) - -// 3xxx: Server errors -class OcpiServerGenericException( - message: String, - override val httpStatus: HttpStatus = HttpStatus.OK, - override val ocpiStatus: OcpiStatus = OcpiStatus.SERVER_ERROR -) : OcpiException(message, httpStatus, ocpiStatus) - -class OcpiServerUnusableApiException( - message: String = "Unable to use client's API", - override val httpStatus: HttpStatus = HttpStatus.OK, - override val ocpiStatus: OcpiStatus = OcpiStatus.SERVER_UNUSABLE_API -) : OcpiException(message, httpStatus, ocpiStatus) - -class OcpiServerUnsupportedVersionException( - message: String = "Unsupported version", - override val httpStatus: HttpStatus = HttpStatus.OK, - override val ocpiStatus: OcpiStatus = OcpiStatus.SERVER_UNSUPPORTED_VERSION -) : OcpiException(message, httpStatus, ocpiStatus) - -class OcpiServerNoMatchingEndpointsException( - message: String = "No matching endpoints or expected endpoints missing between parties", - override val httpStatus: HttpStatus = HttpStatus.OK, - override val ocpiStatus: OcpiStatus = OcpiStatus.SERVER_NO_MATCHING_ENDPOINTS -) : OcpiException(message, httpStatus, ocpiStatus) \ No newline at end of file diff --git a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/common/OcpiResponseBody.kt b/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/common/OcpiResponseBody.kt deleted file mode 100644 index 8dcaf5d4..00000000 --- a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/common/OcpiResponseBody.kt +++ /dev/null @@ -1,151 +0,0 @@ -package com.izivia.ocpi.toolkit.common - -import com.fasterxml.jackson.core.JsonProcessingException -import com.izivia.ocpi.toolkit.common.validation.toReadableString -import com.izivia.ocpi.toolkit.transport.domain.HttpException -import com.izivia.ocpi.toolkit.transport.domain.HttpRequest -import com.izivia.ocpi.toolkit.transport.domain.HttpResponse -import com.izivia.ocpi.toolkit.transport.domain.HttpStatus -import org.apache.logging.log4j.LogManager -import org.valiktor.ConstraintViolationException -import java.time.Instant - -/** - * When the status code is in the success range (1xxx), the data field in the response message should contain the - * information as specified in the protocol. Otherwise the data field is unspecified and may be omitted, null or - * something else that could help to debug the problem from a programmer's perspective. For example, it could specify - * which fields contain an error or are missing. - * - * The content that is sent with all the response messages is an 'application/json' type and contains a JSON object with - * the following properties: - * - * @property data Contains the actual response data object or list of objects from each request, depending on the - * cardinality of the response data, this is an array (card. * or +), or a single object (card. 1 or ?) - * @property status_code Response code, as listed in Status Codes, indicates how the request was handled. To avoid - * confusion with HTTP codes, at least four digits are used. - * @property status_message An optional status message which may help when debugging. - * @property timestamp The time this message was generated. - */ -data class OcpiResponseBody( - val data: T?, - val status_code: Int, - val status_message: String?, - val timestamp: Instant -) { - companion object { - fun success(data: T) = OcpiResponseBody( - data = data, - status_code = OcpiStatus.SUCCESS.code, - status_message = null, - timestamp = Instant.now() - ) - - fun invalid(message: String) = OcpiResponseBody( - data = null, - status_code = OcpiStatus.CLIENT_INVALID_PARAMETERS.code, - status_message = message, - timestamp = Instant.now() - ) - - fun of(data: () -> T) = - try { - success(data = data()) - } catch (e: ConstraintViolationException) { - invalid(message = e.toReadableString()) - } - } -} - -private val logger = LogManager.getLogger(OcpiResponseBody::class.java) - -/** - * Generates all required headers for a paginated response from a OcpiBody with a searchResult. - * @param request the request that generated the body. - * @return Map the headers required for pagination - */ -fun OcpiResponseBody>.getPaginatedHeaders(request: HttpRequest) = - if (data != null) { - val nextPageOffset = (data.offset + data.limit).takeIf { it <= data.totalCount } - - val queries = request - .queryParams - .filter { it.key != "offset" && it.value != null } - .plus("offset" to (data.limit + data.offset)) - .map { "${it.key}=${it.value}" } - .joinToString("&", "?") - - listOfNotNull( - nextPageOffset?.let { "Link" to "<${request.baseUrl}${request.path}$queries>; rel=\"next\"" }, - "X-Total-Count" to data.totalCount.toString(), - "X-Limit" to data.limit.toString() - ).toMap() - } else { - emptyMap() - } - -/** - * Transforms an OcpiException to an HttpResponse. May be used in TransportServer implementation to handle - * OCPI exceptions. - */ -fun OcpiException.toHttpResponse(): HttpResponse = - HttpResponse( - status = httpStatus, - body = mapper.writeValueAsString( - OcpiResponseBody( - data = null, - status_code = ocpiStatus.code, - status_message = message, - timestamp = Instant.now() - ) - ), - headers = if (httpStatus == HttpStatus.UNAUTHORIZED) mapOf("WWW-Authenticate" to "Token") else emptyMap() - ) - -/** - * Used to handle errors & paginated responses when handling a request. fn() should contain the code generating the - * body. If an error is caught, everything will be handled here. If it's a paginated response, it will be automatically - * be handled too. - * - * @return the HttpResponse properly formatted according to the body generated by fn() - */ -@Suppress("UNCHECKED_CAST") -fun HttpRequest.httpResponse(fn: () -> OcpiResponseBody): HttpResponse = - try { - val ocpiResponseBody = fn() - val isPaginated = ocpiResponseBody.data is SearchResult<*> - - HttpResponse( - status = when (ocpiResponseBody.status_code) { - OcpiStatus.SUCCESS.code -> if (ocpiResponseBody.data != null) HttpStatus.OK else HttpStatus.NOT_FOUND - OcpiStatus.CLIENT_INVALID_PARAMETERS.code -> HttpStatus.BAD_REQUEST - else -> HttpStatus.INTERNAL_SERVER_ERROR - }, - body = mapper.writeValueAsString( - if (isPaginated) OcpiResponseBody( - data = (ocpiResponseBody.data as SearchResult<*>?)?.list, - status_code = ocpiResponseBody.status_code, - status_message = ocpiResponseBody.status_message, - timestamp = ocpiResponseBody.timestamp - ) - else ocpiResponseBody - ) - ).let { - if (isPaginated) it.copy( - headers = (ocpiResponseBody as OcpiResponseBody>) - .getPaginatedHeaders(request = this) - ) - else it - } - } catch (e: OcpiException) { - e.toHttpResponse() - } catch (e: HttpException) { - logger.error(e) - HttpResponse( - status = e.status - ) - } catch (e: JsonProcessingException) { - logger.error(e) - HttpResponse( - status = HttpStatus.BAD_REQUEST - ) - } \ No newline at end of file diff --git a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/common/OcpiStatus.kt b/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/common/OcpiStatus.kt deleted file mode 100644 index 8651a321..00000000 --- a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/common/OcpiStatus.kt +++ /dev/null @@ -1,60 +0,0 @@ -package com.izivia.ocpi.toolkit.common - -/** - * - 1xxx: Success - * - 2xxx: Client errors - Errors detected by a server in the message sent by a client: The client did something wrong - * - 3xxx: Server errors - Error during processing of the OCPI payload in the server. The message was syntactically - * correct but could not be processed by the server. - */ -enum class OcpiStatus(val code: Int) { - /** - * Generic success code - */ - SUCCESS(1000), - - /** - * Generic client error - */ - CLIENT_ERROR(2000), - - /** - * Invalid or missing parameters - */ - CLIENT_INVALID_PARAMETERS(2001), - - /** - * Not enough information, for example: Authorization request with too little information. - */ - CLIENT_NOT_ENOUGH_INFORMATION(2002), - - /** - * Unknown Location, for example: Command: START_SESSION with unknown location. - */ - CLIENT_UNKNOWN_LOCATION(2003), - - /** - * Generic server error - */ - SERVER_ERROR(3000), - - /** - * Unable to use the client's API. For example during the credentials registration: When the initializing party - * requests data from the other party during the open POST call to its credentials endpoint. If one of the GETs can - * not be processed, the party should return this error in the POST response. - */ - SERVER_UNUSABLE_API(3001), - - /** - * Unsupported version. - */ - SERVER_UNSUPPORTED_VERSION(3002), - - /** - * No matching endpoints or expected endpoints missing between parties. Used during the registration process if the - * two parties do not have any mutual modules or endpoints available, or the minimum expected by the other party - * implementation. - */ - SERVER_NO_MATCHING_ENDPOINTS(3003) -} - -fun Int.toOcpiStatus(): OcpiStatus? = OcpiStatus.values().firstOrNull { it.code == this } \ No newline at end of file diff --git a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/common/OcpiToolkitExceptions.kt b/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/common/OcpiToolkitExceptions.kt deleted file mode 100644 index 59667cfa..00000000 --- a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/common/OcpiToolkitExceptions.kt +++ /dev/null @@ -1,11 +0,0 @@ -package com.izivia.ocpi.toolkit.common - -class OcpiToolkitUnknownEndpointException( - endpointName: String -) : Exception( - """ - Endpoint '$endpointName' is unknown. Make sure you registered (credentialClient#register) first. During - registration process, the available endpoints are saved in platformRepository to be used later on. If you - already registered, make sure that the platformRepository works properly. - """.trimIndent() -) \ No newline at end of file diff --git a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/common/SearchResult.kt b/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/common/SearchResult.kt deleted file mode 100644 index 19b6272b..00000000 --- a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/common/SearchResult.kt +++ /dev/null @@ -1,17 +0,0 @@ -package com.izivia.ocpi.toolkit.common - -data class SearchResult( - val list: List, - val totalCount: Int, - val limit: Int, - val offset: Int, - val nextPageUrl: String? -) - -fun List.toSearchResult(totalCount: Int, limit: Int, offset: Int, nextPageUrl: String? = null) = SearchResult( - list = this, - totalCount = totalCount, - limit = limit, - offset = offset, - nextPageUrl = nextPageUrl -) \ No newline at end of file diff --git a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/common/Utils.kt b/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/common/Utils.kt deleted file mode 100644 index d232b13b..00000000 --- a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/common/Utils.kt +++ /dev/null @@ -1,7 +0,0 @@ -package com.izivia.ocpi.toolkit.common - -import java.util.* - -fun generateUUIDv4Token(): String { - return UUID.randomUUID().toString() -} \ No newline at end of file diff --git a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/common/validation/Iso639Alpha2.kt b/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/common/validation/Iso639Alpha2.kt deleted file mode 100644 index 94da8fd3..00000000 --- a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/common/validation/Iso639Alpha2.kt +++ /dev/null @@ -1,194 +0,0 @@ -package com.izivia.ocpi.toolkit.common.validation - -/** - * ISO 639-1 language codes - */ -enum class Iso639Alpha2 { - aa, - ab, - ae, - af, - ak, - am, - an, - ar, - `as`, - av, - ay, - az, - ba, - be, - bg, - bh, - bi, - bm, - bn, - bo, - br, - bs, - ca, - ce, - ch, - co, - cr, - cs, - cu, - cv, - cy, - da, - de, - dv, - dz, - ee, - el, - en, - eo, - es, - et, - eu, - fa, - ff, - fi, - fj, - fo, - fr, - fy, - ga, - gd, - gl, - gn, - gu, - gv, - ha, - he, - hi, - ho, - hr, - ht, - hu, - hy, - hz, - ia, - id, - ie, - ig, - ii, - ik, - io, - `is`, - it, - iu, - ja, - jv, - ka, - kg, - ki, - kj, - kk, - kl, - km, - kn, - ko, - kr, - ks, - ku, - kv, - kw, - ky, - la, - lb, - lg, - li, - ln, - lo, - lt, - lu, - lv, - mg, - mh, - mi, - mk, - ml, - mn, - mo, - mr, - ms, - mt, - my, - na, - nb, - nd, - ne, - ng, - nl, - nn, - no, - nr, - nv, - ny, - oc, - oj, - om, - or, - os, - pa, - pi, - pl, - ps, - pt, - qu, - rc, - rm, - rn, - ro, - ru, - rw, - sa, - sc, - sd, - se, - sg, - sh, - si, - sk, - sl, - sm, - sn, - so, - sq, - sr, - ss, - st, - su, - sv, - sw, - ta, - te, - tg, - th, - ti, - tk, - tl, - tn, - to, - tr, - ts, - tt, - tw, - ty, - ug, - uk, - ur, - uz, - ve, - vi, - vo, - wa, - wo, - xh, - yi, - yo, - za, - zh, - zu -} \ No newline at end of file diff --git a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/common/validation/Validation.kt b/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/common/validation/Validation.kt deleted file mode 100644 index 7d191549..00000000 --- a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/common/validation/Validation.kt +++ /dev/null @@ -1,60 +0,0 @@ -package com.izivia.ocpi.toolkit.common.validation - -import org.valiktor.ConstraintViolation -import org.valiktor.ConstraintViolationException -import org.valiktor.DefaultConstraintViolation -import org.valiktor.constraints.Greater -import org.valiktor.constraints.Less -import java.time.Instant - -data class ValidationContext( - val violations: MutableSet = mutableSetOf() -) - -fun validate(fn: ValidationContext.() -> T) = with(ValidationContext()) { - fn() - - if (violations.isNotEmpty()) { - throw ConstraintViolationException(violations) - } -} - -fun ValidationContext.validateLength(propertyName: String, property: String, maxLength: Int) { - if (property.length > maxLength) { - violations.add( - DefaultConstraintViolation( - property = property, - constraint = Greater(maxLength) - ) - ) - } -} - -fun ValidationContext.validateDates(fromPropertyName: String, from: Instant, toPropertyName: String, to: Instant) { - if (from.isAfter(to)) { - violations.add( - DefaultConstraintViolation( - property = "from", - constraint = Greater(to) - ) - ) - } -} - -fun ValidationContext.validateInt(propertyName: String, property: Int, min: Int?, max: Int?) { - if (min != null && property < min) { - violations.add( - DefaultConstraintViolation( - property = "value", - constraint = Less(min) - ) - ) - } else if (max != null && property > max) { - violations.add( - DefaultConstraintViolation( - property = "value", - constraint = Greater(min) - ) - ) - } -} diff --git a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/common/validation/Validators.kt b/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/common/validation/Validators.kt deleted file mode 100644 index f05e5f4e..00000000 --- a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/common/validation/Validators.kt +++ /dev/null @@ -1,131 +0,0 @@ -package com.izivia.ocpi.toolkit.common.validation - -import org.valiktor.Constraint -import org.valiktor.ConstraintViolationException -import org.valiktor.Validator -import org.valiktor.i18n.toMessage -import java.net.URL -import java.util.* - -fun ConstraintViolationException.toReadableString(): String = constraintViolations - .map { it.toMessage(baseName = "messages", locale = Locale.ENGLISH) } - .joinToString(",") { "${it.property}: ${it.message}" } - -class PrintableAsciiConstraint : Constraint -class MaxLengthContraint(val length: Int) : Constraint -class CountryCodeConstraint : Constraint -class UrlConstraint : Constraint -class TimeZoneConstraint : Constraint -class LatitudeConstraint : Constraint -class LongitudeConstraint : Constraint -class LanguageConstraint : Constraint -class TimeConstraint : Constraint -class EvseIdConstraint : Constraint -class NoHtmlConstraint : Constraint - -/** - * Valid if the given string only has printable ASCII characters and is smaller or has the same length as the given one. - */ -fun Validator.Property.isPrintableAscii() = - this.validate(PrintableAsciiConstraint()) { - it == null || it.matches("[\\x20-\\x7E]*".toRegex()) - } - - -fun Validator.Property.hasNoHtml() = - this.validate(NoHtmlConstraint()) { - it == null || !it.matches(".*<(\"[^\"]*\"|'[^']*'|[^'\">])*>.*".toRegex()) - } - -/** - * Valid if the string has a max length of the given one - */ -fun Validator.Property.hasMaxLengthOf(length: Int) = - this.validate(MaxLengthContraint(length)) { it == null || it.length <= length } - -/** - * Valid if the string correspond is a ISO 3166-1 alpha-3 code - */ -fun Validator.Property.isCountryCode() = - this.validate(CountryCodeConstraint()) { - it == null || Locale.getISOCountries(Locale.IsoCountryCode.PART1_ALPHA3).contains(it) - } - -/** - * Valid if the string is an URL following the w3.org spec - */ -fun Validator.Property.isUrl() = - this.validate(UrlConstraint()) { - it == null || try { URL(it).toURI().let { true } } catch (e: Exception) { false } - }.hasMaxLengthOf(255) - - -/** - * Valid if the string is one of IANA tzdata's TZ-values representing the time zone. - * Examples: "Europe/Oslo", "Europe/Zurich". (http://www.iana.org/time-zones) - */ -fun Validator.Property.isTimeZone() = - this.validate(TimeZoneConstraint()) { - it == null || TimeZone.getAvailableIDs().contains(it) - } - -/** - * Valid if the string is a latitude in decimal degree. Regex: -?[0-9]{1,2}\.[0-9]{6} - */ -fun Validator.Property.isLatitude() = - this.validate(LatitudeConstraint()) { - it == null || it.matches("-?\\d{1,2}\\.\\d{6}".toRegex()) - } - -/** - * Valid if the string is a longitude in decimal degree. Regex: -?[0-9]{1,3}\.[0-9]{6} - */ -fun Validator.Property.isLongitude() = - this.validate(LongitudeConstraint()) { - it == null || it.matches("-?\\d{1,3}\\.\\d{6}".toRegex()) - } - -/** - * Valid if the string is a language Code ISO 639-1 - */ -fun Validator.Property.isLanguage() = - this.validate(LanguageConstraint()) { - it == null || Iso639Alpha2.values().map { code -> code.name }.contains(it) - }.hasMaxLengthOf(2) - -/** - * Valid if the string is a time from 00:00 to 23:59 - */ -fun Validator.Property.isTime() = - this.validate(TimeConstraint()) { - it == null || it.matches("([0-1]\\d|2[0-3]):[0-5]\\d".toRegex()) - } - -/** - * Compliant with the following specification for EVSE ID from "eMI3 standard version V1.0" - * (http://emi3group.com/documents-links/) "Part 2: business objects." Optional because: if an EVSE ID is to be re-used - * the EVSE ID can be removed from an EVSE that is removed (status: REMOVED) - * - * Extracted from the doc: - * - {EVSE ID} = {Country Code} {S} {Spot Operator ID} {S} {ID Type} {Power Outlet ID} - * - Example: FR*A23*E45B*78C - * - * With: - * - Country Code: two character country code according to ISO-3166-1 (Alpha-2-Code). Country Code SHALL represent the - * country where the EVSE is installed. - * - Spot Operator ID: three alphanumeric characters, defined and listed by eMI3 group, referring to the EVSE operator - * - ID Type: one character “E” indicating that this ID represents an “EVSE” - * - Power Outlet ID: between 1 and 31 sequence of alphanumeric characters or separators, including additional optional - * separators start with alphanumeric character, internal number allowing the EVSE Operator to identify one specific - * EVSE - * - S: optional separator - * - * An example for, a valid EVSE ID is “FR*A23*E45B*78C” with “FR” indicating France, “A23” representing a particular - * EVSE Operator, “E” indicating that it is of type “EVSE” and “45B*78C” representing the power outlet ID, that is to - * say one of its EVSEs.NOTE: In contrast to the eMA ID, no check digit is specified for the EVSE ID in this document. - * Alpha characters SHALL be interpreted case insensitively. - */ -fun Validator.Property.isEvseId() = - this.validate(EvseIdConstraint()) { - it == null || it.matches("(?i)[a-z]{2}\\*?[a-z\\d]{3}\\*?E[a-z\\d*]{1,31}".toRegex()) - } \ No newline at end of file diff --git a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/credentials/CredentialsClient.kt b/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/credentials/CredentialsClient.kt deleted file mode 100644 index c33d548b..00000000 --- a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/credentials/CredentialsClient.kt +++ /dev/null @@ -1,59 +0,0 @@ -package com.izivia.ocpi.toolkit.modules.credentials - -import com.izivia.ocpi.toolkit.common.OcpiResponseBody -import com.izivia.ocpi.toolkit.common.authenticate -import com.izivia.ocpi.toolkit.common.mapper -import com.izivia.ocpi.toolkit.common.parseBody -import com.izivia.ocpi.toolkit.modules.credentials.domain.Credentials -import com.izivia.ocpi.toolkit.transport.TransportClient -import com.izivia.ocpi.toolkit.transport.domain.HttpMethod -import com.izivia.ocpi.toolkit.transport.domain.HttpRequest - -/** - * Use this class only if you know what you are doing. Instead, use CredentialsClientService. - * @property transportClient TransportClient - */ -class CredentialsClient( - private val transportClient: TransportClient -): CredentialsInterface { - - override fun get(tokenC: String): OcpiResponseBody = - transportClient - .send( - HttpRequest( - method = HttpMethod.GET - ).authenticate(token = tokenC) - ) - .parseBody() - - - override fun post(tokenA: String, credentials: Credentials): OcpiResponseBody = - transportClient - .send( - HttpRequest( - method = HttpMethod.POST, - body = mapper.writeValueAsString(credentials) - ).authenticate(token = tokenA) - ) - .parseBody() - - override fun put(tokenC: String, credentials: Credentials): OcpiResponseBody = - transportClient - .send( - HttpRequest( - method = HttpMethod.PUT, - body = mapper.writeValueAsString(credentials) - ).authenticate(token = tokenC) - ) - .parseBody() - - override fun delete(tokenC: String): OcpiResponseBody = - transportClient - .send( - HttpRequest( - method = HttpMethod.DELETE, - path = "/" - ).authenticate(token = tokenC) - ) - .parseBody() -} \ No newline at end of file diff --git a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/credentials/CredentialsInterface.kt b/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/credentials/CredentialsInterface.kt deleted file mode 100644 index db823012..00000000 --- a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/credentials/CredentialsInterface.kt +++ /dev/null @@ -1,55 +0,0 @@ -package com.izivia.ocpi.toolkit.modules.credentials - -import com.izivia.ocpi.toolkit.common.OcpiResponseBody -import com.izivia.ocpi.toolkit.modules.credentials.domain.Credentials - -/** - * The Credentials module is different from all other OCPI modules. This module is symmetric, it has to be implemented - * by all OCPI implementations, and all implementations need to be able call this module on any other platform, and have - * to be able the handle receiving the request from another party. - */ -interface CredentialsInterface { - /** - * Retrieves the credentials object to access the server’s platform. The request body is empty, the response - * contains the credentials object to access the server’s platform. This credentials object also contains extra - * information about the server such as its business details. - */ - fun get(tokenC: String): OcpiResponseBody - - /** - * Provides the server with credentials to access the client's system. This credentials object also contains extra - * information about the client such as its business details. - * - * A POST initiates the registration process for this endpoint's version. The server must also fetch the client's - * endpoints for this version. If successful, the server must generate a new credentials token and respond with the - * client's new credentials to access the server's system. The credentials object in the response also contains - * extra information about the server such as its business details. - * - * This method MUST return a HTTP status code 405: method not allowed if the client has already been registered - * before. - */ - fun post(tokenA: String, credentials: Credentials): OcpiResponseBody - - /** - * Provides the server with updated credentials to access the client’s system. This credentials object also contains - * extra information about the client such as its business details. - * - * A PUT will switch to the version that contains this credentials endpoint if it’s different from the current - * version. The server must fetch the client’s endpoints again, even if the version has not changed. - * - * If successful, the server must generate a new credentials token for the client and respond with the client’s - * updated credentials to access the server’s system. The credentials object in the response also contains extra - * information about the server such as its business details. - * - * This method MUST return a HTTP status code 405: method not allowed if the client has not been registered yet. - */ - fun put(tokenC: String, credentials: Credentials): OcpiResponseBody - - /** - * Informs the server that its credentials to access the client’s system are now invalid and can no longer be used. - * Both parties must end any automated communication. This is the unregistration process. - * - * This method MUST return a HTTP status code 405: method not allowed if the client has not been registered before. - */ - fun delete(tokenC: String): OcpiResponseBody -} \ No newline at end of file diff --git a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/credentials/CredentialsServer.kt b/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/credentials/CredentialsServer.kt deleted file mode 100644 index bd7ff3c1..00000000 --- a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/credentials/CredentialsServer.kt +++ /dev/null @@ -1,69 +0,0 @@ -package com.izivia.ocpi.toolkit.modules.credentials - -import com.izivia.ocpi.toolkit.common.httpResponse -import com.izivia.ocpi.toolkit.common.mapper -import com.izivia.ocpi.toolkit.common.parseAuthorizationHeader -import com.izivia.ocpi.toolkit.modules.credentials.domain.Credentials -import com.izivia.ocpi.toolkit.modules.credentials.services.CredentialsServerService -import com.izivia.ocpi.toolkit.transport.TransportServer -import com.izivia.ocpi.toolkit.transport.domain.FixedPathSegment -import com.izivia.ocpi.toolkit.transport.domain.HttpMethod -import kotlinx.coroutines.runBlocking - -class CredentialsServer( - transportServer: TransportServer, - service: CredentialsServerService, - basePath: List = listOf( - FixedPathSegment("/2.1.1/credentials") - ) -) { - init { - runBlocking { - transportServer.handle( - method = HttpMethod.GET, - path = basePath - ) { req -> - req.httpResponse { - service.get( - tokenC = req.parseAuthorizationHeader() - ) - } - } - - transportServer.handle( - method = HttpMethod.POST, - path = basePath - ) { req -> - req.httpResponse { - service.post( - tokenA = req.parseAuthorizationHeader(), - credentials = mapper.readValue(req.body!!, Credentials::class.java) - ) - } - } - - transportServer.handle( - method = HttpMethod.PUT, - path = basePath - ) { req -> - req.httpResponse { - service.put( - tokenC = req.parseAuthorizationHeader(), - credentials = mapper.readValue(req.body!!, Credentials::class.java) - ) - } - } - - transportServer.handle( - method = HttpMethod.DELETE, - path = basePath - ) { req -> - req.httpResponse { - service.delete( - tokenC = req.parseAuthorizationHeader() - ) - } - } - } - } -} diff --git a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/credentials/domain/Credentials.kt b/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/credentials/domain/Credentials.kt deleted file mode 100644 index 1e5a3ec0..00000000 --- a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/credentials/domain/Credentials.kt +++ /dev/null @@ -1,29 +0,0 @@ -package com.izivia.ocpi.toolkit.modules.credentials.domain - -import com.izivia.ocpi.toolkit.modules.locations.domain.BusinessDetails - -/** - * The party_id and country_code are provided here to inform a server about the party_id and country_code a client will - * use when pushing client owned objects. This helps a server determine the URLs a client will use when pushing a client - * owned object. The country_code is added the make certain the URL used when pushing a client owned object is unique, - * there might be multiple parties in the world with the same party_id, but the combination should always be unique. A - * party operating in multiple countries can always use the home country of the company for all connections. For - * example: an OCPI implementation might push EVSE IDs from a company for different countries, preventing an OCPI - * connection per country a company is operating in. The party_id and country_code give here, have no direct link with - * the eMI3 EVSE IDs and Contract IDs that might be used in the different OCPI modules. For example: an implementation - * OCPI might push EVSE IDs with an eMI3 spot operator different from the OCPI party_id and/or the country_code. - * - * @property token (max-length=64) Case Sensitive, ASCII only. The credentials token for the other party to authenticate - * in your system. Not encoded in Base64 or any other encoding. - * @property url The URL to your API versions endpoint. - * @property business_details Details of this party. - * @property party_id (max-length=3) CPO or eMSP ID of this party. (following the 15118 ISO standard). - * @property country_code(max-length=2) Country code of the country this party is operating in. - */ -data class Credentials( - val token: String, - val url: String, - val business_details: BusinessDetails, - val party_id: String, - val country_code: String -) diff --git a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/credentials/repositories/PlatformRepository.kt b/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/credentials/repositories/PlatformRepository.kt deleted file mode 100644 index 0c851518..00000000 --- a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/credentials/repositories/PlatformRepository.kt +++ /dev/null @@ -1,31 +0,0 @@ -package com.izivia.ocpi.toolkit.modules.credentials.repositories - -import com.izivia.ocpi.toolkit.modules.versions.domain.Endpoint -import com.izivia.ocpi.toolkit.modules.versions.domain.Version - -/** - * - CREDENTIALS_TOKEN_A: used by the client to communicate with the server (when initiating registration). - * - CREDENTIALS_TOKEN_B: used by the server to communicate with the client (during registration). - * - CREDENTIALS_TOKEN_C: used by the client to communicate with the server (once registered). - */ -interface PlatformRepository { - fun getCredentialsTokenA(platformUrl: String): String? - fun getCredentialsTokenB(platformUrl: String): String? - fun getCredentialsTokenC(platformUrl: String): String? - fun platformExistsWithTokenA(token: String): Boolean - fun platformExistsWithTokenB(token: String): Boolean - fun getPlatformUrlByTokenC(token: String): String? - fun getEndpoints(platformUrl: String): List - fun getVersion(platformUrl: String): Version? - fun savePlatformUrlForTokenA(tokenA: String, platformUrl: String): String? - fun saveVersion(platformUrl: String, version: Version): Version - fun saveEndpoints(platformUrl: String, endpoints: List): List - fun saveCredentialsTokenA(platformUrl: String, credentialsTokenA: String): String - fun saveCredentialsTokenB(platformUrl: String, credentialsTokenB: String): String - fun saveCredentialsTokenC(platformUrl: String, credentialsTokenC: String): String - fun removeCredentialsTokenA(platformUrl: String) - fun removeCredentialsTokenB(platformUrl: String) - fun removeCredentialsTokenC(platformUrl: String) - fun removeVersion(platformUrl: String) - fun removeEndpoints(platformUrl: String) -} diff --git a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/credentials/services/CredentialsClientService.kt b/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/credentials/services/CredentialsClientService.kt deleted file mode 100644 index 8afb4e62..00000000 --- a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/credentials/services/CredentialsClientService.kt +++ /dev/null @@ -1,220 +0,0 @@ -package com.izivia.ocpi.toolkit.modules.credentials.services - -import com.izivia.ocpi.toolkit.common.* -import com.izivia.ocpi.toolkit.modules.credentials.CredentialsClient -import com.izivia.ocpi.toolkit.modules.credentials.domain.Credentials -import com.izivia.ocpi.toolkit.modules.credentials.repositories.PlatformRepository -import com.izivia.ocpi.toolkit.modules.locations.domain.BusinessDetails -import com.izivia.ocpi.toolkit.modules.versions.VersionDetailsClient -import com.izivia.ocpi.toolkit.modules.versions.VersionsClient -import com.izivia.ocpi.toolkit.modules.versions.domain.Endpoint -import com.izivia.ocpi.toolkit.modules.versions.domain.ModuleID -import com.izivia.ocpi.toolkit.modules.versions.domain.parseVersionNumber -import com.izivia.ocpi.toolkit.modules.versions.repositories.VersionsRepository -import com.izivia.ocpi.toolkit.transport.TransportClientBuilder - -/** - * Automates authentification process - * - * Note: credentialsClient & versionsClient must target the same platform since the automated process will check the - * versions of the receiver before performing registration. - * - * - Client: the one doing the registration process - * - Server: the one receiving the registration process - * - * @property clientVersionsEndpointUrl the versions endpoints url of the client (for the server to use) - * @property clientPlatformRepository client's repository to store and retrieve tokens and information about platforms - * @property clientVersionsRepository client's repository to retrieve available versions on the client - * @property clientBusinessDetails Details of this party. - * @property clientPartyId (max-length=3) CPO or eMSP ID of this party. (following the 15118 ISO standard). - * @property clientCountryCode(max-length=2) Country code of the country this party is operating in. - * @property serverVersionsEndpointUrl the versions endpoint url of the server (for the client to retrieve endpoints) - * @property transportClientBuilder used to build a transport (will be used to create CredentialClient to make calls) - */ -class CredentialsClientService( - private val clientVersionsEndpointUrl: String, - private val clientPlatformRepository: PlatformRepository, - private val clientVersionsRepository: VersionsRepository, - private val clientBusinessDetails: BusinessDetails, - private val clientPartyId: String, - private val clientCountryCode: String, - private val serverVersionsEndpointUrl: String, - private val transportClientBuilder: TransportClientBuilder -) { - fun get(): Credentials = clientPlatformRepository - .getCredentialsTokenC(platformUrl = serverVersionsEndpointUrl) - ?.let { tokenC -> - buildCredentialClient() - .get(tokenC = tokenC) - .let { it.data ?: throw OcpiResponseException(it.status_code, it.status_message ?: "unknown") } - } - ?: throw OcpiClientGenericException("Could not find CREDENTIALS_TOKEN_C associated with platform $serverVersionsEndpointUrl") - - /** - * To start using OCPI, the Platforms will need to exchange credentials tokens. - * - * To start the exchange of credentials tokens, one platform has to be selected as Sender for the Credentials - * module. This has to be decided between the Platforms (outside of OCPI) before they first connect. - * - * To start the credentials exchange, the Receiver Platform must create a unique credentials token: - * CREDENTIALS_TOKEN_A that has to be used to authorize the Sender until the credentials exchange is finished. This - * credentials token along with the versions endpoint SHOULD be sent to the Sender in a secure way that is outside - * the scope of this protocol. - * - * The Sender starts the registration process, retrieves the version information and details (using - * CREDENTIALS_TOKEN_A in the HTTP Authorization header). The Sender generates a unique credentials token: - * CREDENTIALS_TOKEN_B, sends it to the Receiver in a POST request to the credentials module of the Receiver. The - * Receiver stores CREDENTIALS_TOKEN_B and uses it for any requests to the Sender Platform, including the version - * information and details. - * - * The Receiver generates a unique credentials token: CREDENTIALS_TOKEN_C and returns it to the Sender in the - * response to the POST request from the Sender. - * - * After the credentials exchange has finished, the Sender SHALL use CREDENTIALS_TOKEN_C in future OCPI request to - * the Receiver Platform. The CREDENTIALS_TOKEN_A can then be thrown away, it MAY no longer be used. - * - * @return the credentials to use when communicating with the server (receiver) - */ - fun register(): Credentials { - // Get token provided by receiver outside the OCPI protocol (for example by an admin) - val credentialsTokenA = clientPlatformRepository.getCredentialsTokenA(platformUrl = serverVersionsEndpointUrl) - ?: throw OcpiClientInvalidParametersException("Could not find token A associated with platform $serverVersionsEndpointUrl") - - findLatestMutualVersionAndSaveInformation() - - // Generate token B - val credentialsTokenB = clientPlatformRepository.saveCredentialsTokenB( - platformUrl = serverVersionsEndpointUrl, - credentialsTokenB = generateUUIDv4Token() - ) - - // Initiate registration process - val credentials = buildCredentialClient().post( - tokenA = credentialsTokenA, - credentials = Credentials( - token = credentialsTokenB, - url = clientVersionsEndpointUrl, - business_details = clientBusinessDetails, - party_id = clientPartyId, - country_code = clientCountryCode - ) - ).let { - it.data ?: throw OcpiResponseException(it.status_code, it.status_message ?: "unknown") - } - - // Store token C - clientPlatformRepository.saveCredentialsTokenC( - platformUrl = serverVersionsEndpointUrl, - credentialsTokenC = credentials.token - ) - - // Remove token A and B because it is useless from now on - clientPlatformRepository.removeCredentialsTokenA(platformUrl = serverVersionsEndpointUrl) - clientPlatformRepository.removeCredentialsTokenB(platformUrl = serverVersionsEndpointUrl) - return credentials - } - - fun update(): Credentials { - // Token to communicate with receiver - val credentialsTokenC = clientPlatformRepository.getCredentialsTokenC(platformUrl = serverVersionsEndpointUrl) - ?: throw OcpiClientInvalidParametersException("Could not find token C associated with platform $serverVersionsEndpointUrl") - - findLatestMutualVersionAndSaveInformation() - - // Generate token B - val credentialsTokenB = clientPlatformRepository.saveCredentialsTokenB( - platformUrl = serverVersionsEndpointUrl, - credentialsTokenB = generateUUIDv4Token() - ) - - // Initiate registration process - val credentials = buildCredentialClient().put( - tokenC = credentialsTokenC, - credentials = Credentials( - token = credentialsTokenB, - url = clientVersionsEndpointUrl, - business_details = clientBusinessDetails, - party_id = clientPartyId, - country_code = clientCountryCode - ) - ).let { - it.data ?: throw OcpiResponseException(it.status_code, it.status_message ?: "unknown") - } - - // Store token C - clientPlatformRepository.saveCredentialsTokenC( - platformUrl = serverVersionsEndpointUrl, - credentialsTokenC = credentials.token - ) - - return credentials - } - - fun delete() = clientPlatformRepository - .getCredentialsTokenC(platformUrl = serverVersionsEndpointUrl) - ?.let { tokenC -> - buildCredentialClient() - .delete(tokenC = tokenC) - .also { - clientPlatformRepository.removeCredentialsTokenC(platformUrl = serverVersionsEndpointUrl) - } - .also { - if (it.status_code != OcpiStatus.SUCCESS.code) - throw OcpiResponseException(it.status_code, it.status_message ?: "unknown") - } - } - ?: throw OcpiClientGenericException("Could not find CREDENTIALS_TOKEN_C associated with platform $serverVersionsEndpointUrl") - - private fun findLatestMutualVersionAndSaveInformation(): List { - val availableServerVersions = VersionsClient( - transportClientBuilder = transportClientBuilder, - serverVersionsEndpointUrl = serverVersionsEndpointUrl, - platformRepository = clientPlatformRepository - ) - .getVersions() - .let { - it.data ?: throw OcpiResponseException(it.status_code, it.status_message ?: "unknown") - } - val availableClientVersions = clientVersionsRepository.getVersions() - - // Get available versions and pick latest mutual - val latestMutualVersion = availableServerVersions - .sortedByDescending { clientVersion -> parseVersionNumber(clientVersion.version)!!.index } - .firstOrNull { serverVersion -> - availableClientVersions - .any { clientVersion -> serverVersion.version == clientVersion.version } - } - ?: throw OcpiServerUnsupportedVersionException("Could not find mutual version with platform $serverVersionsEndpointUrl") - - // Store version that will be used - clientPlatformRepository.saveVersion(platformUrl = serverVersionsEndpointUrl, version = latestMutualVersion) - - // Get available endpoints for the used version - val versionDetails = VersionDetailsClient( - transportClientBuilder = transportClientBuilder, - serverVersionsEndpointUrl = serverVersionsEndpointUrl, - platformRepository = clientPlatformRepository - ) - .getVersionDetails() - .let { - it.data ?: throw OcpiResponseException(it.status_code, it.status_message ?: "unknown") - } - - return clientPlatformRepository.saveEndpoints(platformUrl = serverVersionsEndpointUrl, endpoints = versionDetails.endpoints) - } - - private fun getOrFindEndpoints(): List = clientPlatformRepository - .getEndpoints(platformUrl = serverVersionsEndpointUrl) - .takeIf { it.isNotEmpty() } - ?: findLatestMutualVersionAndSaveInformation() - - private fun buildCredentialClient(): CredentialsClient = CredentialsClient( - transportClient = transportClientBuilder - .build( - baseUrl = getOrFindEndpoints() - .find { it.identifier == ModuleID.credentials } - ?.url - ?: throw OcpiServerUnsupportedVersionException("No credentials endpoint for $serverVersionsEndpointUrl") - ) - ) -} diff --git a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/credentials/services/CredentialsServerService.kt b/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/credentials/services/CredentialsServerService.kt deleted file mode 100644 index 5cf51b93..00000000 --- a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/credentials/services/CredentialsServerService.kt +++ /dev/null @@ -1,138 +0,0 @@ -package com.izivia.ocpi.toolkit.modules.credentials.services - -import com.izivia.ocpi.toolkit.common.* -import com.izivia.ocpi.toolkit.modules.credentials.CredentialsInterface -import com.izivia.ocpi.toolkit.modules.credentials.domain.Credentials -import com.izivia.ocpi.toolkit.modules.credentials.repositories.PlatformRepository -import com.izivia.ocpi.toolkit.modules.locations.domain.BusinessDetails -import com.izivia.ocpi.toolkit.modules.versions.VersionDetailsClient -import com.izivia.ocpi.toolkit.modules.versions.VersionsClient -import com.izivia.ocpi.toolkit.modules.versions.domain.VersionNumber -import com.izivia.ocpi.toolkit.transport.TransportClientBuilder - -class CredentialsServerService( - private val platformRepository: PlatformRepository, - private val serverBusinessDetails: BusinessDetails, - private val serverPartyId: String, - private val serverCountryCode: String, - private val transportClientBuilder: TransportClientBuilder, - private val serverVersionsUrl: String -) : CredentialsInterface { - - override fun get( - tokenC: String - ): OcpiResponseBody = OcpiResponseBody.of { - platformRepository - .getPlatformUrlByTokenC(tokenC) - ?.let { platformUrl -> - getCredentials( - token = platformRepository.getCredentialsTokenC(platformUrl) - ?: throw OcpiClientInvalidParametersException( - "Could not find CREDENTIALS_TOKEN_C associated with platform $platformUrl" - ) - ) - } - ?: throw OcpiClientInvalidParametersException("Invalid CREDENTIALS_TOKEN_C ($tokenC)") - } - - override fun post( - tokenA: String, - credentials: Credentials - ): OcpiResponseBody = OcpiResponseBody.of { - val platformUrl = platformRepository.savePlatformUrlForTokenA( - tokenA = tokenA, - platformUrl = credentials.url - ) ?: throw OcpiClientInvalidParametersException("Invalid CREDENTIALS_TOKEN_A ($tokenA)") - - platformRepository.saveCredentialsTokenB(platformUrl = credentials.url, credentialsTokenB = credentials.token) - - findLatestMutualVersionAndStoreInformation(credentials = credentials) - - platformRepository.removeCredentialsTokenA(platformUrl = platformUrl) - platformRepository.removeCredentialsTokenB(platformUrl = platformUrl) - - getCredentials( - token = platformRepository.saveCredentialsTokenC( - platformUrl = platformUrl, - credentialsTokenC = generateUUIDv4Token() - ) - ) - } - - override fun put(tokenC: String, credentials: Credentials): OcpiResponseBody = OcpiResponseBody.of { - val platformUrl = platformRepository.getPlatformUrlByTokenC(tokenC) - ?: throw OcpiClientInvalidParametersException("Invalid CREDENTIALS_TOKEN_C ($tokenC)") - - platformRepository.saveCredentialsTokenB(platformUrl = credentials.url, credentialsTokenB = credentials.token) - - findLatestMutualVersionAndStoreInformation(credentials = credentials) - - platformRepository.removeCredentialsTokenA(platformUrl = platformUrl) - platformRepository.removeCredentialsTokenB(platformUrl = platformUrl) - - getCredentials( - token = platformRepository.saveCredentialsTokenC( - platformUrl = platformUrl, - credentialsTokenC = generateUUIDv4Token() - ) - ) - } - - override fun delete( - tokenC: String - ): OcpiResponseBody = OcpiResponseBody.of { - platformRepository - .getPlatformUrlByTokenC(tokenC) - ?.also { platformUrl -> - platformRepository.removeVersion(platformUrl = platformUrl) - platformRepository.removeEndpoints(platformUrl = platformUrl) - platformRepository.removeCredentialsTokenC(platformUrl = platformUrl) - } - ?: throw OcpiClientInvalidParametersException("Invalid CREDENTIALS_TOKEN_C ($tokenC)") - - null - } - - private fun findLatestMutualVersionAndStoreInformation(credentials: Credentials) { - val versions = VersionsClient( - transportClientBuilder = transportClientBuilder, - serverVersionsEndpointUrl = credentials.url, - platformRepository = platformRepository - ) - .getVersions() - .let { - it.data - ?: throw OcpiServerGenericException( - "Could not get versions of sender, there was an error during the call: '${it.status_message}'" - ) - } - - val matchingVersion = versions.firstOrNull { it.version == VersionNumber.V2_1_1.value } - ?: throw OcpiServerNoMatchingEndpointsException("Expected version 2.1.1 from $versions") - - platformRepository.saveVersion(platformUrl = credentials.url, version = matchingVersion) - - val versionDetail = VersionDetailsClient( - transportClientBuilder = transportClientBuilder, - serverVersionsEndpointUrl = credentials.url, - platformRepository = platformRepository - ) - .getVersionDetails() - .let { - it.data - ?: throw OcpiServerGenericException( - "Could not get version of sender, there was an error during the call: '${it.status_message}'" - ) - } - - platformRepository.saveEndpoints(platformUrl = credentials.url, endpoints = versionDetail.endpoints) - } - - private fun getCredentials(token: String): Credentials = Credentials( - token = token, - url = serverVersionsUrl, - business_details = serverBusinessDetails, - party_id = serverPartyId, - country_code = serverCountryCode - ) -} diff --git a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/LocationsCpoClient.kt b/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/LocationsCpoClient.kt deleted file mode 100644 index ccaa40d3..00000000 --- a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/LocationsCpoClient.kt +++ /dev/null @@ -1,177 +0,0 @@ -package com.izivia.ocpi.toolkit.modules.locations - -import com.izivia.ocpi.toolkit.common.* -import com.izivia.ocpi.toolkit.modules.credentials.repositories.PlatformRepository -import com.izivia.ocpi.toolkit.modules.locations.domain.* -import com.izivia.ocpi.toolkit.modules.versions.domain.ModuleID -import com.izivia.ocpi.toolkit.transport.TransportClient -import com.izivia.ocpi.toolkit.transport.TransportClientBuilder -import com.izivia.ocpi.toolkit.transport.domain.HttpMethod -import com.izivia.ocpi.toolkit.transport.domain.HttpRequest - -/** - * Sends calls to an eMSP server - * @property transportClientBuilder used to build transport client - * @property serverVersionsEndpointUrl used to know which platform to communicate with - * @property platformRepository used to get information about the platform (endpoint, token) - */ -class LocationsCpoClient( - private val transportClientBuilder: TransportClientBuilder, - private val serverVersionsEndpointUrl: String, - private val platformRepository: PlatformRepository -) : LocationsEmspInterface { - - private fun buildTransport(): TransportClient = transportClientBuilder - .buildFor( - module = ModuleID.locations, - platformUrl = serverVersionsEndpointUrl, - platformRepository = platformRepository - ) - - override fun getLocation( - countryCode: String, - partyId: String, - locationId: String - ): OcpiResponseBody = - buildTransport() - .send( - HttpRequest( - method = HttpMethod.GET, - path = "/$countryCode/$partyId/$locationId" - ).authenticate(platformRepository = platformRepository, baseUrl = serverVersionsEndpointUrl) - ) - .parseBody() - - override fun getEvse( - countryCode: String, - partyId: String, - locationId: String, - evseUid: String - ): OcpiResponseBody = - buildTransport() - .send( - HttpRequest( - method = HttpMethod.GET, - path = "/$countryCode/$partyId/$locationId/$evseUid" - ).authenticate(platformRepository = platformRepository, baseUrl = serverVersionsEndpointUrl) - ) - .parseBody() - - override fun getConnector( - countryCode: String, - partyId: String, - locationId: String, - evseUid: String, - connectorId: String - ): OcpiResponseBody = - buildTransport() - .send( - HttpRequest( - method = HttpMethod.GET, - path = "/$countryCode/$partyId/$locationId/$evseUid/$connectorId", - ).authenticate(platformRepository = platformRepository, baseUrl = serverVersionsEndpointUrl) - ) - .parseBody() - - override fun putLocation( - countryCode: String, - partyId: String, - locationId: String, - location: Location - ): OcpiResponseBody = - buildTransport() - .send( - HttpRequest( - method = HttpMethod.PUT, - path = "/$countryCode/$partyId/$locationId", - body = mapper.writeValueAsString(location) - ).authenticate(platformRepository = platformRepository, baseUrl = serverVersionsEndpointUrl) - ) - .parseBody() - - override fun putEvse( - countryCode: String, - partyId: String, - locationId: String, - evseUid: String, - evse: Evse - ): OcpiResponseBody = - buildTransport() - .send( - HttpRequest( - method = HttpMethod.PUT, - path = "/$countryCode/$partyId/$locationId/$evseUid", - body = mapper.writeValueAsString(evse) - ).authenticate(platformRepository = platformRepository, baseUrl = serverVersionsEndpointUrl) - ) - .parseBody() - - override fun putConnector( - countryCode: String, - partyId: String, - locationId: String, - evseUid: String, - connectorId: String, - connector: Connector - ): OcpiResponseBody = - buildTransport() - .send( - HttpRequest( - method = HttpMethod.PUT, - path = "/$countryCode/$partyId/$locationId/$evseUid/$connectorId", - body = mapper.writeValueAsString(connector) - ).authenticate(platformRepository = platformRepository, baseUrl = serverVersionsEndpointUrl) - ) - .parseBody() - - override fun patchLocation( - countryCode: String, - partyId: String, - locationId: String, - location: LocationPartial - ): OcpiResponseBody = - buildTransport() - .send( - HttpRequest( - method = HttpMethod.PATCH, - path = "/$countryCode/$partyId/$locationId", - body = mapper.writeValueAsString(location) - ).authenticate(platformRepository = platformRepository, baseUrl = serverVersionsEndpointUrl) - ) - .parseBody() - - override fun patchEvse( - countryCode: String, - partyId: String, - locationId: String, - evseUid: String, - evse: EvsePartial - ): OcpiResponseBody = - buildTransport() - .send( - HttpRequest( - method = HttpMethod.PATCH, - path = "/$countryCode/$partyId/$locationId", - body = mapper.writeValueAsString(evse) - ).authenticate(platformRepository = platformRepository, baseUrl = serverVersionsEndpointUrl) - ) - .parseBody() - - override fun patchConnector( - countryCode: String, - partyId: String, - locationId: String, - evseUid: String, - connectorId: String, - connector: ConnectorPartial - ): OcpiResponseBody = - buildTransport() - .send( - HttpRequest( - method = HttpMethod.PATCH, - path = "/$countryCode/$partyId/$locationId", - body = mapper.writeValueAsString(connector) - ).authenticate(platformRepository = platformRepository, baseUrl = serverVersionsEndpointUrl) - ) - .parseBody() -} diff --git a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/LocationsCpoInterface.kt b/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/LocationsCpoInterface.kt deleted file mode 100644 index 0dd98d2b..00000000 --- a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/LocationsCpoInterface.kt +++ /dev/null @@ -1,65 +0,0 @@ -package com.izivia.ocpi.toolkit.modules.locations - -import com.izivia.ocpi.toolkit.common.OcpiResponseBody -import com.izivia.ocpi.toolkit.common.SearchResult -import com.izivia.ocpi.toolkit.modules.locations.domain.Connector -import com.izivia.ocpi.toolkit.modules.locations.domain.Evse -import com.izivia.ocpi.toolkit.modules.locations.domain.Location -import java.time.Instant - -/** - * CPO Interface - * - * - GET: Fetch a list locations, last updated between the {date_from} and {date_to} (paginated), or get a specific - * location, EVSE or Connector. - * - POST: n/a - * - PUT: n/a - * - PATCH: n/a - * - DELETE: n/a - */ -interface LocationsCpoInterface { - - /** - * If additional parameters: {date_from} and/or {date_to} are provided, only Locations with - * (last_updated) between the given date_from and date_to will be returned. If an EVSE is - * updated, also the 'parent' Location's last_updated fields is updated. If a Connector is - * updated, the EVSE's last_updated and the Location's last_updated field are updated. - * - * This request is paginated, it supports the pagination related URL parameters. - * - * @param dateFrom Instant? Only return Locations that have last_updated after this Date/Time. - * @param dateTo Instant? Only return Locations that have last_updated before this Date/Time. - * @param offset Int? The offset of the first object returned. Default is 0. - * @param limit Int? Maximum number of objects to GET. - * @return List The endpoint returns a list of Location objects The header will - * contain the pagination related headers. - */ - fun getLocations( - dateFrom: Instant?, - dateTo: Instant?, - offset: Int = 0, - limit: Int? - ): OcpiResponseBody> - - /** - * @param locationId String max-length = 39 - */ - fun getLocation(locationId: String): OcpiResponseBody - - /** - * @param locationId String max-length = 39 - * @param evseUid String? max-length = 39 - */ - fun getEvse(locationId: String, evseUid: String): OcpiResponseBody - - /** - * @param locationId String max-length = 39 - * @param evseUid max-length = 39 - * @param connectorId max-length = 36 - */ - fun getConnector( - locationId: String, - evseUid: String, - connectorId: String - ): OcpiResponseBody -} \ No newline at end of file diff --git a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/LocationsCpoServer.kt b/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/LocationsCpoServer.kt deleted file mode 100644 index ddbd8732..00000000 --- a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/LocationsCpoServer.kt +++ /dev/null @@ -1,97 +0,0 @@ -package com.izivia.ocpi.toolkit.modules.locations - -import com.izivia.ocpi.toolkit.common.httpResponse -import com.izivia.ocpi.toolkit.common.checkToken -import com.izivia.ocpi.toolkit.modules.credentials.repositories.PlatformRepository -import com.izivia.ocpi.toolkit.transport.TransportServer -import com.izivia.ocpi.toolkit.transport.domain.FixedPathSegment -import com.izivia.ocpi.toolkit.transport.domain.HttpMethod -import com.izivia.ocpi.toolkit.transport.domain.VariablePathSegment -import kotlinx.coroutines.runBlocking -import java.time.Instant - -/** - * Receives calls from a CPO - * @property transportServer - */ -class LocationsCpoServer( - private val transportServer: TransportServer, - private val platformRepository: PlatformRepository, - private val service: LocationsCpoInterface, - basePath: List = listOf( - FixedPathSegment("/2.1.1/locations") - ) -) { - init { - runBlocking { - transportServer.handle( - method = HttpMethod.GET, - path = basePath, - queryParams = listOf("date_from", "date_to", "offset", "limit"), - filters = listOf(platformRepository::checkToken) - ) { req -> - req.httpResponse { - val dateFrom = req.queryParams["date_from"] - val dateTo = req.queryParams["date_to"] - - service - .getLocations( - dateFrom = dateFrom?.let { Instant.parse(it) }, - dateTo = dateTo?.let { Instant.parse(it) }, - offset = req.queryParams["offset"]?.toInt() ?: 0, - limit = req.queryParams["limit"]?.toInt() - ) - } - } - - transportServer.handle( - method = HttpMethod.GET, - path = basePath + VariablePathSegment("locationId"), - filters = listOf(platformRepository::checkToken) - ) { req -> - req.httpResponse { - service - .getLocation( - locationId = req.pathParams["locationId"]!! - ) - } - } - - transportServer.handle( - method = HttpMethod.GET, - path = basePath + listOf( - VariablePathSegment("locationId"), - VariablePathSegment("evseUid") - ), - filters = listOf(platformRepository::checkToken) - ) { req -> - req.httpResponse { - service - .getEvse( - locationId = req.pathParams["locationId"]!!, - evseUid = req.pathParams["evseUid"]!! - ) - } - } - - transportServer.handle( - method = HttpMethod.GET, - path = basePath + listOf( - VariablePathSegment("locationId"), - VariablePathSegment("evseUid"), - VariablePathSegment("connectorId") - ), - filters = listOf(platformRepository::checkToken) - ) { req -> - req.httpResponse { - service - .getConnector( - locationId = req.pathParams["locationId"]!!, - evseUid = req.pathParams["evseUid"]!!, - connectorId = req.pathParams["connectorId"]!! - ) - } - } - } - } -} diff --git a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/LocationsEmspClient.kt b/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/LocationsEmspClient.kt deleted file mode 100644 index e669338e..00000000 --- a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/LocationsEmspClient.kt +++ /dev/null @@ -1,87 +0,0 @@ -package com.izivia.ocpi.toolkit.modules.locations - -import com.izivia.ocpi.toolkit.common.* -import com.izivia.ocpi.toolkit.modules.credentials.repositories.PlatformRepository -import com.izivia.ocpi.toolkit.modules.locations.domain.Connector -import com.izivia.ocpi.toolkit.modules.locations.domain.Evse -import com.izivia.ocpi.toolkit.modules.locations.domain.Location -import com.izivia.ocpi.toolkit.modules.versions.domain.ModuleID -import com.izivia.ocpi.toolkit.transport.TransportClient -import com.izivia.ocpi.toolkit.transport.TransportClientBuilder -import com.izivia.ocpi.toolkit.transport.domain.HttpMethod -import com.izivia.ocpi.toolkit.transport.domain.HttpRequest -import java.time.Instant - -/** - * Sends calls to the CPO - * @property transportClientBuilder used to build transport client - * @property serverVersionsEndpointUrl used to know which platform to communicate with - * @property platformRepository used to get information about the platform (endpoint, token) - */ -class LocationsEmspClient( - private val transportClientBuilder: TransportClientBuilder, - private val serverVersionsEndpointUrl: String, - private val platformRepository: PlatformRepository -) : LocationsCpoInterface { - - private fun buildTransport(): TransportClient = transportClientBuilder - .buildFor( - module = ModuleID.locations, - platformUrl = serverVersionsEndpointUrl, - platformRepository = platformRepository - ) - - override fun getLocations( - dateFrom: Instant?, - dateTo: Instant?, - offset: Int, - limit: Int? - ): OcpiResponseBody> = - buildTransport() - .send( - HttpRequest( - method = HttpMethod.GET, - queryParams = listOfNotNull( - dateFrom?.let { "date_from" to dateFrom.toString() }, - dateTo?.let { "date_to" to dateTo.toString() }, - "offset" to offset.toString(), - limit?.let { "limit" to limit.toString() } - ).toMap() - ).authenticate(platformRepository = platformRepository, baseUrl = serverVersionsEndpointUrl) - ) - .parsePaginatedBody(offset) - - override fun getLocation(locationId: String): OcpiResponseBody = - buildTransport() - .send( - HttpRequest( - method = HttpMethod.GET, - path = "/$locationId" - ).authenticate(platformRepository = platformRepository, baseUrl = serverVersionsEndpointUrl) - ) - .parseBody() - - override fun getEvse(locationId: String, evseUid: String): OcpiResponseBody = - buildTransport() - .send( - HttpRequest( - method = HttpMethod.GET, - path = "/$locationId/$evseUid" - ).authenticate(platformRepository = platformRepository, baseUrl = serverVersionsEndpointUrl) - ) - .parseBody() - - override fun getConnector( - locationId: String, - evseUid: String, - connectorId: String - ): OcpiResponseBody = - buildTransport() - .send( - HttpRequest( - method = HttpMethod.GET, - path = "/$locationId/$evseUid/$connectorId" - ).authenticate(platformRepository = platformRepository, baseUrl = serverVersionsEndpointUrl) - ) - .parseBody() -} diff --git a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/LocationsEmspInterface.kt b/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/LocationsEmspInterface.kt deleted file mode 100644 index 4568cde6..00000000 --- a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/LocationsEmspInterface.kt +++ /dev/null @@ -1,180 +0,0 @@ -package com.izivia.ocpi.toolkit.modules.locations - -import com.izivia.ocpi.toolkit.common.OcpiResponseBody -import com.izivia.ocpi.toolkit.modules.locations.domain.* - -/** - * Locations is a client owned object, so the end-points need to contain the required extra fields: {party_id} and - * {country_code}. Example endpoint structures: - * - /ocpi/emsp/2.1.1/locations/{country_code}/{party_id}/{location_id} - * - /ocpi/emsp/2.1.1/locations/{country_code}/{party_id}/{location_id}/{evse_uid} - * - /ocpi/emsp/2.1.1/locations/{country_code}/{party_id}/{location_id}/{evse_uid}/{connector_id} - * - * Method: Description - * - GET: Retrieve a Location as it is stored in the eMSP system. - * - POST: n/a (use PUT) - * - PUT: Push new/updated Location, EVSE and/or Connectors to the eMSP - * - PATCH: Notify the eMSP of partial updates to a Location, EVSEs or Connector (such as the status). - * - DELETE: n/a (use PATCH) - */ -interface LocationsEmspInterface { - - /** - * If the CPO wants to check the status of a Location, EVSE or Connector object in the eMSP system, it might GET the - * object from the eMSP system for validation purposes. The CPO is the owner of the objects, so it would be - * illogical if the eMSP system had a different status or was missing an object. If a discrepancy is found, the CPO - * might push an update to the eMSP via a PUT or PATCH call. - * - * @param countryCode (max-length=2) Country code of the CPO requesting this PUT to the eMSP system. - * @param partyId (max-length=3) Party ID (Provider ID) of the CPO requesting this PUT to the eMSP system. - * @param locationId (max-length=39) Location.id of the Location object to retrieve. - */ - fun getLocation( - countryCode: String, - partyId: String, - locationId: String - ): OcpiResponseBody - - /** - * If the CPO wants to check the status of a Location, EVSE or Connector object in the eMSP system, it might GET the - * object from the eMSP system for validation purposes. The CPO is the owner of the objects, so it would be - * illogical if the eMSP system had a different status or was missing an object. If a discrepancy is found, the CPO - * might push an update to the eMSP via a PUT or PATCH call. - * - * @param countryCode (max-length=2) Country code of the CPO requesting this PUT to the eMSP system. - * @param partyId (max-length=3) Party ID (Provider ID) of the CPO requesting this PUT to the eMSP system. - * @param locationId (max-length=39) Location.id of the Location object to retrieve. - * @param evseUid (max-length=39) Evse.uid, required when requesting an EVSE or Connector object. - */ - fun getEvse( - countryCode: String, - partyId: String, - locationId: String, - evseUid: String - ): OcpiResponseBody - - /** - * If the CPO wants to check the status of a Location, EVSE or Connector object in the eMSP system, it might GET the - * object from the eMSP system for validation purposes. The CPO is the owner of the objects, so it would be - * illogical if the eMSP system had a different status or was missing an object. If a discrepancy is found, the CPO - * might push an update to the eMSP via a PUT or PATCH call. - * - * @param countryCode (max-length=2) Country code of the CPO requesting this PUT to the eMSP system. - * @param partyId (max-length=3) Party ID (Provider ID) of the CPO requesting this PUT to the eMSP system. - * @param locationId (max-length=39) Location.id of the Location object to retrieve. - * @param evseUid (max-length=39) Evse.uid, required when requesting an EVSE or Connector object. - * @param connectorId (max-length=36) Connector.id, required when requesting a Connector object. - */ - fun getConnector( - countryCode: String, - partyId: String, - locationId: String, - evseUid: String, - connectorId: String - ): OcpiResponseBody - - /** - * The CPO pushes available Location/EVSE or Connector objects to the eMSP. PUT is used to send new Location objects - * to the eMSP, or to replace existing Locations. - * - * @param countryCode (max-length=2) Country code of the CPO requesting this PUT to the eMSP system. - * @param partyId (max-length=3) Party ID (Provider ID) of the CPO requesting this PUT to the eMSP system. - * @param locationId (max-length=39) Location.id of the new Location object, or the Location of which an EVSE or - * Location object is send - */ - fun putLocation( - countryCode: String, - partyId: String, - locationId: String, - location: Location - ): OcpiResponseBody - - /** - * The CPO pushes available Location/EVSE or Connector objects to the eMSP. PUT is used to send new Location objects - * to the eMSP, or to replace existing Locations. - * - * @param countryCode (max-length=2) Country code of the CPO requesting this PUT to the eMSP system. - * @param partyId (max-length=3) Party ID (Provider ID) of the CPO requesting this PUT to the eMSP system. - * @param locationId (max-length=39) Location.id of the new Location object, or the Location of which an EVSE or - * Location object is send - * @param evseUid (max-length=39) Evse.uid, required when an EVSE or Connector object is send/replaced. - */ - fun putEvse( - countryCode: String, - partyId: String, - locationId: String, - evseUid: String, - evse: Evse - ): OcpiResponseBody - - /** - * The CPO pushes available Location/EVSE or Connector objects to the eMSP. PUT is used to send new Location objects - * to the eMSP, or to replace existing Locations. - * - * @param countryCode (max-length=2) Country code of the CPO requesting this PUT to the eMSP system. - * @param partyId (max-length=3) Party ID (Provider ID) of the CPO requesting this PUT to the eMSP system. - * @param locationId (max-length=39) Location.id of the new Location object, or the Location of which an EVSE or - * Location object is send - * @param evseUid (max-length=39) Evse.uid, required when an EVSE or Connector object is send/replaced. - * @param connectorId (max-length=36) Connector.id, required when a Connector object is send/replaced. - */ - fun putConnector( - countryCode: String, - partyId: String, - locationId: String, - evseUid: String, - connectorId: String, - connector: Connector - ): OcpiResponseBody - - /** - * Same as the PUT method, but only the fields/objects that have to be updated have to be present, other - * fields/objects that are not specified are considered unchanged. - * - * @param countryCode (max-length=2) Country code of the CPO requesting this PUT to the eMSP system. - * @param partyId (max-length=3) Party ID (Provider ID) of the CPO requesting this PUT to the eMSP system. - * @param locationId (max-length=39) Location.id of the new Location object - */ - fun patchLocation( - countryCode: String, - partyId: String, - locationId: String, - location: LocationPartial - ): OcpiResponseBody - - /** - * Same as the PUT method, but only the fields/objects that have to be updated have to be present, other - * fields/objects that are not specified are considered unchanged. - * - * @param countryCode (max-length=2) Country code of the CPO requesting this PUT to the eMSP system. - * @param partyId (max-length=3) Party ID (Provider ID) of the CPO requesting this PUT to the eMSP system. - * @param locationId (max-length=39) Location.id of the Location of which an EVSE or Location object is send - * @param evseUid (max-length=39) Evse.uid, required when an EVSE or Connector object is send/replaced. - */ - fun patchEvse( - countryCode: String, - partyId: String, - locationId: String, - evseUid: String, - evse: EvsePartial - ): OcpiResponseBody - - /** - * Same as the PUT method, but only the fields/objects that have to be updated have to be present, other - * fields/objects that are not specified are considered unchanged. - * - * @param countryCode (max-length=2) Country code of the CPO requesting this PUT to the eMSP system. - * @param partyId (max-length=3) Party ID (Provider ID) of the CPO requesting this PUT to the eMSP system. - * @param locationId (max-length=39) Location.id of the Location of which an EVSE or Location object is send - * @param evseUid (max-length=39) Evse.uid, required when an EVSE or Connector object is send/replaced. - * @param connectorId (max-length=36) Connector.id, required when a Connector object is send/replaced. - */ - fun patchConnector( - countryCode: String, - partyId: String, - locationId: String, - evseUid: String, - connectorId: String, - connector: ConnectorPartial - ): OcpiResponseBody -} \ No newline at end of file diff --git a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/LocationsEmspServer.kt b/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/LocationsEmspServer.kt deleted file mode 100644 index c8469991..00000000 --- a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/LocationsEmspServer.kt +++ /dev/null @@ -1,224 +0,0 @@ -package com.izivia.ocpi.toolkit.modules.locations - -import com.izivia.ocpi.toolkit.common.httpResponse -import com.izivia.ocpi.toolkit.common.mapper -import com.izivia.ocpi.toolkit.common.checkToken -import com.izivia.ocpi.toolkit.modules.credentials.repositories.PlatformRepository -import com.izivia.ocpi.toolkit.modules.locations.domain.* -import com.izivia.ocpi.toolkit.transport.TransportServer -import com.izivia.ocpi.toolkit.transport.domain.FixedPathSegment -import com.izivia.ocpi.toolkit.transport.domain.HttpMethod -import com.izivia.ocpi.toolkit.transport.domain.VariablePathSegment -import kotlinx.coroutines.runBlocking - -/** - * Receives calls from a CPO - * @property transportServer - */ -class LocationsEmspServer( - private val transportServer: TransportServer, - private val platformRepository: PlatformRepository, - private val service: LocationsEmspInterface, - basePath: List = listOf( - FixedPathSegment("/2.1.1/locations") - ) -) { - init { - runBlocking { - transportServer.handle( - method = HttpMethod.GET, - path = basePath + listOf( - VariablePathSegment("countryCode"), - VariablePathSegment("partyId"), - VariablePathSegment("locationId") - ), - filters = listOf(platformRepository::checkToken) - ) { req -> - req.httpResponse { - service - .getLocation( - countryCode = req.pathParams["countryCode"]!!, - partyId = req.pathParams["partyId"]!!, - locationId = req.pathParams["locationId"]!! - ) - } - } - - transportServer.handle( - method = HttpMethod.GET, - path = basePath + listOf( - VariablePathSegment("countryCode"), - VariablePathSegment("partyId"), - VariablePathSegment("locationId"), - VariablePathSegment("evseUid") - ), - filters = listOf(platformRepository::checkToken) - ) { req -> - req.httpResponse { - service - .getEvse( - countryCode = req.pathParams["countryCode"]!!, - partyId = req.pathParams["partyId"]!!, - locationId = req.pathParams["locationId"]!!, - evseUid = req.pathParams["evseUid"]!! - ) - } - } - - transportServer.handle( - method = HttpMethod.GET, - path = basePath + listOf( - VariablePathSegment("countryCode"), - VariablePathSegment("partyId"), - VariablePathSegment("locationId"), - VariablePathSegment("evseUid"), - VariablePathSegment("connectorId") - ), - filters = listOf(platformRepository::checkToken) - ) { req -> - req.httpResponse { - service - .getConnector( - countryCode = req.pathParams["countryCode"]!!, - partyId = req.pathParams["partyId"]!!, - locationId = req.pathParams["locationId"]!!, - evseUid = req.pathParams["evseUid"]!!, - connectorId = req.pathParams["connectorId"]!! - ) - } - } - - transportServer.handle( - method = HttpMethod.PUT, - path = basePath + listOf( - VariablePathSegment("countryCode"), - VariablePathSegment("partyId"), - VariablePathSegment("locationId") - ), - filters = listOf(platformRepository::checkToken) - ) { req -> - req.httpResponse { - service - .putLocation( - countryCode = req.pathParams["countryCode"]!!, - partyId = req.pathParams["partyId"]!!, - locationId = req.pathParams["locationId"]!!, - location = mapper.readValue(req.body, Location::class.java) - ) - } - } - - transportServer.handle( - method = HttpMethod.PUT, - path = basePath + listOf( - VariablePathSegment("countryCode"), - VariablePathSegment("partyId"), - VariablePathSegment("locationId"), - VariablePathSegment("evseUid") - ), - filters = listOf(platformRepository::checkToken) - ) { req -> - req.httpResponse { - service - .putEvse( - countryCode = req.pathParams["countryCode"]!!, - partyId = req.pathParams["partyId"]!!, - locationId = req.pathParams["locationId"]!!, - evseUid = req.pathParams["evseUid"]!!, - evse = mapper.readValue(req.body!!, Evse::class.java) - ) - } - } - - transportServer.handle( - method = HttpMethod.PUT, - path = basePath + listOf( - VariablePathSegment("countryCode"), - VariablePathSegment("partyId"), - VariablePathSegment("locationId"), - VariablePathSegment("evseUid"), - VariablePathSegment("connectorId") - ), - filters = listOf(platformRepository::checkToken) - ) { req -> - req.httpResponse { - service - .putConnector( - countryCode = req.pathParams["countryCode"]!!, - partyId = req.pathParams["partyId"]!!, - locationId = req.pathParams["locationId"]!!, - evseUid = req.pathParams["evseUid"]!!, - connectorId = req.pathParams["connectorId"]!!, - connector = mapper.readValue(req.body!!, Connector::class.java) - ) - } - } - - transportServer.handle( - method = HttpMethod.PATCH, - path = basePath + listOf( - VariablePathSegment("countryCode"), - VariablePathSegment("partyId"), - VariablePathSegment("locationId") - ), - filters = listOf(platformRepository::checkToken) - ) { req -> - req.httpResponse { - service - .patchLocation( - countryCode = req.pathParams["countryCode"]!!, - partyId = req.pathParams["partyId"]!!, - locationId = req.pathParams["locationId"]!!, - location = mapper.readValue(req.body!!, LocationPartial::class.java) - ) - } - } - - transportServer.handle( - method = HttpMethod.PATCH, - path = basePath + listOf( - VariablePathSegment("countryCode"), - VariablePathSegment("partyId"), - VariablePathSegment("locationId"), - VariablePathSegment("evseUid") - ), - filters = listOf(platformRepository::checkToken) - ) { req -> - req.httpResponse { - service - .patchEvse( - countryCode = req.pathParams["countryCode"]!!, - partyId = req.pathParams["partyId"]!!, - locationId = req.pathParams["locationId"]!!, - evseUid = req.pathParams["evseUid"]!!, - evse = mapper.readValue(req.body!!, EvsePartial::class.java) - ) - } - } - - transportServer.handle( - method = HttpMethod.PATCH, - path = basePath + listOf( - VariablePathSegment("countryCode"), - VariablePathSegment("partyId"), - VariablePathSegment("locationId"), - VariablePathSegment("evseUid"), - VariablePathSegment("connectorId") - ), - filters = listOf(platformRepository::checkToken) - ) { req -> - req.httpResponse { - service - .patchConnector( - countryCode = req.pathParams["countryCode"]!!, - partyId = req.pathParams["partyId"]!!, - locationId = req.pathParams["locationId"]!!, - evseUid = req.pathParams["evseUid"]!!, - connectorId = req.pathParams["connectorId"]!!, - connector = mapper.readValue(req.body!!, ConnectorPartial::class.java) - ) - } - } - } - } -} diff --git a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/AdditionalGeoLocation.kt b/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/AdditionalGeoLocation.kt deleted file mode 100644 index b1ee5c47..00000000 --- a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/AdditionalGeoLocation.kt +++ /dev/null @@ -1,22 +0,0 @@ -package com.izivia.ocpi.toolkit.modules.locations.domain - -import com.izivia.ocpi.toolkit.annotations.Partial -import com.izivia.ocpi.toolkit.modules.types.DisplayText - -/** - * This class defines an additional geolocation that is relevant for the Charge Point. The geodetic system to be used - * is WGS 84. - * - * @property latitude String (max-length=10) Latitude of the point in decimal degree. Example: 50.770774. Decimal - * separator: "." Regex: -?[0-9]{1,2}\.[0-9]{6} - * @property longitude String (max-length=11) Longitude of the point in decimal degree. Example: -126.104965. Decimal - * separator: "." Regex: -?[0-9]{1,3}\.[0-9]{6} - * @property name DisplayText? Name of the point in local language or as written at the location. For example the street - * name of a parking lot entrance, or its number. - */ -@Partial -data class AdditionalGeoLocation( - val latitude: String, - val longitude: String, - val name: DisplayText? -) diff --git a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/BusinessDetails.kt b/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/BusinessDetails.kt deleted file mode 100644 index 647fa96e..00000000 --- a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/BusinessDetails.kt +++ /dev/null @@ -1,16 +0,0 @@ -package com.izivia.ocpi.toolkit.modules.locations.domain - -import com.izivia.ocpi.toolkit.annotations.Partial - -/** - * @property name (max-length=100) Name of the operator. - * @property website Link (string(255) type following the w3.org spec. to the operator's website. - * @property logo Image link to the operator's logo. - * @constructor - */ -@Partial -data class BusinessDetails( - val name: String, - val website: String?, - val logo: Image? -) \ No newline at end of file diff --git a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/Capability.kt b/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/Capability.kt deleted file mode 100644 index 77193eb5..00000000 --- a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/Capability.kt +++ /dev/null @@ -1,36 +0,0 @@ -package com.izivia.ocpi.toolkit.modules.locations.domain - -/** - * The capabilities of an EVSE. - */ -enum class Capability { - /** - * The EVSE supports charging profiles. Sending Charging Profiles is not yet supported by OCPI. - */ - CHARGING_PROFILE_CAPABLE, - - /** - * Charging at this EVSE can be payed with credit card. - */ - CREDIT_CARD_PAYABLE, - - /** - * The EVSE can remotely be started/stopped. - */ - REMOTE_START_STOP_CAPABLE, - - /** - * The EVSE can be reserved. - */ - RESERVABLE, - - /** - * Charging at this EVSE can be authorized with an RFID token - */ - RFID_READER, - - /** - * Connectors have mechanical lock that can be requested by the eMSP to be unlocked. - */ - UNLOCK_CAPABLE -} diff --git a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/Connector.kt b/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/Connector.kt deleted file mode 100644 index 236ff947..00000000 --- a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/Connector.kt +++ /dev/null @@ -1,34 +0,0 @@ -package com.izivia.ocpi.toolkit.modules.locations.domain - -import com.izivia.ocpi.toolkit.annotations.Partial -import java.time.Instant - -/** - * A connector is the socket or cable available for the EV to use. A single EVSE may provide multiple connectors but - * only one of them can be in use at the same time. A connector always belongs to an EVSE object. - * - * @property id (max-length=36) Identifier of the connector within the EVSE. Two connectors may have the same id as long - * as they do not belong to the same EVSE object. - * @property standard The standard of the installed connector. - * @property format The format (socket/cable) of the installed connector. - * @property power_type - * @property voltage Voltage of the connector (line to neutral for AC_3_PHASE), in volt V. - * @property amperage maximum amperage of the connector, in ampere A. - * @property tariff_id (max-length=36) Identifier of the current charging tariff structure. For a "Free of Charge" - * tariff this field should be set, and point to a defined "Free of Charge" tariff. - * @property terms_and_conditions URL (string(255) type following the w3.org spec. to the operator's terms and - * conditions - * @property last_updated Timestamp when this Connectors was last updated (or created). - */ -@Partial -data class Connector( - val id: String, - val standard: ConnectorType, - val format: ConnectorFormat, - val power_type: PowerType, - val voltage: Int, - val amperage: Int, - val tariff_id: String?, - val terms_and_conditions: String?, - val last_updated: Instant -) \ No newline at end of file diff --git a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/ConnectorFormat.kt b/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/ConnectorFormat.kt deleted file mode 100644 index 0b0f38bc..00000000 --- a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/ConnectorFormat.kt +++ /dev/null @@ -1,16 +0,0 @@ -package com.izivia.ocpi.toolkit.modules.locations.domain - -/** - * The format of the connector, whether it is a socket or a plug. - */ -enum class ConnectorFormat { - /** - * The connector is a socket; the EV user needs to bring a fitting plug. - */ - SOCKET, - - /** - * The connector is an attached cable; the EV users car needs to have a fitting inlet. - */ - CABLE -} \ No newline at end of file diff --git a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/ConnectorType.kt b/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/ConnectorType.kt deleted file mode 100644 index 1d1a3ba2..00000000 --- a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/ConnectorType.kt +++ /dev/null @@ -1,131 +0,0 @@ -package com.izivia.ocpi.toolkit.modules.locations.domain - -/** - * The socket or plug standard of the charging point. - */ -enum class ConnectorType { - /** - * The connector type is CHAdeMO, DC - */ - CHADEMO, - - /** - * Standard/Domestic household, type "A", NEMA 1-15, 2 pins - */ - DOMESTIC_A, - - /** - * Standard/Domestic household, type "B", NEMA 5-15, 3 pins - */ - DOMESTIC_B, - - /** - * Standard/Domestic household, type "C", CEE 7/17, 2 pins - */ - DOMESTIC_C, - - /** - * Standard/Domestic household, type "D", 3 pin - */ - DOMESTIC_D, - - /** - * Standard/Domestic household, type "E", CEE 7/5 3 pins - */ - DOMESTIC_E, - - /** - * Standard/Domestic household, type "F", CEE 7/4, Schuko, 3 pins - */ - DOMESTIC_F, - - /** - * Standard/Domestic household, type "G", BS 1363, Commonwealth, 3 pins - */ - DOMESTIC_G, - - /** - * Standard/Domestic household, type "H", SI-32, 3 pins - */ - DOMESTIC_H, - - /** - * Standard/Domestic household, type "I", AS 3112, 3 pins - */ - DOMESTIC_I, - - /** - * Standard/Domestic household, type "J", SEV 1011, 3 pins - */ - DOMESTIC_J, - - /** - * Standard/Domestic household, type "K", DS 60884-2-D1, 3 pins - */ - DOMESTIC_K, - - /** - * Standard/Domestic household, type "L", CEI 23-16-VII, 3 pins - */ - DOMESTIC_L, - - /** - * IEC 60309-2 Industrial Connector single phase 16 Amperes (usually blue) - */ - IEC_60309_2_single_16, - - /** - * IEC 60309-2 Industrial Connector three phase 16 Amperes (usually red) - */ - IEC_60309_2_three_16, - - /** - * IEC 60309-2 Industrial Connector three phase 32 Amperes (usually red) - */ - IEC_60309_2_three_32, - - /** - * IEC 60309-2 Industrial Connector three phase 64 Amperes (usually red) - */ - IEC_60309_2_three_64, - - /** - * IEC 62196 Type 1 "SAE J1772" - */ - IEC_62196_T1, - - /** - * Combo Type 1 based, DC - */ - IEC_62196_T1_COMBO, - - /** - * IEC 62196 Type 2 "Mennekes" - */ - IEC_62196_T2, - - /** - * Combo Type 2 based, DC - */ - IEC_62196_T2_COMBO, - - /** - * IEC 62196 Type 3A - */ - IEC_62196_T3A, - - /** - * IEC 62196 Type 3C "Scame" - */ - IEC_62196_T3C, - - /** - * Tesla Connector "Roadster"-type (round, 4 pin) - */ - TESLA_R, - - /** - * Tesla Connector "Model-S"-type (oval, 5 pin) - */ - TESLA_S -} \ No newline at end of file diff --git a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/EnergyMix.kt b/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/EnergyMix.kt deleted file mode 100644 index b4e2c481..00000000 --- a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/EnergyMix.kt +++ /dev/null @@ -1,28 +0,0 @@ -package com.izivia.ocpi.toolkit.modules.locations.domain - -import com.izivia.ocpi.toolkit.annotations.Partial - -/** - * This type is used to specify the energy mix and environmental impact of the supplied energy at a location or in a - * tariff. - * - * @property is_green_energy True if 100% from regenerative sources. (CO2 and nuclear waste is zero) - * @property energy_sources Key-value pairs (enum + percentage) of energy sources of this location's tariff. - * @property environ_impact Key-value pairs (enum + percentage) of nuclear waste and CO2 exhaust of this location's - * tariff. - * @property supplier_name (max-length=64) Name of the energy supplier, delivering the energy for this location or - * tariff. ** - * @property energy_product_name (max-length=64) Name of the energy suppliers product/tariff plan used at this - * location. ** - * - * ** These fields can be used to look-up energy qualification or to show it directly to the customer (for well-known - * brands like Greenpeace Energy, etc.) - */ -@Partial -data class EnergyMix( - val is_green_energy: Boolean, - val energy_sources: List?, - val environ_impact: List?, - val supplier_name: String?, - val energy_product_name: String? -) \ No newline at end of file diff --git a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/EnergySource.kt b/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/EnergySource.kt deleted file mode 100644 index de37b4a9..00000000 --- a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/EnergySource.kt +++ /dev/null @@ -1,16 +0,0 @@ -package com.izivia.ocpi.toolkit.modules.locations.domain - -import com.izivia.ocpi.toolkit.annotations.Partial -import java.math.BigDecimal - -/** - * Key-value pairs (enum + percentage) of energy sources. All given values should add up to 100 percent per category. - * - * @property source The type of energy source. - * @property percentage Percentage of this source (0-100) in the mix. - */ -@Partial -data class EnergySource( - val source: EnergySourceCategory, - val percentage: BigDecimal -) diff --git a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/EnergySourceCategory.kt b/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/EnergySourceCategory.kt deleted file mode 100644 index 2df3e7ed..00000000 --- a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/EnergySourceCategory.kt +++ /dev/null @@ -1,46 +0,0 @@ -package com.izivia.ocpi.toolkit.modules.locations.domain - -/** - * Categories of energy sources. - */ -enum class EnergySourceCategory { - /** - * Nuclear power sources. - */ - NUCLEAR, - - /** - * All kinds of fossil power sources. - */ - GENERAL_FOSSIL, - - /** - * Fossil power from coal. - */ - COAL, - - /** - * Fossil power from gas. - */ - GAS, - - /** - * All kinds of regenerative power sources. - */ - GENERAL_GREEN, - - /** - * Regenerative power from PV. - */ - SOLAR, - - /** - * Regenerative power from wind turbines. - */ - WIND, - - /** - * Regenerative power from water turbines. - */ - WATER -} \ No newline at end of file diff --git a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/EnvironmentalImpact.kt b/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/EnvironmentalImpact.kt deleted file mode 100644 index e1755b85..00000000 --- a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/EnvironmentalImpact.kt +++ /dev/null @@ -1,15 +0,0 @@ -package com.izivia.ocpi.toolkit.modules.locations.domain - -import com.izivia.ocpi.toolkit.annotations.Partial -import java.math.BigDecimal - -/** - * Key-value pairs (enum + amount) of waste and carbon dioxide emittion per kWh. - * @property source The category of this value. - * @property amount Amount of this portion in g/kWh. - */ -@Partial -data class EnvironmentalImpact( - val source: EnvironmentalImpactCategory, - val amount: BigDecimal -) \ No newline at end of file diff --git a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/EnvironmentalImpactCategory.kt b/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/EnvironmentalImpactCategory.kt deleted file mode 100644 index 715274c5..00000000 --- a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/EnvironmentalImpactCategory.kt +++ /dev/null @@ -1,16 +0,0 @@ -package com.izivia.ocpi.toolkit.modules.locations.domain - -/** - * Categories of environmental impact values. - */ -enum class EnvironmentalImpactCategory { - /** - * Produced nuclear waste in gramms per kilowatthour - */ - NUCLEAR_WASTE, - - /** - * Exhausted carbon dioxide in gramms per kilowarrhour - */ - CARBON_DIOXIDE -} diff --git a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/Evse.kt b/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/Evse.kt deleted file mode 100644 index 087d91b5..00000000 --- a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/Evse.kt +++ /dev/null @@ -1,54 +0,0 @@ -package com.izivia.ocpi.toolkit.modules.locations.domain - -import com.izivia.ocpi.toolkit.annotations.Partial -import com.izivia.ocpi.toolkit.modules.types.DisplayText -import java.time.Instant - -/** - * The EVSE object describes the part that controls the power supply to a single EV in a single session. It always - * belongs to a Location object. It will only contain directions to get from the location to the EVSE (i.e. floor, - * physical_reference or directions). When these properties are insufficient to reach the EVSE from the Location point, - * then it typically indicates that this EVSE should be put in a different Location object (sometimes with the same - * address but with different coordinates/directions). - * - * An EVSE object has a list of connectors which can not be used simultaneously: only one connector per EVSE can be used - * at the time. - * - * @property uid (max-length=39) Uniquely identifies the EVSE within the CPOs platform (and suboperator platforms). For - * example a database unique ID or the "EVSE ID". This field can never be changed, modified or renamed. This is the - * 'technical' identification of the EVSE, not to be used as 'human readable' identification, use the field: evse_id for - * that. - * @property evse_id Compliant with the following specification for EVSE ID from "eMI3 standard version V1.0" - * (http://emi3group.com/documents-links/) "Part 2: business objects." Optional because: if an EVSE ID is to be re-used - * the EVSE ID can be removed from an EVSE that is removed (status: REMOVED) - * @property status Indicates the current status of the EVSE. - * @property status_schedule Indicates a planned status in the future of the EVSE. - * @property capabilities List of functionalities that the EVSE is capable of. - * @property connectors (at least one in the list) List of available connectors on the EVSE. - * @property floor_level (max-length=4) Level on which the charging station is located (in garage buildings) in the - * locally displayed numbering scheme. - * @property coordinates Coordinates of the EVSE. - * @property physical_reference (max-length=16) A number/string printed on the outside of the EVSE for visual - * identification. - * @property directions Multi-language human-readable directions when more detailed information on how to reach the EVSE - * from the Location is required. - * @property parking_restrictions The restrictions that apply to the parking spot. - * @property images Links to images related to the EVSE such as photos or logos. - * @property last_updated Instant Timestamp when this EVSE or one of its Connectors was last updated (or created). - */ -@Partial -data class Evse( - val uid: String, - val evse_id: String?, - val status: Status, - val status_schedule: List?, - val capabilities: List?, - val connectors: List, - val floor_level: String?, - val coordinates: GeoLocation?, - val physical_reference: String?, - val directions: List?, - val parking_restrictions: List?, - val images: List?, - val last_updated: Instant -) diff --git a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/ExceptionalPeriod.kt b/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/ExceptionalPeriod.kt deleted file mode 100644 index edf1eb97..00000000 --- a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/ExceptionalPeriod.kt +++ /dev/null @@ -1,16 +0,0 @@ -package com.izivia.ocpi.toolkit.modules.locations.domain - -import com.izivia.ocpi.toolkit.annotations.Partial -import java.time.Instant - -/** - * Specifies one exceptional period for opening or access hours. - * - * @property period_begin Begin of the exception. - * @property period_end End of the exception. - */ -@Partial -data class ExceptionalPeriod( - val period_begin: Instant, - val period_end: Instant -) \ No newline at end of file diff --git a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/Facility.kt b/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/Facility.kt deleted file mode 100644 index f62a7983..00000000 --- a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/Facility.kt +++ /dev/null @@ -1,83 +0,0 @@ -package com.izivia.ocpi.toolkit.modules.locations.domain - -enum class Facility { - /** - * A hotel. - */ - HOTEL, - - /** - * A restaurant. - */ - RESTAURANT, - - /** - * A cafe. - */ - CAFE, - - /** - * A mall or shopping center. - */ - MALL, - - /** - * A supermarket. - */ - SUPERMARKET, - - /** - * Sport facilities: gym, field etc. - */ - SPORT, - - /** - * A Recreation area. - */ - RECREATION_AREA, - - /** - * Located in, or close to, a park, nature reserve/park etc. - */ - NATURE, - - /** - * A museum. - */ - MUSEUM, - - /** - * A bus stop. - */ - BUS_STOP, - - /** - * A taxi stand. - */ - TAXI_STAND, - - /** - * A train station. - */ - TRAIN_STATION, - - /** - * An airport. - */ - AIRPORT, - - /** - * A carpool parking. - */ - CARPOOL_PARKING, - - /** - * A Fuel station. - */ - FUEL_STATION, - - /** - * Wifi or other type of internet available. - */ - WIFI -} diff --git a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/GeoLocation.kt b/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/GeoLocation.kt deleted file mode 100644 index b4c90033..00000000 --- a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/GeoLocation.kt +++ /dev/null @@ -1,17 +0,0 @@ -package com.izivia.ocpi.toolkit.modules.locations.domain - -import com.izivia.ocpi.toolkit.annotations.Partial - -/** - * This class defines the geolocation of the Charge Point. The geodetic system to be used is WGS 84. - * - * @property latitude (max-length=10) Latitude of the point in decimal degree. Example: 50.770774. Decimal - * separator: "." Regex: -?[0-9]{1,2}\.[0-9]{6} - * @property longitude (max-length=11) Longitude of the point in decimal degree. Example: -126.104965. Decimal - * separator: "." Regex: -?[0-9]{1,3}\.[0-9]{6} - */ -@Partial -data class GeoLocation( - val latitude: String, - val longitude: String -) \ No newline at end of file diff --git a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/Hours.kt b/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/Hours.kt deleted file mode 100644 index c04d460d..00000000 --- a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/Hours.kt +++ /dev/null @@ -1,23 +0,0 @@ -package com.izivia.ocpi.toolkit.modules.locations.domain - -import com.izivia.ocpi.toolkit.annotations.Partial - -/** - * Opening and access hours of the location. - * Either regularHours or twentyFourSeven is set. Both cannot be null and both cannot be set. - * - * @property regular_hours Regular hours, weekday based. Should not be set for representing 24/7 as this is the most - * common case. - * @property twenty_four_seven True to represent 24 hours a day and 7 days a week, except the given exceptions. - * @property exceptional_openings Exceptions for specified calendar dates, time-range based. Periods the station is - * operating/accessible. Additional to regular hours. May overlap regular rules. - * @property exceptional_closings Exceptions for specified calendar dates, time-range based. Periods the station is not - * operating/accessible. Overwriting regularHours and exceptionalOpenings. Should not overlap exceptionalOpenings. - */ -@Partial -data class Hours( - val regular_hours: List?, - val twenty_four_seven: Boolean?, - val exceptional_openings: List?, - val exceptional_closings: List? -) \ No newline at end of file diff --git a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/Image.kt b/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/Image.kt deleted file mode 100644 index e8aec7c4..00000000 --- a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/Image.kt +++ /dev/null @@ -1,39 +0,0 @@ -package com.izivia.ocpi.toolkit.modules.locations.domain - -import com.izivia.ocpi.toolkit.annotations.Partial - -/** - * This class references images related to a EVSE in terms of a file name or url. According to the roaming connection - * between one EVSE Operator and one or more Navigation Service Providers the hosting or file exchange of image payload - * data has to be defined. The exchange of this content data is out of scope of OCHP. However, the recommended setup is - * a public available web server hosted and updated by the EVSE Operator. Per charge point an unlimited number of images - * of each type is allowed. Recommended are at least two images where one is a network or provider logo and the second - * is a station photo. If two images of the same type are defined they should be displayed additionally, not optionally. - * - * Photo Dimensions: The recommended dimensions for all photos is a minimum of 800 pixels wide and 600 pixels height. - * Thumbnail representations for photos should always have the same orientation as the original with a size of 200 to - * 200 pixels. - * - * Logo Dimensions: The recommended dimensions for logos are exactly 512 pixels wide and 512 pixels height. Thumbnail - * representations for logos should be exactly 128 pixels in width and height. If not squared, thumbnails should have - * the same orientation as the original. - * - * @property url URL (string(255) type following the w3.org spec. from where the image data can be fetched through a - * web browser. - * @property thumbnail URL (string(255) type following the w3.org spec. from where a thumbnail of the image can - * be fetched through a web browser. - * @property category Describes what the image is used for. - * @property type (max-length=4) Image type like: gif, jpeg, png, svg - * @property width (max-length=5) - * @property height (max-length=5) - * @constructor - */ -@Partial -data class Image( - val url: String, - val thumbnail: String?, - val category: ImageCategory, - val type: String, - val width: Int?, - val height: Int? -) \ No newline at end of file diff --git a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/ImageCategory.kt b/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/ImageCategory.kt deleted file mode 100644 index 2bcb4f82..00000000 --- a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/ImageCategory.kt +++ /dev/null @@ -1,45 +0,0 @@ -package com.izivia.ocpi.toolkit.modules.locations.domain - -/** - * The category of an image to obtain the correct usage in a user presentation. The category has to be set accordingly - * to the image content in order to guarantee the right usage. - */ -enum class ImageCategory { - /** - * Photo of the physical device that contains one or more EVSEs. - */ - CHARGER, - - /** - * Location entrance photo. Should show the car entrance to the location from street side. - */ - ENTRANCE, - - /** - * Location overview photo. - */ - LOCATION, - - /** - * Logo of an associated roaming network to be displayed with the EVSE for example in lists, maps and detailed - * information view - */ - NETWORK, - - /** - * Logo of the charge points operator, for example a municipality, to be displayed with the EVSEs detailed - * information view or in lists and maps, if no networkLogo is present - */ - OPERATOR, - - /** - * Other - */ - OTHER, - - /** - * Logo of the charge points owner, for example a local store, to be displayed with the EVSEs detailed information - * view - */ - OWNER, -} \ No newline at end of file diff --git a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/Location.kt b/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/Location.kt deleted file mode 100644 index 644d81ba..00000000 --- a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/Location.kt +++ /dev/null @@ -1,63 +0,0 @@ -package com.izivia.ocpi.toolkit.modules.locations.domain - -import com.izivia.ocpi.toolkit.annotations.Partial -import com.izivia.ocpi.toolkit.modules.types.DisplayText -import java.time.Instant - -/** - * The Location object describes the location and its properties where a group of EVSEs that belong together are - * installed. Typically, the Location object is the exact location of the group of EVSEs, but it can also be the entrance - * of a parking garage which contains these EVSEs. The exact way to reach each EVSE can be further specified by its own - * properties. - * - * @property id (max-length=39) Uniquely identifies the location within the CPOs platform (and suboperator platforms). - * This field can never be changed, modified or renamed. - * @property type The general type of the charge point location. - * @property name (max-length=255) Display name of the location. - * @property address (max-length=45) Street/block name and house number if available. - * @property city (max-length=45) City or town. - * @property postal_code (max-length=10) Postal code of the location. - * @property country (max-length=3) ISO 3166-1 alpha-3 code for the country of this location. - * @property coordinates Coordinates of the location. - * @property related_locations Geographical location of related points relevant to the user. - * @property evses List of EVSEs that belong to this Location. - * @property directions Human-readable directions on how to reach the location. - * @property operator Information of the operator. When not specified, the information retrieved from the api_info - * endpoint should be used instead. - * @property suboperator Information of the suboperator if available. - * @property owner Information of the owner if available. - * @property facilities Optional list of facilities this charge location directly belongs to. - * @property time_zone (max-length=255) One of IANA tzdata's TZ-values representing the time zone of the location. - * Examples: "Europe/Oslo", "Europe/Zurich". (http://www.iana.org/time-zones) - * @property opening_times The times when the EVSEs at the location can be accessed for charging. - * @property charging_when_closed Indicates if the EVSEs are still charging outside the opening hours of the location. - * E.g. when the parking garage closes its barriers overnight, is it allowed to charge till the next morning? - * Default: true - * @property images Links to images related to the location such as photos or logos. - * @property energy_mix Details on the energy supplied at this location. - * @property last_updated Timestamp when this Location or one of its EVSEs or Connectors were last updated (or created). - */ -@Partial -data class Location( - val id: String, - val type: LocationType, - val name: String?, - val address: String, - val city: String, - val postal_code: String, - val country: String, - val coordinates: GeoLocation, - val related_locations: List?, - val evses: List?, - val directions: List?, - val operator: BusinessDetails?, - val suboperator: BusinessDetails?, - val owner: BusinessDetails?, - val facilities: List?, - val time_zone: String?, - val opening_times: Hours?, - val charging_when_closed: Boolean?, - val images: List?, - val energy_mix: EnergyMix?, - val last_updated: Instant -) diff --git a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/LocationType.kt b/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/LocationType.kt deleted file mode 100644 index 8a5e06de..00000000 --- a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/LocationType.kt +++ /dev/null @@ -1,36 +0,0 @@ -package com.izivia.ocpi.toolkit.modules.locations.domain - -/** - * Reflects the general type of the charge points location. May be used for user information. - */ -enum class LocationType { - /** - * Parking in public space. - */ - ON_STREET, - - /** - * Multistory car park. - */ - PARKING_GARAGE, - - /** - * Multistory car park, mainly underground. - */ - UNDERGROUND_GARAGE, - - /** - * A cleared area that is intended for parking vehicles, i.e. at super markets, bars, etc. - */ - PARKING_LOT, - - /** - * None of the given possibilities. - */ - OTHER, - - /** - * Parking location type is not known by the operator (default). - */ - UNKNOWN -} \ No newline at end of file diff --git a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/ParkingRestriction.kt b/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/ParkingRestriction.kt deleted file mode 100644 index 9eb7bc9e..00000000 --- a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/ParkingRestriction.kt +++ /dev/null @@ -1,31 +0,0 @@ -package com.izivia.ocpi.toolkit.modules.locations.domain - -/** - * This value, if provided, represents the restriction to the parking spot for different purposes. - */ -enum class ParkingRestriction { - /** - * Reserved parking spot for electric vehicles. - */ - EV_ONLY, - - /** - * Parking is only allowed while plugged in (charging). - */ - PLUGGED, - - /** - * Reserved parking spot for disabled people with valid ID. - */ - DISABLED, - - /** - * Parking spot for customers/guests only, for example in case of a hotel or shop. - */ - CUSTOMERS, - - /** - * Parking spot only suitable for (electric) motorcycles or scooters. - */ - MOTORCYCLES -} \ No newline at end of file diff --git a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/PowerType.kt b/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/PowerType.kt deleted file mode 100644 index ed733fae..00000000 --- a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/PowerType.kt +++ /dev/null @@ -1,18 +0,0 @@ -package com.izivia.ocpi.toolkit.modules.locations.domain - -enum class PowerType { - /** - * AC mono phase. - */ - AC_1_PHASE, - - /** - * AC 3 phase. - */ - AC_3_PHASE, - - /** - * Direct Current. - */ - DC -} \ No newline at end of file diff --git a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/RegularHours.kt b/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/RegularHours.kt deleted file mode 100644 index 0a41058a..00000000 --- a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/RegularHours.kt +++ /dev/null @@ -1,19 +0,0 @@ -package com.izivia.ocpi.toolkit.modules.locations.domain - -import com.izivia.ocpi.toolkit.annotations.Partial - -/** - * Regular recurring operation or access hours - * - * @property weekday (max-length=1) Number of day in the week, from Monday (1) till Sunday (7) - * @property period_begin (max-length=5) Begin of the regular period given in hours and minutes. Must be in 24h format - * with leading zeros. Example: "18:15". Hour/Minute separator: ":" Regex: ([0-1][0-9]|2[0-3]):[0-5][0-9] - * @property period_end (max-length=5) End of the regular period, syntax as for periodBegin. Must be later than - * periodBegin. - */ -@Partial -data class RegularHours( - val weekday: Int, - val period_begin: String, - val period_end: String -) \ No newline at end of file diff --git a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/Status.kt b/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/Status.kt deleted file mode 100644 index 0fd0ed9e..00000000 --- a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/Status.kt +++ /dev/null @@ -1,51 +0,0 @@ -package com.izivia.ocpi.toolkit.modules.locations.domain - -/** - * The status of an EVSE. - */ -enum class Status { - /** - * The EVSE/Connector is able to start a new charging session. - */ - AVAILABLE, - - /** - * The EVSE/Connector is not accessible because of a physical barrier, i.e. a car. - */ - BLOCKED, - - /** - * The EVSE/Connector is in use. - */ - CHARGING, - - /** - * The EVSE/Connector is not yet active, or it is no longer available (deleted). - */ - INOPERATIVE, - - /** - * The EVSE/Connector is currently out of order. - */ - OUTOFORDER, - - /** - * The EVSE/Connector is planned, will be operating soon - */ - PLANNED, - - /** - * The EVSE/Connector/charge point is discontinued/removed. - */ - REMOVED, - - /** - * The EVSE/Connector is reserved for a particular EV driver and is unavailable for other drivers. - */ - RESERVED, - - /** - * No status information available. (Also used when offline) - */ - UNKNOWN -} diff --git a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/StatusSchedule.kt b/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/StatusSchedule.kt deleted file mode 100644 index abcc3653..00000000 --- a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/StatusSchedule.kt +++ /dev/null @@ -1,23 +0,0 @@ -package com.izivia.ocpi.toolkit.modules.locations.domain - -import com.izivia.ocpi.toolkit.annotations.Partial -import java.time.Instant - -/** - * This type is used to schedule status periods in the future. The eMSP can provide this information to the EV user for - * trip planning purpose. A period MAY have no end. Example: "This station will be running as of tomorrow. Today it is - * still planned and under construction." - * - * Note that the scheduled status is purely informational. When the status actually changes, the CPO must push an update - * to the EVSEs `status` field itself. - * - * @property period_begin Begin of the scheduled period. - * @property period_end End of the scheduled period, if known. - * @property status Status value during the scheduled period. - */ -@Partial -data class StatusSchedule( - val period_begin: Instant, - val period_end: Instant?, - val status: Status -) \ No newline at end of file diff --git a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/services/LocationsCpoService.kt b/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/services/LocationsCpoService.kt deleted file mode 100644 index e9baa713..00000000 --- a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/services/LocationsCpoService.kt +++ /dev/null @@ -1,52 +0,0 @@ -package com.izivia.ocpi.toolkit.modules.locations.services - -import com.izivia.ocpi.toolkit.common.SearchResult -import com.izivia.ocpi.toolkit.modules.locations.domain.Connector -import com.izivia.ocpi.toolkit.modules.locations.domain.Evse -import com.izivia.ocpi.toolkit.modules.locations.domain.Location -import java.time.Instant - -/** - * - GET: Fetch a list locations, last updated between the {date_from} and {date_to} (paginated), or get a specific - * location, EVSE or Connector. - * - POST: n/a - * - PUT: n/a - * - PATCH: n/a - * - DELETE: n/a - */ -interface LocationsCpoService { - /** - * If additional parameters: {date_from} and/or {date_to} are provided, only Locations with - * (last_updated) between the given date_from and date_to will be returned. If an EVSE is - * updated, also the 'parent' Location's last_updated fields is updated. If a Connector is - * updated, the EVSE's last_updated and the Location's last_updated field are updated. - * - * This request is paginated, it supports the pagination related URL parameters. - * - * @param dateFrom Instant? Only return Locations that have last_updated after this Date/Time. - * @param dateTo Instant? Only return Locations that have last_updated before this Date/Time. - * @param offset Int? The offset of the first object returned. Default is 0. - * @param limit Int? Maximum number of objects to GET. - * @return List The endpoint returns a list of Location objects The header will - * contain the pagination related headers. - */ - fun getLocations(dateFrom: Instant?, dateTo: Instant?, offset: Int = 0, limit: Int?): SearchResult - - /** - * @param locationId String max-length = 39 - */ - fun getLocation(locationId: String): Location? - - /** - * @param locationId String max-length = 39 - * @param evseUid String? max-length = 39 - */ - fun getEvse(locationId: String, evseUid: String): Evse? - - /** - * @param locationId String max-length = 39 - * @param evseUid max-length = 39 - * @param connectorId max-length = 39 - */ - fun getConnector(locationId: String, evseUid: String, connectorId: String): Connector? -} diff --git a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/services/LocationsEmspService.kt b/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/services/LocationsEmspService.kt deleted file mode 100644 index c4c7c1c8..00000000 --- a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/services/LocationsEmspService.kt +++ /dev/null @@ -1,170 +0,0 @@ -package com.izivia.ocpi.toolkit.modules.locations.services - -import com.izivia.ocpi.toolkit.modules.locations.domain.* - - -/** - * Locations is a client owned object, so the end-points need to contain the required extra fields: {party_id} and - * {country_code}. Example endpoint structures: - * - /ocpi/emsp/2.1.1/locations/{country_code}/{party_id}/{location_id} - * - /ocpi/emsp/2.1.1/locations/{country_code}/{party_id}/{location_id}/{evse_uid} - * - /ocpi/emsp/2.1.1/locations/{country_code}/{party_id}/{location_id}/{evse_uid}/{connector_id} - * - * Method: Description - * - GET: Retrieve a Location as it is stored in the eMSP system. - * - POST: n/a (use PUT) - * - PUT: Push new/updated Location, EVSE and/or Connectors to the eMSP - * - PATCH: Notify the eMSP of partial updates to a Location, EVSEs or Connector (such as the status). - * - DELETE: n/a (use PATCH) - */ -interface LocationsEmspService { - /** - * If the CPO wants to check the status of a Location, EVSE or Connector object in the eMSP system, it might GET the - * object from the eMSP system for validation purposes. The CPO is the owner of the objects, so it would be - * illogical if the eMSP system had a different status or was missing an object. If a discrepancy is found, the CPO - * might push an update to the eMSP via a PUT or PATCH call. - * - * @param countryCode (max-length=2) Country code of the CPO requesting this PUT to the eMSP system. - * @param partyId (max-length=3) Party ID (Provider ID) of the CPO requesting this PUT to the eMSP system. - * @param locationId (max-length=39) Location.id of the Location object to retrieve. - */ - fun getLocation(countryCode: String, partyId: String, locationId: String): Location? - - /** - * If the CPO wants to check the status of a Location, EVSE or Connector object in the eMSP system, it might GET the - * object from the eMSP system for validation purposes. The CPO is the owner of the objects, so it would be - * illogical if the eMSP system had a different status or was missing an object. If a discrepancy is found, the CPO - * might push an update to the eMSP via a PUT or PATCH call. - * - * @param countryCode (max-length=2) Country code of the CPO requesting this PUT to the eMSP system. - * @param partyId (max-length=3) Party ID (Provider ID) of the CPO requesting this PUT to the eMSP system. - * @param locationId (max-length=39) Location.id of the Location object to retrieve. - * @param evseUid (max-length=39) Evse.uid, required when requesting an EVSE or Connector object. - */ - fun getEvse(countryCode: String, partyId: String, locationId: String, evseUid: String): Evse? - - /** - * If the CPO wants to check the status of a Location, EVSE or Connector object in the eMSP system, it might GET the - * object from the eMSP system for validation purposes. The CPO is the owner of the objects, so it would be - * illogical if the eMSP system had a different status or was missing an object. If a discrepancy is found, the CPO - * might push an update to the eMSP via a PUT or PATCH call. - * - * @param countryCode (max-length=2) Country code of the CPO requesting this PUT to the eMSP system. - * @param partyId (max-length=3) Party ID (Provider ID) of the CPO requesting this PUT to the eMSP system. - * @param locationId (max-length=39) Location.id of the Location object to retrieve. - * @param evseUid (max-length=39) Evse.uid, required when requesting an EVSE or Connector object. - * @param connectorId (max-length=36) Connector.id, required when requesting a Connector object. - */ - fun getConnector( - countryCode: String, - partyId: String, - locationId: String, - evseUid: String, - connectorId: String - ): Connector? - - /** - * The CPO pushes available Location/EVSE or Connector objects to the eMSP. PUT is used to send new Location objects - * to the eMSP, or to replace existing Locations. - * - * @param countryCode (max-length=2) Country code of the CPO requesting this PUT to the eMSP system. - * @param partyId (max-length=3) Party ID (Provider ID) of the CPO requesting this PUT to the eMSP system. - * @param locationId (max-length=39) Location.id of the new Location object, or the Location of which an EVSE or - * Location object is send - */ - fun putLocation( - countryCode: String, - partyId: String, - locationId: String, - location: Location - ): Location - - /** - * The CPO pushes available Location/EVSE or Connector objects to the eMSP. PUT is used to send new Location objects - * to the eMSP, or to replace existing Locations. - * - * @param countryCode (max-length=2) Country code of the CPO requesting this PUT to the eMSP system. - * @param partyId (max-length=3) Party ID (Provider ID) of the CPO requesting this PUT to the eMSP system. - * @param locationId (max-length=39) Location.id of the new Location object, or the Location of which an EVSE or - * Location object is send - * @param evseUid (max-length=39) Evse.uid, required when an EVSE or Connector object is send/replaced. - */ - fun putEvse( - countryCode: String, - partyId: String, - locationId: String, - evseUid: String, - evse: Evse - ): Evse - - /** - * The CPO pushes available Location/EVSE or Connector objects to the eMSP. PUT is used to send new Location objects - * to the eMSP, or to replace existing Locations. - * - * @param countryCode (max-length=2) Country code of the CPO requesting this PUT to the eMSP system. - * @param partyId (max-length=3) Party ID (Provider ID) of the CPO requesting this PUT to the eMSP system. - * @param locationId (max-length=39) Location.id of the new Location object, or the Location of which an EVSE or - * Location object is send - * @param evseUid (max-length=39) Evse.uid, required when an EVSE or Connector object is send/replaced. - * @param connectorId (max-length=36) Connector.id, required when a Connector object is send/replaced. - */ - fun putConnector( - countryCode: String, - partyId: String, - locationId: String, - evseUid: String, - connectorId: String, - connector: Connector - ): Connector - - /** - * Same as the PUT method, but only the fields/objects that have to be updated have to be present, other - * fields/objects that are not specified are considered unchanged. - * - * @param countryCode (max-length=2) Country code of the CPO requesting this PUT to the eMSP system. - * @param partyId (max-length=3) Party ID (Provider ID) of the CPO requesting this PUT to the eMSP system. - * @param locationId (max-length=39) Location.id of the new Location object - */ - fun patchLocation( - countryCode: String, - partyId: String, - locationId: String, - location: LocationPartial - ): Location? - - /** - * Same as the PUT method, but only the fields/objects that have to be updated have to be present, other - * fields/objects that are not specified are considered unchanged. - * - * @param countryCode (max-length=2) Country code of the CPO requesting this PUT to the eMSP system. - * @param partyId (max-length=3) Party ID (Provider ID) of the CPO requesting this PUT to the eMSP system. - * @param locationId (max-length=39) Location.id of the Location of which an EVSE or Location object is send - * @param evseUid (max-length=39) Evse.uid, required when an EVSE or Connector object is send/replaced. - */ - fun patchEvse( - countryCode: String, - partyId: String, - locationId: String, - evseUid: String, - evse: EvsePartial - ): Evse? - - /** - * Same as the PUT method, but only the fields/objects that have to be updated have to be present, other - * fields/objects that are not specified are considered unchanged. - * - * @param countryCode (max-length=2) Country code of the CPO requesting this PUT to the eMSP system. - * @param partyId (max-length=3) Party ID (Provider ID) of the CPO requesting this PUT to the eMSP system. - * @param locationId (max-length=39) Location.id of the Location of which an EVSE or Location object is send - * @param evseUid (max-length=39) Evse.uid, required when an EVSE or Connector object is send/replaced. - * @param connectorId (max-length=36) Connector.id, required when a Connector object is send/replaced. - */ - fun patchConnector( - countryCode: String, - partyId: String, - locationId: String, - evseUid: String, - connectorId: String, - connector: ConnectorPartial - ): Connector? -} \ No newline at end of file diff --git a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/validation/LocationValidators.kt b/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/validation/LocationValidators.kt deleted file mode 100644 index 6865a90f..00000000 --- a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/validation/LocationValidators.kt +++ /dev/null @@ -1,228 +0,0 @@ -package com.izivia.ocpi.toolkit.modules.locations.validation - -import com.izivia.ocpi.toolkit.common.validation.* -import com.izivia.ocpi.toolkit.modules.locations.domain.* -import com.izivia.ocpi.toolkit.modules.types.DisplayText -import com.izivia.ocpi.toolkit.modules.types.DisplayTextPartial -import com.izivia.ocpi.toolkit.modules.types.toPartial -import org.valiktor.DefaultConstraintViolation -import org.valiktor.constraints.Greater -import org.valiktor.constraints.NotNull -import org.valiktor.constraints.Null -import org.valiktor.functions.isGreaterThanOrEqualTo -import org.valiktor.functions.isLessThanOrEqualTo -import org.valiktor.functions.isNotEmpty -import org.valiktor.validate -import java.math.BigDecimal - -fun LocationPartial.validate(): LocationPartial = validate(this) { - validate(LocationPartial::id).isPrintableAscii().hasMaxLengthOf(39) - validate(LocationPartial::name).isPrintableAscii().hasMaxLengthOf(255) - validate(LocationPartial::address).isPrintableAscii().hasMaxLengthOf(45) - validate(LocationPartial::city).isPrintableAscii().hasMaxLengthOf(45) - validate(LocationPartial::postal_code).isPrintableAscii().hasMaxLengthOf(10) - validate(LocationPartial::country).isCountryCode() - coordinates?.validate() - related_locations?.forEach { it.validate() } - evses?.forEach { it.validate() } - directions?.forEach { it.validate() } - operator?.validate() - suboperator?.validate() - owner?.validate() - // facilities: nothing to validate - validate(LocationPartial::time_zone).isTimeZone() - opening_times?.validate() - // charging_when_closed: nothing to validate - images?.forEach { it.validate() } - energy_mix?.validate() - // last_updated: nothing to validate -} - -fun EnvironmentalImpactPartial.validate(): EnvironmentalImpactPartial = validate(this) { - // source: nothing to validate - validate(EnvironmentalImpactPartial::amount) - .isGreaterThanOrEqualTo(BigDecimal.valueOf(0)) -} - -fun EnergySourcePartial.validate(): EnergySourcePartial = validate(this) { - // source: nothing to validate - validate(EnergySourcePartial::percentage) - .isGreaterThanOrEqualTo(BigDecimal.valueOf(0)) - .isLessThanOrEqualTo(BigDecimal.valueOf(100)) -} - -fun EnergyMixPartial.validate(): EnergyMixPartial = validate(this) { - // is_green_energy: nothing to validate - energy_sources?.forEach { it.validate() } - environ_impact?.forEach { it.validate() } - validate(EnergyMixPartial::supplier_name).isPrintableAscii().hasMaxLengthOf(64) - validate(EnergyMixPartial::energy_product_name).isPrintableAscii().hasMaxLengthOf(64) -} - -fun ExceptionalPeriodPartial.validate(): ExceptionalPeriodPartial = validate(this) { - if (it.period_end != null) { - validate(ExceptionalPeriodPartial::period_begin).isLessThanOrEqualTo(it.period_end) - } -} - -fun RegularHoursPartial.validate(): RegularHoursPartial = validate(this) { regularHours -> - validate(RegularHoursPartial::weekday).isGreaterThanOrEqualTo(1).isLessThanOrEqualTo(7) - validate(RegularHoursPartial::period_begin).isTime() - validate(RegularHoursPartial::period_end).isTime() - - val beginInMinutes = regularHours.period_begin?.split(":") - ?.mapIndexed { index, time -> time.toInt() * (1 - index) * 60 } - ?.sum() - val endInMinutes = regularHours.period_end?.split(":") - ?.mapIndexed { index, time -> time.toInt() * (1 - index) * 60 } - ?.sum() - - if (beginInMinutes != null && endInMinutes != null && beginInMinutes > endInMinutes) { - constraintViolations.add( - DefaultConstraintViolation( - property = "period_begin ($period_begin) is after period_end ($period_end)", - constraint = Greater(endInMinutes) - ) - ) - } -} - -fun HoursPartial.validate(): HoursPartial = validate(this) { hours -> - if (hours.regular_hours != null && hours.twenty_four_seven != null) { - constraintViolations.add( - DefaultConstraintViolation( - property = "regular_hours and twenty_four_seven are both set (only one must be set)", - constraint = NotNull - ) - ) - } - - regular_hours?.forEach { it.validate() } - /// twenty_four_seven: nothing to validate - exceptional_openings?.forEach { it.validate() } - exceptional_closings?.forEach { it.validate() } -} - -fun ImagePartial.validate(): ImagePartial = validate(this) { - validate(ImagePartial::url).isUrl() - validate(ImagePartial::thumbnail).isUrl() - // category: nothing to validate - validate(ImagePartial::type).isPrintableAscii().hasMaxLengthOf(4) - validate(ImagePartial::width).isLessThanOrEqualTo(99999) - validate(ImagePartial::height).isLessThanOrEqualTo(99999) -} - -fun BusinessDetailsPartial.validate(): BusinessDetailsPartial = validate(this) { - validate(BusinessDetailsPartial::name).isPrintableAscii().hasMaxLengthOf(100) - validate(BusinessDetailsPartial::website).isUrl() - logo?.validate() -} - -fun GeoLocationPartial.validate(): GeoLocationPartial = validate(this) { - validate(GeoLocationPartial::latitude).isLatitude() - validate(GeoLocationPartial::longitude).isLongitude() -} - -fun AdditionalGeoLocationPartial.validate(): AdditionalGeoLocationPartial = validate(this) { - validate(AdditionalGeoLocationPartial::latitude).isLatitude() - validate(AdditionalGeoLocationPartial::longitude).isLongitude() - name?.validate() -} - -fun DisplayTextPartial.validate(): DisplayTextPartial = validate(this) { - validate(DisplayTextPartial::language).isLanguage() - validate(DisplayTextPartial::text) - .isPrintableAscii() - .hasNoHtml() - .hasMaxLengthOf(512) -} - -fun StatusSchedulePartial.validate(): StatusSchedulePartial = validate(this) { - if (it.period_end != null) { - validate(StatusSchedulePartial::period_begin).isLessThanOrEqualTo(it.period_end) - } -} - -fun EvsePartial.validate(): EvsePartial = validate(this) { - validate(EvsePartial::uid).isPrintableAscii().hasMaxLengthOf(39) - validate(EvsePartial::evse_id).isEvseId() - // status: nothing to validate - status_schedule?.forEach { it.validate() } - // capabilities: nothing to validate - validate(EvsePartial::connectors).isNotEmpty() - connectors?.forEach { it.validate() } - validate(EvsePartial::floor_level).isPrintableAscii().hasMaxLengthOf(4) - coordinates?.validate() - validate(EvsePartial::physical_reference).isPrintableAscii().hasMaxLengthOf(16) - directions?.forEach { it.validate() } - // parking_restrictions: nothing to validate - images?.forEach { it.validate() } - // last_updated: nothing to validate -} - -fun ConnectorPartial.validate(): ConnectorPartial = validate(this) { - validate(ConnectorPartial::id).isPrintableAscii().hasMaxLengthOf(36) - // standard: nothing to validate - // format: nothing to validate - // power_type: nothing to validate - validate(ConnectorPartial::voltage).isGreaterThanOrEqualTo(0) - validate(ConnectorPartial::amperage).isGreaterThanOrEqualTo(0) - validate(ConnectorPartial::tariff_id).isPrintableAscii().hasMaxLengthOf(36) - validate(ConnectorPartial::terms_and_conditions).isUrl() - // last_updated: nothing to validate -} - -fun Location.validate(): Location = validate(this) { - toPartial().validate() -} -fun EnvironmentalImpact.validate(): EnvironmentalImpact = validate(this) { - toPartial().validate() -} -fun EnergySource.validate(): EnergySource = validate(this) { - toPartial().validate() -} -fun EnergyMix.validate(): EnergyMix = validate(this) { - toPartial().validate() -} -fun ExceptionalPeriod.validate(): ExceptionalPeriod = validate(this) { - toPartial().validate() -} -fun RegularHours.validate(): RegularHours = validate(this) { - toPartial().validate() -} -fun Hours.validate(): Hours = validate(this) { hours -> - if (hours.regular_hours == null && hours.twenty_four_seven == null) { - constraintViolations.add( - DefaultConstraintViolation( - property = "regular_hours or twenty_four_seven must be set (both are null)", - constraint = Null - ) - ) - } - - toPartial().validate() -} -fun Image.validate(): Image = validate(this) { - toPartial().validate() -} -fun BusinessDetails.validate(): BusinessDetails = validate(this) { - toPartial().validate() -} -fun GeoLocation.validate(): GeoLocation = validate(this) { - toPartial().validate() -} -fun AdditionalGeoLocation.validate(): AdditionalGeoLocation = validate(this) { - toPartial().validate() -} -fun DisplayText.validate(): DisplayText = validate(this) { - toPartial().validate() -} -fun StatusSchedule.validate(): StatusSchedule = validate(this) { - toPartial().validate() -} -fun Evse.validate(): Evse = validate(this) { - toPartial().validate() -} -fun Connector.validate(): Connector = validate(this) { - toPartial().validate() -} diff --git a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/validation/LocationsCpoValidationService.kt b/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/validation/LocationsCpoValidationService.kt deleted file mode 100644 index 4e917676..00000000 --- a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/validation/LocationsCpoValidationService.kt +++ /dev/null @@ -1,80 +0,0 @@ -package com.izivia.ocpi.toolkit.modules.locations.validation - -import com.izivia.ocpi.toolkit.common.OcpiResponseBody -import com.izivia.ocpi.toolkit.common.SearchResult -import com.izivia.ocpi.toolkit.common.validation.validate -import com.izivia.ocpi.toolkit.common.validation.validateDates -import com.izivia.ocpi.toolkit.common.validation.validateInt -import com.izivia.ocpi.toolkit.common.validation.validateLength -import com.izivia.ocpi.toolkit.modules.locations.LocationsCpoInterface -import com.izivia.ocpi.toolkit.modules.locations.domain.Connector -import com.izivia.ocpi.toolkit.modules.locations.domain.Evse -import com.izivia.ocpi.toolkit.modules.locations.domain.Location -import com.izivia.ocpi.toolkit.modules.locations.services.LocationsCpoService -import java.time.Instant - -class LocationsCpoValidationService( - private val service: LocationsCpoService -) : LocationsCpoInterface { - - override fun getLocations( - dateFrom: Instant?, - dateTo: Instant?, - offset: Int, - limit: Int? - ): OcpiResponseBody> = OcpiResponseBody.of { - validate { - if (dateFrom != null && dateTo != null) validateDates("dateFrom", dateFrom, "dateTo", dateTo) - if (limit != null) validateInt("limit", limit, 0, null) - validateInt("offset", offset, 0, null) - } - - service - .getLocations(dateFrom, dateTo, offset, limit) - .also { searchResult -> - searchResult.list.forEach { location -> location.validate() } - } - } - - override fun getLocation( - locationId: String - ): OcpiResponseBody = OcpiResponseBody.of { - validate { - validateLength("locationId", locationId, 39) - } - - service - .getLocation(locationId) - ?.validate() - } - - override fun getEvse( - locationId: String, - evseUid: String - ): OcpiResponseBody = OcpiResponseBody.of { - validate { - validateLength("locationId", locationId, 39) - validateLength("evseUid", evseUid, 39) - } - - service - .getEvse(locationId, evseUid) - ?.validate() - } - - override fun getConnector( - locationId: String, - evseUid: String, - connectorId: String - ): OcpiResponseBody = OcpiResponseBody.of { - validate { - validateLength("locationId", locationId, 39) - validateLength("evseUid", evseUid, 39) - validateLength("connectorId", connectorId, 36) - } - - service - .getConnector(locationId, evseUid, connectorId) - ?.validate() - } -} diff --git a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/validation/LocationsEmspValidationService.kt b/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/validation/LocationsEmspValidationService.kt deleted file mode 100644 index fb993093..00000000 --- a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/validation/LocationsEmspValidationService.kt +++ /dev/null @@ -1,225 +0,0 @@ -package com.izivia.ocpi.toolkit.modules.locations.validation - -import com.izivia.ocpi.toolkit.common.OcpiResponseBody -import com.izivia.ocpi.toolkit.common.validation.validate -import com.izivia.ocpi.toolkit.common.validation.validateLength -import com.izivia.ocpi.toolkit.modules.locations.LocationsEmspInterface -import com.izivia.ocpi.toolkit.modules.locations.domain.* -import com.izivia.ocpi.toolkit.modules.locations.services.LocationsEmspService - -class LocationsEmspValidationService( - private val service: LocationsEmspService -) : LocationsEmspInterface { - - override fun getLocation( - countryCode: String, - partyId: String, - locationId: String - ): OcpiResponseBody = OcpiResponseBody.of { - validate { - validateLength("countryCode", countryCode, 2) - validateLength("partyId", partyId, 3) - validateLength("locationId", locationId, 39) - } - - service - .getLocation(countryCode = countryCode, partyId = partyId, locationId = locationId) - ?.validate() - } - - - override fun getEvse( - countryCode: String, - partyId: String, - locationId: String, - evseUid: String - ): OcpiResponseBody = OcpiResponseBody.of { - validate { - validateLength("countryCode", countryCode, 2) - validateLength("partyId", partyId, 3) - validateLength("locationId", locationId, 39) - validateLength("evseUid", evseUid, 39) - } - - service - .getEvse(countryCode = countryCode, partyId = partyId, locationId = locationId, evseUid = evseUid) - ?.validate() - } - - override fun getConnector( - countryCode: String, - partyId: String, - locationId: String, - evseUid: String, - connectorId: String - ): OcpiResponseBody = OcpiResponseBody.of { - validate { - validateLength("countryCode", countryCode, 2) - validateLength("partyId", partyId, 3) - validateLength("locationId", locationId, 39) - validateLength("evseUid", evseUid, 39) - validateLength("connectorId", connectorId, 36) - } - - service - .getConnector( - countryCode = countryCode, - partyId = partyId, - locationId = locationId, - evseUid = evseUid, - connectorId = connectorId - ) - ?.validate() - } - - override fun putLocation( - countryCode: String, - partyId: String, - locationId: String, - location: Location - ): OcpiResponseBody = OcpiResponseBody.of { - validate { - validateLength("countryCode", countryCode, 2) - validateLength("partyId", partyId, 3) - validateLength("locationId", locationId, 39) - location.validate() - } - - service - .putLocation(countryCode = countryCode, partyId = partyId, locationId = locationId, location = location) - .validate() - } - - override fun putEvse( - countryCode: String, - partyId: String, - locationId: String, - evseUid: String, - evse: Evse - ): OcpiResponseBody = OcpiResponseBody.of { - validate { - validateLength("countryCode", countryCode, 2) - validateLength("partyId", partyId, 3) - validateLength("locationId", locationId, 39) - validateLength("evseUid", evseUid, 39) - evse.validate() - } - - service - .putEvse( - countryCode = countryCode, - partyId = partyId, - locationId = locationId, - evseUid = evseUid, - evse = evse - ) - .validate() - } - - override fun putConnector( - countryCode: String, - partyId: String, - locationId: String, - evseUid: String, - connectorId: String, - connector: Connector - ): OcpiResponseBody = OcpiResponseBody.of { - validate { - validateLength("countryCode", countryCode, 2) - validateLength("partyId", partyId, 3) - validateLength("locationId", locationId, 39) - validateLength("evseUid", evseUid, 39) - validateLength("connectorId", connectorId, 36) - connector.validate() - } - - service - .putConnector( - countryCode = countryCode, - partyId = partyId, - locationId = locationId, - evseUid = evseUid, - connectorId = connectorId, - connector = connector - ) - .validate() - } - - override fun patchLocation( - countryCode: String, - partyId: String, - locationId: String, - location: LocationPartial - ): OcpiResponseBody = OcpiResponseBody.of { - validate { - validateLength("countryCode", countryCode, 2) - validateLength("partyId", partyId, 3) - validateLength("locationId", locationId, 39) - location.validate() - } - - service - .patchLocation( - countryCode = countryCode, - partyId = partyId, - locationId = locationId, - location = location - ) - ?.validate() - } - - override fun patchEvse( - countryCode: String, - partyId: String, - locationId: String, - evseUid: String, - evse: EvsePartial - ): OcpiResponseBody = OcpiResponseBody.of { - validate { - validateLength("countryCode", countryCode, 2) - validateLength("partyId", partyId, 3) - validateLength("locationId", locationId, 39) - validateLength("evseUid", evseUid, 39) - evse.validate() - } - - service - .patchEvse( - countryCode = countryCode, - partyId = partyId, - locationId = locationId, - evseUid = evseUid, - evse = evse - ) - ?.validate() - } - - override fun patchConnector( - countryCode: String, - partyId: String, - locationId: String, - evseUid: String, - connectorId: String, - connector: ConnectorPartial - ): OcpiResponseBody = OcpiResponseBody.of { - validate { - validateLength("countryCode", countryCode, 2) - validateLength("partyId", partyId, 3) - validateLength("locationId", locationId, 39) - validateLength("evseUid", evseUid, 39) - validateLength("connectorId", connectorId, 36) - connector.validate() - } - - service - .patchConnector( - countryCode = countryCode, - partyId = partyId, - locationId = locationId, - evseUid = evseUid, - connectorId = connectorId, - connector = connector - ) - ?.validate() - } -} diff --git a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/TokensCpoClient.kt b/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/TokensCpoClient.kt deleted file mode 100644 index e6486ed2..00000000 --- a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/TokensCpoClient.kt +++ /dev/null @@ -1,64 +0,0 @@ -package com.izivia.ocpi.toolkit.modules.tokens - -import com.izivia.ocpi.toolkit.common.* -import com.izivia.ocpi.toolkit.modules.credentials.repositories.PlatformRepository -import com.izivia.ocpi.toolkit.modules.tokens.domain.AuthorizationInfo -import com.izivia.ocpi.toolkit.modules.tokens.domain.LocationReferences -import com.izivia.ocpi.toolkit.modules.tokens.domain.Token -import com.izivia.ocpi.toolkit.modules.tokens.domain.TokenType -import com.izivia.ocpi.toolkit.modules.versions.domain.ModuleID -import com.izivia.ocpi.toolkit.transport.TransportClient -import com.izivia.ocpi.toolkit.transport.TransportClientBuilder -import com.izivia.ocpi.toolkit.transport.domain.HttpMethod -import com.izivia.ocpi.toolkit.transport.domain.HttpRequest -import java.time.Instant - -class TokensCpoClient( - private val transportClientBuilder: TransportClientBuilder, - private val serverVersionsEndpointUrl: String, - private val platformRepository: PlatformRepository -) : TokensEmspInterface { - - private fun buildTransport(): TransportClient = transportClientBuilder - .buildFor( - module = ModuleID.tokens, - platformUrl = serverVersionsEndpointUrl, - platformRepository = platformRepository - ) - - override fun getTokens( - dateFrom: Instant?, - dateTo: Instant?, - offset: Int, - limit: Int? - ): OcpiResponseBody> = - buildTransport() - .send( - HttpRequest( - method = HttpMethod.GET, - queryParams = listOfNotNull( - dateFrom?.let { "date_from" to dateFrom.toString() }, - dateTo?.let { "date_to" to dateTo.toString() }, - "offset" to offset.toString(), - limit?.let { "limit" to limit.toString() } - ).toMap() - ).authenticate(platformRepository = platformRepository, baseUrl = serverVersionsEndpointUrl) - ) - .parsePaginatedBody(offset) - - override fun postToken( - tokenUid: String, - tokenType: TokenType, - locationReferences: LocationReferences? - ): OcpiResponseBody = - buildTransport() - .send( - HttpRequest( - method = HttpMethod.POST, - path = "/$tokenUid/authorize", - queryParams = mapOf("type" to tokenType.name), - body = locationReferences?.run(mapper::writeValueAsString) - ).authenticate(platformRepository = platformRepository, baseUrl = serverVersionsEndpointUrl) - ) - .parseBody() -} diff --git a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/TokensCpoInterface.kt b/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/TokensCpoInterface.kt deleted file mode 100644 index 0034efaa..00000000 --- a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/TokensCpoInterface.kt +++ /dev/null @@ -1,66 +0,0 @@ -package com.izivia.ocpi.toolkit.modules.tokens - -import com.izivia.ocpi.toolkit.common.OcpiResponseBody -import com.izivia.ocpi.toolkit.modules.tokens.domain.Token -import com.izivia.ocpi.toolkit.modules.tokens.domain.TokenPartial - -/** - * With this interface the eMSP can push the Token information to the CPO. Tokens is a client owned object, so the - * end-points need to contain the required extra fields: {party_id} and {country_code}. Example endpoint structure: - * /ocpi/cpo/2.0/tokens/{country_code}/{party_id}/{token_uid} - * - * - GET: Retrieve a Token as it is stored in the CPO system. - * - POST: n/a - * - PUT: Push new/updated Token object to the CPO. - * - PATCH: Notify the CPO of partial updates to a Token. - * - DELETE: n/a, (Use PUT, Tokens cannot be removed). - */ -interface TokensCpoInterface { - - /** - * If the eMSP wants to check the status of a Token in the CPO system it might GET the object from the CPO system - * for validation purposes. The eMSP is the owner of the objects, so it would be illogical if the CPO system had a - * different status or was missing an object. - * - * @param countryCode (max-length 2) Country code of the eMSP requesting this GET from the CPO system. - * @param partyId (max-length 3) Party ID (Provider ID) of the eMSP requesting this GET from the CPO system. - * @param tokenUid (max-length 36) Token.uid of the Token object to retrieve. - * @return The requested Token object. - */ - fun getToken( - countryCode: String, - partyId: String, - tokenUid: String - ): OcpiResponseBody - - /** - * New or updated Token objects are pushed from the eMSP to the CPO. - * - * @param countryCode (max-length 2) Country code of the eMSP sending this PUT request to the CPO system. - * @param partyId (max-length 3) Party ID (Provider ID) of the eMSP sending this PUT request to the CPO system. - * @param tokenUid (max-length 36) Token.uid of the (new) Token object (to replace). - * @param token New or updated Token object. - */ - fun putToken( - countryCode: String, - partyId: String, - tokenUid: String, - token: Token - ): OcpiResponseBody - - /** - * Same as the PUT method, but only the fields/objects that have to be updated have to be present, other - * fields/objects that are not specified are considered unchanged. - * - * @param countryCode (max-length 2) Country code of the eMSP sending this PUT request to the CPO system. - * @param partyId (max-length 3) Party ID (Provider ID) of the eMSP sending this PUT request to the CPO system. - * @param tokenUid (max-length 36) Token.uid of the (new) Token object (to replace). - * @param token New or updated Token object. - */ - fun patchToken( - countryCode: String, - partyId: String, - tokenUid: String, - token: TokenPartial - ): OcpiResponseBody -} diff --git a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/TokensCpoServer.kt b/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/TokensCpoServer.kt deleted file mode 100644 index a889d059..00000000 --- a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/TokensCpoServer.kt +++ /dev/null @@ -1,85 +0,0 @@ -package com.izivia.ocpi.toolkit.modules.tokens - -import com.izivia.ocpi.toolkit.common.httpResponse -import com.izivia.ocpi.toolkit.common.mapper -import com.izivia.ocpi.toolkit.common.checkToken -import com.izivia.ocpi.toolkit.modules.credentials.repositories.PlatformRepository -import com.izivia.ocpi.toolkit.modules.tokens.domain.Token -import com.izivia.ocpi.toolkit.modules.tokens.domain.TokenPartial -import com.izivia.ocpi.toolkit.transport.TransportServer -import com.izivia.ocpi.toolkit.transport.domain.FixedPathSegment -import com.izivia.ocpi.toolkit.transport.domain.HttpMethod -import com.izivia.ocpi.toolkit.transport.domain.VariablePathSegment -import kotlinx.coroutines.runBlocking - -class TokensCpoServer( - private val transportServer: TransportServer, - private val platformRepository: PlatformRepository, - private val service: TokensCpoInterface, - basePath: List = listOf( - FixedPathSegment("/2.1.1/tokens") - ) -) { - init { - runBlocking { - transportServer.handle( - method = HttpMethod.GET, - path = basePath + listOf( - VariablePathSegment("countryCode"), - VariablePathSegment("partyId"), - VariablePathSegment("tokenUid") - ), - filters = listOf(platformRepository::checkToken) - ) { req -> - req.httpResponse { - service - .getToken( - countryCode = req.pathParams["countryCode"]!!, - partyId = req.pathParams["partyId"]!!, - tokenUid = req.pathParams["tokenUid"]!! - ) - } - } - - transportServer.handle( - method = HttpMethod.PUT, - path = basePath + listOf( - VariablePathSegment("countryCode"), - VariablePathSegment("partyId"), - VariablePathSegment("tokenUid") - ), - filters = listOf(platformRepository::checkToken) - ) { req -> - req.httpResponse { - service - .putToken( - countryCode = req.pathParams["countryCode"]!!, - partyId = req.pathParams["partyId"]!!, - tokenUid = req.pathParams["tokenUid"]!!, - token = mapper.readValue(req.body, Token::class.java) - ) - } - } - - transportServer.handle( - method = HttpMethod.PATCH, - path = basePath + listOf( - VariablePathSegment("countryCode"), - VariablePathSegment("partyId"), - VariablePathSegment("tokenUid") - ), - filters = listOf(platformRepository::checkToken) - ) { req -> - req.httpResponse { - service - .patchToken( - countryCode = req.pathParams["countryCode"]!!, - partyId = req.pathParams["partyId"]!!, - tokenUid = req.pathParams["tokenUid"]!!, - token = mapper.readValue(req.body!!, TokenPartial::class.java) - ) - } - } - } - } -} diff --git a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/TokensEmspClient.kt b/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/TokensEmspClient.kt deleted file mode 100644 index 5ffafa30..00000000 --- a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/TokensEmspClient.kt +++ /dev/null @@ -1,71 +0,0 @@ -package com.izivia.ocpi.toolkit.modules.tokens - -import com.izivia.ocpi.toolkit.common.* -import com.izivia.ocpi.toolkit.modules.credentials.repositories.PlatformRepository -import com.izivia.ocpi.toolkit.modules.tokens.domain.Token -import com.izivia.ocpi.toolkit.modules.tokens.domain.TokenPartial -import com.izivia.ocpi.toolkit.modules.versions.domain.ModuleID -import com.izivia.ocpi.toolkit.transport.TransportClient -import com.izivia.ocpi.toolkit.transport.TransportClientBuilder -import com.izivia.ocpi.toolkit.transport.domain.HttpMethod -import com.izivia.ocpi.toolkit.transport.domain.HttpRequest - -class TokensEmspClient( - private val transportClientBuilder: TransportClientBuilder, - private val serverVersionsEndpointUrl: String, - private val platformRepository: PlatformRepository -) : TokensCpoInterface { - - private fun buildTransport(): TransportClient = transportClientBuilder - .buildFor( - module = ModuleID.tokens, - platformUrl = serverVersionsEndpointUrl, - platformRepository = platformRepository - ) - - override fun getToken( - countryCode: String, - partyId: String, - tokenUid: String - ): OcpiResponseBody = - buildTransport() - .send( - HttpRequest( - method = HttpMethod.GET, - path = "/$countryCode/$partyId/$tokenUid" - ).authenticate(platformRepository = platformRepository, baseUrl = serverVersionsEndpointUrl) - ) - .parseBody() - - override fun putToken( - countryCode: String, - partyId: String, - tokenUid: String, - token: Token - ): OcpiResponseBody = - buildTransport() - .send( - HttpRequest( - method = HttpMethod.PUT, - path = "/$countryCode/$partyId/$tokenUid", - body = mapper.writeValueAsString(token) - ).authenticate(platformRepository = platformRepository, baseUrl = serverVersionsEndpointUrl) - ) - .parseBody() - - override fun patchToken( - countryCode: String, - partyId: String, - tokenUid: String, - token: TokenPartial - ): OcpiResponseBody = - buildTransport() - .send( - HttpRequest( - method = HttpMethod.PATCH, - path = "/$countryCode/$partyId/$tokenUid", - body = mapper.writeValueAsString(token) - ).authenticate(platformRepository = platformRepository, baseUrl = serverVersionsEndpointUrl) - ) - .parseBody() -} diff --git a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/TokensEmspInterface.kt b/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/TokensEmspInterface.kt deleted file mode 100644 index 720d42d6..00000000 --- a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/TokensEmspInterface.kt +++ /dev/null @@ -1,71 +0,0 @@ -package com.izivia.ocpi.toolkit.modules.tokens - -import com.izivia.ocpi.toolkit.common.OcpiResponseBody -import com.izivia.ocpi.toolkit.common.SearchResult -import com.izivia.ocpi.toolkit.modules.tokens.domain.AuthorizationInfo -import com.izivia.ocpi.toolkit.modules.tokens.domain.LocationReferences -import com.izivia.ocpi.toolkit.modules.tokens.domain.Token -import com.izivia.ocpi.toolkit.modules.tokens.domain.TokenType -import java.time.Instant - -/** - * This interface enables the CPO to request the current list of Tokens, when needed. Via the POST method it is possible - * to authorize a single token. Example endpoint structure: /ocpi/emsp/2.0/tokens/?date_from=xxx&date_to=yyy - * - * - GET: Get the list of known Tokens, last updated between the {date_from} and {date_to} (paginated) - * - POST: Real-time authorization request - * - PUT: n/a - * - PATCH: n/a - * - DELETE: n/a - */ -interface TokensEmspInterface { - - /** - * Fetch information about Tokens known in the eMSP systems. - * - * If additional parameters: {date_from} and/or {date_to} are provided, only Tokens with (last_updated) between the - * iven date_from and date_to will be returned. - * - * This request is paginated, it supports the pagination related URL parameters. - * - * @param dateFrom Only return Tokens that have last_updated after this Date/Time. - * @param dateTo Only return Tokens that have last_updated before this Date/Time. - * @param offset The offset of the first object returned. Default is 0. - * @param limit Maximum number of objects to GET. - * @return The endpoint response with list of valid Token objects, the header will contain the pagination related - * headers. - */ - fun getTokens( - dateFrom: Instant?, - dateTo: Instant?, - offset: Int = 0, - limit: Int? - ): OcpiResponseBody> - - /** - * Do a 'real-time' authorization request to the eMSP system, validating if a Token might be used (at the optionally - * given Location). - * - * Example endpoint structure: /ocpi/emsp/2.0/tokens/{token_uid}/authorize?{type=token_type} The /authorize is - * required for the real-time authorize request. - * - * When the eMSP receives a 'real-time' authorization request from a CPO that contains too little information (no - * LocationReferences provided) to determine if the Token might be used, the eMSP SHOULD respond with the OCPI - * status: 2002 - * - * In the body an optional LocationReferences object can be given. The eMSP SHALL then validate if the Token is - * allowed to be used at this Location, and if applicable: which of the Locations EVSEs/Connectors. The object with - * valid Location and EVSEs/Connectors will be returned in the response. - * - * @param tokenUid (max-length 36) Token.uid of the Token for which this authorization is. - * @param tokenType Token.type of the Token for which this authorization is. Default if omitted: RFID - * @param locationReferences Location and EVSEs/Connectors for which the Token is requested to be authorized. - * @return Contains information about the authorization, if the Token is allowed to charge and optionally which - * EVSEs/Connectors are allowed to be used. - */ - fun postToken( - tokenUid: String, - tokenType: TokenType = TokenType.RFID, - locationReferences: LocationReferences? - ): OcpiResponseBody -} diff --git a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/TokensEmspServer.kt b/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/TokensEmspServer.kt deleted file mode 100644 index 8656252b..00000000 --- a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/TokensEmspServer.kt +++ /dev/null @@ -1,71 +0,0 @@ -package com.izivia.ocpi.toolkit.modules.tokens - -import com.izivia.ocpi.toolkit.common.httpResponse -import com.izivia.ocpi.toolkit.common.mapper -import com.izivia.ocpi.toolkit.common.checkToken -import com.izivia.ocpi.toolkit.modules.credentials.repositories.PlatformRepository -import com.izivia.ocpi.toolkit.modules.tokens.domain.LocationReferences -import com.izivia.ocpi.toolkit.modules.tokens.domain.TokenType -import com.izivia.ocpi.toolkit.transport.TransportServer -import com.izivia.ocpi.toolkit.transport.domain.FixedPathSegment -import com.izivia.ocpi.toolkit.transport.domain.HttpMethod -import com.izivia.ocpi.toolkit.transport.domain.VariablePathSegment -import kotlinx.coroutines.runBlocking -import java.time.Instant - -class TokensEmspServer( - private val transportServer: TransportServer, - private val platformRepository: PlatformRepository, - private val service: TokensEmspInterface, - basePath: List = listOf( - FixedPathSegment("/2.1.1/tokens") - ) -) { - init { - runBlocking { - transportServer.handle( - method = HttpMethod.GET, - path = basePath, - queryParams = listOf("date_from", "date_to", "offset", "limit"), - filters = listOf(platformRepository::checkToken) - ) { req -> - req.httpResponse { - val dateFrom = req.queryParams["date_from"] - val dateTo = req.queryParams["date_to"] - - service - .getTokens( - dateFrom = dateFrom?.let { Instant.parse(it) }, - dateTo = dateTo?.let { Instant.parse(it) }, - offset = req.queryParams["offset"]?.toInt() ?: 0, - limit = req.queryParams["limit"]?.toInt() - ) - } - } - - transportServer.handle( - method = HttpMethod.POST, - path = basePath + listOf( - VariablePathSegment("tokenUid"), - FixedPathSegment("authorize") - ), - queryParams = listOf("type"), - filters = listOf(platformRepository::checkToken) - ) { req -> - req.httpResponse { - service - .postToken( - tokenUid = req.pathParams["tokenUid"]!!, - tokenType = req.queryParams["type"]?.run(TokenType::valueOf) ?: TokenType.RFID, - locationReferences = req.body?.run { - mapper.readValue( - this, - LocationReferences::class.java - ) - } - ) - } - } - } - } -} diff --git a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/domain/Allowed.kt b/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/domain/Allowed.kt deleted file mode 100644 index f245c975..00000000 --- a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/domain/Allowed.kt +++ /dev/null @@ -1,28 +0,0 @@ -package com.izivia.ocpi.toolkit.modules.tokens.domain - -enum class Allowed { - /** - * This Token is allowed to charge at this location - */ - ALLOWED, - - /** - * This Token is blocked. - */ - BLOCKED, - - /** - * This Token has expired. - */ - EXPIRED, - - /** - * This Token belongs to an account that has not enough credits to charge at the given location. - */ - NOT_CREDIT, - - /** - * Token is valid, but is not allowed to charge at the given location. - */ - NOT_ALLOWED -} diff --git a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/domain/AuthorizationInfo.kt b/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/domain/AuthorizationInfo.kt deleted file mode 100644 index d9af57bf..00000000 --- a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/domain/AuthorizationInfo.kt +++ /dev/null @@ -1,15 +0,0 @@ -package com.izivia.ocpi.toolkit.modules.tokens.domain - -import com.izivia.ocpi.toolkit.modules.types.DisplayText - -/** - * @property allowed Status of the Token, and whether charging is allowed at the optionally given location. - * @property location Optional reference to the location if it was included in the request, and if the EV driver is - * allowed to charge at that location. Only the EVSEs/Connectors the EV driver is allowed to charge at are returned. - * @property info Optional display text, additional information to the EV driver. - */ -data class AuthorizationInfo( - val allowed: Allowed, - val location: LocationReferences?, - val info: DisplayText? -) diff --git a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/domain/LocationReferences.kt b/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/domain/LocationReferences.kt deleted file mode 100644 index 670d913b..00000000 --- a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/domain/LocationReferences.kt +++ /dev/null @@ -1,15 +0,0 @@ -package com.izivia.ocpi.toolkit.modules.tokens.domain - -/** - * References to location details. - * @property location_id (max-length 39) Unique identifier for the location. - * @property evse_uids (list of string of max-length 39) Unique identifier for EVSEs within the CPO's platform for the - * EVSE within the the given location. - * @property connector_ids (list of string of max-length 39) Identifies the connectors within the given EVSEs. - * @constructor - */ -data class LocationReferences( - val location_id: String, - val evse_uids: List, - val connector_ids: List -) diff --git a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/domain/Token.kt b/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/domain/Token.kt deleted file mode 100644 index aa36e9ee..00000000 --- a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/domain/Token.kt +++ /dev/null @@ -1,34 +0,0 @@ -package com.izivia.ocpi.toolkit.modules.tokens.domain - -import com.izivia.ocpi.toolkit.annotations.Partial -import java.time.Instant - -/** - * @property uid (max-length 36) Identification used by CPO system to identify this token. Currently, in most cases, - * this is the RFID hidden ID as read by the RFID reader. - * @property type Type of the token - * @property auth_id (max-length 36) Uniquely identifies the EV Driver contract token within the eMSP's platform (and - * suboperator platforms). Recommended to follow the specification for eMA ID from "eMI3 standard version V1.0" - * (http://emi3group.com/documents-links/) "Part 2: business objects." - * @property visual_number (max-length 64) Visual readable number/identification as printed on the Token (RFID card), - * might be equal to the auth_id. - * @property issuer (max-length 64) Issuing company, most of the times the name of the company printed on the token - * (RFID card), not necessarily the eMSP. - * @property valid Is this Token valid - * @property whitelist Indicates what type of white-listing is allowed. - * @property language (max-length 2) Language Code ISO 639-1. This optional field indicates the Token owner's preferred - * interface language. If the language is not provided or not supported then the CPO is free to choose its own language. - * @property last_updated Timestamp when this Token was last updated (or created). - */ -@Partial -data class Token( - val uid: String, - val type: TokenType, - val auth_id: String, - val visual_number: String?, - val issuer: String, - val valid: Boolean, - val whitelist: WhitelistType, - val language: String?, - val last_updated: Instant -) diff --git a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/domain/TokenType.kt b/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/domain/TokenType.kt deleted file mode 100644 index d8888322..00000000 --- a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/domain/TokenType.kt +++ /dev/null @@ -1,13 +0,0 @@ -package com.izivia.ocpi.toolkit.modules.tokens.domain - -enum class TokenType { - /** - * Other type of token - */ - OTHER, - - /** - * RFID Token - */ - RFID -} diff --git a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/domain/WhitelistType.kt b/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/domain/WhitelistType.kt deleted file mode 100644 index bda97737..00000000 --- a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/domain/WhitelistType.kt +++ /dev/null @@ -1,26 +0,0 @@ -package com.izivia.ocpi.toolkit.modules.tokens.domain - -/** - * Defines when authorization of a Token by the CPO is allowed. - */ -enum class WhitelistType { - /** - * Token always has to be whitelisted, realtime authorization is not possible/allowed. - */ - ALWAYS, - - /** - * It is allowed to whitelist the token, realtime authorization is also allowed. - */ - ALLOWED, - - /** - * Whitelisting is only allowed when CPO cannot reach the eMSP (communication between CPO and eMSP is offline) - */ - ALLOWED_OFFLINE, - - /** - * Whitelisting is forbidden, only realtime authorization is allowed. Token should always be authorized by the eMSP. - */ - NEVER -} diff --git a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/services/TokensCpoService.kt b/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/services/TokensCpoService.kt deleted file mode 100644 index b1019864..00000000 --- a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/services/TokensCpoService.kt +++ /dev/null @@ -1,65 +0,0 @@ -package com.izivia.ocpi.toolkit.modules.tokens.services - -import com.izivia.ocpi.toolkit.modules.tokens.domain.Token -import com.izivia.ocpi.toolkit.modules.tokens.domain.TokenPartial - -/** - * With this interface the eMSP can push the Token information to the CPO. Tokens is a client owned object, so the - * end-points need to contain the required extra fields: {party_id} and {country_code}. Example endpoint structure: - * /ocpi/cpo/2.0/tokens/{country_code}/{party_id}/{token_uid} - * - * - GET: Retrieve a Token as it is stored in the CPO system. - * - POST: n/a - * - PUT: Push new/updated Token object to the CPO. - * - PATCH: Notify the CPO of partial updates to a Token. - * - DELETE: n/a, (Use PUT, Tokens cannot be removed). - */ -interface TokensCpoService { - - /** - * If the eMSP wants to check the status of a Token in the CPO system it might GET the object from the CPO system - * for validation purposes. The eMSP is the owner of the objects, so it would be illogical if the CPO system had a - * different status or was missing an object. - * - * @param countryCode (max-length 2) Country code of the eMSP requesting this GET from the CPO system. - * @param partyId (max-length 3) Party ID (Provider ID) of the eMSP requesting this GET from the CPO system. - * @param tokenUid (max-length 36) Token.uid of the Token object to retrieve. - * @return The requested Token object. - */ - fun getToken( - countryCode: String, - partyId: String, - tokenUid: String - ): Token? - - /** - * New or updated Token objects are pushed from the eMSP to the CPO. - * - * @param countryCode (max-length 2) Country code of the eMSP sending this PUT request to the CPO system. - * @param partyId (max-length 3) Party ID (Provider ID) of the eMSP sending this PUT request to the CPO system. - * @param tokenUid (max-length 36) Token.uid of the (new) Token object (to replace). - * @param token New or updated Token object. - */ - fun putToken( - countryCode: String, - partyId: String, - tokenUid: String, - token: Token - ): Token - - /** - * Same as the PUT method, but only the fields/objects that have to be updated have to be present, other - * fields/objects that are not specified are considered unchanged. - * - * @param countryCode (max-length 2) Country code of the eMSP sending this PUT request to the CPO system. - * @param partyId (max-length 3) Party ID (Provider ID) of the eMSP sending this PUT request to the CPO system. - * @param tokenUid (max-length 36) Token.uid of the (new) Token object (to replace). - * @param token New or updated Token object. - */ - fun patchToken( - countryCode: String, - partyId: String, - tokenUid: String, - token: TokenPartial - ): Token -} diff --git a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/services/TokensEmspService.kt b/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/services/TokensEmspService.kt deleted file mode 100644 index 518f425c..00000000 --- a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/services/TokensEmspService.kt +++ /dev/null @@ -1,70 +0,0 @@ -package com.izivia.ocpi.toolkit.modules.tokens.services - -import com.izivia.ocpi.toolkit.common.SearchResult -import com.izivia.ocpi.toolkit.modules.tokens.domain.AuthorizationInfo -import com.izivia.ocpi.toolkit.modules.tokens.domain.LocationReferences -import com.izivia.ocpi.toolkit.modules.tokens.domain.Token -import com.izivia.ocpi.toolkit.modules.tokens.domain.TokenType -import java.time.Instant - -/** - * This interface enables the CPO to request the current list of Tokens, when needed. Via the POST method it is possible - * to authorize a single token. Example endpoint structure: /ocpi/emsp/2.0/tokens/?date_from=xxx&date_to=yyy - * - * - GET: Get the list of known Tokens, last updated between the {date_from} and {date_to} (paginated) - * - POST: Real-time authorization request - * - PUT: n/a - * - PATCH: n/a - * - DELETE: n/a - */ -interface TokensEmspService { - - /** - * Fetch information about Tokens known in the eMSP systems. - * - * If additional parameters: {date_from} and/or {date_to} are provided, only Tokens with (last_updated) between the - * iven date_from and date_to will be returned. - * - * This request is paginated, it supports the pagination related URL parameters. - * - * @param dateFrom Only return Tokens that have last_updated after this Date/Time. - * @param dateTo Only return Tokens that have last_updated before this Date/Time. - * @param offset The offset of the first object returned. Default is 0. - * @param limit Maximum number of objects to GET. - * @return The endpoint response with list of valid Token objects, the header will contain the pagination related - * headers. - */ - fun getTokens( - dateFrom: Instant?, - dateTo: Instant?, - offset: Int = 0, - limit: Int? - ): SearchResult - - /** - * Do a 'real-time' authorization request to the eMSP system, validating if a Token might be used (at the optionally - * given Location). - * - * Example endpoint structure: /ocpi/emsp/2.0/tokens/{token_uid}/authorize?{type=token_type} The /authorize is - * required for the real-time authorize request. - * - * When the eMSP receives a 'real-time' authorization request from a CPO that contains too little information (no - * LocationReferences provided) to determine if the Token might be used, the eMSP SHOULD respond with the OCPI - * status: 2002 - * - * In the body an optional LocationReferences object can be given. The eMSP SHALL then validate if the Token is - * allowed to be used at this Location, and if applicable: which of the Locations EVSEs/Connectors. The object with - * valid Location and EVSEs/Connectors will be returned in the response. - * - * @param tokenUid (max-length 36) Token.uid of the Token for which this authorization is. - * @param tokenType Token.type of the Token for which this authorization is. Default if omitted: RFID - * @param locationReferences Location and EVSEs/Connectors for which the Token is requested to be authorized. - * @return Contains information about the authorization, if the Token is allowed to charge and optionally which - * EVSEs/Connectors are allowed to be used. - */ - fun postToken( - tokenUid: String, - tokenType: TokenType = TokenType.RFID, - locationReferences: LocationReferences? - ): AuthorizationInfo -} diff --git a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/validation/TokensCpoValidationService.kt b/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/validation/TokensCpoValidationService.kt deleted file mode 100644 index 4ddbbf00..00000000 --- a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/validation/TokensCpoValidationService.kt +++ /dev/null @@ -1,67 +0,0 @@ -package com.izivia.ocpi.toolkit.modules.tokens.validation - -import com.izivia.ocpi.toolkit.common.OcpiResponseBody -import com.izivia.ocpi.toolkit.common.validation.validate -import com.izivia.ocpi.toolkit.common.validation.validateLength -import com.izivia.ocpi.toolkit.modules.tokens.TokensCpoInterface -import com.izivia.ocpi.toolkit.modules.tokens.domain.Token -import com.izivia.ocpi.toolkit.modules.tokens.domain.TokenPartial -import com.izivia.ocpi.toolkit.modules.tokens.services.TokensCpoService - -class TokensCpoValidationService( - private val service: TokensCpoService -): TokensCpoInterface { - - override fun getToken( - countryCode: String, - partyId: String, - tokenUid: String - ): OcpiResponseBody = OcpiResponseBody.of { - validate { - validateLength("countryCode", countryCode, 2) - validateLength("partyId", partyId, 3) - validateLength("tokenUid", tokenUid, 36) - } - - service - .getToken(countryCode = countryCode, partyId = partyId, tokenUid = tokenUid) - ?.validate() - } - - override fun putToken( - countryCode: String, - partyId: String, - tokenUid: String, - token: Token - ): OcpiResponseBody = OcpiResponseBody.of { - validate { - validateLength("countryCode", countryCode, 2) - validateLength("partyId", partyId, 3) - validateLength("tokenUid", tokenUid, 36) - token.validate() - } - - service - .putToken(countryCode = countryCode, partyId = partyId, tokenUid = tokenUid, token = token) - .validate() - } - - override fun patchToken( - countryCode: String, - partyId: String, - tokenUid: String, - token: TokenPartial - ): OcpiResponseBody = OcpiResponseBody.of { - validate { - validateLength("countryCode", countryCode, 2) - validateLength("partyId", partyId, 3) - validateLength("tokenUid", tokenUid, 36) - token.validate() - } - - service - .patchToken(countryCode = countryCode, partyId = partyId, tokenUid = tokenUid, token = token) - .validate() - } - -} diff --git a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/validation/TokensEmspValidationService.kt b/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/validation/TokensEmspValidationService.kt deleted file mode 100644 index 1d717dca..00000000 --- a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/validation/TokensEmspValidationService.kt +++ /dev/null @@ -1,54 +0,0 @@ -package com.izivia.ocpi.toolkit.modules.tokens.validation - -import com.izivia.ocpi.toolkit.common.OcpiResponseBody -import com.izivia.ocpi.toolkit.common.SearchResult -import com.izivia.ocpi.toolkit.common.validation.validate -import com.izivia.ocpi.toolkit.common.validation.validateDates -import com.izivia.ocpi.toolkit.common.validation.validateInt -import com.izivia.ocpi.toolkit.common.validation.validateLength -import com.izivia.ocpi.toolkit.modules.tokens.TokensEmspInterface -import com.izivia.ocpi.toolkit.modules.tokens.domain.AuthorizationInfo -import com.izivia.ocpi.toolkit.modules.tokens.domain.LocationReferences -import com.izivia.ocpi.toolkit.modules.tokens.domain.Token -import com.izivia.ocpi.toolkit.modules.tokens.domain.TokenType -import com.izivia.ocpi.toolkit.modules.tokens.services.TokensEmspService -import java.time.Instant - -class TokensEmspValidationService( - private val service: TokensEmspService -): TokensEmspInterface { - - override fun getTokens( - dateFrom: Instant?, - dateTo: Instant?, - offset: Int, - limit: Int? - ): OcpiResponseBody> = OcpiResponseBody.of { - validate { - if (dateFrom != null && dateTo != null) validateDates("dateFrom", dateFrom, "dateTo", dateTo) - if (limit != null) validateInt("limit", limit, 0, null) - validateInt("offset", offset, 0, null) - } - - service - .getTokens(dateFrom, dateTo, offset, limit) - .also { searchResult -> - searchResult.list.forEach { token -> token.validate() } - } - } - - override fun postToken( - tokenUid: String, - tokenType: TokenType, - locationReferences: LocationReferences? - ): OcpiResponseBody = OcpiResponseBody.of { - validate { - validateLength("tokenUid", tokenUid, 36) - locationReferences?.validate() - } - - service - .postToken(tokenUid = tokenUid, tokenType = tokenType, locationReferences = locationReferences) - .validate() - } -} diff --git a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/validation/TokensValidators.kt b/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/validation/TokensValidators.kt deleted file mode 100644 index 110e0c40..00000000 --- a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/validation/TokensValidators.kt +++ /dev/null @@ -1,50 +0,0 @@ -package com.izivia.ocpi.toolkit.modules.tokens.validation - -import com.izivia.ocpi.toolkit.common.validation.hasMaxLengthOf -import com.izivia.ocpi.toolkit.common.validation.isLanguage -import com.izivia.ocpi.toolkit.common.validation.isPrintableAscii -import com.izivia.ocpi.toolkit.modules.locations.validation.validate -import com.izivia.ocpi.toolkit.modules.tokens.domain.* -import org.valiktor.validate - -private data class StringWrapper(val str: String) - -fun TokenPartial.validate(): TokenPartial = validate(this) { - validate(TokenPartial::uid).isPrintableAscii().hasMaxLengthOf(36) - // type: nothing to validate - validate(TokenPartial::auth_id).isPrintableAscii().hasMaxLengthOf(36) - validate(TokenPartial::visual_number).isPrintableAscii().hasMaxLengthOf(64) - validate(TokenPartial::issuer).isPrintableAscii().hasMaxLengthOf(64) - // valid: nothing to validate - // whitelist: nothing to validate - validate(TokenPartial::language).isLanguage() - // last_updated: : nothing to validate -} - -fun LocationReferences.validate(): LocationReferences = validate(this) { - validate(LocationReferences::location_id).isPrintableAscii().hasMaxLengthOf(39) - evse_uids - .map { StringWrapper(it) } - .forEach { - validate(it) { - validate(StringWrapper::str).isPrintableAscii().hasMaxLengthOf(39) - } - } - connector_ids - .map { StringWrapper(it) } - .forEach { - validate(it) { - validate(StringWrapper::str).isPrintableAscii().hasMaxLengthOf(39) - } - } -} - -fun AuthorizationInfo.validate(): AuthorizationInfo = validate(this) { - // allowed: nothing to validate - location?.validate() - info?.validate() -} - -fun Token.validate(): Token = validate(this) { - toPartial().validate() -} diff --git a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/types/DisplayText.kt b/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/types/DisplayText.kt deleted file mode 100644 index acbf6c7c..00000000 --- a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/types/DisplayText.kt +++ /dev/null @@ -1,13 +0,0 @@ -package com.izivia.ocpi.toolkit.modules.types - -import com.izivia.ocpi.toolkit.annotations.Partial - -/** - * @property language (max-length=2) Language Code ISO 639-1 - * @property text (max-length=512) Text to be displayed to an end user. No markup, html etc. allowed. - */ -@Partial -data class DisplayText( - val language: String, - val text: String -) diff --git a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/types/Price.kt b/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/types/Price.kt deleted file mode 100644 index 9556f318..00000000 --- a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/types/Price.kt +++ /dev/null @@ -1,15 +0,0 @@ -package com.izivia.ocpi.toolkit.modules.types - -import com.izivia.ocpi.toolkit.annotations.Partial -import java.math.BigDecimal - -/** - * @property excl_vat Price/Cost excluding VAT. - * @property incl_vat Price/Cost including VAT. - */ - -@Partial -data class Price( - val excl_vat: BigDecimal, - val incl_vat: BigDecimal? = null -) diff --git a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/versions/VersionDetailsClient.kt b/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/versions/VersionDetailsClient.kt deleted file mode 100644 index 088edc86..00000000 --- a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/versions/VersionDetailsClient.kt +++ /dev/null @@ -1,42 +0,0 @@ -package com.izivia.ocpi.toolkit.modules.versions - -import com.izivia.ocpi.toolkit.common.OcpiResponseBody -import com.izivia.ocpi.toolkit.common.OcpiToolkitUnknownEndpointException -import com.izivia.ocpi.toolkit.common.authenticate -import com.izivia.ocpi.toolkit.common.parseBody -import com.izivia.ocpi.toolkit.modules.credentials.repositories.PlatformRepository -import com.izivia.ocpi.toolkit.modules.versions.domain.VersionDetails -import com.izivia.ocpi.toolkit.transport.TransportClientBuilder -import com.izivia.ocpi.toolkit.transport.domain.HttpMethod -import com.izivia.ocpi.toolkit.transport.domain.HttpRequest - -/** - * Used to get the version details of a platform - * @property transportClientBuilder used to build transport client - * @property serverVersionsEndpointUrl used to know which platform to communicate with - * @property platformRepository used to get information about the platform (endpoint, token) - */ -class VersionDetailsClient( - private val transportClientBuilder: TransportClientBuilder, - private val serverVersionsEndpointUrl: String, - private val platformRepository: PlatformRepository -) : VersionDetailsInterface { - - override fun getVersionDetails(): OcpiResponseBody = - transportClientBuilder - .build(baseUrl = platformRepository - .getVersion(platformUrl = serverVersionsEndpointUrl) - ?.url - ?: throw OcpiToolkitUnknownEndpointException("version details") - ) - .send( - HttpRequest( - method = HttpMethod.GET - ).authenticate( - platformRepository = platformRepository, - baseUrl = serverVersionsEndpointUrl, - allowTokenAOrTokenB = true - ) - ) - .parseBody() -} diff --git a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/versions/VersionDetailsInterface.kt b/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/versions/VersionDetailsInterface.kt deleted file mode 100644 index 64d847db..00000000 --- a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/versions/VersionDetailsInterface.kt +++ /dev/null @@ -1,8 +0,0 @@ -package com.izivia.ocpi.toolkit.modules.versions - -import com.izivia.ocpi.toolkit.common.OcpiResponseBody -import com.izivia.ocpi.toolkit.modules.versions.domain.VersionDetails - -interface VersionDetailsInterface { - fun getVersionDetails(): OcpiResponseBody -} \ No newline at end of file diff --git a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/versions/VersionDetailsServer.kt b/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/versions/VersionDetailsServer.kt deleted file mode 100644 index 2aedbb59..00000000 --- a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/versions/VersionDetailsServer.kt +++ /dev/null @@ -1,36 +0,0 @@ -package com.izivia.ocpi.toolkit.modules.versions - -import com.izivia.ocpi.toolkit.common.httpResponse -import com.izivia.ocpi.toolkit.common.checkToken -import com.izivia.ocpi.toolkit.modules.credentials.repositories.PlatformRepository -import com.izivia.ocpi.toolkit.modules.versions.validation.VersionDetailsValidationService -import com.izivia.ocpi.toolkit.transport.TransportServer -import com.izivia.ocpi.toolkit.transport.domain.FixedPathSegment -import com.izivia.ocpi.toolkit.transport.domain.HttpMethod -import com.izivia.ocpi.toolkit.transport.domain.VariablePathSegment -import kotlinx.coroutines.runBlocking - -class VersionDetailsServer( - transportServer: TransportServer, - platformRepository: PlatformRepository, - validationService: VersionDetailsValidationService, - basePath: List = emptyList() -) { - init { - runBlocking { - transportServer.handle( - method = HttpMethod.GET, - path = basePath + listOf( - VariablePathSegment("versionNumber") - ), - filters = listOf(platformRepository::checkToken) - ) { req -> - req.httpResponse { - validationService.getVersionDetails( - versionNumber = req.pathParams["versionNumber"]!! - ) - } - } - } - } -} diff --git a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/versions/VersionsClient.kt b/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/versions/VersionsClient.kt deleted file mode 100644 index 2b42921d..00000000 --- a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/versions/VersionsClient.kt +++ /dev/null @@ -1,37 +0,0 @@ -package com.izivia.ocpi.toolkit.modules.versions - -import com.izivia.ocpi.toolkit.common.OcpiResponseBody -import com.izivia.ocpi.toolkit.common.authenticate -import com.izivia.ocpi.toolkit.common.parseBody -import com.izivia.ocpi.toolkit.modules.credentials.repositories.PlatformRepository -import com.izivia.ocpi.toolkit.modules.versions.domain.Version -import com.izivia.ocpi.toolkit.transport.TransportClientBuilder -import com.izivia.ocpi.toolkit.transport.domain.HttpMethod -import com.izivia.ocpi.toolkit.transport.domain.HttpRequest - -/** - * Used to get the versions of a platform - * @property transportClientBuilder used to build transport client - * @property serverVersionsEndpointUrl used to know which platform to communicate with - * @property platformRepository used to get information about the platform (token) - */ -class VersionsClient( - private val transportClientBuilder: TransportClientBuilder, - private val serverVersionsEndpointUrl: String, - private val platformRepository: PlatformRepository -) : VersionsInterface { - - override fun getVersions(): OcpiResponseBody> = - transportClientBuilder - .build(baseUrl = serverVersionsEndpointUrl) - .send( - HttpRequest( - method = HttpMethod.GET - ).authenticate( - platformRepository = platformRepository, - baseUrl = serverVersionsEndpointUrl, - allowTokenAOrTokenB = true - ) - ) - .parseBody() -} diff --git a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/versions/VersionsInterface.kt b/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/versions/VersionsInterface.kt deleted file mode 100644 index bb0883d7..00000000 --- a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/versions/VersionsInterface.kt +++ /dev/null @@ -1,8 +0,0 @@ -package com.izivia.ocpi.toolkit.modules.versions - -import com.izivia.ocpi.toolkit.common.OcpiResponseBody -import com.izivia.ocpi.toolkit.modules.versions.domain.Version - -interface VersionsInterface { - fun getVersions(): OcpiResponseBody> -} \ No newline at end of file diff --git a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/versions/VersionsServer.kt b/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/versions/VersionsServer.kt deleted file mode 100644 index b74c2911..00000000 --- a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/versions/VersionsServer.kt +++ /dev/null @@ -1,34 +0,0 @@ -package com.izivia.ocpi.toolkit.modules.versions - -import com.izivia.ocpi.toolkit.common.httpResponse -import com.izivia.ocpi.toolkit.common.checkToken -import com.izivia.ocpi.toolkit.modules.credentials.repositories.PlatformRepository -import com.izivia.ocpi.toolkit.modules.versions.validation.VersionsValidationService -import com.izivia.ocpi.toolkit.transport.TransportServer -import com.izivia.ocpi.toolkit.transport.domain.FixedPathSegment -import com.izivia.ocpi.toolkit.transport.domain.HttpMethod -import kotlinx.coroutines.runBlocking - -class VersionsServer( - transportServer: TransportServer, - platformRepository: PlatformRepository, - validationService: VersionsValidationService, - basePath: List = listOf( - FixedPathSegment("/versions") - ) -) { - - init { - runBlocking { - transportServer.handle( - method = HttpMethod.GET, - path = basePath, - filters = listOf(platformRepository::checkToken) - ) { req -> - req.httpResponse { - validationService.getVersions() - } - } - } - } -} diff --git a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/versions/domain/Endpoint.kt b/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/versions/domain/Endpoint.kt deleted file mode 100644 index 74942d54..00000000 --- a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/versions/domain/Endpoint.kt +++ /dev/null @@ -1,12 +0,0 @@ -package com.izivia.ocpi.toolkit.modules.versions.domain - -/** - * NOTE: for the credentials module, the role is not relevant as this module is the same for all roles - * - * @property identifier Endpoint identifie - * @property url URL to the endpoint - */ -data class Endpoint( - val identifier: ModuleID, - val url: String -) diff --git a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/versions/domain/ModuleID.kt b/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/versions/domain/ModuleID.kt deleted file mode 100644 index ab6c77ae..00000000 --- a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/versions/domain/ModuleID.kt +++ /dev/null @@ -1,30 +0,0 @@ -package com.izivia.ocpi.toolkit.modules.versions.domain - -/** - * The Module identifiers for each endpoint are described in the beginning of each Module chapter. The following table - * contains the list of modules in this version of OCPI. Most modules (except Credentials & Registration) are optional, - * but there might be dependencies between modules. If there are dependencies between modules, it will be mentioned in - * the affected module description. - */ -enum class ModuleID { - cdrs, - - chargingprofiles, - - commands, - - /** - * Required for all implementations. The role field has no function for this module - */ - credentials, - - hubclientinfo, - - locations, - - sessions, - - tariffs, - - tokens -} \ No newline at end of file diff --git a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/versions/domain/Version.kt b/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/versions/domain/Version.kt deleted file mode 100644 index 0da556d3..00000000 --- a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/versions/domain/Version.kt +++ /dev/null @@ -1,6 +0,0 @@ -package com.izivia.ocpi.toolkit.modules.versions.domain - -data class Version( - val version: String, - val url: String -) diff --git a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/versions/domain/VersionDetails.kt b/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/versions/domain/VersionDetails.kt deleted file mode 100644 index 5f368fb7..00000000 --- a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/versions/domain/VersionDetails.kt +++ /dev/null @@ -1,17 +0,0 @@ -package com.izivia.ocpi.toolkit.modules.versions.domain - -/** - * Via the version details, the parties can exchange which modules are implemented for a specific version of OCPI, which - * interface role is implemented, and what the endpoint URL is for this interface. - * - * Parties that are both CPO and eMSP (or a Hub) can implement one version endpoint that covers both roles. With the - * information that is available in the version details, parties don’t need to implement a separate endpoint per role - * (CPO or eMSP) anymore. In practice this means that when a company is both a CPO and an eMSP and it connects to - * another party that implements both interfaces, only one OCPI connection is needed. - * @property version The version number. - * @property endpoints A list of supported endpoints for this version. (at least one in the list) - */ -data class VersionDetails( - val version: String, - val endpoints: List -) diff --git a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/versions/domain/VersionNumber.kt b/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/versions/domain/VersionNumber.kt deleted file mode 100644 index e0825a63..00000000 --- a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/versions/domain/VersionNumber.kt +++ /dev/null @@ -1,25 +0,0 @@ -package com.izivia.ocpi.toolkit.modules.versions.domain - -/** - * List of known versions. - */ -enum class VersionNumber(val value: String, val index: Int) { - - /** - * OCPI version 2.0 - */ - V2_0("2.0", 0), - - /** - * OCPI version 2.1 (DEPRECATED, do not use, use 2.1.1 instead) - */ - V2_1("2.1", 1), - - /** - * OCPI version 2.1.1 - */ - V2_1_1("2.1.1", 2) -} - -fun parseVersionNumber(value: String): VersionNumber? = - VersionNumber.values().firstOrNull { it.value == value } \ No newline at end of file diff --git a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/versions/repositories/VersionDetailsRepository.kt b/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/versions/repositories/VersionDetailsRepository.kt deleted file mode 100644 index 8a5a3fd2..00000000 --- a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/versions/repositories/VersionDetailsRepository.kt +++ /dev/null @@ -1,8 +0,0 @@ -package com.izivia.ocpi.toolkit.modules.versions.repositories - -import com.izivia.ocpi.toolkit.modules.versions.domain.VersionDetails -import com.izivia.ocpi.toolkit.modules.versions.domain.VersionNumber - -interface VersionDetailsRepository { - fun getVersionDetails(versionNumber: VersionNumber): VersionDetails? -} \ No newline at end of file diff --git a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/versions/repositories/VersionsRepository.kt b/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/versions/repositories/VersionsRepository.kt deleted file mode 100644 index 565e308c..00000000 --- a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/versions/repositories/VersionsRepository.kt +++ /dev/null @@ -1,7 +0,0 @@ -package com.izivia.ocpi.toolkit.modules.versions.repositories - -import com.izivia.ocpi.toolkit.modules.versions.domain.Version - -interface VersionsRepository { - fun getVersions(): List -} \ No newline at end of file diff --git a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/versions/validation/VersionDetailsValidationService.kt b/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/versions/validation/VersionDetailsValidationService.kt deleted file mode 100644 index 4731b893..00000000 --- a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/versions/validation/VersionDetailsValidationService.kt +++ /dev/null @@ -1,21 +0,0 @@ -package com.izivia.ocpi.toolkit.modules.versions.validation - -import com.izivia.ocpi.toolkit.common.OcpiResponseBody -import com.izivia.ocpi.toolkit.common.OcpiServerUnsupportedVersionException -import com.izivia.ocpi.toolkit.modules.versions.domain.VersionDetails -import com.izivia.ocpi.toolkit.modules.versions.domain.parseVersionNumber -import com.izivia.ocpi.toolkit.modules.versions.repositories.VersionDetailsRepository - -class VersionDetailsValidationService( - private val repository: VersionDetailsRepository -) { - fun getVersionDetails( - versionNumber: String - ): OcpiResponseBody = OcpiResponseBody.of { - parseVersionNumber(versionNumber) - ?.let { parsedVersionNumber -> - repository.getVersionDetails(parsedVersionNumber) - } - ?: throw OcpiServerUnsupportedVersionException("Invalid version number: $versionNumber") - } -} \ No newline at end of file diff --git a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/versions/validation/VersionsValidationService.kt b/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/versions/validation/VersionsValidationService.kt deleted file mode 100644 index 699ebbb2..00000000 --- a/ocpi-toolkit-2.1.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/versions/validation/VersionsValidationService.kt +++ /dev/null @@ -1,15 +0,0 @@ -package com.izivia.ocpi.toolkit.modules.versions.validation - -import com.izivia.ocpi.toolkit.common.OcpiResponseBody -import com.izivia.ocpi.toolkit.modules.versions.VersionsInterface -import com.izivia.ocpi.toolkit.modules.versions.domain.Version -import com.izivia.ocpi.toolkit.modules.versions.repositories.VersionsRepository - -class VersionsValidationService( - private val repository: VersionsRepository -) : VersionsInterface { - - override fun getVersions(): OcpiResponseBody> = OcpiResponseBody.of { - repository.getVersions() - } -} \ No newline at end of file diff --git a/ocpi-toolkit-2.1.1/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/locations/domain/AdditionalGeoLocationPartial.kt b/ocpi-toolkit-2.1.1/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/locations/domain/AdditionalGeoLocationPartial.kt deleted file mode 100644 index 4e593072..00000000 --- a/ocpi-toolkit-2.1.1/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/locations/domain/AdditionalGeoLocationPartial.kt +++ /dev/null @@ -1,33 +0,0 @@ -// ---------- -// - WARNING - -// ---------- -// This code is generated AND MUST NOT BE EDITED -// ---------- -package com.izivia.ocpi.toolkit.modules.locations.domain - -import com.izivia.ocpi.toolkit.modules.types.DisplayTextPartial -import com.izivia.ocpi.toolkit.modules.types.toPartial -import kotlin.String -import kotlin.collections.List - -/** - * Partial representation of - * [com.izivia.ocpi.toolkit.modules.locations.domain.AdditionalGeoLocation] - */ -public data class AdditionalGeoLocationPartial( - public val latitude: String?, - public val longitude: String?, - public val name: DisplayTextPartial?, -) - -public fun AdditionalGeoLocation.toPartial(): AdditionalGeoLocationPartial { - return AdditionalGeoLocationPartial( - latitude = latitude, - longitude = longitude, - name = name?.toPartial() - ) -} - -public fun List.toPartial(): List { - return mapNotNull { it.toPartial() } -} diff --git a/ocpi-toolkit-2.1.1/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/locations/domain/BusinessDetailsPartial.kt b/ocpi-toolkit-2.1.1/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/locations/domain/BusinessDetailsPartial.kt deleted file mode 100644 index 3d3106b9..00000000 --- a/ocpi-toolkit-2.1.1/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/locations/domain/BusinessDetailsPartial.kt +++ /dev/null @@ -1,30 +0,0 @@ -// ---------- -// - WARNING - -// ---------- -// This code is generated AND MUST NOT BE EDITED -// ---------- -package com.izivia.ocpi.toolkit.modules.locations.domain - -import kotlin.String -import kotlin.collections.List - -/** - * Partial representation of [com.izivia.ocpi.toolkit.modules.locations.domain.BusinessDetails] - */ -public data class BusinessDetailsPartial( - public val name: String?, - public val website: String?, - public val logo: ImagePartial?, -) - -public fun BusinessDetails.toPartial(): BusinessDetailsPartial { - return BusinessDetailsPartial( - name = name, - website = website, - logo = logo?.toPartial() - ) -} - -public fun List.toPartial(): List { - return mapNotNull { it.toPartial() } -} diff --git a/ocpi-toolkit-2.1.1/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/locations/domain/ConnectorPartial.kt b/ocpi-toolkit-2.1.1/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/locations/domain/ConnectorPartial.kt deleted file mode 100644 index d294b8ca..00000000 --- a/ocpi-toolkit-2.1.1/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/locations/domain/ConnectorPartial.kt +++ /dev/null @@ -1,44 +0,0 @@ -// ---------- -// - WARNING - -// ---------- -// This code is generated AND MUST NOT BE EDITED -// ---------- -package com.izivia.ocpi.toolkit.modules.locations.domain - -import java.time.Instant -import kotlin.Int -import kotlin.String -import kotlin.collections.List - -/** - * Partial representation of [com.izivia.ocpi.toolkit.modules.locations.domain.Connector] - */ -public data class ConnectorPartial( - public val id: String?, - public val standard: ConnectorType?, - public val format: ConnectorFormat?, - public val power_type: PowerType?, - public val voltage: Int?, - public val amperage: Int?, - public val tariff_id: String?, - public val terms_and_conditions: String?, - public val last_updated: Instant?, -) - -public fun Connector.toPartial(): ConnectorPartial { - return ConnectorPartial( - id = id, - standard = standard, - format = format, - power_type = power_type, - voltage = voltage, - amperage = amperage, - tariff_id = tariff_id, - terms_and_conditions = terms_and_conditions, - last_updated = last_updated - ) -} - -public fun List.toPartial(): List { - return mapNotNull { it.toPartial() } -} diff --git a/ocpi-toolkit-2.1.1/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/locations/domain/EnergyMixPartial.kt b/ocpi-toolkit-2.1.1/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/locations/domain/EnergyMixPartial.kt deleted file mode 100644 index 178ec172..00000000 --- a/ocpi-toolkit-2.1.1/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/locations/domain/EnergyMixPartial.kt +++ /dev/null @@ -1,35 +0,0 @@ -// ---------- -// - WARNING - -// ---------- -// This code is generated AND MUST NOT BE EDITED -// ---------- -package com.izivia.ocpi.toolkit.modules.locations.domain - -import kotlin.Boolean -import kotlin.String -import kotlin.collections.List - -/** - * Partial representation of [com.izivia.ocpi.toolkit.modules.locations.domain.EnergyMix] - */ -public data class EnergyMixPartial( - public val is_green_energy: Boolean?, - public val energy_sources: List?, - public val environ_impact: List?, - public val supplier_name: String?, - public val energy_product_name: String?, -) - -public fun EnergyMix.toPartial(): EnergyMixPartial { - return EnergyMixPartial( - is_green_energy = is_green_energy, - energy_sources = energy_sources?.toPartial(), - environ_impact = environ_impact?.toPartial(), - supplier_name = supplier_name, - energy_product_name = energy_product_name - ) -} - -public fun List.toPartial(): List { - return mapNotNull { it.toPartial() } -} diff --git a/ocpi-toolkit-2.1.1/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/locations/domain/EnergySourcePartial.kt b/ocpi-toolkit-2.1.1/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/locations/domain/EnergySourcePartial.kt deleted file mode 100644 index 689ef406..00000000 --- a/ocpi-toolkit-2.1.1/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/locations/domain/EnergySourcePartial.kt +++ /dev/null @@ -1,28 +0,0 @@ -// ---------- -// - WARNING - -// ---------- -// This code is generated AND MUST NOT BE EDITED -// ---------- -package com.izivia.ocpi.toolkit.modules.locations.domain - -import java.math.BigDecimal -import kotlin.collections.List - -/** - * Partial representation of [com.izivia.ocpi.toolkit.modules.locations.domain.EnergySource] - */ -public data class EnergySourcePartial( - public val source: EnergySourceCategory?, - public val percentage: BigDecimal?, -) - -public fun EnergySource.toPartial(): EnergySourcePartial { - return EnergySourcePartial( - source = source, - percentage = percentage - ) -} - -public fun List.toPartial(): List { - return mapNotNull { it.toPartial() } -} diff --git a/ocpi-toolkit-2.1.1/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/locations/domain/EnvironmentalImpactPartial.kt b/ocpi-toolkit-2.1.1/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/locations/domain/EnvironmentalImpactPartial.kt deleted file mode 100644 index 3c4bd5dc..00000000 --- a/ocpi-toolkit-2.1.1/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/locations/domain/EnvironmentalImpactPartial.kt +++ /dev/null @@ -1,28 +0,0 @@ -// ---------- -// - WARNING - -// ---------- -// This code is generated AND MUST NOT BE EDITED -// ---------- -package com.izivia.ocpi.toolkit.modules.locations.domain - -import java.math.BigDecimal -import kotlin.collections.List - -/** - * Partial representation of [com.izivia.ocpi.toolkit.modules.locations.domain.EnvironmentalImpact] - */ -public data class EnvironmentalImpactPartial( - public val source: EnvironmentalImpactCategory?, - public val amount: BigDecimal?, -) - -public fun EnvironmentalImpact.toPartial(): EnvironmentalImpactPartial { - return EnvironmentalImpactPartial( - source = source, - amount = amount - ) -} - -public fun List.toPartial(): List { - return mapNotNull { it.toPartial() } -} diff --git a/ocpi-toolkit-2.1.1/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/locations/domain/EvsePartial.kt b/ocpi-toolkit-2.1.1/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/locations/domain/EvsePartial.kt deleted file mode 100644 index 11485b90..00000000 --- a/ocpi-toolkit-2.1.1/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/locations/domain/EvsePartial.kt +++ /dev/null @@ -1,53 +0,0 @@ -// ---------- -// - WARNING - -// ---------- -// This code is generated AND MUST NOT BE EDITED -// ---------- -package com.izivia.ocpi.toolkit.modules.locations.domain - -import com.izivia.ocpi.toolkit.modules.types.DisplayTextPartial -import com.izivia.ocpi.toolkit.modules.types.toPartial -import java.time.Instant -import kotlin.String -import kotlin.collections.List - -/** - * Partial representation of [com.izivia.ocpi.toolkit.modules.locations.domain.Evse] - */ -public data class EvsePartial( - public val uid: String?, - public val evse_id: String?, - public val status: Status?, - public val status_schedule: List?, - public val capabilities: List?, - public val connectors: List?, - public val floor_level: String?, - public val coordinates: GeoLocationPartial?, - public val physical_reference: String?, - public val directions: List?, - public val parking_restrictions: List?, - public val images: List?, - public val last_updated: Instant?, -) - -public fun Evse.toPartial(): EvsePartial { - return EvsePartial( - uid = uid, - evse_id = evse_id, - status = status, - status_schedule = status_schedule?.toPartial(), - capabilities = capabilities, - connectors = connectors.toPartial(), - floor_level = floor_level, - coordinates = coordinates?.toPartial(), - physical_reference = physical_reference, - directions = directions?.toPartial(), - parking_restrictions = parking_restrictions, - images = images?.toPartial(), - last_updated = last_updated - ) -} - -public fun List.toPartial(): List { - return mapNotNull { it.toPartial() } -} diff --git a/ocpi-toolkit-2.1.1/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/locations/domain/ExceptionalPeriodPartial.kt b/ocpi-toolkit-2.1.1/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/locations/domain/ExceptionalPeriodPartial.kt deleted file mode 100644 index cc44ed42..00000000 --- a/ocpi-toolkit-2.1.1/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/locations/domain/ExceptionalPeriodPartial.kt +++ /dev/null @@ -1,28 +0,0 @@ -// ---------- -// - WARNING - -// ---------- -// This code is generated AND MUST NOT BE EDITED -// ---------- -package com.izivia.ocpi.toolkit.modules.locations.domain - -import java.time.Instant -import kotlin.collections.List - -/** - * Partial representation of [com.izivia.ocpi.toolkit.modules.locations.domain.ExceptionalPeriod] - */ -public data class ExceptionalPeriodPartial( - public val period_begin: Instant?, - public val period_end: Instant?, -) - -public fun ExceptionalPeriod.toPartial(): ExceptionalPeriodPartial { - return ExceptionalPeriodPartial( - period_begin = period_begin, - period_end = period_end - ) -} - -public fun List.toPartial(): List { - return mapNotNull { it.toPartial() } -} diff --git a/ocpi-toolkit-2.1.1/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/locations/domain/GeoLocationPartial.kt b/ocpi-toolkit-2.1.1/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/locations/domain/GeoLocationPartial.kt deleted file mode 100644 index 49b0cd8a..00000000 --- a/ocpi-toolkit-2.1.1/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/locations/domain/GeoLocationPartial.kt +++ /dev/null @@ -1,28 +0,0 @@ -// ---------- -// - WARNING - -// ---------- -// This code is generated AND MUST NOT BE EDITED -// ---------- -package com.izivia.ocpi.toolkit.modules.locations.domain - -import kotlin.String -import kotlin.collections.List - -/** - * Partial representation of [com.izivia.ocpi.toolkit.modules.locations.domain.GeoLocation] - */ -public data class GeoLocationPartial( - public val latitude: String?, - public val longitude: String?, -) - -public fun GeoLocation.toPartial(): GeoLocationPartial { - return GeoLocationPartial( - latitude = latitude, - longitude = longitude - ) -} - -public fun List.toPartial(): List { - return mapNotNull { it.toPartial() } -} diff --git a/ocpi-toolkit-2.1.1/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/locations/domain/HoursPartial.kt b/ocpi-toolkit-2.1.1/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/locations/domain/HoursPartial.kt deleted file mode 100644 index c9d1cb3e..00000000 --- a/ocpi-toolkit-2.1.1/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/locations/domain/HoursPartial.kt +++ /dev/null @@ -1,32 +0,0 @@ -// ---------- -// - WARNING - -// ---------- -// This code is generated AND MUST NOT BE EDITED -// ---------- -package com.izivia.ocpi.toolkit.modules.locations.domain - -import kotlin.Boolean -import kotlin.collections.List - -/** - * Partial representation of [com.izivia.ocpi.toolkit.modules.locations.domain.Hours] - */ -public data class HoursPartial( - public val regular_hours: List?, - public val twenty_four_seven: Boolean?, - public val exceptional_openings: List?, - public val exceptional_closings: List?, -) - -public fun Hours.toPartial(): HoursPartial { - return HoursPartial( - regular_hours = regular_hours?.toPartial(), - twenty_four_seven = twenty_four_seven, - exceptional_openings = exceptional_openings?.toPartial(), - exceptional_closings = exceptional_closings?.toPartial() - ) -} - -public fun List.toPartial(): List { - return mapNotNull { it.toPartial() } -} diff --git a/ocpi-toolkit-2.1.1/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/locations/domain/ImagePartial.kt b/ocpi-toolkit-2.1.1/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/locations/domain/ImagePartial.kt deleted file mode 100644 index b5851cdf..00000000 --- a/ocpi-toolkit-2.1.1/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/locations/domain/ImagePartial.kt +++ /dev/null @@ -1,37 +0,0 @@ -// ---------- -// - WARNING - -// ---------- -// This code is generated AND MUST NOT BE EDITED -// ---------- -package com.izivia.ocpi.toolkit.modules.locations.domain - -import kotlin.Int -import kotlin.String -import kotlin.collections.List - -/** - * Partial representation of [com.izivia.ocpi.toolkit.modules.locations.domain.Image] - */ -public data class ImagePartial( - public val url: String?, - public val thumbnail: String?, - public val category: ImageCategory?, - public val type: String?, - public val width: Int?, - public val height: Int?, -) - -public fun Image.toPartial(): ImagePartial { - return ImagePartial( - url = url, - thumbnail = thumbnail, - category = category, - type = type, - width = width, - height = height - ) -} - -public fun List.toPartial(): List { - return mapNotNull { it.toPartial() } -} diff --git a/ocpi-toolkit-2.1.1/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/locations/domain/LocationPartial.kt b/ocpi-toolkit-2.1.1/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/locations/domain/LocationPartial.kt deleted file mode 100644 index f5cf64cb..00000000 --- a/ocpi-toolkit-2.1.1/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/locations/domain/LocationPartial.kt +++ /dev/null @@ -1,70 +0,0 @@ -// ---------- -// - WARNING - -// ---------- -// This code is generated AND MUST NOT BE EDITED -// ---------- -package com.izivia.ocpi.toolkit.modules.locations.domain - -import com.izivia.ocpi.toolkit.modules.types.DisplayTextPartial -import com.izivia.ocpi.toolkit.modules.types.toPartial -import java.time.Instant -import kotlin.Boolean -import kotlin.String -import kotlin.collections.List - -/** - * Partial representation of [com.izivia.ocpi.toolkit.modules.locations.domain.Location] - */ -public data class LocationPartial( - public val id: String?, - public val type: LocationType?, - public val name: String?, - public val address: String?, - public val city: String?, - public val postal_code: String?, - public val country: String?, - public val coordinates: GeoLocationPartial?, - public val related_locations: List?, - public val evses: List?, - public val directions: List?, - public val `operator`: BusinessDetailsPartial?, - public val suboperator: BusinessDetailsPartial?, - public val owner: BusinessDetailsPartial?, - public val facilities: List?, - public val time_zone: String?, - public val opening_times: HoursPartial?, - public val charging_when_closed: Boolean?, - public val images: List?, - public val energy_mix: EnergyMixPartial?, - public val last_updated: Instant?, -) - -public fun Location.toPartial(): LocationPartial { - return LocationPartial( - id = id, - type = type, - name = name, - address = address, - city = city, - postal_code = postal_code, - country = country, - coordinates = coordinates.toPartial(), - related_locations = related_locations?.toPartial(), - evses = evses?.toPartial(), - directions = directions?.toPartial(), - operator = operator?.toPartial(), - suboperator = suboperator?.toPartial(), - owner = owner?.toPartial(), - facilities = facilities, - time_zone = time_zone, - opening_times = opening_times?.toPartial(), - charging_when_closed = charging_when_closed, - images = images?.toPartial(), - energy_mix = energy_mix?.toPartial(), - last_updated = last_updated - ) -} - -public fun List.toPartial(): List { - return mapNotNull { it.toPartial() } -} diff --git a/ocpi-toolkit-2.1.1/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/locations/domain/RegularHoursPartial.kt b/ocpi-toolkit-2.1.1/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/locations/domain/RegularHoursPartial.kt deleted file mode 100644 index 1259b46b..00000000 --- a/ocpi-toolkit-2.1.1/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/locations/domain/RegularHoursPartial.kt +++ /dev/null @@ -1,31 +0,0 @@ -// ---------- -// - WARNING - -// ---------- -// This code is generated AND MUST NOT BE EDITED -// ---------- -package com.izivia.ocpi.toolkit.modules.locations.domain - -import kotlin.Int -import kotlin.String -import kotlin.collections.List - -/** - * Partial representation of [com.izivia.ocpi.toolkit.modules.locations.domain.RegularHours] - */ -public data class RegularHoursPartial( - public val weekday: Int?, - public val period_begin: String?, - public val period_end: String?, -) - -public fun RegularHours.toPartial(): RegularHoursPartial { - return RegularHoursPartial( - weekday = weekday, - period_begin = period_begin, - period_end = period_end - ) -} - -public fun List.toPartial(): List { - return mapNotNull { it.toPartial() } -} diff --git a/ocpi-toolkit-2.1.1/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/locations/domain/StatusSchedulePartial.kt b/ocpi-toolkit-2.1.1/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/locations/domain/StatusSchedulePartial.kt deleted file mode 100644 index 971f00a2..00000000 --- a/ocpi-toolkit-2.1.1/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/locations/domain/StatusSchedulePartial.kt +++ /dev/null @@ -1,30 +0,0 @@ -// ---------- -// - WARNING - -// ---------- -// This code is generated AND MUST NOT BE EDITED -// ---------- -package com.izivia.ocpi.toolkit.modules.locations.domain - -import java.time.Instant -import kotlin.collections.List - -/** - * Partial representation of [com.izivia.ocpi.toolkit.modules.locations.domain.StatusSchedule] - */ -public data class StatusSchedulePartial( - public val period_begin: Instant?, - public val period_end: Instant?, - public val status: Status?, -) - -public fun StatusSchedule.toPartial(): StatusSchedulePartial { - return StatusSchedulePartial( - period_begin = period_begin, - period_end = period_end, - status = status - ) -} - -public fun List.toPartial(): List { - return mapNotNull { it.toPartial() } -} diff --git a/ocpi-toolkit-2.1.1/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/tokens/domain/TokenPartial.kt b/ocpi-toolkit-2.1.1/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/tokens/domain/TokenPartial.kt deleted file mode 100644 index 5eb7c185..00000000 --- a/ocpi-toolkit-2.1.1/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/tokens/domain/TokenPartial.kt +++ /dev/null @@ -1,44 +0,0 @@ -// ---------- -// - WARNING - -// ---------- -// This code is generated AND MUST NOT BE EDITED -// ---------- -package com.izivia.ocpi.toolkit.modules.tokens.domain - -import java.time.Instant -import kotlin.Boolean -import kotlin.String -import kotlin.collections.List - -/** - * Partial representation of [com.izivia.ocpi.toolkit.modules.tokens.domain.Token] - */ -public data class TokenPartial( - public val uid: String?, - public val type: TokenType?, - public val auth_id: String?, - public val visual_number: String?, - public val issuer: String?, - public val valid: Boolean?, - public val whitelist: WhitelistType?, - public val language: String?, - public val last_updated: Instant?, -) - -public fun Token.toPartial(): TokenPartial { - return TokenPartial( - uid = uid, - type = type, - auth_id = auth_id, - visual_number = visual_number, - issuer = issuer, - valid = valid, - whitelist = whitelist, - language = language, - last_updated = last_updated - ) -} - -public fun List.toPartial(): List { - return mapNotNull { it.toPartial() } -} diff --git a/ocpi-toolkit-2.1.1/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/types/DisplayTextPartial.kt b/ocpi-toolkit-2.1.1/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/types/DisplayTextPartial.kt deleted file mode 100644 index 250eec77..00000000 --- a/ocpi-toolkit-2.1.1/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/types/DisplayTextPartial.kt +++ /dev/null @@ -1,28 +0,0 @@ -// ---------- -// - WARNING - -// ---------- -// This code is generated AND MUST NOT BE EDITED -// ---------- -package com.izivia.ocpi.toolkit.modules.types - -import kotlin.String -import kotlin.collections.List - -/** - * Partial representation of [com.izivia.ocpi.toolkit.modules.types.DisplayText] - */ -public data class DisplayTextPartial( - public val language: String?, - public val text: String?, -) - -public fun DisplayText.toPartial(): DisplayTextPartial { - return DisplayTextPartial( - language = language, - text = text - ) -} - -public fun List.toPartial(): List { - return mapNotNull { it.toPartial() } -} diff --git a/ocpi-toolkit-2.1.1/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/types/PricePartial.kt b/ocpi-toolkit-2.1.1/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/types/PricePartial.kt deleted file mode 100644 index 753d22b8..00000000 --- a/ocpi-toolkit-2.1.1/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/types/PricePartial.kt +++ /dev/null @@ -1,28 +0,0 @@ -// ---------- -// - WARNING - -// ---------- -// This code is generated AND MUST NOT BE EDITED -// ---------- -package com.izivia.ocpi.toolkit.modules.types - -import java.math.BigDecimal -import kotlin.collections.List - -/** - * Partial representation of [com.izivia.ocpi.toolkit.modules.types.Price] - */ -public data class PricePartial( - public val excl_vat: BigDecimal?, - public val incl_vat: BigDecimal?, -) - -public fun Price.toPartial(): PricePartial { - return PricePartial( - excl_vat = excl_vat, - incl_vat = incl_vat - ) -} - -public fun List.toPartial(): List { - return mapNotNull { it.toPartial() } -} diff --git a/ocpi-toolkit-2.1.1/src/main/resources/log4j2.xml b/ocpi-toolkit-2.1.1/src/main/resources/log4j2.xml deleted file mode 100644 index 2265c21b..00000000 --- a/ocpi-toolkit-2.1.1/src/main/resources/log4j2.xml +++ /dev/null @@ -1,24 +0,0 @@ - - - - logs/lib.log - %d [%-6p] %c{2} - %m%n - - - - - - - - - - - - - - - - - - - diff --git a/ocpi-toolkit-2.1.1/src/test/kotlin/com/izivia/ocpi/toolkit/samples/common/DummyPlatformCacheRepository.kt b/ocpi-toolkit-2.1.1/src/test/kotlin/com/izivia/ocpi/toolkit/samples/common/DummyPlatformCacheRepository.kt deleted file mode 100644 index bcfed116..00000000 --- a/ocpi-toolkit-2.1.1/src/test/kotlin/com/izivia/ocpi/toolkit/samples/common/DummyPlatformCacheRepository.kt +++ /dev/null @@ -1,10 +0,0 @@ -package com.izivia.ocpi.toolkit.samples.common - -class DummyPlatformCacheRepository(private val tokenC: String): PlatformCacheRepository() { - - override fun getPlatformUrlByTokenC(token: String): String? = super.getPlatformUrlByTokenC(token) - ?: (if (token == tokenC) "*" else null) - - override fun getCredentialsTokenC(platformUrl: String): String = super.getCredentialsTokenC(platformUrl) - ?: tokenC -} diff --git a/ocpi-toolkit-2.1.1/src/test/kotlin/com/izivia/ocpi/toolkit/samples/common/Http4kTransportClient.kt b/ocpi-toolkit-2.1.1/src/test/kotlin/com/izivia/ocpi/toolkit/samples/common/Http4kTransportClient.kt deleted file mode 100644 index efa3f5be..00000000 --- a/ocpi-toolkit-2.1.1/src/test/kotlin/com/izivia/ocpi/toolkit/samples/common/Http4kTransportClient.kt +++ /dev/null @@ -1,49 +0,0 @@ -package com.izivia.ocpi.toolkit.samples.common - -import com.izivia.ocpi.toolkit.transport.TransportClient -import com.izivia.ocpi.toolkit.transport.domain.HttpRequest -import com.izivia.ocpi.toolkit.transport.domain.HttpResponse -import com.izivia.ocpi.toolkit.transport.domain.parseHttpStatus -import org.http4k.client.JettyClient -import org.http4k.core.Method -import org.http4k.core.Request -import org.http4k.core.Uri -import org.http4k.core.then -import org.http4k.filter.ClientFilters - -class Http4kTransportClient( - baseUrl: String -) : TransportClient { - - val client = ClientFilters.SetBaseUriFrom(Uri.of(baseUrl)).then(JettyClient()) - - override fun send(request: HttpRequest): HttpResponse { - val http4kRequest = Request( - method = Method.valueOf(request.method.name), - uri = request.path - ) - .run { - request.queryParams.toList().foldRight(this) { queryParam, r -> - r.query(queryParam.first, queryParam.second) - } - } - .run { - request.headers.toList().foldRight(this) { header, r -> - r.header(header.first, header.second) - } - } - .run { - request.body?.let { body -> body(body) } ?: this - } - - return client(http4kRequest).let { - HttpResponse( - status = parseHttpStatus(it.status.code), - body = it.bodyString(), - headers = it.headers - .filter { (_, value) -> value != null } - .associate { (key, value) -> key to value!! } - ) - } - } -} diff --git a/ocpi-toolkit-2.1.1/src/test/kotlin/com/izivia/ocpi/toolkit/samples/common/Http4kTransportClientBuilder.kt b/ocpi-toolkit-2.1.1/src/test/kotlin/com/izivia/ocpi/toolkit/samples/common/Http4kTransportClientBuilder.kt deleted file mode 100644 index e5659ea7..00000000 --- a/ocpi-toolkit-2.1.1/src/test/kotlin/com/izivia/ocpi/toolkit/samples/common/Http4kTransportClientBuilder.kt +++ /dev/null @@ -1,9 +0,0 @@ -package com.izivia.ocpi.toolkit.samples.common - -import com.izivia.ocpi.toolkit.transport.TransportClient -import com.izivia.ocpi.toolkit.transport.TransportClientBuilder - -class Http4kTransportClientBuilder : TransportClientBuilder { - override fun build(baseUrl: String): TransportClient = - Http4kTransportClient(baseUrl) -} diff --git a/ocpi-toolkit-2.1.1/src/test/kotlin/com/izivia/ocpi/toolkit/samples/common/Http4kTransportServer.kt b/ocpi-toolkit-2.1.1/src/test/kotlin/com/izivia/ocpi/toolkit/samples/common/Http4kTransportServer.kt deleted file mode 100644 index b7a61e48..00000000 --- a/ocpi-toolkit-2.1.1/src/test/kotlin/com/izivia/ocpi/toolkit/samples/common/Http4kTransportServer.kt +++ /dev/null @@ -1,96 +0,0 @@ -package com.izivia.ocpi.toolkit.samples.common - -import com.izivia.ocpi.toolkit.common.OcpiException -import com.izivia.ocpi.toolkit.common.toHttpResponse -import com.izivia.ocpi.toolkit.transport.TransportServer -import com.izivia.ocpi.toolkit.transport.domain.* -import kotlinx.coroutines.runBlocking -import org.http4k.core.* -import org.http4k.filter.DebuggingFilters -import org.http4k.routing.RoutingHttpHandler -import org.http4k.routing.bind -import org.http4k.routing.path -import org.http4k.routing.routes -import org.http4k.server.Http4kServer -import org.http4k.server.Netty -import org.http4k.server.asServer - -class Http4kTransportServer( - val baseUrl: String, - val port: Int -) : TransportServer { - - private val serverRoutes: MutableList = mutableListOf() - private lateinit var server: Http4kServer - - override suspend fun handle( - method: HttpMethod, - path: List, - queryParams: List, - secured: Boolean, - filters: List<(request: HttpRequest) -> Unit>, - callback: suspend (request: HttpRequest) -> HttpResponse - ) { - val pathParams = path - .filterIsInstance(VariablePathSegment::class.java) - .map { it.path } - - val route = path.joinToString("/") { segment -> - when (segment) { - is VariablePathSegment -> "{${segment.path}}" - is FixedPathSegment -> segment.path - } - } - - serverRoutes.add( - route bind Method.valueOf(method.name) to { req: Request -> - try { - HttpRequest( - baseUrl = baseUrl, - method = method, - path = route, - pathParams = pathParams.associateWith { param -> req.path(param)!! }, - queryParams = queryParams.associateWith { param -> req.query(param) }, - headers = req.headers - .filter { (_, value) -> value != null } - .associate { (key, value) -> key to value!! }, - body = req.bodyString() - ) - .also { httpRequest -> filters.forEach { filter -> filter(httpRequest) } } - .let { httpRequest -> - runBlocking { callback(httpRequest) } - } - .let { httpResponse -> - Response(Status(httpResponse.status.code, null)) - .body(httpResponse.body ?: "") - .headers(httpResponse.headers.toList()) - } - } catch (ocpiException: OcpiException) { - ocpiException.toHttpResponse().toHttp4kResponse() - } catch (httpException: HttpException) { - Response(Status(httpException.status.code, httpException.reason)) - } catch (exception: Exception) { - Response(Status.INTERNAL_SERVER_ERROR) - } - } - ) - } - - private fun HttpResponse.toHttp4kResponse() = - Response(Status(status.code, null)) - .body(body ?: "") - .headers(headers.toList()) - - override fun start() { - server = DebuggingFilters.PrintRequestAndResponse() - .then( - serverRoutes.reduce { a, b -> routes(a, b) } - ) - .asServer(Netty(port)) - .start() - } - - override fun stop() { - server.stop() - } -} diff --git a/ocpi-toolkit-2.1.1/src/test/kotlin/com/izivia/ocpi/toolkit/samples/common/Platform.kt b/ocpi-toolkit-2.1.1/src/test/kotlin/com/izivia/ocpi/toolkit/samples/common/Platform.kt deleted file mode 100644 index 86b36f3f..00000000 --- a/ocpi-toolkit-2.1.1/src/test/kotlin/com/izivia/ocpi/toolkit/samples/common/Platform.kt +++ /dev/null @@ -1,13 +0,0 @@ -package com.izivia.ocpi.toolkit.samples.common - -import com.izivia.ocpi.toolkit.modules.versions.domain.Endpoint -import com.izivia.ocpi.toolkit.modules.versions.domain.Version - -data class Platform( - val url: String? = null, - val version: Version? = null, - val endpoints: List? = null, - val tokenA: String? = null, - val tokenB: String? = null, - val tokenC: String? = null -) diff --git a/ocpi-toolkit-2.1.1/src/test/kotlin/com/izivia/ocpi/toolkit/samples/common/PlatformCacheRepository.kt b/ocpi-toolkit-2.1.1/src/test/kotlin/com/izivia/ocpi/toolkit/samples/common/PlatformCacheRepository.kt deleted file mode 100644 index 1490ee78..00000000 --- a/ocpi-toolkit-2.1.1/src/test/kotlin/com/izivia/ocpi/toolkit/samples/common/PlatformCacheRepository.kt +++ /dev/null @@ -1,113 +0,0 @@ -package com.izivia.ocpi.toolkit.samples.common - -import com.izivia.ocpi.toolkit.modules.credentials.repositories.PlatformRepository -import com.izivia.ocpi.toolkit.modules.versions.domain.Endpoint -import com.izivia.ocpi.toolkit.modules.versions.domain.Version - -open class PlatformCacheRepository : PlatformRepository { - val platforms = mutableListOf() - - private fun List.getOrDefault(url: String, platform: Platform): Platform = - platforms[url] ?: platform - - private operator fun List.get(url: String): Platform? = - platforms.firstOrNull { it.url == url } - - private operator fun List.set(url: String, platform: Platform) { - platforms.removeAll { it.url == url } - platforms.add(platform) - } - - override fun savePlatformUrlForTokenA(tokenA: String, platformUrl: String): String? = platforms - .toList() - .firstOrNull { it.tokenA == tokenA } - ?.copy(url = platformUrl) - ?.also { platforms[it.url!!] = it } - ?.url - - override fun saveVersion(platformUrl: String, version: Version): Version = platforms - .getOrDefault(platformUrl, Platform(platformUrl)) - .copy(version = version) - .also { platforms[it.url!!] = it } - .let { it.version!! } - - override fun saveEndpoints(platformUrl: String, endpoints: List): List = platforms - .getOrDefault(platformUrl, Platform(platformUrl)) - .copy(endpoints = endpoints) - .also { platforms[it.url!!] = it } - .let { it.endpoints!! } - - override fun saveCredentialsTokenA(platformUrl: String, credentialsTokenA: String): String = platforms - .getOrDefault(platformUrl, Platform(platformUrl)) - .copy(tokenA = credentialsTokenA) - .also { platforms[it.url!!] = it } - .let { it.tokenA!! } - - override fun saveCredentialsTokenB(platformUrl: String, credentialsTokenB: String): String = platforms - .getOrDefault(platformUrl, Platform(platformUrl)) - .copy(tokenB = credentialsTokenB) - .also { platforms[it.url!!] = it } - .let { it.tokenB!! } - - override fun saveCredentialsTokenC(platformUrl: String, credentialsTokenC: String): String = platforms - .getOrDefault(platformUrl, Platform(platformUrl)) - .copy(tokenC = credentialsTokenC) - .also { platforms[it.url!!] = it } - .let { it.tokenC!! } - - override fun getCredentialsTokenC(platformUrl: String): String? = platforms[platformUrl]?.tokenC - - override fun getCredentialsTokenB(platformUrl: String): String? = platforms[platformUrl]?.tokenB - - override fun getCredentialsTokenA(platformUrl: String): String? = platforms[platformUrl]?.tokenA - - override fun platformExistsWithTokenA(token: String): Boolean = platforms - .any { it.tokenA == token } - - override fun platformExistsWithTokenB(token: String): Boolean = platforms - .any { it.tokenB == token } - - override fun getPlatformUrlByTokenC(token: String): String? = platforms - .firstOrNull { it.tokenC == token }?.url - - override fun getEndpoints(platformUrl: String): List = platforms - .firstOrNull { it.url == platformUrl }?.endpoints ?: emptyList() - - override fun getVersion(platformUrl: String): Version? = platforms - .firstOrNull { it.url == platformUrl }?.version - - override fun removeCredentialsTokenA(platformUrl: String) { - platforms - .getOrDefault(platformUrl, Platform(platformUrl)) - .copy(tokenA = null) - .also { platforms[it.url!!] = it } - } - - override fun removeCredentialsTokenB(platformUrl: String) { - platforms - .getOrDefault(platformUrl, Platform(platformUrl)) - .copy(tokenB = null) - .also { platforms[it.url!!] = it } - } - - override fun removeCredentialsTokenC(platformUrl: String) { - platforms - .getOrDefault(platformUrl, Platform(platformUrl)) - .copy(tokenC = null) - .also { platforms[it.url!!] = it } - } - - override fun removeVersion(platformUrl: String) { - platforms - .getOrDefault(platformUrl, Platform(platformUrl)) - .copy(version = null) - .also { platforms[it.url!!] = it } - } - - override fun removeEndpoints(platformUrl: String) { - platforms - .getOrDefault(platformUrl, Platform(platformUrl)) - .copy(endpoints = null) - .also { platforms[it.url!!] = it } - } -} diff --git a/ocpi-toolkit-2.1.1/src/test/kotlin/com/izivia/ocpi/toolkit/samples/common/ValidDomainObjets.kt b/ocpi-toolkit-2.1.1/src/test/kotlin/com/izivia/ocpi/toolkit/samples/common/ValidDomainObjets.kt deleted file mode 100644 index 814f5f17..00000000 --- a/ocpi-toolkit-2.1.1/src/test/kotlin/com/izivia/ocpi/toolkit/samples/common/ValidDomainObjets.kt +++ /dev/null @@ -1,158 +0,0 @@ -package com.izivia.ocpi.toolkit.samples.common - -import com.izivia.ocpi.toolkit.common.validation.Iso639Alpha2 -import com.izivia.ocpi.toolkit.modules.locations.domain.* -import com.izivia.ocpi.toolkit.modules.tokens.domain.LocationReferences -import com.izivia.ocpi.toolkit.modules.tokens.domain.Token -import com.izivia.ocpi.toolkit.modules.tokens.domain.TokenType -import com.izivia.ocpi.toolkit.modules.tokens.domain.WhitelistType -import com.izivia.ocpi.toolkit.modules.types.DisplayText -import java.math.BigDecimal -import java.time.Instant - -val validUrl = "https://abc.com" -val validLatitude = "-15.234567" -val validLongitude = "23.234567" - -val validStatusSchedule = StatusSchedule( - period_begin = Instant.parse("2022-04-28T08:00:00.000Z"), - period_end = Instant.parse("2022-04-28T09:00:00.000Z"), - status = Status.AVAILABLE -) - -val validDisplayText = DisplayText( - language = "fr", - text = "abcdef" -) - -val validGeoLocation = GeoLocation( - latitude = validLatitude, - longitude = validLongitude -) - -val validAdditionalGeoLocation = AdditionalGeoLocation( - latitude = validLatitude, - longitude = validLongitude, - name = validDisplayText -) - -val validImage = Image( - url = validUrl, - thumbnail = validUrl, - category = ImageCategory.LOCATION, - type = "jpeg", - width = 12345, - height = 123 -) - -val validBusinessDetails = BusinessDetails( - name = "name", - website = validUrl, - logo = validImage -) - -val validRegularHours = RegularHours( - weekday = 1, - period_begin = "00:00", - period_end = "23:59", -) - -val validExceptionalPeriod = ExceptionalPeriod( - period_begin = Instant.parse("2022-04-28T08:00:00.000Z"), - period_end = Instant.parse("2022-04-28T09:00:00.000Z") -) - -val validHours = Hours( - regular_hours = listOf(validRegularHours), - twenty_four_seven = null, - exceptional_openings = listOf(validExceptionalPeriod), - exceptional_closings = emptyList() -) - -val validEnergySource = EnergySource( - source = EnergySourceCategory.NUCLEAR, - percentage = BigDecimal.ZERO -) - -val validEnvironmentalImpact = EnvironmentalImpact( - source = EnvironmentalImpactCategory.CARBON_DIOXIDE, - amount = BigDecimal.ZERO -) - -val validEnergyMix = EnergyMix( - is_green_energy = true, - energy_sources = listOf(validEnergySource), - environ_impact = listOf(validEnvironmentalImpact), - supplier_name = "supplier_name", - energy_product_name = "energy_product_name" -) - -val validLocation = Location( - id = "location1", - type = LocationType.ON_STREET, - name = "name", - address = "address", - city = "city", - postal_code = "33520", - country = "FRA", - coordinates = validGeoLocation, - related_locations = listOf(validAdditionalGeoLocation), - evses = emptyList(), - directions = listOf(validDisplayText), - operator = validBusinessDetails, - suboperator = null, - owner = null, - facilities = listOf(Facility.CARPOOL_PARKING), - time_zone = "Europe/Oslo", - opening_times = validHours, - charging_when_closed = false, - images = listOf(validImage), - energy_mix = validEnergyMix, - last_updated = Instant.now() -) - -val validConnector = Connector( - id = "id", - standard = ConnectorType.DOMESTIC_A, - format = ConnectorFormat.CABLE, - power_type = PowerType.AC_1_PHASE, - voltage = 12, - amperage = 8, - tariff_id = "tariff_id", - terms_and_conditions = "https://myspecs.com/me", - last_updated = Instant.now() -) - -val validEvse = Evse( - uid = "uid", - evse_id = "FR*A23*E45B*78C", - status = Status.AVAILABLE, - status_schedule = listOf(validStatusSchedule), - capabilities = listOf(Capability.CHARGING_PROFILE_CAPABLE), - connectors = listOf(validConnector), - floor_level = "5", - coordinates = validGeoLocation, - physical_reference = "visualid1", - directions = listOf(validDisplayText), - parking_restrictions = listOf(ParkingRestriction.CUSTOMERS), - images = listOf(validImage), - last_updated = Instant.now() -) - -val validToken = Token( - uid = "012345678", - type = TokenType.RFID, - auth_id = "DE8ACC12E46L89", - visual_number = "DF000-2001-8999", - issuer = "TheNewMotion", - valid = true, - whitelist = WhitelistType.ALLOWED, - last_updated = Instant.parse("2015-06-29T22:39:09Z"), - language = Iso639Alpha2.fr.name -) - -val validLocationReferences = LocationReferences( - location_id = validLocation.id, - evse_uids = listOf(validEvse.uid), - connector_ids = listOf(validConnector.id) -) diff --git a/ocpi-toolkit-2.1.1/src/test/kotlin/com/izivia/ocpi/toolkit/samples/common/VersionDetailsCacheRepository.kt b/ocpi-toolkit-2.1.1/src/test/kotlin/com/izivia/ocpi/toolkit/samples/common/VersionDetailsCacheRepository.kt deleted file mode 100644 index 317236ce..00000000 --- a/ocpi-toolkit-2.1.1/src/test/kotlin/com/izivia/ocpi/toolkit/samples/common/VersionDetailsCacheRepository.kt +++ /dev/null @@ -1,31 +0,0 @@ -package com.izivia.ocpi.toolkit.samples.common - -import com.izivia.ocpi.toolkit.modules.versions.domain.Endpoint -import com.izivia.ocpi.toolkit.modules.versions.domain.ModuleID -import com.izivia.ocpi.toolkit.modules.versions.domain.VersionDetails -import com.izivia.ocpi.toolkit.modules.versions.domain.VersionNumber -import com.izivia.ocpi.toolkit.modules.versions.repositories.VersionDetailsRepository - -class VersionDetailsCacheRepository( - private val baseUrl: String -): VersionDetailsRepository { - - override fun getVersionDetails(versionNumber: VersionNumber): VersionDetails? = - VersionDetails( - version = VersionNumber.V2_1_1.value, - endpoints = listOf( - Endpoint( - identifier = ModuleID.credentials, - url = "$baseUrl/${VersionNumber.V2_1_1.value}/credentials" - ), - Endpoint( - identifier = ModuleID.locations, - url = "$baseUrl/${VersionNumber.V2_1_1.value}/locations" - ), - Endpoint( - identifier = ModuleID.tokens, - url = "$baseUrl/${VersionNumber.V2_1_1.value}/tokens" - ) - ) - ).takeIf { versionNumber.value == it.version } -} diff --git a/ocpi-toolkit-2.1.1/src/test/kotlin/com/izivia/ocpi/toolkit/samples/common/VersionsCacheRepository.kt b/ocpi-toolkit-2.1.1/src/test/kotlin/com/izivia/ocpi/toolkit/samples/common/VersionsCacheRepository.kt deleted file mode 100644 index 1ff116b1..00000000 --- a/ocpi-toolkit-2.1.1/src/test/kotlin/com/izivia/ocpi/toolkit/samples/common/VersionsCacheRepository.kt +++ /dev/null @@ -1,17 +0,0 @@ -package com.izivia.ocpi.toolkit.samples.common - -import com.izivia.ocpi.toolkit.modules.versions.domain.Version -import com.izivia.ocpi.toolkit.modules.versions.domain.VersionNumber -import com.izivia.ocpi.toolkit.modules.versions.repositories.VersionsRepository - -class VersionsCacheRepository( - private val baseUrl: String -): VersionsRepository { - - override fun getVersions(): List = listOf( - Version( - version = VersionNumber.V2_1_1.value, - url = "$baseUrl/${VersionNumber.V2_1_1.value}" - ) - ) -} \ No newline at end of file diff --git a/ocpi-toolkit-2.1.1/src/test/kotlin/com/izivia/ocpi/toolkit/samples/credentials/CredentialsReceiver.kt b/ocpi-toolkit-2.1.1/src/test/kotlin/com/izivia/ocpi/toolkit/samples/credentials/CredentialsReceiver.kt deleted file mode 100644 index 38e9c579..00000000 --- a/ocpi-toolkit-2.1.1/src/test/kotlin/com/izivia/ocpi/toolkit/samples/credentials/CredentialsReceiver.kt +++ /dev/null @@ -1,53 +0,0 @@ -package com.izivia.ocpi.toolkit.samples.credentials - -import com.izivia.ocpi.toolkit.modules.credentials.CredentialsServer -import com.izivia.ocpi.toolkit.modules.credentials.services.CredentialsServerService -import com.izivia.ocpi.toolkit.modules.locations.domain.BusinessDetails -import com.izivia.ocpi.toolkit.modules.versions.VersionDetailsServer -import com.izivia.ocpi.toolkit.modules.versions.VersionsServer -import com.izivia.ocpi.toolkit.modules.versions.validation.VersionDetailsValidationService -import com.izivia.ocpi.toolkit.modules.versions.validation.VersionsValidationService -import com.izivia.ocpi.toolkit.samples.common.* - -const val receiverPort = 8080 -const val receiverUrl = "http://localhost:$receiverPort" -const val receiverVersionsUrl = "http://localhost:$receiverPort/versions" -const val tokenA = "06f7967e-65c3-4def-a966-701ffb362b3c" - -fun main() { - // Add token A associated with the sender - val receiverPlatformRepository = PlatformCacheRepository() - receiverPlatformRepository.platforms.add(Platform(tokenA = tokenA)) - - val receiverServer = Http4kTransportServer( - baseUrl = receiverUrl, - port = receiverPort - ) - - CredentialsServer( - transportServer = receiverServer, - service = CredentialsServerService( - platformRepository = receiverPlatformRepository, - serverBusinessDetails = BusinessDetails(name = "Receiver", website = null, logo = null), - serverPartyId = "DEF", - serverCountryCode = "FR", - transportClientBuilder = Http4kTransportClientBuilder(), - serverVersionsUrl = receiverVersionsUrl - ) - ) - VersionsServer( - transportServer = receiverServer, - platformRepository = receiverPlatformRepository, - validationService = VersionsValidationService( - repository = VersionsCacheRepository(baseUrl = receiverUrl) - ) - ) - VersionDetailsServer( - transportServer = receiverServer, - platformRepository = receiverPlatformRepository, - validationService = VersionDetailsValidationService( - repository = VersionDetailsCacheRepository(baseUrl = receiverUrl) - ) - ) - receiverServer.start() -} diff --git a/ocpi-toolkit-2.1.1/src/test/kotlin/com/izivia/ocpi/toolkit/samples/credentials/CredentialsSender.kt b/ocpi-toolkit-2.1.1/src/test/kotlin/com/izivia/ocpi/toolkit/samples/credentials/CredentialsSender.kt deleted file mode 100644 index 2a4597ea..00000000 --- a/ocpi-toolkit-2.1.1/src/test/kotlin/com/izivia/ocpi/toolkit/samples/credentials/CredentialsSender.kt +++ /dev/null @@ -1,72 +0,0 @@ -package com.izivia.ocpi.toolkit.samples.credentials - -import com.izivia.ocpi.toolkit.modules.credentials.services.CredentialsClientService -import com.izivia.ocpi.toolkit.modules.locations.domain.BusinessDetails -import com.izivia.ocpi.toolkit.modules.versions.VersionDetailsServer -import com.izivia.ocpi.toolkit.modules.versions.VersionsServer -import com.izivia.ocpi.toolkit.modules.versions.validation.VersionDetailsValidationService -import com.izivia.ocpi.toolkit.modules.versions.validation.VersionsValidationService -import com.izivia.ocpi.toolkit.samples.common.* - -const val senderPort = 8081 -const val senderUrl = "http://localhost:$senderPort" -const val senderVersionsUrl = "http://localhost:$senderPort/versions" - -fun main() { - // Add token A associated with the sender - val senderVersionsRepository = VersionsCacheRepository(baseUrl = senderUrl) - val senderVersionDetailsRepository = VersionDetailsCacheRepository(baseUrl = senderUrl) - val senderPlatformRepository = PlatformCacheRepository() - senderPlatformRepository.platforms.add(Platform(url = receiverVersionsUrl, tokenA = tokenA)) - - // Server - val senderServer = Http4kTransportServer( - baseUrl = senderUrl, - port = senderPort - ) - - VersionsServer( - transportServer = senderServer, - platformRepository = senderPlatformRepository, - validationService = VersionsValidationService( - repository = senderVersionsRepository - ) - ) - VersionDetailsServer( - transportServer = senderServer, - platformRepository = senderPlatformRepository, - validationService = VersionDetailsValidationService( - repository = senderVersionDetailsRepository - ) - ) - senderServer.start() - - // Client - - val credentialsClientService = CredentialsClientService( - clientVersionsEndpointUrl = senderVersionsUrl, - clientPlatformRepository = senderPlatformRepository, - clientVersionsRepository = senderVersionsRepository, - clientBusinessDetails = BusinessDetails(name = "Sender", website = null, logo = null), - clientPartyId = "ABC", - clientCountryCode = "FR", - serverVersionsEndpointUrl = receiverVersionsUrl, - transportClientBuilder = Http4kTransportClientBuilder() - ) - - println("Registering $senderUrl to $receiverUrl") - var credentials = credentialsClientService.register() - println("Success. Credentials after register : $credentials") - - println("Retrieving credentials from $receiverUrl...") - credentials = credentialsClientService.get() - println("Success. Credentials : $credentials") - - println("Looking for updates, and updating if needed $receiverUrl...") - credentials = credentialsClientService.update() - println("Success. Credentials : $credentials") - - println("Deleting credentials of $senderUrl on $receiverUrl...") - credentialsClientService.delete() - println("Success.") -} diff --git a/ocpi-toolkit-2.1.1/src/test/kotlin/com/izivia/ocpi/toolkit/samples/locations/LocationsCommon.kt b/ocpi-toolkit-2.1.1/src/test/kotlin/com/izivia/ocpi/toolkit/samples/locations/LocationsCommon.kt deleted file mode 100644 index 0fadbb39..00000000 --- a/ocpi-toolkit-2.1.1/src/test/kotlin/com/izivia/ocpi/toolkit/samples/locations/LocationsCommon.kt +++ /dev/null @@ -1,21 +0,0 @@ -package com.izivia.ocpi.toolkit.samples.locations - -import com.izivia.ocpi.toolkit.modules.versions.domain.VersionNumber -import com.izivia.ocpi.toolkit.samples.common.DummyPlatformCacheRepository -import com.izivia.ocpi.toolkit.samples.common.VersionDetailsCacheRepository - -const val CREDENTIALS_TOKEN_C = "e0748bbe-d535-4a6b-8f80-94f2457d5b9d" -val DUMMY_PLATFORM_REPOSITORY = DummyPlatformCacheRepository(tokenC = CREDENTIALS_TOKEN_C).also { - val versionDetailsEmsp = VersionDetailsCacheRepository(baseUrl = emspServerUrl) - val versionDetailsCpo = VersionDetailsCacheRepository(baseUrl = cpoServerUrl) - - it.saveEndpoints( - emspServerVersionsUrl, - versionDetailsEmsp.getVersionDetails(VersionNumber.V2_1_1)!!.endpoints - ) - - it.saveEndpoints( - cpoServerVersionsUrl, - versionDetailsCpo.getVersionDetails(VersionNumber.V2_1_1)!!.endpoints - ) -} \ No newline at end of file diff --git a/ocpi-toolkit-2.1.1/src/test/kotlin/com/izivia/ocpi/toolkit/samples/locations/LocationsCpoClient.kt b/ocpi-toolkit-2.1.1/src/test/kotlin/com/izivia/ocpi/toolkit/samples/locations/LocationsCpoClient.kt deleted file mode 100644 index 6e62d23e..00000000 --- a/ocpi-toolkit-2.1.1/src/test/kotlin/com/izivia/ocpi/toolkit/samples/locations/LocationsCpoClient.kt +++ /dev/null @@ -1,21 +0,0 @@ -package com.izivia.ocpi.toolkit.samples.locations - -import com.izivia.ocpi.toolkit.modules.locations.LocationsCpoClient -import com.izivia.ocpi.toolkit.samples.common.Http4kTransportClientBuilder - -/** - * Example on how to use the CPO client - */ -fun main() { - // We instantiate the clients that we want to use - val locationsCpoClient = LocationsCpoClient( - transportClientBuilder = Http4kTransportClientBuilder(), - serverVersionsEndpointUrl = emspServerVersionsUrl, - platformRepository = DUMMY_PLATFORM_REPOSITORY - ) - - // We can use it - println( - locationsCpoClient.getLocation(countryCode = "fr", partyId = "abc", locationId = "location1") - ) -} \ No newline at end of file diff --git a/ocpi-toolkit-2.1.1/src/test/kotlin/com/izivia/ocpi/toolkit/samples/locations/LocationsCpoServer.kt b/ocpi-toolkit-2.1.1/src/test/kotlin/com/izivia/ocpi/toolkit/samples/locations/LocationsCpoServer.kt deleted file mode 100644 index fc360afc..00000000 --- a/ocpi-toolkit-2.1.1/src/test/kotlin/com/izivia/ocpi/toolkit/samples/locations/LocationsCpoServer.kt +++ /dev/null @@ -1,54 +0,0 @@ -package com.izivia.ocpi.toolkit.samples.locations - -import com.izivia.ocpi.toolkit.common.SearchResult -import com.izivia.ocpi.toolkit.modules.locations.LocationsCpoServer -import com.izivia.ocpi.toolkit.modules.locations.domain.Connector -import com.izivia.ocpi.toolkit.modules.locations.domain.Evse -import com.izivia.ocpi.toolkit.modules.locations.domain.Location -import com.izivia.ocpi.toolkit.modules.locations.services.LocationsCpoService -import com.izivia.ocpi.toolkit.modules.locations.validation.LocationsCpoValidationService -import com.izivia.ocpi.toolkit.samples.common.Http4kTransportServer -import java.time.Instant - -val cpoServerUrl = "http://localhost:8080" -val cpoServerVersionsUrl = "http://localhost:8080/versions" -val cpoServerPort = 8080 - -/** - * Example on how to serve a CPO server - */ -fun main() { - // We specify the transport to serve the cpo server - val transportServer = Http4kTransportServer(baseUrl = cpoServerUrl, port = cpoServerPort) - - // We specify service for the validation service - val service = CacheLocationsCpoService() - - // We implement callbacks for the server using the built-in service and our service implementation - LocationsCpoServer( - transportServer = transportServer, - platformRepository = DUMMY_PLATFORM_REPOSITORY, - service = LocationsCpoValidationService(service = service) - ) - - // It is recommended to start the server after setting up the routes to handle - transportServer.start() -} - -class CacheLocationsCpoService : LocationsCpoService { - override fun getLocations(dateFrom: Instant?, dateTo: Instant?, offset: Int, limit: Int?): SearchResult { - TODO("Not yet implemented") - } - - override fun getLocation(locationId: String): Location? { - TODO("Not yet implemented") - } - - override fun getEvse(locationId: String, evseUid: String): Evse? { - TODO("Not yet implemented") - } - - override fun getConnector(locationId: String, evseUid: String, connectorId: String): Connector? { - TODO("Not yet implemented") - } -} diff --git a/ocpi-toolkit-2.1.1/src/test/kotlin/com/izivia/ocpi/toolkit/samples/locations/LocationsEmspClient.kt b/ocpi-toolkit-2.1.1/src/test/kotlin/com/izivia/ocpi/toolkit/samples/locations/LocationsEmspClient.kt deleted file mode 100644 index c2c1e632..00000000 --- a/ocpi-toolkit-2.1.1/src/test/kotlin/com/izivia/ocpi/toolkit/samples/locations/LocationsEmspClient.kt +++ /dev/null @@ -1,21 +0,0 @@ -package com.izivia.ocpi.toolkit.samples.locations - -import com.izivia.ocpi.toolkit.modules.locations.LocationsEmspClient -import com.izivia.ocpi.toolkit.samples.common.Http4kTransportClientBuilder - -/** - * Example on how to use the eMSP client - */ -fun main() { - // We instantiate the clients that we want to use - val locationsEmspClient = LocationsEmspClient( - transportClientBuilder = Http4kTransportClientBuilder(), - serverVersionsEndpointUrl = cpoServerVersionsUrl, - platformRepository = DUMMY_PLATFORM_REPOSITORY - ) - - // We can use it - println( - locationsEmspClient.getConnector(locationId = "location1", evseUid = "evse1", connectorId = "connector1") - ) -} \ No newline at end of file diff --git a/ocpi-toolkit-2.1.1/src/test/kotlin/com/izivia/ocpi/toolkit/samples/locations/LocationsEmspServer.kt b/ocpi-toolkit-2.1.1/src/test/kotlin/com/izivia/ocpi/toolkit/samples/locations/LocationsEmspServer.kt deleted file mode 100644 index 19cbd15b..00000000 --- a/ocpi-toolkit-2.1.1/src/test/kotlin/com/izivia/ocpi/toolkit/samples/locations/LocationsEmspServer.kt +++ /dev/null @@ -1,124 +0,0 @@ -package com.izivia.ocpi.toolkit.samples.locations - -import com.izivia.ocpi.toolkit.modules.locations.LocationsEmspServer -import com.izivia.ocpi.toolkit.modules.locations.domain.* -import com.izivia.ocpi.toolkit.modules.locations.services.LocationsEmspService -import com.izivia.ocpi.toolkit.modules.locations.validation.LocationsEmspValidationService -import com.izivia.ocpi.toolkit.samples.common.Http4kTransportServer -import java.time.Instant - -val emspServerUrl = "http://localhost:8081" -val emspServerVersionsUrl = "http://localhost:8081/versions" -val emspServerPort = 8081 - -/** - * Example on how to server an eMSP server - */ -fun main() { - // We specify the transport to serve the eMSP server - val transportServer = Http4kTransportServer(baseUrl = emspServerUrl, port = emspServerPort) - - // We specify service for the validation service - val service = CacheLocationsEmspService() - - // We implement callbacks for the server using the built-in service and our repository implementation - LocationsEmspServer( - transportServer = transportServer, - platformRepository = DUMMY_PLATFORM_REPOSITORY, - service = LocationsEmspValidationService(service = service) - ) - - // It is recommended to start the server after setting up the routes to handle - transportServer.start() -} - -class CacheLocationsEmspService : LocationsEmspService { - override fun getLocation(countryCode: String, partyId: String, locationId: String): Location? { - return Location( - id = locationId, - type = LocationType.ON_STREET, - name = null, - address = "1 avenue des satellites", - city = "Bruges", - postal_code = "33520", - country = "FRA", - coordinates = GeoLocation(latitude = "-15.234567", longitude = "23.234567"), - related_locations = emptyList(), - evses = emptyList(), - directions = emptyList(), - operator = null, - suboperator = null, - owner = null, - facilities = emptyList(), - time_zone = null, - opening_times = null, - charging_when_closed = null, - images = emptyList(), - energy_mix = null, - last_updated = Instant.now() - ) - } - - override fun getEvse(countryCode: String, partyId: String, locationId: String, evseUid: String): Evse? { - TODO("Not yet implemented") - } - - override fun getConnector( - countryCode: String, - partyId: String, - locationId: String, - evseUid: String, - connectorId: String - ): Connector? { - TODO("Not yet implemented") - } - - override fun putLocation(countryCode: String, partyId: String, locationId: String, location: Location): Location { - TODO("Not yet implemented") - } - - override fun putEvse(countryCode: String, partyId: String, locationId: String, evseUid: String, evse: Evse): Evse { - TODO("Not yet implemented") - } - - override fun putConnector( - countryCode: String, - partyId: String, - locationId: String, - evseUid: String, - connectorId: String, - connector: Connector - ): Connector { - TODO("Not yet implemented") - } - - override fun patchLocation( - countryCode: String, - partyId: String, - locationId: String, - location: LocationPartial - ): Location? { - TODO("Not yet implemented") - } - - override fun patchEvse( - countryCode: String, - partyId: String, - locationId: String, - evseUid: String, - evse: EvsePartial - ): Evse? { - TODO("Not yet implemented") - } - - override fun patchConnector( - countryCode: String, - partyId: String, - locationId: String, - evseUid: String, - connectorId: String, - connector: ConnectorPartial - ): Connector? { - TODO("Not yet implemented") - } -} diff --git a/ocpi-toolkit-2.1.1/src/test/kotlin/com/izivia/ocpi/toolkit/tests/integration/CredentialsIntegrationTests.kt b/ocpi-toolkit-2.1.1/src/test/kotlin/com/izivia/ocpi/toolkit/tests/integration/CredentialsIntegrationTests.kt deleted file mode 100644 index f4983fd2..00000000 --- a/ocpi-toolkit-2.1.1/src/test/kotlin/com/izivia/ocpi/toolkit/tests/integration/CredentialsIntegrationTests.kt +++ /dev/null @@ -1,412 +0,0 @@ -package com.izivia.ocpi.toolkit.tests.integration - -import com.izivia.ocpi.toolkit.common.OcpiClientInvalidParametersException -import com.izivia.ocpi.toolkit.common.OcpiResponseException -import com.izivia.ocpi.toolkit.common.OcpiStatus -import com.izivia.ocpi.toolkit.modules.credentials.CredentialsServer -import com.izivia.ocpi.toolkit.modules.credentials.services.CredentialsClientService -import com.izivia.ocpi.toolkit.modules.credentials.services.CredentialsServerService -import com.izivia.ocpi.toolkit.modules.locations.domain.BusinessDetails -import com.izivia.ocpi.toolkit.modules.versions.VersionDetailsServer -import com.izivia.ocpi.toolkit.modules.versions.VersionsClient -import com.izivia.ocpi.toolkit.modules.versions.VersionsServer -import com.izivia.ocpi.toolkit.modules.versions.validation.VersionDetailsValidationService -import com.izivia.ocpi.toolkit.modules.versions.validation.VersionsValidationService -import com.izivia.ocpi.toolkit.samples.common.* -import com.izivia.ocpi.toolkit.tests.integration.common.BaseServerIntegrationTest -import com.izivia.ocpi.toolkit.tests.integration.mock.PlatformMongoRepository -import com.mongodb.client.MongoCollection -import com.mongodb.client.MongoDatabase -import org.junit.jupiter.api.Test -import org.litote.kmongo.eq -import org.litote.kmongo.getCollection -import strikt.api.expectCatching -import strikt.api.expectThat -import strikt.assertions.* -import java.util.* - - -class CredentialsIntegrationTests : BaseServerIntegrationTest() { - - data class ServerSetupResult( - val transport: Http4kTransportServer, - val platformCollection: MongoCollection, - val versionsEndpoint: String - ) - - private var database: MongoDatabase? = null - - private fun setupReceiver(): ServerSetupResult { - if (database == null) database = buildDBClient().getDatabase("ocpi-2-1-1-tests") - val receiverPlatformCollection = database!! - .getCollection("receiver-server-${UUID.randomUUID()}") - - // Setup receiver (only server) - val receiverServer = buildTransportServer() - val receiverServerVersionsUrl = "${receiverServer.baseUrl}/versions" - val receiverPlatformRepo = PlatformMongoRepository(collection = receiverPlatformCollection) - val receiverVersionsCacheRepository = VersionsCacheRepository(baseUrl = receiverServer.baseUrl) - val receiverVersionDetailsCacheRepository = VersionDetailsCacheRepository(baseUrl = receiverServer.baseUrl) - CredentialsServer( - transportServer = receiverServer, - service = CredentialsServerService( - platformRepository = receiverPlatformRepo, - serverBusinessDetails = BusinessDetails(name = "Receiver", website = null, logo = null), - serverPartyId = "DEF", - serverCountryCode = "FR", - transportClientBuilder = Http4kTransportClientBuilder(), - serverVersionsUrl = receiverServerVersionsUrl - ) - ) - VersionsServer( - transportServer = receiverServer, - platformRepository = receiverPlatformRepo, - validationService = VersionsValidationService( - repository = receiverVersionsCacheRepository - ) - ) - VersionDetailsServer( - transportServer = receiverServer, - platformRepository = receiverPlatformRepo, - validationService = VersionDetailsValidationService( - repository = receiverVersionDetailsCacheRepository - ) - ) - - return ServerSetupResult( - transport = receiverServer, - platformCollection = receiverPlatformCollection, - versionsEndpoint = receiverServerVersionsUrl - ) - } - - private fun setupSender(): ServerSetupResult { - if (database == null) database = buildDBClient().getDatabase("ocpi-2-1-1-tests") - val senderPlatformCollection = database!! - .getCollection("sender-server-${UUID.randomUUID()}") - - // Setup sender (server) - val senderServer = buildTransportServer() - val senderServerVersionsUrl = "${senderServer.baseUrl}/versions" - - VersionsServer( - transportServer = senderServer, - platformRepository = PlatformMongoRepository(collection = senderPlatformCollection), - validationService = VersionsValidationService( - repository = VersionsCacheRepository(baseUrl = senderServer.baseUrl) - ) - ) - VersionDetailsServer( - transportServer = senderServer, - platformRepository = PlatformMongoRepository(collection = senderPlatformCollection), - validationService = VersionDetailsValidationService( - repository = VersionDetailsCacheRepository(baseUrl = senderServer.baseUrl) - ) - ) - - return ServerSetupResult( - transport = senderServer, - platformCollection = senderPlatformCollection, - versionsEndpoint = senderServerVersionsUrl - ) - } - - private fun setupCredentialsSenderClient( - senderServerSetupResult: ServerSetupResult, - receiverServerSetupResult: ServerSetupResult - ): CredentialsClientService { - // Setup sender (client) - return CredentialsClientService( - clientVersionsEndpointUrl = senderServerSetupResult.versionsEndpoint, - clientPlatformRepository = PlatformMongoRepository(collection = senderServerSetupResult.platformCollection), - clientVersionsRepository = VersionsCacheRepository(baseUrl = senderServerSetupResult.transport.baseUrl), - clientBusinessDetails = BusinessDetails(name = "Sender", website = null, logo = null), - clientPartyId = "ABC", - clientCountryCode = "FR", - serverVersionsEndpointUrl = receiverServerSetupResult.versionsEndpoint, - transportClientBuilder = Http4kTransportClientBuilder() - ) - } - - @Test - fun `should not properly run registration because wrong setup of token A`() { - val receiverServer = setupReceiver() - val senderServer = setupSender() - - val credentialsClientService = setupCredentialsSenderClient( - senderServerSetupResult = senderServer, - receiverServerSetupResult = receiverServer - ) - - val tokenA = UUID.randomUUID().toString() - receiverServer.platformCollection.insertOne(Platform(url = senderServer.versionsEndpoint, tokenA = tokenA)) - - // Start the servers - receiverServer.transport.start() - senderServer.transport.start() - - // Fails because the senders does not know the TOKEN_A to send with the request - expectCatching { - credentialsClientService.register() - }.isFailure().isA() - - receiverServer.platformCollection.deleteOne(Platform::url eq senderServer.versionsEndpoint) - senderServer.platformCollection.insertOne(Platform(url = receiverServer.versionsEndpoint, tokenA = tokenA)) - - // Fails because the receiver does not know the TOKEN_A used by the sender - expectCatching { - credentialsClientService.register() - } - .isFailure() - .isA() - .get { statusCode } - .isEqualTo(OcpiStatus.CLIENT_INVALID_PARAMETERS.code) - - receiverServer.platformCollection.deleteOne(Platform::url eq senderServer.versionsEndpoint) - receiverServer.platformCollection.insertOne( - Platform( - url = receiverServer.versionsEndpoint, - tokenA = "!$tokenA" - ) - ) - - // Fails because the token sent by sender is not the same as the one in the receiver - expectCatching { - credentialsClientService.register() - } - .isFailure() - .isA() - .get { statusCode } - .isEqualTo(OcpiStatus.CLIENT_INVALID_PARAMETERS.code) - } - - @Test - fun `should access versions module properly with token A`() { - val receiverServer = setupReceiver() - val senderServer = setupSender() - - val tokenA = UUID.randomUUID().toString() - receiverServer.platformCollection.insertOne(Platform(url = senderServer.versionsEndpoint, tokenA = tokenA)) - senderServer.platformCollection.insertOne(Platform(url = receiverServer.versionsEndpoint, tokenA = tokenA)) - - receiverServer.transport.start() - senderServer.transport.start() - - // We don't need to register, we will use TOKEN_A for our requests - - val versionsClient = VersionsClient( - transportClientBuilder = Http4kTransportClientBuilder(), - serverVersionsEndpointUrl = receiverServer.versionsEndpoint, - platformRepository = PlatformMongoRepository(collection = senderServer.platformCollection) - ) - - expectThat( - versionsClient.getVersions() - ) { - get { data } - .isNotNull() - .isEqualTo(VersionsCacheRepository(baseUrl = receiverServer.transport.baseUrl).getVersions()) - - get { status_code } - .isEqualTo(OcpiStatus.SUCCESS.code) - } - } - - @Test - fun `should properly run registration process then correct get credentials from receiver`() { - val receiverServer = setupReceiver() - val senderServer = setupSender() - - val credentialsClientService = setupCredentialsSenderClient( - senderServerSetupResult = senderServer, - receiverServerSetupResult = receiverServer - ) - - // Store token A on the receiver side, that will be used by the sender to begin registration and store it as - // well in the client so that it knows what token to send - val tokenA = UUID.randomUUID().toString() - receiverServer.platformCollection.insertOne(Platform(url = senderServer.versionsEndpoint, tokenA = tokenA)) - senderServer.platformCollection.insertOne(Platform(url = receiverServer.versionsEndpoint, tokenA = tokenA)) - - // Start the servers - receiverServer.transport.start() - senderServer.transport.start() - - val credentials = credentialsClientService.register() - - expectThat( - credentialsClientService.get() - ).isEqualTo(credentials) - } - - @Test - fun `should properly run registration process then run update properly`() { - val receiverServer = setupReceiver() - val senderServer = setupSender() - - val credentialsClientService = setupCredentialsSenderClient( - senderServerSetupResult = senderServer, - receiverServerSetupResult = receiverServer - ) - - // Store token A on the receiver side, that will be used by the sender to begin registration and store it as - // well in the client so that it knows what token to send - val tokenA = UUID.randomUUID().toString() - receiverServer.platformCollection.insertOne(Platform(url = senderServer.versionsEndpoint, tokenA = tokenA)) - senderServer.platformCollection.insertOne(Platform(url = receiverServer.versionsEndpoint, tokenA = tokenA)) - - // Start the servers - receiverServer.transport.start() - senderServer.transport.start() - - credentialsClientService.register() - - val versionsClient = VersionsClient( - transportClientBuilder = Http4kTransportClientBuilder(), - serverVersionsEndpointUrl = receiverServer.versionsEndpoint, - platformRepository = PlatformMongoRepository(collection = senderServer.platformCollection) - ) - - expectThat( - versionsClient.getVersions() - ) { - get { data } - .isNotNull() - .isNotEmpty() - .isEqualTo( - VersionsCacheRepository(baseUrl = receiverServer.transport.baseUrl) - .getVersions() - ) - - get { status_code } - .isEqualTo(OcpiStatus.SUCCESS.code) - } - } - - @Test - fun `should properly run registration process then delete credentials properly`() { - val receiverServer = setupReceiver() - val senderServer = setupSender() - - val credentialsClientService = setupCredentialsSenderClient( - senderServerSetupResult = senderServer, - receiverServerSetupResult = receiverServer - ) - - // Store token A on the receiver side, that will be used by the sender to begin registration and store it as - // well in the client so that it knows what token to send - val tokenA = UUID.randomUUID().toString() - receiverServer.platformCollection.insertOne(Platform(url = senderServer.versionsEndpoint, tokenA = tokenA)) - senderServer.platformCollection.insertOne(Platform(url = receiverServer.versionsEndpoint, tokenA = tokenA)) - - // Start the servers - receiverServer.transport.start() - senderServer.transport.start() - - credentialsClientService.register() - - val versionsClient = VersionsClient( - transportClientBuilder = Http4kTransportClientBuilder(), - serverVersionsEndpointUrl = receiverServer.versionsEndpoint, - platformRepository = PlatformMongoRepository(collection = senderServer.platformCollection) - ) - - expectThat( - versionsClient.getVersions() - ) { - get { data } - .isNotNull() - .isNotEmpty() - .isEqualTo( - VersionsCacheRepository(baseUrl = receiverServer.transport.baseUrl) - .getVersions() - ) - - get { status_code } - .isEqualTo(OcpiStatus.SUCCESS.code) - } - - credentialsClientService.delete() - - expectCatching { - versionsClient.getVersions() - }.isFailure() - } - - @Test - fun `should properly run registration process then get, update, delete properly`() { - val receiverServer = setupReceiver() - val senderServer = setupSender() - - val credentialsClientService = setupCredentialsSenderClient( - senderServerSetupResult = senderServer, - receiverServerSetupResult = receiverServer - ) - - // Store token A on the receiver side, that will be used by the sender to begin registration and store it as - // well in the client so that it knows what token to send - val tokenA = UUID.randomUUID().toString() - receiverServer.platformCollection.insertOne(Platform(url = senderServer.versionsEndpoint, tokenA = tokenA)) - senderServer.platformCollection.insertOne(Platform(url = receiverServer.versionsEndpoint, tokenA = tokenA)) - - // Start the servers - receiverServer.transport.start() - senderServer.transport.start() - - val credentialsAfterRegistration = credentialsClientService.register() - - val versionsClient = VersionsClient( - transportClientBuilder = Http4kTransportClientBuilder(), - serverVersionsEndpointUrl = receiverServer.versionsEndpoint, - platformRepository = PlatformMongoRepository(collection = senderServer.platformCollection) - ) - - expectThat( - versionsClient.getVersions() - ) { - get { data } - .isNotNull() - .isNotEmpty() - .isEqualTo( - VersionsCacheRepository(baseUrl = receiverServer.transport.baseUrl) - .getVersions() - ) - - get { status_code } - .isEqualTo(OcpiStatus.SUCCESS.code) - } - - expectThat( - credentialsClientService.get() - ).isEqualTo(credentialsAfterRegistration) - - credentialsClientService.update() - - expectThat( - versionsClient.getVersions() - ) { - get { data } - .isNotNull() - .isNotEmpty() - .isEqualTo( - VersionsCacheRepository(baseUrl = receiverServer.transport.baseUrl) - .getVersions() - ) - - get { status_code } - .isEqualTo(OcpiStatus.SUCCESS.code) - } - - credentialsClientService.delete() - - expectThat( - versionsClient.getVersions() - ) { - get { data } - .isNull() - - get { status_code } - .isEqualTo(OcpiStatus.CLIENT_INVALID_PARAMETERS.code) - } - } -} \ No newline at end of file diff --git a/ocpi-toolkit-2.1.1/src/test/kotlin/com/izivia/ocpi/toolkit/tests/integration/LocationsIntegrationTest.kt b/ocpi-toolkit-2.1.1/src/test/kotlin/com/izivia/ocpi/toolkit/tests/integration/LocationsIntegrationTest.kt deleted file mode 100644 index 79fcc50a..00000000 --- a/ocpi-toolkit-2.1.1/src/test/kotlin/com/izivia/ocpi/toolkit/tests/integration/LocationsIntegrationTest.kt +++ /dev/null @@ -1,523 +0,0 @@ -package com.izivia.ocpi.toolkit.tests.integration - -import com.izivia.ocpi.toolkit.common.OcpiStatus -import com.izivia.ocpi.toolkit.modules.locations.LocationsCpoServer -import com.izivia.ocpi.toolkit.modules.locations.LocationsEmspClient -import com.izivia.ocpi.toolkit.modules.locations.domain.Location -import com.izivia.ocpi.toolkit.modules.locations.validation.LocationsCpoValidationService -import com.izivia.ocpi.toolkit.modules.versions.domain.VersionNumber -import com.izivia.ocpi.toolkit.samples.common.* -import com.izivia.ocpi.toolkit.tests.integration.common.BaseServerIntegrationTest -import com.izivia.ocpi.toolkit.tests.integration.mock.LocationsCpoMongoService -import com.mongodb.client.MongoDatabase -import org.junit.jupiter.api.Test -import org.litote.kmongo.getCollection -import strikt.api.expectThat -import strikt.assertions.* -import java.time.Instant -import java.util.* -import kotlin.math.min - - -class LocationsIntegrationTest : BaseServerIntegrationTest() { - - private val tokenC = UUID.randomUUID().toString() - private var database: MongoDatabase? = null - - private fun setupCpoServer(locations: List): Http4kTransportServer { - if (database == null) database = buildDBClient().getDatabase("ocpi-2-1-1-tests") - val collection = database!!.getCollection("cpo-server-locations-${UUID.randomUUID()}") - collection.insertMany(locations) - val server = buildTransportServer() - LocationsCpoServer( - server, - platformRepository = DummyPlatformCacheRepository(tokenC = tokenC), - LocationsCpoValidationService( - service = LocationsCpoMongoService(collection), - ) - ) - return server - } - - @Test - fun `getLocations test (paginated)`() { - - // Start CPO server with dummy data - val numberOfLocations = 500 - val referenceDate = Instant.parse("2022-04-28T09:00:00.000Z") - val lastDate = referenceDate.plusSeconds(3600L * (numberOfLocations - 1)) - - val cpoServer = setupCpoServer( - locations = (0 until numberOfLocations).map { index -> - validLocation.copy( - evses = listOf(validEvse.copy(connectors = listOf(validConnector))), - last_updated = referenceDate.plusSeconds(3600L * index) - ) - } - ) - cpoServer.start() - - val cpoServerVersionsUrl = "${cpoServer.baseUrl}/versions" - - val platformRepo = DummyPlatformCacheRepository(tokenC = tokenC).also { - val versionDetailsCpo = VersionDetailsCacheRepository(baseUrl = cpoServer.baseUrl) - - it.saveEndpoints( - cpoServerVersionsUrl, - versionDetailsCpo.getVersionDetails(VersionNumber.V2_1_1)!!.endpoints - ) - } - - val locationsEmspClient = LocationsEmspClient( - transportClientBuilder = Http4kTransportClientBuilder(), - serverVersionsEndpointUrl = cpoServerVersionsUrl, - platformRepository = platformRepo - ) - - // Tests - var limit = numberOfLocations + 1 - var offset = 0 - var dateFrom: Instant? = null - var dateTo: Instant? = null - - expectThat( - locationsEmspClient.getLocations( - dateFrom = dateFrom, - dateTo = dateTo, - offset = offset, - limit = limit - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.SUCCESS.code) - - get { data } - .isNotNull() - .and { - get { list } - .isNotEmpty() - .hasSize(min(limit, numberOfLocations)) - - get { list } - .first() - .isA() - } - .and { - get { limit } - .isEqualTo(limit) - } - .and { - get { offset } - .isEqualTo(offset) - } - .and { - get { totalCount } - .isEqualTo(numberOfLocations) - } - .and { - get { nextPageUrl } - .isNull() - } - } - - limit = 100 - offset = 100 - dateFrom = null - dateTo = null - - expectThat( - locationsEmspClient.getLocations( - dateFrom = dateFrom, - dateTo = dateTo, - offset = offset, - limit = limit - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.SUCCESS.code) - - get { data } - .isNotNull() - .and { - get { list } - .isNotEmpty() - .hasSize(min(limit, numberOfLocations)) - - get { list } - .first() - .isA() - } - .and { - get { limit } - .isEqualTo(limit) - } - .and { - get { offset } - .isEqualTo(offset) - } - .and { - get { totalCount } - .isEqualTo(numberOfLocations) - } - .and { - get { nextPageUrl } - .isEqualTo("${cpoServer.baseUrl}/2.1.1/locations?limit=$limit&offset=${offset + limit}") - } - } - - limit = 50 - offset = 50 - dateFrom = null - dateTo = null - - expectThat( - locationsEmspClient.getLocations( - dateFrom = dateFrom, - dateTo = dateTo, - offset = offset, - limit = limit - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.SUCCESS.code) - - get { data } - .isNotNull() - .and { - get { list } - .isNotEmpty() - .hasSize(min(limit, numberOfLocations)) - - get { list } - .first() - .isA() - } - .and { - get { limit } - .isEqualTo(limit) - } - .and { - get { offset } - .isEqualTo(offset) - } - .and { - get { totalCount } - .isEqualTo(numberOfLocations) - } - .and { - get { nextPageUrl } - .isEqualTo("${cpoServer.baseUrl}/2.1.1/locations?limit=$limit&offset=${offset + limit}") - } - } - - limit = numberOfLocations + 1 - offset = 0 - dateFrom = referenceDate - dateTo = lastDate - - expectThat( - locationsEmspClient.getLocations( - dateFrom = dateFrom, - dateTo = dateTo, - offset = offset, - limit = limit - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.SUCCESS.code) - - get { data } - .isNotNull() - .and { - get { list } - .isNotEmpty() - .hasSize(min(limit, numberOfLocations)) - - get { list } - .first() - .isA() - } - .and { - get { limit } - .isEqualTo(limit) - } - .and { - get { offset } - .isEqualTo(offset) - } - .and { - get { totalCount } - .isEqualTo(numberOfLocations) - } - .and { - get { nextPageUrl } - .isNull() - } - } - - limit = numberOfLocations + 1 - offset = 0 - dateFrom = referenceDate - dateTo = null - - expectThat( - locationsEmspClient.getLocations( - dateFrom = dateFrom, - dateTo = dateTo, - offset = offset, - limit = limit - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.SUCCESS.code) - - get { data } - .isNotNull() - .and { - get { list } - .isNotEmpty() - .hasSize(min(limit, numberOfLocations)) - - get { list } - .first() - .isA() - } - .and { - get { limit } - .isEqualTo(limit) - } - .and { - get { offset } - .isEqualTo(offset) - } - .and { - get { totalCount } - .isEqualTo(numberOfLocations) - } - .and { - get { nextPageUrl } - .isNull() - } - } - - limit = numberOfLocations + 1 - offset = 0 - dateFrom = null - dateTo = lastDate - - expectThat( - locationsEmspClient.getLocations( - dateFrom = dateFrom, - dateTo = dateTo, - offset = offset, - limit = limit - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.SUCCESS.code) - - get { data } - .isNotNull() - .and { - get { list } - .isNotEmpty() - .hasSize(min(limit, numberOfLocations)) - - get { list } - .first() - .isA() - } - .and { - get { limit } - .isEqualTo(limit) - } - .and { - get { offset } - .isEqualTo(offset) - } - .and { - get { totalCount } - .isEqualTo(numberOfLocations) - } - .and { - get { nextPageUrl } - .isNull() - } - } - - limit = numberOfLocations + 1 - offset = 0 - dateFrom = lastDate - dateTo = null - - expectThat( - locationsEmspClient.getLocations( - dateFrom = dateFrom, - dateTo = dateTo, - offset = offset, - limit = limit - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.SUCCESS.code) - - get { data } - .isNotNull() - .and { - get { list } - .isNotEmpty() - .hasSize(1) - - get { list } - .first() - .isA() - } - .and { - get { limit } - .isEqualTo(limit) - } - .and { - get { offset } - .isEqualTo(offset) - } - .and { - get { totalCount } - .isEqualTo(1) - } - .and { - get { nextPageUrl } - .isNull() - } - } - - limit = numberOfLocations + 1 - offset = 0 - dateFrom = null - dateTo = referenceDate - - expectThat( - locationsEmspClient.getLocations( - dateFrom = dateFrom, - dateTo = dateTo, - offset = offset, - limit = limit - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.SUCCESS.code) - - get { data } - .isNotNull() - .and { - get { list } - .isNotEmpty() - .hasSize(1) - - get { list } - .first() - .isA() - } - .and { - get { limit } - .isEqualTo(limit) - } - .and { - get { offset } - .isEqualTo(offset) - } - .and { - get { totalCount } - .isEqualTo(1) - } - .and { - get { nextPageUrl } - .isNull() - } - } - - limit = numberOfLocations + 1 - offset = 1 - dateFrom = null - dateTo = referenceDate - - expectThat( - locationsEmspClient.getLocations( - dateFrom = dateFrom, - dateTo = dateTo, - offset = offset, - limit = limit - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.SUCCESS.code) - - get { data } - .isNotNull() - .and { - get { list } - .isEmpty() - } - .and { - get { limit } - .isEqualTo(limit) - } - .and { - get { offset } - .isEqualTo(offset) - } - .and { - get { totalCount } - .isEqualTo(1) - } - .and { - get { nextPageUrl } - .isNull() - } - } - - limit = 1 - offset = 0 - dateFrom = null - dateTo = lastDate.minusSeconds(3600L) - - expectThat( - locationsEmspClient.getLocations( - dateFrom = dateFrom, - dateTo = dateTo, - offset = offset, - limit = limit - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.SUCCESS.code) - - get { data } - .isNotNull() - .and { - get { list } - .isNotEmpty() - .hasSize(1) - - get { list } - .first() - .isA() - } - .and { - get { limit } - .isEqualTo(limit) - } - .and { - get { offset } - .isEqualTo(offset) - } - .and { - get { totalCount } - .isEqualTo(numberOfLocations - 1) - } - .and { - get { nextPageUrl } - .isEqualTo("${cpoServer.baseUrl}/2.1.1/locations?date_to=${dateTo}&limit=$limit&offset=${offset + limit}") - } - } - } -} diff --git a/ocpi-toolkit-2.1.1/src/test/kotlin/com/izivia/ocpi/toolkit/tests/integration/TokensIntegrationTest.kt b/ocpi-toolkit-2.1.1/src/test/kotlin/com/izivia/ocpi/toolkit/tests/integration/TokensIntegrationTest.kt deleted file mode 100644 index e40434b1..00000000 --- a/ocpi-toolkit-2.1.1/src/test/kotlin/com/izivia/ocpi/toolkit/tests/integration/TokensIntegrationTest.kt +++ /dev/null @@ -1,523 +0,0 @@ -package com.izivia.ocpi.toolkit.tests.integration - -import com.izivia.ocpi.toolkit.common.OcpiStatus -import com.izivia.ocpi.toolkit.modules.tokens.TokensCpoClient -import com.izivia.ocpi.toolkit.modules.tokens.TokensEmspServer -import com.izivia.ocpi.toolkit.modules.tokens.domain.Token -import com.izivia.ocpi.toolkit.modules.tokens.validation.TokensEmspValidationService -import com.izivia.ocpi.toolkit.modules.versions.domain.VersionNumber -import com.izivia.ocpi.toolkit.samples.common.* -import com.izivia.ocpi.toolkit.tests.integration.common.BaseServerIntegrationTest -import com.izivia.ocpi.toolkit.tests.integration.mock.TokensEmspMongoRepository -import com.mongodb.client.MongoDatabase -import org.junit.jupiter.api.Test -import org.litote.kmongo.getCollection -import strikt.api.expectThat -import strikt.assertions.* -import java.time.Instant -import java.util.* -import kotlin.math.min - - -class TokensIntegrationTest : BaseServerIntegrationTest() { - - private val tokenC = UUID.randomUUID().toString() - private var database: MongoDatabase? = null - - private fun setupEmspServer(tokens: List): Http4kTransportServer { - if (database == null) database = buildDBClient().getDatabase("ocpi-2-1-1-tests") - val collection = database!!.getCollection("emsp-server-tokens-${UUID.randomUUID()}") - collection.insertMany(tokens) - val server = buildTransportServer() - TokensEmspServer( - server, - platformRepository = DummyPlatformCacheRepository(tokenC = tokenC), - TokensEmspValidationService( - service = TokensEmspMongoRepository(collection), - ) - ) - return server - } - - @Test - fun `getTokens test (paginated)`() { - - // Start EMSP server with dummy data - val numberOfTokens = 500 - val referenceDate = Instant.parse("2022-04-28T09:00:00.000Z") - val lastDate = referenceDate.plusSeconds(3600L * (numberOfTokens - 1)) - - val emspServer = setupEmspServer( - tokens = (0 until numberOfTokens).map { index -> - validToken.copy( - uid = UUID.randomUUID().toString(), - last_updated = referenceDate.plusSeconds(3600L * index) - ) - } - ) - emspServer.start() - - val emspServerVersionsUrl = "${emspServer.baseUrl}/versions" - - val platformRepo = DummyPlatformCacheRepository(tokenC = tokenC).also { - val versionDetailsEmsp = VersionDetailsCacheRepository(baseUrl = emspServer.baseUrl) - - it.saveEndpoints( - emspServerVersionsUrl, - versionDetailsEmsp.getVersionDetails(VersionNumber.V2_1_1)!!.endpoints - ) - } - - val tokensCpoClient = TokensCpoClient( - transportClientBuilder = Http4kTransportClientBuilder(), - serverVersionsEndpointUrl = emspServerVersionsUrl, - platformRepository = platformRepo - ) - - // Tests - var limit = numberOfTokens + 1 - var offset = 0 - var dateFrom: Instant? = null - var dateTo: Instant? = null - - expectThat( - tokensCpoClient.getTokens( - dateFrom = dateFrom, - dateTo = dateTo, - offset = offset, - limit = limit - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.SUCCESS.code) - - get { data } - .isNotNull() - .and { - get { list } - .isNotEmpty() - .hasSize(min(limit, numberOfTokens)) - - get { list } - .first() - .isA() - } - .and { - get { limit } - .isEqualTo(limit) - } - .and { - get { offset } - .isEqualTo(offset) - } - .and { - get { totalCount } - .isEqualTo(numberOfTokens) - } - .and { - get { nextPageUrl } - .isNull() - } - } - - limit = 100 - offset = 100 - dateFrom = null - dateTo = null - - expectThat( - tokensCpoClient.getTokens( - dateFrom = dateFrom, - dateTo = dateTo, - offset = offset, - limit = limit - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.SUCCESS.code) - - get { data } - .isNotNull() - .and { - get { list } - .isNotEmpty() - .hasSize(min(limit, numberOfTokens)) - - get { list } - .first() - .isA() - } - .and { - get { limit } - .isEqualTo(limit) - } - .and { - get { offset } - .isEqualTo(offset) - } - .and { - get { totalCount } - .isEqualTo(numberOfTokens) - } - .and { - get { nextPageUrl } - .isEqualTo("${emspServer.baseUrl}/2.1.1/tokens?limit=$limit&offset=${offset + limit}") - } - } - - limit = 50 - offset = 50 - dateFrom = null - dateTo = null - - expectThat( - tokensCpoClient.getTokens( - dateFrom = dateFrom, - dateTo = dateTo, - offset = offset, - limit = limit - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.SUCCESS.code) - - get { data } - .isNotNull() - .and { - get { list } - .isNotEmpty() - .hasSize(min(limit, numberOfTokens)) - - get { list } - .first() - .isA() - } - .and { - get { limit } - .isEqualTo(limit) - } - .and { - get { offset } - .isEqualTo(offset) - } - .and { - get { totalCount } - .isEqualTo(numberOfTokens) - } - .and { - get { nextPageUrl } - .isEqualTo("${emspServer.baseUrl}/2.1.1/tokens?limit=$limit&offset=${offset + limit}") - } - } - - limit = numberOfTokens + 1 - offset = 0 - dateFrom = referenceDate - dateTo = lastDate - - expectThat( - tokensCpoClient.getTokens( - dateFrom = dateFrom, - dateTo = dateTo, - offset = offset, - limit = limit - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.SUCCESS.code) - - get { data } - .isNotNull() - .and { - get { list } - .isNotEmpty() - .hasSize(min(limit, numberOfTokens)) - - get { list } - .first() - .isA() - } - .and { - get { limit } - .isEqualTo(limit) - } - .and { - get { offset } - .isEqualTo(offset) - } - .and { - get { totalCount } - .isEqualTo(numberOfTokens) - } - .and { - get { nextPageUrl } - .isNull() - } - } - - limit = numberOfTokens + 1 - offset = 0 - dateFrom = referenceDate - dateTo = null - - expectThat( - tokensCpoClient.getTokens( - dateFrom = dateFrom, - dateTo = dateTo, - offset = offset, - limit = limit - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.SUCCESS.code) - - get { data } - .isNotNull() - .and { - get { list } - .isNotEmpty() - .hasSize(min(limit, numberOfTokens)) - - get { list } - .first() - .isA() - } - .and { - get { limit } - .isEqualTo(limit) - } - .and { - get { offset } - .isEqualTo(offset) - } - .and { - get { totalCount } - .isEqualTo(numberOfTokens) - } - .and { - get { nextPageUrl } - .isNull() - } - } - - limit = numberOfTokens + 1 - offset = 0 - dateFrom = null - dateTo = lastDate - - expectThat( - tokensCpoClient.getTokens( - dateFrom = dateFrom, - dateTo = dateTo, - offset = offset, - limit = limit - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.SUCCESS.code) - - get { data } - .isNotNull() - .and { - get { list } - .isNotEmpty() - .hasSize(min(limit, numberOfTokens)) - - get { list } - .first() - .isA() - } - .and { - get { limit } - .isEqualTo(limit) - } - .and { - get { offset } - .isEqualTo(offset) - } - .and { - get { totalCount } - .isEqualTo(numberOfTokens) - } - .and { - get { nextPageUrl } - .isNull() - } - } - - limit = numberOfTokens + 1 - offset = 0 - dateFrom = lastDate - dateTo = null - - expectThat( - tokensCpoClient.getTokens( - dateFrom = dateFrom, - dateTo = dateTo, - offset = offset, - limit = limit - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.SUCCESS.code) - - get { data } - .isNotNull() - .and { - get { list } - .isNotEmpty() - .hasSize(1) - - get { list } - .first() - .isA() - } - .and { - get { limit } - .isEqualTo(limit) - } - .and { - get { offset } - .isEqualTo(offset) - } - .and { - get { totalCount } - .isEqualTo(1) - } - .and { - get { nextPageUrl } - .isNull() - } - } - - limit = numberOfTokens + 1 - offset = 0 - dateFrom = null - dateTo = referenceDate - - expectThat( - tokensCpoClient.getTokens( - dateFrom = dateFrom, - dateTo = dateTo, - offset = offset, - limit = limit - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.SUCCESS.code) - - get { data } - .isNotNull() - .and { - get { list } - .isNotEmpty() - .hasSize(1) - - get { list } - .first() - .isA() - } - .and { - get { limit } - .isEqualTo(limit) - } - .and { - get { offset } - .isEqualTo(offset) - } - .and { - get { totalCount } - .isEqualTo(1) - } - .and { - get { nextPageUrl } - .isNull() - } - } - - limit = numberOfTokens + 1 - offset = 1 - dateFrom = null - dateTo = referenceDate - - expectThat( - tokensCpoClient.getTokens( - dateFrom = dateFrom, - dateTo = dateTo, - offset = offset, - limit = limit - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.SUCCESS.code) - - get { data } - .isNotNull() - .and { - get { list } - .isEmpty() - } - .and { - get { limit } - .isEqualTo(limit) - } - .and { - get { offset } - .isEqualTo(offset) - } - .and { - get { totalCount } - .isEqualTo(1) - } - .and { - get { nextPageUrl } - .isNull() - } - } - - limit = 1 - offset = 0 - dateFrom = null - dateTo = lastDate.minusSeconds(3600L) - - expectThat( - tokensCpoClient.getTokens( - dateFrom = dateFrom, - dateTo = dateTo, - offset = offset, - limit = limit - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.SUCCESS.code) - - get { data } - .isNotNull() - .and { - get { list } - .isNotEmpty() - .hasSize(1) - - get { list } - .first() - .isA() - } - .and { - get { limit } - .isEqualTo(limit) - } - .and { - get { offset } - .isEqualTo(offset) - } - .and { - get { totalCount } - .isEqualTo(numberOfTokens - 1) - } - .and { - get { nextPageUrl } - .isEqualTo("${emspServer.baseUrl}/2.1.1/tokens?date_to=${dateTo}&limit=$limit&offset=${offset + limit}") - } - } - } -} diff --git a/ocpi-toolkit-2.1.1/src/test/kotlin/com/izivia/ocpi/toolkit/tests/integration/common/BaseDBIntegrationTest.kt b/ocpi-toolkit-2.1.1/src/test/kotlin/com/izivia/ocpi/toolkit/tests/integration/common/BaseDBIntegrationTest.kt deleted file mode 100644 index 6934c32e..00000000 --- a/ocpi-toolkit-2.1.1/src/test/kotlin/com/izivia/ocpi/toolkit/tests/integration/common/BaseDBIntegrationTest.kt +++ /dev/null @@ -1,17 +0,0 @@ -package com.izivia.ocpi.toolkit.tests.integration.common - -import org.litote.kmongo.KMongo -import org.testcontainers.containers.MongoDBContainer -import org.testcontainers.junit.jupiter.Container -import org.testcontainers.junit.jupiter.Testcontainers -import org.testcontainers.utility.DockerImageName - -@Testcontainers -abstract class BaseDBIntegrationTest { - - @Container - protected val mongoDBContainer = MongoDBContainer(DockerImageName.parse("mongo:5.0.8")) - - protected fun buildDBClient() = - KMongo.createClient(mongoDBContainer.replicaSetUrl) -} \ No newline at end of file diff --git a/ocpi-toolkit-2.1.1/src/test/kotlin/com/izivia/ocpi/toolkit/tests/integration/common/BaseServerIntegrationTest.kt b/ocpi-toolkit-2.1.1/src/test/kotlin/com/izivia/ocpi/toolkit/tests/integration/common/BaseServerIntegrationTest.kt deleted file mode 100644 index 7b0d1d19..00000000 --- a/ocpi-toolkit-2.1.1/src/test/kotlin/com/izivia/ocpi/toolkit/tests/integration/common/BaseServerIntegrationTest.kt +++ /dev/null @@ -1,21 +0,0 @@ -package com.izivia.ocpi.toolkit.tests.integration.common - -import com.izivia.ocpi.toolkit.samples.common.Http4kTransportClient -import com.izivia.ocpi.toolkit.samples.common.Http4kTransportServer -import java.net.ServerSocket - -abstract class BaseServerIntegrationTest: BaseDBIntegrationTest() { - - private fun getFreeNetworkPort() = ServerSocket(0).use { it.localPort } - - protected fun buildTransportServer(): Http4kTransportServer { - val port = getFreeNetworkPort() - return Http4kTransportServer( - baseUrl = "http://localhost:$port", - port = port - ) - } - - protected fun Http4kTransportServer.getClient() = - Http4kTransportClient(baseUrl) -} diff --git a/ocpi-toolkit-2.1.1/src/test/kotlin/com/izivia/ocpi/toolkit/tests/integration/mock/LocationsCpoMongoService.kt b/ocpi-toolkit-2.1.1/src/test/kotlin/com/izivia/ocpi/toolkit/tests/integration/mock/LocationsCpoMongoService.kt deleted file mode 100644 index 2616359a..00000000 --- a/ocpi-toolkit-2.1.1/src/test/kotlin/com/izivia/ocpi/toolkit/tests/integration/mock/LocationsCpoMongoService.kt +++ /dev/null @@ -1,51 +0,0 @@ -package com.izivia.ocpi.toolkit.tests.integration.mock - -import com.izivia.ocpi.toolkit.common.SearchResult -import com.izivia.ocpi.toolkit.common.toSearchResult -import com.izivia.ocpi.toolkit.modules.locations.domain.Connector -import com.izivia.ocpi.toolkit.modules.locations.domain.Evse -import com.izivia.ocpi.toolkit.modules.locations.domain.Location -import com.izivia.ocpi.toolkit.modules.locations.services.LocationsCpoService -import com.mongodb.client.MongoCollection -import org.litote.kmongo.and -import org.litote.kmongo.gte -import org.litote.kmongo.lte -import java.time.Instant - -class LocationsCpoMongoService( - private val collection: MongoCollection -) : LocationsCpoService { - - override fun getLocations(dateFrom: Instant?, dateTo: Instant?, offset: Int, limit: Int?): SearchResult = - collection - .run { - find( - and( - dateFrom?.let { Location::last_updated gte dateFrom }, - dateTo?.let { Location::last_updated lte dateTo } - ) - ) - } - .toList() - .let { - val actualLimit = limit ?: 10 - val size = it.size - - it - .filterIndexed { index: Int, _: Location -> index + 1 > offset } - .take(actualLimit) - .toSearchResult(totalCount = size, limit = actualLimit, offset = offset) - } - - override fun getLocation(locationId: String): Location? { - TODO("Not yet implemented") - } - - override fun getEvse(locationId: String, evseUid: String): Evse? { - TODO("Not yet implemented") - } - - override fun getConnector(locationId: String, evseUid: String, connectorId: String): Connector? { - TODO("Not yet implemented") - } -} diff --git a/ocpi-toolkit-2.1.1/src/test/kotlin/com/izivia/ocpi/toolkit/tests/integration/mock/PlatformMongoRepository.kt b/ocpi-toolkit-2.1.1/src/test/kotlin/com/izivia/ocpi/toolkit/tests/integration/mock/PlatformMongoRepository.kt deleted file mode 100644 index 6e65db84..00000000 --- a/ocpi-toolkit-2.1.1/src/test/kotlin/com/izivia/ocpi/toolkit/tests/integration/mock/PlatformMongoRepository.kt +++ /dev/null @@ -1,99 +0,0 @@ -package com.izivia.ocpi.toolkit.tests.integration.mock - -import com.izivia.ocpi.toolkit.modules.credentials.repositories.PlatformRepository -import com.izivia.ocpi.toolkit.modules.versions.domain.Endpoint -import com.izivia.ocpi.toolkit.modules.versions.domain.Version -import com.izivia.ocpi.toolkit.samples.common.Platform -import com.mongodb.client.MongoCollection -import com.mongodb.client.model.FindOneAndUpdateOptions -import com.mongodb.client.model.ReturnDocument -import org.litote.kmongo.eq -import org.litote.kmongo.findOne -import org.litote.kmongo.set -import org.litote.kmongo.setTo - -class PlatformMongoRepository( - private val collection: MongoCollection -) : PlatformRepository { - - override fun savePlatformUrlForTokenA(tokenA: String, platformUrl: String): String? = - collection - .findOneAndUpdate( - Platform::tokenA eq tokenA, - set(Platform::url setTo platformUrl), - FindOneAndUpdateOptions().returnDocument(ReturnDocument.AFTER) - ) - ?.url - - override fun saveVersion(platformUrl: String, version: Version): Version = version.also { - collection - .updateOne(Platform::url eq platformUrl, set(Platform::version setTo it)) - } - - override fun saveEndpoints(platformUrl: String, endpoints: List): List = endpoints.also { - collection - .updateOne(Platform::url eq platformUrl, set(Platform::endpoints setTo it)) - } - - override fun saveCredentialsTokenA(platformUrl: String, credentialsTokenA: String): String = - credentialsTokenA.also { - collection - .updateOne(Platform::url eq platformUrl, set(Platform::tokenA setTo it)) - } - - override fun saveCredentialsTokenB(platformUrl: String, credentialsTokenB: String): String = - credentialsTokenB.also { - collection - .updateOne(Platform::url eq platformUrl, set(Platform::tokenB setTo it)) - } - - override fun saveCredentialsTokenC(platformUrl: String, credentialsTokenC: String): String = - credentialsTokenC.also { - collection - .updateOne(Platform::url eq platformUrl, set(Platform::tokenC setTo it)) - } - - override fun getCredentialsTokenA(platformUrl: String): String? = collection - .findOne(Platform::url eq platformUrl)?.tokenA - - override fun getCredentialsTokenB(platformUrl: String): String? = collection - .findOne(Platform::url eq platformUrl)?.tokenB - - override fun getCredentialsTokenC(platformUrl: String): String? = collection - .findOne(Platform::url eq platformUrl)?.tokenC - - override fun platformExistsWithTokenA(token: String): Boolean = collection - .findOne(Platform::tokenA eq token) != null - - override fun platformExistsWithTokenB(token: String): Boolean = collection - .findOne(Platform::tokenB eq token) != null - - override fun getPlatformUrlByTokenC(token: String): String? = collection - .findOne(Platform::tokenC eq token)?.url - - override fun getEndpoints(platformUrl: String): List = collection - .findOne(Platform::url eq platformUrl)?.endpoints ?: emptyList() - - override fun getVersion(platformUrl: String): Version? = collection - .findOne(Platform::url eq platformUrl)?.version - - override fun removeCredentialsTokenA(platformUrl: String) { - collection.updateOne(Platform::url eq platformUrl, set(Platform::tokenA setTo null)) - } - - override fun removeCredentialsTokenB(platformUrl: String) { - collection.updateOne(Platform::url eq platformUrl, set(Platform::tokenB setTo null)) - } - - override fun removeCredentialsTokenC(platformUrl: String) { - collection.updateOne(Platform::url eq platformUrl, set(Platform::tokenC setTo null)) - } - - override fun removeVersion(platformUrl: String) { - collection.updateOne(Platform::url eq platformUrl, set(Platform::version setTo null)) - } - - override fun removeEndpoints(platformUrl: String) { - collection.updateOne(Platform::url eq platformUrl, set(Platform::endpoints setTo null)) - } -} diff --git a/ocpi-toolkit-2.1.1/src/test/kotlin/com/izivia/ocpi/toolkit/tests/integration/mock/TokensEmspMongoRepository.kt b/ocpi-toolkit-2.1.1/src/test/kotlin/com/izivia/ocpi/toolkit/tests/integration/mock/TokensEmspMongoRepository.kt deleted file mode 100644 index 4a57ef7f..00000000 --- a/ocpi-toolkit-2.1.1/src/test/kotlin/com/izivia/ocpi/toolkit/tests/integration/mock/TokensEmspMongoRepository.kt +++ /dev/null @@ -1,48 +0,0 @@ -package com.izivia.ocpi.toolkit.tests.integration.mock - -import com.izivia.ocpi.toolkit.common.SearchResult -import com.izivia.ocpi.toolkit.common.toSearchResult -import com.izivia.ocpi.toolkit.modules.tokens.domain.AuthorizationInfo -import com.izivia.ocpi.toolkit.modules.tokens.domain.LocationReferences -import com.izivia.ocpi.toolkit.modules.tokens.domain.Token -import com.izivia.ocpi.toolkit.modules.tokens.domain.TokenType -import com.izivia.ocpi.toolkit.modules.tokens.services.TokensEmspService -import com.mongodb.client.MongoCollection -import org.litote.kmongo.and -import org.litote.kmongo.gte -import org.litote.kmongo.lte -import java.time.Instant - -class TokensEmspMongoRepository( - private val collection: MongoCollection -) : TokensEmspService { - - override fun getTokens(dateFrom: Instant?, dateTo: Instant?, offset: Int, limit: Int?): SearchResult = - collection - .run { - find( - and( - dateFrom?.let { Token::last_updated gte dateFrom }, - dateTo?.let { Token::last_updated lte dateTo } - ) - ) - } - .toList() - .let { - val actualLimit = limit ?: 10 - val size = it.size - - it - .filterIndexed { index: Int, _: Token -> index + 1 > offset } - .take(actualLimit) - .toSearchResult(totalCount = size, limit = actualLimit, offset = offset) - } - - override fun postToken( - tokenUid: String, - tokenType: TokenType, - locationReferences: LocationReferences? - ): AuthorizationInfo { - TODO("Not yet implemented") - } -} diff --git a/ocpi-toolkit-2.1.1/src/test/kotlin/com/izivia/ocpi/toolkit/tests/mock/LocationsCpoRepository.kt b/ocpi-toolkit-2.1.1/src/test/kotlin/com/izivia/ocpi/toolkit/tests/mock/LocationsCpoRepository.kt deleted file mode 100644 index cab6944f..00000000 --- a/ocpi-toolkit-2.1.1/src/test/kotlin/com/izivia/ocpi/toolkit/tests/mock/LocationsCpoRepository.kt +++ /dev/null @@ -1,57 +0,0 @@ -package com.izivia.ocpi.toolkit.tests.mock - -import com.izivia.ocpi.toolkit.common.toSearchResult -import com.izivia.ocpi.toolkit.modules.locations.domain.Location -import com.izivia.ocpi.toolkit.modules.locations.services.LocationsCpoService -import io.mockk.every -import io.mockk.mockk -import io.mockk.slot -import java.time.Instant - -fun locationsCpoService(locations: List): LocationsCpoService = mockk { - val locationId = slot() - val evseUid = slot() - val connectorId = slot() - val dateFrom = mutableListOf() - val dateTo = mutableListOf() - val offset = slot() - val limit = mutableListOf() - - every { getLocations(captureNullable(dateFrom), captureNullable(dateTo), capture(offset), captureNullable(limit)) } answers { - val capturedOffset = offset.captured - val capturedLimit = limit.captured() ?: 10 - - locations - .filter { loc -> - val dateFromFilterOk = dateFrom.captured()?.let { loc.last_updated.isAfter(it) } ?: true - val dateToFilterOk = dateTo.captured()?.let { loc.last_updated.isBefore(it) } ?: true - - dateFromFilterOk && dateToFilterOk - } - .filterIndexed { index: Int, _: Location -> - index >= capturedOffset - } - .take(capturedLimit) - .toSearchResult(totalCount = locations.size, limit = capturedLimit, offset = capturedOffset) - } - - every { getLocation(capture(locationId)) } answers { - locations.find { it.id == locationId.captured } - } - - every { getEvse(capture(locationId), capture(evseUid)) } answers { - locations - .find { it.id == locationId.captured } - ?.evses - ?.find { it.uid == evseUid.captured } - } - - every { getConnector(capture(locationId), capture(evseUid), capture(connectorId)) } answers { - locations - .find { it.id == locationId.captured } - ?.evses - ?.find { it.uid == evseUid.captured } - ?.connectors - ?.find { it.id == connectorId.captured } - } -} \ No newline at end of file diff --git a/ocpi-toolkit-2.1.1/src/test/kotlin/com/izivia/ocpi/toolkit/tests/mock/LocationsEmspRepository.kt b/ocpi-toolkit-2.1.1/src/test/kotlin/com/izivia/ocpi/toolkit/tests/mock/LocationsEmspRepository.kt deleted file mode 100644 index 865b09bb..00000000 --- a/ocpi-toolkit-2.1.1/src/test/kotlin/com/izivia/ocpi/toolkit/tests/mock/LocationsEmspRepository.kt +++ /dev/null @@ -1,92 +0,0 @@ -package com.izivia.ocpi.toolkit.tests.mock - -import com.izivia.ocpi.toolkit.modules.locations.domain.* -import com.izivia.ocpi.toolkit.modules.locations.services.LocationsEmspService -import io.mockk.every -import io.mockk.mockk -import io.mockk.slot - -fun locationsEmspService(locations: List): LocationsEmspService = mockk { - val countryCode = slot() - val partyId = slot() - val locationId = slot() - val evseUid = slot() - val connectorId = slot() - val location = slot() - val evse = slot() - val connector = slot() - val locationPartial = slot() - val evsePartial = slot() - val connectorPartial = slot() - - every { getLocation(capture(countryCode), capture(partyId), capture(locationId)) } answers { - locations.find { it.id == locationId.captured } - } - - every { getEvse(capture(countryCode), capture(partyId), capture(locationId), capture(evseUid)) } answers { - locations - .find { it.id == locationId.captured } - ?.evses - ?.find { it.uid == evseUid.captured } - } - - every { getConnector(capture(countryCode), capture(partyId), capture(locationId), capture(evseUid), capture(connectorId)) } answers { - locations - .find { it.id == locationId.captured } - ?.evses - ?.find { it.uid == evseUid.captured } - ?.connectors - ?.find { it.id == connectorId.captured } - } - - every { patchLocation(capture(countryCode), capture(partyId), capture(locationId), capture(locationPartial)) } answers { - // Patch logic is not implemented - locations - .find { it.id == locationId.captured } - } - - every { patchEvse(capture(countryCode), capture(partyId), capture(locationId), capture(evseUid), capture(evsePartial)) } answers { - // Patch logic is not implemented - locations - .find { it.id == locationId.captured } - ?.evses - ?.find { it.uid == evseUid.captured } - } - - every { patchConnector(capture(countryCode), capture(partyId), capture(locationId), capture(evseUid), capture(connectorId), capture(connectorPartial)) } answers { - // Patch logic is not implemented - locations - .find { it.id == locationId.captured } - ?.evses - ?.find { it.uid == evseUid.captured } - ?.connectors - ?.find { it.id == connectorId.captured } - } - - every { putLocation(capture(countryCode), capture(partyId), capture(locationId), capture(location)) } answers { - // Put logic is not implemented - locations - .find { it.id == locationId.captured } - ?: location.captured - } - - every { putEvse(capture(countryCode), capture(partyId), capture(locationId), capture(evseUid), capture(evse)) } answers { - // Put logic is not implemented - locations - .find { it.id == locationId.captured } - ?.evses - ?.find { it.uid == evseUid.captured } - ?: evse.captured - } - - every { putConnector(capture(countryCode), capture(partyId), capture(locationId), capture(evseUid), capture(connectorId), capture(connector)) } answers { - // Put logic is not implemented - locations - .find { it.id == locationId.captured } - ?.evses - ?.find { it.uid == evseUid.captured } - ?.connectors - ?.find { it.id == connectorId.captured } - ?: connector.captured - } -} \ No newline at end of file diff --git a/ocpi-toolkit-2.1.1/src/test/kotlin/com/izivia/ocpi/toolkit/tests/mock/TokensCoreRepository.kt b/ocpi-toolkit-2.1.1/src/test/kotlin/com/izivia/ocpi/toolkit/tests/mock/TokensCoreRepository.kt deleted file mode 100644 index 79d9b59c..00000000 --- a/ocpi-toolkit-2.1.1/src/test/kotlin/com/izivia/ocpi/toolkit/tests/mock/TokensCoreRepository.kt +++ /dev/null @@ -1,69 +0,0 @@ -package com.izivia.ocpi.toolkit.tests.mock - -import com.izivia.ocpi.toolkit.modules.tokens.domain.Token -import com.izivia.ocpi.toolkit.modules.tokens.domain.TokenPartial -import com.izivia.ocpi.toolkit.modules.tokens.services.TokensCpoService -import io.mockk.every -import io.mockk.mockk -import io.mockk.slot - -fun tokensCpoService(tokens: MutableList): TokensCpoService = mockk { - - val countryCode = slot() - val partyId = slot() - val tokenUid = slot() - val token = slot() - val tokenPartial = slot() - - every { - getToken( - capture(countryCode), - capture(partyId), - capture(tokenUid) - ) - } answers { - tokens.find { - it.uid == tokenUid.captured - } - } - - every { - putToken( - capture(countryCode), - capture(partyId), - capture(tokenUid), - capture(token) - ) - } answers { - tokens.add(token.captured) - tokens.find { it.uid == token.captured.uid }!! - } - - every { - patchToken( - capture(countryCode), - capture(partyId), - capture(tokenUid), - capture(tokenPartial) - ) - } answers { - tokens - .indexOfFirst { it.uid == tokenUid.captured } - .let { index -> - val existingToken = tokens[index] - existingToken.copy( - uid = tokenPartial.captured.uid ?: existingToken.uid, - type = tokenPartial.captured.type ?: existingToken.type, - auth_id = tokenPartial.captured.auth_id ?: existingToken.auth_id, - visual_number = tokenPartial.captured.visual_number ?: existingToken.visual_number, - issuer = tokenPartial.captured.issuer ?: existingToken.issuer, - valid = tokenPartial.captured.valid ?: existingToken.valid, - whitelist = tokenPartial.captured.whitelist ?: existingToken.whitelist, - language = tokenPartial.captured.language ?: existingToken.language, - last_updated = tokenPartial.captured.last_updated ?: existingToken.last_updated, - ).also { - tokens[index] = it - } - } - } -} diff --git a/ocpi-toolkit-2.1.1/src/test/kotlin/com/izivia/ocpi/toolkit/tests/mock/TokensEmspRepository.kt b/ocpi-toolkit-2.1.1/src/test/kotlin/com/izivia/ocpi/toolkit/tests/mock/TokensEmspRepository.kt deleted file mode 100644 index 7f2cdd72..00000000 --- a/ocpi-toolkit-2.1.1/src/test/kotlin/com/izivia/ocpi/toolkit/tests/mock/TokensEmspRepository.kt +++ /dev/null @@ -1,50 +0,0 @@ -package com.izivia.ocpi.toolkit.tests.mock - -import com.izivia.ocpi.toolkit.common.toSearchResult -import com.izivia.ocpi.toolkit.modules.tokens.domain.* -import com.izivia.ocpi.toolkit.modules.tokens.services.TokensEmspService -import io.mockk.every -import io.mockk.mockk -import io.mockk.slot -import java.time.Instant - -fun tokensEmspService(tokens: List): TokensEmspService = mockk { - val dateFrom = mutableListOf() - val dateTo = mutableListOf() - val offset = slot() - val limit = mutableListOf() - - val tokenUid = slot() - val tokenType = slot() - val locationReferences = mutableListOf() - - every { getTokens(captureNullable(dateFrom), captureNullable(dateTo), capture(offset), captureNullable(limit)) } answers { - val capturedOffset = offset.captured - val capturedLimit = limit.captured() ?: 10 - - tokens - .filter { token -> - val dateFromFilterOk = dateFrom.captured()?.let { token.last_updated.isAfter(it) } ?: true - val dateToFilterOk = dateTo.captured()?.let { token.last_updated.isBefore(it) } ?: true - - dateFromFilterOk && dateToFilterOk - } - .filterIndexed { index: Int, _: Token -> - index >= capturedOffset - } - .take(capturedLimit) - .toSearchResult(totalCount = tokens.size, limit = capturedLimit, offset = capturedOffset) - } - - every { postToken(capture(tokenUid), capture(tokenType), captureNullable(locationReferences)) } answers { - tokens - .find { it.uid == tokenUid.captured } - .let { - AuthorizationInfo( - allowed = Allowed.ALLOWED, - location = locationReferences[0], - info = null - ) - } - } -} diff --git a/ocpi-toolkit-2.1.1/src/test/kotlin/com/izivia/ocpi/toolkit/tests/validation/LocationsCpoValidationServiceTest.kt b/ocpi-toolkit-2.1.1/src/test/kotlin/com/izivia/ocpi/toolkit/tests/validation/LocationsCpoValidationServiceTest.kt deleted file mode 100644 index 254f0a2d..00000000 --- a/ocpi-toolkit-2.1.1/src/test/kotlin/com/izivia/ocpi/toolkit/tests/validation/LocationsCpoValidationServiceTest.kt +++ /dev/null @@ -1,323 +0,0 @@ -package com.izivia.ocpi.toolkit.tests.validation - -import com.izivia.ocpi.toolkit.common.OcpiStatus -import com.izivia.ocpi.toolkit.common.SearchResult -import com.izivia.ocpi.toolkit.modules.locations.domain.Location -import com.izivia.ocpi.toolkit.modules.locations.validation.LocationsCpoValidationService -import com.izivia.ocpi.toolkit.tests.mock.locationsCpoService -import org.junit.jupiter.api.Test -import strikt.api.expectThat -import strikt.assertions.isEqualTo -import strikt.assertions.isNotNull -import strikt.assertions.isNull -import java.time.Instant -import java.util.* - -class LocationsCpoValidationServiceTest { - private lateinit var service: LocationsCpoValidationService - private val from = Instant.parse("2022-04-28T08:00:00.000Z") - private val to = Instant.parse("2022-04-28T09:00:00.000Z") - - @Test - fun getLocationsParamsValidationTest() { - service = LocationsCpoValidationService(service = locationsCpoService(emptyList())) - - expectThat(service.getLocations(dateFrom = from, dateTo = from, offset = 0, limit = null)) { - get { status_code } - .isEqualTo(OcpiStatus.SUCCESS.code) - - get { data } - .isNotNull() - .get(SearchResult::offset) - .isEqualTo(0) - } - - expectThat(service.getLocations(dateFrom = to, dateTo = from, offset = 0, limit = null)) { - get { status_code } - .isEqualTo(OcpiStatus.CLIENT_INVALID_PARAMETERS.code) - - get { data } - .isNull() - } - - expectThat(service.getLocations(dateFrom = from, dateTo = to, offset = 0, limit = null)) { - get { status_code } - .isEqualTo(OcpiStatus.SUCCESS.code) - - get { data } - .isNotNull() - .get(SearchResult::offset) - .isEqualTo(0) - } - - expectThat(service.getLocations(dateFrom = null, dateTo = to, offset = 0, limit = null)) { - get { status_code } - .isEqualTo(OcpiStatus.SUCCESS.code) - - get { data } - .isNotNull() - .get(SearchResult::offset) - .isEqualTo(0) - } - - expectThat(service.getLocations(dateFrom = from, dateTo = null, offset = 0, limit = null)) { - get { status_code } - .isEqualTo(OcpiStatus.SUCCESS.code) - - get { data } - .isNotNull() - .get(SearchResult::offset) - .isEqualTo(0) - } - - expectThat(service.getLocations(dateFrom = null, dateTo = null, offset = 0, limit = null)) { - get { status_code } - .isEqualTo(OcpiStatus.SUCCESS.code) - - get { data } - .isNotNull() - .get(SearchResult::offset) - .isEqualTo(0) - } - - expectThat(service.getLocations(dateFrom = null, dateTo = null, offset = -10, limit = null)) { - get { status_code } - .isEqualTo(OcpiStatus.CLIENT_INVALID_PARAMETERS.code) - - get { data } - .isNull() - } - - expectThat(service.getLocations(dateFrom = null, dateTo = null, offset = 0, limit = -10)) { - get { status_code } - .isEqualTo(OcpiStatus.CLIENT_INVALID_PARAMETERS.code) - - get { data } - .isNull() - } - - expectThat(service.getLocations(dateFrom = null, dateTo = null, offset = 0, limit = 100)) { - get { status_code } - .isEqualTo(OcpiStatus.SUCCESS.code) - - get { data } - .isNotNull() - .get(SearchResult::offset) - .isEqualTo(0) - - get { data } - .isNotNull() - .get(SearchResult::limit) - .isEqualTo(100) - } - - expectThat(service.getLocations(dateFrom = null, dateTo = null, offset = 100, limit = 100)) { - get { status_code } - .isEqualTo(OcpiStatus.SUCCESS.code) - - get { data } - .isNotNull() - .get(SearchResult::offset) - .isEqualTo(100) - - get { data } - .isNotNull() - .get(SearchResult::limit) - .isEqualTo(100) - } - - expectThat(service.getLocations(dateFrom = null, dateTo = null, offset = 0, limit = 0)) { - get { status_code } - .isEqualTo(OcpiStatus.SUCCESS.code) - - get { data } - .isNotNull() - .get(SearchResult::offset) - .isEqualTo(0) - - get { data } - .isNotNull() - .get(SearchResult::limit) - .isEqualTo(0) - } - } - - @Test - fun getLocationParamsValidationTest() { - service = - LocationsCpoValidationService(service = locationsCpoService(emptyList())) - - val str3chars = "abc" - val str39chars = "abababababababababababababababababababa" - val str40chars = "abababababababababababababababababababab" - - expectThat(service.getLocation(locationId = str3chars)) { - get { status_code } - .isEqualTo(OcpiStatus.SUCCESS.code) - } - - expectThat(service.getLocation(locationId = str39chars)) { - get { status_code } - .isEqualTo(OcpiStatus.SUCCESS.code) - } - - expectThat(service.getLocation(locationId = str40chars)) { - get { status_code } - .isEqualTo(OcpiStatus.CLIENT_INVALID_PARAMETERS.code) - } - } - - @Test - fun getEvseParamsValidationTest() { - service = LocationsCpoValidationService(service = locationsCpoService(emptyList())) - - val str3chars = "abc" - val str39chars = "abababababababababababababababababababa" - val str40chars = "abababababababababababababababababababab" - - expectThat(service.getEvse(locationId = str3chars, evseUid = str3chars)) { - get { status_code } - .isEqualTo(OcpiStatus.SUCCESS.code) - } - - expectThat(service.getEvse(locationId = str39chars, evseUid = str3chars)) { - get { status_code } - .isEqualTo(OcpiStatus.SUCCESS.code) - } - - expectThat(service.getEvse(locationId = str40chars, evseUid = str3chars)) { - get { status_code } - .isEqualTo(OcpiStatus.CLIENT_INVALID_PARAMETERS.code) - } - - expectThat(service.getEvse(locationId = str3chars, evseUid = str3chars)) { - get { status_code } - .isEqualTo(OcpiStatus.SUCCESS.code) - } - - expectThat(service.getEvse(locationId = str3chars, evseUid = str39chars)) { - get { status_code } - .isEqualTo(OcpiStatus.SUCCESS.code) - } - - expectThat(service.getEvse(locationId = str3chars, evseUid = str40chars)) { - get { status_code } - .isEqualTo(OcpiStatus.CLIENT_INVALID_PARAMETERS.code) - } - - expectThat(service.getEvse(locationId = str40chars, evseUid = str40chars)) { - get { status_code } - .isEqualTo(OcpiStatus.CLIENT_INVALID_PARAMETERS.code) - } - } - - @Test - fun getConnectorParamsValidationTest() { - service = - LocationsCpoValidationService(service = locationsCpoService(emptyList())) - - val str3chars = "abc" - val str37chars = "ababababababababababababababababababa" - val str39chars = "abababababababababababababababababababa" - val str40chars = "abababababababababababababababababababab" - - expectThat( - service.getConnector( - locationId = str3chars, - evseUid = str3chars, - connectorId = str3chars - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.SUCCESS.code) - } - - expectThat( - service.getConnector( - locationId = str39chars, - evseUid = str3chars, - connectorId = str3chars - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.SUCCESS.code) - } - - expectThat( - service.getConnector( - locationId = str40chars, - evseUid = str3chars, - connectorId = str3chars - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.CLIENT_INVALID_PARAMETERS.code) - } - - expectThat( - service.getConnector( - locationId = str3chars, - evseUid = str3chars, - connectorId = str3chars - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.SUCCESS.code) - } - - expectThat( - service.getConnector( - locationId = str3chars, - evseUid = str39chars, - connectorId = str3chars - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.SUCCESS.code) - } - - expectThat( - service.getConnector( - locationId = str3chars, - evseUid = str40chars, - connectorId = str3chars - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.CLIENT_INVALID_PARAMETERS.code) - } - - expectThat( - service.getConnector( - locationId = str40chars, - evseUid = str40chars, - connectorId = str3chars - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.CLIENT_INVALID_PARAMETERS.code) - } - - expectThat( - service.getConnector( - locationId = str3chars, - evseUid = str3chars, - connectorId = str37chars - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.CLIENT_INVALID_PARAMETERS.code) - } - - expectThat( - service.getConnector( - locationId = str40chars, - evseUid = str40chars, - connectorId = str37chars - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.CLIENT_INVALID_PARAMETERS.code) - } - } -} diff --git a/ocpi-toolkit-2.1.1/src/test/kotlin/com/izivia/ocpi/toolkit/tests/validation/LocationsEmspValidationServiceTest.kt b/ocpi-toolkit-2.1.1/src/test/kotlin/com/izivia/ocpi/toolkit/tests/validation/LocationsEmspValidationServiceTest.kt deleted file mode 100644 index e2f08000..00000000 --- a/ocpi-toolkit-2.1.1/src/test/kotlin/com/izivia/ocpi/toolkit/tests/validation/LocationsEmspValidationServiceTest.kt +++ /dev/null @@ -1,732 +0,0 @@ -package com.izivia.ocpi.toolkit.tests.validation - -import com.izivia.ocpi.toolkit.common.OcpiStatus -import com.izivia.ocpi.toolkit.modules.locations.domain.toPartial -import com.izivia.ocpi.toolkit.modules.locations.validation.LocationsEmspValidationService -import com.izivia.ocpi.toolkit.samples.common.validConnector -import com.izivia.ocpi.toolkit.samples.common.validEvse -import com.izivia.ocpi.toolkit.samples.common.validLocation -import com.izivia.ocpi.toolkit.tests.mock.locationsEmspService -import org.junit.jupiter.api.Test -import strikt.api.expectThat -import strikt.assertions.isEqualTo -import java.util.* - -class LocationsEmspValidationServiceTest { - private lateinit var service: LocationsEmspValidationService - - val token = UUID.randomUUID().toString() - val str1char = "a" - val str2chars = "ab" - val str3chars = "abc" - val str4chars = "abcd" - val str36chars = "abababababababababababababababababab" - val str37chars = "ababababababababababababababababababa" - val str39chars = "abababababababababababababababababababa" - val str40chars = "abababababababababababababababababababab" - - @Test - fun getLocationParamsValidationTest() { - service = LocationsEmspValidationService(service = locationsEmspService(emptyList())) - - expectThat(service.getLocation(countryCode = str1char, partyId = str2chars, locationId = str4chars)) { - get { status_code } - .isEqualTo(OcpiStatus.SUCCESS.code) - } - - expectThat(service.getLocation(countryCode = str2chars, partyId = str3chars, locationId = str39chars)) { - get { status_code } - .isEqualTo(OcpiStatus.SUCCESS.code) - } - - expectThat(service.getLocation(countryCode = str3chars, partyId = str3chars, locationId = str39chars)) { - get { status_code } - .isEqualTo(OcpiStatus.CLIENT_INVALID_PARAMETERS.code) - } - - expectThat(service.getLocation(countryCode = str2chars, partyId = str4chars, locationId = str39chars)) { - get { status_code } - .isEqualTo(OcpiStatus.CLIENT_INVALID_PARAMETERS.code) - } - - expectThat(service.getLocation(countryCode = str2chars, partyId = str3chars, locationId = str40chars)) { - get { status_code } - .isEqualTo(OcpiStatus.CLIENT_INVALID_PARAMETERS.code) - } - } - - @Test - fun getEvseParamsValidationTest() { - service = LocationsEmspValidationService(service = locationsEmspService(emptyList())) - - expectThat( - service.getEvse( - countryCode = str1char, - partyId = str2chars, - locationId = str4chars, - evseUid = str4chars - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.SUCCESS.code) - } - - expectThat( - service.getEvse( - countryCode = str2chars, - partyId = str3chars, - locationId = str39chars, - evseUid = str39chars - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.SUCCESS.code) - } - - expectThat( - service.getEvse( - countryCode = str3chars, - partyId = str3chars, - locationId = str39chars, - evseUid = str39chars - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.CLIENT_INVALID_PARAMETERS.code) - } - - expectThat( - service.getEvse( - countryCode = str2chars, - partyId = str4chars, - locationId = str39chars, - evseUid = str39chars - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.CLIENT_INVALID_PARAMETERS.code) - } - - expectThat( - service.getEvse( - countryCode = str2chars, - partyId = str3chars, - locationId = str40chars, - evseUid = str39chars - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.CLIENT_INVALID_PARAMETERS.code) - } - - expectThat( - service.getEvse( - countryCode = str2chars, - partyId = str3chars, - locationId = str39chars, - evseUid = str40chars - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.CLIENT_INVALID_PARAMETERS.code) - } - } - - @Test - fun getConnectorParamsValidationTest() { - service = LocationsEmspValidationService(service = locationsEmspService(emptyList())) - - expectThat( - service.getConnector( - countryCode = str1char, - partyId = str2chars, - locationId = str4chars, - evseUid = str4chars, - connectorId = str4chars - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.SUCCESS.code) - } - - expectThat( - service.getConnector( - countryCode = str2chars, - partyId = str3chars, - locationId = str39chars, - evseUid = str39chars, - connectorId = str36chars - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.SUCCESS.code) - } - - expectThat( - service.getConnector( - countryCode = str3chars, - partyId = str3chars, - locationId = str39chars, - evseUid = str39chars, - connectorId = str36chars - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.CLIENT_INVALID_PARAMETERS.code) - } - - expectThat( - service.getConnector( - countryCode = str2chars, - partyId = str4chars, - locationId = str39chars, - evseUid = str39chars, - connectorId = str36chars - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.CLIENT_INVALID_PARAMETERS.code) - } - - expectThat( - service.getConnector( - countryCode = str2chars, - partyId = str3chars, - locationId = str40chars, - evseUid = str39chars, - connectorId = str36chars - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.CLIENT_INVALID_PARAMETERS.code) - } - - expectThat( - service.getConnector( - countryCode = str2chars, - partyId = str3chars, - locationId = str39chars, - evseUid = str40chars, - connectorId = str36chars - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.CLIENT_INVALID_PARAMETERS.code) - } - - expectThat( - service.getConnector( - countryCode = str2chars, - partyId = str3chars, - locationId = str39chars, - evseUid = str39chars, - connectorId = str37chars - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.CLIENT_INVALID_PARAMETERS.code) - } - } - - @Test - fun patchLocationParamsValidationTest() { - service = LocationsEmspValidationService(service = locationsEmspService(emptyList())) - - expectThat( - service.patchLocation( - countryCode = str1char, - partyId = str2chars, - locationId = str4chars, - location = validLocation.toPartial() - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.SUCCESS.code) - } - - expectThat( - service.patchLocation( - countryCode = str2chars, - partyId = str3chars, - locationId = str39chars, - location = validLocation.toPartial() - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.SUCCESS.code) - } - - expectThat( - service.patchLocation( - countryCode = str3chars, - partyId = str3chars, - locationId = str39chars, - location = validLocation.toPartial() - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.CLIENT_INVALID_PARAMETERS.code) - } - - expectThat( - service.patchLocation( - countryCode = str2chars, - partyId = str4chars, - locationId = str39chars, - location = validLocation.toPartial() - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.CLIENT_INVALID_PARAMETERS.code) - } - - expectThat( - service.patchLocation( - countryCode = str2chars, - partyId = str3chars, - locationId = str40chars, - location = validLocation.toPartial() - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.CLIENT_INVALID_PARAMETERS.code) - } - } - - @Test - fun patchEvseParamsValidationTest() { - service = LocationsEmspValidationService(service = locationsEmspService(emptyList())) - - expectThat( - service.patchEvse( - countryCode = str1char, - partyId = str2chars, - locationId = str4chars, - evseUid = str4chars, - evse = validEvse.toPartial() - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.SUCCESS.code) - } - - expectThat( - service.patchEvse( - countryCode = str2chars, - partyId = str3chars, - locationId = str39chars, - evseUid = str39chars, - evse = validEvse.toPartial() - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.SUCCESS.code) - } - - expectThat( - service.patchEvse( - countryCode = str3chars, - partyId = str3chars, - locationId = str39chars, - evseUid = str39chars, - evse = validEvse.toPartial() - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.CLIENT_INVALID_PARAMETERS.code) - } - - expectThat( - service.patchEvse( - countryCode = str2chars, - partyId = str4chars, - locationId = str39chars, - evseUid = str39chars, - evse = validEvse.toPartial() - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.CLIENT_INVALID_PARAMETERS.code) - } - - expectThat( - service.patchEvse( - countryCode = str2chars, - partyId = str3chars, - locationId = str40chars, - evseUid = str39chars, - evse = validEvse.toPartial() - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.CLIENT_INVALID_PARAMETERS.code) - } - - expectThat( - service.patchEvse( - countryCode = str2chars, - partyId = str3chars, - locationId = str39chars, - evseUid = str40chars, - evse = validEvse.toPartial() - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.CLIENT_INVALID_PARAMETERS.code) - } - } - - @Test - fun patchConnectorParamsValidationTest() { - service = LocationsEmspValidationService(service = locationsEmspService(emptyList())) - - expectThat( - service.patchConnector( - countryCode = str1char, - partyId = str2chars, - locationId = str4chars, - evseUid = str4chars, - connectorId = str4chars, - connector = validConnector.toPartial() - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.SUCCESS.code) - } - - expectThat( - service.patchConnector( - countryCode = str2chars, - partyId = str3chars, - locationId = str39chars, - evseUid = str39chars, - connectorId = str36chars, - connector = validConnector.toPartial() - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.SUCCESS.code) - } - - expectThat( - service.patchConnector( - countryCode = str3chars, - partyId = str3chars, - locationId = str39chars, - evseUid = str39chars, - connectorId = str36chars, - connector = validConnector.toPartial() - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.CLIENT_INVALID_PARAMETERS.code) - } - - expectThat( - service.patchConnector( - countryCode = str2chars, - partyId = str4chars, - locationId = str39chars, - evseUid = str39chars, - connectorId = str36chars, - connector = validConnector.toPartial() - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.CLIENT_INVALID_PARAMETERS.code) - } - - expectThat( - service.patchConnector( - countryCode = str2chars, - partyId = str3chars, - locationId = str40chars, - evseUid = str39chars, - connectorId = str36chars, - connector = validConnector.toPartial() - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.CLIENT_INVALID_PARAMETERS.code) - } - - expectThat( - service.patchConnector( - countryCode = str2chars, - partyId = str3chars, - locationId = str39chars, - evseUid = str40chars, - connectorId = str36chars, - connector = validConnector.toPartial() - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.CLIENT_INVALID_PARAMETERS.code) - } - - expectThat( - service.patchConnector( - countryCode = str2chars, - partyId = str3chars, - locationId = str39chars, - evseUid = str39chars, - connectorId = str37chars, - connector = validConnector.toPartial() - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.CLIENT_INVALID_PARAMETERS.code) - } - } - - @Test - fun putLocationParamsValidationTest() { - service = LocationsEmspValidationService(service = locationsEmspService(emptyList())) - - expectThat( - service.putLocation( - countryCode = str1char, - partyId = str2chars, - locationId = str4chars, - location = validLocation - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.SUCCESS.code) - } - - expectThat( - service.putLocation( - countryCode = str2chars, - partyId = str3chars, - locationId = str39chars, - location = validLocation - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.SUCCESS.code) - } - - expectThat( - service.putLocation( - countryCode = str3chars, - partyId = str3chars, - locationId = str39chars, - location = validLocation - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.CLIENT_INVALID_PARAMETERS.code) - } - - expectThat( - service.putLocation( - countryCode = str2chars, - partyId = str4chars, - locationId = str39chars, - location = validLocation - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.CLIENT_INVALID_PARAMETERS.code) - } - - expectThat( - service.putLocation( - countryCode = str2chars, - partyId = str3chars, - locationId = str40chars, - location = validLocation - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.CLIENT_INVALID_PARAMETERS.code) - } - } - - @Test - fun putEvseParamsValidationTest() { - service = LocationsEmspValidationService(service = locationsEmspService(emptyList())) - - expectThat( - service.putEvse( - countryCode = str1char, - partyId = str2chars, - locationId = str4chars, - evseUid = str4chars, - evse = validEvse - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.SUCCESS.code) - } - - expectThat( - service.putEvse( - countryCode = str2chars, - partyId = str3chars, - locationId = str39chars, - evseUid = str39chars, - evse = validEvse - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.SUCCESS.code) - } - - expectThat( - service.putEvse( - countryCode = str3chars, - partyId = str3chars, - locationId = str39chars, - evseUid = str39chars, - evse = validEvse - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.CLIENT_INVALID_PARAMETERS.code) - } - - expectThat( - service.putEvse( - countryCode = str2chars, - partyId = str4chars, - locationId = str39chars, - evseUid = str39chars, - evse = validEvse - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.CLIENT_INVALID_PARAMETERS.code) - } - - expectThat( - service.putEvse( - countryCode = str2chars, - partyId = str3chars, - locationId = str40chars, - evseUid = str39chars, - evse = validEvse - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.CLIENT_INVALID_PARAMETERS.code) - } - - expectThat( - service.putEvse( - countryCode = str2chars, - partyId = str3chars, - locationId = str39chars, - evseUid = str40chars, - evse = validEvse - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.CLIENT_INVALID_PARAMETERS.code) - } - } - - @Test - fun putConnectorParamsValidationTest() { - service = LocationsEmspValidationService(service = locationsEmspService(emptyList())) - - expectThat( - service.putConnector( - countryCode = str1char, - partyId = str2chars, - locationId = str4chars, - evseUid = str4chars, - connectorId = str4chars, - connector = validConnector - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.SUCCESS.code) - } - - expectThat( - service.putConnector( - countryCode = str2chars, - partyId = str3chars, - locationId = str39chars, - evseUid = str39chars, - connectorId = str36chars, - connector = validConnector - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.SUCCESS.code) - } - - expectThat( - service.putConnector( - countryCode = str3chars, - partyId = str3chars, - locationId = str39chars, - evseUid = str39chars, - connectorId = str36chars, - connector = validConnector - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.CLIENT_INVALID_PARAMETERS.code) - } - - expectThat( - service.putConnector( - countryCode = str2chars, - partyId = str4chars, - locationId = str39chars, - evseUid = str39chars, - connectorId = str36chars, - connector = validConnector - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.CLIENT_INVALID_PARAMETERS.code) - } - - expectThat( - service.putConnector( - countryCode = str2chars, - partyId = str3chars, - locationId = str40chars, - evseUid = str39chars, - connectorId = str36chars, - connector = validConnector - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.CLIENT_INVALID_PARAMETERS.code) - } - - expectThat( - service.putConnector( - countryCode = str2chars, - partyId = str3chars, - locationId = str39chars, - evseUid = str40chars, - connectorId = str36chars, - connector = validConnector - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.CLIENT_INVALID_PARAMETERS.code) - } - - expectThat( - service.putConnector( - countryCode = str2chars, - partyId = str3chars, - locationId = str39chars, - evseUid = str39chars, - connectorId = str37chars, - connector = validConnector - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.CLIENT_INVALID_PARAMETERS.code) - } - } -} diff --git a/ocpi-toolkit-2.1.1/src/test/kotlin/com/izivia/ocpi/toolkit/tests/validation/LocationsValidatorTest.kt b/ocpi-toolkit-2.1.1/src/test/kotlin/com/izivia/ocpi/toolkit/tests/validation/LocationsValidatorTest.kt deleted file mode 100644 index caef6f1e..00000000 --- a/ocpi-toolkit-2.1.1/src/test/kotlin/com/izivia/ocpi/toolkit/tests/validation/LocationsValidatorTest.kt +++ /dev/null @@ -1,574 +0,0 @@ -package com.izivia.ocpi.toolkit.tests.validation - -import com.izivia.ocpi.toolkit.modules.locations.domain.* -import com.izivia.ocpi.toolkit.modules.locations.validation.validate -import com.izivia.ocpi.toolkit.samples.common.* -import org.junit.jupiter.api.Test -import strikt.api.expectCatching -import strikt.assertions.isFailure -import strikt.assertions.isSuccess -import java.math.BigDecimal -import kotlin.random.Random - -class LocationsValidatorTest { - - private fun generateRandomString(length: Int): String = (('a'..'z') + ('A'..'Z')) - .let { chars -> - (0 until length) - .map { chars[Random.nextInt(chars.size)] } - .joinToString("") - } - - @Test - fun `Location validator`() { - expectCatching { - validLocation.validate() - }.isSuccess() - - expectCatching { - validLocation.copy(id = generateRandomString(40)).validate() - }.isFailure() - - expectCatching { - validLocation.copy(name = generateRandomString(256)).validate() - }.isFailure() - - expectCatching { - validLocation.copy(address = generateRandomString(46)).validate() - }.isFailure() - - expectCatching { - validLocation.copy(city = generateRandomString(46)).validate() - }.isFailure() - - expectCatching { - validLocation.copy(postal_code = generateRandomString(11)).validate() - }.isFailure() - - expectCatching { - validLocation.copy(country = generateRandomString(4)).validate() - }.isFailure() - - expectCatching { - validLocation.copy(country = "fra").validate() - }.isFailure() - - expectCatching { - validLocation.copy(time_zone = generateRandomString(256)).validate() - }.isFailure() - - expectCatching { - validLocation.copy(time_zone = "EuropeOslo").validate() - }.isFailure() - } - - @Test - fun `Evse validator`() { - expectCatching { - validEvse.validate() - }.isSuccess() - - expectCatching { - validEvse.copy(evse_id = "FR*A23*E45B*78C").validate() - }.isSuccess() - - expectCatching { - validEvse.copy(evse_id = "fr*a23*e45b*78c").validate() - }.isSuccess() - - expectCatching { - validEvse.copy(evse_id = "FRA23E45B78C").validate() - }.isSuccess() - - expectCatching { - validEvse.copy(evse_id = "FRA23E45B*78C").validate() - }.isSuccess() - - expectCatching { - validEvse.copy(evse_id = "FR*A23*E${generateRandomString(31)}").validate() - }.isSuccess() - - expectCatching { - validEvse.copy(evse_id = "F*A23*E45B*78C").validate() - }.isFailure() - - expectCatching { - validEvse.copy(evse_id = "FR*A2*E45B*78C").validate() - }.isFailure() - - expectCatching { - validEvse.copy(evse_id = "FR*A23*A45B*78C").validate() - }.isFailure() - - expectCatching { - validEvse.copy(evse_id = "FR*A23*E").validate() - }.isFailure() - - expectCatching { - validEvse.copy(evse_id = "FR*A23*E${generateRandomString(32)}").validate() - }.isFailure() - - expectCatching { - validEvse.copy(uid = generateRandomString(40)).validate() - }.isFailure() - - expectCatching { - validEvse.copy(floor_level = generateRandomString(5)).validate() - }.isFailure() - - expectCatching { - validEvse.copy(physical_reference = generateRandomString(17)).validate() - }.isFailure() - } - - @Test - fun `Connector validator`() { - expectCatching { - validConnector.validate() - validConnector.copy(voltage = 0).validate() - validConnector.copy(amperage = 0).validate() - }.isSuccess() - - expectCatching { - validConnector.copy(id = generateRandomString(37)).validate() - }.isFailure() - - expectCatching { - validConnector.copy(voltage = -1).validate() - }.isFailure() - - expectCatching { - validConnector.copy(amperage = -1).validate() - }.isFailure() - - expectCatching { - validConnector.copy(tariff_id = generateRandomString(37)).validate() - }.isFailure() - - expectCatching { - validConnector.copy(terms_and_conditions = "not an url").validate() - }.isFailure() - } - - @Test - fun `GeoLocation validator`() { - expectCatching { - GeoLocation( - "1.55", - "2.15" - ).validate() - }.isFailure() - - expectCatching { - GeoLocation( - "1.123456", - "2111.123456" - ).validate() - }.isFailure() - - expectCatching { - GeoLocation( - "111.123456", - "21.123456" - ).validate() - }.isFailure() - - expectCatching { - GeoLocation( - "-111.123456", - "21.123456" - ).validate() - }.isFailure() - - expectCatching { - GeoLocation( - "1.123456", - ".123456" - ).validate() - }.isFailure() - - expectCatching { - GeoLocation( - "1.123456", - "-.123456" - ).validate() - }.isFailure() - - expectCatching { - GeoLocation( - "1.123456", - "-1111.123456" - ).validate() - }.isFailure() - - expectCatching { - GeoLocation( - "101.123456", - "2.123456" - ).validate() - }.isFailure() - - expectCatching { - validGeoLocation.validate() - - GeoLocation( - "1.123456", - "2.123456" - ).validate() - - GeoLocation( - "-5.123456", - "12.123456" - ).validate() - - GeoLocation( - "1.123456", - "-2.123456" - ).validate() - - GeoLocation( - "-1.123456", - "-2.123456" - ).validate() - - GeoLocation( - "-1.123456", - "-211.123456" - ).validate() - }.isSuccess() - } - - @Test - fun `EnvironmentalImpact validator`() { - expectCatching { - EnvironmentalImpact( - source = EnvironmentalImpactCategory.CARBON_DIOXIDE, - amount = BigDecimal(0.0) - ).validate() - - EnvironmentalImpact( - source = EnvironmentalImpactCategory.CARBON_DIOXIDE, - amount = BigDecimal(1.0) - ).validate() - - EnvironmentalImpact( - source = EnvironmentalImpactCategory.CARBON_DIOXIDE, - amount = BigDecimal(12.0) - ).validate() - - EnvironmentalImpact( - source = EnvironmentalImpactCategory.CARBON_DIOXIDE, - amount = BigDecimal(12.1234) - ).validate() - }.isSuccess() - - expectCatching { - EnvironmentalImpact( - source = EnvironmentalImpactCategory.CARBON_DIOXIDE, - amount = BigDecimal(-0.1) - ).validate() - }.isFailure() - - expectCatching { - EnvironmentalImpact( - source = EnvironmentalImpactCategory.CARBON_DIOXIDE, - amount = BigDecimal(-10) - ).validate() - }.isFailure() - } - - @Test - fun `EnergySource validator`() { - expectCatching { - EnergySource( - source = EnergySourceCategory.NUCLEAR, - percentage = BigDecimal(0.0) - ).validate() - - EnergySource( - source = EnergySourceCategory.NUCLEAR, - percentage = BigDecimal(1.0) - ).validate() - - EnergySource( - source = EnergySourceCategory.NUCLEAR, - percentage = BigDecimal(12.0) - ).validate() - - EnergySource( - source = EnergySourceCategory.NUCLEAR, - percentage = BigDecimal(12.1234) - ).validate() - - EnergySource( - source = EnergySourceCategory.NUCLEAR, - percentage = BigDecimal(100.00) - ).validate() - }.isSuccess() - - expectCatching { - EnergySource( - source = EnergySourceCategory.NUCLEAR, - percentage = BigDecimal(-0.1) - ).validate() - }.isFailure() - - expectCatching { - EnergySource( - source = EnergySourceCategory.NUCLEAR, - percentage = BigDecimal(-10) - ).validate() - }.isFailure() - - expectCatching { - EnergySource( - source = EnergySourceCategory.NUCLEAR, - percentage = BigDecimal(100.1) - ).validate() - }.isFailure() - - expectCatching { - EnergySource( - source = EnergySourceCategory.NUCLEAR, - percentage = BigDecimal(101) - ).validate() - }.isFailure() - } - - @Test - fun `EnergyMix validator`() { - expectCatching { - validEnergyMix.validate() - }.isSuccess() - - expectCatching { - validEnergyMix.copy(supplier_name = generateRandomString(65)).validate() - }.isFailure() - - expectCatching { - validEnergyMix.copy(energy_product_name = generateRandomString(65)).validate() - }.isFailure() - } - - @Test - fun `ExceptionalPeriod validator`() { - expectCatching { - validExceptionalPeriod.validate() - - validExceptionalPeriod.copy( - period_begin = validExceptionalPeriod.period_begin, - period_end = validExceptionalPeriod.period_begin - ).validate() - }.isSuccess() - - expectCatching { - validExceptionalPeriod.copy( - period_begin = validExceptionalPeriod.period_end, - period_end = validExceptionalPeriod.period_begin - ).validate() - }.isFailure() - } - - @Test - fun `RegularHours validator`() { - expectCatching { - validRegularHours.validate() - - validRegularHours.copy( - period_begin = validRegularHours.period_begin, - period_end = validRegularHours.period_begin - ).validate() - }.isSuccess() - - expectCatching { - validRegularHours.copy( - period_begin = validRegularHours.period_end, - period_end = validRegularHours.period_begin - ).validate() - }.isFailure() - - expectCatching { - validRegularHours.copy( - weekday = 0 - ).validate() - }.isFailure() - - expectCatching { - validRegularHours.copy( - weekday = 8 - ).validate() - }.isFailure() - - expectCatching { - validRegularHours.copy( - period_begin = "1:00" - ).validate() - }.isFailure() - - expectCatching { - validRegularHours.copy( - period_begin = "00:1" - ).validate() - }.isFailure() - - expectCatching { - validRegularHours.copy( - period_begin = "0010" - ).validate() - }.isFailure() - } - - @Test - fun `Hours validator`() { - expectCatching { - validHours.validate() - - validHours.copy( - regular_hours = null, - twenty_four_seven = true - ).validate() - - validHours.copy( - exceptional_openings = emptyList(), - exceptional_closings = emptyList() - ).validate() - }.isSuccess() - - expectCatching { - validHours.toPartial().validate() - - // This fails when not partial, but does not when partial - validHours.toPartial().copy(regular_hours = null, twenty_four_seven = null).validate() - }.isSuccess() - - expectCatching { - validHours.copy( - regular_hours = listOf(validRegularHours), - twenty_four_seven = true - ).toPartial().validate() - }.isFailure() - - expectCatching { - validHours.copy( - regular_hours = listOf(validRegularHours), - twenty_four_seven = true - ).validate() - }.isFailure() - - expectCatching { - validHours.copy( - regular_hours = null, - twenty_four_seven = null - ).validate() - }.isFailure() - } - - @Test - fun `Image validator`() { - expectCatching { - validImage.validate() - }.isSuccess() - - expectCatching { - validImage.copy(width = 123456).validate() - }.isFailure() - - expectCatching { - validImage.copy(height = 123456).validate() - }.isFailure() - - expectCatching { - validImage.copy(type = "abcde").validate() - }.isFailure() - - expectCatching { - validImage.copy(url = "not an url").validate() - }.isFailure() - - expectCatching { - validImage.copy(thumbnail = "not an url").validate() - }.isFailure() - } - - @Test - fun `BusinessDetails validator`() { - expectCatching { - validBusinessDetails.validate() - validBusinessDetails.copy(website = null).validate() - validBusinessDetails.copy(logo = null).validate() - }.isSuccess() - - expectCatching { - validBusinessDetails.copy(name = generateRandomString(101)).validate() - }.isFailure() - - expectCatching { - validBusinessDetails.copy(website = "not an url").validate() - }.isFailure() - } - - @Test - fun `AdditionalGeoLocation validator`() { - expectCatching { - validAdditionalGeoLocation.validate() - validAdditionalGeoLocation.copy(longitude = "123.123456").validate() - validAdditionalGeoLocation.copy(longitude = "-123.123456").validate() - validAdditionalGeoLocation.copy(latitude = "-13.123456").validate() - validAdditionalGeoLocation.copy(latitude = "13.123456").validate() - }.isSuccess() - - expectCatching { - validAdditionalGeoLocation.copy(latitude = "1.55").validate() - }.isFailure() - - expectCatching { - validAdditionalGeoLocation.copy(longitude = "1.55").validate() - }.isFailure() - - expectCatching { - validAdditionalGeoLocation.copy(longitude = "1111.55").validate() - }.isFailure() - - expectCatching { - validAdditionalGeoLocation.copy(latitude = "111.55").validate() - }.isFailure() - } - - @Test - fun `DisplayText validator`() { - expectCatching { - validDisplayText.validate() - }.isSuccess() - - expectCatching { - validDisplayText.copy(language = "fra").validate() - }.isFailure() - - expectCatching { - validDisplayText.copy(text = generateRandomString(513)).validate() - }.isFailure() - - expectCatching { - validDisplayText.copy(text = "no html!").validate() - }.isFailure() - } - - @Test - fun `StatusSchedule validator`() { - expectCatching { - validStatusSchedule.validate() - validStatusSchedule.copy( - period_begin = validStatusSchedule.period_begin, - period_end = validStatusSchedule.period_begin, - ).validate() - validStatusSchedule.copy(period_end = null).validate() - }.isSuccess() - - expectCatching { - validStatusSchedule.copy( - period_begin = validStatusSchedule.period_end!!, - period_end = validStatusSchedule.period_begin, - ).validate() - }.isFailure() - } -} \ No newline at end of file diff --git a/ocpi-toolkit-2.1.1/src/test/kotlin/com/izivia/ocpi/toolkit/tests/validation/TokensCpoValidationServiceTest.kt b/ocpi-toolkit-2.1.1/src/test/kotlin/com/izivia/ocpi/toolkit/tests/validation/TokensCpoValidationServiceTest.kt deleted file mode 100644 index 7e8d9350..00000000 --- a/ocpi-toolkit-2.1.1/src/test/kotlin/com/izivia/ocpi/toolkit/tests/validation/TokensCpoValidationServiceTest.kt +++ /dev/null @@ -1,170 +0,0 @@ -package com.izivia.ocpi.toolkit.tests.validation - -import com.izivia.ocpi.toolkit.common.OcpiStatus -import com.izivia.ocpi.toolkit.modules.tokens.domain.toPartial -import com.izivia.ocpi.toolkit.modules.tokens.validation.TokensCpoValidationService -import com.izivia.ocpi.toolkit.samples.common.validToken -import com.izivia.ocpi.toolkit.tests.mock.tokensCpoService -import org.junit.jupiter.api.Test -import strikt.api.expectThat -import strikt.assertions.isEqualTo - -class TokensCpoValidationServiceTest { - private lateinit var service: TokensCpoValidationService - private val str40chars = "abababababababababababababababababababab" - - @Test - fun getTokenParamsValidationTest() { - service = TokensCpoValidationService(service = tokensCpoService(mutableListOf())) - - expectThat( - service.getToken( - countryCode = "FR", - partyId = "ABC", - tokenUid = validToken.uid - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.SUCCESS.code) - } - - expectThat( - service.getToken( - countryCode = "FRx", - partyId = "ABC", - tokenUid = validToken.uid - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.CLIENT_INVALID_PARAMETERS.code) - } - - expectThat( - service.getToken( - countryCode = "FR", - partyId = "ABCx", - tokenUid = validToken.uid - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.CLIENT_INVALID_PARAMETERS.code) - } - - expectThat( - service.getToken( - countryCode = "FR", - partyId = "ABC", - tokenUid = str40chars - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.CLIENT_INVALID_PARAMETERS.code) - } - } - - @Test - fun putTokenParamsValidationTest() { - service = TokensCpoValidationService(service = tokensCpoService(mutableListOf())) - - expectThat( - service.putToken( - countryCode = "FR", - partyId = "ABC", - tokenUid = validToken.uid, - token = validToken - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.SUCCESS.code) - } - - expectThat( - service.putToken( - countryCode = "FRx", - partyId = "ABC", - tokenUid = validToken.uid, - token = validToken - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.CLIENT_INVALID_PARAMETERS.code) - } - - expectThat( - service.putToken( - countryCode = "FR", - partyId = "ABCx", - tokenUid = validToken.uid, - token = validToken - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.CLIENT_INVALID_PARAMETERS.code) - } - - expectThat( - service.putToken( - countryCode = "FR", - partyId = "ABC", - tokenUid = str40chars, - token = validToken - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.CLIENT_INVALID_PARAMETERS.code) - } - } - - @Test - fun patchTokenParamsValidationTest() { - service = TokensCpoValidationService(service = tokensCpoService(mutableListOf(validToken))) - - expectThat( - service.patchToken( - countryCode = "FR", - partyId = "ABC", - tokenUid = validToken.uid, - token = validToken.toPartial() - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.SUCCESS.code) - } - - expectThat( - service.patchToken( - countryCode = "FRx", - partyId = "ABC", - tokenUid = validToken.uid, - token = validToken.toPartial() - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.CLIENT_INVALID_PARAMETERS.code) - } - - expectThat( - service.patchToken( - countryCode = "FR", - partyId = "ABCx", - tokenUid = validToken.uid, - token = validToken.toPartial() - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.CLIENT_INVALID_PARAMETERS.code) - } - - expectThat( - service.patchToken( - countryCode = "FR", - partyId = "ABC", - tokenUid = str40chars, - token = validToken.toPartial() - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.CLIENT_INVALID_PARAMETERS.code) - } - } -} diff --git a/ocpi-toolkit-2.1.1/src/test/kotlin/com/izivia/ocpi/toolkit/tests/validation/TokensEmspValidationServiceTest.kt b/ocpi-toolkit-2.1.1/src/test/kotlin/com/izivia/ocpi/toolkit/tests/validation/TokensEmspValidationServiceTest.kt deleted file mode 100644 index 5a9907fd..00000000 --- a/ocpi-toolkit-2.1.1/src/test/kotlin/com/izivia/ocpi/toolkit/tests/validation/TokensEmspValidationServiceTest.kt +++ /dev/null @@ -1,235 +0,0 @@ -package com.izivia.ocpi.toolkit.tests.validation - -import com.izivia.ocpi.toolkit.common.OcpiStatus -import com.izivia.ocpi.toolkit.common.SearchResult -import com.izivia.ocpi.toolkit.modules.tokens.domain.LocationReferences -import com.izivia.ocpi.toolkit.modules.tokens.domain.Token -import com.izivia.ocpi.toolkit.modules.tokens.domain.TokenType -import com.izivia.ocpi.toolkit.modules.tokens.validation.TokensEmspValidationService -import com.izivia.ocpi.toolkit.samples.common.validEvse -import com.izivia.ocpi.toolkit.samples.common.validLocation -import com.izivia.ocpi.toolkit.samples.common.validLocationReferences -import com.izivia.ocpi.toolkit.samples.common.validToken -import com.izivia.ocpi.toolkit.tests.mock.tokensEmspService -import org.junit.jupiter.api.Test -import strikt.api.expectThat -import strikt.assertions.isEqualTo -import strikt.assertions.isNotNull -import strikt.assertions.isNull -import java.time.Instant -import java.util.* - -class TokensEmspValidationServiceTest { - private lateinit var service: TokensEmspValidationService - private val from = Instant.parse("2022-04-28T08:00:00.000Z") - private val to = Instant.parse("2022-04-28T09:00:00.000Z") - private val str37chars = "ababababababababababababababababababa" - private val str40chars = "abababababababababababababababababababab" - - @Test - fun getTokensParamsValidationTest() { - service = TokensEmspValidationService(service = tokensEmspService(emptyList())) - - expectThat(service.getTokens(dateFrom = from, dateTo = from, offset = 0, limit = null)) { - get { status_code } - .isEqualTo(OcpiStatus.SUCCESS.code) - - get { data } - .isNotNull() - .get(SearchResult::offset) - .isEqualTo(0) - } - - expectThat(service.getTokens(dateFrom = to, dateTo = from, offset = 0, limit = null)) { - get { status_code } - .isEqualTo(OcpiStatus.CLIENT_INVALID_PARAMETERS.code) - - get { data } - .isNull() - } - - expectThat(service.getTokens(dateFrom = from, dateTo = to, offset = 0, limit = null)) { - get { status_code } - .isEqualTo(OcpiStatus.SUCCESS.code) - - get { data } - .isNotNull() - .get(SearchResult::offset) - .isEqualTo(0) - } - - expectThat(service.getTokens(dateFrom = null, dateTo = to, offset = 0, limit = null)) { - get { status_code } - .isEqualTo(OcpiStatus.SUCCESS.code) - - get { data } - .isNotNull() - .get(SearchResult::offset) - .isEqualTo(0) - } - - expectThat(service.getTokens(dateFrom = from, dateTo = null, offset = 0, limit = null)) { - get { status_code } - .isEqualTo(OcpiStatus.SUCCESS.code) - - get { data } - .isNotNull() - .get(SearchResult::offset) - .isEqualTo(0) - } - - expectThat(service.getTokens(dateFrom = null, dateTo = null, offset = 0, limit = null)) { - get { status_code } - .isEqualTo(OcpiStatus.SUCCESS.code) - - get { data } - .isNotNull() - .get(SearchResult::offset) - .isEqualTo(0) - } - - expectThat(service.getTokens(dateFrom = null, dateTo = null, offset = -10, limit = null)) { - get { status_code } - .isEqualTo(OcpiStatus.CLIENT_INVALID_PARAMETERS.code) - - get { data } - .isNull() - } - - expectThat(service.getTokens(dateFrom = null, dateTo = null, offset = 0, limit = -10)) { - get { status_code } - .isEqualTo(OcpiStatus.CLIENT_INVALID_PARAMETERS.code) - - get { data } - .isNull() - } - - expectThat(service.getTokens(dateFrom = null, dateTo = null, offset = 0, limit = 100)) { - get { status_code } - .isEqualTo(OcpiStatus.SUCCESS.code) - - get { data } - .isNotNull() - .get(SearchResult::offset) - .isEqualTo(0) - - get { data } - .isNotNull() - .get(SearchResult::limit) - .isEqualTo(100) - } - - expectThat(service.getTokens(dateFrom = null, dateTo = null, offset = 100, limit = 100)) { - get { status_code } - .isEqualTo(OcpiStatus.SUCCESS.code) - - get { data } - .isNotNull() - .get(SearchResult::offset) - .isEqualTo(100) - - get { data } - .isNotNull() - .get(SearchResult::limit) - .isEqualTo(100) - } - - expectThat(service.getTokens(dateFrom = null, dateTo = null, offset = 0, limit = 0)) { - get { status_code } - .isEqualTo(OcpiStatus.SUCCESS.code) - - get { data } - .isNotNull() - .get(SearchResult::offset) - .isEqualTo(0) - - get { data } - .isNotNull() - .get(SearchResult::limit) - .isEqualTo(0) - } - } - - @Test - fun postTokenParamsValidationTest() { - service = TokensEmspValidationService(service = tokensEmspService(emptyList())) - - expectThat( - service.postToken( - tokenUid = validToken.uid, - tokenType = TokenType.RFID, - locationReferences = null - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.SUCCESS.code) - } - - expectThat( - service.postToken( - tokenUid = validToken.uid, - tokenType = TokenType.RFID, - locationReferences = validLocationReferences - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.SUCCESS.code) - } - - expectThat( - service.postToken( - tokenUid = str37chars, - tokenType = TokenType.RFID, - locationReferences = null - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.CLIENT_INVALID_PARAMETERS.code) - } - - expectThat( - service.postToken( - tokenUid = validToken.uid, - tokenType = TokenType.RFID, - locationReferences = LocationReferences( - location_id = str40chars, - evse_uids = emptyList(), - connector_ids = emptyList() - ) - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.CLIENT_INVALID_PARAMETERS.code) - } - - expectThat( - service.postToken( - tokenUid = validToken.uid, - tokenType = TokenType.RFID, - locationReferences = LocationReferences( - location_id = validLocation.id, - evse_uids = listOf(str40chars), - connector_ids = emptyList() - ) - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.CLIENT_INVALID_PARAMETERS.code) - } - - expectThat( - service.postToken( - tokenUid = validToken.uid, - tokenType = TokenType.RFID, - locationReferences = LocationReferences( - location_id = validLocation.id, - evse_uids = listOf(validEvse.uid), - connector_ids = listOf(str40chars) - ) - ) - ) { - get { status_code } - .isEqualTo(OcpiStatus.CLIENT_INVALID_PARAMETERS.code) - } - } -} diff --git a/ocpi-toolkit-2.1.1/src/test/kotlin/com/izivia/ocpi/toolkit/tests/validation/TokensValidatorTest.kt b/ocpi-toolkit-2.1.1/src/test/kotlin/com/izivia/ocpi/toolkit/tests/validation/TokensValidatorTest.kt deleted file mode 100644 index df8de816..00000000 --- a/ocpi-toolkit-2.1.1/src/test/kotlin/com/izivia/ocpi/toolkit/tests/validation/TokensValidatorTest.kt +++ /dev/null @@ -1,68 +0,0 @@ -package com.izivia.ocpi.toolkit.tests.validation - -import com.izivia.ocpi.toolkit.modules.tokens.validation.validate -import com.izivia.ocpi.toolkit.samples.common.validLocationReferences -import com.izivia.ocpi.toolkit.samples.common.validToken -import org.junit.jupiter.api.Test -import strikt.api.expectCatching -import strikt.assertions.isFailure -import strikt.assertions.isSuccess -import kotlin.random.Random - -class TokensValidatorTest { - - private fun generateRandomString(length: Int): String = (('a'..'z') + ('A'..'Z')) - .let { chars -> - (0 until length) - .map { chars[Random.nextInt(chars.size)] } - .joinToString("") - } - - @Test - fun `Token validator`() { - expectCatching { - validToken.validate() - }.isSuccess() - - expectCatching { - validToken.copy(uid = generateRandomString(37)).validate() - }.isFailure() - - expectCatching { - validToken.copy(auth_id = generateRandomString(37)).validate() - }.isFailure() - - expectCatching { - validToken.copy(visual_number = generateRandomString(65)).validate() - }.isFailure() - - expectCatching { - validToken.copy(issuer = generateRandomString(65)).validate() - }.isFailure() - } - - @Test - fun `LocationReferences validator`() { - expectCatching { - validLocationReferences.validate() - }.isSuccess() - - expectCatching { - validLocationReferences - .copy(location_id = generateRandomString(40)) - .validate() - }.isFailure() - - expectCatching { - validLocationReferences - .copy(evse_uids = listOf(generateRandomString(40))) - .validate() - }.isFailure() - - expectCatching { - validLocationReferences - .copy(connector_ids = listOf(generateRandomString(40))) - .validate() - }.isFailure() - } -} diff --git a/ocpi-toolkit-2.2.1/build.gradle.kts b/ocpi-toolkit-2.2.1/build.gradle.kts index 55aa5f92..8bd67be8 100644 --- a/ocpi-toolkit-2.2.1/build.gradle.kts +++ b/ocpi-toolkit-2.2.1/build.gradle.kts @@ -1,11 +1,12 @@ plugins { - id("com.izivia.ocpi.toolkit.processor") id("java-library") id("maven-publish") + id("com.google.devtools.ksp") } dependencies { implementation(project(":common")) + ksp(project(":annotation-processor")) api(project(":transport")) api("org.apache.logging.log4j:log4j-api:${Versions.log4j}") @@ -43,7 +44,8 @@ tasks.test { } sourceSets.main { - java.srcDirs("src/main/kotlinGen") + // new way to use buildDir: https://docs.gradle.org/current/userguide/upgrading_version_8.html#deprecations_3 + kotlin.srcDirs("${layout.buildDirectory.get().asFile.absolutePath}/generated/ksp") } java { @@ -67,4 +69,3 @@ publishing { } } } - diff --git a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/common/HttpUtils.kt b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/common/HttpUtils.kt index 0ffff7ec..a0fcf761 100644 --- a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/common/HttpUtils.kt +++ b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/common/HttpUtils.kt @@ -1,7 +1,7 @@ package com.izivia.ocpi.toolkit.common import com.fasterxml.jackson.core.type.TypeReference -import com.izivia.ocpi.toolkit.modules.credentials.repositories.PlatformRepository +import com.izivia.ocpi.toolkit.modules.credentials.repositories.PartnerRepository import com.izivia.ocpi.toolkit.modules.versions.domain.ModuleID import com.izivia.ocpi.toolkit.transport.TransportClient import com.izivia.ocpi.toolkit.transport.TransportClientBuilder @@ -71,48 +71,48 @@ fun String.decodeBase64(): String = Base64.getDecoder().decode(this).decodeToStr fun authorizationHeader(token: String): Pair = Header.AUTHORIZATION to "Token ${token.encodeBase64()}" /** - * Creates the authorization header by taking the client token (or the token A if allowed) in the platform repository + * Creates the authorization header by taking the client token (or the token A if allowed) in the partner repository * * @receiver PlatformRepository used to retrieve tokens - * @param platformUrl partner /versions url + * @param partnerUrl partner /versions url * @param allowTokenA only true when called on versions / credentials module * @return Pair */ -suspend fun PlatformRepository.buildAuthorizationHeader( - platformUrl: String, +suspend fun PartnerRepository.buildAuthorizationHeader( + partnerUrl: String, allowTokenA: Boolean = false ): Pair = if (allowTokenA) { - getCredentialsTokenA(platformUrl = platformUrl) - ?: getCredentialsClientToken(platformUrl = platformUrl) + getCredentialsTokenA(partnerUrl = partnerUrl) + ?: getCredentialsClientToken(partnerUrl = partnerUrl) ?: throw throw OcpiClientUnknownTokenException( - "Could not find token A or client token associated with platform $platformUrl" + "Could not find token A or client token associated with partner $partnerUrl" ) } else { - getCredentialsClientToken(platformUrl = platformUrl) + getCredentialsClientToken(partnerUrl = partnerUrl) ?: throw throw OcpiClientUnknownTokenException( - "Could not find client token associated with platform $platformUrl" + "Could not find client token associated with partner $partnerUrl" ) } .let { token -> authorizationHeader(token = token) } /** - * Adds the authorization header to the request by taking the client token (or the token A if allowed) in the platform + * Adds the authorization header to the request by taking the client token (or the token A if allowed) in the partner * repository. * - * @param platformRepository use to retrieve tokens - * @param platformUrl partner /versions url + * @param partnerRepository use to retrieve tokens + * @param partnerUrl partner /versions url * @param allowTokenA only true when called on versions / credentials module */ suspend fun HttpRequest.authenticate( - platformRepository: PlatformRepository, - platformUrl: String, + partnerRepository: PartnerRepository, + partnerUrl: String, allowTokenA: Boolean = false ): AuthenticatedHttpRequest = withHeaders( headers = headers.plus( - platformRepository.buildAuthorizationHeader( - platformUrl = platformUrl, + partnerRepository.buildAuthorizationHeader( + partnerUrl = partnerUrl, allowTokenA = allowTokenA ) ) @@ -258,7 +258,7 @@ fun HttpRequest.parseAuthorizationHeader() = getHeader(Header.AUTHORIZATION) * @throws HttpException if the authorization header is missing * */ -suspend fun PlatformRepository.checkToken( +suspend fun PartnerRepository.checkToken( httpRequest: HttpRequest ) { val token = httpRequest.parseAuthorizationHeader() @@ -285,11 +285,11 @@ suspend fun PlatformRepository.checkToken( suspend fun TransportClientBuilder.buildFor( module: ModuleID, - platformUrl: String, - platformRepository: PlatformRepository + partnerUrl: String, + partnerRepository: PartnerRepository ): TransportClient = - platformRepository - .getEndpoints(platformUrl = platformUrl) + partnerRepository + .getEndpoints(partnerUrl = partnerUrl) .find { it.identifier == module } ?.let { build(baseUrl = it.url) } ?: throw OcpiToolkitUnknownEndpointException(endpointName = module.name) diff --git a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/common/Mapper.kt b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/common/Mapper.kt index 7653a447..8f9affd6 100644 --- a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/common/Mapper.kt +++ b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/common/Mapper.kt @@ -2,6 +2,7 @@ package com.izivia.ocpi.toolkit.common import com.fasterxml.jackson.annotation.JsonInclude import com.fasterxml.jackson.databind.ObjectMapper +import com.fasterxml.jackson.databind.PropertyNamingStrategies import com.fasterxml.jackson.databind.SerializationFeature import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule import com.fasterxml.jackson.module.kotlin.KotlinFeature @@ -21,4 +22,5 @@ val mapper: ObjectMapper = jacksonObjectMapper() ) .registerModule(JavaTimeModule()) .configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false) - .setSerializationInclusion(JsonInclude.Include.NON_NULL) \ No newline at end of file + .setSerializationInclusion(JsonInclude.Include.NON_NULL) + .setPropertyNamingStrategy(PropertyNamingStrategies.SNAKE_CASE) diff --git a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/common/OcpiExceptions.kt b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/common/OcpiExceptions.kt index d7a29f7a..df9841d3 100644 --- a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/common/OcpiExceptions.kt +++ b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/common/OcpiExceptions.kt @@ -6,12 +6,12 @@ sealed class OcpiException( message: String, open val httpStatus: HttpStatus, open val ocpiStatus: OcpiStatus -): Exception(message) +) : Exception(message) class OcpiResponseException( val statusCode: Int, val statusMessage: String -): Exception("Ocpi error: ${statusCode.toOcpiStatus()} $statusCode ($statusMessage)") +) : Exception("Ocpi error: ${statusCode.toOcpiStatus()} $statusCode ($statusMessage)") // 2xxx: Client errors class OcpiClientGenericException( @@ -86,4 +86,4 @@ class OcpiHubConnectionProblemException( message: String = "Connection problem", override val httpStatus: HttpStatus = HttpStatus.OK, override val ocpiStatus: OcpiStatus = OcpiStatus.HUB_CONNECTION_PROBLEM -) : OcpiException(message, httpStatus, ocpiStatus) \ No newline at end of file +) : OcpiException(message, httpStatus, ocpiStatus) diff --git a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/common/OcpiStatus.kt b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/common/OcpiStatus.kt index 772302ad..e7208914 100644 --- a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/common/OcpiStatus.kt +++ b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/common/OcpiStatus.kt @@ -82,4 +82,4 @@ enum class OcpiStatus(val code: Int) { HUB_CONNECTION_PROBLEM(4003) } -fun Int.toOcpiStatus(): OcpiStatus? = OcpiStatus.values().firstOrNull { it.code == this } \ No newline at end of file +fun Int.toOcpiStatus(): OcpiStatus? = OcpiStatus.values().firstOrNull { it.code == this } diff --git a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/common/OcpiToolkitExceptions.kt b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/common/OcpiToolkitExceptions.kt index 59667cfa..9e3b10cb 100644 --- a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/common/OcpiToolkitExceptions.kt +++ b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/common/OcpiToolkitExceptions.kt @@ -5,7 +5,7 @@ class OcpiToolkitUnknownEndpointException( ) : Exception( """ Endpoint '$endpointName' is unknown. Make sure you registered (credentialClient#register) first. During - registration process, the available endpoints are saved in platformRepository to be used later on. If you - already registered, make sure that the platformRepository works properly. + registration process, the available endpoints are saved in partnerRepository to be used later on. If you + already registered, make sure that the partnerRepository works properly. """.trimIndent() -) \ No newline at end of file +) diff --git a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/common/SearchResult.kt b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/common/SearchResult.kt index 19b6272b..a0656465 100644 --- a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/common/SearchResult.kt +++ b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/common/SearchResult.kt @@ -14,4 +14,4 @@ fun List.toSearchResult(totalCount: Int, limit: Int, offset: Int, nextPag limit = limit, offset = offset, nextPageUrl = nextPageUrl -) \ No newline at end of file +) diff --git a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/common/Utils.kt b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/common/Utils.kt index 5960f7c7..ec3a740c 100644 --- a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/common/Utils.kt +++ b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/common/Utils.kt @@ -6,4 +6,4 @@ fun generateUUIDv4Token(): String { return UUID.randomUUID().toString() } -typealias CiString = String \ No newline at end of file +typealias CiString = String diff --git a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/common/validation/Iso639Alpha2.kt b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/common/validation/Iso639Alpha2.kt index 94da8fd3..1d98cf6b 100644 --- a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/common/validation/Iso639Alpha2.kt +++ b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/common/validation/Iso639Alpha2.kt @@ -191,4 +191,4 @@ enum class Iso639Alpha2 { za, zh, zu -} \ No newline at end of file +} diff --git a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/common/validation/Validators.kt b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/common/validation/Validators.kt index bd0ca8d2..001438e5 100644 --- a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/common/validation/Validators.kt +++ b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/common/validation/Validators.kt @@ -76,19 +76,23 @@ fun Validator.Property.isCountryCode(caseSensitive: Boolean, alp fun Validator.Property.isCurrencyCode(caseSensitive: Boolean) = this.validate(CurrencyCodeConstraint()) { it == null || Currency.getAvailableCurrencies() - .contains(if (caseSensitive) Currency.getInstance(it) else Currency.getInstance(it.uppercase(Locale.ENGLISH))) + .contains( + if (caseSensitive) Currency.getInstance(it) else Currency.getInstance(it.uppercase(Locale.ENGLISH)) + ) } - /** * Valid if the string is an URL following the w3.org spec */ fun Validator.Property.isUrl() = this.validate(UrlConstraint()) { - it == null || try { URL(it).toURI().let { true } } catch (e: Exception) { false } + it == null || try { + URL(it).toURI().let { true } + } catch (e: Exception) { + false + } }.hasMaxLengthOf(255) - /** * Valid if the string is one of IANA tzdata's TZ-values representing the time zone. * Examples: "Europe/Oslo", "Europe/Zurich". (http://www.iana.org/time-zones) diff --git a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/cdr/domain/AuthMethod.kt b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/cdr/domain/AuthMethod.kt index 707c1f2a..4f226d0f 100644 --- a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/cdr/domain/AuthMethod.kt +++ b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/cdr/domain/AuthMethod.kt @@ -8,7 +8,7 @@ enum class AuthMethod { /** * Command like StartSession or ReserveNow used to start the Session, the Token provided in the - Command was used as authorization + Command was used as authorization */ COMMAND, diff --git a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/cdr/domain/Cdr.kt b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/cdr/domain/Cdr.kt index bac14ee9..f54a872c 100644 --- a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/cdr/domain/Cdr.kt +++ b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/cdr/domain/Cdr.kt @@ -15,100 +15,100 @@ suboperator platforms). This field is longer than the usual 36 characters to allow for credit CDRs to have something appended to the original ID. Normal (non-credit) CDRs SHALL only have an ID with a maximum length of 36. - * @property country_code (max-length=2) ISO-3166 alpha-2 country code of the CPO that 'owns' this CDR. - * @property party_id (max-length=3) CPO ID of the CPO that 'owns' this CDR (following the ISO-15118 + * @property countryCode (max-length=2) ISO-3166 alpha-2 country code of the CPO that 'owns' this CDR. + * @property partyId (max-length=3) CPO ID of the CPO that 'owns' this CDR (following the ISO-15118 standard). - * @property start_date_time Start timestamp of the charging session, or in-case of a reservation + * @property startDateTime Start timestamp of the charging session, or in-case of a reservation (before the start of a session) the start of the reservation. - * @property end_date_time The timestamp when the session was completed/finished, charging + * @property endDateTime The timestamp when the session was completed/finished, charging might have finished before the session ends, for example: EV is full, but parking cost also has to be paid. - * @property session_id (max-length=36) Unique ID of the Session for which this CDR is sent. Is only allowed + * @property sessionId (max-length=36) Unique ID of the Session for which this CDR is sent. Is only allowed to be omitted when the CPO has not implemented the Sessions module or this CDR is the result of a reservation that never became a charging session, thus no OCPI Session. - * @property cdr_token Token used to start this charging session, includes all the relevant + * @property cdrToken Token used to start this charging session, includes all the relevant information to identify the unique token. - * @property auth_method Method used for authentication. - * @property authorization_reference (max-length=36) Reference to the authorization given by the eMSP. When the eMSP + * @property authMethod Method used for authentication. + * @property authorizationReference (max-length=36) Reference to the authorization given by the eMSP. When the eMSP provided an authorization_reference in either: real-time authorization or StartSession, this field SHALL contain the same value. When different authorization_reference values have been given by the eMSP that are relevant to this Session, the last given value SHALL be used here. - * @property cdr_location Location where the charging session took place, including only the + * @property cdrLocation Location where the charging session took place, including only the relevant EVSE and Connector. - * @property meter_id (max-length=255) Identification of the Meter inside the Charge Point. + * @property meterId (max-length=255) Identification of the Meter inside the Charge Point. * @property currency (max-length=3) Currency of the CDR in ISO 4217 Code. * @property tariffs List of relevant Tariff Elements, see: Tariff. When relevant, a Free of Charge tariff should also be in this list, and point to a defined Free of Charge Tariff. - * @property charging_periods List of Charging Periods that make up this charging session. A + * @property chargingPeriods List of Charging Periods that make up this charging session. A session consists of 1 or more periods, where each period has a different relevant Tariff. - * @property signed_data Signed data that belongs to this charging Session - * @property total_cost Total sum of all the costs of this transaction in the specified + * @property signedData Signed data that belongs to this charging Session + * @property totalCost Total sum of all the costs of this transaction in the specified currency - * @property total_fixed_cost Total sum of all the fixed costs in the specified currency, except + * @property totalFixedCost Total sum of all the fixed costs in the specified currency, except fixed price components of parking and reservation. The cost not depending on amount of time/energy used etc. Can contain costs like a start tariff. - * @property total_energy Total energy charged, in kWh - * @property total_energy_cost Total sum of all the cost of all the energy used, in the specified + * @property totalEnergy Total energy charged, in kWh + * @property totalEnergyCost Total sum of all the cost of all the energy used, in the specified currency - * @property total_time Total duration of the charging session (including the duration of + * @property totalTime Total duration of the charging session (including the duration of charging and not charging), in hours - * @property total_time_cost Total sum of all the cost related to duration of charging during this + * @property totalTimeCost Total sum of all the cost related to duration of charging during this transaction, in the specified currency. - * @property total_parking_time Total duration of the charging session where the EV was not + * @property totalParkingTime Total duration of the charging session where the EV was not charging (no energy was transferred between EVSE and EV), in hours. - * @property total_parking_cost Total sum of all the cost related to parking of this transaction, + * @property totalParkingCost Total sum of all the cost related to parking of this transaction, including fixed price components, in the specified currency. - * @property total_reservation_cost Total sum of all the cost related to a reservation of a Charge Point, + * @property totalReservationCost Total sum of all the cost related to a reservation of a Charge Point, including fixed price components, in the specified currency. * @property remark (max-length=255) Optional remark, can be used to provide additional human readable information to the CDR, for example: reason why a transaction was stopped. - * @property invoice_reference_id (max-length=39) This field can be used to reference an invoice, that will later be send + * @property invoiceReferenceId (max-length=39) This field can be used to reference an invoice, that will later be send for this CDR. Making it easier to link a CDR to a given invoice. Maybe even group CDRs that will be on the same invoice. * @property credit ? When set to true, this is a Credit CDR, and the field credit_reference_id needs to be set as well. - * @property credit_reference_id (max-length=39) Is required to be set for a Credit CDR. This SHALL contain the id + * @property creditReferenceId (max-length=39) Is required to be set for a Credit CDR. This SHALL contain the id of the CDR for which this is a Credit CDR. - * @property last_updated Timestamp when this CDR was last updated (or created). + * @property lastUpdated Timestamp when this CDR was last updated (or created). */ @Partial data class Cdr( val id: CiString, - val country_code: CiString, - val party_id: CiString, - val start_date_time: Instant, - val end_date_time: Instant, - val session_id: CiString? = null, - val cdr_token: CdrToken, - val auth_method: AuthMethod, - val authorization_reference: String? = null, - val cdr_location: CdrLocation, - val meter_id: String? = null, + val countryCode: CiString, + val partyId: CiString, + val startDateTime: Instant, + val endDateTime: Instant, + val sessionId: CiString? = null, + val cdrToken: CdrToken, + val authMethod: AuthMethod, + val authorizationReference: String? = null, + val cdrLocation: CdrLocation, + val meterId: String? = null, val currency: String, val tariffs: List, - val charging_periods: List, - val signed_data: SignedData? = null, - val total_cost: Price, - val total_fixed_cost: Price? = null, - val total_energy: BigDecimal, - val total_energy_cost: Price? = null, - val total_time: BigDecimal, - val total_time_cost: Price? = null, - val total_parking_time: BigDecimal? = null, - val total_parking_cost: Price? = null, - val total_reservation_cost: Price? = null, + val chargingPeriods: List, + val signedData: SignedData? = null, + val totalCost: Price, + val totalFixedCost: Price? = null, + val totalEnergy: BigDecimal, + val totalEnergyCost: Price? = null, + val totalTime: BigDecimal, + val totalTimeCost: Price? = null, + val totalParkingTime: BigDecimal? = null, + val totalParkingCost: Price? = null, + val totalReservationCost: Price? = null, val remark: String? = null, - val invoice_reference_id: CiString? = null, + val invoiceReferenceId: CiString? = null, val credit: Boolean? = null, - val credit_reference_id: CiString? = null, - val last_updated: Instant + val creditReferenceId: CiString? = null, + val lastUpdated: Instant ) diff --git a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/cdr/domain/CdrDimensionType.kt b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/cdr/domain/CdrDimensionType.kt index 3e86bce5..ac5f4963 100644 --- a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/cdr/domain/CdrDimensionType.kt +++ b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/cdr/domain/CdrDimensionType.kt @@ -1,6 +1,5 @@ package com.izivia.ocpi.toolkit.modules.cdr.domain - /** * This enumeration contains allowed values for CdrDimensions, which are used to define dimensions of ChargingPeriods in both CDRs and Sessions. Some of these values are not useful for CDRs, and SHALL therefor only be used in Sessions, these are @@ -11,13 +10,13 @@ enum class CdrDimensionType { /** * Session Only. * Average charging current during this ChargingPeriod: defined in A (Ampere). When - negative, the current is flowing from the EV to the grid. + negative, the current is flowing from the EV to the grid. */ CURRENT, /** *Total amount of energy (dis-)charged during this ChargingPeriod: defined in kWh. When - negative, more energy was feed into the grid then charged into the EV. Default step_size is 1. + negative, more energy was feed into the grid then charged into the EV. Default step_size is 1. */ ENERGY, @@ -35,13 +34,13 @@ enum class CdrDimensionType { /** * Sum of the maximum current over all phases, reached during this ChargingPeriod: defined - in A (Ampere). + in A (Ampere). */ MAX_CURRENT, /** * Sum of the minimum current over all phases, reached during this ChargingPeriod, when - negative, current has flowed from the EV to the grid. Defined in A (Ampere). + negative, current has flowed from the EV to the grid. Defined in A (Ampere). */ MIN_CURRENT, @@ -52,26 +51,26 @@ enum class CdrDimensionType { /** * Minimum power reached during this ChargingPeriod: defined in kW (Kilowatt), when - negative, the power has flowed from the EV to the grid. + negative, the power has flowed from the EV to the grid. */ MIN_POWER, /** * Time during this ChargingPeriod not charging: defined in hours, default step_size multiplier - is 1 second. + is 1 second. */ PARKING_TIME, /** * Session Only. * Average power during this ChargingPeriod: defined in kW (Kilowatt). When negative, the - power is flowing from the EV to the grid. + power is flowing from the EV to the grid. */ POWER, /** * Time during this ChargingPeriod Charge Point has been reserved and not yet been in use - for this customer: defined in hours, default step_size multiplier is 1 second. + for this customer: defined in hours, default step_size multiplier is 1 second. */ RESERVATION_TIME, @@ -83,7 +82,7 @@ enum class CdrDimensionType { /** * Time charging during this ChargingPeriod: defined in hours, default step_size multiplier is 1 - second. + second. */ TIME } diff --git a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/cdr/domain/CdrLocation.kt b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/cdr/domain/CdrLocation.kt index 88e74ced..f1765cd3 100644 --- a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/cdr/domain/CdrLocation.kt +++ b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/cdr/domain/CdrLocation.kt @@ -5,7 +5,6 @@ import com.izivia.ocpi.toolkit.modules.locations.domain.ConnectorFormat import com.izivia.ocpi.toolkit.modules.locations.domain.ConnectorType import com.izivia.ocpi.toolkit.modules.locations.domain.PowerType - /** * The CdrLocation class contains only the relevant information from the Location object that is needed in a CDR. * @property id Uniquely identifies the location within the CPO’s platform (and suboperator @@ -13,20 +12,20 @@ platforms). This field can never be changed, modified or renamed. * @property name Display name of the location. * @property address Street/block name and house number if available * @property city City or town - * @property postal_code Postal code of the location. + * @property postalCode Postal code of the location. * @property country ISO 3166-1 alpha-3 code for the country of this location. * @property coordinates Coordinates of the location. - * @property evse_uid Uniquely identifies the EVSE within the CPO’s platform (and suboperator + * @property evseUid Uniquely identifies the EVSE within the CPO’s platform (and suboperator platforms). For example a database unique ID or the actual EVSE ID. This field can never be changed, modified or renamed. This is the technical identification of the EVSE, not to be used as human readable identification, use the field: evse_id for that. - * @property evse_id Compliant with the following specification for EVSE ID from "eMI3 standard + * @property evseId Compliant with the following specification for EVSE ID from "eMI3 standard version V1.0" (http://emi3group.com/documents-links/) "Part 2: business objects.". - * @property connector_id Identifier of the connector within the EVSE. - * @property connector_standard The standard of the installed connector. - * @property connector_format The format (socket/cable) of the installed connector. + * @property connectorId Identifier of the connector within the EVSE. + * @property connectorStandard The standard of the installed connector. + * @property connectorFormat The format (socket/cable) of the installed connector. * */ data class CdrLocation( @@ -34,13 +33,13 @@ data class CdrLocation( val name: String? = null, val address: String, val city: String, - val postal_code: String, + val postalCode: String, val country: String, val coordinates: String, - val evse_uid: CiString, - val evse_id: CiString, - val connector_id: CiString, - val connector_standard: ConnectorType, - val connector_format: ConnectorFormat, - val connector_power_type: PowerType, + val evseUid: CiString, + val evseId: CiString, + val connectorId: CiString, + val connectorStandard: ConnectorType, + val connectorFormat: ConnectorFormat, + val connectorPowerType: PowerType ) diff --git a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/cdr/domain/CdrToken.kt b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/cdr/domain/CdrToken.kt index 34c5e6b3..8666b489 100644 --- a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/cdr/domain/CdrToken.kt +++ b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/cdr/domain/CdrToken.kt @@ -4,24 +4,23 @@ import com.izivia.ocpi.toolkit.annotations.Partial import com.izivia.ocpi.toolkit.common.CiString import com.izivia.ocpi.toolkit.modules.tokens.domain.TokenType - /** - * @property country_code (max-length=2) ISO-3166 alpha-2 country code of the MSP that 'owns' this Token. - * @property party_id (max-length=3) ID of the eMSP that 'owns' this Token (following the ISO-15118 standard). + * @property countryCode (max-length=2) ISO-3166 alpha-2 country code of the MSP that 'owns' this Token. + * @property partyId (max-length=3) ID of the eMSP that 'owns' this Token (following the ISO-15118 standard). * @property uid (max-length=36) Unique ID by which this Token can be identified. * This is the field used by the CPO’s system (RFID reader on the Charge Point) to identify this token. * Currently, in most cases: type=RFID, this is the RFID hidden ID as read by the RFID reader, but that is not a requirement. * If this is a type=APP_USER Token, it will be a unique, by the eMSP, generated ID. * @property type Type of the token - * @property contract_id (max-length=36) Uniquely identifies the EV driver contract token within the eMSP’s platform (and + * @property contractId (max-length=36) Uniquely identifies the EV driver contract token within the eMSP’s platform (and * suboperator platforms). Recommended to follow the specification for eMA ID from "eMI3 standard version V1.0" * (http://emi3group.com/documents-links/) "Part 2: business objects." */ @Partial data class CdrToken( - val country_code: CiString, - val party_id: CiString, + val countryCode: CiString, + val partyId: CiString, val uid: CiString, val type: TokenType, - val contract_id: CiString, + val contractId: CiString ) diff --git a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/cdr/domain/ChargingPeriod.kt b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/cdr/domain/ChargingPeriod.kt index bcd64f4c..be70397d 100644 --- a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/cdr/domain/ChargingPeriod.kt +++ b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/cdr/domain/ChargingPeriod.kt @@ -7,17 +7,16 @@ import java.time.Instant /** * A Charging Period consists of a start timestamp and a list of possible values that influence this period, for example: amount of energy charged this period, maximum current during this period etc. - *@property start_date_time Start timestamp of the charging period. A period ends when the next period + * @property startDateTime Start timestamp of the charging period. A period ends when the next period starts. The last period ends when the session ends. - *@property dimensions List of relevant values for this charging period. - *@property tariff_id Unique identifier of the Tariff that is relevant for this Charging Period. If not + * @property dimensions List of relevant values for this charging period. + * @property tariffId Unique identifier of the Tariff that is relevant for this Charging Period. If not provided, no Tariff is relevant during this period. * */ @Partial data class ChargingPeriod( - val start_date_time: Instant, + val startDateTime: Instant, val dimensions: List, - val tariff_id: CiString? = null + val tariffId: CiString? = null ) - diff --git a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/cdr/domain/SignedData.kt b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/cdr/domain/SignedData.kt index f177ba04..7876cfa7 100644 --- a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/cdr/domain/SignedData.kt +++ b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/cdr/domain/SignedData.kt @@ -3,24 +3,23 @@ package com.izivia.ocpi.toolkit.modules.cdr.domain import com.izivia.ocpi.toolkit.annotations.Partial import com.izivia.ocpi.toolkit.common.CiString - /** * This class contains all the information of the signed data. Which encoding method is used, if needed, the public key and a list of signed values. - * @property encoding_method The name of the encoding used in the SignedData field. This is the + * @property encodingMethod The name of the encoding used in the SignedData field. This is the name given to the encoding by a company or group of companies. See note below. - * @property encoding_method_version Version of the EncodingMethod (when applicable) - * @property public_key Public key used to sign the data, base64 encoded. - * @property signed_values One or more signed values. + * @property encodingMethodVersion Version of the EncodingMethod (when applicable) + * @property publicKey Public key used to sign the data, base64 encoded. + * @property signedValues One or more signed values. * @property url URL that can be shown to an EV driver. This URL gives the EV driver the possibility to check the signed data from a charging session. */ @Partial data class SignedData( - val encoding_method: CiString, - val encoding_method_version: Int, - val public_key: CiString? = null, - val signed_values: List, - val url: CiString? = null, + val encodingMethod: CiString, + val encodingMethodVersion: Int, + val publicKey: CiString? = null, + val signedValues: List, + val url: CiString? = null ) diff --git a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/cdr/domain/SignedValue.kt b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/cdr/domain/SignedValue.kt index 50d427c3..3afd408f 100644 --- a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/cdr/domain/SignedValue.kt +++ b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/cdr/domain/SignedValue.kt @@ -12,14 +12,14 @@ Possible values at moment of writing: - End (signed value at the end of the Session) - Intermediate (signed values take during the Session, after Start, before End) Others might be added later. - * @property plain_data The unencoded string of data. The format of the content depends on the + * @property plainData The unencoded string of data. The format of the content depends on the EncodingMethod field. - * @property signed_data Blob of signed data, base64 encoded. The format of the content depends on the + * @property signedData Blob of signed data, base64 encoded. The format of the content depends on the EncodingMethod field. */ @Partial data class SignedValue( val nature: CiString, - val plain_data: CiString, - val signed_data: CiString + val plainData: CiString, + val signedData: CiString ) diff --git a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/credentials/CredentialsInterface.kt b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/credentials/CredentialsInterface.kt index 3a1bc373..dd7decc1 100644 --- a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/credentials/CredentialsInterface.kt +++ b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/credentials/CredentialsInterface.kt @@ -5,7 +5,7 @@ import com.izivia.ocpi.toolkit.modules.credentials.domain.Credentials /** * The Credentials module is different from all other OCPI modules. This module is symmetric, it has to be implemented - * by all OCPI implementations, and all implementations need to be able call this module on any other platform, and have + * by all OCPI implementations, and all implementations need to be able call this module on any other partner, and have * to be able the handle receiving the request from another party. */ interface CredentialsInterface { @@ -29,7 +29,7 @@ interface CredentialsInterface { * before. */ suspend fun post( - tokenA: String, + token: String, credentials: Credentials, debugHeaders: Map ): OcpiResponseBody diff --git a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/credentials/CredentialsServer.kt b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/credentials/CredentialsServer.kt index 8db9eb1b..c0225f7c 100644 --- a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/credentials/CredentialsServer.kt +++ b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/credentials/CredentialsServer.kt @@ -30,7 +30,7 @@ class CredentialsServer( ) { req -> req.httpResponse { service.post( - tokenA = req.parseAuthorizationHeader(), + token = req.parseAuthorizationHeader(), credentials = mapper.readValue(req.body!!, Credentials::class.java), debugHeaders = req.getDebugHeaders() ) diff --git a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/credentials/domain/BusinessDetails.kt b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/credentials/domain/BusinessDetails.kt index 47dc4bcf..63ea1846 100644 --- a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/credentials/domain/BusinessDetails.kt +++ b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/credentials/domain/BusinessDetails.kt @@ -9,4 +9,4 @@ data class BusinessDetails( val name: String, val website: String?, val logo: Image? -) \ No newline at end of file +) diff --git a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/credentials/domain/CredentialRole.kt b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/credentials/domain/CredentialRole.kt index 911f54e5..f650b565 100644 --- a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/credentials/domain/CredentialRole.kt +++ b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/credentials/domain/CredentialRole.kt @@ -4,13 +4,13 @@ import com.izivia.ocpi.toolkit.common.CiString /** * @property role Type of role - * @property business_details Details of this party - * @property party_id CPO, eMSP (or other role) ID of this party (following the ISO-15118 standard). - * @property country_code ISO-3166 alpha-2 country code of the country this party is operating in. + * @property businessDetails Details of this party + * @property partyId CPO, eMSP (or other role) ID of this party (following the ISO-15118 standard). + * @property countryCode ISO-3166 alpha-2 country code of the country this party is operating in. */ data class CredentialRole( val role: Role, - val business_details: BusinessDetails, - val party_id: CiString, - val country_code: CiString + val businessDetails: BusinessDetails, + val partyId: CiString, + val countryCode: CiString ) diff --git a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/credentials/domain/Credentials.kt b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/credentials/domain/Credentials.kt index ba8888c7..a620fc25 100644 --- a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/credentials/domain/Credentials.kt +++ b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/credentials/domain/Credentials.kt @@ -3,7 +3,7 @@ package com.izivia.ocpi.toolkit.modules.credentials.domain /** * Every role needs a unique combination of: role, party_id and country_code. * - * A platform can have the same role more than once, each with its own unique party_id and country_code, for example + * A partner can have the same role more than once, each with its own unique party_id and country_code, for example * when a CPO provides 'white-label' services for 'virtual' CPOs. * * One or more roles and thus party_id and country_code sets are provided here to inform a server about the party_id and @@ -22,7 +22,7 @@ package com.izivia.ocpi.toolkit.modules.credentials.domain * from the OCPI party_id and/or the country_code. * * A Hub SHALL only reports itself as role: Hub. A Hub SHALL NOT report all the other connected parties as a role on the - * platform. A Hub SHALL report connected parties via the HubClientInfo module. + * partner. A Hub SHALL report connected parties via the HubClientInfo module. * * @property token Case Sensitive, ASCII only. The credentials token for the other party to authenticate in your system. * Not encoded in Base64 or any other encoding. diff --git a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/credentials/domain/Image.kt b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/credentials/domain/Image.kt index c7ee3152..6d6c5695 100644 --- a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/credentials/domain/Image.kt +++ b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/credentials/domain/Image.kt @@ -32,4 +32,4 @@ data class Image( val type: CiString, val width: Int?, val height: Int? -) \ No newline at end of file +) diff --git a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/credentials/domain/ImageCategory.kt b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/credentials/domain/ImageCategory.kt index 304b6f46..0d3e7abd 100644 --- a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/credentials/domain/ImageCategory.kt +++ b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/credentials/domain/ImageCategory.kt @@ -41,5 +41,5 @@ enum class ImageCategory { * Logo of the charge points owner, for example a local store, to be displayed with the EVSEs detailed information * view */ - OWNER, -} \ No newline at end of file + OWNER +} diff --git a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/credentials/domain/Role.kt b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/credentials/domain/Role.kt index cd01d504..a71519de 100644 --- a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/credentials/domain/Role.kt +++ b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/credentials/domain/Role.kt @@ -35,4 +35,4 @@ enum class Role { * Smart Charging Service Provider Role */ SCSP -} \ No newline at end of file +} diff --git a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/credentials/repositories/PlatformRepository.kt b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/credentials/repositories/PartnerRepository.kt similarity index 58% rename from ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/credentials/repositories/PlatformRepository.kt rename to ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/credentials/repositories/PartnerRepository.kt index 144c1ee5..0ee642bc 100644 --- a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/credentials/repositories/PlatformRepository.kt +++ b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/credentials/repositories/PartnerRepository.kt @@ -1,5 +1,6 @@ package com.izivia.ocpi.toolkit.modules.credentials.repositories +import com.izivia.ocpi.toolkit.modules.credentials.domain.CredentialRole import com.izivia.ocpi.toolkit.modules.versions.domain.Endpoint import com.izivia.ocpi.toolkit.modules.versions.domain.Version @@ -20,7 +21,7 @@ import com.izivia.ocpi.toolkit.modules.versions.domain.Version * you have to use a different token. Using "Client Token" and "Server Token" simplifies that process of picking the * right token for the right operation. */ -interface PlatformRepository { +interface PartnerRepository { /** * When calling a partner, the http client has to be authenticated. This method is called to retrieve the @@ -28,19 +29,19 @@ interface PlatformRepository { * * The token A is only used during registration process. * - * @param platformUrl the partner, identified by its /versions url + * @param partnerUrl the partner, identified by its /versions url * @return the token A, if found, null otherwise */ - suspend fun getCredentialsTokenA(platformUrl: String): String? + suspend fun getCredentialsTokenA(partnerUrl: String): String? /** * When calling a partner, the http client has to be authenticated. This method is called to retrieve the * client token for a given partner identified by its /versions url. * - * @param platformUrl the partner, identified by its /versions url + * @param partnerUrl the partner, identified by its /versions url * @return the client token, if found, null otherwise */ - suspend fun getCredentialsClientToken(platformUrl: String): String? + suspend fun getCredentialsClientToken(partnerUrl: String): String? /** * A partner has to use its server token to communicate with us. On first registration, the token used is the token @@ -61,76 +62,85 @@ interface PlatformRepository { suspend fun isCredentialsServerTokenValid(credentialsServerToken: String): Boolean /** - * Used to find a platform url by its server token. Basically used to retrieve all the partner information + * Used to find a partner url by its server token. Basically used to retrieve all the partner information * from the token in a request. * * @param credentialsServerToken the server token, the one partners use to communicate - * @return the platform url + * @return the partner url */ - suspend fun getPlatformUrlByCredentialsServerToken(credentialsServerToken: String): String? + suspend fun getPartnerUrlByCredentialsServerToken(credentialsServerToken: String): String? /** - * Used to get available endpoints for a given partner identified by its url (platformUrl) + * Used to get available endpoints for a given partner identified by its url (partnerUrl) * - * @param platformUrl the partner, identified by its /versions url + * @param partnerUrl the partner, identified by its /versions url * @return the list of available endpoints for the given partner */ - suspend fun getEndpoints(platformUrl: String): List + suspend fun getEndpoints(partnerUrl: String): List /** - * Used to get used version for a given partner identified by its url (platformUrl) + * Used to get used version for a given partner identified by its url (partnerUrl) * - * @param platformUrl the partner, identified by its /versions url + * @param partnerUrl the partner, identified by its /versions url * @return the currently used version for the given partner or null */ - suspend fun getVersion(platformUrl: String): Version? + suspend fun getVersion(partnerUrl: String): Version? /** - * This is the first function to be called on registration. So that later on we can use platform url as an + * This is the first function to be called on registration. So that later on we can use partner url as an * identifier for a given partner. * - * It searches for a platform with the given token A and saves the corresponding platformUrl + * It searches for a partner with the given token A and saves the corresponding partnerUrl * * @param tokenA - * @param platformUrl the partner, identified by its /versions url - * @return the platformUrl if a platform was found for given token A and the update was a success, null otherwise + * @param partnerUrl the partner, identified by its /versions url + * @return the partnerUrl if a partner was found for given token A and the update was a success, null otherwise */ - suspend fun savePlatformUrlForTokenA(tokenA: String, platformUrl: String): String? + suspend fun savePartnerUrlForTokenA(tokenA: String, partnerUrl: String): String? /** - * Used to save available version for a given partner identified by its url (platformUrl) + * Used to save credentials roles given by a partner during registration. * - * @param platformUrl the partner, identified by its /versions url + * @param partnerUrl the partner, identified by its /versions url + * @param credentialsRoles + * @return the updated credentials roles + */ + suspend fun saveCredentialsRoles(partnerUrl: String, credentialsRoles: List): List + + /** + * Used to save available version for a given partner identified by its url (partnerUrl) + * + * @param partnerUrl the partner, identified by its /versions url * @param version Version * @return the updated version */ - suspend fun saveVersion(platformUrl: String, version: Version): Version + suspend fun saveVersion(partnerUrl: String, version: Version): Version /** - * Used to save endpoints for a given partner identified by its url (platformUrl) + * Used to save endpoints for a given partner identified by its url (partnerUrl) * - * @param platformUrl the partner, identified by its /versions url + * @param partnerUrl the partner, identified by its /versions url * @param endpoints List * @return List the updated list of endpoints */ - suspend fun saveEndpoints(platformUrl: String, endpoints: List): List + suspend fun saveEndpoints(partnerUrl: String, endpoints: List): List /** - * Called to save the client token for a given partner identified by its url (platformUrl). + * Called to save the client token for a given partner identified by its url (partnerUrl). * * This token is the one that will be used to communicate with the partner. * For context in OCPI, on registration, this token is: * - if you are the receiver: token B * - if you are the sender: token C * - * @param platformUrl the partner, identified by its /versions url + * @param partnerUrl the partner, identified by its /versions url * @param credentialsClientToken String * @return the credentialsClientToken */ - suspend fun saveCredentialsClientToken(platformUrl: String, credentialsClientToken: String): String + suspend fun saveCredentialsClientToken(partnerUrl: String, credentialsClientToken: String): String /** - * Called to save the server token for a given partner identified by its url (platformUrl). + * Called to save the server token for a given partner identified by its url (partnerUrl). * * This token is the one that the partner will use to communicate. So it is this token that has to be used to check * if requests are properly authenticated. @@ -139,29 +149,40 @@ interface PlatformRepository { * - if you are the receiver: token C * - if you are the sender: token B * - * @param platformUrl the partner, identified by its /versions url + * @param partnerUrl the partner, identified by its /versions url * @param credentialsServerToken String * @return the credentialsServerToken */ - suspend fun saveCredentialsServerToken(platformUrl: String, credentialsServerToken: String): String + suspend fun saveCredentialsServerToken(partnerUrl: String, credentialsServerToken: String): String /** - * Called once registration is done for a given partner identified by its url (platformUrl). + * Called once registration is done for a given partner identified by its url (partnerUrl). * * The token A has to be invalidated. * - * @param platformUrl the partner, identified by its /versions url + * @param partnerUrl the partner, identified by its /versions url + * @return true if it was a success, false otherwise + */ + suspend fun invalidateCredentialsTokenA(partnerUrl: String): Boolean + + /** + * Called when a partner asks to unregister itself. + * + * It has to invalidate **ONLY clientToken**. ServerToken must stay valid because the partner can still use it. + * + * @param partnerUrl the partner, identified by its /versions url * @return true if it was a success, false otherwise */ - suspend fun invalidateCredentialsTokenA(platformUrl: String): Boolean + suspend fun invalidateCredentialsClientToken(partnerUrl: String): Boolean /** - * Called on unregistration for a given partner identified by its url (platformUrl). + * Called when your system unregisters from a partner. * - * It has to at least invalidate all the tokens. So that future requests with those token fail. + * It has to invalidate **ONLY serverToken**. ClientToken must stay valid because your system can still use it + * to communicate with the partner. * - * @param platformUrl the partner, identified by its /versions url + * @param partnerUrl the partner, identified by its /versions url * @return true if it was a success, false otherwise */ - suspend fun unregisterPlatform(platformUrl: String): Boolean + suspend fun invalidateCredentialsServerToken(partnerUrl: String): Boolean } diff --git a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/credentials/services/CredentialsClientService.kt b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/credentials/services/CredentialsClientService.kt index fb7902ec..1a89c8be 100644 --- a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/credentials/services/CredentialsClientService.kt +++ b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/credentials/services/CredentialsClientService.kt @@ -4,7 +4,7 @@ import com.izivia.ocpi.toolkit.common.* import com.izivia.ocpi.toolkit.modules.credentials.CredentialsClient import com.izivia.ocpi.toolkit.modules.credentials.domain.Credentials import com.izivia.ocpi.toolkit.modules.credentials.repositories.CredentialsRoleRepository -import com.izivia.ocpi.toolkit.modules.credentials.repositories.PlatformRepository +import com.izivia.ocpi.toolkit.modules.credentials.repositories.PartnerRepository import com.izivia.ocpi.toolkit.modules.versions.VersionDetailsClient import com.izivia.ocpi.toolkit.modules.versions.VersionsClient import com.izivia.ocpi.toolkit.modules.versions.domain.Endpoint @@ -16,14 +16,14 @@ import com.izivia.ocpi.toolkit.transport.TransportClientBuilder /** * Automates authentification process * - * Note: credentialsClient & versionsClient must target the same platform since the automated process will check the + * Note: credentialsClient & versionsClient must target the same partner since the automated process will check the * versions of the receiver before performing registration. * * - Client: the one doing the registration process * - Server: the one receiving the registration process * * @property clientVersionsEndpointUrl the versions endpoints url of the client (for the server to use) - * @property clientPlatformRepository client's repository to store and retrieve tokens and information about platforms + * @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) @@ -31,27 +31,27 @@ import com.izivia.ocpi.toolkit.transport.TransportClientBuilder */ class CredentialsClientService( private val clientVersionsEndpointUrl: String, - private val clientPlatformRepository: PlatformRepository, + private val clientPartnerRepository: PartnerRepository, private val clientVersionsRepository: VersionsRepository, private val clientCredentialsRoleRepository: CredentialsRoleRepository, private val serverVersionsEndpointUrl: String, private val transportClientBuilder: TransportClientBuilder ) { - suspend fun get(): Credentials = clientPlatformRepository - .getCredentialsClientToken(platformUrl = serverVersionsEndpointUrl) + suspend fun get(): Credentials = clientPartnerRepository + .getCredentialsClientToken(partnerUrl = serverVersionsEndpointUrl) ?.let { clientToken -> buildCredentialClient() .get(token = clientToken) .let { it.data ?: throw OcpiResponseException(it.status_code, it.status_message ?: "unknown") } } ?: throw OcpiClientGenericException( - "Could not find CREDENTIALS_TOKEN_C associated with platform $serverVersionsEndpointUrl" + "Could not find CREDENTIALS_TOKEN_C associated with partner $serverVersionsEndpointUrl" ) /** * To start using OCPI, the Platforms will need to exchange credentials tokens. * - * To start the exchange of credentials tokens, one platform has to be selected as Sender for the Credentials + * To start the exchange of credentials tokens, one partner has to be selected as Sender for the Credentials * module. This has to be decided between the Platforms (outside of OCPI) before they first connect. * * To start the credentials exchange, the Receiver Platform must create a unique credentials token: @@ -75,17 +75,19 @@ class CredentialsClientService( */ suspend fun register(): Credentials { // Get token provided by receiver outside the OCPI protocol (for example by an admin) - val credentialsTokenA = clientPlatformRepository.getCredentialsTokenA(platformUrl = serverVersionsEndpointUrl) - ?: throw OcpiClientInvalidParametersException( - "Could not find token A associated with platform $serverVersionsEndpointUrl" - ) + val credentialsTokenA = + clientPartnerRepository.getCredentialsClientToken(partnerUrl = serverVersionsEndpointUrl) + ?: clientPartnerRepository.getCredentialsTokenA(partnerUrl = serverVersionsEndpointUrl) + ?: throw OcpiClientInvalidParametersException( + "Could not find the TokenA or the ClientToken associated with partner $serverVersionsEndpointUrl" + ) findLatestMutualVersionAndSaveInformation() // Generate token B, which is the server token in this case because we are the sender. It's this token // that the receiver will use to contact us. - val serverToken = clientPlatformRepository.saveCredentialsServerToken( - platformUrl = serverVersionsEndpointUrl, + val serverToken = clientPartnerRepository.saveCredentialsServerToken( + partnerUrl = serverVersionsEndpointUrl, credentialsServerToken = generateUUIDv4Token() ) @@ -102,15 +104,21 @@ class CredentialsClientService( it.data ?: throw OcpiResponseException(it.status_code, it.status_message ?: "unknown") } + // Save credentials roles of partner + clientPartnerRepository.saveCredentialsRoles( + partnerUrl = credentials.url, + credentialsRoles = credentials.roles + ) + // Store token C, which is the client token in this case because we are the sender. It's this one that // we will use to communicate with the receiver - clientPlatformRepository.saveCredentialsClientToken( - platformUrl = serverVersionsEndpointUrl, + clientPartnerRepository.saveCredentialsClientToken( + partnerUrl = serverVersionsEndpointUrl, credentialsClientToken = credentials.token ) // Remove token A because it is useless from now on - clientPlatformRepository.invalidateCredentialsTokenA(platformUrl = serverVersionsEndpointUrl) + clientPartnerRepository.invalidateCredentialsTokenA(partnerUrl = serverVersionsEndpointUrl) return credentials } @@ -118,17 +126,17 @@ class CredentialsClientService( suspend fun update(): Credentials { // Token to communicate with receiver val credentialsClientToken = - clientPlatformRepository.getCredentialsClientToken(platformUrl = serverVersionsEndpointUrl) + clientPartnerRepository.getCredentialsClientToken(partnerUrl = serverVersionsEndpointUrl) ?: throw OcpiClientInvalidParametersException( - "Could not find credentialsClientToken associated with platform $serverVersionsEndpointUrl" + "Could not find the ClientToken associated with partner $serverVersionsEndpointUrl" ) findLatestMutualVersionAndSaveInformation() // Generate token B, which is the server token, because it's the one that will be used by the partner (receiver) // to communicate with us - val credentialsServerToken = clientPlatformRepository.saveCredentialsServerToken( - platformUrl = serverVersionsEndpointUrl, + val credentialsServerToken = clientPartnerRepository.saveCredentialsServerToken( + partnerUrl = serverVersionsEndpointUrl, credentialsServerToken = generateUUIDv4Token() ) @@ -145,23 +153,31 @@ class CredentialsClientService( it.data ?: throw OcpiResponseException(it.status_code, it.status_message ?: "unknown") } + // Save credentials roles of partner + clientPartnerRepository.saveCredentialsRoles( + partnerUrl = credentials.url, + credentialsRoles = credentials.roles + ) + // Store token C, which is the client token in this case because we are the sender. It's this one that // we will use to communicate with the receiver - clientPlatformRepository.saveCredentialsClientToken( - platformUrl = serverVersionsEndpointUrl, + clientPartnerRepository.saveCredentialsClientToken( + partnerUrl = serverVersionsEndpointUrl, credentialsClientToken = credentials.token ) return credentials } - suspend fun delete() = clientPlatformRepository - .getCredentialsClientToken(platformUrl = serverVersionsEndpointUrl) + suspend fun delete() = clientPartnerRepository + .getCredentialsClientToken(partnerUrl = serverVersionsEndpointUrl) ?.let { clientToken -> buildCredentialClient() .delete(token = clientToken) .also { - clientPlatformRepository.unregisterPlatform(platformUrl = serverVersionsEndpointUrl) + // Only server token is invalidated. It means that the system can still send authenticated requests + // to the partner + clientPartnerRepository.invalidateCredentialsServerToken(partnerUrl = serverVersionsEndpointUrl) } .also { if (it.status_code != OcpiStatus.SUCCESS.code) { @@ -170,14 +186,14 @@ class CredentialsClientService( } } ?: throw OcpiClientGenericException( - "Could not find client token associated with platform $serverVersionsEndpointUrl" + "Could not find client token associated with partner $serverVersionsEndpointUrl" ) private suspend fun findLatestMutualVersionAndSaveInformation(): List { val availableServerVersions = VersionsClient( transportClientBuilder = transportClientBuilder, serverVersionsEndpointUrl = serverVersionsEndpointUrl, - platformRepository = clientPlatformRepository + partnerRepository = clientPartnerRepository ) .getVersions() .let { @@ -193,17 +209,17 @@ class CredentialsClientService( .any { clientVersion -> serverVersion.version == clientVersion.version } } ?: throw OcpiServerUnsupportedVersionException( - "Could not find mutual version with platform $serverVersionsEndpointUrl" + "Could not find mutual version with partner $serverVersionsEndpointUrl" ) // Store version that will be used - clientPlatformRepository.saveVersion(platformUrl = serverVersionsEndpointUrl, version = latestMutualVersion) + clientPartnerRepository.saveVersion(partnerUrl = serverVersionsEndpointUrl, version = latestMutualVersion) // Get available endpoints for a given version val versionDetails = VersionDetailsClient( transportClientBuilder = transportClientBuilder, serverVersionsEndpointUrl = serverVersionsEndpointUrl, - platformRepository = clientPlatformRepository + partnerRepository = clientPartnerRepository ) .getVersionDetails() .let { @@ -211,14 +227,14 @@ class CredentialsClientService( } // Store version & endpoint - return clientPlatformRepository.saveEndpoints( - platformUrl = serverVersionsEndpointUrl, + return clientPartnerRepository.saveEndpoints( + partnerUrl = serverVersionsEndpointUrl, endpoints = versionDetails.endpoints ) } - private suspend fun getOrFindEndpoints(): List = clientPlatformRepository - .getEndpoints(platformUrl = serverVersionsEndpointUrl) + private suspend fun getOrFindEndpoints(): List = clientPartnerRepository + .getEndpoints(partnerUrl = serverVersionsEndpointUrl) .takeIf { it.isNotEmpty() } ?: findLatestMutualVersionAndSaveInformation() diff --git a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/credentials/services/CredentialsServerService.kt b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/credentials/services/CredentialsServerService.kt index 55ec8f73..ab73f640 100644 --- a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/credentials/services/CredentialsServerService.kt +++ b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/credentials/services/CredentialsServerService.kt @@ -4,7 +4,7 @@ import com.izivia.ocpi.toolkit.common.* import com.izivia.ocpi.toolkit.modules.credentials.CredentialsInterface import com.izivia.ocpi.toolkit.modules.credentials.domain.Credentials import com.izivia.ocpi.toolkit.modules.credentials.repositories.CredentialsRoleRepository -import com.izivia.ocpi.toolkit.modules.credentials.repositories.PlatformRepository +import com.izivia.ocpi.toolkit.modules.credentials.repositories.PartnerRepository import com.izivia.ocpi.toolkit.modules.versions.domain.Version import com.izivia.ocpi.toolkit.modules.versions.domain.VersionDetails import com.izivia.ocpi.toolkit.modules.versions.domain.VersionNumber @@ -13,7 +13,7 @@ import com.izivia.ocpi.toolkit.transport.domain.HttpMethod import com.izivia.ocpi.toolkit.transport.domain.HttpRequest class CredentialsServerService( - private val platformRepository: PlatformRepository, + private val partnerRepository: PartnerRepository, private val credentialsRoleRepository: CredentialsRoleRepository, private val transportClientBuilder: TransportClientBuilder, private val serverVersionsUrlProvider: suspend () -> String @@ -28,31 +28,43 @@ class CredentialsServerService( } override suspend fun post( - tokenA: String, + token: String, credentials: Credentials, debugHeaders: Map ): OcpiResponseBody = OcpiResponseBody.of { - val platformUrl = platformRepository.savePlatformUrlForTokenA( - tokenA = tokenA, - platformUrl = credentials.url - ) ?: throw OcpiClientInvalidParametersException("Invalid token A ($tokenA)") + // 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) + val partnerUrl = 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" + ) + + // Save credentials roles of partner + partnerRepository.saveCredentialsRoles( + partnerUrl = credentials.url, + credentialsRoles = credentials.roles + ) // Save token B, which is in our case the client token, because it's the one that we will use to communicate // with the sender - platformRepository.saveCredentialsClientToken( - platformUrl = credentials.url, + partnerRepository.saveCredentialsClientToken( + partnerUrl = credentials.url, credentialsClientToken = credentials.token ) findLatestMutualVersionAndStoreInformation(credentials = credentials, debugHeaders = debugHeaders) // Remove token A because it is useless from now on - platformRepository.invalidateCredentialsTokenA(platformUrl = platformUrl) + partnerRepository.invalidateCredentialsTokenA(partnerUrl = partnerUrl) // Return Credentials objet to sender with the token C inside (which is for us the server token) getCredentials( - serverToken = platformRepository.saveCredentialsServerToken( - platformUrl = platformUrl, + serverToken = partnerRepository.saveCredentialsServerToken( + partnerUrl = partnerUrl, credentialsServerToken = generateUUIDv4Token() ) ) @@ -63,13 +75,19 @@ class CredentialsServerService( credentials: Credentials, debugHeaders: Map ): OcpiResponseBody = OcpiResponseBody.of { - val platformUrl = platformRepository.getPlatformUrlByCredentialsServerToken(token) + val partnerUrl = partnerRepository.getPartnerUrlByCredentialsServerToken(token) ?: throw OcpiClientInvalidParametersException("Invalid server token ($token)") + // Save credentials roles of partner + partnerRepository.saveCredentialsRoles( + partnerUrl = credentials.url, + credentialsRoles = credentials.roles + ) + // In the payload, there is the new token B (the client token for us) to use to communicate with the receiver, // so we save it - platformRepository.saveCredentialsClientToken( - platformUrl = credentials.url, + partnerRepository.saveCredentialsClientToken( + partnerUrl = credentials.url, credentialsClientToken = credentials.token ) @@ -78,8 +96,8 @@ class CredentialsServerService( // Return Credentials objet to sender with the updated token C inside (which is for us the server token) getCredentials( - serverToken = platformRepository.saveCredentialsServerToken( - platformUrl = platformUrl, + serverToken = partnerRepository.saveCredentialsServerToken( + partnerUrl = partnerUrl, credentialsServerToken = generateUUIDv4Token() ) ) @@ -88,10 +106,12 @@ class CredentialsServerService( override suspend fun delete( token: String ): OcpiResponseBody = OcpiResponseBody.of { - platformRepository - .getPlatformUrlByCredentialsServerToken(token) - ?.also { platformUrl -> - platformRepository.unregisterPlatform(platformUrl = platformUrl) + partnerRepository + .getPartnerUrlByCredentialsServerToken(token) + ?.also { partnerUrl -> + // Only client token is invalidated. It means that the partner can still send authenticated requests + // to the system. + partnerRepository.invalidateCredentialsClientToken(partnerUrl = partnerUrl) } ?: throw OcpiClientInvalidParametersException("Invalid server token ($token)") @@ -125,7 +145,7 @@ class CredentialsServerService( val matchingVersion = versions.firstOrNull { it.version == VersionNumber.V2_2_1.value } ?: throw OcpiServerNoMatchingEndpointsException("Expected version 2.2.1 from $versions") - platformRepository.saveVersion(platformUrl = credentials.url, version = matchingVersion) + partnerRepository.saveVersion(partnerUrl = credentials.url, version = matchingVersion) val versionDetail = transportClientBuilder .build(matchingVersion.url) @@ -147,7 +167,7 @@ class CredentialsServerService( ) } - platformRepository.saveEndpoints(platformUrl = credentials.url, endpoints = versionDetail.endpoints) + partnerRepository.saveEndpoints(partnerUrl = credentials.url, endpoints = versionDetail.endpoints) } private suspend fun getCredentials(serverToken: String): Credentials = Credentials( diff --git a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/LocationsCpoClient.kt b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/LocationsCpoClient.kt index 785a2c39..32d54e31 100644 --- a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/LocationsCpoClient.kt +++ b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/LocationsCpoClient.kt @@ -1,7 +1,7 @@ package com.izivia.ocpi.toolkit.modules.locations import com.izivia.ocpi.toolkit.common.* -import com.izivia.ocpi.toolkit.modules.credentials.repositories.PlatformRepository +import com.izivia.ocpi.toolkit.modules.credentials.repositories.PartnerRepository import com.izivia.ocpi.toolkit.modules.locations.domain.* import com.izivia.ocpi.toolkit.modules.versions.domain.ModuleID import com.izivia.ocpi.toolkit.transport.TransportClient @@ -12,20 +12,20 @@ import com.izivia.ocpi.toolkit.transport.domain.HttpRequest /** * Sends calls to an eMSP server * @property transportClientBuilder used to build transport client - * @property serverVersionsEndpointUrl used to know which platform to communicate with - * @property platformRepository used to get information about the platform (endpoint, token) + * @property serverVersionsEndpointUrl used to know which partner to communicate with + * @property partnerRepository used to get information about the partner (endpoint, token) */ class LocationsCpoClient( private val transportClientBuilder: TransportClientBuilder, private val serverVersionsEndpointUrl: String, - private val platformRepository: PlatformRepository + private val partnerRepository: PartnerRepository ) : LocationsEmspInterface { private suspend fun buildTransport(): TransportClient = transportClientBuilder .buildFor( module = ModuleID.locations, - platformUrl = serverVersionsEndpointUrl, - platformRepository = platformRepository + partnerUrl = serverVersionsEndpointUrl, + partnerRepository = partnerRepository ) override suspend fun getLocation( @@ -42,7 +42,7 @@ class LocationsCpoClient( requestId = generateRequestId(), correlationId = generateCorrelationId() ) - .authenticate(platformRepository = platformRepository, platformUrl = serverVersionsEndpointUrl) + .authenticate(partnerRepository = partnerRepository, partnerUrl = serverVersionsEndpointUrl) ) .parseBody() } @@ -62,7 +62,7 @@ class LocationsCpoClient( requestId = generateRequestId(), correlationId = generateCorrelationId() ) - .authenticate(platformRepository = platformRepository, platformUrl = serverVersionsEndpointUrl) + .authenticate(partnerRepository = partnerRepository, partnerUrl = serverVersionsEndpointUrl) ) .parseBody() } @@ -83,7 +83,7 @@ class LocationsCpoClient( requestId = generateRequestId(), correlationId = generateCorrelationId() ) - .authenticate(platformRepository = platformRepository, platformUrl = serverVersionsEndpointUrl) + .authenticate(partnerRepository = partnerRepository, partnerUrl = serverVersionsEndpointUrl) ) .parseBody() } @@ -104,7 +104,7 @@ class LocationsCpoClient( requestId = generateRequestId(), correlationId = generateCorrelationId() ) - .authenticate(platformRepository = platformRepository, platformUrl = serverVersionsEndpointUrl) + .authenticate(partnerRepository = partnerRepository, partnerUrl = serverVersionsEndpointUrl) ) .parseBody() } @@ -126,7 +126,7 @@ class LocationsCpoClient( requestId = generateRequestId(), correlationId = generateCorrelationId() ) - .authenticate(platformRepository = platformRepository, platformUrl = serverVersionsEndpointUrl) + .authenticate(partnerRepository = partnerRepository, partnerUrl = serverVersionsEndpointUrl) ) .parseBody() } @@ -149,7 +149,7 @@ class LocationsCpoClient( requestId = generateRequestId(), correlationId = generateCorrelationId() ) - .authenticate(platformRepository = platformRepository, platformUrl = serverVersionsEndpointUrl) + .authenticate(partnerRepository = partnerRepository, partnerUrl = serverVersionsEndpointUrl) ) .parseBody() } @@ -170,7 +170,7 @@ class LocationsCpoClient( requestId = generateRequestId(), correlationId = generateCorrelationId() ) - .authenticate(platformRepository = platformRepository, platformUrl = serverVersionsEndpointUrl) + .authenticate(partnerRepository = partnerRepository, partnerUrl = serverVersionsEndpointUrl) ) .parseBody() } @@ -192,7 +192,7 @@ class LocationsCpoClient( requestId = generateRequestId(), correlationId = generateCorrelationId() ) - .authenticate(platformRepository = platformRepository, platformUrl = serverVersionsEndpointUrl) + .authenticate(partnerRepository = partnerRepository, partnerUrl = serverVersionsEndpointUrl) ) .parseBody() } @@ -215,7 +215,7 @@ class LocationsCpoClient( requestId = generateRequestId(), correlationId = generateCorrelationId() ) - .authenticate(platformRepository = platformRepository, platformUrl = serverVersionsEndpointUrl) + .authenticate(partnerRepository = partnerRepository, partnerUrl = serverVersionsEndpointUrl) ) .parseBody() } diff --git a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/LocationsEmspClient.kt b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/LocationsEmspClient.kt index 344bb66f..a017710e 100644 --- a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/LocationsEmspClient.kt +++ b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/LocationsEmspClient.kt @@ -1,7 +1,7 @@ package com.izivia.ocpi.toolkit.modules.locations import com.izivia.ocpi.toolkit.common.* -import com.izivia.ocpi.toolkit.modules.credentials.repositories.PlatformRepository +import com.izivia.ocpi.toolkit.modules.credentials.repositories.PartnerRepository import com.izivia.ocpi.toolkit.modules.locations.domain.Connector import com.izivia.ocpi.toolkit.modules.locations.domain.Evse import com.izivia.ocpi.toolkit.modules.locations.domain.Location @@ -15,20 +15,20 @@ import java.time.Instant /** * Sends calls to the CPO * @property transportClientBuilder used to build transport client - * @property serverVersionsEndpointUrl used to know which platform to communicate with - * @property platformRepository used to get information about the platform (endpoint, token) + * @property serverVersionsEndpointUrl used to know which partner to communicate with + * @property partnerRepository used to get information about the partner (endpoint, token) */ class LocationsEmspClient( private val transportClientBuilder: TransportClientBuilder, private val serverVersionsEndpointUrl: String, - private val platformRepository: PlatformRepository + private val partnerRepository: PartnerRepository ) : LocationsCpoInterface { private suspend fun buildTransport(): TransportClient = transportClientBuilder .buildFor( module = ModuleID.locations, - platformUrl = serverVersionsEndpointUrl, - platformRepository = platformRepository + partnerUrl = serverVersionsEndpointUrl, + partnerRepository = partnerRepository ) override suspend fun getLocations( @@ -51,7 +51,7 @@ class LocationsEmspClient( requestId = generateRequestId(), correlationId = generateCorrelationId() ) - .authenticate(platformRepository = platformRepository, platformUrl = serverVersionsEndpointUrl) + .authenticate(partnerRepository = partnerRepository, partnerUrl = serverVersionsEndpointUrl) ) .parsePaginatedBody(offset) } @@ -66,7 +66,7 @@ class LocationsEmspClient( requestId = generateRequestId(), correlationId = generateCorrelationId() ) - .authenticate(platformRepository = platformRepository, platformUrl = serverVersionsEndpointUrl) + .authenticate(partnerRepository = partnerRepository, partnerUrl = serverVersionsEndpointUrl) ) .parseBody() } @@ -82,7 +82,7 @@ class LocationsEmspClient( requestId = generateRequestId(), correlationId = generateCorrelationId() ) - .authenticate(platformRepository = platformRepository, platformUrl = serverVersionsEndpointUrl) + .authenticate(partnerRepository = partnerRepository, partnerUrl = serverVersionsEndpointUrl) ) .parseBody() } @@ -101,7 +101,7 @@ class LocationsEmspClient( requestId = generateRequestId(), correlationId = generateCorrelationId() ) - .authenticate(platformRepository = platformRepository, platformUrl = serverVersionsEndpointUrl) + .authenticate(partnerRepository = partnerRepository, partnerUrl = serverVersionsEndpointUrl) ) .parseBody() } diff --git a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/Connector.kt b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/Connector.kt index 5dc3b404..338f8dc3 100644 --- a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/Connector.kt +++ b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/Connector.kt @@ -12,31 +12,31 @@ import java.time.Instant * as they do not belong to the same EVSE object. * @property standard The standard of the installed connector. * @property format The format (socket/cable) of the installed connector. - * @property power_type - * @property max_voltage Maximum voltage of the connector (line to neutral for AC_3_PHASE), in volt V. For example: DC + * @property powerType + * @property maxVoltage Maximum voltage of the connector (line to neutral for AC_3_PHASE), in volt V. For example: DC * Chargers might vary the voltage during charging when battery almost full. - * @property max_amperage Maximum amperage of the connector, in ampere A. - * @property max_electric_power Maximum electric power that can be delivered by this connector, in Watts (W). When the + * @property maxAmperage Maximum amperage of the connector, in ampere A. + * @property maxElectricPower Maximum electric power that can be delivered by this connector, in Watts (W). When the * maximum electric power is lower than the calculated value from voltage and amperage, this value should be set. For * example: A DC Charge Point which can delivers up to 920V and up to 400A can be limited to a maximum of 150kW * (max_electric_power = 150000). Depending on the car, it may supply max voltage or current, but not both at the same * time. For AC Charge Points, the amount of phases used can also have influence on the maximum power. - * @property tariff_ids (max-length=36) Identifier of the current charging tariff structure. For a "Free of Charge" + * @property tariffIds (max-length=36) Identifier of the current charging tariff structure. For a "Free of Charge" * tariff this field should be set, and point to a defined "Free of Charge" tariff. - * @property terms_and_conditions URL (string(255) type following the w3.org spec. to the operator's terms and + * @property termsAndConditions URL (string(255) type following the w3.org spec. to the operator's terms and * conditions - * @property last_updated Timestamp when this Connectors was last updated (or created). + * @property lastUpdated Timestamp when this Connectors was last updated (or created). */ @Partial data class Connector( val id: CiString, val standard: ConnectorType, val format: ConnectorFormat, - val power_type: PowerType, - val max_voltage: Int, - val max_amperage: Int, - val max_electric_power: Int? = null, - val tariff_ids: List? = null, - val terms_and_conditions: String? = null, - val last_updated: Instant + val powerType: PowerType, + val maxVoltage: Int, + val maxAmperage: Int, + val maxElectricPower: Int? = null, + val tariffIds: List? = null, + val termsAndConditions: String? = null, + val lastUpdated: Instant ) diff --git a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/ConnectorFormat.kt b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/ConnectorFormat.kt index 0b0f38bc..e7e1ba4e 100644 --- a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/ConnectorFormat.kt +++ b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/ConnectorFormat.kt @@ -13,4 +13,4 @@ enum class ConnectorFormat { * The connector is an attached cable; the EV users car needs to have a fitting inlet. */ CABLE -} \ No newline at end of file +} diff --git a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/ConnectorType.kt b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/ConnectorType.kt index 92ded4a8..8fbb6ddb 100644 --- a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/ConnectorType.kt +++ b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/ConnectorType.kt @@ -203,4 +203,4 @@ enum class ConnectorType { * Tesla Connector "Model-S"-type (oval, 5 pin) */ TESLA_S -} \ No newline at end of file +} diff --git a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/EnergyMix.kt b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/EnergyMix.kt index b4e2c481..57610af2 100644 --- a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/EnergyMix.kt +++ b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/EnergyMix.kt @@ -6,13 +6,13 @@ import com.izivia.ocpi.toolkit.annotations.Partial * This type is used to specify the energy mix and environmental impact of the supplied energy at a location or in a * tariff. * - * @property is_green_energy True if 100% from regenerative sources. (CO2 and nuclear waste is zero) - * @property energy_sources Key-value pairs (enum + percentage) of energy sources of this location's tariff. - * @property environ_impact Key-value pairs (enum + percentage) of nuclear waste and CO2 exhaust of this location's + * @property isGreenEnergy True if 100% from regenerative sources. (CO2 and nuclear waste is zero) + * @property energySources Key-value pairs (enum + percentage) of energy sources of this location's tariff. + * @property environImpact Key-value pairs (enum + percentage) of nuclear waste and CO2 exhaust of this location's * tariff. - * @property supplier_name (max-length=64) Name of the energy supplier, delivering the energy for this location or + * @property supplierName (max-length=64) Name of the energy supplier, delivering the energy for this location or * tariff. ** - * @property energy_product_name (max-length=64) Name of the energy suppliers product/tariff plan used at this + * @property energyProductName (max-length=64) Name of the energy suppliers product/tariff plan used at this * location. ** * * ** These fields can be used to look-up energy qualification or to show it directly to the customer (for well-known @@ -20,9 +20,9 @@ import com.izivia.ocpi.toolkit.annotations.Partial */ @Partial data class EnergyMix( - val is_green_energy: Boolean, - val energy_sources: List?, - val environ_impact: List?, - val supplier_name: String?, - val energy_product_name: String? -) \ No newline at end of file + val isGreenEnergy: Boolean, + val energySources: List?, + val environImpact: List?, + val supplierName: String?, + val energyProductName: String? +) diff --git a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/EnergySourceCategory.kt b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/EnergySourceCategory.kt index 2df3e7ed..33150e43 100644 --- a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/EnergySourceCategory.kt +++ b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/EnergySourceCategory.kt @@ -43,4 +43,4 @@ enum class EnergySourceCategory { * Regenerative power from water turbines. */ WATER -} \ No newline at end of file +} diff --git a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/EnvironmentalImpact.kt b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/EnvironmentalImpact.kt index 991657aa..29364fd7 100644 --- a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/EnvironmentalImpact.kt +++ b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/EnvironmentalImpact.kt @@ -12,4 +12,4 @@ import java.math.BigDecimal data class EnvironmentalImpact( val category: EnvironmentalImpactCategory, val amount: BigDecimal -) \ No newline at end of file +) diff --git a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/Evse.kt b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/Evse.kt index 08896e6f..a4b768d7 100644 --- a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/Evse.kt +++ b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/Evse.kt @@ -15,43 +15,43 @@ import java.time.Instant * An EVSE object has a list of connectors which can not be used simultaneously: only one connector per EVSE can be used * at the time. * - * @property uid (max-length=36) Uniquely identifies the EVSE within the CPOs platform (and suboperator platforms). For + * @property uid (max-length=36) Uniquely identifies the EVSE within the CPOs partner (and suboperator platforms). For * example a database unique ID or the "EVSE ID". This field can never be changed, modified or renamed. This is the * 'technical' identification of the EVSE, not to be used as 'human readable' identification, use the field: evse_id for * that. - * @property evse_id Compliant with the following specification for EVSE ID from "eMI3 standard version V1.0" + * @property evseId Compliant with the following specification for EVSE ID from "eMI3 standard version V1.0" * (http://emi3group.com/documents-links/) "Part 2: business objects." Optional for OCPI because: if an EVSE ID is to be * re-used the EVSE ID can be removed from an EVSE that is removed (status: REMOVED). BUT REQUIRED for gireve: required * by GIREVE to ensure seamless compatibility with operators connected via other protocols (eMIP, ...). In addition, the * eMI3 standard requires that the eMI3 Id of an EVSE begins by the eMI3 Id of the CPO. * @property status Indicates the current status of the EVSE. - * @property status_schedule Indicates a planned status in the future of the EVSE. + * @property statusSchedule Indicates a planned status in the future of the EVSE. * @property capabilities List of functionalities that the EVSE is capable of. * @property connectors (at least one in the list) List of available connectors on the EVSE. - * @property floor_level (max-length=4) Level on which the charging station is located (in garage buildings) in the + * @property floorLevel (max-length=4) Level on which the charging station is located (in garage buildings) in the * locally displayed numbering scheme. * @property coordinates Coordinates of the EVSE. - * @property physical_reference (max-length=16) A number/string printed on the outside of the EVSE for visual + * @property physicalReference (max-length=16) A number/string printed on the outside of the EVSE for visual * identification. * @property directions Multi-language human-readable directions when more detailed information on how to reach the EVSE * from the Location is required. - * @property parking_restrictions The restrictions that apply to the parking spot. + * @property parkingRestrictions The restrictions that apply to the parking spot. * @property images Links to images related to the EVSE such as photos or logos. - * @property last_updated Instant Timestamp when this EVSE or one of its Connectors was last updated (or created). + * @property lastUpdated Instant Timestamp when this EVSE or one of its Connectors was last updated (or created). */ @Partial data class Evse( val uid: CiString, - val evse_id: CiString, + val evseId: CiString, val status: Status, - val status_schedule: List? = null, + val statusSchedule: List? = null, val capabilities: List? = null, val connectors: List, - val floor_level: String? = null, + val floorLevel: String? = null, val coordinates: GeoLocation? = null, - val physical_reference: String? = null, + val physicalReference: String? = null, val directions: List? = null, - val parking_restrictions: List? = null, + val parkingRestrictions: List? = null, val images: List? = null, - val last_updated: Instant + val lastUpdated: Instant ) diff --git a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/ExceptionalPeriod.kt b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/ExceptionalPeriod.kt index edf1eb97..7b359fd6 100644 --- a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/ExceptionalPeriod.kt +++ b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/ExceptionalPeriod.kt @@ -6,11 +6,11 @@ import java.time.Instant /** * Specifies one exceptional period for opening or access hours. * - * @property period_begin Begin of the exception. - * @property period_end End of the exception. + * @property periodBegin Begin of the exception. + * @property periodEnd End of the exception. */ @Partial data class ExceptionalPeriod( - val period_begin: Instant, - val period_end: Instant -) \ No newline at end of file + val periodBegin: Instant, + val periodEnd: Instant +) diff --git a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/GeoLocation.kt b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/GeoLocation.kt index 0885424f..489c5936 100644 --- a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/GeoLocation.kt +++ b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/GeoLocation.kt @@ -14,4 +14,4 @@ import com.izivia.ocpi.toolkit.annotations.Partial data class GeoLocation( val latitude: String, val longitude: String -) \ No newline at end of file +) diff --git a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/Hours.kt b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/Hours.kt index bc38ab70..f0e64ee7 100644 --- a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/Hours.kt +++ b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/Hours.kt @@ -6,18 +6,18 @@ import com.izivia.ocpi.toolkit.annotations.Partial * Opening and access hours of the location. * Note: regular_hours is required when twentyfourseven=false, this is much less confusing. * - * @property regular_hours Regular hours, weekday based. Should not be set for representing 24/7 as this is the most + * @property regularHours Regular hours, weekday based. Should not be set for representing 24/7 as this is the most * common case. - * @property twenty_four_seven True to represent 24 hours a day and 7 days a week, except the given exceptions. - * @property exceptional_openings Exceptions for specified calendar dates, time-range based. Periods the station is + * @property twentyFourSeven True to represent 24 hours a day and 7 days a week, except the given exceptions. + * @property exceptionalOpenings Exceptions for specified calendar dates, time-range based. Periods the station is * operating/accessible. Additional to regular hours. May overlap regular rules. - * @property exceptional_closings Exceptions for specified calendar dates, time-range based. Periods the station is not + * @property exceptionalClosings Exceptions for specified calendar dates, time-range based. Periods the station is not * operating/accessible. Overwriting regularHours and exceptionalOpenings. Should not overlap exceptionalOpenings. */ @Partial data class Hours( - val regular_hours: List?, - val twenty_four_seven: Boolean, - val exceptional_openings: List?, - val exceptional_closings: List? -) \ No newline at end of file + val regularHours: List?, + val twentyFourSeven: Boolean, + val exceptionalOpenings: List?, + val exceptionalClosings: List? +) diff --git a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/Image.kt b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/Image.kt index 06107920..ba100efc 100644 --- a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/Image.kt +++ b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/Image.kt @@ -37,4 +37,4 @@ data class Image( val type: CiString, val width: Int?, val height: Int? -) \ No newline at end of file +) diff --git a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/ImageCategory.kt b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/ImageCategory.kt index 2bcb4f82..c1e0d101 100644 --- a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/ImageCategory.kt +++ b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/ImageCategory.kt @@ -41,5 +41,5 @@ enum class ImageCategory { * Logo of the charge points owner, for example a local store, to be displayed with the EVSEs detailed information * view */ - OWNER, -} \ No newline at end of file + OWNER +} diff --git a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/Location.kt b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/Location.kt index cf6cec9a..62aa9782 100644 --- a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/Location.kt +++ b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/Location.kt @@ -11,25 +11,25 @@ import java.time.Instant * of a parking garage which contains these EVSEs. The exact way to reach each EVSE can be further specified by its own * properties. * - * @property country_code (max-length=2) ISO-3166 alpha-2 country code of the CPO that 'owns' this Location. - * @property party_id (max-length=3) ID of the CPO that 'owns' this Location (following the ISO-15118 standard). + * @property countryCode (max-length=2) ISO-3166 alpha-2 country code of the CPO that 'owns' this Location. + * @property partyId (max-length=3) ID of the CPO that 'owns' this Location (following the ISO-15118 standard). * @property id (max-length=36) Uniquely identifies the location within the CPOs platform (and suboperator platforms). * This field can never be changed, modified or renamed. * @property publish Defines if a Location may be published on a website or app etc. When this is set to false, only * tokens identified in the field: publish_allowed_to are allowed to be shown this Location. When the same location has * EVSEs that may be published and may not be published, two 'Locations' should be created. - * @property publish_allowed_to This field may only be used when the publish field is set to false. Only owners of + * @property publishAllowedTo This field may only be used when the publish field is set to false. Only owners of * Tokens that match all the set fields of one PublishToken in the list are allowed to be shown this location. * @property name (max-length=255) Display name of the location. * @property address (max-length=45) Street/block name and house number if available. * @property city (max-length=45) City or town. - * @property postal_code (max-length=10) Postal code of the location, may only be omitted when the location has no + * @property postalCode (max-length=10) Postal code of the location, may only be omitted when the location has no * postal code: in some countries charging locations at highways don’t have postal codes. * @property state (max-length=20) State or province of the location, only to be used when relevant. * @property country (max-length=3) ISO 3166-1 alpha-3 code for the country of this location. * @property coordinates Coordinates of the location. - * @property related_locations Geographical location of related points relevant to the user. - * @property parking_type The general type of parking at the charge point location. + * @property relatedLocations Geographical location of related points relevant to the user. + * @property parkingType The general type of parking at the charge point location. * @property evses List of EVSEs that belong to this Location. * @property directions Human-readable directions on how to reach the location. * @property operator Information of the operator. When not specified, the information retrieved from the api_info @@ -37,42 +37,42 @@ import java.time.Instant * @property suboperator Information of the suboperator if available. * @property owner Information of the owner if available. * @property facilities Optional list of facilities this charge location directly belongs to. - * @property time_zone (max-length=255) One of IANA tzdata's TZ-values representing the time zone of the location. + * @property timeZone (max-length=255) One of IANA tzdata's TZ-values representing the time zone of the location. * Examples: "Europe/Oslo", "Europe/Zurich". (http://www.iana.org/time-zones) - * @property opening_times The times when the EVSEs at the location can be accessed for charging. - * @property charging_when_closed Indicates if the EVSEs are still charging outside the opening hours of the location. + * @property openingTimes The times when the EVSEs at the location can be accessed for charging. + * @property chargingWhenClosed Indicates if the EVSEs are still charging outside the opening hours of the location. * E.g. when the parking garage closes its barriers overnight, is it allowed to charge till the next morning? * Default: true * @property images Links to images related to the location such as photos or logos. - * @property energy_mix Details on the energy supplied at this location. - * @property last_updated Timestamp when this Location or one of its EVSEs or Connectors were last updated (or created). + * @property energyMix Details on the energy supplied at this location. + * @property lastUpdated Timestamp when this Location or one of its EVSEs or Connectors were last updated (or created). */ @Partial data class Location( - val country_code: CiString, - val party_id: CiString, + val countryCode: CiString, + val partyId: CiString, val id: CiString, val publish: Boolean, - val publish_allowed_to: List? = null, + val publishAllowedTo: List? = null, val name: String? = null, val address: String, val city: String, - val postal_code: String? = null, + val postalCode: String? = null, val state: String? = null, val country: String, val coordinates: GeoLocation, - val related_locations: List? = null, - val parking_type: ParkingType? = null, + val relatedLocations: List? = null, + val parkingType: ParkingType? = null, val evses: List? = null, val directions: List? = null, val operator: BusinessDetails? = null, val suboperator: BusinessDetails? = null, val owner: BusinessDetails? = null, val facilities: List? = null, - val time_zone: String, - val opening_times: Hours? = null, - val charging_when_closed: Boolean? = null, + val timeZone: String, + val openingTimes: Hours? = null, + val chargingWhenClosed: Boolean? = null, val images: List? = null, - val energy_mix: EnergyMix? = null, - val last_updated: Instant + val energyMix: EnergyMix? = null, + val lastUpdated: Instant ) diff --git a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/ParkingRestriction.kt b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/ParkingRestriction.kt index 9eb7bc9e..2d56dd56 100644 --- a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/ParkingRestriction.kt +++ b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/ParkingRestriction.kt @@ -28,4 +28,4 @@ enum class ParkingRestriction { * Parking spot only suitable for (electric) motorcycles or scooters. */ MOTORCYCLES -} \ No newline at end of file +} diff --git a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/ParkingType.kt b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/ParkingType.kt index 8e8075af..9245b056 100644 --- a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/ParkingType.kt +++ b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/ParkingType.kt @@ -33,4 +33,4 @@ enum class ParkingType { * Multistory car park, mainly underground. */ UNDERGROUND_GARAGE -} \ No newline at end of file +} diff --git a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/PowerType.kt b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/PowerType.kt index fbf26259..31e8b4a5 100644 --- a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/PowerType.kt +++ b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/PowerType.kt @@ -25,4 +25,4 @@ enum class PowerType { * Direct Current. */ DC -} \ No newline at end of file +} diff --git a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/PublishTokenType.kt b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/PublishTokenType.kt index 776ccd8e..80db5d8b 100644 --- a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/PublishTokenType.kt +++ b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/PublishTokenType.kt @@ -13,10 +13,10 @@ import com.izivia.ocpi.toolkit.modules.tokens.domain.TokenType * * @property uid (max-length=36) Unique ID by which this Token can be identified. * @property type Type of the token. - * @property visual_number (max-length=64) Visual readable number/identification as printed on the Token (RFID card). + * @property visualNumber (max-length=64) Visual readable number/identification as printed on the Token (RFID card). * @property issuer (max-length=64) Issuing company, most of the times the name of the company printed on the token * (RFID card), not necessarily the eMSP. - * @property group_id (max-length=36) This ID groups a couple of tokens. This can be used to make two or more tokens + * @property groupId (max-length=36) This ID groups a couple of tokens. This can be used to make two or more tokens * work as one * @constructor */ @@ -24,7 +24,7 @@ import com.izivia.ocpi.toolkit.modules.tokens.domain.TokenType data class PublishTokenType( val uid: CiString?, val type: TokenType?, - val visual_number: String?, + val visualNumber: String?, val issuer: String?, - val group_id: CiString + val groupId: CiString ) diff --git a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/RegularHours.kt b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/RegularHours.kt index 0a41058a..e4e7dd3c 100644 --- a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/RegularHours.kt +++ b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/RegularHours.kt @@ -6,14 +6,14 @@ import com.izivia.ocpi.toolkit.annotations.Partial * Regular recurring operation or access hours * * @property weekday (max-length=1) Number of day in the week, from Monday (1) till Sunday (7) - * @property period_begin (max-length=5) Begin of the regular period given in hours and minutes. Must be in 24h format + * @property periodBegin (max-length=5) Begin of the regular period given in hours and minutes. Must be in 24h format * with leading zeros. Example: "18:15". Hour/Minute separator: ":" Regex: ([0-1][0-9]|2[0-3]):[0-5][0-9] - * @property period_end (max-length=5) End of the regular period, syntax as for periodBegin. Must be later than + * @property periodEnd (max-length=5) End of the regular period, syntax as for periodBegin. Must be later than * periodBegin. */ @Partial data class RegularHours( val weekday: Int, - val period_begin: String, - val period_end: String -) \ No newline at end of file + val periodBegin: String, + val periodEnd: String +) diff --git a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/StatusSchedule.kt b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/StatusSchedule.kt index abcc3653..15d2e7d8 100644 --- a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/StatusSchedule.kt +++ b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/domain/StatusSchedule.kt @@ -11,13 +11,13 @@ import java.time.Instant * Note that the scheduled status is purely informational. When the status actually changes, the CPO must push an update * to the EVSEs `status` field itself. * - * @property period_begin Begin of the scheduled period. - * @property period_end End of the scheduled period, if known. + * @property periodBegin Begin of the scheduled period. + * @property periodEnd End of the scheduled period, if known. * @property status Status value during the scheduled period. */ @Partial data class StatusSchedule( - val period_begin: Instant, - val period_end: Instant?, + val periodBegin: Instant, + val periodEnd: Instant?, val status: Status -) \ No newline at end of file +) diff --git a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/repositories/LocationsCpoRepository.kt b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/repositories/LocationsCpoRepository.kt index 98fea4a4..6c529641 100644 --- a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/repositories/LocationsCpoRepository.kt +++ b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/repositories/LocationsCpoRepository.kt @@ -30,23 +30,23 @@ interface LocationsCpoRepository { * @return List The endpoint returns a list of Location objects The header will * contain the pagination related headers. */ - fun getLocations(dateFrom: Instant?, dateTo: Instant?, offset: Int = 0, limit: Int?): SearchResult + suspend fun getLocations(dateFrom: Instant?, dateTo: Instant?, offset: Int = 0, limit: Int?): SearchResult /** * @param locationId String max-length = 39 */ - fun getLocation(locationId: String): Location? + suspend fun getLocation(locationId: String): Location? /** * @param locationId String max-length = 39 * @param evseUid String? max-length = 39 */ - fun getEvse(locationId: String, evseUid: String): Evse? + suspend fun getEvse(locationId: String, evseUid: String): Evse? /** * @param locationId String max-length = 39 * @param evseUid max-length = 39 * @param connectorId max-length = 39 */ - fun getConnector(locationId: String, evseUid: String, connectorId: String): Connector? + suspend fun getConnector(locationId: String, evseUid: String, connectorId: String): Connector? } diff --git a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/repositories/LocationsEmspRepository.kt b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/repositories/LocationsEmspRepository.kt index 68db9989..c5194e26 100644 --- a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/repositories/LocationsEmspRepository.kt +++ b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/repositories/LocationsEmspRepository.kt @@ -2,7 +2,6 @@ package com.izivia.ocpi.toolkit.modules.locations.repositories import com.izivia.ocpi.toolkit.modules.locations.domain.* - /** * Locations is a client owned object, so the end-points need to contain the required extra fields: {party_id} and * {country_code}. Example endpoint structures: @@ -28,7 +27,7 @@ interface LocationsEmspRepository { * @param partyId (max-length=3) Party ID (Provider ID) of the CPO requesting this PUT to the eMSP system. * @param locationId (max-length=39) Location.id of the Location object to retrieve. */ - fun getLocation(countryCode: String, partyId: String, locationId: String): Location? + suspend fun getLocation(countryCode: String, partyId: String, locationId: String): Location? /** * If the CPO wants to check the status of a Location, EVSE or Connector object in the eMSP system, it might GET the @@ -41,7 +40,7 @@ interface LocationsEmspRepository { * @param locationId (max-length=39) Location.id of the Location object to retrieve. * @param evseUid (max-length=39) Evse.uid, required when requesting an EVSE or Connector object. */ - fun getEvse(countryCode: String, partyId: String, locationId: String, evseUid: String): Evse? + suspend fun getEvse(countryCode: String, partyId: String, locationId: String, evseUid: String): Evse? /** * If the CPO wants to check the status of a Location, EVSE or Connector object in the eMSP system, it might GET the @@ -55,7 +54,7 @@ interface LocationsEmspRepository { * @param evseUid (max-length=39) Evse.uid, required when requesting an EVSE or Connector object. * @param connectorId (max-length=36) Connector.id, required when requesting a Connector object. */ - fun getConnector( + suspend fun getConnector( countryCode: String, partyId: String, locationId: String, @@ -72,7 +71,7 @@ interface LocationsEmspRepository { * @param locationId (max-length=39) Location.id of the new Location object, or the Location of which an EVSE or * Location object is send */ - fun putLocation( + suspend fun putLocation( countryCode: String, partyId: String, locationId: String, @@ -89,7 +88,7 @@ interface LocationsEmspRepository { * Location object is send * @param evseUid (max-length=39) Evse.uid, required when an EVSE or Connector object is send/replaced. */ - fun putEvse( + suspend fun putEvse( countryCode: String, partyId: String, locationId: String, @@ -108,7 +107,7 @@ interface LocationsEmspRepository { * @param evseUid (max-length=39) Evse.uid, required when an EVSE or Connector object is send/replaced. * @param connectorId (max-length=36) Connector.id, required when a Connector object is send/replaced. */ - fun putConnector( + suspend fun putConnector( countryCode: String, partyId: String, locationId: String, @@ -125,7 +124,7 @@ interface LocationsEmspRepository { * @param partyId (max-length=3) Party ID (Provider ID) of the CPO requesting this PUT to the eMSP system. * @param locationId (max-length=39) Location.id of the new Location object */ - fun patchLocation( + suspend fun patchLocation( countryCode: String, partyId: String, locationId: String, @@ -141,7 +140,7 @@ interface LocationsEmspRepository { * @param locationId (max-length=39) Location.id of the Location of which an EVSE or Location object is send * @param evseUid (max-length=39) Evse.uid, required when an EVSE or Connector object is send/replaced. */ - fun patchEvse( + suspend fun patchEvse( countryCode: String, partyId: String, locationId: String, @@ -159,7 +158,7 @@ interface LocationsEmspRepository { * @param evseUid (max-length=39) Evse.uid, required when an EVSE or Connector object is send/replaced. * @param connectorId (max-length=36) Connector.id, required when a Connector object is send/replaced. */ - fun patchConnector( + suspend fun patchConnector( countryCode: String, partyId: String, locationId: String, diff --git a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/services/LocationValidators.kt b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/services/LocationValidators.kt index c11076ec..c703664a 100644 --- a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/services/LocationValidators.kt +++ b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/services/LocationValidators.kt @@ -14,32 +14,32 @@ import org.valiktor.validate import java.math.BigDecimal fun LocationPartial.validate(): LocationPartial = validate(this) { - validate(LocationPartial::country_code).isCountryCode(caseSensitive = false, alpha2 = true) - validate(LocationPartial::party_id).isPrintableAscii().hasMaxLengthOf(3) + validate(LocationPartial::countryCode).isCountryCode(caseSensitive = false, alpha2 = true) + validate(LocationPartial::partyId).isPrintableAscii().hasMaxLengthOf(3) validate(LocationPartial::id).isPrintableAscii().hasMaxLengthOf(36) // publish: nothing to validate - // publish_allowed_to: nothing to validate + // publishAllowedTo: nothing to validate validate(LocationPartial::name).isPrintableUtf8().hasMaxLengthOf(255) validate(LocationPartial::address).isPrintableUtf8().hasMaxLengthOf(45) validate(LocationPartial::city).isPrintableUtf8().hasMaxLengthOf(45) - validate(LocationPartial::postal_code).isPrintableUtf8().hasMaxLengthOf(10) + validate(LocationPartial::postalCode).isPrintableUtf8().hasMaxLengthOf(10) validate(LocationPartial::state).isPrintableUtf8().hasMaxLengthOf(20) validate(LocationPartial::country).isCountryCode(caseSensitive = true, alpha2 = false) coordinates?.validate() - related_locations?.forEach { it.validate() } - // parking_type: nothing to validate + relatedLocations?.forEach { it.validate() } + // parkingType: nothing to validate evses?.forEach { it.validate() } directions?.forEach { it.validate() } operator?.validate() suboperator?.validate() owner?.validate() // facilities: nothing to validate - validate(LocationPartial::time_zone).isTimeZone() - opening_times?.validate() - // charging_when_closed: nothing to validate + validate(LocationPartial::timeZone).isTimeZone() + openingTimes?.validate() + // chargingWhenClosed: nothing to validate images?.forEach { it.validate() } - energy_mix?.validate() - // last_updated: nothing to validate + energyMix?.validate() + // lastUpdated: nothing to validate } fun EnvironmentalImpactPartial.validate(): EnvironmentalImpactPartial = validate(this) { @@ -56,35 +56,35 @@ fun EnergySourcePartial.validate(): EnergySourcePartial = validate(this) { } fun EnergyMixPartial.validate(): EnergyMixPartial = validate(this) { - // is_green_energy: nothing to validate - energy_sources?.forEach { it.validate() } - environ_impact?.forEach { it.validate() } - validate(EnergyMixPartial::supplier_name).isPrintableUtf8().hasMaxLengthOf(64) - validate(EnergyMixPartial::energy_product_name).isPrintableUtf8().hasMaxLengthOf(64) + // isGreenEnergy: nothing to validate + energySources?.forEach { it.validate() } + environImpact?.forEach { it.validate() } + validate(EnergyMixPartial::supplierName).isPrintableUtf8().hasMaxLengthOf(64) + validate(EnergyMixPartial::energyProductName).isPrintableUtf8().hasMaxLengthOf(64) } fun ExceptionalPeriodPartial.validate(): ExceptionalPeriodPartial = validate(this) { - if (it.period_end != null) { - validate(ExceptionalPeriodPartial::period_begin).isLessThanOrEqualTo(it.period_end) + if (it.periodEnd != null) { + validate(ExceptionalPeriodPartial::periodBegin).isLessThanOrEqualTo(it.periodEnd) } } fun RegularHoursPartial.validate(): RegularHoursPartial = validate(this) { regularHours -> validate(RegularHoursPartial::weekday).isGreaterThanOrEqualTo(1).isLessThanOrEqualTo(7) - validate(RegularHoursPartial::period_begin).isTime() - validate(RegularHoursPartial::period_end).isTime() + validate(RegularHoursPartial::periodBegin).isTime() + validate(RegularHoursPartial::periodEnd).isTime() - val beginInMinutes = regularHours.period_begin?.split(":") + val beginInMinutes = regularHours.periodBegin?.split(":") ?.mapIndexed { index, time -> time.toInt() * (1 - index) * 60 } ?.sum() - val endInMinutes = regularHours.period_end?.split(":") + val endInMinutes = regularHours.periodEnd?.split(":") ?.mapIndexed { index, time -> time.toInt() * (1 - index) * 60 } ?.sum() if (beginInMinutes != null && endInMinutes != null && beginInMinutes > endInMinutes) { constraintViolations.add( DefaultConstraintViolation( - property = "period_begin ($period_begin) is after period_end ($period_end)", + property = "periodBegin ($periodBegin) is after periodEnd ($periodEnd)", constraint = Greater(endInMinutes) ) ) @@ -92,26 +92,26 @@ fun RegularHoursPartial.validate(): RegularHoursPartial = validate(this) { regul } fun HoursPartial.validate(): HoursPartial = validate(this) { hours -> - if (hours.regular_hours == null && hours.twenty_four_seven == false) { + if (hours.regularHours == null && hours.twentyFourSeven == false) { constraintViolations.add( DefaultConstraintViolation( - property = "regular_hours is not set whereas twenty_four_seven is false", + property = "regularHours is not set whereas twentyFourSeven is false", constraint = RegularHoursSetWhenNotTwentyFourSevenConstraint() ) ) - } else if (hours.regular_hours != null && hours.twenty_four_seven == true) { + } else if (hours.regularHours != null && hours.twentyFourSeven == true) { constraintViolations.add( DefaultConstraintViolation( - property = "twenty_four_seven is set to true whereas regular_hours are set", + property = "twentyFourSeven is set to true whereas regularHours are set", constraint = RegularHoursSetAtTheSameTimeAsTwentyFourSevenConstraint() ) ) } - regular_hours?.forEach { it.validate() } - /// twenty_four_seven: nothing to validate - exceptional_openings?.forEach { it.validate() } - exceptional_closings?.forEach { it.validate() } + regularHours?.forEach { it.validate() } + // twentyFourSeven: nothing to validate + exceptionalOpenings?.forEach { it.validate() } + exceptionalClosings?.forEach { it.validate() } } fun ImagePartial.validate(): ImagePartial = validate(this) { @@ -149,41 +149,41 @@ fun DisplayTextPartial.validate(): DisplayTextPartial = validate(this) { } fun StatusSchedulePartial.validate(): StatusSchedulePartial = validate(this) { - if (it.period_end != null) { - validate(StatusSchedulePartial::period_begin).isLessThanOrEqualTo(it.period_end) + if (it.periodEnd != null) { + validate(StatusSchedulePartial::periodBegin).isLessThanOrEqualTo(it.periodEnd) } } fun EvsePartial.validate(): EvsePartial = validate(this) { validate(EvsePartial::uid).isPrintableAscii().hasMaxLengthOf(39) - validate(EvsePartial::evse_id).isEvseId() + validate(EvsePartial::evseId).isEvseId() // status: nothing to validate - status_schedule?.forEach { it.validate() } + statusSchedule?.forEach { it.validate() } // capabilities: nothing to validate validate(EvsePartial::connectors).isNotEmpty() connectors?.forEach { it.validate() } - validate(EvsePartial::floor_level).isPrintableUtf8().hasMaxLengthOf(4) + validate(EvsePartial::floorLevel).isPrintableUtf8().hasMaxLengthOf(4) coordinates?.validate() - validate(EvsePartial::physical_reference).isPrintableUtf8().hasMaxLengthOf(16) + validate(EvsePartial::physicalReference).isPrintableUtf8().hasMaxLengthOf(16) directions?.forEach { it.validate() } - // parking_restrictions: nothing to validate + // parkingRestrictions: nothing to validate images?.forEach { it.validate() } - // last_updated: nothing to validate + // lastUpdated: nothing to validate } fun ConnectorPartial.validate(): ConnectorPartial = validate(this) { validate(ConnectorPartial::id).isPrintableAscii().hasMaxLengthOf(36) // standard: nothing to validate // format: nothing to validate - // power_type: nothing to validate - validate(ConnectorPartial::max_voltage).isGreaterThanOrEqualTo(0) - validate(ConnectorPartial::max_amperage).isGreaterThanOrEqualTo(0) - validate(ConnectorPartial::max_voltage).isGreaterThanOrEqualTo(0) - tariff_ids?.forEach { tariffId -> + // powerType: nothing to validate + validate(ConnectorPartial::maxVoltage).isGreaterThanOrEqualTo(0) + validate(ConnectorPartial::maxAmperage).isGreaterThanOrEqualTo(0) + validate(ConnectorPartial::maxVoltage).isGreaterThanOrEqualTo(0) + tariffIds?.forEach { tariffId -> if (tariffId.length > 36) { constraintViolations.add( DefaultConstraintViolation( - property = "tariff_ids", + property = "tariffIds", constraint = MaxLengthContraint(36) ) ) @@ -191,14 +191,14 @@ fun ConnectorPartial.validate(): ConnectorPartial = validate(this) { if (!tariffId.isPrintableAscii()) { constraintViolations.add( DefaultConstraintViolation( - property = "tariff_ids", + property = "tariffIds", constraint = PrintableAsciiConstraint() ) ) } } - validate(ConnectorPartial::terms_and_conditions).isUrl() - // last_updated: nothing to validate + validate(ConnectorPartial::termsAndConditions).isUrl() + // lastUpdated: nothing to validate } fun Location.validate(): Location = validate(this) { diff --git a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/services/LocationsEmspService.kt b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/services/LocationsEmspService.kt index 6f3f5d06..e4a23b57 100644 --- a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/services/LocationsEmspService.kt +++ b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/services/LocationsEmspService.kt @@ -28,7 +28,6 @@ class LocationsEmspService( ?.validate() } - override suspend fun getEvse( countryCode: CiString, partyId: CiString, diff --git a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/sessions/SessionsCpoClient.kt b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/sessions/SessionsCpoClient.kt index 820b5944..354028c4 100644 --- a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/sessions/SessionsCpoClient.kt +++ b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/sessions/SessionsCpoClient.kt @@ -1,8 +1,9 @@ package com.izivia.ocpi.toolkit.modules.sessions import com.izivia.ocpi.toolkit.common.* -import com.izivia.ocpi.toolkit.modules.credentials.repositories.PlatformRepository +import com.izivia.ocpi.toolkit.modules.credentials.repositories.PartnerRepository import com.izivia.ocpi.toolkit.modules.sessions.domain.Session +import com.izivia.ocpi.toolkit.modules.sessions.domain.SessionPartial import com.izivia.ocpi.toolkit.modules.versions.domain.ModuleID import com.izivia.ocpi.toolkit.transport.TransportClient import com.izivia.ocpi.toolkit.transport.TransportClientBuilder @@ -12,26 +13,26 @@ import com.izivia.ocpi.toolkit.transport.domain.HttpRequest /** * Sends calls to an eMSP server * @property transportClientBuilder used to build transport client - * @property serverVersionsEndpointUrl used to know which platform to communicate with - * @property platformRepository used to get information about the platform (endpoint, token) + * @property serverVersionsEndpointUrl used to know which partner to communicate with + * @property partnerRepository used to get information about the partner (endpoint, token) */ class SessionsCpoClient( private val transportClientBuilder: TransportClientBuilder, private val serverVersionsEndpointUrl: String, - private val platformRepository: PlatformRepository + private val partnerRepository: PartnerRepository ) : SessionsEmspInterface { private suspend fun buildTransport(): TransportClient = transportClientBuilder .buildFor( module = ModuleID.sessions, - platformUrl = serverVersionsEndpointUrl, - platformRepository = platformRepository + partnerUrl = serverVersionsEndpointUrl, + partnerRepository = partnerRepository ) override suspend fun getSession( countryCode: CiString, partyId: CiString, sessionId: CiString - ): OcpiResponseBody = + ): OcpiResponseBody = with(buildTransport()) { send( HttpRequest( @@ -41,7 +42,7 @@ class SessionsCpoClient( requestId = generateRequestId(), correlationId = generateCorrelationId() ) - .authenticate(platformRepository = platformRepository, platformUrl = serverVersionsEndpointUrl) + .authenticate(partnerRepository = partnerRepository, partnerUrl = serverVersionsEndpointUrl) ) .parseBody() } @@ -62,7 +63,7 @@ class SessionsCpoClient( requestId = generateRequestId(), correlationId = generateCorrelationId() ) - .authenticate(platformRepository = platformRepository, platformUrl = serverVersionsEndpointUrl) + .authenticate(partnerRepository = partnerRepository, partnerUrl = serverVersionsEndpointUrl) ) .parseBody() } @@ -71,7 +72,7 @@ class SessionsCpoClient( countryCode: CiString, partyId: CiString, sessionId: CiString, - session: Session + session: SessionPartial ): OcpiResponseBody = with(buildTransport()) { send( @@ -83,7 +84,7 @@ class SessionsCpoClient( requestId = generateRequestId(), correlationId = generateCorrelationId() ) - .authenticate(platformRepository = platformRepository, platformUrl = serverVersionsEndpointUrl) + .authenticate(partnerRepository = partnerRepository, partnerUrl = serverVersionsEndpointUrl) ) .parseBody() } diff --git a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/sessions/SessionsCpoInterface.kt b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/sessions/SessionsCpoInterface.kt index a97da292..af93de3e 100644 --- a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/sessions/SessionsCpoInterface.kt +++ b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/sessions/SessionsCpoInterface.kt @@ -8,7 +8,6 @@ import com.izivia.ocpi.toolkit.modules.sessions.domain.ChargingPreferencesRespon import com.izivia.ocpi.toolkit.modules.sessions.domain.Session import java.time.Instant - /** * Typically implemented by market roles like: CPO. * @@ -55,5 +54,4 @@ interface SessionsCpoInterface { sessionId: CiString, chargingPreferences: ChargingPreferences ): OcpiResponseBody - } diff --git a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/sessions/SessionsEmspClient.kt b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/sessions/SessionsEmspClient.kt index d9239a4e..8a194ee1 100644 --- a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/sessions/SessionsEmspClient.kt +++ b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/sessions/SessionsEmspClient.kt @@ -1,7 +1,7 @@ package com.izivia.ocpi.toolkit.modules.sessions import com.izivia.ocpi.toolkit.common.* -import com.izivia.ocpi.toolkit.modules.credentials.repositories.PlatformRepository +import com.izivia.ocpi.toolkit.modules.credentials.repositories.PartnerRepository import com.izivia.ocpi.toolkit.modules.sessions.domain.ChargingPreferences import com.izivia.ocpi.toolkit.modules.sessions.domain.ChargingPreferencesResponseType import com.izivia.ocpi.toolkit.modules.sessions.domain.Session @@ -15,19 +15,19 @@ import java.time.Instant /** * Sends calls to the CPO * @property transportClientBuilder used to build transport client - * @property serverVersionsEndpointUrl used to know which platform to communicate with - * @property platformRepository used to get information about the platform (endpoint, token) + * @property serverVersionsEndpointUrl used to know which partner to communicate with + * @property partnerRepository used to get information about the partner (endpoint, token) */ class SessionsEmspClient( private val transportClientBuilder: TransportClientBuilder, private val serverVersionsEndpointUrl: String, - private val platformRepository: PlatformRepository + private val partnerRepository: PartnerRepository ) : SessionsCpoInterface { private suspend fun buildTransport(): TransportClient = transportClientBuilder .buildFor( module = ModuleID.sessions, - platformUrl = serverVersionsEndpointUrl, - platformRepository = platformRepository + partnerUrl = serverVersionsEndpointUrl, + partnerRepository = partnerRepository ) override suspend fun getSessions( @@ -50,7 +50,7 @@ class SessionsEmspClient( requestId = generateRequestId(), correlationId = generateCorrelationId() ) - .authenticate(platformRepository = platformRepository, platformUrl = serverVersionsEndpointUrl) + .authenticate(partnerRepository = partnerRepository, partnerUrl = serverVersionsEndpointUrl) ) .parsePaginatedBody(offset) } @@ -69,7 +69,7 @@ class SessionsEmspClient( requestId = generateRequestId(), correlationId = generateCorrelationId() ) - .authenticate(platformRepository = platformRepository, platformUrl = serverVersionsEndpointUrl) + .authenticate(partnerRepository = partnerRepository, partnerUrl = serverVersionsEndpointUrl) ) .parseBody() } diff --git a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/sessions/SessionsEmspInterface.kt b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/sessions/SessionsEmspInterface.kt index 03c7bdc1..85400e80 100644 --- a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/sessions/SessionsEmspInterface.kt +++ b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/sessions/SessionsEmspInterface.kt @@ -3,6 +3,7 @@ package com.izivia.ocpi.toolkit.modules.sessions import com.izivia.ocpi.toolkit.common.CiString import com.izivia.ocpi.toolkit.common.OcpiResponseBody import com.izivia.ocpi.toolkit.modules.sessions.domain.Session +import com.izivia.ocpi.toolkit.modules.sessions.domain.SessionPartial /** * Typically implemented by market roles like: eMSP and SCSP. @@ -27,7 +28,7 @@ interface SessionsEmspInterface { * @param sessionId (max-length 36) id of the Session object to get from the eMSP’s system. * @return Session Requested Session object. */ - suspend fun getSession(countryCode: CiString, partyId: CiString, sessionId: CiString): OcpiResponseBody + suspend fun getSession(countryCode: CiString, partyId: CiString, sessionId: CiString): OcpiResponseBody /** * PUT Method @@ -73,6 +74,6 @@ interface SessionsEmspInterface { countryCode: CiString, partyId: CiString, sessionId: CiString, - session: Session + session: SessionPartial ): OcpiResponseBody } diff --git a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/sessions/SessionsEmspServer.kt b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/sessions/SessionsEmspServer.kt index b22bec8b..2327de27 100644 --- a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/sessions/SessionsEmspServer.kt +++ b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/sessions/SessionsEmspServer.kt @@ -4,6 +4,7 @@ import com.izivia.ocpi.toolkit.common.OcpiModuleServer import com.izivia.ocpi.toolkit.common.httpResponse import com.izivia.ocpi.toolkit.common.mapper import com.izivia.ocpi.toolkit.modules.sessions.domain.Session +import com.izivia.ocpi.toolkit.modules.sessions.domain.SessionPartial import com.izivia.ocpi.toolkit.transport.TransportServer import com.izivia.ocpi.toolkit.transport.domain.HttpMethod import com.izivia.ocpi.toolkit.transport.domain.VariablePathSegment @@ -68,7 +69,7 @@ class SessionsEmspServer( countryCode = req.pathParams["countryCode"]!!, partyId = req.pathParams["partyId"]!!, sessionId = req.pathParams["sessionId"]!!, - session = mapper.readValue(req.body, Session::class.java) + session = mapper.readValue(req.body, SessionPartial::class.java) ) } } diff --git a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/sessions/domain/ChargingPreferences.kt b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/sessions/domain/ChargingPreferences.kt index 62264190..b3cf2688 100644 --- a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/sessions/domain/ChargingPreferences.kt +++ b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/sessions/domain/ChargingPreferences.kt @@ -6,20 +6,20 @@ import java.time.Instant /** * Contains the charging preferences of an EV driver. * - * @property profile_type Type of Smart Charging Profile selected by the driver. The ProfileType has to be supported at + * @property profileType Type of Smart Charging Profile selected by the driver. The ProfileType has to be supported at * the Connector and for every supported ProfileType, a Tariff MUST be provided. This gives the EV driver the option * between different pricing options. - * @property departure_time Expected departure. The driver has given this Date/Time as expected departure moment. + * @property departureTime Expected departure. The driver has given this Date/Time as expected departure moment. * It is only an estimation and not necessarily the Date/Time of the actual departure. - * @property energy_need Requested amount of energy in kWh. The EV driver wants to have this amount of energy charged. - * @property discharge_allowed The driver allows their EV to be discharged when needed, as long as the other preferences + * @property energyNeed Requested amount of energy in kWh. The EV driver wants to have this amount of energy charged. + * @property dischargeAllowed The driver allows their EV to be discharged when needed, as long as the other preferences * are met: EV is charged with the preferred energy (energy_need) until the preferred departure moment (departure_time). * Default if omitted: false */ @Partial data class ChargingPreferences( - val profile_type: ProfileType, - val departure_time: Instant? = null, - val energy_need: Int? = null, - val discharge_allowed: Boolean? = false + val profileType: ProfileType, + val departureTime: Instant? = null, + val energyNeed: Int? = null, + val dischargeAllowed: Boolean? = false ) diff --git a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/sessions/domain/ChargingPreferencesResponseType.kt b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/sessions/domain/ChargingPreferencesResponseType.kt index a047da40..626beac3 100644 --- a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/sessions/domain/ChargingPreferencesResponseType.kt +++ b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/sessions/domain/ChargingPreferencesResponseType.kt @@ -27,5 +27,5 @@ enum class ChargingPreferencesResponseType { /** * profile_type contains a value that is not supported by the EVSE. */ - PROFILE_TYPE_NOT_SUPPORTED, + PROFILE_TYPE_NOT_SUPPORTED } diff --git a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/sessions/domain/ProfileType.kt b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/sessions/domain/ProfileType.kt index 3f6243f8..9419a526 100644 --- a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/sessions/domain/ProfileType.kt +++ b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/sessions/domain/ProfileType.kt @@ -20,5 +20,5 @@ enum class ProfileType { /** * Driver does not have special preferences. */ - REGULAR, + REGULAR } diff --git a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/sessions/domain/Session.kt b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/sessions/domain/Session.kt index ed2e005d..12744a64 100644 --- a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/sessions/domain/Session.kt +++ b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/sessions/domain/Session.kt @@ -1,5 +1,4 @@ -package com.izivia.ocpi.toolkit.modules.sessions.domain; - +package com.izivia.ocpi.toolkit.modules.sessions.domain import com.izivia.ocpi.toolkit.annotations.Partial import com.izivia.ocpi.toolkit.common.CiString @@ -34,59 +33,59 @@ import java.time.Instant * NOTE : Different authorization_reference values might happen when for example a ReserveNow had a different * authorization_reference then the value returned by a real-time authorization. * - * @property country_code (max-length 2) ISO-3166 alpha-2 country code of the MSP that 'owns' this Token. - * @property party_id (max-length 3) ID of the eMSP that 'owns' this Token (following the ISO-15118 standard). + * @property countryCode (max-length 2) ISO-3166 alpha-2 country code of the MSP that 'owns' this Token. + * @property partyId (max-length 3) ID of the eMSP that 'owns' this Token (following the ISO-15118 standard). * @property id (max-length 36) The unique id that identifies the charging session in the CPO platform. - * @property start_date_time The timestamp when the session became ACTIVE in the Charge Point. When the session is still + * @property startDateTime The timestamp when the session became ACTIVE in the Charge Point. When the session is still * PENDING, this field SHALL be set to thetime the Session was created at the Charge Point. When a Session goes from * PENDING to ACTIVE, this field SHALL be updated to the moment the Session went to ACTIVE in the Charge Point. - * @property end_date_time The timestamp when the session was completed/finished, charging might have finished before + * @property endDateTime The timestamp when the session was completed/finished, charging might have finished before * the session ends, for example: EV is full, but parking cost also has to be paid. * @property kwh How many kWh were charged. - * @property cdr_token Token used to start this charging session, including all the relevant information to identify the unique token. - * @property auth_method Method used for authentication. This might change during a session, for example when the + * @property cdrToken Token used to start this charging session, including all the relevant information to identify the unique token. + * @property authMethod Method used for authentication. This might change during a session, for example when the * session was started with a reservation: ReserveNow: COMMAND. When the driver arrives and starts charging using a * Token that is whitelisted: WHITELIST. - * @property authorization_reference (max-length 36) Reference to the authorization given by the eMSP. When the eMSP + * @property authorizationReference (max-length 36) Reference to the authorization given by the eMSP. When the eMSP * provided an authorization_reference in either: real-time authorization, StartSession or ReserveNow this field SHALL * contain the same value . When different authorization_reference values have been given by the eMSP that are relevant * to this Session, the last given value SHALL be used here. - * @property location_id (max-length 36) Location.id of the Location object of this CO, on which the charging session is/was happening. - * @property evse_uid (max-length 36) EVSE.uid of the EVSE of this Location on which the charging + * @property locationId (max-length 36) Location.id of the Location object of this CO, on which the charging session is/was happening. + * @property evseUid (max-length 36) EVSE.uid of the EVSE of this Location on which the charging * session is/was happening. Allowed to be set to: #NA when this session is created for a reservation, but no EVSE yet * assigned to the driver. - * @property connector_id (max-length 36) Connector.id of the Connector of this Location where the charging + * @property connectorId (max-length 36) Connector.id of the Connector of this Location where the charging * session is/was happening. Allowed to be set to: #NA when this session is created for a reservation, but no connector * yet assigned to the driver. - * @property meter_id (max-length 255) Optional identification of the kWh meter. + * @property meterId (max-length 255) Optional identification of the kWh meter. * @property currency (max-length 3) ISO 4217 code of the currency used for this session. - * @property charging_periods An optional list of Charging Periods that can be used to calculate + * @property chargingPeriods An optional list of Charging Periods that can be used to calculate * and verify the total cost. - * @property total_cost The total cost of the session in the specified currency. This is the price that the eMSP will + * @property totalCost The total cost of the session in the specified currency. This is the price that the eMSP will * have to pay to the CPO. A total_cost of 0.00 means free of charge. When omitted, i.e. no price information is given * in the Session object, it does not imply the session is/was free of charge. * @property status The status of the session. - * @property last_updated Timestamp when this Session was last updated (or created). + * @property lastUpdated Timestamp when this Session was last updated (or created). */ @Partial data class Session( - val country_code: CiString, - val party_id: CiString, + val countryCode: CiString, + val partyId: CiString, val id: CiString, - val start_date_time: Instant, - val end_date_time: Instant? = null, + val startDateTime: Instant, + val endDateTime: Instant? = null, val kwh: Int, - val cdr_token: CdrToken, - val auth_method: AuthMethod, - val authorization_reference: CiString? = null, - val location_id: CiString, - val evse_uid: CiString, - val connector_id: CiString, - val meter_id: String? = null, + val cdrToken: CdrToken, + val authMethod: AuthMethod, + val authorizationReference: CiString? = null, + val locationId: CiString, + val evseUid: CiString, + val connectorId: CiString, + val meterId: String? = null, val currency: CiString, - val charging_periods: List? = emptyList(), - val total_cost: Price? = null, + val chargingPeriods: List? = emptyList(), + val totalCost: Price? = null, val status: SessionStatusType, - val last_updated: Instant, + val lastUpdated: Instant ) diff --git a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/sessions/domain/SessionStatusType.kt b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/sessions/domain/SessionStatusType.kt index 9e33fe10..604173c0 100644 --- a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/sessions/domain/SessionStatusType.kt +++ b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/sessions/domain/SessionStatusType.kt @@ -29,5 +29,5 @@ enum class SessionStatusType { * The session is started due to a reservation, charging has not yet started. The session might never * become an active session. */ - RESERVATION, + RESERVATION } diff --git a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/sessions/repositories/SessionsCpoRepository.kt b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/sessions/repositories/SessionsCpoRepository.kt index cd1d3c9c..35aa271b 100644 --- a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/sessions/repositories/SessionsCpoRepository.kt +++ b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/sessions/repositories/SessionsCpoRepository.kt @@ -7,7 +7,6 @@ import com.izivia.ocpi.toolkit.modules.sessions.domain.ChargingPreferencesRespon import com.izivia.ocpi.toolkit.modules.sessions.domain.Session import java.time.Instant - /** * Typically implemented by market roles like: CPO. * @@ -33,7 +32,7 @@ interface SessionsCpoRepository { * @return List The response contains a list of Session objects that match the given parameters in the request, the header will contain the * pagination related headers. */ - fun getSessions(dateFrom: Instant?, dateTo: Instant?, offset: Int = 0, limit: Int?): SearchResult + suspend fun getSessions(dateFrom: Instant?, dateTo: Instant?, offset: Int = 0, limit: Int?): SearchResult /** * PUT Method @@ -45,9 +44,8 @@ interface SessionsCpoRepository { * @param chargingPreferences Updated Charging Preferences of the driver for this Session. * @return ChargingPreferencesResponseType The response contains a ChargingPreferencesResponse value. */ - fun putChargingPreferences( + suspend fun putChargingPreferences( sessionId: CiString, chargingPreferences: ChargingPreferences ): ChargingPreferencesResponseType - } diff --git a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/sessions/repositories/SessionsEmspRepository.kt b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/sessions/repositories/SessionsEmspRepository.kt index 5f961d23..e5c15518 100644 --- a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/sessions/repositories/SessionsEmspRepository.kt +++ b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/sessions/repositories/SessionsEmspRepository.kt @@ -2,6 +2,7 @@ package com.izivia.ocpi.toolkit.modules.sessions.repositories import com.izivia.ocpi.toolkit.common.CiString import com.izivia.ocpi.toolkit.modules.sessions.domain.Session +import com.izivia.ocpi.toolkit.modules.sessions.domain.SessionPartial /** * Typically implemented by market roles like: eMSP and SCSP. @@ -27,7 +28,7 @@ interface SessionsEmspRepository { * @param sessionId (max-length 36) id of the Session object to get from the eMSP’s system. * @return Session Requested Session object. */ - fun getSession(countryCode: CiString, partyId: CiString, sessionId: CiString): Session + suspend fun getSession(countryCode: CiString, partyId: CiString, sessionId: CiString): Session? /** * PUT Method @@ -45,7 +46,7 @@ interface SessionsEmspRepository { * @param session New or updated Session object. * @return Session New or updated Session object. */ - fun putSession(countryCode: CiString, partyId: CiString, sessionId: CiString, session: Session): Session? + suspend fun putSession(countryCode: CiString, partyId: CiString, sessionId: CiString, session: Session): Session? /** * PATCH Method @@ -64,5 +65,10 @@ interface SessionsEmspRepository { * @param session New or updated Session object. * @return Session New or updated Session object. */ - fun patchSession(countryCode: CiString, partyId: CiString, sessionId: CiString, session: Session): Session? + suspend fun patchSession( + countryCode: CiString, + partyId: CiString, + sessionId: CiString, + session: SessionPartial + ): Session? } diff --git a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/sessions/services/SessionsCpoService.kt b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/sessions/services/SessionsCpoService.kt index c215adf3..26ff4bc4 100644 --- a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/sessions/services/SessionsCpoService.kt +++ b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/sessions/services/SessionsCpoService.kt @@ -40,6 +40,6 @@ class SessionsCpoService( validateLength("sessionId", sessionId, 36) chargingPreferences.validate() } - service.putChargingPreferences(sessionId, chargingPreferences) //nothing to validate + service.putChargingPreferences(sessionId, chargingPreferences) // nothing to validate } } diff --git a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/sessions/services/SessionsEmspService.kt b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/sessions/services/SessionsEmspService.kt index 2c8e2033..e5cbdabd 100644 --- a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/sessions/services/SessionsEmspService.kt +++ b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/sessions/services/SessionsEmspService.kt @@ -6,20 +6,26 @@ import com.izivia.ocpi.toolkit.common.validation.validate import com.izivia.ocpi.toolkit.common.validation.validateLength import com.izivia.ocpi.toolkit.modules.sessions.SessionsEmspInterface import com.izivia.ocpi.toolkit.modules.sessions.domain.Session +import com.izivia.ocpi.toolkit.modules.sessions.domain.SessionPartial import com.izivia.ocpi.toolkit.modules.sessions.repositories.SessionsEmspRepository class SessionsEmspService( private val service: SessionsEmspRepository ) : SessionsEmspInterface { - override suspend fun getSession(countryCode: CiString, partyId: CiString, sessionId: CiString): OcpiResponseBody = - OcpiResponseBody.of { - validate { - validateLength("countryCode", countryCode, 2) - validateLength("partyId", partyId, 3) - validateLength("sessionId", sessionId, 36) - } - service.getSession(countryCode, partyId, sessionId).validate() + override suspend fun getSession( + countryCode: CiString, + partyId: CiString, + sessionId: CiString + ): OcpiResponseBody = OcpiResponseBody.of { + validate { + validateLength("countryCode", countryCode, 2) + validateLength("partyId", partyId, 3) + validateLength("sessionId", sessionId, 36) } + service + .getSession(countryCode, partyId, sessionId) + ?.validate() + } override suspend fun putSession( countryCode: CiString, @@ -40,7 +46,7 @@ class SessionsEmspService( countryCode: CiString, partyId: CiString, sessionId: CiString, - session: Session + session: SessionPartial ): OcpiResponseBody = OcpiResponseBody.of { validate { session.validate() diff --git a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/sessions/services/SessionsValidators.kt b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/sessions/services/SessionsValidators.kt index cec6323f..48788f07 100644 --- a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/sessions/services/SessionsValidators.kt +++ b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/sessions/services/SessionsValidators.kt @@ -13,55 +13,55 @@ import java.math.BigDecimal import java.time.Instant fun SessionPartial.validate(): SessionPartial = validate(this) { - validate(SessionPartial::country_code).isCountryCode(caseSensitive = false, alpha2 = true) - validate(SessionPartial::party_id).isPrintableAscii().hasMaxLengthOf(3) + validate(SessionPartial::countryCode).isCountryCode(caseSensitive = false, alpha2 = true) + validate(SessionPartial::partyId).isPrintableAscii().hasMaxLengthOf(3) validate(SessionPartial::id).isPrintableAscii().hasMaxLengthOf(36) - validate(SessionPartial::start_date_time).isGreaterThan(Instant.now()) - validate(SessionPartial::end_date_time).isGreaterThan(it.start_date_time ?: Instant.now()) + validate(SessionPartial::startDateTime).isGreaterThan(Instant.now()) + validate(SessionPartial::endDateTime).isGreaterThan(it.startDateTime ?: Instant.now()) validate(SessionPartial::kwh).isGreaterThanOrEqualTo(0) - cdr_token?.validate() - //auth_method: nothing to validate - validate(SessionPartial::authorization_reference).isPrintableAscii().hasMaxLengthOf(36) - validate(SessionPartial::location_id).isPrintableAscii().hasMaxLengthOf(36) - validate(SessionPartial::evse_uid).isEvseId() - validate(SessionPartial::connector_id).isPrintableAscii().hasMaxLengthOf(36) - validate(SessionPartial::meter_id).isPrintableAscii().hasMaxLengthOf(255) + cdrToken?.validate() + // authMethod: nothing to validate + validate(SessionPartial::authorizationReference).isPrintableAscii().hasMaxLengthOf(36) + validate(SessionPartial::locationId).isPrintableAscii().hasMaxLengthOf(36) + validate(SessionPartial::evseUid).isEvseId() + validate(SessionPartial::connectorId).isPrintableAscii().hasMaxLengthOf(36) + validate(SessionPartial::meterId).isPrintableAscii().hasMaxLengthOf(255) validate(SessionPartial::currency).isCurrencyCode(false) - charging_periods?.forEach() { charging_period -> charging_period.validate() } - total_cost?.validate() - //status: nothing to validate - //last_updated: nothing to validate + chargingPeriods?.forEach { chargingPeriod -> chargingPeriod.validate() } + totalCost?.validate() + // status: nothing to validate + // lastUpdated: nothing to validate } fun ChargingPreferencesPartial.validate(): ChargingPreferencesPartial = validate(this) { - //profile_type nothing to validate - validate(ChargingPreferencesPartial::departure_time).isGreaterThan(Instant.now()) - validate(ChargingPreferencesPartial::energy_need).isGreaterThanOrEqualTo(0) - //discharge_allowed nothing to validate + // profileType nothing to validate + validate(ChargingPreferencesPartial::departureTime).isGreaterThan(Instant.now()) + validate(ChargingPreferencesPartial::energyNeed).isGreaterThanOrEqualTo(0) + // dischargeAllowed nothing to validate } fun CdrTokenPartial.validate(): CdrTokenPartial = validate(this) { - validate(CdrTokenPartial::country_code).isCountryCode(caseSensitive = false, alpha2 = true) - validate(CdrTokenPartial::party_id).isPrintableAscii().hasMaxLengthOf(3) + validate(CdrTokenPartial::countryCode).isCountryCode(caseSensitive = false, alpha2 = true) + validate(CdrTokenPartial::partyId).isPrintableAscii().hasMaxLengthOf(3) validate(CdrTokenPartial::uid).isPrintableAscii().hasMaxLengthOf(36) - //tokenType : nothing to validate - validate(CdrTokenPartial::contract_id).isPrintableAscii().hasMaxLengthOf(36) + // tokenType : nothing to validate + validate(CdrTokenPartial::contractId).isPrintableAscii().hasMaxLengthOf(36) } fun ChargingPeriodPartial.validate(): ChargingPeriodPartial = validate(this) { - validate(ChargingPeriodPartial::start_date_time).isGreaterThan(Instant.now()) - dimensions?.forEach() { dimension -> dimension.validate() } - validate(ChargingPeriodPartial::tariff_id).isPrintableAscii().hasMaxLengthOf(36) + validate(ChargingPeriodPartial::startDateTime).isGreaterThan(Instant.now()) + dimensions?.forEach { dimension -> dimension.validate() } + validate(ChargingPeriodPartial::tariffId).isPrintableAscii().hasMaxLengthOf(36) } fun CdrDimensionPartial.validate(): CdrDimensionPartial = validate(this) { - //cdrDimensionType : nothing to validate + // cdrDimensionType : nothing to validate validate(CdrDimensionPartial::volume).isGreaterThanOrEqualTo(BigDecimal.ZERO) } fun PricePartial.validate(): PricePartial = validate(this) { - validate(PricePartial::excl_vat).isGreaterThanOrEqualTo(BigDecimal.ZERO) - validate(PricePartial::incl_vat).isGreaterThanOrEqualTo(BigDecimal.ZERO) + validate(PricePartial::exclVat).isGreaterThanOrEqualTo(BigDecimal.ZERO) + validate(PricePartial::inclVat).isGreaterThanOrEqualTo(BigDecimal.ZERO) } fun Session.validate(): Session = validate(this) { diff --git a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tariff/domain/PriceComponent.kt b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tariff/domain/PriceComponent.kt index 61bbbc20..51500687 100644 --- a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tariff/domain/PriceComponent.kt +++ b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tariff/domain/PriceComponent.kt @@ -9,7 +9,7 @@ import java.math.BigDecimal * @property vat Applicable VAT percentage for this tariff dimension. If omitted, no VAT * is applicable. Not providing a VAT is different from 0% VAT, which would * be a value of 0.0 here. - * @property step_size Minimum amount to be billed. This unit will be billed in this step_size + * @property stepSize Minimum amount to be billed. This unit will be billed in this step_size * blocks. Amounts that are less then this step_size are rounded up to * the given step_size. For example: if type is TIME and step_size * has a value of 300, then time will be billed in blocks of 5 minutes. If 6 @@ -21,5 +21,5 @@ data class PriceComponent( val type: TariffDimensionType, val price: BigDecimal, val vat: BigDecimal? = null, - val step_size: Int + val stepSize: Int ) diff --git a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tariff/domain/ReservationRestrictionType.kt b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tariff/domain/ReservationRestrictionType.kt index f64e326c..1f1ba1ab 100644 --- a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tariff/domain/ReservationRestrictionType.kt +++ b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tariff/domain/ReservationRestrictionType.kt @@ -1,7 +1,5 @@ package com.izivia.ocpi.toolkit.modules.tariff.domain -import com.izivia.ocpi.toolkit.annotations.Partial - enum class ReservationRestrictionType { /** * Used in TariffElements to describe costs for a reservation @@ -10,7 +8,7 @@ enum class ReservationRestrictionType { /** *Used in TariffElements to describe costs for a reservation that expires (i.e. driver does not start a - charging session before expiry_date of the reservation). + charging session before expiry_date of the reservation). */ RESERVATION_EXPIRES } diff --git a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tariff/domain/Tariff.kt b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tariff/domain/Tariff.kt index 809e4612..c9d722e7 100644 --- a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tariff/domain/Tariff.kt +++ b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tariff/domain/Tariff.kt @@ -2,8 +2,8 @@ package com.izivia.ocpi.toolkit.modules.tariff.domain import com.izivia.ocpi.toolkit.annotations.Partial import com.izivia.ocpi.toolkit.common.CiString -import com.izivia.ocpi.toolkit.modules.types.DisplayText import com.izivia.ocpi.toolkit.modules.locations.domain.EnergyMix +import com.izivia.ocpi.toolkit.modules.types.DisplayText import com.izivia.ocpi.toolkit.modules.types.Price import java.time.Instant @@ -14,45 +14,45 @@ import java.time.Instant * @property id (max-length=36) Uniquely identifies the tariff within the CPO’s platform (and suboperator platforms). * @property type Defines the type of the tar iff. This allows for distinction in case of given Charging Preferences. * When omitted, this tariff is valid for all sessions - * @property party_id (max-length=3) CPO ID of the CPO that owns this Tariff (following the ISO-15118 standard). - * @property country_code (max-length=2) ISO-3166 alpha-2 country code of the CPO that owns this Tariff. + * @property partyId (max-length=3) CPO ID of the CPO that owns this Tariff (following the ISO-15118 standard). + * @property countryCode (max-length=2) ISO-3166 alpha-2 country code of the CPO that owns this Tariff. * @property currency (max-length=3) ISO-4217 code of the currency of this tariff. - * @property tariff_alt_text List of multi-language alternative tariff info texts. - * @property tariff_alt_url URL to a web page that contains an explanation of the tariff information in human readable + * @property tariffAltText List of multi-language alternative tariff info texts. + * @property tariffAltUrl URL to a web page that contains an explanation of the tariff information in human readable * form. - * @property min_price When this field is set, a Charging Session with this tariff will at least cost this + * @property minPrice When this field is set, a Charging Session with this tariff will at least cost this * amount. This is different from a FLAT fee (Start Tariff, Transaction Fee), as a * FLAT fee is a fixed amount that has to be paid for any Charging Session. A * minimum price indicates that when the cost of a Charging Session is lower than * this amount, the cost of the Session will be equal to this amount. (Also see note * below) - * @property max_price When this field is set, a Charging Session with this tariff will NOT cost more than + * @property maxPrice When this field is set, a Charging Session with this tariff will NOT cost more than * this amount. (See note below) * @property elements List of Tariff Elements. - * @property start_date_time The time when this tariff becomes active, in UTC, time_zone field of the Location can be + * @property startDateTime The time when this tariff becomes active, in UTC, time_zone field of the Location can be * used to convert to local time. Typically used for a new tariff that is already given with the location, before it * becomes active. (See note below) - * @property end_date_time The time after which this tariff is no longer valid, in UTC, time_zone field if the + * @property endDateTime The time after which this tariff is no longer valid, in UTC, time_zone field if the * Location can be used to convert to local time. Typically used when this tariff is * going to be replaced with a different tariff in the near future. (See note below) - * @property energy_mix Details on the energy supplied with this tariff - * @property last_updated Timestamp when this Tariff was last updated (or created). + * @property energyMix Details on the energy supplied with this tariff + * @property lastUpdated Timestamp when this Tariff was last updated (or created). */ @Partial data class Tariff( val id: CiString, val type: TariffType? = null, - val party_id: CiString, - val country_code: CiString, + val partyId: CiString, + val countryCode: CiString, val currency: String, - val tariff_alt_text: List? = null, - val tariff_alt_url: CiString? = null, - val min_price: Price? = null, - val max_price: Price? = null, + val tariffAltText: List? = null, + val tariffAltUrl: CiString? = null, + val minPrice: Price? = null, + val maxPrice: Price? = null, val elements: List, - val start_date_time: Instant? = null, - val end_date_time: Instant? = null, - val energy_mix: EnergyMix? = null, - val last_updated: Instant, + val startDateTime: Instant? = null, + val endDateTime: Instant? = null, + val energyMix: EnergyMix? = null, + val lastUpdated: Instant ) diff --git a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tariff/domain/TariffDimensionType.kt b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tariff/domain/TariffDimensionType.kt index db861672..e937a7b1 100644 --- a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tariff/domain/TariffDimensionType.kt +++ b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tariff/domain/TariffDimensionType.kt @@ -1,7 +1,5 @@ package com.izivia.ocpi.toolkit.modules.tariff.domain -import com.izivia.ocpi.toolkit.annotations.Partial - enum class TariffDimensionType { /** * Defined in kWh, step_size multiplier: 1 Wh diff --git a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tariff/domain/TariffElement.kt b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tariff/domain/TariffElement.kt index 412c805e..d5808580 100644 --- a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tariff/domain/TariffElement.kt +++ b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tariff/domain/TariffElement.kt @@ -3,12 +3,12 @@ package com.izivia.ocpi.toolkit.modules.tariff.domain import com.izivia.ocpi.toolkit.annotations.Partial /** - * @property price_components List of price components that describe the pricing of a tariff. + * @property priceComponents List of price components that describe the pricing of a tariff. * @property restrictions Restrictions that describe the applicability of a tariff. */ @Partial data class TariffElement( - val price_components: List, - val restrictions: TariffRestrictions? = null, + val priceComponents: List, + val restrictions: TariffRestrictions? = null ) diff --git a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tariff/domain/TariffRestrictions.kt b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tariff/domain/TariffRestrictions.kt index 6773d9ff..f89ce6cb 100644 --- a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tariff/domain/TariffRestrictions.kt +++ b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tariff/domain/TariffRestrictions.kt @@ -8,30 +8,30 @@ import java.time.DayOfWeek * These restrictions are not for the entire Charging Session. They only describe if and when a TariffElement becomes active or * inactive during a Charging Session. * - *@property start_time Start time of day in local time, the time zone is defined in the time_zone field of + * @property startTime Start time of day in local time, the time zone is defined in the time_zone field of * the Location, for example 13:30, valid from this time of the day. Must be in 24h * format with leading zeros. Hour/Minute separator: ":" Regex: ([0-1][0-9]|2[0-3]):[0-5][0-9] * - * @property end_time End time of day in local time, the time zone is defined in the time_zone field of + * @property endTime End time of day in local time, the time zone is defined in the time_zone field of * the Location, for example 19:45, valid until this time of the day. Same syntax as * start_time. If end_time < start_time then the period wraps around to the next * day. To stop at end of the day use: 00:00. * - * @property start_date Start date in local time, the time zone is defined in the time_zone field of the + * @property startDate Start date in local time, the time zone is defined in the time_zone field of the * Location, for example: 2015-12-24, valid from this day (inclusive). * Regex:([12][0-9]{3})-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01]) * - * @property end_date End date in local time, the time zone is defined in the time_zone field of the + * @property endDate End date in local time, the time zone is defined in the time_zone field of the * Location, for example: 2015-12-27, valid until this day (exclusive). Same syntax * as start_date. * - * @property min_kwh Minimum consumed energy in kWh, for example 20, valid from this amount of + * @property minKwh Minimum consumed energy in kWh, for example 20, valid from this amount of * energy (inclusive) being used. * - * @property max_kwh Maximum consumed energy in kWh, for example 50, valid until this amount of + * @property maxKwh Maximum consumed energy in kWh, for example 50, valid until this amount of * energy (exclusive) being used. * - * @property min_current Sum of the minimum current (in Amperes) over all phases, for example 5. When + * @property minCurrent Sum of the minimum current (in Amperes) over all phases, for example 5. When the EV is charging with more than, or equal to, the defined amount of current this TariffElement is/becomes active. If the charging current is or becomes lower, this TariffElement is not or no longer valid and becomes inactive. This describes @@ -40,7 +40,7 @@ make a TariffElement become active when the charging current is above the defined value, but the TariffElement MUST no longer be active when the charging current drops below the defined value. * - * @property max_current Sum of the maximum current (in Amperes) over all phases, for example 20. + * @property maxCurrent Sum of the maximum current (in Amperes) over all phases, for example 20. When the EV is charging with less than the defined amount of current, this TariffElement becomes/is active. If the charging current is or becomes higher, this TariffElement is not or no longer valid and becomes inactive. This describes @@ -49,7 +49,7 @@ make a TariffElement become active when the charging current is below this value, but the TariffElement MUST no longer be active when the charging current raises above the defined value * - * @property min_power Minimum power in kW, for example 5. When the EV is charging with more than, + * @property minPower Minimum power in kW, for example 5. When the EV is charging with more than, or equal to, the defined amount of power, this TariffElement is/becomes active. If the charging power is or becomes lower, this TariffElement is not or no longer valid and becomes inactive. This describes NOT the minimum power over the @@ -57,7 +57,7 @@ entire Charging Session. This restriction can make a TariffElement become active when the charging power is above this value, but the TariffElement MUST no longer be active when the charging power drops below the defined value. * - * @property max_power Maximum power in kW, for example 20. When the EV is charging with less than + * @property maxPower Maximum power in kW, for example 20. When the EV is charging with less than the defined amount of power, this TariffElement becomes/is active. If the charging power is or becomes higher, this TariffElement is not or no longer valid and becomes inactive. This describes NOT the maximum power over the entire @@ -65,17 +65,17 @@ Charging Session. This restriction can make a TariffElement become active when the charging power is below this value, but the TariffElement MUST no longer be active when the charging power raises above the defined value * - * @property min_duration Minimum duration in seconds the Charging Session MUST last (inclusive). + * @property minDuration Minimum duration in seconds the Charging Session MUST last (inclusive). When the duration of a Charging Session is longer than the defined value, this TariffElement is or becomes active. Before that moment, this TariffElement is not yet active. * - * @property max_duration Maximum duration in seconds the Charging Session MUST last (exclusive). + * @property maxDuration Maximum duration in seconds the Charging Session MUST last (exclusive). When the duration of a Charging Session is shorter than the defined value, this TariffElement is or becomes active. After that moment, this TariffElement is no longer active. * - * @property day_of_week Which day(s) of the week this TariffElement is active. + * @property dayOfWeek Which day(s) of the week this TariffElement is active. * * @property reservation When this field is present, the TariffElement describes reservation costs. A reservation starts when the reservation is made, and ends when the driver @@ -87,18 +87,18 @@ TIME is for the duration of the reservation @Partial data class TariffRestrictions( - val start_time: String? = null, - val end_time: String? = null, - val start_date: String? = null, - val end_date: String? = null, - val min_kwh: BigDecimal? = null, - val max_kwh: BigDecimal? = null, - val min_current: BigDecimal? = null, - val max_current: BigDecimal? = null, - val min_power: BigDecimal? = null, - val max_power: BigDecimal? = null, - val min_duration: Int? = null, - val max_duration: Int? = null, - val day_of_week: List? = null, - val reservation: ReservationRestrictionType? = null, + val startTime: String? = null, + val endTime: String? = null, + val startDate: String? = null, + val endDate: String? = null, + val minKwh: BigDecimal? = null, + val maxKwh: BigDecimal? = null, + val minCurrent: BigDecimal? = null, + val maxCurrent: BigDecimal? = null, + val minPower: BigDecimal? = null, + val maxPower: BigDecimal? = null, + val minDuration: Int? = null, + val maxDuration: Int? = null, + val dayOfWeek: List? = null, + val reservation: ReservationRestrictionType? = null ) diff --git a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tariff/domain/TariffType.kt b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tariff/domain/TariffType.kt index ff1ccfd4..1815a0c4 100644 --- a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tariff/domain/TariffType.kt +++ b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tariff/domain/TariffType.kt @@ -1,7 +1,5 @@ package com.izivia.ocpi.toolkit.modules.tariff.domain -import com.izivia.ocpi.toolkit.annotations.Partial - enum class TariffType { /** *Used to describe that a Tariff is valid when ad-hoc payment is used at the Charge Point (for example: Debit or diff --git a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/TokensCpoClient.kt b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/TokensCpoClient.kt index 2e2e7ba8..b6858e7e 100644 --- a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/TokensCpoClient.kt +++ b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/TokensCpoClient.kt @@ -1,7 +1,7 @@ package com.izivia.ocpi.toolkit.modules.tokens import com.izivia.ocpi.toolkit.common.* -import com.izivia.ocpi.toolkit.modules.credentials.repositories.PlatformRepository +import com.izivia.ocpi.toolkit.modules.credentials.repositories.PartnerRepository import com.izivia.ocpi.toolkit.modules.tokens.domain.AuthorizationInfo import com.izivia.ocpi.toolkit.modules.tokens.domain.LocationReferences import com.izivia.ocpi.toolkit.modules.tokens.domain.Token @@ -16,19 +16,19 @@ import java.time.Instant /** * Sends calls to an eMSP server * @property transportClientBuilder used to build transport client - * @property serverVersionsEndpointUrl used to know which platform to communicate with - * @property platformRepository used to get information about the platform (endpoint, token) + * @property serverVersionsEndpointUrl used to know which partner to communicate with + * @property partnerRepository used to get information about the partner (endpoint, token) */ class TokensCpoClient( private val transportClientBuilder: TransportClientBuilder, private val serverVersionsEndpointUrl: String, - private val platformRepository: PlatformRepository + private val partnerRepository: PartnerRepository ) : TokensEmspInterface { private suspend fun buildTransport(): TransportClient = transportClientBuilder .buildFor( module = ModuleID.tokens, - platformUrl = serverVersionsEndpointUrl, - platformRepository = platformRepository + partnerUrl = serverVersionsEndpointUrl, + partnerRepository = partnerRepository ) override suspend fun getTokens( @@ -52,7 +52,7 @@ class TokensCpoClient( requestId = generateRequestId(), correlationId = generateCorrelationId() ) - .authenticate(platformRepository = platformRepository, platformUrl = serverVersionsEndpointUrl) + .authenticate(partnerRepository = partnerRepository, partnerUrl = serverVersionsEndpointUrl) ) .parsePaginatedBody(offset) } @@ -74,7 +74,7 @@ class TokensCpoClient( requestId = generateRequestId(), correlationId = generateCorrelationId() ) - .authenticate(platformRepository = platformRepository, platformUrl = serverVersionsEndpointUrl) + .authenticate(partnerRepository = partnerRepository, partnerUrl = serverVersionsEndpointUrl) ).parseBody() } } diff --git a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/TokensCpoServer.kt b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/TokensCpoServer.kt index 6fea81aa..a7393619 100644 --- a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/TokensCpoServer.kt +++ b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/TokensCpoServer.kt @@ -9,7 +9,6 @@ import com.izivia.ocpi.toolkit.modules.tokens.domain.TokenType import com.izivia.ocpi.toolkit.transport.TransportServer import com.izivia.ocpi.toolkit.transport.domain.HttpMethod import com.izivia.ocpi.toolkit.transport.domain.VariablePathSegment -import java.time.Instant /** * Receives calls from a CPO @@ -20,8 +19,7 @@ class TokensCpoServer( basePath: String = "/2.2.1/tokens" ) : OcpiModuleServer(basePath) { override suspend fun registerOn(transportServer: TransportServer) { - - //Get Method + // Get Method transportServer.handle( method = HttpMethod.GET, path = basePathSegments + listOf( @@ -37,12 +35,12 @@ class TokensCpoServer( countryCode = req.pathParams["countryCode"]!!, partyId = req.pathParams["partyId"]!!, tokenUid = req.pathParams["tokenUid"]!!, - type = req.queryParams["type"]?.run(TokenType::valueOf) ?: TokenType.RFID, + type = req.queryParams["type"]?.run(TokenType::valueOf) ?: TokenType.RFID ) } } - //Put Method + // Put Method transportServer.handle( method = HttpMethod.PUT, path = basePathSegments + listOf( @@ -63,7 +61,7 @@ class TokensCpoServer( ) } } - //Patch Method + // Patch Method transportServer.handle( method = HttpMethod.PATCH, path = basePathSegments + listOf( diff --git a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/TokensEmspClient.kt b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/TokensEmspClient.kt index b6a8158c..92ce6d84 100644 --- a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/TokensEmspClient.kt +++ b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/TokensEmspClient.kt @@ -1,7 +1,7 @@ package com.izivia.ocpi.toolkit.modules.tokens import com.izivia.ocpi.toolkit.common.* -import com.izivia.ocpi.toolkit.modules.credentials.repositories.PlatformRepository +import com.izivia.ocpi.toolkit.modules.credentials.repositories.PartnerRepository import com.izivia.ocpi.toolkit.modules.tokens.domain.Token import com.izivia.ocpi.toolkit.modules.tokens.domain.TokenPartial import com.izivia.ocpi.toolkit.modules.tokens.domain.TokenType @@ -14,20 +14,20 @@ import com.izivia.ocpi.toolkit.transport.domain.HttpRequest /** * Sends calls to the CPO * @property transportClientBuilder used to build transport client - * @property serverVersionsEndpointUrl used to know which platform to communicate with - * @property platformRepository used to get information about the platform (endpoint, token) + * @property serverVersionsEndpointUrl used to know which partner to communicate with + * @property partnerRepository used to get information about the partner (endpoint, token) */ class TokensEmspClient( private val transportClientBuilder: TransportClientBuilder, private val serverVersionsEndpointUrl: String, - private val platformRepository: PlatformRepository + private val partnerRepository: PartnerRepository ) : TokensCpoInterface { private suspend fun buildTransport(): TransportClient = transportClientBuilder .buildFor( module = ModuleID.tokens, - platformUrl = serverVersionsEndpointUrl, - platformRepository = platformRepository + partnerUrl = serverVersionsEndpointUrl, + partnerRepository = partnerRepository ) override suspend fun getToken( @@ -47,7 +47,7 @@ class TokensEmspClient( requestId = generateRequestId(), correlationId = generateCorrelationId() ) - .authenticate(platformRepository = platformRepository, platformUrl = serverVersionsEndpointUrl) + .authenticate(partnerRepository = partnerRepository, partnerUrl = serverVersionsEndpointUrl) ).parseBody() } @@ -74,7 +74,7 @@ class TokensEmspClient( requestId = generateRequestId(), correlationId = generateCorrelationId() ) - .authenticate(platformRepository = platformRepository, platformUrl = serverVersionsEndpointUrl) + .authenticate(partnerRepository = partnerRepository, partnerUrl = serverVersionsEndpointUrl) ).parseBody() } @@ -101,7 +101,7 @@ class TokensEmspClient( requestId = generateRequestId(), correlationId = generateCorrelationId() ) - .authenticate(platformRepository = platformRepository, platformUrl = serverVersionsEndpointUrl) + .authenticate(partnerRepository = partnerRepository, partnerUrl = serverVersionsEndpointUrl) ).parseBody() } } diff --git a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/TokensEmspInterface.kt b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/TokensEmspInterface.kt index d8e15dca..59e45f1c 100644 --- a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/TokensEmspInterface.kt +++ b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/TokensEmspInterface.kt @@ -1,4 +1,4 @@ -package com.izivia.ocpi.toolkit.modules.tokens; +package com.izivia.ocpi.toolkit.modules.tokens import com.izivia.ocpi.toolkit.common.CiString import com.izivia.ocpi.toolkit.common.OcpiResponseBody @@ -7,7 +7,7 @@ import com.izivia.ocpi.toolkit.modules.tokens.domain.AuthorizationInfo import com.izivia.ocpi.toolkit.modules.tokens.domain.LocationReferences import com.izivia.ocpi.toolkit.modules.tokens.domain.Token import com.izivia.ocpi.toolkit.modules.tokens.domain.TokenType -import java.time.Instant; +import java.time.Instant /** * Typically implemented by market roles like: eMSP. @@ -41,8 +41,12 @@ interface TokensEmspInterface { * Any older information that is not specified in the response is considered as no longer valid. Each object must contain all required * fields. Fields that are not specified may be considered as null values. */ - suspend fun getTokens(dateFrom: Instant?, dateTo: Instant?, offset: Int = 0, limit: Int?): OcpiResponseBody> - + suspend fun getTokens( + dateFrom: Instant?, + dateTo: Instant?, + offset: Int = 0, + limit: Int? + ): OcpiResponseBody> /** * POST Method diff --git a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/TokensEmspServer.kt b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/TokensEmspServer.kt index 66a68758..f4afb319 100644 --- a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/TokensEmspServer.kt +++ b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/TokensEmspServer.kt @@ -20,8 +20,7 @@ class TokensEmspServer( basePath: String = "/2.2.1/tokens" ) : OcpiModuleServer(basePath) { override suspend fun registerOn(transportServer: TransportServer) { - - //GET Token + // GET Token transportServer.handle( method = HttpMethod.GET, path = basePathSegments, @@ -41,7 +40,7 @@ class TokensEmspServer( } } - //POST token + // POST token transportServer.handle( method = HttpMethod.POST, path = basePathSegments + listOf( @@ -50,15 +49,15 @@ class TokensEmspServer( ), queryParams = listOf("type") ) { req -> - req.httpResponse { - service.postToken( - tokenUid = req.pathParams["tokenUid"]!!, - type = req.queryParams["type"]?.let { enumValueOf(it) } ?: TokenType.RFID, - locationReferences = req.body - ?.takeIf { it.isNotBlank() } // During Test if client sent body = null, this reiceve body="" - ?.let { mapper.readValue(it, LocationReferences::class.java) } - ) - } + req.httpResponse { + service.postToken( + tokenUid = req.pathParams["tokenUid"]!!, + type = req.queryParams["type"]?.let { enumValueOf(it) } ?: TokenType.RFID, + locationReferences = req.body + ?.takeIf { it.isNotBlank() } // During Test if client sent body = null, this reiceve body="" + ?.let { mapper.readValue(it, LocationReferences::class.java) } + ) + } } } } diff --git a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/domain/AuthorizationInfo.kt b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/domain/AuthorizationInfo.kt index 9aec38a0..fd6533da 100644 --- a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/domain/AuthorizationInfo.kt +++ b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/domain/AuthorizationInfo.kt @@ -11,7 +11,7 @@ import com.izivia.ocpi.toolkit.modules.types.DisplayText * @property location Optional reference to the location if it was included in the request, and if * the EV driver is allowed to charge at that location. Only the EVSEs the * EV driver is allowed to charge at are returned. - * @property authorization_reference (max-length 36) Reference to the authorization given by the eMSP, when given, this + * @property authorizationReference (max-length 36) Reference to the authorization given by the eMSP, when given, this * reference will be provided in the relevant Session and/or CDR. * @property info Optional display text, additional information to the EV driver. * @@ -22,6 +22,6 @@ data class AuthorizationInfo( val allowed: AllowedType, val token: Token, val location: LocationReferences? = null, - val authorization_reference: CiString? = null, + val authorizationReference: CiString? = null, val info: DisplayText? = null ) diff --git a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/domain/EnergyContract.kt b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/domain/EnergyContract.kt index d72c3b22..bf6968bc 100644 --- a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/domain/EnergyContract.kt +++ b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/domain/EnergyContract.kt @@ -6,13 +6,13 @@ import com.izivia.ocpi.toolkit.annotations.Partial * Information about a energy contract that belongs to a Token so a driver could use his/her own energy contract when charging at a * Charge Point. * - * @property supplier_name (max-length 64) Name of the energy supplier for this token. - * @property contract_id (max-length 64) Contract ID at the energy supplier, that belongs to the owner of this token. + * @property supplierName (max-length 64) Name of the energy supplier for this token. + * @property contractId (max-length 64) Contract ID at the energy supplier, that belongs to the owner of this token. * * @constructor */ @Partial data class EnergyContract( - val supplier_name: String, - val contract_id: String? + val supplierName: String, + val contractId: String? ) diff --git a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/domain/LocationReferences.kt b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/domain/LocationReferences.kt index 54e3f9d8..11d390bb 100644 --- a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/domain/LocationReferences.kt +++ b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/domain/LocationReferences.kt @@ -6,13 +6,13 @@ import com.izivia.ocpi.toolkit.common.CiString /** * References to location details. * - * @property location_id (max-length 36) Unique identifier for the location. - * @property evse_uids (max-length 36) Unique identifiers for EVSEs within the CPO’s platform for the EVSE within the + * @property locationId (max-length 36) Unique identifier for the location. + * @property evseUids (max-length 36) Unique identifiers for EVSEs within the CPO’s platform for the EVSE within the * given location. * @constructor */ @Partial data class LocationReferences( - val location_id: CiString, - val evse_uids: List + val locationId: CiString, + val evseUids: List ) diff --git a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/domain/Token.kt b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/domain/Token.kt index 3b611ad2..b007c023 100644 --- a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/domain/Token.kt +++ b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/domain/Token.kt @@ -12,8 +12,8 @@ import java.time.Instant * maximum length of string(20), case insensitive. As long as EV-driver can be expected to charge at an OCPP * 1.5/1.6 Charge Point, it is adviced to not used a group_id longer then 20. * - * @property country_code (max-length 2) ISO-3166 alpha-2 country code of the MSP that 'owns' this Token. - * @property party_id (max-length 3) ID of the eMSP that 'owns' this Token (following the ISO-15118 standard). + * @property countryCode (max-length 2) ISO-3166 alpha-2 country code of the MSP that 'owns' this Token. + * @property partyId (max-length 3) ID of the eMSP that 'owns' this Token (following the ISO-15118 standard). * @property uid (max-length 36) Unique ID by which this Token, combined with the Token type, can be identified. * This is the field used by CPO system (RFID reader on the Charge Point) to * identify this token. @@ -23,15 +23,15 @@ import java.time.Instant * generated ID. * This field is named uid instead of id to prevent confusion with: contract_id. * @property type Type of the token - * @property contract_id (max-length 36) Uniquely identifies the EV Driver contract token within the eMSP’s platform (and + * @property contractId (max-length 36) Uniquely identifies the EV Driver contract token within the eMSP’s platform (and * suboperator platforms). Recommended to follow the specification for eMA ID * from "eMI3 standard version V1.0" (http://emi3group.com/documents-links/) * "Part 2: business objects." - * @property visual_number (max-length 64) Visual readable number/identification as printed on the Token (RFID card), might + * @property visualNumber (max-length 64) Visual readable number/identification as printed on the Token (RFID card), might * be equal to the contract_id. * @property issuer (max-length 64) Issuing company, most of the times the name of the company printed on the * token (RFID card), not necessarily the eMSP. - * @property group_id (max-length 36) This ID groups a couple of tokens. This can be used to make two or more + * @property groupId (max-length 36) This ID groups a couple of tokens. This can be used to make two or more * tokens work as one, so that a session can be started with one token and * stopped with another, handy when a card and key-fob are given to the EV-driver. * Beware that OCPP 1.5/1.6 only support group_ids (it is called parentId in OCPP @@ -41,33 +41,33 @@ import java.time.Instant * @property language (max-length 2) Language Code ISO 639-1. This optional field indicates the Token owner’s * preferred interface language. If the language is not provided or not supported * then the CPO is free to choose its own language. - * @property default_profile_type The default Charging Preference. When this is provided, and a charging session + * @property defaultProfileType The default Charging Preference. When this is provided, and a charging session * is started on an Charge Point that support Preference base Smart Charging and * support this ProfileType, the Charge Point can start using this ProfileType, * without this having to be set via: Set Charging Preferences. - * @property energy_contract When the Charge Point supports using your own energy supplier/contract at a + * @property energyContract When the Charge Point supports using your own energy supplier/contract at a * Charge Point, information about the energy supplier/contract is needed so the * CPO knows which energy supplier to use. * NOTE: In a lot of countries it is currently not allowed/possible to use a drivers * own energy supplier/contract at a Charge Point. - * @property last_updated Timestamp when this Token was last updated (or created). + * @property lastUpdated Timestamp when this Token was last updated (or created). * * @constructor */ @Partial data class Token( - val country_code: CiString, - val party_id: CiString, + val countryCode: CiString, + val partyId: CiString, val uid: CiString, val type: TokenType, - val contract_id: CiString, - val visual_number: String? = null, + val contractId: CiString, + val visualNumber: String? = null, val issuer: String, - val group_id: CiString? = null, + val groupId: CiString? = null, val valid: Boolean, val whitelist: WhitelistType, val language: String? = null, - val default_profile_type: ProfileType? = null, - val energy_contract: EnergyContract? = null, - val last_updated: Instant + val defaultProfileType: ProfileType? = null, + val energyContract: EnergyContract? = null, + val lastUpdated: Instant ) diff --git a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/domain/TokenType.kt b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/domain/TokenType.kt index daf0839d..5538b8d2 100644 --- a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/domain/TokenType.kt +++ b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/domain/TokenType.kt @@ -27,4 +27,4 @@ enum class TokenType { * RFID Token */ RFID -} \ No newline at end of file +} diff --git a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/domain/WhitelistType.kt b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/domain/WhitelistType.kt index eb7ca26f..234c920e 100644 --- a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/domain/WhitelistType.kt +++ b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/domain/WhitelistType.kt @@ -29,5 +29,5 @@ enum class WhitelistType { * Whitelisting is forbidden, only realtime authorization is allowed. CPO shall always send a realtime * authorization for any use of this Token to the eMSP. */ - NEVER, + NEVER } diff --git a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/repositories/TokensCpoRepository.kt b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/repositories/TokensCpoRepository.kt index 50347737..4e81b9bb 100644 --- a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/repositories/TokensCpoRepository.kt +++ b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/repositories/TokensCpoRepository.kt @@ -33,7 +33,12 @@ interface TokensCpoRepository { * @param type Token.type of the Token to retrieve. Default if omitted: RFID * @return The requested Token object. */ - fun getToken(countryCode: CiString, partyId: CiString, tokenUid: CiString, type: TokenType? = TokenType.RFID): Token + suspend fun getToken( + countryCode: CiString, + partyId: CiString, + tokenUid: CiString, + type: TokenType? = TokenType.RFID + ): Token /** * PUT Method @@ -51,7 +56,7 @@ interface TokensCpoRepository { * @param type (Request parameter) Token.type of the Token of the (new) Token object (to replace). Default if omitted: * RFID */ - fun putToken( + suspend fun putToken( token: Token, countryCode: CiString, partyId: CiString, @@ -78,7 +83,7 @@ interface TokensCpoRepository { * @param type (Request parameter) Token.type of the Token of the (new) Token object (to replace). Default if omitted: * RFID */ - fun patchToken( + suspend fun patchToken( token: TokenPartial, countryCode: CiString, partyId: CiString, diff --git a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/repositories/TokensEmspRepository.kt b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/repositories/TokensEmspRepository.kt index 902e1a25..72443a91 100644 --- a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/repositories/TokensEmspRepository.kt +++ b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/repositories/TokensEmspRepository.kt @@ -1,4 +1,4 @@ -package com.izivia.ocpi.toolkit.modules.tokens.repositories; +package com.izivia.ocpi.toolkit.modules.tokens.repositories import com.izivia.ocpi.toolkit.common.CiString import com.izivia.ocpi.toolkit.common.SearchResult @@ -6,7 +6,7 @@ import com.izivia.ocpi.toolkit.modules.tokens.domain.AuthorizationInfo import com.izivia.ocpi.toolkit.modules.tokens.domain.LocationReferences import com.izivia.ocpi.toolkit.modules.tokens.domain.Token import com.izivia.ocpi.toolkit.modules.tokens.domain.TokenType -import java.time.Instant; +import java.time.Instant /** * Typically implemented by market roles like: eMSP. @@ -40,8 +40,7 @@ interface TokensEmspRepository { * Any older information that is not specified in the response is considered as no longer valid. Each object must contain all required * fields. Fields that are not specified may be considered as null values. */ - fun getTokens(dateFrom: Instant?, dateTo: Instant?, offset: Int = 0, limit: Int?): SearchResult - + suspend fun getTokens(dateFrom: Instant?, dateTo: Instant?, offset: Int = 0, limit: Int?): SearchResult /** * POST Method @@ -70,7 +69,7 @@ interface TokensEmspRepository { * optionally which EVSEs are allowed to be used. */ - fun postToken( + suspend fun postToken( tokenUid: CiString, type: TokenType? = TokenType.RFID, locationReferences: LocationReferences? = null diff --git a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/services/TokenValidators.kt b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/services/TokenValidators.kt index c03d0caf..2d4d230e 100644 --- a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/services/TokenValidators.kt +++ b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/services/TokenValidators.kt @@ -12,42 +12,42 @@ fun AuthorizationInfoPartial.validate(): AuthorizationInfoPartial = validate(thi // allowed : nothing to validate token?.validate() location?.validate() - validate(AuthorizationInfoPartial::authorization_reference).isPrintableAscii().hasMaxLengthOf(36) + validate(AuthorizationInfoPartial::authorizationReference).isPrintableAscii().hasMaxLengthOf(36) info?.validate() } fun TokenPartial.validate(): TokenPartial = validate(this) { - validate(TokenPartial::country_code).isCountryCode(caseSensitive = false, alpha2 = true) - validate(TokenPartial::party_id).isPrintableAscii().hasMaxLengthOf(3) + validate(TokenPartial::countryCode).isCountryCode(caseSensitive = false, alpha2 = true) + validate(TokenPartial::partyId).isPrintableAscii().hasMaxLengthOf(3) validate(TokenPartial::uid).isPrintableAscii().hasMaxLengthOf(36) - //type : nothing to validate - validate(TokenPartial::contract_id).isPrintableAscii().hasMaxLengthOf(36) - validate(TokenPartial::visual_number).isPrintableAscii().hasMaxLengthOf(64) + // type : nothing to validate + validate(TokenPartial::contractId).isPrintableAscii().hasMaxLengthOf(36) + validate(TokenPartial::visualNumber).isPrintableAscii().hasMaxLengthOf(64) validate(TokenPartial::issuer).isPrintableAscii().hasMaxLengthOf(64) - validate(TokenPartial::group_id).isPrintableAscii().hasMaxLengthOf(36) + validate(TokenPartial::groupId).isPrintableAscii().hasMaxLengthOf(36) // valid : nothing to validate // whitelist : nothing to validate validate(TokenPartial::language).isPrintableAscii().hasMaxLengthOf(2) - // default_profile_type : nothing to validate - energy_contract?.validate() - // last_updated: nothing to validate + // defaultProfileType : nothing to validate + energyContract?.validate() + // lastUpdated: nothing to validate } fun LocationReferencesPartial.validate(): LocationReferencesPartial = validate(this) { - validate(LocationReferencesPartial::location_id).isPrintableAscii().hasMaxLengthOf(36) - evse_uids?.forEach { evse_uid -> - if (evse_uid.length > 36) { + validate(LocationReferencesPartial::locationId).isPrintableAscii().hasMaxLengthOf(36) + evseUids?.forEach { evseUid -> + if (evseUid.length > 36) { constraintViolations.add( DefaultConstraintViolation( - property = "evse_uids", + property = "evseUids", constraint = MaxLengthContraint(36) ) ) } - if (!evse_uid.isPrintableAscii()) { + if (!evseUid.isPrintableAscii()) { constraintViolations.add( DefaultConstraintViolation( - property = "evse_uids", + property = "evseUids", constraint = PrintableAsciiConstraint() ) ) @@ -56,8 +56,8 @@ fun LocationReferencesPartial.validate(): LocationReferencesPartial = validate(t } fun EnergyContractPartial.validate(): EnergyContractPartial = validate(this) { - validate(EnergyContractPartial::supplier_name).isPrintableAscii().hasMaxLengthOf(64) - validate(EnergyContractPartial::contract_id).isPrintableAscii().hasMaxLengthOf(64) + validate(EnergyContractPartial::supplierName).isPrintableAscii().hasMaxLengthOf(64) + validate(EnergyContractPartial::contractId).isPrintableAscii().hasMaxLengthOf(64) } fun DisplayTextPartial.validate(): DisplayTextPartial = validate(this) { @@ -87,4 +87,3 @@ fun LocationReferences.validate(): LocationReferences = validate(this) { fun EnergyContract.validate(): EnergyContract = validate(this) { toPartial().validate() } - diff --git a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/services/TokensEmspService.kt b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/services/TokensEmspService.kt index 8eb41884..ec482c53 100644 --- a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/services/TokensEmspService.kt +++ b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/services/TokensEmspService.kt @@ -36,7 +36,6 @@ class TokensEmspService( } } - override suspend fun postToken( tokenUid: CiString, type: TokenType?, diff --git a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/types/Price.kt b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/types/Price.kt index 9556f318..91bf1973 100644 --- a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/types/Price.kt +++ b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/types/Price.kt @@ -4,12 +4,12 @@ import com.izivia.ocpi.toolkit.annotations.Partial import java.math.BigDecimal /** - * @property excl_vat Price/Cost excluding VAT. - * @property incl_vat Price/Cost including VAT. + * @property exclVat Price/Cost excluding VAT. + * @property inclVat Price/Cost including VAT. */ @Partial data class Price( - val excl_vat: BigDecimal, - val incl_vat: BigDecimal? = null + val exclVat: BigDecimal, + val inclVat: BigDecimal? = null ) diff --git a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/versions/VersionDetailsClient.kt b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/versions/VersionDetailsClient.kt index 39353a9b..9320d098 100644 --- a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/versions/VersionDetailsClient.kt +++ b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/versions/VersionDetailsClient.kt @@ -1,30 +1,30 @@ package com.izivia.ocpi.toolkit.modules.versions import com.izivia.ocpi.toolkit.common.* -import com.izivia.ocpi.toolkit.modules.credentials.repositories.PlatformRepository +import com.izivia.ocpi.toolkit.modules.credentials.repositories.PartnerRepository import com.izivia.ocpi.toolkit.modules.versions.domain.VersionDetails import com.izivia.ocpi.toolkit.transport.TransportClientBuilder import com.izivia.ocpi.toolkit.transport.domain.HttpMethod import com.izivia.ocpi.toolkit.transport.domain.HttpRequest /** - * Used to get the version details of a platform + * Used to get the version details of a partner * @property transportClientBuilder used to build transport client - * @property serverVersionsEndpointUrl used to know which platform to communicate with - * @property platformRepository used to get information about the platform (endpoint, token) + * @property serverVersionsEndpointUrl used to know which partner to communicate with + * @property partnerRepository used to get information about the partner (endpoint, token) */ class VersionDetailsClient( private val transportClientBuilder: TransportClientBuilder, private val serverVersionsEndpointUrl: String, - private val platformRepository: PlatformRepository + private val partnerRepository: PartnerRepository ) : VersionDetailsInterface { override suspend fun getVersionDetails(): OcpiResponseBody = with( transportClientBuilder .build( - baseUrl = platformRepository - .getVersion(platformUrl = serverVersionsEndpointUrl) + baseUrl = partnerRepository + .getVersion(partnerUrl = serverVersionsEndpointUrl) ?.url ?: throw OcpiToolkitUnknownEndpointException("version details") ) @@ -36,8 +36,8 @@ class VersionDetailsClient( correlationId = generateCorrelationId() ) .authenticate( - platformRepository = platformRepository, - platformUrl = serverVersionsEndpointUrl, + partnerRepository = partnerRepository, + partnerUrl = serverVersionsEndpointUrl, allowTokenA = true ) ) diff --git a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/versions/VersionsClient.kt b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/versions/VersionsClient.kt index 76cfa5df..edcef130 100644 --- a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/versions/VersionsClient.kt +++ b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/versions/VersionsClient.kt @@ -4,22 +4,22 @@ import com.izivia.ocpi.toolkit.common.OcpiResponseBody import com.izivia.ocpi.toolkit.common.authenticate import com.izivia.ocpi.toolkit.common.parseBody import com.izivia.ocpi.toolkit.common.withRequiredHeaders -import com.izivia.ocpi.toolkit.modules.credentials.repositories.PlatformRepository +import com.izivia.ocpi.toolkit.modules.credentials.repositories.PartnerRepository import com.izivia.ocpi.toolkit.modules.versions.domain.Version import com.izivia.ocpi.toolkit.transport.TransportClientBuilder import com.izivia.ocpi.toolkit.transport.domain.HttpMethod import com.izivia.ocpi.toolkit.transport.domain.HttpRequest /** - * Used to get the versions of a platform + * Used to get the versions of a partner * @property transportClientBuilder used to build transport client - * @property serverVersionsEndpointUrl used to know which platform to communicate with - * @property platformRepository used to get information about the platform (token) + * @property serverVersionsEndpointUrl 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 platformRepository: PlatformRepository + private val partnerRepository: PartnerRepository ) : VersionsInterface { override suspend fun getVersions(): OcpiResponseBody> = @@ -34,8 +34,8 @@ class VersionsClient( correlationId = generateCorrelationId() ) .authenticate( - platformRepository = platformRepository, - platformUrl = serverVersionsEndpointUrl, + partnerRepository = partnerRepository, + partnerUrl = serverVersionsEndpointUrl, allowTokenA = true ) ) diff --git a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/versions/domain/InterfaceRole.kt b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/versions/domain/InterfaceRole.kt index 099d8165..811ddefc 100644 --- a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/versions/domain/InterfaceRole.kt +++ b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/versions/domain/InterfaceRole.kt @@ -11,5 +11,5 @@ enum class InterfaceRole { * Receiver Interface implementation. Interface implemented by the receiver of data, so the Sender/owner can Push * information to the Receiver. */ - RECEIVER, -} \ No newline at end of file + RECEIVER +} diff --git a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/versions/domain/ModuleID.kt b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/versions/domain/ModuleID.kt index ab6c77ae..9c94da52 100644 --- a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/versions/domain/ModuleID.kt +++ b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/versions/domain/ModuleID.kt @@ -27,4 +27,4 @@ enum class ModuleID { tariffs, tokens -} \ No newline at end of file +} diff --git a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/versions/domain/VersionNumber.kt b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/versions/domain/VersionNumber.kt index 5c171a1c..ceb893ad 100644 --- a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/versions/domain/VersionNumber.kt +++ b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/versions/domain/VersionNumber.kt @@ -16,4 +16,4 @@ enum class VersionNumber(val value: String, val index: Int) { } fun parseVersionNumber(value: String): VersionNumber? = - VersionNumber.values().firstOrNull { it.value == value } \ No newline at end of file + VersionNumber.values().firstOrNull { it.value == value } diff --git a/ocpi-toolkit-2.2.1/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/cdr/domain/CdrDimensionPartial.kt b/ocpi-toolkit-2.2.1/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/cdr/domain/CdrDimensionPartial.kt deleted file mode 100644 index c5a04ab7..00000000 --- a/ocpi-toolkit-2.2.1/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/cdr/domain/CdrDimensionPartial.kt +++ /dev/null @@ -1,28 +0,0 @@ -// ---------- -// - WARNING - -// ---------- -// This code is generated AND MUST NOT BE EDITED -// ---------- -package com.izivia.ocpi.toolkit.modules.cdr.domain - -import java.math.BigDecimal -import kotlin.collections.List - -/** - * Partial representation of [com.izivia.ocpi.toolkit.modules.cdr.domain.CdrDimension] - */ -public data class CdrDimensionPartial( - public val type: CdrDimensionType?, - public val volume: BigDecimal?, -) - -public fun CdrDimension.toPartial(): CdrDimensionPartial { - return CdrDimensionPartial( - type = type, - volume = volume - ) -} - -public fun List.toPartial(): List { - return mapNotNull { it.toPartial() } -} diff --git a/ocpi-toolkit-2.2.1/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/cdr/domain/CdrPartial.kt b/ocpi-toolkit-2.2.1/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/cdr/domain/CdrPartial.kt deleted file mode 100644 index 6eb948b8..00000000 --- a/ocpi-toolkit-2.2.1/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/cdr/domain/CdrPartial.kt +++ /dev/null @@ -1,90 +0,0 @@ -// ---------- -// - WARNING - -// ---------- -// This code is generated AND MUST NOT BE EDITED -// ---------- -package com.izivia.ocpi.toolkit.modules.cdr.domain - -import com.izivia.ocpi.toolkit.common.CiString -import com.izivia.ocpi.toolkit.modules.tariff.domain.TariffPartial -import com.izivia.ocpi.toolkit.modules.tariff.domain.toPartial -import com.izivia.ocpi.toolkit.modules.types.PricePartial -import com.izivia.ocpi.toolkit.modules.types.toPartial -import java.math.BigDecimal -import java.time.Instant -import kotlin.Boolean -import kotlin.String -import kotlin.collections.List - -/** - * Partial representation of [com.izivia.ocpi.toolkit.modules.cdr.domain.Cdr] - */ -public data class CdrPartial( - public val id: CiString?, - public val country_code: CiString?, - public val party_id: CiString?, - public val start_date_time: Instant?, - public val end_date_time: Instant?, - public val session_id: CiString?, - public val cdr_token: CdrTokenPartial?, - public val auth_method: AuthMethod?, - public val authorization_reference: String?, - public val cdr_location: CdrLocation?, - public val meter_id: String?, - public val currency: String?, - public val tariffs: List?, - public val charging_periods: List?, - public val signed_data: SignedDataPartial?, - public val total_cost: PricePartial?, - public val total_fixed_cost: PricePartial?, - public val total_energy: BigDecimal?, - public val total_energy_cost: PricePartial?, - public val total_time: BigDecimal?, - public val total_time_cost: PricePartial?, - public val total_parking_time: BigDecimal?, - public val total_parking_cost: PricePartial?, - public val total_reservation_cost: PricePartial?, - public val remark: String?, - public val invoice_reference_id: CiString?, - public val credit: Boolean?, - public val credit_reference_id: CiString?, - public val last_updated: Instant?, -) - -public fun Cdr.toPartial(): CdrPartial { - return CdrPartial( - id = id, - country_code = country_code, - party_id = party_id, - start_date_time = start_date_time, - end_date_time = end_date_time, - session_id = session_id, - cdr_token = cdr_token.toPartial(), - auth_method = auth_method, - authorization_reference = authorization_reference, - cdr_location = cdr_location, - meter_id = meter_id, - currency = currency, - tariffs = tariffs.toPartial(), - charging_periods = charging_periods.toPartial(), - signed_data = signed_data?.toPartial(), - total_cost = total_cost.toPartial(), - total_fixed_cost = total_fixed_cost?.toPartial(), - total_energy = total_energy, - total_energy_cost = total_energy_cost?.toPartial(), - total_time = total_time, - total_time_cost = total_time_cost?.toPartial(), - total_parking_time = total_parking_time, - total_parking_cost = total_parking_cost?.toPartial(), - total_reservation_cost = total_reservation_cost?.toPartial(), - remark = remark, - invoice_reference_id = invoice_reference_id, - credit = credit, - credit_reference_id = credit_reference_id, - last_updated = last_updated - ) -} - -public fun List.toPartial(): List { - return mapNotNull { it.toPartial() } -} diff --git a/ocpi-toolkit-2.2.1/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/cdr/domain/CdrTokenPartial.kt b/ocpi-toolkit-2.2.1/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/cdr/domain/CdrTokenPartial.kt deleted file mode 100644 index e21ba201..00000000 --- a/ocpi-toolkit-2.2.1/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/cdr/domain/CdrTokenPartial.kt +++ /dev/null @@ -1,35 +0,0 @@ -// ---------- -// - WARNING - -// ---------- -// This code is generated AND MUST NOT BE EDITED -// ---------- -package com.izivia.ocpi.toolkit.modules.cdr.domain - -import com.izivia.ocpi.toolkit.common.CiString -import com.izivia.ocpi.toolkit.modules.tokens.domain.TokenType -import kotlin.collections.List - -/** - * Partial representation of [com.izivia.ocpi.toolkit.modules.cdr.domain.CdrToken] - */ -public data class CdrTokenPartial( - public val country_code: CiString?, - public val party_id: CiString?, - public val uid: CiString?, - public val type: TokenType?, - public val contract_id: CiString?, -) - -public fun CdrToken.toPartial(): CdrTokenPartial { - return CdrTokenPartial( - country_code = country_code, - party_id = party_id, - uid = uid, - type = type, - contract_id = contract_id - ) -} - -public fun List.toPartial(): List { - return mapNotNull { it.toPartial() } -} diff --git a/ocpi-toolkit-2.2.1/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/cdr/domain/ChargingPeriodPartial.kt b/ocpi-toolkit-2.2.1/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/cdr/domain/ChargingPeriodPartial.kt deleted file mode 100644 index 3fa2b89c..00000000 --- a/ocpi-toolkit-2.2.1/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/cdr/domain/ChargingPeriodPartial.kt +++ /dev/null @@ -1,31 +0,0 @@ -// ---------- -// - WARNING - -// ---------- -// This code is generated AND MUST NOT BE EDITED -// ---------- -package com.izivia.ocpi.toolkit.modules.cdr.domain - -import com.izivia.ocpi.toolkit.common.CiString -import java.time.Instant -import kotlin.collections.List - -/** - * Partial representation of [com.izivia.ocpi.toolkit.modules.cdr.domain.ChargingPeriod] - */ -public data class ChargingPeriodPartial( - public val start_date_time: Instant?, - public val dimensions: List?, - public val tariff_id: CiString?, -) - -public fun ChargingPeriod.toPartial(): ChargingPeriodPartial { - return ChargingPeriodPartial( - start_date_time = start_date_time, - dimensions = dimensions.toPartial(), - tariff_id = tariff_id - ) -} - -public fun List.toPartial(): List { - return mapNotNull { it.toPartial() } -} diff --git a/ocpi-toolkit-2.2.1/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/cdr/domain/SignedDataPartial.kt b/ocpi-toolkit-2.2.1/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/cdr/domain/SignedDataPartial.kt deleted file mode 100644 index b57f7052..00000000 --- a/ocpi-toolkit-2.2.1/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/cdr/domain/SignedDataPartial.kt +++ /dev/null @@ -1,35 +0,0 @@ -// ---------- -// - WARNING - -// ---------- -// This code is generated AND MUST NOT BE EDITED -// ---------- -package com.izivia.ocpi.toolkit.modules.cdr.domain - -import com.izivia.ocpi.toolkit.common.CiString -import kotlin.Int -import kotlin.collections.List - -/** - * Partial representation of [com.izivia.ocpi.toolkit.modules.cdr.domain.SignedData] - */ -public data class SignedDataPartial( - public val encoding_method: CiString?, - public val encoding_method_version: Int?, - public val public_key: CiString?, - public val signed_values: List?, - public val url: CiString?, -) - -public fun SignedData.toPartial(): SignedDataPartial { - return SignedDataPartial( - encoding_method = encoding_method, - encoding_method_version = encoding_method_version, - public_key = public_key, - signed_values = signed_values.toPartial(), - url = url - ) -} - -public fun List.toPartial(): List { - return mapNotNull { it.toPartial() } -} diff --git a/ocpi-toolkit-2.2.1/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/cdr/domain/SignedValuePartial.kt b/ocpi-toolkit-2.2.1/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/cdr/domain/SignedValuePartial.kt deleted file mode 100644 index 84f470b2..00000000 --- a/ocpi-toolkit-2.2.1/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/cdr/domain/SignedValuePartial.kt +++ /dev/null @@ -1,30 +0,0 @@ -// ---------- -// - WARNING - -// ---------- -// This code is generated AND MUST NOT BE EDITED -// ---------- -package com.izivia.ocpi.toolkit.modules.cdr.domain - -import com.izivia.ocpi.toolkit.common.CiString -import kotlin.collections.List - -/** - * Partial representation of [com.izivia.ocpi.toolkit.modules.cdr.domain.SignedValue] - */ -public data class SignedValuePartial( - public val nature: CiString?, - public val plain_data: CiString?, - public val signed_data: CiString?, -) - -public fun SignedValue.toPartial(): SignedValuePartial { - return SignedValuePartial( - nature = nature, - plain_data = plain_data, - signed_data = signed_data - ) -} - -public fun List.toPartial(): List { - return mapNotNull { it.toPartial() } -} diff --git a/ocpi-toolkit-2.2.1/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/locations/domain/AdditionalGeoLocationPartial.kt b/ocpi-toolkit-2.2.1/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/locations/domain/AdditionalGeoLocationPartial.kt deleted file mode 100644 index 4e593072..00000000 --- a/ocpi-toolkit-2.2.1/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/locations/domain/AdditionalGeoLocationPartial.kt +++ /dev/null @@ -1,33 +0,0 @@ -// ---------- -// - WARNING - -// ---------- -// This code is generated AND MUST NOT BE EDITED -// ---------- -package com.izivia.ocpi.toolkit.modules.locations.domain - -import com.izivia.ocpi.toolkit.modules.types.DisplayTextPartial -import com.izivia.ocpi.toolkit.modules.types.toPartial -import kotlin.String -import kotlin.collections.List - -/** - * Partial representation of - * [com.izivia.ocpi.toolkit.modules.locations.domain.AdditionalGeoLocation] - */ -public data class AdditionalGeoLocationPartial( - public val latitude: String?, - public val longitude: String?, - public val name: DisplayTextPartial?, -) - -public fun AdditionalGeoLocation.toPartial(): AdditionalGeoLocationPartial { - return AdditionalGeoLocationPartial( - latitude = latitude, - longitude = longitude, - name = name?.toPartial() - ) -} - -public fun List.toPartial(): List { - return mapNotNull { it.toPartial() } -} diff --git a/ocpi-toolkit-2.2.1/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/locations/domain/BusinessDetailsPartial.kt b/ocpi-toolkit-2.2.1/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/locations/domain/BusinessDetailsPartial.kt deleted file mode 100644 index 3d3106b9..00000000 --- a/ocpi-toolkit-2.2.1/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/locations/domain/BusinessDetailsPartial.kt +++ /dev/null @@ -1,30 +0,0 @@ -// ---------- -// - WARNING - -// ---------- -// This code is generated AND MUST NOT BE EDITED -// ---------- -package com.izivia.ocpi.toolkit.modules.locations.domain - -import kotlin.String -import kotlin.collections.List - -/** - * Partial representation of [com.izivia.ocpi.toolkit.modules.locations.domain.BusinessDetails] - */ -public data class BusinessDetailsPartial( - public val name: String?, - public val website: String?, - public val logo: ImagePartial?, -) - -public fun BusinessDetails.toPartial(): BusinessDetailsPartial { - return BusinessDetailsPartial( - name = name, - website = website, - logo = logo?.toPartial() - ) -} - -public fun List.toPartial(): List { - return mapNotNull { it.toPartial() } -} diff --git a/ocpi-toolkit-2.2.1/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/locations/domain/ConnectorPartial.kt b/ocpi-toolkit-2.2.1/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/locations/domain/ConnectorPartial.kt deleted file mode 100644 index c117831f..00000000 --- a/ocpi-toolkit-2.2.1/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/locations/domain/ConnectorPartial.kt +++ /dev/null @@ -1,47 +0,0 @@ -// ---------- -// - WARNING - -// ---------- -// This code is generated AND MUST NOT BE EDITED -// ---------- -package com.izivia.ocpi.toolkit.modules.locations.domain - -import com.izivia.ocpi.toolkit.common.CiString -import java.time.Instant -import kotlin.Int -import kotlin.String -import kotlin.collections.List - -/** - * Partial representation of [com.izivia.ocpi.toolkit.modules.locations.domain.Connector] - */ -public data class ConnectorPartial( - public val id: CiString?, - public val standard: ConnectorType?, - public val format: ConnectorFormat?, - public val power_type: PowerType?, - public val max_voltage: Int?, - public val max_amperage: Int?, - public val max_electric_power: Int?, - public val tariff_ids: List?, - public val terms_and_conditions: String?, - public val last_updated: Instant?, -) - -public fun Connector.toPartial(): ConnectorPartial { - return ConnectorPartial( - id = id, - standard = standard, - format = format, - power_type = power_type, - max_voltage = max_voltage, - max_amperage = max_amperage, - max_electric_power = max_electric_power, - tariff_ids = tariff_ids, - terms_and_conditions = terms_and_conditions, - last_updated = last_updated - ) -} - -public fun List.toPartial(): List { - return mapNotNull { it.toPartial() } -} diff --git a/ocpi-toolkit-2.2.1/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/locations/domain/EnergyMixPartial.kt b/ocpi-toolkit-2.2.1/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/locations/domain/EnergyMixPartial.kt deleted file mode 100644 index 178ec172..00000000 --- a/ocpi-toolkit-2.2.1/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/locations/domain/EnergyMixPartial.kt +++ /dev/null @@ -1,35 +0,0 @@ -// ---------- -// - WARNING - -// ---------- -// This code is generated AND MUST NOT BE EDITED -// ---------- -package com.izivia.ocpi.toolkit.modules.locations.domain - -import kotlin.Boolean -import kotlin.String -import kotlin.collections.List - -/** - * Partial representation of [com.izivia.ocpi.toolkit.modules.locations.domain.EnergyMix] - */ -public data class EnergyMixPartial( - public val is_green_energy: Boolean?, - public val energy_sources: List?, - public val environ_impact: List?, - public val supplier_name: String?, - public val energy_product_name: String?, -) - -public fun EnergyMix.toPartial(): EnergyMixPartial { - return EnergyMixPartial( - is_green_energy = is_green_energy, - energy_sources = energy_sources?.toPartial(), - environ_impact = environ_impact?.toPartial(), - supplier_name = supplier_name, - energy_product_name = energy_product_name - ) -} - -public fun List.toPartial(): List { - return mapNotNull { it.toPartial() } -} diff --git a/ocpi-toolkit-2.2.1/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/locations/domain/EnergySourcePartial.kt b/ocpi-toolkit-2.2.1/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/locations/domain/EnergySourcePartial.kt deleted file mode 100644 index 689ef406..00000000 --- a/ocpi-toolkit-2.2.1/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/locations/domain/EnergySourcePartial.kt +++ /dev/null @@ -1,28 +0,0 @@ -// ---------- -// - WARNING - -// ---------- -// This code is generated AND MUST NOT BE EDITED -// ---------- -package com.izivia.ocpi.toolkit.modules.locations.domain - -import java.math.BigDecimal -import kotlin.collections.List - -/** - * Partial representation of [com.izivia.ocpi.toolkit.modules.locations.domain.EnergySource] - */ -public data class EnergySourcePartial( - public val source: EnergySourceCategory?, - public val percentage: BigDecimal?, -) - -public fun EnergySource.toPartial(): EnergySourcePartial { - return EnergySourcePartial( - source = source, - percentage = percentage - ) -} - -public fun List.toPartial(): List { - return mapNotNull { it.toPartial() } -} diff --git a/ocpi-toolkit-2.2.1/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/locations/domain/EnvironmentalImpactPartial.kt b/ocpi-toolkit-2.2.1/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/locations/domain/EnvironmentalImpactPartial.kt deleted file mode 100644 index e3eaa610..00000000 --- a/ocpi-toolkit-2.2.1/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/locations/domain/EnvironmentalImpactPartial.kt +++ /dev/null @@ -1,28 +0,0 @@ -// ---------- -// - WARNING - -// ---------- -// This code is generated AND MUST NOT BE EDITED -// ---------- -package com.izivia.ocpi.toolkit.modules.locations.domain - -import java.math.BigDecimal -import kotlin.collections.List - -/** - * Partial representation of [com.izivia.ocpi.toolkit.modules.locations.domain.EnvironmentalImpact] - */ -public data class EnvironmentalImpactPartial( - public val category: EnvironmentalImpactCategory?, - public val amount: BigDecimal?, -) - -public fun EnvironmentalImpact.toPartial(): EnvironmentalImpactPartial { - return EnvironmentalImpactPartial( - category = category, - amount = amount - ) -} - -public fun List.toPartial(): List { - return mapNotNull { it.toPartial() } -} diff --git a/ocpi-toolkit-2.2.1/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/locations/domain/EvsePartial.kt b/ocpi-toolkit-2.2.1/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/locations/domain/EvsePartial.kt deleted file mode 100644 index 67fa8173..00000000 --- a/ocpi-toolkit-2.2.1/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/locations/domain/EvsePartial.kt +++ /dev/null @@ -1,54 +0,0 @@ -// ---------- -// - WARNING - -// ---------- -// This code is generated AND MUST NOT BE EDITED -// ---------- -package com.izivia.ocpi.toolkit.modules.locations.domain - -import com.izivia.ocpi.toolkit.common.CiString -import com.izivia.ocpi.toolkit.modules.types.DisplayTextPartial -import com.izivia.ocpi.toolkit.modules.types.toPartial -import java.time.Instant -import kotlin.String -import kotlin.collections.List - -/** - * Partial representation of [com.izivia.ocpi.toolkit.modules.locations.domain.Evse] - */ -public data class EvsePartial( - public val uid: CiString?, - public val evse_id: CiString?, - public val status: Status?, - public val status_schedule: List?, - public val capabilities: List?, - public val connectors: List?, - public val floor_level: String?, - public val coordinates: GeoLocationPartial?, - public val physical_reference: String?, - public val directions: List?, - public val parking_restrictions: List?, - public val images: List?, - public val last_updated: Instant?, -) - -public fun Evse.toPartial(): EvsePartial { - return EvsePartial( - uid = uid, - evse_id = evse_id, - status = status, - status_schedule = status_schedule?.toPartial(), - capabilities = capabilities, - connectors = connectors.toPartial(), - floor_level = floor_level, - coordinates = coordinates?.toPartial(), - physical_reference = physical_reference, - directions = directions?.toPartial(), - parking_restrictions = parking_restrictions, - images = images?.toPartial(), - last_updated = last_updated - ) -} - -public fun List.toPartial(): List { - return mapNotNull { it.toPartial() } -} diff --git a/ocpi-toolkit-2.2.1/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/locations/domain/ExceptionalPeriodPartial.kt b/ocpi-toolkit-2.2.1/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/locations/domain/ExceptionalPeriodPartial.kt deleted file mode 100644 index cc44ed42..00000000 --- a/ocpi-toolkit-2.2.1/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/locations/domain/ExceptionalPeriodPartial.kt +++ /dev/null @@ -1,28 +0,0 @@ -// ---------- -// - WARNING - -// ---------- -// This code is generated AND MUST NOT BE EDITED -// ---------- -package com.izivia.ocpi.toolkit.modules.locations.domain - -import java.time.Instant -import kotlin.collections.List - -/** - * Partial representation of [com.izivia.ocpi.toolkit.modules.locations.domain.ExceptionalPeriod] - */ -public data class ExceptionalPeriodPartial( - public val period_begin: Instant?, - public val period_end: Instant?, -) - -public fun ExceptionalPeriod.toPartial(): ExceptionalPeriodPartial { - return ExceptionalPeriodPartial( - period_begin = period_begin, - period_end = period_end - ) -} - -public fun List.toPartial(): List { - return mapNotNull { it.toPartial() } -} diff --git a/ocpi-toolkit-2.2.1/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/locations/domain/GeoLocationPartial.kt b/ocpi-toolkit-2.2.1/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/locations/domain/GeoLocationPartial.kt deleted file mode 100644 index 49b0cd8a..00000000 --- a/ocpi-toolkit-2.2.1/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/locations/domain/GeoLocationPartial.kt +++ /dev/null @@ -1,28 +0,0 @@ -// ---------- -// - WARNING - -// ---------- -// This code is generated AND MUST NOT BE EDITED -// ---------- -package com.izivia.ocpi.toolkit.modules.locations.domain - -import kotlin.String -import kotlin.collections.List - -/** - * Partial representation of [com.izivia.ocpi.toolkit.modules.locations.domain.GeoLocation] - */ -public data class GeoLocationPartial( - public val latitude: String?, - public val longitude: String?, -) - -public fun GeoLocation.toPartial(): GeoLocationPartial { - return GeoLocationPartial( - latitude = latitude, - longitude = longitude - ) -} - -public fun List.toPartial(): List { - return mapNotNull { it.toPartial() } -} diff --git a/ocpi-toolkit-2.2.1/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/locations/domain/HoursPartial.kt b/ocpi-toolkit-2.2.1/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/locations/domain/HoursPartial.kt deleted file mode 100644 index c9d1cb3e..00000000 --- a/ocpi-toolkit-2.2.1/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/locations/domain/HoursPartial.kt +++ /dev/null @@ -1,32 +0,0 @@ -// ---------- -// - WARNING - -// ---------- -// This code is generated AND MUST NOT BE EDITED -// ---------- -package com.izivia.ocpi.toolkit.modules.locations.domain - -import kotlin.Boolean -import kotlin.collections.List - -/** - * Partial representation of [com.izivia.ocpi.toolkit.modules.locations.domain.Hours] - */ -public data class HoursPartial( - public val regular_hours: List?, - public val twenty_four_seven: Boolean?, - public val exceptional_openings: List?, - public val exceptional_closings: List?, -) - -public fun Hours.toPartial(): HoursPartial { - return HoursPartial( - regular_hours = regular_hours?.toPartial(), - twenty_four_seven = twenty_four_seven, - exceptional_openings = exceptional_openings?.toPartial(), - exceptional_closings = exceptional_closings?.toPartial() - ) -} - -public fun List.toPartial(): List { - return mapNotNull { it.toPartial() } -} diff --git a/ocpi-toolkit-2.2.1/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/locations/domain/ImagePartial.kt b/ocpi-toolkit-2.2.1/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/locations/domain/ImagePartial.kt deleted file mode 100644 index 36b64f3e..00000000 --- a/ocpi-toolkit-2.2.1/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/locations/domain/ImagePartial.kt +++ /dev/null @@ -1,38 +0,0 @@ -// ---------- -// - WARNING - -// ---------- -// This code is generated AND MUST NOT BE EDITED -// ---------- -package com.izivia.ocpi.toolkit.modules.locations.domain - -import com.izivia.ocpi.toolkit.common.CiString -import kotlin.Int -import kotlin.String -import kotlin.collections.List - -/** - * Partial representation of [com.izivia.ocpi.toolkit.modules.locations.domain.Image] - */ -public data class ImagePartial( - public val url: String?, - public val thumbnail: String?, - public val category: ImageCategory?, - public val type: CiString?, - public val width: Int?, - public val height: Int?, -) - -public fun Image.toPartial(): ImagePartial { - return ImagePartial( - url = url, - thumbnail = thumbnail, - category = category, - type = type, - width = width, - height = height - ) -} - -public fun List.toPartial(): List { - return mapNotNull { it.toPartial() } -} diff --git a/ocpi-toolkit-2.2.1/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/locations/domain/LocationPartial.kt b/ocpi-toolkit-2.2.1/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/locations/domain/LocationPartial.kt deleted file mode 100644 index 9f4c7051..00000000 --- a/ocpi-toolkit-2.2.1/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/locations/domain/LocationPartial.kt +++ /dev/null @@ -1,81 +0,0 @@ -// ---------- -// - WARNING - -// ---------- -// This code is generated AND MUST NOT BE EDITED -// ---------- -package com.izivia.ocpi.toolkit.modules.locations.domain - -import com.izivia.ocpi.toolkit.common.CiString -import com.izivia.ocpi.toolkit.modules.types.DisplayTextPartial -import com.izivia.ocpi.toolkit.modules.types.toPartial -import java.time.Instant -import kotlin.Boolean -import kotlin.String -import kotlin.collections.List - -/** - * Partial representation of [com.izivia.ocpi.toolkit.modules.locations.domain.Location] - */ -public data class LocationPartial( - public val country_code: CiString?, - public val party_id: CiString?, - public val id: CiString?, - public val publish: Boolean?, - public val publish_allowed_to: List?, - public val name: String?, - public val address: String?, - public val city: String?, - public val postal_code: String?, - public val state: String?, - public val country: String?, - public val coordinates: GeoLocationPartial?, - public val related_locations: List?, - public val parking_type: ParkingType?, - public val evses: List?, - public val directions: List?, - public val `operator`: BusinessDetailsPartial?, - public val suboperator: BusinessDetailsPartial?, - public val owner: BusinessDetailsPartial?, - public val facilities: List?, - public val time_zone: String?, - public val opening_times: HoursPartial?, - public val charging_when_closed: Boolean?, - public val images: List?, - public val energy_mix: EnergyMixPartial?, - public val last_updated: Instant?, -) - -public fun Location.toPartial(): LocationPartial { - return LocationPartial( - country_code = country_code, - party_id = party_id, - id = id, - publish = publish, - publish_allowed_to = publish_allowed_to?.toPartial(), - name = name, - address = address, - city = city, - postal_code = postal_code, - state = state, - country = country, - coordinates = coordinates.toPartial(), - related_locations = related_locations?.toPartial(), - parking_type = parking_type, - evses = evses?.toPartial(), - directions = directions?.toPartial(), - operator = operator?.toPartial(), - suboperator = suboperator?.toPartial(), - owner = owner?.toPartial(), - facilities = facilities, - time_zone = time_zone, - opening_times = opening_times?.toPartial(), - charging_when_closed = charging_when_closed, - images = images?.toPartial(), - energy_mix = energy_mix?.toPartial(), - last_updated = last_updated - ) -} - -public fun List.toPartial(): List { - return mapNotNull { it.toPartial() } -} diff --git a/ocpi-toolkit-2.2.1/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/locations/domain/PublishTokenTypePartial.kt b/ocpi-toolkit-2.2.1/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/locations/domain/PublishTokenTypePartial.kt deleted file mode 100644 index b85e55ee..00000000 --- a/ocpi-toolkit-2.2.1/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/locations/domain/PublishTokenTypePartial.kt +++ /dev/null @@ -1,36 +0,0 @@ -// ---------- -// - WARNING - -// ---------- -// This code is generated AND MUST NOT BE EDITED -// ---------- -package com.izivia.ocpi.toolkit.modules.locations.domain - -import com.izivia.ocpi.toolkit.common.CiString -import com.izivia.ocpi.toolkit.modules.tokens.domain.TokenType -import kotlin.String -import kotlin.collections.List - -/** - * Partial representation of [com.izivia.ocpi.toolkit.modules.locations.domain.PublishTokenType] - */ -public data class PublishTokenTypePartial( - public val uid: CiString?, - public val type: TokenType?, - public val visual_number: String?, - public val issuer: String?, - public val group_id: CiString?, -) - -public fun PublishTokenType.toPartial(): PublishTokenTypePartial { - return PublishTokenTypePartial( - uid = uid, - type = type, - visual_number = visual_number, - issuer = issuer, - group_id = group_id - ) -} - -public fun List.toPartial(): List { - return mapNotNull { it.toPartial() } -} diff --git a/ocpi-toolkit-2.2.1/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/locations/domain/RegularHoursPartial.kt b/ocpi-toolkit-2.2.1/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/locations/domain/RegularHoursPartial.kt deleted file mode 100644 index 1259b46b..00000000 --- a/ocpi-toolkit-2.2.1/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/locations/domain/RegularHoursPartial.kt +++ /dev/null @@ -1,31 +0,0 @@ -// ---------- -// - WARNING - -// ---------- -// This code is generated AND MUST NOT BE EDITED -// ---------- -package com.izivia.ocpi.toolkit.modules.locations.domain - -import kotlin.Int -import kotlin.String -import kotlin.collections.List - -/** - * Partial representation of [com.izivia.ocpi.toolkit.modules.locations.domain.RegularHours] - */ -public data class RegularHoursPartial( - public val weekday: Int?, - public val period_begin: String?, - public val period_end: String?, -) - -public fun RegularHours.toPartial(): RegularHoursPartial { - return RegularHoursPartial( - weekday = weekday, - period_begin = period_begin, - period_end = period_end - ) -} - -public fun List.toPartial(): List { - return mapNotNull { it.toPartial() } -} diff --git a/ocpi-toolkit-2.2.1/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/locations/domain/StatusSchedulePartial.kt b/ocpi-toolkit-2.2.1/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/locations/domain/StatusSchedulePartial.kt deleted file mode 100644 index 971f00a2..00000000 --- a/ocpi-toolkit-2.2.1/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/locations/domain/StatusSchedulePartial.kt +++ /dev/null @@ -1,30 +0,0 @@ -// ---------- -// - WARNING - -// ---------- -// This code is generated AND MUST NOT BE EDITED -// ---------- -package com.izivia.ocpi.toolkit.modules.locations.domain - -import java.time.Instant -import kotlin.collections.List - -/** - * Partial representation of [com.izivia.ocpi.toolkit.modules.locations.domain.StatusSchedule] - */ -public data class StatusSchedulePartial( - public val period_begin: Instant?, - public val period_end: Instant?, - public val status: Status?, -) - -public fun StatusSchedule.toPartial(): StatusSchedulePartial { - return StatusSchedulePartial( - period_begin = period_begin, - period_end = period_end, - status = status - ) -} - -public fun List.toPartial(): List { - return mapNotNull { it.toPartial() } -} diff --git a/ocpi-toolkit-2.2.1/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/sessions/domain/ChargingPreferencesPartial.kt b/ocpi-toolkit-2.2.1/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/sessions/domain/ChargingPreferencesPartial.kt deleted file mode 100644 index e63c2a37..00000000 --- a/ocpi-toolkit-2.2.1/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/sessions/domain/ChargingPreferencesPartial.kt +++ /dev/null @@ -1,34 +0,0 @@ -// ---------- -// - WARNING - -// ---------- -// This code is generated AND MUST NOT BE EDITED -// ---------- -package com.izivia.ocpi.toolkit.modules.sessions.domain - -import java.time.Instant -import kotlin.Boolean -import kotlin.Int -import kotlin.collections.List - -/** - * Partial representation of [com.izivia.ocpi.toolkit.modules.sessions.domain.ChargingPreferences] - */ -public data class ChargingPreferencesPartial( - public val profile_type: ProfileType?, - public val departure_time: Instant?, - public val energy_need: Int?, - public val discharge_allowed: Boolean?, -) - -public fun ChargingPreferences.toPartial(): ChargingPreferencesPartial { - return ChargingPreferencesPartial( - profile_type = profile_type, - departure_time = departure_time, - energy_need = energy_need, - discharge_allowed = discharge_allowed - ) -} - -public fun List.toPartial(): List { - return mapNotNull { it.toPartial() } -} diff --git a/ocpi-toolkit-2.2.1/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/sessions/domain/SessionPartial.kt b/ocpi-toolkit-2.2.1/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/sessions/domain/SessionPartial.kt deleted file mode 100644 index 5a6a10d3..00000000 --- a/ocpi-toolkit-2.2.1/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/sessions/domain/SessionPartial.kt +++ /dev/null @@ -1,69 +0,0 @@ -// ---------- -// - WARNING - -// ---------- -// This code is generated AND MUST NOT BE EDITED -// ---------- -package com.izivia.ocpi.toolkit.modules.sessions.domain - -import com.izivia.ocpi.toolkit.common.CiString -import com.izivia.ocpi.toolkit.modules.cdr.domain.AuthMethod -import com.izivia.ocpi.toolkit.modules.cdr.domain.CdrTokenPartial -import com.izivia.ocpi.toolkit.modules.cdr.domain.ChargingPeriodPartial -import com.izivia.ocpi.toolkit.modules.cdr.domain.toPartial -import com.izivia.ocpi.toolkit.modules.types.PricePartial -import com.izivia.ocpi.toolkit.modules.types.toPartial -import java.time.Instant -import kotlin.Int -import kotlin.String -import kotlin.collections.List - -/** - * Partial representation of [com.izivia.ocpi.toolkit.modules.sessions.domain.Session] - */ -public data class SessionPartial( - public val country_code: CiString?, - public val party_id: CiString?, - public val id: CiString?, - public val start_date_time: Instant?, - public val end_date_time: Instant?, - public val kwh: Int?, - public val cdr_token: CdrTokenPartial?, - public val auth_method: AuthMethod?, - public val authorization_reference: CiString?, - public val location_id: CiString?, - public val evse_uid: CiString?, - public val connector_id: CiString?, - public val meter_id: String?, - public val currency: CiString?, - public val charging_periods: List?, - public val total_cost: PricePartial?, - public val status: SessionStatusType?, - public val last_updated: Instant?, -) - -public fun Session.toPartial(): SessionPartial { - return SessionPartial( - country_code = country_code, - party_id = party_id, - id = id, - start_date_time = start_date_time, - end_date_time = end_date_time, - kwh = kwh, - cdr_token = cdr_token.toPartial(), - auth_method = auth_method, - authorization_reference = authorization_reference, - location_id = location_id, - evse_uid = evse_uid, - connector_id = connector_id, - meter_id = meter_id, - currency = currency, - charging_periods = charging_periods?.toPartial(), - total_cost = total_cost?.toPartial(), - status = status, - last_updated = last_updated - ) -} - -public fun List.toPartial(): List { - return mapNotNull { it.toPartial() } -} diff --git a/ocpi-toolkit-2.2.1/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/tariff/domain/PriceComponentPartial.kt b/ocpi-toolkit-2.2.1/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/tariff/domain/PriceComponentPartial.kt deleted file mode 100644 index 4f944739..00000000 --- a/ocpi-toolkit-2.2.1/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/tariff/domain/PriceComponentPartial.kt +++ /dev/null @@ -1,33 +0,0 @@ -// ---------- -// - WARNING - -// ---------- -// This code is generated AND MUST NOT BE EDITED -// ---------- -package com.izivia.ocpi.toolkit.modules.tariff.domain - -import java.math.BigDecimal -import kotlin.Int -import kotlin.collections.List - -/** - * Partial representation of [com.izivia.ocpi.toolkit.modules.tariff.domain.PriceComponent] - */ -public data class PriceComponentPartial( - public val type: TariffDimensionType?, - public val price: BigDecimal?, - public val vat: BigDecimal?, - public val step_size: Int?, -) - -public fun PriceComponent.toPartial(): PriceComponentPartial { - return PriceComponentPartial( - type = type, - price = price, - vat = vat, - step_size = step_size - ) -} - -public fun List.toPartial(): List { - return mapNotNull { it.toPartial() } -} diff --git a/ocpi-toolkit-2.2.1/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/tariff/domain/TariffElementPartial.kt b/ocpi-toolkit-2.2.1/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/tariff/domain/TariffElementPartial.kt deleted file mode 100644 index 31ab4f3d..00000000 --- a/ocpi-toolkit-2.2.1/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/tariff/domain/TariffElementPartial.kt +++ /dev/null @@ -1,27 +0,0 @@ -// ---------- -// - WARNING - -// ---------- -// This code is generated AND MUST NOT BE EDITED -// ---------- -package com.izivia.ocpi.toolkit.modules.tariff.domain - -import kotlin.collections.List - -/** - * Partial representation of [com.izivia.ocpi.toolkit.modules.tariff.domain.TariffElement] - */ -public data class TariffElementPartial( - public val price_components: List?, - public val restrictions: TariffRestrictionsPartial?, -) - -public fun TariffElement.toPartial(): TariffElementPartial { - return TariffElementPartial( - price_components = price_components.toPartial(), - restrictions = restrictions?.toPartial() - ) -} - -public fun List.toPartial(): List { - return mapNotNull { it.toPartial() } -} diff --git a/ocpi-toolkit-2.2.1/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/tariff/domain/TariffPartial.kt b/ocpi-toolkit-2.2.1/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/tariff/domain/TariffPartial.kt deleted file mode 100644 index 80f4a149..00000000 --- a/ocpi-toolkit-2.2.1/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/tariff/domain/TariffPartial.kt +++ /dev/null @@ -1,59 +0,0 @@ -// ---------- -// - WARNING - -// ---------- -// This code is generated AND MUST NOT BE EDITED -// ---------- -package com.izivia.ocpi.toolkit.modules.tariff.domain - -import com.izivia.ocpi.toolkit.common.CiString -import com.izivia.ocpi.toolkit.modules.locations.domain.EnergyMixPartial -import com.izivia.ocpi.toolkit.modules.locations.domain.toPartial -import com.izivia.ocpi.toolkit.modules.types.DisplayTextPartial -import com.izivia.ocpi.toolkit.modules.types.PricePartial -import com.izivia.ocpi.toolkit.modules.types.toPartial -import java.time.Instant -import kotlin.String -import kotlin.collections.List - -/** - * Partial representation of [com.izivia.ocpi.toolkit.modules.tariff.domain.Tariff] - */ -public data class TariffPartial( - public val id: CiString?, - public val type: TariffType?, - public val party_id: CiString?, - public val country_code: CiString?, - public val currency: String?, - public val tariff_alt_text: List?, - public val tariff_alt_url: CiString?, - public val min_price: PricePartial?, - public val max_price: PricePartial?, - public val elements: List?, - public val start_date_time: Instant?, - public val end_date_time: Instant?, - public val energy_mix: EnergyMixPartial?, - public val last_updated: Instant?, -) - -public fun Tariff.toPartial(): TariffPartial { - return TariffPartial( - id = id, - type = type, - party_id = party_id, - country_code = country_code, - currency = currency, - tariff_alt_text = tariff_alt_text?.toPartial(), - tariff_alt_url = tariff_alt_url, - min_price = min_price?.toPartial(), - max_price = max_price?.toPartial(), - elements = elements.toPartial(), - start_date_time = start_date_time, - end_date_time = end_date_time, - energy_mix = energy_mix?.toPartial(), - last_updated = last_updated - ) -} - -public fun List.toPartial(): List { - return mapNotNull { it.toPartial() } -} diff --git a/ocpi-toolkit-2.2.1/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/tariff/domain/TariffRestrictionsPartial.kt b/ocpi-toolkit-2.2.1/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/tariff/domain/TariffRestrictionsPartial.kt deleted file mode 100644 index b8c2f093..00000000 --- a/ocpi-toolkit-2.2.1/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/tariff/domain/TariffRestrictionsPartial.kt +++ /dev/null @@ -1,55 +0,0 @@ -// ---------- -// - WARNING - -// ---------- -// This code is generated AND MUST NOT BE EDITED -// ---------- -package com.izivia.ocpi.toolkit.modules.tariff.domain - -import java.math.BigDecimal -import java.time.DayOfWeek -import kotlin.Int -import kotlin.String -import kotlin.collections.List - -/** - * Partial representation of [com.izivia.ocpi.toolkit.modules.tariff.domain.TariffRestrictions] - */ -public data class TariffRestrictionsPartial( - public val start_time: String?, - public val end_time: String?, - public val start_date: String?, - public val end_date: String?, - public val min_kwh: BigDecimal?, - public val max_kwh: BigDecimal?, - public val min_current: BigDecimal?, - public val max_current: BigDecimal?, - public val min_power: BigDecimal?, - public val max_power: BigDecimal?, - public val min_duration: Int?, - public val max_duration: Int?, - public val day_of_week: List?, - public val reservation: ReservationRestrictionType?, -) - -public fun TariffRestrictions.toPartial(): TariffRestrictionsPartial { - return TariffRestrictionsPartial( - start_time = start_time, - end_time = end_time, - start_date = start_date, - end_date = end_date, - min_kwh = min_kwh, - max_kwh = max_kwh, - min_current = min_current, - max_current = max_current, - min_power = min_power, - max_power = max_power, - min_duration = min_duration, - max_duration = max_duration, - day_of_week = day_of_week, - reservation = reservation - ) -} - -public fun List.toPartial(): List { - return mapNotNull { it.toPartial() } -} diff --git a/ocpi-toolkit-2.2.1/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/tokens/domain/AuthorizationInfoPartial.kt b/ocpi-toolkit-2.2.1/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/tokens/domain/AuthorizationInfoPartial.kt deleted file mode 100644 index da010144..00000000 --- a/ocpi-toolkit-2.2.1/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/tokens/domain/AuthorizationInfoPartial.kt +++ /dev/null @@ -1,36 +0,0 @@ -// ---------- -// - WARNING - -// ---------- -// This code is generated AND MUST NOT BE EDITED -// ---------- -package com.izivia.ocpi.toolkit.modules.tokens.domain - -import com.izivia.ocpi.toolkit.common.CiString -import com.izivia.ocpi.toolkit.modules.types.DisplayTextPartial -import com.izivia.ocpi.toolkit.modules.types.toPartial -import kotlin.collections.List - -/** - * Partial representation of [com.izivia.ocpi.toolkit.modules.tokens.domain.AuthorizationInfo] - */ -public data class AuthorizationInfoPartial( - public val allowed: AllowedType?, - public val token: TokenPartial?, - public val location: LocationReferencesPartial?, - public val authorization_reference: CiString?, - public val info: DisplayTextPartial?, -) - -public fun AuthorizationInfo.toPartial(): AuthorizationInfoPartial { - return AuthorizationInfoPartial( - allowed = allowed, - token = token.toPartial(), - location = location?.toPartial(), - authorization_reference = authorization_reference, - info = info?.toPartial() - ) -} - -public fun List.toPartial(): List { - return mapNotNull { it.toPartial() } -} diff --git a/ocpi-toolkit-2.2.1/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/tokens/domain/EnergyContractPartial.kt b/ocpi-toolkit-2.2.1/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/tokens/domain/EnergyContractPartial.kt deleted file mode 100644 index a90c45de..00000000 --- a/ocpi-toolkit-2.2.1/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/tokens/domain/EnergyContractPartial.kt +++ /dev/null @@ -1,28 +0,0 @@ -// ---------- -// - WARNING - -// ---------- -// This code is generated AND MUST NOT BE EDITED -// ---------- -package com.izivia.ocpi.toolkit.modules.tokens.domain - -import kotlin.String -import kotlin.collections.List - -/** - * Partial representation of [com.izivia.ocpi.toolkit.modules.tokens.domain.EnergyContract] - */ -public data class EnergyContractPartial( - public val supplier_name: String?, - public val contract_id: String?, -) - -public fun EnergyContract.toPartial(): EnergyContractPartial { - return EnergyContractPartial( - supplier_name = supplier_name, - contract_id = contract_id - ) -} - -public fun List.toPartial(): List { - return mapNotNull { it.toPartial() } -} diff --git a/ocpi-toolkit-2.2.1/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/tokens/domain/LocationReferencesPartial.kt b/ocpi-toolkit-2.2.1/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/tokens/domain/LocationReferencesPartial.kt deleted file mode 100644 index 638406a0..00000000 --- a/ocpi-toolkit-2.2.1/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/tokens/domain/LocationReferencesPartial.kt +++ /dev/null @@ -1,28 +0,0 @@ -// ---------- -// - WARNING - -// ---------- -// This code is generated AND MUST NOT BE EDITED -// ---------- -package com.izivia.ocpi.toolkit.modules.tokens.domain - -import com.izivia.ocpi.toolkit.common.CiString -import kotlin.collections.List - -/** - * Partial representation of [com.izivia.ocpi.toolkit.modules.tokens.domain.LocationReferences] - */ -public data class LocationReferencesPartial( - public val location_id: CiString?, - public val evse_uids: List?, -) - -public fun LocationReferences.toPartial(): LocationReferencesPartial { - return LocationReferencesPartial( - location_id = location_id, - evse_uids = evse_uids - ) -} - -public fun List.toPartial(): List { - return mapNotNull { it.toPartial() } -} diff --git a/ocpi-toolkit-2.2.1/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/tokens/domain/TokenPartial.kt b/ocpi-toolkit-2.2.1/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/tokens/domain/TokenPartial.kt deleted file mode 100644 index 3c681b19..00000000 --- a/ocpi-toolkit-2.2.1/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/tokens/domain/TokenPartial.kt +++ /dev/null @@ -1,56 +0,0 @@ -// ---------- -// - WARNING - -// ---------- -// This code is generated AND MUST NOT BE EDITED -// ---------- -package com.izivia.ocpi.toolkit.modules.tokens.domain - -import com.izivia.ocpi.toolkit.common.CiString -import com.izivia.ocpi.toolkit.modules.sessions.domain.ProfileType -import java.time.Instant -import kotlin.Boolean -import kotlin.String -import kotlin.collections.List - -/** - * Partial representation of [com.izivia.ocpi.toolkit.modules.tokens.domain.Token] - */ -public data class TokenPartial( - public val country_code: CiString?, - public val party_id: CiString?, - public val uid: CiString?, - public val type: TokenType?, - public val contract_id: CiString?, - public val visual_number: String?, - public val issuer: String?, - public val group_id: CiString?, - public val valid: Boolean?, - public val whitelist: WhitelistType?, - public val language: String?, - public val default_profile_type: ProfileType?, - public val energy_contract: EnergyContractPartial?, - public val last_updated: Instant?, -) - -public fun Token.toPartial(): TokenPartial { - return TokenPartial( - country_code = country_code, - party_id = party_id, - uid = uid, - type = type, - contract_id = contract_id, - visual_number = visual_number, - issuer = issuer, - group_id = group_id, - valid = valid, - whitelist = whitelist, - language = language, - default_profile_type = default_profile_type, - energy_contract = energy_contract?.toPartial(), - last_updated = last_updated - ) -} - -public fun List.toPartial(): List { - return mapNotNull { it.toPartial() } -} diff --git a/ocpi-toolkit-2.2.1/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/types/DisplayTextPartial.kt b/ocpi-toolkit-2.2.1/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/types/DisplayTextPartial.kt deleted file mode 100644 index 250eec77..00000000 --- a/ocpi-toolkit-2.2.1/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/types/DisplayTextPartial.kt +++ /dev/null @@ -1,28 +0,0 @@ -// ---------- -// - WARNING - -// ---------- -// This code is generated AND MUST NOT BE EDITED -// ---------- -package com.izivia.ocpi.toolkit.modules.types - -import kotlin.String -import kotlin.collections.List - -/** - * Partial representation of [com.izivia.ocpi.toolkit.modules.types.DisplayText] - */ -public data class DisplayTextPartial( - public val language: String?, - public val text: String?, -) - -public fun DisplayText.toPartial(): DisplayTextPartial { - return DisplayTextPartial( - language = language, - text = text - ) -} - -public fun List.toPartial(): List { - return mapNotNull { it.toPartial() } -} diff --git a/ocpi-toolkit-2.2.1/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/types/PricePartial.kt b/ocpi-toolkit-2.2.1/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/types/PricePartial.kt deleted file mode 100644 index 753d22b8..00000000 --- a/ocpi-toolkit-2.2.1/src/main/kotlinGen/com/izivia/ocpi/toolkit/modules/types/PricePartial.kt +++ /dev/null @@ -1,28 +0,0 @@ -// ---------- -// - WARNING - -// ---------- -// This code is generated AND MUST NOT BE EDITED -// ---------- -package com.izivia.ocpi.toolkit.modules.types - -import java.math.BigDecimal -import kotlin.collections.List - -/** - * Partial representation of [com.izivia.ocpi.toolkit.modules.types.Price] - */ -public data class PricePartial( - public val excl_vat: BigDecimal?, - public val incl_vat: BigDecimal?, -) - -public fun Price.toPartial(): PricePartial { - return PricePartial( - excl_vat = excl_vat, - incl_vat = incl_vat - ) -} - -public fun List.toPartial(): List { - return mapNotNull { it.toPartial() } -} diff --git a/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/locations/http/cpo/LocationsCpoHttpGetConnectorTest.kt b/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/locations/http/cpo/LocationsCpoHttpGetConnectorTest.kt index 2ee35bcb..1d6b5c55 100644 --- a/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/locations/http/cpo/LocationsCpoHttpGetConnectorTest.kt +++ b/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/locations/http/cpo/LocationsCpoHttpGetConnectorTest.kt @@ -15,7 +15,7 @@ import com.izivia.ocpi.toolkit.transport.TransportClient import com.izivia.ocpi.toolkit.transport.domain.HttpMethod import com.izivia.ocpi.toolkit.transport.domain.HttpResponse import com.izivia.ocpi.toolkit.transport.domain.HttpStatus -import io.mockk.every +import io.mockk.coEvery import io.mockk.mockk import io.mockk.slot import kotlinx.coroutines.runBlocking @@ -33,22 +33,22 @@ class LocationsCpoHttpGetConnectorTest { var connectorId = slot() } val srv = mockk() { - every { + coEvery { getConnector( capture(slots.locationId), capture(slots.evseUid), capture(slots.connectorId) ) - } answers { + } coAnswers { Connector( id = "1", standard = ConnectorType.IEC_62196_T2, format = ConnectorFormat.CABLE, - power_type = PowerType.AC_3_PHASE, - max_voltage = 220, - max_amperage = 16, - tariff_ids = listOf("11"), - last_updated = Instant.parse("2015-03-16T10:10:02Z") + powerType = PowerType.AC_3_PHASE, + maxVoltage = 220, + maxAmperage = 16, + tariffIds = listOf("11"), + lastUpdated = Instant.parse("2015-03-16T10:10:02Z") ) } }.buildServer() @@ -84,7 +84,7 @@ class LocationsCpoHttpGetConnectorTest { "status_message": "Success", "timestamp": "2015-06-30T21:59:59Z" } - """.trimIndent() + """.trimIndent() ) } } diff --git a/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/locations/http/cpo/LocationsCpoHttpGetEvseTest.kt b/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/locations/http/cpo/LocationsCpoHttpGetEvseTest.kt index 74b0cc57..5c474620 100644 --- a/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/locations/http/cpo/LocationsCpoHttpGetEvseTest.kt +++ b/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/locations/http/cpo/LocationsCpoHttpGetEvseTest.kt @@ -12,7 +12,7 @@ import com.izivia.ocpi.toolkit.transport.TransportClient import com.izivia.ocpi.toolkit.transport.domain.HttpMethod import com.izivia.ocpi.toolkit.transport.domain.HttpResponse import com.izivia.ocpi.toolkit.transport.domain.HttpStatus -import io.mockk.every +import io.mockk.coEvery import io.mockk.mockk import io.mockk.slot import kotlinx.coroutines.runBlocking @@ -29,10 +29,10 @@ class LocationsCpoHttpGetEvseTest { var evseUid = slot() } val srv = mockk() { - every { getEvse(capture(slots.locationId), capture(slots.evseUid)) } answers { + coEvery { getEvse(capture(slots.locationId), capture(slots.evseUid)) } coAnswers { Evse( uid = "3256", - evse_id = "BE*BEC*E041503001", + evseId = "BE*BEC*E041503001", status = Status.AVAILABLE, capabilities = listOf(Capability.RESERVABLE), connectors = listOf( @@ -40,26 +40,26 @@ class LocationsCpoHttpGetEvseTest { id = "1", standard = ConnectorType.IEC_62196_T2, format = ConnectorFormat.CABLE, - power_type = PowerType.AC_3_PHASE, - max_voltage = 220, - max_amperage = 16, - tariff_ids = listOf("11"), - last_updated = Instant.parse("2015-03-16T10:10:02Z") + powerType = PowerType.AC_3_PHASE, + maxVoltage = 220, + maxAmperage = 16, + tariffIds = listOf("11"), + lastUpdated = Instant.parse("2015-03-16T10:10:02Z") ), Connector( id = "2", standard = ConnectorType.IEC_62196_T2, format = ConnectorFormat.SOCKET, - power_type = PowerType.AC_3_PHASE, - max_voltage = 220, - max_amperage = 16, - tariff_ids = listOf("13"), - last_updated = Instant.parse("2015-03-18T08:12:01Z") - ), + powerType = PowerType.AC_3_PHASE, + maxVoltage = 220, + maxAmperage = 16, + tariffIds = listOf("13"), + lastUpdated = Instant.parse("2015-03-18T08:12:01Z") + ) ), - floor_level = "-1", - physical_reference = "1", - last_updated = Instant.parse("2015-06-28T08:12:01Z") + floorLevel = "-1", + physicalReference = "1", + lastUpdated = Instant.parse("2015-06-28T08:12:01Z") ) } }.buildServer() @@ -117,7 +117,7 @@ class LocationsCpoHttpGetEvseTest { "status_message": "Success", "timestamp": "2015-06-30T21:59:59Z" } - """.trimIndent() + """.trimIndent() ) } } diff --git a/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/locations/http/cpo/LocationsCpoHttpGetLocationTest.kt b/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/locations/http/cpo/LocationsCpoHttpGetLocationTest.kt index eeafda2b..39d515d7 100644 --- a/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/locations/http/cpo/LocationsCpoHttpGetLocationTest.kt +++ b/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/locations/http/cpo/LocationsCpoHttpGetLocationTest.kt @@ -12,7 +12,7 @@ import com.izivia.ocpi.toolkit.transport.TransportClient import com.izivia.ocpi.toolkit.transport.domain.HttpMethod import com.izivia.ocpi.toolkit.transport.domain.HttpResponse import com.izivia.ocpi.toolkit.transport.domain.HttpStatus -import io.mockk.every +import io.mockk.coEvery import io.mockk.mockk import io.mockk.slot import kotlinx.coroutines.runBlocking @@ -28,22 +28,22 @@ class LocationsCpoHttpGetLocationTest { var locationId = slot() } val srv = mockk() { - every { getLocation(capture((slots.locationId))) } answers { + coEvery { getLocation(capture((slots.locationId))) } coAnswers { Location( - country_code = "BE", - party_id = "BEC", + countryCode = "BE", + partyId = "BEC", id = "LOC1", name = "Gent Zuid", address = "F.Rooseveltlaan 3A", city = "Gent", - postal_code = "9000", + postalCode = "9000", country = "BEL", coordinates = GeoLocation("51.047599", "3.729944"), - parking_type = ParkingType.ON_STREET, + parkingType = ParkingType.ON_STREET, evses = listOf( Evse( uid = "3256", - evse_id = "BE*BEC*E041503001", + evseId = "BE*BEC*E041503001", status = Status.AVAILABLE, capabilities = listOf(Capability.RESERVABLE), connectors = listOf( @@ -51,30 +51,30 @@ class LocationsCpoHttpGetLocationTest { id = "1", standard = ConnectorType.IEC_62196_T2, format = ConnectorFormat.CABLE, - power_type = PowerType.AC_3_PHASE, - max_voltage = 220, - max_amperage = 16, - tariff_ids = listOf("11"), - last_updated = Instant.parse("2015-03-16T10:10:02Z") + powerType = PowerType.AC_3_PHASE, + maxVoltage = 220, + maxAmperage = 16, + tariffIds = listOf("11"), + lastUpdated = Instant.parse("2015-03-16T10:10:02Z") ), Connector( id = "2", standard = ConnectorType.IEC_62196_T2, format = ConnectorFormat.SOCKET, - power_type = PowerType.AC_3_PHASE, - max_voltage = 220, - max_amperage = 16, - tariff_ids = listOf("13"), - last_updated = Instant.parse("2015-03-18T08:12:01Z") - ), + powerType = PowerType.AC_3_PHASE, + maxVoltage = 220, + maxAmperage = 16, + tariffIds = listOf("13"), + lastUpdated = Instant.parse("2015-03-18T08:12:01Z") + ) ), - floor_level = "-1", - physical_reference = "1", - last_updated = Instant.parse("2015-06-28T08:12:01Z") + floorLevel = "-1", + physicalReference = "1", + lastUpdated = Instant.parse("2015-06-28T08:12:01Z") ), Evse( uid = "3257", - evse_id = "BE*BEC*E041503002", + evseId = "BE*BEC*E041503002", status = Status.RESERVED, capabilities = listOf(Capability.RESERVABLE), connectors = listOf( @@ -82,24 +82,24 @@ class LocationsCpoHttpGetLocationTest { id = "1", standard = ConnectorType.IEC_62196_T2, format = ConnectorFormat.SOCKET, - power_type = PowerType.AC_3_PHASE, - max_voltage = 220, - max_amperage = 16, - tariff_ids = listOf("12"), - last_updated = Instant.parse("2015-06-29T20:39:09Z") + powerType = PowerType.AC_3_PHASE, + maxVoltage = 220, + maxAmperage = 16, + tariffIds = listOf("12"), + lastUpdated = Instant.parse("2015-06-29T20:39:09Z") ) ), - floor_level = "-2", - physical_reference = "2", - last_updated = Instant.parse("2015-06-29T20:39:09Z") + floorLevel = "-2", + physicalReference = "2", + lastUpdated = Instant.parse("2015-06-29T20:39:09Z") ) ), operator = BusinessDetails( name = "BeCharged" ), publish = true, - time_zone = "Europe/Brussels", - last_updated = Instant.parse("2015-06-29T20:39:09Z") + timeZone = "Europe/Brussels", + lastUpdated = Instant.parse("2015-06-29T20:39:09Z") ) } }.buildServer() @@ -202,7 +202,7 @@ class LocationsCpoHttpGetLocationTest { "status_message": "Success", "timestamp": "2015-06-30T21:59:59Z" } - """.trimIndent() + """.trimIndent() ) } } diff --git a/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/locations/http/cpo/LocationsCpoHttpGetLocationsTest.kt b/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/locations/http/cpo/LocationsCpoHttpGetLocationsTest.kt index a9721ccf..bcd554b6 100644 --- a/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/locations/http/cpo/LocationsCpoHttpGetLocationsTest.kt +++ b/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/locations/http/cpo/LocationsCpoHttpGetLocationsTest.kt @@ -13,7 +13,7 @@ import com.izivia.ocpi.toolkit.transport.TransportClient import com.izivia.ocpi.toolkit.transport.domain.HttpMethod import com.izivia.ocpi.toolkit.transport.domain.HttpResponse import com.izivia.ocpi.toolkit.transport.domain.HttpStatus -import io.mockk.every +import io.mockk.coEvery import io.mockk.mockk import io.mockk.slot import kotlinx.coroutines.runBlocking @@ -31,42 +31,42 @@ class LocationsCpoHttpGetLocationsTest { var dateTo = slot() } val srv = mockk() { - every { getLocations(capture(slots.dateFrom), capture(slots.dateTo), any(), any()) } answers { + coEvery { getLocations(capture(slots.dateFrom), capture(slots.dateTo), any(), any()) } coAnswers { listOf( Location( - country_code = "NL", - party_id = "ALF", + countryCode = "NL", + partyId = "ALF", id = "3e7b39c2-10d0-4138-a8b3-8509a25f9920", name = "ihomer", address = "Tamboerijn 7", city = "Etten-Leur", - postal_code = "4876 BS", + postalCode = "4876 BS", country = "NLD", coordinates = GeoLocation("51.562787", "4.638975"), - parking_type = ParkingType.PARKING_LOT, + parkingType = ParkingType.PARKING_LOT, evses = listOf( Evse( uid = "fd855359-bc81-47bb-bb89-849ae3dac89e", - evse_id = "NL*ALF*E000000001", + evseId = "NL*ALF*E000000001", status = Status.AVAILABLE, connectors = listOf( Connector( id = "1", standard = ConnectorType.IEC_62196_T2, format = ConnectorFormat.SOCKET, - power_type = PowerType.AC_3_PHASE, - max_voltage = 220, - max_amperage = 16, - last_updated = Instant.parse("2019-07-01T12:12:11Z") + powerType = PowerType.AC_3_PHASE, + maxVoltage = 220, + maxAmperage = 16, + lastUpdated = Instant.parse("2019-07-01T12:12:11Z") ) ), - parking_restrictions = listOf(ParkingRestriction.CUSTOMERS), - last_updated = Instant.parse("2019-07-01T12:12:11Z") + parkingRestrictions = listOf(ParkingRestriction.CUSTOMERS), + lastUpdated = Instant.parse("2019-07-01T12:12:11Z") ) ), publish = true, - time_zone = "Europe/Amsterdam", - last_updated = Instant.parse("2019-07-01T12:12:11Z") + timeZone = "Europe/Amsterdam", + lastUpdated = Instant.parse("2019-07-01T12:12:11Z") ) ).toSearchResult() } diff --git a/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/locations/http/emsp/LocationsEmspHttpGetConnectorTest.kt b/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/locations/http/emsp/LocationsEmspHttpGetConnectorTest.kt index 0477e20b..8abd8cf9 100644 --- a/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/locations/http/emsp/LocationsEmspHttpGetConnectorTest.kt +++ b/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/locations/http/emsp/LocationsEmspHttpGetConnectorTest.kt @@ -15,7 +15,7 @@ import com.izivia.ocpi.toolkit.transport.TransportClient import com.izivia.ocpi.toolkit.transport.domain.HttpMethod import com.izivia.ocpi.toolkit.transport.domain.HttpResponse import com.izivia.ocpi.toolkit.transport.domain.HttpStatus -import io.mockk.every +import io.mockk.coEvery import io.mockk.mockk import io.mockk.slot import kotlinx.coroutines.runBlocking @@ -35,7 +35,7 @@ class LocationsEmspHttpGetConnectorTest { var connectorId = slot() } val srv = mockk() { - every { + coEvery { getConnector( capture(slots.countryCode), capture(slots.partyId), @@ -43,16 +43,16 @@ class LocationsEmspHttpGetConnectorTest { capture(slots.evseUid), capture(slots.connectorId) ) - } answers { + } coAnswers { Connector( id = "1", standard = ConnectorType.IEC_62196_T2, format = ConnectorFormat.CABLE, - power_type = PowerType.AC_3_PHASE, - max_voltage = 220, - max_amperage = 16, - tariff_ids = listOf("11"), - last_updated = Instant.parse("2015-03-16T10:10:02Z") + powerType = PowerType.AC_3_PHASE, + maxVoltage = 220, + maxAmperage = 16, + tariffIds = listOf("11"), + lastUpdated = Instant.parse("2015-03-16T10:10:02Z") ) } }.buildServer() @@ -90,7 +90,7 @@ class LocationsEmspHttpGetConnectorTest { "status_message": "Success", "timestamp": "2015-06-30T21:59:59Z" } - """.trimIndent() + """.trimIndent() ) } } diff --git a/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/locations/http/emsp/LocationsEmspHttpGetEvseTest.kt b/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/locations/http/emsp/LocationsEmspHttpGetEvseTest.kt index d8d539db..5e5c041a 100644 --- a/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/locations/http/emsp/LocationsEmspHttpGetEvseTest.kt +++ b/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/locations/http/emsp/LocationsEmspHttpGetEvseTest.kt @@ -12,7 +12,7 @@ import com.izivia.ocpi.toolkit.transport.TransportClient import com.izivia.ocpi.toolkit.transport.domain.HttpMethod import com.izivia.ocpi.toolkit.transport.domain.HttpResponse import com.izivia.ocpi.toolkit.transport.domain.HttpStatus -import io.mockk.every +import io.mockk.coEvery import io.mockk.mockk import io.mockk.slot import kotlinx.coroutines.runBlocking @@ -31,17 +31,17 @@ class LocationsEmspHttpGetEvseTest { var evseUid = slot() } val srv = mockk() { - every { + coEvery { getEvse( capture(slots.countryCode), capture(slots.partyId), capture(slots.locationId), capture(slots.evseUid) ) - } answers { + } coAnswers { Evse( uid = "3256", - evse_id = "BE*BEC*E041503001", + evseId = "BE*BEC*E041503001", status = Status.AVAILABLE, capabilities = listOf(Capability.RESERVABLE), connectors = listOf( @@ -49,26 +49,26 @@ class LocationsEmspHttpGetEvseTest { id = "1", standard = ConnectorType.IEC_62196_T2, format = ConnectorFormat.CABLE, - power_type = PowerType.AC_3_PHASE, - max_voltage = 220, - max_amperage = 16, - tariff_ids = listOf("11"), - last_updated = Instant.parse("2015-03-16T10:10:02Z") + powerType = PowerType.AC_3_PHASE, + maxVoltage = 220, + maxAmperage = 16, + tariffIds = listOf("11"), + lastUpdated = Instant.parse("2015-03-16T10:10:02Z") ), Connector( id = "2", standard = ConnectorType.IEC_62196_T2, format = ConnectorFormat.SOCKET, - power_type = PowerType.AC_3_PHASE, - max_voltage = 220, - max_amperage = 16, - tariff_ids = listOf("13"), - last_updated = Instant.parse("2015-03-18T08:12:01Z") - ), + powerType = PowerType.AC_3_PHASE, + maxVoltage = 220, + maxAmperage = 16, + tariffIds = listOf("13"), + lastUpdated = Instant.parse("2015-03-18T08:12:01Z") + ) ), - floor_level = "-1", - physical_reference = "1", - last_updated = Instant.parse("2015-06-28T08:12:01Z") + floorLevel = "-1", + physicalReference = "1", + lastUpdated = Instant.parse("2015-06-28T08:12:01Z") ) } }.buildServer() @@ -128,7 +128,7 @@ class LocationsEmspHttpGetEvseTest { "status_message": "Success", "timestamp": "2015-06-30T21:59:59Z" } - """.trimIndent() + """.trimIndent() ) } } diff --git a/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/locations/http/emsp/LocationsEmspHttpGetLocationTest.kt b/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/locations/http/emsp/LocationsEmspHttpGetLocationTest.kt index 1f41c3d2..4ca2cfea 100644 --- a/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/locations/http/emsp/LocationsEmspHttpGetLocationTest.kt +++ b/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/locations/http/emsp/LocationsEmspHttpGetLocationTest.kt @@ -12,7 +12,7 @@ import com.izivia.ocpi.toolkit.transport.TransportClient import com.izivia.ocpi.toolkit.transport.domain.HttpMethod import com.izivia.ocpi.toolkit.transport.domain.HttpResponse import com.izivia.ocpi.toolkit.transport.domain.HttpStatus -import io.mockk.every +import io.mockk.coEvery import io.mockk.mockk import io.mockk.slot import kotlinx.coroutines.runBlocking @@ -30,28 +30,28 @@ class LocationsEmspHttpGetLocationTest { var locationId = slot() } val srv = mockk() { - every { + coEvery { getLocation( capture(slots.countryCode), capture(slots.partyId), - capture(slots.locationId), + capture(slots.locationId) ) - } answers { + } coAnswers { Location( - country_code = "BE", - party_id = "BEC", + countryCode = "BE", + partyId = "BEC", id = "LOC1", name = "Gent Zuid", address = "F.Rooseveltlaan 3A", city = "Gent", - postal_code = "9000", + postalCode = "9000", country = "BEL", coordinates = GeoLocation("51.047599", "3.729944"), - parking_type = ParkingType.ON_STREET, + parkingType = ParkingType.ON_STREET, evses = listOf( Evse( uid = "3256", - evse_id = "BE*BEC*E041503001", + evseId = "BE*BEC*E041503001", status = Status.AVAILABLE, capabilities = listOf(Capability.RESERVABLE), connectors = listOf( @@ -59,30 +59,30 @@ class LocationsEmspHttpGetLocationTest { id = "1", standard = ConnectorType.IEC_62196_T2, format = ConnectorFormat.CABLE, - power_type = PowerType.AC_3_PHASE, - max_voltage = 220, - max_amperage = 16, - tariff_ids = listOf("11"), - last_updated = Instant.parse("2015-03-16T10:10:02Z") + powerType = PowerType.AC_3_PHASE, + maxVoltage = 220, + maxAmperage = 16, + tariffIds = listOf("11"), + lastUpdated = Instant.parse("2015-03-16T10:10:02Z") ), Connector( id = "2", standard = ConnectorType.IEC_62196_T2, format = ConnectorFormat.SOCKET, - power_type = PowerType.AC_3_PHASE, - max_voltage = 220, - max_amperage = 16, - tariff_ids = listOf("13"), - last_updated = Instant.parse("2015-03-18T08:12:01Z") - ), + powerType = PowerType.AC_3_PHASE, + maxVoltage = 220, + maxAmperage = 16, + tariffIds = listOf("13"), + lastUpdated = Instant.parse("2015-03-18T08:12:01Z") + ) ), - floor_level = "-1", - physical_reference = "1", - last_updated = Instant.parse("2015-06-28T08:12:01Z") + floorLevel = "-1", + physicalReference = "1", + lastUpdated = Instant.parse("2015-06-28T08:12:01Z") ), Evse( uid = "3257", - evse_id = "BE*BEC*E041503002", + evseId = "BE*BEC*E041503002", status = Status.RESERVED, capabilities = listOf(Capability.RESERVABLE), connectors = listOf( @@ -90,24 +90,24 @@ class LocationsEmspHttpGetLocationTest { id = "1", standard = ConnectorType.IEC_62196_T2, format = ConnectorFormat.SOCKET, - power_type = PowerType.AC_3_PHASE, - max_voltage = 220, - max_amperage = 16, - tariff_ids = listOf("12"), - last_updated = Instant.parse("2015-06-29T20:39:09Z") + powerType = PowerType.AC_3_PHASE, + maxVoltage = 220, + maxAmperage = 16, + tariffIds = listOf("12"), + lastUpdated = Instant.parse("2015-06-29T20:39:09Z") ) ), - floor_level = "-2", - physical_reference = "2", - last_updated = Instant.parse("2015-06-29T20:39:09Z") + floorLevel = "-2", + physicalReference = "2", + lastUpdated = Instant.parse("2015-06-29T20:39:09Z") ) ), operator = BusinessDetails( name = "BeCharged" ), publish = true, - time_zone = "Europe/Brussels", - last_updated = Instant.parse("2015-06-29T20:39:09Z") + timeZone = "Europe/Brussels", + lastUpdated = Instant.parse("2015-06-29T20:39:09Z") ) } }.buildServer() @@ -212,7 +212,7 @@ class LocationsEmspHttpGetLocationTest { "status_message": "Success", "timestamp": "2015-06-30T21:59:59Z" } - """.trimIndent() + """.trimIndent() ) } } diff --git a/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/locations/http/emsp/LocationsEmspHttpPatchConnectorTest.kt b/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/locations/http/emsp/LocationsEmspHttpPatchConnectorTest.kt index c1912713..db19fba3 100644 --- a/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/locations/http/emsp/LocationsEmspHttpPatchConnectorTest.kt +++ b/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/locations/http/emsp/LocationsEmspHttpPatchConnectorTest.kt @@ -13,7 +13,7 @@ import com.izivia.ocpi.toolkit.transport.TransportClient import com.izivia.ocpi.toolkit.transport.domain.HttpMethod import com.izivia.ocpi.toolkit.transport.domain.HttpResponse import com.izivia.ocpi.toolkit.transport.domain.HttpStatus -import io.mockk.every +import io.mockk.coEvery import io.mockk.mockk import io.mockk.slot import kotlinx.coroutines.runBlocking @@ -34,7 +34,7 @@ class LocationsEmspHttpPatchConnectorTest { var connector = slot() } val srv = mockk() { - every { + coEvery { patchConnector( capture(slots.countryCode), capture(slots.partyId), @@ -43,16 +43,16 @@ class LocationsEmspHttpPatchConnectorTest { capture(slots.connectorId), capture(slots.connector) ) - } answers { + } coAnswers { Connector( id = "1", standard = ConnectorType.IEC_62196_T2, format = ConnectorFormat.CABLE, - power_type = PowerType.AC_3_PHASE, - max_voltage = 220, - max_amperage = 16, - tariff_ids = listOf("11"), - last_updated = Instant.parse("2015-03-16T10:10:02Z") + powerType = PowerType.AC_3_PHASE, + maxVoltage = 220, + maxAmperage = 16, + tariffIds = listOf("11"), + lastUpdated = Instant.parse("2015-03-16T10:10:02Z") ) } }.buildServer() @@ -63,13 +63,13 @@ class LocationsEmspHttpPatchConnectorTest { id = "1", standard = null, format = null, - power_type = null, - max_voltage = null, - max_amperage = null, - tariff_ids = null, - max_electric_power = null, - terms_and_conditions = null, - last_updated = null + powerType = null, + maxVoltage = null, + maxAmperage = null, + tariffIds = null, + maxElectricPower = null, + termsAndConditions = null, + lastUpdated = null ) val resp: HttpResponse = srv.send( buildHttpRequest(HttpMethod.PATCH, "/locations/BE/BEC/LOC1/3256/1", mapper.writeValueAsString(connector)) @@ -92,7 +92,7 @@ class LocationsEmspHttpPatchConnectorTest { "status_message": "Success", "timestamp": "2015-06-30T21:59:59Z" } - """.trimIndent() + """.trimIndent() ) } } diff --git a/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/locations/http/emsp/LocationsEmspHttpPatchEvseTest.kt b/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/locations/http/emsp/LocationsEmspHttpPatchEvseTest.kt index 10e27a6d..2c57576f 100644 --- a/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/locations/http/emsp/LocationsEmspHttpPatchEvseTest.kt +++ b/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/locations/http/emsp/LocationsEmspHttpPatchEvseTest.kt @@ -13,7 +13,7 @@ import com.izivia.ocpi.toolkit.transport.TransportClient import com.izivia.ocpi.toolkit.transport.domain.HttpMethod import com.izivia.ocpi.toolkit.transport.domain.HttpResponse import com.izivia.ocpi.toolkit.transport.domain.HttpStatus -import io.mockk.every +import io.mockk.coEvery import io.mockk.mockk import io.mockk.slot import kotlinx.coroutines.runBlocking @@ -33,7 +33,7 @@ class LocationsEmspHttpPatchEvseTest { var evse = slot() } val srv = mockk() { - every { + coEvery { patchEvse( capture(slots.countryCode), capture(slots.partyId), @@ -41,10 +41,10 @@ class LocationsEmspHttpPatchEvseTest { capture(slots.evseUid), capture(slots.evse) ) - } answers { + } coAnswers { Evse( uid = "3256", - evse_id = "BE*BEC*E041503001", + evseId = "BE*BEC*E041503001", status = Status.AVAILABLE, capabilities = listOf(Capability.RESERVABLE), connectors = listOf( @@ -52,26 +52,26 @@ class LocationsEmspHttpPatchEvseTest { id = "1", standard = ConnectorType.IEC_62196_T2, format = ConnectorFormat.CABLE, - power_type = PowerType.AC_3_PHASE, - max_voltage = 220, - max_amperage = 16, - tariff_ids = listOf("11"), - last_updated = Instant.parse("2015-03-16T10:10:02Z") + powerType = PowerType.AC_3_PHASE, + maxVoltage = 220, + maxAmperage = 16, + tariffIds = listOf("11"), + lastUpdated = Instant.parse("2015-03-16T10:10:02Z") ), Connector( id = "2", standard = ConnectorType.IEC_62196_T2, format = ConnectorFormat.SOCKET, - power_type = PowerType.AC_3_PHASE, - max_voltage = 220, - max_amperage = 16, - tariff_ids = listOf("13"), - last_updated = Instant.parse("2015-03-18T08:12:01Z") - ), + powerType = PowerType.AC_3_PHASE, + maxVoltage = 220, + maxAmperage = 16, + tariffIds = listOf("13"), + lastUpdated = Instant.parse("2015-03-18T08:12:01Z") + ) ), - floor_level = "-1", - physical_reference = "1", - last_updated = Instant.parse("2015-06-28T08:12:01Z") + floorLevel = "-1", + physicalReference = "1", + lastUpdated = Instant.parse("2015-06-28T08:12:01Z") ) } }.buildServer() @@ -80,18 +80,18 @@ class LocationsEmspHttpPatchEvseTest { // when val evse = EvsePartial( uid = "1", - evse_id = null, + evseId = null, status = null, - status_schedule = null, + statusSchedule = null, capabilities = null, connectors = null, - floor_level = null, + floorLevel = null, coordinates = null, - physical_reference = null, + physicalReference = null, directions = null, - parking_restrictions = null, + parkingRestrictions = null, images = null, - last_updated = null, + lastUpdated = null ) val resp: HttpResponse = srv.send( buildHttpRequest(HttpMethod.PATCH, "/locations/BE/BEC/LOC1/3256", mapper.writeValueAsString(evse)) @@ -113,7 +113,7 @@ class LocationsEmspHttpPatchEvseTest { "status_message": "Success", "timestamp": "2015-06-30T21:59:59Z" } - """.trimIndent() + """.trimIndent() ) } } @@ -132,4 +132,3 @@ private fun LocationsEmspRepository.buildServer(): TransportClient { return transportServer.initRouterAndBuildClient() } - diff --git a/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/locations/http/emsp/LocationsEmspHttpPatchLocationTest.kt b/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/locations/http/emsp/LocationsEmspHttpPatchLocationTest.kt index 9ba5b72c..dadac80c 100644 --- a/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/locations/http/emsp/LocationsEmspHttpPatchLocationTest.kt +++ b/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/locations/http/emsp/LocationsEmspHttpPatchLocationTest.kt @@ -13,7 +13,7 @@ import com.izivia.ocpi.toolkit.transport.TransportClient import com.izivia.ocpi.toolkit.transport.domain.HttpMethod import com.izivia.ocpi.toolkit.transport.domain.HttpResponse import com.izivia.ocpi.toolkit.transport.domain.HttpStatus -import io.mockk.every +import io.mockk.coEvery import io.mockk.mockk import io.mockk.slot import kotlinx.coroutines.runBlocking @@ -32,29 +32,29 @@ class LocationsEmspHttpPatchLocationTest { var location = slot() } val srv = mockk() { - every { + coEvery { patchLocation( capture(slots.countryCode), capture(slots.partyId), capture(slots.locationId), capture(slots.location) ) - } answers { + } coAnswers { Location( - country_code = "BE", - party_id = "BEC", + countryCode = "BE", + partyId = "BEC", id = "LOC1", name = "Gent Zuid", address = "F.Rooseveltlaan 3A", city = "Gent", - postal_code = "9000", + postalCode = "9000", country = "BEL", coordinates = GeoLocation("51.047599", "3.729944"), - parking_type = ParkingType.ON_STREET, + parkingType = ParkingType.ON_STREET, evses = listOf( Evse( uid = "3256", - evse_id = "BE*BEC*E041503001", + evseId = "BE*BEC*E041503001", status = Status.AVAILABLE, capabilities = listOf(Capability.RESERVABLE), connectors = listOf( @@ -62,30 +62,30 @@ class LocationsEmspHttpPatchLocationTest { id = "1", standard = ConnectorType.IEC_62196_T2, format = ConnectorFormat.CABLE, - power_type = PowerType.AC_3_PHASE, - max_voltage = 220, - max_amperage = 16, - tariff_ids = listOf("11"), - last_updated = Instant.parse("2015-03-16T10:10:02Z") + powerType = PowerType.AC_3_PHASE, + maxVoltage = 220, + maxAmperage = 16, + tariffIds = listOf("11"), + lastUpdated = Instant.parse("2015-03-16T10:10:02Z") ), Connector( id = "2", standard = ConnectorType.IEC_62196_T2, format = ConnectorFormat.SOCKET, - power_type = PowerType.AC_3_PHASE, - max_voltage = 220, - max_amperage = 16, - tariff_ids = listOf("13"), - last_updated = Instant.parse("2015-03-18T08:12:01Z") - ), + powerType = PowerType.AC_3_PHASE, + maxVoltage = 220, + maxAmperage = 16, + tariffIds = listOf("13"), + lastUpdated = Instant.parse("2015-03-18T08:12:01Z") + ) ), - floor_level = "-1", - physical_reference = "1", - last_updated = Instant.parse("2015-06-28T08:12:01Z") + floorLevel = "-1", + physicalReference = "1", + lastUpdated = Instant.parse("2015-06-28T08:12:01Z") ), Evse( uid = "3257", - evse_id = "BE*BEC*E041503002", + evseId = "BE*BEC*E041503002", status = Status.RESERVED, capabilities = listOf(Capability.RESERVABLE), connectors = listOf( @@ -93,24 +93,24 @@ class LocationsEmspHttpPatchLocationTest { id = "1", standard = ConnectorType.IEC_62196_T2, format = ConnectorFormat.SOCKET, - power_type = PowerType.AC_3_PHASE, - max_voltage = 220, - max_amperage = 16, - tariff_ids = listOf("12"), - last_updated = Instant.parse("2015-06-29T20:39:09Z") + powerType = PowerType.AC_3_PHASE, + maxVoltage = 220, + maxAmperage = 16, + tariffIds = listOf("12"), + lastUpdated = Instant.parse("2015-06-29T20:39:09Z") ) ), - floor_level = "-2", - physical_reference = "2", - last_updated = Instant.parse("2015-06-29T20:39:09Z") + floorLevel = "-2", + physicalReference = "2", + lastUpdated = Instant.parse("2015-06-29T20:39:09Z") ) ), operator = BusinessDetails( name = "BeCharged" ), publish = true, - time_zone = "Europe/Brussels", - last_updated = Instant.parse("2015-06-29T20:39:09Z") + timeZone = "Europe/Brussels", + lastUpdated = Instant.parse("2015-06-29T20:39:09Z") ) } }.buildServer() @@ -119,31 +119,31 @@ class LocationsEmspHttpPatchLocationTest { // when val location = LocationPartial( id = "1", - country_code = null, - party_id = null, + countryCode = null, + partyId = null, publish = null, - publish_allowed_to = null, + publishAllowedTo = null, name = null, address = null, city = null, - postal_code = null, + postalCode = null, state = null, country = null, coordinates = null, - related_locations = null, - parking_type = null, + relatedLocations = null, + parkingType = null, evses = null, directions = null, `operator` = null, suboperator = null, owner = null, facilities = null, - time_zone = null, - opening_times = null, - charging_when_closed = null, + timeZone = null, + openingTimes = null, + chargingWhenClosed = null, images = null, - energy_mix = null, - last_updated = null, + energyMix = null, + lastUpdated = null ) val resp: HttpResponse = srv.send( buildHttpRequest(HttpMethod.PATCH, "/locations/BE/BEC/LOC1", mapper.writeValueAsString(location)) @@ -164,7 +164,7 @@ class LocationsEmspHttpPatchLocationTest { "status_message": "Success", "timestamp": "2015-06-30T21:59:59Z" } - """.trimIndent() + """.trimIndent() ) } } diff --git a/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/locations/http/emsp/LocationsEmspHttpPutConnectorTest.kt b/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/locations/http/emsp/LocationsEmspHttpPutConnectorTest.kt index b25de03e..1e15de57 100644 --- a/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/locations/http/emsp/LocationsEmspHttpPutConnectorTest.kt +++ b/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/locations/http/emsp/LocationsEmspHttpPutConnectorTest.kt @@ -16,7 +16,7 @@ import com.izivia.ocpi.toolkit.transport.TransportClient import com.izivia.ocpi.toolkit.transport.domain.HttpMethod import com.izivia.ocpi.toolkit.transport.domain.HttpResponse import com.izivia.ocpi.toolkit.transport.domain.HttpStatus -import io.mockk.every +import io.mockk.coEvery import io.mockk.mockk import io.mockk.slot import kotlinx.coroutines.runBlocking @@ -40,14 +40,14 @@ class LocationsEmspHttpPutConnectorTest { id = "1", standard = ConnectorType.IEC_62196_T2, format = ConnectorFormat.CABLE, - power_type = PowerType.AC_3_PHASE, - max_voltage = 220, - max_amperage = 16, - tariff_ids = listOf("11"), - last_updated = Instant.parse("2015-03-16T10:10:02Z") + powerType = PowerType.AC_3_PHASE, + maxVoltage = 220, + maxAmperage = 16, + tariffIds = listOf("11"), + lastUpdated = Instant.parse("2015-03-16T10:10:02Z") ) val srv = mockk() { - every { + coEvery { putConnector( capture(slots.countryCode), capture(slots.partyId), @@ -56,9 +56,8 @@ class LocationsEmspHttpPutConnectorTest { capture(slots.connectorId), capture(slots.connector) ) - } answers { + } coAnswers { connector - } }.buildServer() OcpiResponseBody.now = { Instant.parse("2015-06-30T21:59:59Z") } @@ -85,7 +84,7 @@ class LocationsEmspHttpPutConnectorTest { "status_message": "Success", "timestamp": "2015-06-30T21:59:59Z" } - """.trimIndent() + """.trimIndent() ) } } diff --git a/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/locations/http/emsp/LocationsEmspHttpPutEvseTest.kt b/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/locations/http/emsp/LocationsEmspHttpPutEvseTest.kt index ed12ae3c..59d4aa4c 100644 --- a/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/locations/http/emsp/LocationsEmspHttpPutEvseTest.kt +++ b/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/locations/http/emsp/LocationsEmspHttpPutEvseTest.kt @@ -13,7 +13,7 @@ import com.izivia.ocpi.toolkit.transport.TransportClient import com.izivia.ocpi.toolkit.transport.domain.HttpMethod import com.izivia.ocpi.toolkit.transport.domain.HttpResponse import com.izivia.ocpi.toolkit.transport.domain.HttpStatus -import io.mockk.every +import io.mockk.coEvery import io.mockk.mockk import io.mockk.slot import kotlinx.coroutines.runBlocking @@ -34,7 +34,7 @@ class LocationsEmspHttpPutEvseTest { } val evse = Evse( uid = "3256", - evse_id = "BE*BEC*E041503001", + evseId = "BE*BEC*E041503001", status = Status.AVAILABLE, capabilities = listOf(Capability.RESERVABLE), connectors = listOf( @@ -42,29 +42,29 @@ class LocationsEmspHttpPutEvseTest { id = "1", standard = ConnectorType.IEC_62196_T2, format = ConnectorFormat.CABLE, - power_type = PowerType.AC_3_PHASE, - max_voltage = 220, - max_amperage = 16, - tariff_ids = listOf("11"), - last_updated = Instant.parse("2015-03-16T10:10:02Z") + powerType = PowerType.AC_3_PHASE, + maxVoltage = 220, + maxAmperage = 16, + tariffIds = listOf("11"), + lastUpdated = Instant.parse("2015-03-16T10:10:02Z") ), Connector( id = "2", standard = ConnectorType.IEC_62196_T2, format = ConnectorFormat.SOCKET, - power_type = PowerType.AC_3_PHASE, - max_voltage = 220, - max_amperage = 16, - tariff_ids = listOf("13"), - last_updated = Instant.parse("2015-03-18T08:12:01Z") - ), + powerType = PowerType.AC_3_PHASE, + maxVoltage = 220, + maxAmperage = 16, + tariffIds = listOf("13"), + lastUpdated = Instant.parse("2015-03-18T08:12:01Z") + ) ), - floor_level = "-1", - physical_reference = "1", - last_updated = Instant.parse("2015-06-28T08:12:01Z") + floorLevel = "-1", + physicalReference = "1", + lastUpdated = Instant.parse("2015-06-28T08:12:01Z") ) val srv = mockk() { - every { + coEvery { putEvse( capture(slots.countryCode), capture(slots.partyId), @@ -72,7 +72,7 @@ class LocationsEmspHttpPutEvseTest { capture(slots.evseUid), capture(slots.evse) ) - } answers { + } coAnswers { evse } }.buildServer() @@ -99,7 +99,7 @@ class LocationsEmspHttpPutEvseTest { "status_message": "Success", "timestamp": "2015-06-30T21:59:59Z" } - """.trimIndent() + """.trimIndent() ) } } diff --git a/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/locations/http/emsp/LocationsEmspHttpPutLocationTest.kt b/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/locations/http/emsp/LocationsEmspHttpPutLocationTest.kt index 02ce7351..f2670863 100644 --- a/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/locations/http/emsp/LocationsEmspHttpPutLocationTest.kt +++ b/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/locations/http/emsp/LocationsEmspHttpPutLocationTest.kt @@ -13,7 +13,7 @@ import com.izivia.ocpi.toolkit.transport.TransportClient import com.izivia.ocpi.toolkit.transport.domain.HttpMethod import com.izivia.ocpi.toolkit.transport.domain.HttpResponse import com.izivia.ocpi.toolkit.transport.domain.HttpStatus -import io.mockk.every +import io.mockk.coEvery import io.mockk.mockk import io.mockk.slot import kotlinx.coroutines.runBlocking @@ -32,20 +32,20 @@ class LocationsEmspHttpPutLocationTest { var location = slot() } val location = Location( - country_code = "BE", - party_id = "BEC", + countryCode = "BE", + partyId = "BEC", id = "LOC1", name = "Gent Zuid", address = "F.Rooseveltlaan 3A", city = "Gent", - postal_code = "9000", + postalCode = "9000", country = "BEL", coordinates = GeoLocation("51.047599", "3.729944"), - parking_type = ParkingType.ON_STREET, + parkingType = ParkingType.ON_STREET, evses = listOf( Evse( uid = "3256", - evse_id = "BE*BEC*E041503001", + evseId = "BE*BEC*E041503001", status = Status.AVAILABLE, capabilities = listOf(Capability.RESERVABLE), connectors = listOf( @@ -53,30 +53,30 @@ class LocationsEmspHttpPutLocationTest { id = "1", standard = ConnectorType.IEC_62196_T2, format = ConnectorFormat.CABLE, - power_type = PowerType.AC_3_PHASE, - max_voltage = 220, - max_amperage = 16, - tariff_ids = listOf("11"), - last_updated = Instant.parse("2015-03-16T10:10:02Z") + powerType = PowerType.AC_3_PHASE, + maxVoltage = 220, + maxAmperage = 16, + tariffIds = listOf("11"), + lastUpdated = Instant.parse("2015-03-16T10:10:02Z") ), Connector( id = "2", standard = ConnectorType.IEC_62196_T2, format = ConnectorFormat.SOCKET, - power_type = PowerType.AC_3_PHASE, - max_voltage = 220, - max_amperage = 16, - tariff_ids = listOf("13"), - last_updated = Instant.parse("2015-03-18T08:12:01Z") - ), + powerType = PowerType.AC_3_PHASE, + maxVoltage = 220, + maxAmperage = 16, + tariffIds = listOf("13"), + lastUpdated = Instant.parse("2015-03-18T08:12:01Z") + ) ), - floor_level = "-1", - physical_reference = "1", - last_updated = Instant.parse("2015-06-28T08:12:01Z") + floorLevel = "-1", + physicalReference = "1", + lastUpdated = Instant.parse("2015-06-28T08:12:01Z") ), Evse( uid = "3257", - evse_id = "BE*BEC*E041503002", + evseId = "BE*BEC*E041503002", status = Status.RESERVED, capabilities = listOf(Capability.RESERVABLE), connectors = listOf( @@ -84,35 +84,35 @@ class LocationsEmspHttpPutLocationTest { id = "1", standard = ConnectorType.IEC_62196_T2, format = ConnectorFormat.SOCKET, - power_type = PowerType.AC_3_PHASE, - max_voltage = 220, - max_amperage = 16, - tariff_ids = listOf("12"), - last_updated = Instant.parse("2015-06-29T20:39:09Z") + powerType = PowerType.AC_3_PHASE, + maxVoltage = 220, + maxAmperage = 16, + tariffIds = listOf("12"), + lastUpdated = Instant.parse("2015-06-29T20:39:09Z") ) ), - floor_level = "-2", - physical_reference = "2", - last_updated = Instant.parse("2015-06-29T20:39:09Z") + floorLevel = "-2", + physicalReference = "2", + lastUpdated = Instant.parse("2015-06-29T20:39:09Z") ) ), operator = BusinessDetails( name = "BeCharged" ), publish = true, - time_zone = "Europe/Brussels", - last_updated = Instant.parse("2015-06-29T20:39:09Z") + timeZone = "Europe/Brussels", + lastUpdated = Instant.parse("2015-06-29T20:39:09Z") ) val srv = mockk() { - every { + coEvery { putLocation( capture(slots.countryCode), capture(slots.partyId), capture(slots.locationId), capture(slots.location) ) - } answers { + } coAnswers { location } }.buildServer() @@ -138,7 +138,7 @@ class LocationsEmspHttpPutLocationTest { "status_message": "Success", "timestamp": "2015-06-30T21:59:59Z" } - """.trimIndent() + """.trimIndent() ) } } diff --git a/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/locations/mock/LocationsCpoRepository.kt b/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/locations/mock/LocationsCpoRepository.kt index 72d27c0f..090ab64c 100644 --- a/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/locations/mock/LocationsCpoRepository.kt +++ b/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/locations/mock/LocationsCpoRepository.kt @@ -3,7 +3,7 @@ package com.izivia.ocpi.toolkit.modules.locations.mock import com.izivia.ocpi.toolkit.common.toSearchResult import com.izivia.ocpi.toolkit.modules.locations.domain.Location import com.izivia.ocpi.toolkit.modules.locations.repositories.LocationsCpoRepository -import io.mockk.every +import io.mockk.coEvery import io.mockk.mockk import io.mockk.slot import java.time.Instant @@ -18,14 +18,16 @@ fun locationsCpoRepository(locations: List): LocationsCpoRepository = val offset = slot() val limit = mutableListOf() - every { getLocations(captureNullable(dateFrom), captureNullable(dateTo), capture(offset), captureNullable(limit)) } answers { + coEvery { + getLocations(captureNullable(dateFrom), captureNullable(dateTo), capture(offset), captureNullable(limit)) + } coAnswers { val capturedOffset = offset.captured val capturedLimit = limit.captured() ?: 10 locations .filter { loc -> - val dateFromFilterOk = dateFrom.captured()?.let { loc.last_updated.isAfter(it) } ?: true - val dateToFilterOk = dateTo.captured()?.let { loc.last_updated.isBefore(it) } ?: true + val dateFromFilterOk = dateFrom.captured()?.let { loc.lastUpdated.isAfter(it) } ?: true + val dateToFilterOk = dateTo.captured()?.let { loc.lastUpdated.isBefore(it) } ?: true dateFromFilterOk && dateToFilterOk } @@ -36,20 +38,20 @@ fun locationsCpoRepository(locations: List): LocationsCpoRepository = .toSearchResult(totalCount = locations.size, limit = capturedLimit, offset = capturedOffset) } - every { getLocation(capture(locationId)) } answers { + coEvery { getLocation(capture(locationId)) } coAnswers { locations.find { it.id.lowercase(Locale.ENGLISH) == locationId.captured.lowercase(Locale.ENGLISH) } } - every { getEvse(capture(locationId), capture(evseUid)) } answers { + coEvery { getEvse(capture(locationId), capture(evseUid)) } coAnswers { locations - .find { it.id.lowercase(Locale.ENGLISH) == locationId.captured.lowercase(Locale.ENGLISH) } + .find { it.id.lowercase(Locale.ENGLISH) == locationId.captured.lowercase(Locale.ENGLISH) } ?.evses ?.find { it.uid.lowercase(Locale.ENGLISH) == evseUid.captured.lowercase(Locale.ENGLISH) } } - every { getConnector(capture(locationId), capture(evseUid), capture(connectorId)) } answers { + coEvery { getConnector(capture(locationId), capture(evseUid), capture(connectorId)) } coAnswers { locations - .find { it.id.lowercase(Locale.ENGLISH) == locationId.captured.lowercase(Locale.ENGLISH) } + .find { it.id.lowercase(Locale.ENGLISH) == locationId.captured.lowercase(Locale.ENGLISH) } ?.evses ?.find { it.uid.lowercase(Locale.ENGLISH) == evseUid.captured.lowercase(Locale.ENGLISH) } ?.connectors diff --git a/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/locations/mock/LocationsEmspRepository.kt b/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/locations/mock/LocationsEmspRepository.kt index 0f469e38..63a4acbd 100644 --- a/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/locations/mock/LocationsEmspRepository.kt +++ b/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/locations/mock/LocationsEmspRepository.kt @@ -2,7 +2,7 @@ package com.izivia.ocpi.toolkit.modules.locations.mock import com.izivia.ocpi.toolkit.modules.locations.domain.* import com.izivia.ocpi.toolkit.modules.locations.repositories.LocationsEmspRepository -import io.mockk.every +import io.mockk.coEvery import io.mockk.mockk import io.mockk.slot import java.util.* @@ -20,33 +20,45 @@ fun locationsEmspRepository(locations: List): LocationsEmspRepository val evsePartial = slot() val connectorPartial = slot() - every { getLocation(capture(countryCode), capture(partyId), capture(locationId)) } answers { + coEvery { getLocation(capture(countryCode), capture(partyId), capture(locationId)) } coAnswers { locations.find { it.id.lowercase(Locale.ENGLISH) == locationId.captured.lowercase(Locale.ENGLISH) } } - every { getEvse(capture(countryCode), capture(partyId), capture(locationId), capture(evseUid)) } answers { + coEvery { getEvse(capture(countryCode), capture(partyId), capture(locationId), capture(evseUid)) } coAnswers { locations .find { it.id.lowercase(Locale.ENGLISH) == locationId.captured.lowercase(Locale.ENGLISH) } ?.evses ?.find { it.uid.lowercase(Locale.ENGLISH) == evseUid.captured.lowercase(Locale.ENGLISH) } } - every { getConnector(capture(countryCode), capture(partyId), capture(locationId), capture(evseUid), capture(connectorId)) } answers { + coEvery { + getConnector( + capture(countryCode), + capture(partyId), + capture(locationId), + capture(evseUid), + capture(connectorId) + ) + } coAnswers { locations - .find { it.id.lowercase(Locale.ENGLISH) == locationId.captured.lowercase(Locale.ENGLISH) } + .find { it.id.lowercase(Locale.ENGLISH) == locationId.captured.lowercase(Locale.ENGLISH) } ?.evses ?.find { it.uid.lowercase(Locale.ENGLISH) == evseUid.captured.lowercase(Locale.ENGLISH) } ?.connectors ?.find { it.id.lowercase(Locale.ENGLISH) == connectorId.captured.lowercase(Locale.ENGLISH) } } - every { patchLocation(capture(countryCode), capture(partyId), capture(locationId), capture(locationPartial)) } answers { + coEvery { + patchLocation(capture(countryCode), capture(partyId), capture(locationId), capture(locationPartial)) + } coAnswers { // Patch logic is not implemented locations .find { it.id.lowercase(Locale.ENGLISH) == locationId.captured.lowercase(Locale.ENGLISH) } } - every { patchEvse(capture(countryCode), capture(partyId), capture(locationId), capture(evseUid), capture(evsePartial)) } answers { + coEvery { + patchEvse(capture(countryCode), capture(partyId), capture(locationId), capture(evseUid), capture(evsePartial)) + } coAnswers { // Patch logic is not implemented locations .find { it.id.lowercase(Locale.ENGLISH) == locationId.captured.lowercase(Locale.ENGLISH) } @@ -54,24 +66,35 @@ fun locationsEmspRepository(locations: List): LocationsEmspRepository ?.find { it.uid.lowercase(Locale.ENGLISH) == evseUid.captured.lowercase(Locale.ENGLISH) } } - every { patchConnector(capture(countryCode), capture(partyId), capture(locationId), capture(evseUid), capture(connectorId), capture(connectorPartial)) } answers { + coEvery { + patchConnector( + capture(countryCode), + capture(partyId), + capture(locationId), + capture(evseUid), + capture(connectorId), + capture(connectorPartial) + ) + } coAnswers { // Patch logic is not implemented locations - .find { it.id.lowercase(Locale.ENGLISH) == locationId.captured.lowercase(Locale.ENGLISH) } + .find { it.id.lowercase(Locale.ENGLISH) == locationId.captured.lowercase(Locale.ENGLISH) } ?.evses ?.find { it.uid.lowercase(Locale.ENGLISH) == evseUid.captured.lowercase(Locale.ENGLISH) } ?.connectors ?.find { it.id.lowercase(Locale.ENGLISH) == connectorId.captured.lowercase(Locale.ENGLISH) } } - every { putLocation(capture(countryCode), capture(partyId), capture(locationId), capture(location)) } answers { + coEvery { putLocation(capture(countryCode), capture(partyId), capture(locationId), capture(location)) } coAnswers { // Put logic is not implemented locations .find { it.id.lowercase(Locale.ENGLISH) == locationId.captured.lowercase(Locale.ENGLISH) } ?: location.captured } - every { putEvse(capture(countryCode), capture(partyId), capture(locationId), capture(evseUid), capture(evse)) } answers { + coEvery { + putEvse(capture(countryCode), capture(partyId), capture(locationId), capture(evseUid), capture(evse)) + } coAnswers { // Put logic is not implemented locations .find { it.id.lowercase(Locale.ENGLISH) == locationId.captured.lowercase(Locale.ENGLISH) } @@ -80,10 +103,19 @@ fun locationsEmspRepository(locations: List): LocationsEmspRepository ?: evse.captured } - every { putConnector(capture(countryCode), capture(partyId), capture(locationId), capture(evseUid), capture(connectorId), capture(connector)) } answers { + coEvery { + putConnector( + capture(countryCode), + capture(partyId), + capture(locationId), + capture(evseUid), + capture(connectorId), + capture(connector) + ) + } coAnswers { // Put logic is not implemented locations - .find { it.id.lowercase(Locale.ENGLISH) == locationId.captured.lowercase(Locale.ENGLISH) } + .find { it.id.lowercase(Locale.ENGLISH) == locationId.captured.lowercase(Locale.ENGLISH) } ?.evses ?.find { it.uid.lowercase(Locale.ENGLISH) == evseUid.captured.lowercase(Locale.ENGLISH) } ?.connectors diff --git a/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/locations/services/LocationsCpoServiceTest.kt b/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/locations/services/LocationsCpoServiceTest.kt index 414bafe3..793ce770 100644 --- a/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/locations/services/LocationsCpoServiceTest.kt +++ b/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/locations/services/LocationsCpoServiceTest.kt @@ -3,7 +3,6 @@ package com.izivia.ocpi.toolkit.modules.locations.services import com.izivia.ocpi.toolkit.common.OcpiStatus import com.izivia.ocpi.toolkit.common.SearchResult import com.izivia.ocpi.toolkit.modules.locations.domain.Location -import com.izivia.ocpi.toolkit.modules.locations.services.LocationsCpoService import com.izivia.ocpi.toolkit.modules.locations.mock.locationsCpoRepository import kotlinx.coroutines.runBlocking import org.junit.jupiter.api.Test diff --git a/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/locations/services/LocationsEmspServiceTest.kt b/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/locations/services/LocationsEmspServiceTest.kt index b529b6df..a39341fe 100644 --- a/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/locations/services/LocationsEmspServiceTest.kt +++ b/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/locations/services/LocationsEmspServiceTest.kt @@ -2,11 +2,10 @@ package com.izivia.ocpi.toolkit.modules.locations.services import com.izivia.ocpi.toolkit.common.OcpiStatus import com.izivia.ocpi.toolkit.modules.locations.domain.toPartial -import com.izivia.ocpi.toolkit.modules.locations.services.LocationsEmspService +import com.izivia.ocpi.toolkit.modules.locations.mock.locationsEmspRepository import com.izivia.ocpi.toolkit.samples.common.validConnector import com.izivia.ocpi.toolkit.samples.common.validEvse import com.izivia.ocpi.toolkit.samples.common.validLocation -import com.izivia.ocpi.toolkit.modules.locations.mock.locationsEmspRepository import kotlinx.coroutines.runBlocking import org.junit.jupiter.api.Test import strikt.api.expectThat @@ -28,7 +27,8 @@ class LocationsEmspServiceTest { service = LocationsEmspService(service = locationsEmspRepository(emptyList())) expectThat( - runBlocking { service.getLocation(countryCode = str1char, partyId = str2chars, locationId = str4chars) }) { + runBlocking { service.getLocation(countryCode = str1char, partyId = str2chars, locationId = str4chars) } + ) { get { status_code } .isEqualTo(OcpiStatus.SUCCESS.code) } @@ -40,7 +40,8 @@ class LocationsEmspServiceTest { partyId = str3chars, locationId = str36chars ) - }) { + } + ) { get { status_code } .isEqualTo(OcpiStatus.SUCCESS.code) } @@ -52,7 +53,8 @@ class LocationsEmspServiceTest { partyId = str3chars, locationId = str36chars ) - }) { + } + ) { get { status_code } .isEqualTo(OcpiStatus.CLIENT_INVALID_PARAMETERS.code) } @@ -64,7 +66,8 @@ class LocationsEmspServiceTest { partyId = str4chars, locationId = str36chars ) - }) { + } + ) { get { status_code } .isEqualTo(OcpiStatus.CLIENT_INVALID_PARAMETERS.code) } @@ -76,7 +79,8 @@ class LocationsEmspServiceTest { partyId = str3chars, locationId = str40chars ) - }) { + } + ) { get { status_code } .isEqualTo(OcpiStatus.CLIENT_INVALID_PARAMETERS.code) } diff --git a/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/locations/services/LocationsValidatorTest.kt b/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/locations/services/LocationsValidatorTest.kt index 62cbb79c..152f6e1a 100644 --- a/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/locations/services/LocationsValidatorTest.kt +++ b/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/locations/services/LocationsValidatorTest.kt @@ -41,7 +41,7 @@ class LocationsValidatorTest { }.isFailure() expectCatching { - validLocation.copy(postal_code = generateRandomString(11)).validate() + validLocation.copy(postalCode = generateRandomString(11)).validate() }.isFailure() expectCatching { @@ -53,11 +53,11 @@ class LocationsValidatorTest { }.isFailure() expectCatching { - validLocation.copy(time_zone = generateRandomString(256)).validate() + validLocation.copy(timeZone = generateRandomString(256)).validate() }.isFailure() expectCatching { - validLocation.copy(time_zone = "EuropeOslo").validate() + validLocation.copy(timeZone = "EuropeOslo").validate() }.isFailure() } @@ -68,43 +68,43 @@ class LocationsValidatorTest { }.isSuccess() expectCatching { - validEvse.copy(evse_id = "FR*A23*E45B*78C").validate() + validEvse.copy(evseId = "FR*A23*E45B*78C").validate() }.isSuccess() expectCatching { - validEvse.copy(evse_id = "fr*a23*e45b*78c").validate() + validEvse.copy(evseId = "fr*a23*e45b*78c").validate() }.isSuccess() expectCatching { - validEvse.copy(evse_id = "FRA23E45B78C").validate() + validEvse.copy(evseId = "FRA23E45B78C").validate() }.isSuccess() expectCatching { - validEvse.copy(evse_id = "FRA23E45B*78C").validate() + validEvse.copy(evseId = "FRA23E45B*78C").validate() }.isSuccess() expectCatching { - validEvse.copy(evse_id = "FR*A23*E${generateRandomString(31)}").validate() + validEvse.copy(evseId = "FR*A23*E${generateRandomString(31)}").validate() }.isSuccess() expectCatching { - validEvse.copy(evse_id = "F*A23*E45B*78C").validate() + validEvse.copy(evseId = "F*A23*E45B*78C").validate() }.isFailure() expectCatching { - validEvse.copy(evse_id = "FR*A2*E45B*78C").validate() + validEvse.copy(evseId = "FR*A2*E45B*78C").validate() }.isFailure() expectCatching { - validEvse.copy(evse_id = "FR*A23*A45B*78C").validate() + validEvse.copy(evseId = "FR*A23*A45B*78C").validate() }.isFailure() expectCatching { - validEvse.copy(evse_id = "FR*A23*E").validate() + validEvse.copy(evseId = "FR*A23*E").validate() }.isFailure() expectCatching { - validEvse.copy(evse_id = "FR*A23*E${generateRandomString(32)}").validate() + validEvse.copy(evseId = "FR*A23*E${generateRandomString(32)}").validate() }.isFailure() expectCatching { @@ -112,11 +112,11 @@ class LocationsValidatorTest { }.isFailure() expectCatching { - validEvse.copy(floor_level = generateRandomString(5)).validate() + validEvse.copy(floorLevel = generateRandomString(5)).validate() }.isFailure() expectCatching { - validEvse.copy(physical_reference = generateRandomString(17)).validate() + validEvse.copy(physicalReference = generateRandomString(17)).validate() }.isFailure() } @@ -124,8 +124,8 @@ class LocationsValidatorTest { fun `Connector validator`() { expectCatching { validConnector.validate() - validConnector.copy(max_voltage = 0).validate() - validConnector.copy(max_amperage = 0).validate() + validConnector.copy(maxVoltage = 0).validate() + validConnector.copy(maxAmperage = 0).validate() }.isSuccess() expectCatching { @@ -133,19 +133,19 @@ class LocationsValidatorTest { }.isFailure() expectCatching { - validConnector.copy(max_voltage = -1).validate() + validConnector.copy(maxVoltage = -1).validate() }.isFailure() expectCatching { - validConnector.copy(max_amperage = -1).validate() + validConnector.copy(maxAmperage = -1).validate() }.isFailure() expectCatching { - validConnector.copy(tariff_ids = listOf(generateRandomString(37))).validate() + validConnector.copy(tariffIds = listOf(generateRandomString(37))).validate() }.isFailure() expectCatching { - validConnector.copy(terms_and_conditions = "not an url").validate() + validConnector.copy(termsAndConditions = "not an url").validate() }.isFailure() } @@ -341,11 +341,11 @@ class LocationsValidatorTest { }.isSuccess() expectCatching { - validEnergyMix.copy(supplier_name = generateRandomString(65)).validate() + validEnergyMix.copy(supplierName = generateRandomString(65)).validate() }.isFailure() expectCatching { - validEnergyMix.copy(energy_product_name = generateRandomString(65)).validate() + validEnergyMix.copy(energyProductName = generateRandomString(65)).validate() }.isFailure() } @@ -355,15 +355,15 @@ class LocationsValidatorTest { validExceptionalPeriod.validate() validExceptionalPeriod.copy( - period_begin = validExceptionalPeriod.period_begin, - period_end = validExceptionalPeriod.period_begin + periodBegin = validExceptionalPeriod.periodBegin, + periodEnd = validExceptionalPeriod.periodBegin ).validate() }.isSuccess() expectCatching { validExceptionalPeriod.copy( - period_begin = validExceptionalPeriod.period_end, - period_end = validExceptionalPeriod.period_begin + periodBegin = validExceptionalPeriod.periodEnd, + periodEnd = validExceptionalPeriod.periodBegin ).validate() }.isFailure() } @@ -374,15 +374,15 @@ class LocationsValidatorTest { validRegularHours.validate() validRegularHours.copy( - period_begin = validRegularHours.period_begin, - period_end = validRegularHours.period_begin + periodBegin = validRegularHours.periodBegin, + periodEnd = validRegularHours.periodBegin ).validate() }.isSuccess() expectCatching { validRegularHours.copy( - period_begin = validRegularHours.period_end, - period_end = validRegularHours.period_begin + periodBegin = validRegularHours.periodEnd, + periodEnd = validRegularHours.periodBegin ).validate() }.isFailure() @@ -400,19 +400,19 @@ class LocationsValidatorTest { expectCatching { validRegularHours.copy( - period_begin = "1:00" + periodBegin = "1:00" ).validate() }.isFailure() expectCatching { validRegularHours.copy( - period_begin = "00:1" + periodBegin = "00:1" ).validate() }.isFailure() expectCatching { validRegularHours.copy( - period_begin = "0010" + periodBegin = "0010" ).validate() }.isFailure() } @@ -423,34 +423,34 @@ class LocationsValidatorTest { validHours.validate() validHours.copy( - regular_hours = null, - twenty_four_seven = true + regularHours = null, + twentyFourSeven = true ).validate() validHours.copy( - exceptional_openings = emptyList(), - exceptional_closings = emptyList() + exceptionalOpenings = emptyList(), + exceptionalClosings = emptyList() ).validate() }.isSuccess() expectCatching { validHours.copy( - regular_hours = listOf(validRegularHours), - twenty_four_seven = true + regularHours = listOf(validRegularHours), + twentyFourSeven = true ).toPartial().validate() }.isFailure() expectCatching { validHours.copy( - regular_hours = listOf(validRegularHours), - twenty_four_seven = true + regularHours = listOf(validRegularHours), + twentyFourSeven = true ).validate() }.isFailure() expectCatching { validHours.copy( - regular_hours = null, - twenty_four_seven = false + regularHours = null, + twentyFourSeven = false ).validate() }.isFailure() } @@ -550,16 +550,16 @@ class LocationsValidatorTest { expectCatching { validStatusSchedule.validate() validStatusSchedule.copy( - period_begin = validStatusSchedule.period_begin, - period_end = validStatusSchedule.period_begin, + periodBegin = validStatusSchedule.periodBegin, + periodEnd = validStatusSchedule.periodBegin ).validate() - validStatusSchedule.copy(period_end = null).validate() + validStatusSchedule.copy(periodEnd = null).validate() }.isSuccess() expectCatching { validStatusSchedule.copy( - period_begin = validStatusSchedule.period_end!!, - period_end = validStatusSchedule.period_begin, + periodBegin = validStatusSchedule.periodEnd!!, + periodEnd = validStatusSchedule.periodBegin ).validate() }.isFailure() } diff --git a/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/tokens/http/cpo/TokensCpoHttpGetTokenTest.kt b/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/tokens/http/cpo/TokensCpoHttpGetTokenTest.kt index f8313f57..97e392a2 100644 --- a/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/tokens/http/cpo/TokensCpoHttpGetTokenTest.kt +++ b/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/tokens/http/cpo/TokensCpoHttpGetTokenTest.kt @@ -16,7 +16,7 @@ import com.izivia.ocpi.toolkit.transport.TransportClient import com.izivia.ocpi.toolkit.transport.domain.HttpMethod import com.izivia.ocpi.toolkit.transport.domain.HttpResponse import com.izivia.ocpi.toolkit.transport.domain.HttpStatus -import io.mockk.every +import io.mockk.coEvery import io.mockk.mockk import io.mockk.slot import kotlinx.coroutines.runBlocking @@ -35,38 +35,38 @@ class TokensCpoHttpGetTokenTest { var type = slot() } val srv = mockk() { - every { + coEvery { getToken( capture(slots.countryCode), capture(slots.partyId), capture(slots.tokenUID), capture(slots.type) ) - } answers { + } coAnswers { Token( - country_code = "DE", - party_id = "TNM", + countryCode = "DE", + partyId = "TNM", uid = "12345678905880", type = TokenType.RFID, - contract_id = "DE8ACC12E46L89", - visual_number = "DF000-2001-8999-1", + contractId = "DE8ACC12E46L89", + visualNumber = "DF000-2001-8999-1", issuer = "TheNewMotion", - group_id = "DF000-2001-8999", + groupId = "DF000-2001-8999", valid = true, whitelist = WhitelistType.ALLOWED, language = "it", - default_profile_type = ProfileType.GREEN, - energy_contract = EnergyContract( - supplier_name = "Greenpeace Energy eG", - contract_id = "0123456789" + defaultProfileType = ProfileType.GREEN, + energyContract = EnergyContract( + supplierName = "Greenpeace Energy eG", + contractId = "0123456789" ), - last_updated = Instant.parse("2018-12-10T17:25:10Z") + lastUpdated = Instant.parse("2018-12-10T17:25:10Z") ) } }.buildServer() OcpiResponseBody.now = { Instant.parse("2015-06-30T21:59:59Z") } - //when + // when val resp: HttpResponse = srv.send( buildHttpRequest(HttpMethod.GET, "/tokens/DE/TNM/012345678/?type=RFID") ) diff --git a/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/tokens/http/cpo/TokensCpoHttpPatchTokenTest.kt b/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/tokens/http/cpo/TokensCpoHttpPatchTokenTest.kt index 6d649b18..ed744966 100644 --- a/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/tokens/http/cpo/TokensCpoHttpPatchTokenTest.kt +++ b/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/tokens/http/cpo/TokensCpoHttpPatchTokenTest.kt @@ -14,7 +14,7 @@ import com.izivia.ocpi.toolkit.transport.TransportClient import com.izivia.ocpi.toolkit.transport.domain.HttpMethod import com.izivia.ocpi.toolkit.transport.domain.HttpResponse import com.izivia.ocpi.toolkit.transport.domain.HttpStatus -import io.mockk.every +import io.mockk.coEvery import io.mockk.mockk import io.mockk.slot import kotlinx.coroutines.runBlocking @@ -27,23 +27,23 @@ class TokensCpoHttpPatchTokenTest { @Test fun `should patch token`() { val token = Token( - country_code = "DE", - party_id = "TNM", + countryCode = "DE", + partyId = "TNM", uid = "12345678905880", type = TokenType.RFID, - contract_id = "DE8ACC12E46L89", - visual_number = "DF000-2001-8999-1", + contractId = "DE8ACC12E46L89", + visualNumber = "DF000-2001-8999-1", issuer = "TheNewMotion", - group_id = "DF000-2001-8999", + groupId = "DF000-2001-8999", valid = true, whitelist = WhitelistType.ALLOWED, language = "it", - default_profile_type = ProfileType.GREEN, - energy_contract = EnergyContract( - supplier_name = "Greenpeace Energy eG", - contract_id = "0123456789" + defaultProfileType = ProfileType.GREEN, + energyContract = EnergyContract( + supplierName = "Greenpeace Energy eG", + contractId = "0123456789" ), - last_updated = Instant.parse("2018-12-10T17:25:10Z") + lastUpdated = Instant.parse("2018-12-10T17:25:10Z") ) val slots = object { var token = slot() @@ -53,7 +53,7 @@ class TokensCpoHttpPatchTokenTest { var type = slot() } val srv = mockk() { - every { + coEvery { patchToken( capture(slots.token), capture(slots.countryCode), @@ -61,13 +61,13 @@ class TokensCpoHttpPatchTokenTest { capture(slots.tokenUID), capture(slots.type) ) - } answers { token } + } coAnswers { token } }.buildServer() OcpiResponseBody.now = { Instant.parse("2015-06-30T21:59:59Z") } - //when + // when val resp: HttpResponse = srv.send( - buildHttpRequest(HttpMethod.PATCH, "/tokens/DE/TNM/012345678/?type=RFID", mapper.writeValueAsString(token)), + buildHttpRequest(HttpMethod.PATCH, "/tokens/DE/TNM/012345678/?type=RFID", mapper.writeValueAsString(token)) ) // then @@ -94,45 +94,45 @@ class TokensCpoHttpPatchTokenTest { @Test fun `should patch partial token`() { val token = Token( - country_code = "DE", - party_id = "TNM", + countryCode = "DE", + partyId = "TNM", uid = "12345678905880", type = TokenType.RFID, - contract_id = "DE8ACC12E46L89", - visual_number = "DF000-2001-8999-1", + contractId = "DE8ACC12E46L89", + visualNumber = "DF000-2001-8999-1", issuer = "TheNewMotion", - group_id = "DF000-2001-8999", + groupId = "DF000-2001-8999", valid = true, whitelist = WhitelistType.ALLOWED, language = "it", - default_profile_type = ProfileType.GREEN, - energy_contract = EnergyContract( - supplier_name = "Greenpeace Energy eG", - contract_id = "0123456789" + defaultProfileType = ProfileType.GREEN, + energyContract = EnergyContract( + supplierName = "Greenpeace Energy eG", + contractId = "0123456789" ), - last_updated = Instant.parse("2018-12-10T17:25:10Z") + lastUpdated = Instant.parse("2018-12-10T17:25:10Z") ) val partialToken = TokenPartial( - country_code = "DE", - party_id = "TNM", + countryCode = "DE", + partyId = "TNM", uid = "12345678905880", type = TokenType.RFID, - contract_id = "DE8ACC12E46L89", - visual_number = "DF000-2001-8999-1", - //issuer = "TheNewMotion", + contractId = "DE8ACC12E46L89", + visualNumber = "DF000-2001-8999-1", + // issuer = "TheNewMotion", issuer = null, - group_id = "DF000-2001-8999", + groupId = "DF000-2001-8999", valid = true, whitelist = WhitelistType.ALLOWED, - //language = "it", + // language = "it", language = null, - default_profile_type = ProfileType.GREEN, - energy_contract = EnergyContractPartial( - supplier_name = "Greenpeace Energy eG", - contract_id = "0123456789" + defaultProfileType = ProfileType.GREEN, + energyContract = EnergyContractPartial( + supplierName = "Greenpeace Energy eG", + contractId = "0123456789" ), - last_updated = Instant.parse("2018-12-10T17:25:10Z") + lastUpdated = Instant.parse("2018-12-10T17:25:10Z") ) val slots = object { @@ -143,7 +143,7 @@ class TokensCpoHttpPatchTokenTest { var type = slot() } val srv = mockk() { - every { + coEvery { patchToken( capture(slots.token), capture(slots.countryCode), @@ -151,13 +151,17 @@ class TokensCpoHttpPatchTokenTest { capture(slots.tokenUID), capture(slots.type) ) - } answers { token } + } coAnswers { token } }.buildServer() OcpiResponseBody.now = { Instant.parse("2015-06-30T21:59:59Z") } - //when + // when val resp: HttpResponse = srv.send( - buildHttpRequest(HttpMethod.PATCH, "/tokens/DE/TNM/012345678/?type=RFID", mapper.writeValueAsString(partialToken)), + buildHttpRequest( + HttpMethod.PATCH, + "/tokens/DE/TNM/012345678/?type=RFID", + mapper.writeValueAsString(partialToken) + ) ) // then diff --git a/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/tokens/http/cpo/TokensCpoHttpPutTokenTest.kt b/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/tokens/http/cpo/TokensCpoHttpPutTokenTest.kt index 4c4a2906..00f53a42 100644 --- a/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/tokens/http/cpo/TokensCpoHttpPutTokenTest.kt +++ b/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/tokens/http/cpo/TokensCpoHttpPutTokenTest.kt @@ -2,9 +2,9 @@ package com.izivia.ocpi.toolkit.modules.tokens.http.cpo import com.izivia.ocpi.toolkit.common.OcpiResponseBody import com.izivia.ocpi.toolkit.common.mapper +import com.izivia.ocpi.toolkit.modules.buildHttpRequest import com.izivia.ocpi.toolkit.modules.isJsonEqualTo import com.izivia.ocpi.toolkit.modules.sessions.domain.ProfileType -import com.izivia.ocpi.toolkit.modules.buildHttpRequest import com.izivia.ocpi.toolkit.modules.tokens.TokensCpoServer import com.izivia.ocpi.toolkit.modules.tokens.domain.EnergyContract import com.izivia.ocpi.toolkit.modules.tokens.domain.Token @@ -17,7 +17,7 @@ import com.izivia.ocpi.toolkit.transport.TransportClient import com.izivia.ocpi.toolkit.transport.domain.HttpMethod import com.izivia.ocpi.toolkit.transport.domain.HttpResponse import com.izivia.ocpi.toolkit.transport.domain.HttpStatus -import io.mockk.every +import io.mockk.coEvery import io.mockk.mockk import io.mockk.slot import kotlinx.coroutines.runBlocking @@ -30,23 +30,23 @@ class TokensCpoHttpPutTokenTest { @Test fun `should put token`() { val token = Token( - country_code = "DE", - party_id = "TNM", + countryCode = "DE", + partyId = "TNM", uid = "12345678905880", type = TokenType.RFID, - contract_id = "DE8ACC12E46L89", - visual_number = "DF000-2001-8999-1", + contractId = "DE8ACC12E46L89", + visualNumber = "DF000-2001-8999-1", issuer = "TheNewMotion", - group_id = "DF000-2001-8999", + groupId = "DF000-2001-8999", valid = true, whitelist = WhitelistType.ALLOWED, language = "it", - default_profile_type = ProfileType.GREEN, - energy_contract = EnergyContract( - supplier_name = "Greenpeace Energy eG", - contract_id = "0123456789" + defaultProfileType = ProfileType.GREEN, + energyContract = EnergyContract( + supplierName = "Greenpeace Energy eG", + contractId = "0123456789" ), - last_updated = Instant.parse("2018-12-10T17:25:10Z") + lastUpdated = Instant.parse("2018-12-10T17:25:10Z") ) val slots = object { var token = slot() @@ -56,7 +56,7 @@ class TokensCpoHttpPutTokenTest { var type = slot() } val srv = mockk() { - every { + coEvery { putToken( capture(slots.token), capture(slots.countryCode), @@ -64,13 +64,13 @@ class TokensCpoHttpPutTokenTest { capture(slots.tokenUID), capture(slots.type) ) - } answers { token } + } coAnswers { token } }.buildServer() OcpiResponseBody.now = { Instant.parse("2015-06-30T21:59:59Z") } - //when + // when val resp: HttpResponse = srv.send( - buildHttpRequest(HttpMethod.PUT, "/tokens/DE/TNM/012345678/?type=RFID", mapper.writeValueAsString(token)), + buildHttpRequest(HttpMethod.PUT, "/tokens/DE/TNM/012345678/?type=RFID", mapper.writeValueAsString(token)) ) // then diff --git a/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/tokens/http/emsp/TokensEmspHttpGetTokensTest.kt b/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/tokens/http/emsp/TokensEmspHttpGetTokensTest.kt index 4c692d0a..39cae148 100644 --- a/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/tokens/http/emsp/TokensEmspHttpGetTokensTest.kt +++ b/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/tokens/http/emsp/TokensEmspHttpGetTokensTest.kt @@ -17,7 +17,7 @@ import com.izivia.ocpi.toolkit.transport.TransportClient import com.izivia.ocpi.toolkit.transport.domain.HttpMethod import com.izivia.ocpi.toolkit.transport.domain.HttpResponse import com.izivia.ocpi.toolkit.transport.domain.HttpStatus -import io.mockk.every +import io.mockk.coEvery import io.mockk.mockk import io.mockk.slot import kotlinx.coroutines.runBlocking @@ -34,35 +34,35 @@ class TokensEmspHttpGetTokensTest { var dateTo = slot() } val srv = mockk() { - every { + coEvery { getTokens(capture(slots.dateFrom), capture(slots.dateTo), any(), any()) - } answers { + } coAnswers { listOf( Token( - country_code = "DE", - party_id = "TNM", + countryCode = "DE", + partyId = "TNM", uid = "12345678905880", type = TokenType.RFID, - contract_id = "DE8ACC12E46L89", - visual_number = "DF000-2001-8999-1", + contractId = "DE8ACC12E46L89", + visualNumber = "DF000-2001-8999-1", issuer = "TheNewMotion", - group_id = "DF000-2001-8999", + groupId = "DF000-2001-8999", valid = true, whitelist = WhitelistType.ALLOWED, language = "it", - default_profile_type = ProfileType.GREEN, - energy_contract = EnergyContract( - supplier_name = "Greenpeace Energy eG", - contract_id = "0123456789" + defaultProfileType = ProfileType.GREEN, + energyContract = EnergyContract( + supplierName = "Greenpeace Energy eG", + contractId = "0123456789" ), - last_updated = Instant.parse("2018-12-10T17:25:10Z") + lastUpdated = Instant.parse("2018-12-10T17:25:10Z") ) ).toSearchResult() } }.buildServer() OcpiResponseBody.now = { Instant.parse("2015-06-30T21:59:59Z") } - //when + // when val resp: HttpResponse = srv.send( buildHttpRequest(HttpMethod.GET, "/tokens/?date_from=2019-01-28T12:00:00Z&date_to=2019-01-29T12:00:00Z") ) diff --git a/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/tokens/http/emsp/TokensEmspHttpPostTokenTest.kt b/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/tokens/http/emsp/TokensEmspHttpPostTokenTest.kt index 2a00d4a0..e54f3d49 100644 --- a/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/tokens/http/emsp/TokensEmspHttpPostTokenTest.kt +++ b/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/tokens/http/emsp/TokensEmspHttpPostTokenTest.kt @@ -14,7 +14,7 @@ import com.izivia.ocpi.toolkit.transport.TransportClient import com.izivia.ocpi.toolkit.transport.domain.HttpMethod import com.izivia.ocpi.toolkit.transport.domain.HttpResponse import com.izivia.ocpi.toolkit.transport.domain.HttpStatus -import io.mockk.every +import io.mockk.coEvery import io.mockk.mockk import io.mockk.slot import kotlinx.coroutines.runBlocking @@ -31,39 +31,39 @@ class TokensEmspHttpPostTokenTest { var type = slot() } val srv = mockk() { - every { + coEvery { postToken(capture(slots.tokenUID), capture(slots.type), null) - } answers { + } coAnswers { AuthorizationInfo( allowed = AllowedType.ALLOWED, token = Token( - country_code = "DE", - party_id = "TNM", + countryCode = "DE", + partyId = "TNM", uid = "12345678905880", type = TokenType.RFID, - contract_id = "DE8ACC12E46L89", - visual_number = "DF000-2001-8999-1", + contractId = "DE8ACC12E46L89", + visualNumber = "DF000-2001-8999-1", issuer = "TheNewMotion", - group_id = "DF000-2001-8999", + groupId = "DF000-2001-8999", valid = true, whitelist = WhitelistType.ALLOWED, language = "it", - default_profile_type = ProfileType.GREEN, - energy_contract = EnergyContract( - supplier_name = "Greenpeace Energy eG", - contract_id = "0123456789" + defaultProfileType = ProfileType.GREEN, + energyContract = EnergyContract( + supplierName = "Greenpeace Energy eG", + contractId = "0123456789" ), - last_updated = Instant.parse("2018-12-10T17:25:10Z") + lastUpdated = Instant.parse("2018-12-10T17:25:10Z") ), location = null, - authorization_reference = null, + authorizationReference = null, info = null ) } }.buildServer() OcpiResponseBody.now = { Instant.parse("2015-06-30T21:59:59Z") } - //when + // when val resp: HttpResponse = srv.send( buildHttpRequest(HttpMethod.POST, "/tokens/012345678/authorize?type=RFID") ) @@ -117,42 +117,42 @@ class TokensEmspHttpPostTokenTest { var locationReferences = slot() } val srv = mockk() { - every { + coEvery { postToken(capture(slots.tokenUID), capture(slots.type), capture(slots.locationReferences)) - } answers { + } coAnswers { AuthorizationInfo( allowed = AllowedType.ALLOWED, token = Token( - country_code = "DE", - party_id = "TNM", + countryCode = "DE", + partyId = "TNM", uid = "12345678905880", type = TokenType.RFID, - contract_id = "DE8ACC12E46L89", - visual_number = "DF000-2001-8999-1", + contractId = "DE8ACC12E46L89", + visualNumber = "DF000-2001-8999-1", issuer = "TheNewMotion", - group_id = "DF000-2001-8999", + groupId = "DF000-2001-8999", valid = true, whitelist = WhitelistType.ALLOWED, language = "it", - default_profile_type = ProfileType.GREEN, - energy_contract = EnergyContract( - supplier_name = "Greenpeace Energy eG", - contract_id = "0123456789" + defaultProfileType = ProfileType.GREEN, + energyContract = EnergyContract( + supplierName = "Greenpeace Energy eG", + contractId = "0123456789" ), - last_updated = Instant.parse("2018-12-10T17:25:10Z") + lastUpdated = Instant.parse("2018-12-10T17:25:10Z") ), location = null, - authorization_reference = null, + authorizationReference = null, info = null ) } }.buildServer() OcpiResponseBody.now = { Instant.parse("2015-06-30T21:59:59Z") } - //when + // when val locationReferences = LocationReferences( - location_id = "LOC1", - evse_uids = listOf("BE*BEC*E041503001", "BE*BEC*E041503002") + locationId = "LOC1", + evseUids = listOf("BE*BEC*E041503001", "BE*BEC*E041503002") ) val resp: HttpResponse = srv.send( buildHttpRequest( @@ -202,7 +202,6 @@ class TokensEmspHttpPostTokenTest { ) } } - } private fun TokensEmspRepository.buildServer(): TransportClient { diff --git a/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/tokens/mock/TokensCpoRepositoryTest.kt b/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/tokens/mock/TokensCpoRepositoryTest.kt index 7fd33263..7d2e71e4 100644 --- a/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/tokens/mock/TokensCpoRepositoryTest.kt +++ b/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/tokens/mock/TokensCpoRepositoryTest.kt @@ -4,12 +4,11 @@ import com.izivia.ocpi.toolkit.modules.tokens.domain.Token import com.izivia.ocpi.toolkit.modules.tokens.domain.TokenPartial import com.izivia.ocpi.toolkit.modules.tokens.domain.TokenType import com.izivia.ocpi.toolkit.modules.tokens.repositories.TokensCpoRepository -import io.mockk.every +import io.mockk.coEvery import io.mockk.mockk import io.mockk.slot fun tokensCpoRepositoryTest(responseToken: Token): TokensCpoRepository = mockk { - val country_code = slot() val party_id = slot() val token_uid = slot() @@ -17,16 +16,16 @@ fun tokensCpoRepositoryTest(responseToken: Token): TokensCpoRepository = mockk { val requestToken = slot() val tokenPartial = slot() - every { + coEvery { getToken( capture(country_code), capture(party_id), capture(token_uid), captureNullable(type) ) - } answers { responseToken } + } coAnswers { responseToken } - every { + coEvery { putToken( token = capture(requestToken), countryCode = capture(country_code), @@ -34,9 +33,9 @@ fun tokensCpoRepositoryTest(responseToken: Token): TokensCpoRepository = mockk { tokenUid = capture(token_uid), type = captureNullable(type) ) - } answers { responseToken } + } coAnswers { responseToken } - every { + coEvery { patchToken( token = capture(tokenPartial), countryCode = capture(country_code), @@ -44,6 +43,5 @@ fun tokensCpoRepositoryTest(responseToken: Token): TokensCpoRepository = mockk { tokenUid = capture(token_uid), type = captureNullable(type) ) - } answers { responseToken } + } coAnswers { responseToken } } - diff --git a/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/tokens/mock/TokensEmspRepositoryTest.kt b/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/tokens/mock/TokensEmspRepositoryTest.kt index 1e49e97e..ccf610dd 100644 --- a/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/tokens/mock/TokensEmspRepositoryTest.kt +++ b/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/tokens/mock/TokensEmspRepositoryTest.kt @@ -6,33 +6,32 @@ import com.izivia.ocpi.toolkit.modules.tokens.domain.LocationReferences import com.izivia.ocpi.toolkit.modules.tokens.domain.Token import com.izivia.ocpi.toolkit.modules.tokens.domain.TokenType import com.izivia.ocpi.toolkit.modules.tokens.repositories.TokensEmspRepository -import io.mockk.every +import io.mockk.coEvery import io.mockk.mockk import io.mockk.slot import java.time.Instant fun getTokensEmspRepositoryTest(tokens: List): TokensEmspRepository = mockk { - val dateFrom = mutableListOf() val dateTo = mutableListOf() val offset = slot() val limit = mutableListOf() - every { + coEvery { getTokens( captureNullable(dateFrom), captureNullable(dateTo), capture(offset), captureNullable(limit) ) - } answers { + } coAnswers { val capturedOffset = offset.captured val capturedLimit = limit.captured() ?: 10 tokens .filter { token -> - val dateFromFilterOk = dateFrom.captured()?.let { token.last_updated.isAfter(it) } ?: true - val dateToFilterOk = dateTo.captured()?.let { token.last_updated.isBefore(it) } ?: true + val dateFromFilterOk = dateFrom.captured()?.let { token.lastUpdated.isAfter(it) } ?: true + val dateToFilterOk = dateTo.captured()?.let { token.lastUpdated.isBefore(it) } ?: true dateFromFilterOk && dateToFilterOk } @@ -45,12 +44,11 @@ fun getTokensEmspRepositoryTest(tokens: List): TokensEmspRepository = moc } fun postTokenEmspRepositoryTest(authorizationInfo: AuthorizationInfo): TokensEmspRepository = mockk { - val tokenUid = slot() val type = mutableListOf() val locationReferences = mutableListOf() - every { + coEvery { postToken(capture(tokenUid), captureNullable(type), captureNullable(locationReferences)) - } answers { authorizationInfo } + } coAnswers { authorizationInfo } } diff --git a/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/tokens/mock/ValidDomainObjects.kt b/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/tokens/mock/ValidDomainObjects.kt index d718a05e..f245a837 100644 --- a/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/tokens/mock/ValidDomainObjects.kt +++ b/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/tokens/mock/ValidDomainObjects.kt @@ -6,8 +6,8 @@ import com.izivia.ocpi.toolkit.modules.types.DisplayText import java.time.Instant val validEnergyContract = EnergyContract( - supplier_name = "Greenpeace Energy eG", - contract_id = "0123456789" + supplierName = "Greenpeace Energy eG", + contractId = "0123456789" ) val validDisplayText = DisplayText( @@ -16,43 +16,43 @@ val validDisplayText = DisplayText( ) val validLocationReference = LocationReferences( - location_id = "LOC1", - evse_uids = listOf("BE*BEC*E041503001", "BE*BEC*E041503002") + locationId = "LOC1", + evseUids = listOf("BE*BEC*E041503001", "BE*BEC*E041503002") ) val validTokenAppUser = Token( - country_code = "DE", - party_id = "TNM", + countryCode = "DE", + partyId = "TNM", uid = "bdf21bce-fc97-11e8-8eb2-f2801f1b9fd1", type = TokenType.APP_USER, - contract_id = "DE8ACC12E46L89", + contractId = "DE8ACC12E46L89", issuer = "TheNewMotion", valid = true, whitelist = WhitelistType.ALLOWED, - last_updated = Instant.parse("2018-12-10T17:16:15Z") + lastUpdated = Instant.parse("2018-12-10T17:16:15Z") ) val validTokenFullRfid = Token( - country_code = "DE", - party_id = "TNM", + countryCode = "DE", + partyId = "TNM", uid = "12345678905880", type = TokenType.RFID, - contract_id = "DE8ACC12E46L89", - visual_number = "DF000-2001-8999-1", + contractId = "DE8ACC12E46L89", + visualNumber = "DF000-2001-8999-1", issuer = "TheNewMotion", - group_id = "DF000-2001-8999", + groupId = "DF000-2001-8999", valid = true, whitelist = WhitelistType.ALLOWED, language = "it", - default_profile_type = ProfileType.GREEN, - energy_contract = validEnergyContract, - last_updated = Instant.now() + defaultProfileType = ProfileType.GREEN, + energyContract = validEnergyContract, + lastUpdated = Instant.now() ) val validAuthorizationInfo = AuthorizationInfo( allowed = AllowedType.ALLOWED, token = validTokenFullRfid, location = validLocationReference, - authorization_reference = "567890", + authorizationReference = "567890", info = validDisplayText ) diff --git a/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/tokens/services/TokensCpoServiceTest.kt b/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/tokens/services/TokensCpoServiceTest.kt index 95d69e48..e7dd6d1c 100644 --- a/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/tokens/services/TokensCpoServiceTest.kt +++ b/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/tokens/services/TokensCpoServiceTest.kt @@ -10,7 +10,6 @@ import org.junit.jupiter.api.Test import strikt.api.expectThat import strikt.assertions.isEqualTo - class TokensCpoServiceTest { private lateinit var service: TokensCpoService @@ -93,7 +92,7 @@ class TokensCpoServiceTest { token = validTokenFullRfid, countryCode = str2chars, partyId = str3chars, - tokenUid = str4chars, + tokenUid = str4chars ) } ) { @@ -167,7 +166,7 @@ class TokensCpoServiceTest { token = validTokenFullRfid.toPartial(), countryCode = str2chars, partyId = str3chars, - tokenUid = str4chars, + tokenUid = str4chars ) } ) { diff --git a/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/tokens/services/TokensEmspServiceTest.kt b/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/tokens/services/TokensEmspServiceTest.kt index 18c2541a..9a12d62e 100644 --- a/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/tokens/services/TokensEmspServiceTest.kt +++ b/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/tokens/services/TokensEmspServiceTest.kt @@ -16,7 +16,6 @@ import strikt.assertions.isNotNull import strikt.assertions.isNull import java.time.Instant - class TokensEmspServiceTest { private lateinit var service: TokensEmspService diff --git a/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/tokens/services/TokensValidatorTest.kt b/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/tokens/services/TokensValidatorTest.kt index 85fd3fdb..793332b5 100644 --- a/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/tokens/services/TokensValidatorTest.kt +++ b/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/modules/tokens/services/TokensValidatorTest.kt @@ -26,24 +26,23 @@ class TokensValidatorTest { }.isSuccess() expectCatching { - validTokenFullRfid.copy(country_code = "test").validate() + validTokenFullRfid.copy(countryCode = "test").validate() }.isFailure() expectCatching { - validTokenFullRfid.copy(party_id = generateRandomString(4)).validate() + validTokenFullRfid.copy(partyId = generateRandomString(4)).validate() }.isFailure() expectCatching { validTokenFullRfid.copy(uid = generateRandomString(37)).validate() }.isFailure() - expectCatching { - validTokenFullRfid.copy(contract_id = generateRandomString(37)).validate() + validTokenFullRfid.copy(contractId = generateRandomString(37)).validate() }.isFailure() expectCatching { - validTokenFullRfid.copy(visual_number = generateRandomString(66)).validate() + validTokenFullRfid.copy(visualNumber = generateRandomString(66)).validate() }.isFailure() expectCatching { @@ -51,7 +50,7 @@ class TokensValidatorTest { }.isFailure() expectCatching { - validTokenFullRfid.copy(group_id = generateRandomString(37)).validate() + validTokenFullRfid.copy(groupId = generateRandomString(37)).validate() }.isFailure() expectCatching { @@ -66,7 +65,7 @@ class TokensValidatorTest { }.isSuccess() expectCatching { - validAuthorizationInfo.copy(authorization_reference = generateRandomString(37)).validate() + validAuthorizationInfo.copy(authorizationReference = generateRandomString(37)).validate() }.isFailure() } @@ -77,11 +76,11 @@ class TokensValidatorTest { }.isSuccess() expectCatching { - validEnergyContract.copy(supplier_name = generateRandomString(65)).validate() + validEnergyContract.copy(supplierName = generateRandomString(65)).validate() }.isFailure() expectCatching { - validEnergyContract.copy(contract_id = generateRandomString(65)).validate() + validEnergyContract.copy(contractId = generateRandomString(65)).validate() }.isFailure() } @@ -92,11 +91,11 @@ class TokensValidatorTest { }.isSuccess() expectCatching { - validLocationReference.copy(location_id = generateRandomString(37)).validate() + validLocationReference.copy(locationId = generateRandomString(37)).validate() }.isFailure() expectCatching { - validLocationReference.copy(evse_uids = listOf(generateRandomString(37))).validate() + validLocationReference.copy(evseUids = listOf(generateRandomString(37))).validate() }.isFailure() } diff --git a/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/samples/common/DummyPlatformCacheRepository.kt b/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/samples/common/DummyPartnerCacheRepository.kt similarity index 54% rename from ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/samples/common/DummyPlatformCacheRepository.kt rename to ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/samples/common/DummyPartnerCacheRepository.kt index e77c8fac..6bfacd83 100644 --- a/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/samples/common/DummyPlatformCacheRepository.kt +++ b/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/samples/common/DummyPartnerCacheRepository.kt @@ -1,9 +1,9 @@ package com.izivia.ocpi.toolkit.samples.common -class DummyPlatformCacheRepository : PlatformCacheRepository() { +class DummyPartnerCacheRepository : PartnerCacheRepository() { override suspend fun isCredentialsServerTokenValid(credentialsServerToken: String): Boolean = true - override suspend fun getCredentialsClientToken(platformUrl: String): String = + override suspend fun getCredentialsClientToken(partnerUrl: String): String = "*" } diff --git a/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/samples/common/Http4kTransportServer.kt b/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/samples/common/Http4kTransportServer.kt index 7ac0a37f..f079431b 100644 --- a/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/samples/common/Http4kTransportServer.kt +++ b/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/samples/common/Http4kTransportServer.kt @@ -2,11 +2,9 @@ package com.izivia.ocpi.toolkit.samples.common import com.izivia.ocpi.toolkit.common.OcpiException import com.izivia.ocpi.toolkit.common.toHttpResponse -import com.izivia.ocpi.toolkit.transport.TransportClient import com.izivia.ocpi.toolkit.transport.TransportServer import com.izivia.ocpi.toolkit.transport.domain.* import kotlinx.coroutines.runBlocking -import kotlinx.coroutines.withContext import org.http4k.core.* import org.http4k.filter.DebuggingFilters import org.http4k.routing.RoutingHttpHandler diff --git a/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/samples/common/Platform.kt b/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/samples/common/Partner.kt similarity index 71% rename from ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/samples/common/Platform.kt rename to ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/samples/common/Partner.kt index 3b5ac490..4e6c30aa 100644 --- a/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/samples/common/Platform.kt +++ b/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/samples/common/Partner.kt @@ -1,10 +1,12 @@ package com.izivia.ocpi.toolkit.samples.common +import com.izivia.ocpi.toolkit.modules.credentials.domain.CredentialRole import com.izivia.ocpi.toolkit.modules.versions.domain.Endpoint import com.izivia.ocpi.toolkit.modules.versions.domain.Version -data class Platform( +data class Partner( val url: String? = null, + val credentialsRoles: List = emptyList(), val version: Version? = null, val endpoints: List? = null, val tokenA: String? = null, diff --git a/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/samples/common/PartnerCacheRepository.kt b/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/samples/common/PartnerCacheRepository.kt new file mode 100644 index 00000000..d8eca7e7 --- /dev/null +++ b/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/samples/common/PartnerCacheRepository.kt @@ -0,0 +1,103 @@ +package com.izivia.ocpi.toolkit.samples.common + +import com.izivia.ocpi.toolkit.modules.credentials.domain.CredentialRole +import com.izivia.ocpi.toolkit.modules.credentials.repositories.PartnerRepository +import com.izivia.ocpi.toolkit.modules.versions.domain.Endpoint +import com.izivia.ocpi.toolkit.modules.versions.domain.Version + +open class PartnerCacheRepository : PartnerRepository { + val partners = mutableListOf() + + private fun List.getOrDefault(url: String, partner: Partner): Partner = + partners[url] ?: partner + + private operator fun List.get(url: String): Partner? = + partners.firstOrNull { it.url == url } + + private operator fun List.set(url: String, partner: Partner) { + partners.removeAll { it.url == url } + partners.add(partner) + } + + override suspend fun savePartnerUrlForTokenA(tokenA: String, partnerUrl: String): String? = partners + .toList() + .firstOrNull { it.tokenA == tokenA } + ?.copy(url = partnerUrl) + ?.also { partners[it.url!!] = it } + ?.url + + override suspend fun saveCredentialsRoles( + partnerUrl: String, + credentialsRoles: List + ): List = partners + .getOrDefault(partnerUrl, Partner(partnerUrl)) + .copy(credentialsRoles = credentialsRoles) + .also { partners[it.url!!] = it } + .credentialsRoles + + override suspend fun saveVersion(partnerUrl: String, version: Version): Version = partners + .getOrDefault(partnerUrl, Partner(partnerUrl)) + .copy(version = version) + .also { partners[it.url!!] = it } + .let { it.version!! } + + override suspend fun saveEndpoints(partnerUrl: String, endpoints: List): List = partners + .getOrDefault(partnerUrl, Partner(partnerUrl)) + .copy(endpoints = endpoints) + .also { partners[it.url!!] = it } + .let { it.endpoints!! } + + override suspend fun saveCredentialsClientToken(partnerUrl: String, credentialsClientToken: String): String = + partners + .getOrDefault(partnerUrl, Partner(partnerUrl)) + .copy(clientToken = credentialsClientToken) + .also { partners[it.url!!] = it } + .let { it.clientToken!! } + + override suspend fun saveCredentialsServerToken(partnerUrl: String, credentialsServerToken: String): String = + partners + .getOrDefault(partnerUrl, Partner(partnerUrl)) + .copy(serverToken = credentialsServerToken) + .also { partners[it.url!!] = it } + .let { it.serverToken!! } + + override suspend fun getCredentialsClientToken(partnerUrl: String): String? = partners[partnerUrl]?.clientToken + + override suspend fun getCredentialsTokenA(partnerUrl: String): String? = partners[partnerUrl]?.tokenA + + override suspend fun isCredentialsTokenAValid(credentialsTokenA: String): Boolean = partners + .any { it.tokenA == credentialsTokenA } + + override suspend fun isCredentialsServerTokenValid(credentialsServerToken: String): Boolean = partners + .any { it.serverToken == credentialsServerToken } + + override suspend fun getPartnerUrlByCredentialsServerToken(credentialsServerToken: String): String? = partners + .firstOrNull { it.serverToken == credentialsServerToken }?.url + + override suspend fun getEndpoints(partnerUrl: String): List = partners + .firstOrNull { it.url == partnerUrl }?.endpoints ?: emptyList() + + override suspend fun getVersion(partnerUrl: String): Version? = partners + .firstOrNull { it.url == partnerUrl }?.version + + override suspend fun invalidateCredentialsTokenA(partnerUrl: String): Boolean = + partners + .getOrDefault(partnerUrl, Partner(partnerUrl)) + .copy(tokenA = null) + .also { partners[it.url!!] = it } + .let { true } + + override suspend fun invalidateCredentialsClientToken(partnerUrl: String): Boolean = + partners + .getOrDefault(partnerUrl, Partner(partnerUrl)) + .copy(clientToken = null) + .also { partners[it.url!!] = it } + .let { true } + + override suspend fun invalidateCredentialsServerToken(partnerUrl: String): Boolean = + partners + .getOrDefault(partnerUrl, Partner(partnerUrl)) + .copy(serverToken = null) + .also { partners[it.url!!] = it } + .let { true } +} diff --git a/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/samples/common/PlatformCacheRepository.kt b/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/samples/common/PlatformCacheRepository.kt deleted file mode 100644 index 434f7c23..00000000 --- a/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/samples/common/PlatformCacheRepository.kt +++ /dev/null @@ -1,84 +0,0 @@ -package com.izivia.ocpi.toolkit.samples.common - -import com.izivia.ocpi.toolkit.modules.credentials.repositories.PlatformRepository -import com.izivia.ocpi.toolkit.modules.versions.domain.Endpoint -import com.izivia.ocpi.toolkit.modules.versions.domain.Version - -open class PlatformCacheRepository : PlatformRepository { - val platforms = mutableListOf() - - private fun List.getOrDefault(url: String, platform: Platform): Platform = - platforms[url] ?: platform - - private operator fun List.get(url: String): Platform? = - platforms.firstOrNull { it.url == url } - - private operator fun List.set(url: String, platform: Platform) { - platforms.removeAll { it.url == url } - platforms.add(platform) - } - - override suspend fun savePlatformUrlForTokenA(tokenA: String, platformUrl: String): String? = platforms - .toList() - .firstOrNull { it.tokenA == tokenA } - ?.copy(url = platformUrl) - ?.also { platforms[it.url!!] = it } - ?.url - - override suspend fun saveVersion(platformUrl: String, version: Version): Version = platforms - .getOrDefault(platformUrl, Platform(platformUrl)) - .copy(version = version) - .also { platforms[it.url!!] = it } - .let { it.version!! } - - override suspend fun saveEndpoints(platformUrl: String, endpoints: List): List = platforms - .getOrDefault(platformUrl, Platform(platformUrl)) - .copy(endpoints = endpoints) - .also { platforms[it.url!!] = it } - .let { it.endpoints!! } - - override suspend fun saveCredentialsClientToken(platformUrl: String, credentialsClientToken: String): String = - platforms - .getOrDefault(platformUrl, Platform(platformUrl)) - .copy(clientToken = credentialsClientToken) - .also { platforms[it.url!!] = it } - .let { it.clientToken!! } - - override suspend fun saveCredentialsServerToken(platformUrl: String, credentialsServerToken: String): String = - platforms - .getOrDefault(platformUrl, Platform(platformUrl)) - .copy(serverToken = credentialsServerToken) - .also { platforms[it.url!!] = it } - .let { it.serverToken!! } - - override suspend fun getCredentialsClientToken(platformUrl: String): String? = platforms[platformUrl]?.clientToken - - override suspend fun getCredentialsTokenA(platformUrl: String): String? = platforms[platformUrl]?.tokenA - - override suspend fun isCredentialsTokenAValid(credentialsTokenA: String): Boolean = platforms - .any { it.tokenA == credentialsTokenA } - - override suspend fun isCredentialsServerTokenValid(credentialsServerToken: String): Boolean = platforms - .any { it.serverToken == credentialsServerToken } - - override suspend fun getPlatformUrlByCredentialsServerToken(credentialsServerToken: String): String? = platforms - .firstOrNull { it.serverToken == credentialsServerToken }?.url - - override suspend fun getEndpoints(platformUrl: String): List = platforms - .firstOrNull { it.url == platformUrl }?.endpoints ?: emptyList() - - override suspend fun getVersion(platformUrl: String): Version? = platforms - .firstOrNull { it.url == platformUrl }?.version - - override suspend fun invalidateCredentialsTokenA(platformUrl: String): Boolean = - platforms - .getOrDefault(platformUrl, Platform(platformUrl)) - .copy(tokenA = null) - .also { platforms[it.url!!] = it } - .let { true } - - override suspend fun unregisterPlatform(platformUrl: String): Boolean { - platforms[platformUrl] = Platform(platformUrl) - return true - } -} diff --git a/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/samples/common/ValidDomainObjets.kt b/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/samples/common/ValidDomainObjets.kt index 74d3edd9..eaf34368 100644 --- a/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/samples/common/ValidDomainObjets.kt +++ b/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/samples/common/ValidDomainObjets.kt @@ -11,8 +11,8 @@ val validLatitude = "-15.234567" val validLongitude = "23.234567" val validStatusSchedule = StatusSchedule( - period_begin = Instant.parse("2022-04-28T08:00:00.000Z"), - period_end = Instant.parse("2022-04-28T09:00:00.000Z"), + periodBegin = Instant.parse("2022-04-28T08:00:00.000Z"), + periodEnd = Instant.parse("2022-04-28T09:00:00.000Z"), status = Status.AVAILABLE ) @@ -49,20 +49,20 @@ val validBusinessDetails = BusinessDetails( val validRegularHours = RegularHours( weekday = 1, - period_begin = "00:00", - period_end = "23:59", + periodBegin = "00:00", + periodEnd = "23:59" ) val validExceptionalPeriod = ExceptionalPeriod( - period_begin = Instant.parse("2022-04-28T08:00:00.000Z"), - period_end = Instant.parse("2022-04-28T09:00:00.000Z") + periodBegin = Instant.parse("2022-04-28T08:00:00.000Z"), + periodEnd = Instant.parse("2022-04-28T09:00:00.000Z") ) val validHours = Hours( - regular_hours = listOf(validRegularHours), - twenty_four_seven = false, - exceptional_openings = listOf(validExceptionalPeriod), - exceptional_closings = emptyList() + regularHours = listOf(validRegularHours), + twentyFourSeven = false, + exceptionalOpenings = listOf(validExceptionalPeriod), + exceptionalClosings = emptyList() ) val validEnergySource = EnergySource( @@ -76,75 +76,75 @@ val validEnvironmentalImpact = EnvironmentalImpact( ) val validEnergyMix = EnergyMix( - is_green_energy = true, - energy_sources = listOf(validEnergySource), - environ_impact = listOf(validEnvironmentalImpact), - supplier_name = "supplier_name", - energy_product_name = "energy_product_name" + isGreenEnergy = true, + energySources = listOf(validEnergySource), + environImpact = listOf(validEnvironmentalImpact), + supplierName = "supplier_name", + energyProductName = "energy_product_name" ) val validPublishTokenType = PublishTokenType( uid = "uid", type = TokenType.AD_HOC_USER, - visual_number = "visual_number", + visualNumber = "visual_number", issuer = "issuer", - group_id = "group_id" + groupId = "group_id" ) val validLocation = Location( - country_code = "fr", - party_id = "abc", + countryCode = "fr", + partyId = "abc", id = "location1", publish = true, - publish_allowed_to = listOf(validPublishTokenType), + publishAllowedTo = listOf(validPublishTokenType), name = "name", address = "address", city = "city", - postal_code = "33520", + postalCode = "33520", state = null, country = "FRA", coordinates = validGeoLocation, - related_locations = listOf(validAdditionalGeoLocation), - parking_type = ParkingType.ON_STREET, + relatedLocations = listOf(validAdditionalGeoLocation), + parkingType = ParkingType.ON_STREET, evses = emptyList(), directions = listOf(validDisplayText), operator = validBusinessDetails, suboperator = null, owner = null, facilities = listOf(Facility.CARPOOL_PARKING), - time_zone = "Europe/Oslo", - opening_times = validHours, - charging_when_closed = false, + timeZone = "Europe/Oslo", + openingTimes = validHours, + chargingWhenClosed = false, images = listOf(validImage), - energy_mix = validEnergyMix, - last_updated = Instant.now() + energyMix = validEnergyMix, + lastUpdated = Instant.now() ) val validConnector = Connector( id = "id", standard = ConnectorType.DOMESTIC_A, format = ConnectorFormat.CABLE, - power_type = PowerType.AC_1_PHASE, - max_voltage = 12, - max_amperage = 8, - max_electric_power = null, - tariff_ids = listOf("tariff_id"), - terms_and_conditions = "https://myspecs.com/me", - last_updated = Instant.now() + powerType = PowerType.AC_1_PHASE, + maxVoltage = 12, + maxAmperage = 8, + maxElectricPower = null, + tariffIds = listOf("tariff_id"), + termsAndConditions = "https://myspecs.com/me", + lastUpdated = Instant.now() ) val validEvse = Evse( uid = "uid", - evse_id = "FR*A23*E45B*78C", + evseId = "FR*A23*E45B*78C", status = Status.AVAILABLE, - status_schedule = listOf(validStatusSchedule), + statusSchedule = listOf(validStatusSchedule), capabilities = listOf(Capability.CHARGING_PROFILE_CAPABLE), connectors = listOf(validConnector), - floor_level = "5", + floorLevel = "5", coordinates = validGeoLocation, - physical_reference = "visualid1", + physicalReference = "visualid1", directions = listOf(validDisplayText), - parking_restrictions = listOf(ParkingRestriction.CUSTOMERS), + parkingRestrictions = listOf(ParkingRestriction.CUSTOMERS), images = listOf(validImage), - last_updated = Instant.now() + lastUpdated = Instant.now() ) diff --git a/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/samples/common/VersionDetailsCacheRepository.kt b/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/samples/common/VersionDetailsCacheRepository.kt index 51ae8d00..086ea273 100644 --- a/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/samples/common/VersionDetailsCacheRepository.kt +++ b/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/samples/common/VersionDetailsCacheRepository.kt @@ -5,7 +5,7 @@ import com.izivia.ocpi.toolkit.modules.versions.repositories.VersionDetailsRepos class VersionDetailsCacheRepository( private val baseUrl: String -): VersionDetailsRepository { +) : VersionDetailsRepository { override suspend fun getVersionDetails(versionNumber: VersionNumber): VersionDetails? = VersionDetails( diff --git a/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/samples/common/VersionsCacheRepository.kt b/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/samples/common/VersionsCacheRepository.kt index 04c7d882..71c4f5ac 100644 --- a/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/samples/common/VersionsCacheRepository.kt +++ b/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/samples/common/VersionsCacheRepository.kt @@ -6,7 +6,7 @@ import com.izivia.ocpi.toolkit.modules.versions.repositories.VersionsRepository class VersionsCacheRepository( private val baseUrl: String -): VersionsRepository { +) : VersionsRepository { override suspend fun getVersions(): List = listOf( Version( diff --git a/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/samples/credentials/CredentialsReceiver.kt b/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/samples/credentials/CredentialsReceiver.kt index 9ca49e9d..055ed349 100644 --- a/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/samples/credentials/CredentialsReceiver.kt +++ b/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/samples/credentials/CredentialsReceiver.kt @@ -21,8 +21,8 @@ const val tokenA = "06f7967e-65c3-4def-a966-701ffb362b3c" fun main() { // Add token A associated with the sender - val receiverPlatformRepository = PlatformCacheRepository() - receiverPlatformRepository.platforms.add(Platform(tokenA = tokenA)) + val receiverPlatformRepository = PartnerCacheRepository() + receiverPlatformRepository.partners.add(Partner(tokenA = tokenA)) val receiverServer = Http4kTransportServer( baseUrl = receiverUrl, @@ -33,14 +33,14 @@ fun main() { runBlocking { CredentialsServer( service = CredentialsServerService( - platformRepository = receiverPlatformRepository, + partnerRepository = receiverPlatformRepository, credentialsRoleRepository = object : CredentialsRoleRepository { override suspend fun getCredentialsRoles(): List = listOf( CredentialRole( role = Role.EMSP, - business_details = BusinessDetails(name = "Receiver", website = null, logo = null), - party_id = "DEF", - country_code = "FR" + businessDetails = BusinessDetails(name = "Receiver", website = null, logo = null), + partyId = "DEF", + countryCode = "FR" ) ) }, diff --git a/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/samples/credentials/CredentialsSender.kt b/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/samples/credentials/CredentialsSender.kt index 92dcf84b..6cb01f46 100644 --- a/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/samples/credentials/CredentialsSender.kt +++ b/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/samples/credentials/CredentialsSender.kt @@ -21,8 +21,8 @@ fun main() { // Add token A associated with the sender val senderVersionsRepository = VersionsCacheRepository(baseUrl = senderUrl) val senderVersionDetailsRepository = VersionDetailsCacheRepository(baseUrl = senderUrl) - val senderPlatformRepository = PlatformCacheRepository() - senderPlatformRepository.platforms.add(Platform(url = receiverVersionsUrl, tokenA = tokenA)) + val senderPlatformRepository = PartnerCacheRepository() + senderPlatformRepository.partners.add(Partner(url = receiverVersionsUrl, tokenA = tokenA)) // Server val senderServer = Http4kTransportServer( @@ -48,15 +48,15 @@ fun main() { // Client val credentialsClientService = CredentialsClientService( clientVersionsEndpointUrl = senderVersionsUrl, - clientPlatformRepository = senderPlatformRepository, + clientPartnerRepository = senderPlatformRepository, clientVersionsRepository = senderVersionsRepository, clientCredentialsRoleRepository = object : CredentialsRoleRepository { override suspend fun getCredentialsRoles(): List = listOf( CredentialRole( role = Role.CPO, - business_details = BusinessDetails(name = "Sender", website = null, logo = null), - party_id = "ABC", - country_code = "FR" + businessDetails = BusinessDetails(name = "Sender", website = null, logo = null), + partyId = "ABC", + countryCode = "FR" ) ) }, diff --git a/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/samples/locations/LocationsCommon.kt b/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/samples/locations/LocationsCommon.kt index ebefcc78..48cf6c88 100644 --- a/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/samples/locations/LocationsCommon.kt +++ b/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/samples/locations/LocationsCommon.kt @@ -1,12 +1,12 @@ package com.izivia.ocpi.toolkit.samples.locations import com.izivia.ocpi.toolkit.modules.versions.domain.VersionNumber -import com.izivia.ocpi.toolkit.samples.common.DummyPlatformCacheRepository +import com.izivia.ocpi.toolkit.samples.common.DummyPartnerCacheRepository import com.izivia.ocpi.toolkit.samples.common.VersionDetailsCacheRepository import kotlinx.coroutines.runBlocking const val CREDENTIALS_TOKEN_C = "e0748bbe-d535-4a6b-8f80-94f2457d5b9d" -val DUMMY_PLATFORM_REPOSITORY = DummyPlatformCacheRepository().also { +val DUMMY_PLATFORM_REPOSITORY = DummyPartnerCacheRepository().also { val versionDetailsEmsp = VersionDetailsCacheRepository(baseUrl = emspServerUrl) val versionDetailsCpo = VersionDetailsCacheRepository(baseUrl = cpoServerUrl) diff --git a/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/samples/locations/LocationsCpoClient.kt b/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/samples/locations/LocationsCpoClient.kt index b87fafdf..917f076d 100644 --- a/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/samples/locations/LocationsCpoClient.kt +++ b/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/samples/locations/LocationsCpoClient.kt @@ -12,7 +12,7 @@ fun main() { val locationsCpoClient = LocationsCpoClient( transportClientBuilder = Http4kTransportClientBuilder(), serverVersionsEndpointUrl = emspServerVersionsUrl, - platformRepository = DUMMY_PLATFORM_REPOSITORY + partnerRepository = DUMMY_PLATFORM_REPOSITORY ) // We can use it diff --git a/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/samples/locations/LocationsCpoServer.kt b/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/samples/locations/LocationsCpoServer.kt index 43d76b50..cf63a0cc 100644 --- a/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/samples/locations/LocationsCpoServer.kt +++ b/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/samples/locations/LocationsCpoServer.kt @@ -42,19 +42,24 @@ fun main() { } class CacheLocationsCpoRepository : LocationsCpoRepository { - override fun getLocations(dateFrom: Instant?, dateTo: Instant?, offset: Int, limit: Int?): SearchResult { + override suspend fun getLocations( + dateFrom: Instant?, + dateTo: Instant?, + offset: Int, + limit: Int? + ): SearchResult { TODO("Not yet implemented") } - override fun getLocation(locationId: String): Location? { + override suspend fun getLocation(locationId: String): Location? { TODO("Not yet implemented") } - override fun getEvse(locationId: String, evseUid: String): Evse? { + override suspend fun getEvse(locationId: String, evseUid: String): Evse? { TODO("Not yet implemented") } - override fun getConnector(locationId: String, evseUid: String, connectorId: String): Connector? { + override suspend fun getConnector(locationId: String, evseUid: String, connectorId: String): Connector? { TODO("Not yet implemented") } } diff --git a/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/samples/locations/LocationsEmspClient.kt b/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/samples/locations/LocationsEmspClient.kt index 423c86e1..52a018c6 100644 --- a/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/samples/locations/LocationsEmspClient.kt +++ b/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/samples/locations/LocationsEmspClient.kt @@ -12,7 +12,7 @@ fun main() { val locationsEmspClient = LocationsEmspClient( transportClientBuilder = Http4kTransportClientBuilder(), serverVersionsEndpointUrl = cpoServerVersionsUrl, - platformRepository = DUMMY_PLATFORM_REPOSITORY + partnerRepository = DUMMY_PLATFORM_REPOSITORY ) // We can use it diff --git a/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/samples/locations/LocationsEmspServer.kt b/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/samples/locations/LocationsEmspServer.kt index 5f9b8323..39ac0326 100644 --- a/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/samples/locations/LocationsEmspServer.kt +++ b/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/samples/locations/LocationsEmspServer.kt @@ -39,15 +39,15 @@ fun main() { } class CacheLocationsEmspRepository : LocationsEmspRepository { - override fun getLocation(countryCode: String, partyId: String, locationId: String): Location? { + override suspend fun getLocation(countryCode: String, partyId: String, locationId: String): Location? { return validLocation } - override fun getEvse(countryCode: String, partyId: String, locationId: String, evseUid: String): Evse? { + override suspend fun getEvse(countryCode: String, partyId: String, locationId: String, evseUid: String): Evse? { TODO("Not yet implemented") } - override fun getConnector( + override suspend fun getConnector( countryCode: String, partyId: String, locationId: String, @@ -57,15 +57,26 @@ class CacheLocationsEmspRepository : LocationsEmspRepository { TODO("Not yet implemented") } - override fun putLocation(countryCode: String, partyId: String, locationId: String, location: Location): Location { + override suspend fun putLocation( + countryCode: String, + partyId: String, + locationId: String, + location: Location + ): Location { TODO("Not yet implemented") } - override fun putEvse(countryCode: String, partyId: String, locationId: String, evseUid: String, evse: Evse): Evse { + override suspend fun putEvse( + countryCode: String, + partyId: String, + locationId: String, + evseUid: String, + evse: Evse + ): Evse { TODO("Not yet implemented") } - override fun putConnector( + override suspend fun putConnector( countryCode: String, partyId: String, locationId: String, @@ -76,7 +87,7 @@ class CacheLocationsEmspRepository : LocationsEmspRepository { TODO("Not yet implemented") } - override fun patchLocation( + override suspend fun patchLocation( countryCode: String, partyId: String, locationId: String, @@ -85,7 +96,7 @@ class CacheLocationsEmspRepository : LocationsEmspRepository { TODO("Not yet implemented") } - override fun patchEvse( + override suspend fun patchEvse( countryCode: String, partyId: String, locationId: String, @@ -95,7 +106,7 @@ class CacheLocationsEmspRepository : LocationsEmspRepository { TODO("Not yet implemented") } - override fun patchConnector( + override suspend fun patchConnector( countryCode: String, partyId: String, locationId: String, diff --git a/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/tests/integration/CredentialsIntegrationTests.kt b/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/tests/integration/CredentialsIntegrationTests.kt index df669aad..bbd840eb 100644 --- a/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/tests/integration/CredentialsIntegrationTests.kt +++ b/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/tests/integration/CredentialsIntegrationTests.kt @@ -15,7 +15,7 @@ import com.izivia.ocpi.toolkit.modules.versions.services.VersionDetailsService import com.izivia.ocpi.toolkit.modules.versions.services.VersionsService import com.izivia.ocpi.toolkit.samples.common.* import com.izivia.ocpi.toolkit.tests.integration.common.BaseServerIntegrationTest -import com.izivia.ocpi.toolkit.tests.integration.mock.PlatformMongoRepository +import com.izivia.ocpi.toolkit.tests.integration.mock.PartnerMongoRepository import com.izivia.ocpi.toolkit.transport.domain.HttpMethod import com.izivia.ocpi.toolkit.transport.domain.HttpStatus import com.mongodb.client.MongoCollection @@ -34,7 +34,7 @@ class CredentialsIntegrationTests : BaseServerIntegrationTest() { data class ServerSetupResult( val transport: Http4kTransportServer, - val platformCollection: MongoCollection, + val partnerCollection: MongoCollection, val versionsEndpoint: String ) @@ -42,15 +42,15 @@ class CredentialsIntegrationTests : BaseServerIntegrationTest() { private fun setupReceiver(): ServerSetupResult { if (database == null) database = buildDBClient().getDatabase("ocpi-2-2-1-tests") - val receiverPlatformCollection = database!! - .getCollection("receiver-server-${UUID.randomUUID()}") + val receiverPartnerCollection = database!! + .getCollection("receiver-server-${UUID.randomUUID()}") // Reset spy variables requestCounter = 1 correlationCounter = 1 // Setup receiver (only server) - val receiverPlatformRepo = PlatformMongoRepository(collection = receiverPlatformCollection) + val receiverPlatformRepo = PartnerMongoRepository(collection = receiverPartnerCollection) val receiverServer = buildTransportServer(receiverPlatformRepo) val receiverServerVersionsUrl = "${receiverServer.baseUrl}/versions" val receiverVersionsCacheRepository = VersionsCacheRepository(baseUrl = receiverServer.baseUrl) @@ -58,14 +58,14 @@ class CredentialsIntegrationTests : BaseServerIntegrationTest() { runBlocking { CredentialsServer( service = CredentialsServerService( - platformRepository = receiverPlatformRepo, + partnerRepository = receiverPlatformRepo, credentialsRoleRepository = object : CredentialsRoleRepository { override suspend fun getCredentialsRoles(): List = listOf( CredentialRole( role = Role.EMSP, - business_details = BusinessDetails(name = "Receiver", website = null, logo = null), - party_id = "DEF", - country_code = "FR" + businessDetails = BusinessDetails(name = "Receiver", website = null, logo = null), + partyId = "DEF", + countryCode = "FR" ) ) }, @@ -87,22 +87,22 @@ class CredentialsIntegrationTests : BaseServerIntegrationTest() { return ServerSetupResult( transport = receiverServer, - platformCollection = receiverPlatformCollection, + partnerCollection = receiverPartnerCollection, versionsEndpoint = receiverServerVersionsUrl ) } private fun setupSender(): ServerSetupResult { if (database == null) database = buildDBClient().getDatabase("ocpi-2-2-1-tests") - val senderPlatformCollection = database!! - .getCollection("sender-server-${UUID.randomUUID()}") + val senderPartnerCollection = database!! + .getCollection("sender-server-${UUID.randomUUID()}") // Reset spy variables requestCounter = 1 correlationCounter = 1 // Setup sender (server) - val senderServer = buildTransportServer(PlatformMongoRepository(collection = senderPlatformCollection)) + val senderServer = buildTransportServer(PartnerMongoRepository(collection = senderPartnerCollection)) val senderServerVersionsUrl = "${senderServer.baseUrl}/versions" runBlocking { @@ -120,7 +120,7 @@ class CredentialsIntegrationTests : BaseServerIntegrationTest() { return ServerSetupResult( transport = senderServer, - platformCollection = senderPlatformCollection, + partnerCollection = senderPartnerCollection, versionsEndpoint = senderServerVersionsUrl ) } @@ -132,15 +132,15 @@ class CredentialsIntegrationTests : BaseServerIntegrationTest() { // Setup sender (client) return CredentialsClientService( clientVersionsEndpointUrl = senderServerSetupResult.versionsEndpoint, - clientPlatformRepository = PlatformMongoRepository(collection = senderServerSetupResult.platformCollection), + clientPartnerRepository = PartnerMongoRepository(collection = senderServerSetupResult.partnerCollection), clientVersionsRepository = VersionsCacheRepository(baseUrl = senderServerSetupResult.transport.baseUrl), clientCredentialsRoleRepository = object : CredentialsRoleRepository { override suspend fun getCredentialsRoles(): List = listOf( CredentialRole( role = Role.CPO, - business_details = BusinessDetails(name = "Sender", website = null, logo = null), - party_id = "ABC", - country_code = "FR" + businessDetails = BusinessDetails(name = "Sender", website = null, logo = null), + partyId = "ABC", + countryCode = "FR" ) ) }, @@ -160,7 +160,7 @@ class CredentialsIntegrationTests : BaseServerIntegrationTest() { ) val tokenA = UUID.randomUUID().toString() - receiverServer.platformCollection.insertOne(Platform(url = senderServer.versionsEndpoint, tokenA = tokenA)) + receiverServer.partnerCollection.insertOne(Partner(url = senderServer.versionsEndpoint, tokenA = tokenA)) // Start the servers receiverServer.transport.start() @@ -171,8 +171,8 @@ class CredentialsIntegrationTests : BaseServerIntegrationTest() { credentialsClientService.register() }.isFailure().isA() - receiverServer.platformCollection.deleteOne(Platform::url eq senderServer.versionsEndpoint) - senderServer.platformCollection.insertOne(Platform(url = receiverServer.versionsEndpoint, tokenA = tokenA)) + receiverServer.partnerCollection.deleteOne(Partner::url eq senderServer.versionsEndpoint) + senderServer.partnerCollection.insertOne(Partner(url = receiverServer.versionsEndpoint, tokenA = tokenA)) // Fails because the receiver does not know the TOKEN_A used by the sender expectCatching { @@ -183,9 +183,9 @@ class CredentialsIntegrationTests : BaseServerIntegrationTest() { .get { statusCode } .isEqualTo(OcpiStatus.CLIENT_INVALID_PARAMETERS.code) - receiverServer.platformCollection.deleteOne(Platform::url eq senderServer.versionsEndpoint) - receiverServer.platformCollection.insertOne( - Platform( + receiverServer.partnerCollection.deleteOne(Partner::url eq senderServer.versionsEndpoint) + receiverServer.partnerCollection.insertOne( + Partner( url = receiverServer.versionsEndpoint, tokenA = "!$tokenA" ) @@ -207,8 +207,8 @@ class CredentialsIntegrationTests : BaseServerIntegrationTest() { val senderServer = setupSender() val tokenA = UUID.randomUUID().toString() - receiverServer.platformCollection.insertOne(Platform(url = senderServer.versionsEndpoint, tokenA = tokenA)) - senderServer.platformCollection.insertOne(Platform(url = receiverServer.versionsEndpoint, tokenA = tokenA)) + receiverServer.partnerCollection.insertOne(Partner(url = senderServer.versionsEndpoint, tokenA = tokenA)) + senderServer.partnerCollection.insertOne(Partner(url = receiverServer.versionsEndpoint, tokenA = tokenA)) receiverServer.transport.start() senderServer.transport.start() @@ -218,7 +218,7 @@ class CredentialsIntegrationTests : BaseServerIntegrationTest() { val versionsClient = VersionsClient( transportClientBuilder = Http4kTransportClientBuilder(), serverVersionsEndpointUrl = receiverServer.versionsEndpoint, - platformRepository = PlatformMongoRepository(collection = senderServer.platformCollection) + partnerRepository = PartnerMongoRepository(collection = senderServer.partnerCollection) ) expectThat( @@ -255,8 +255,8 @@ class CredentialsIntegrationTests : BaseServerIntegrationTest() { // Store token A on the receiver side, that will be used by the sender to begin registration and store it as // well in the client so that it knows what token to send val tokenA = UUID.randomUUID().toString() - receiverServer.platformCollection.insertOne(Platform(url = senderServer.versionsEndpoint, tokenA = tokenA)) - senderServer.platformCollection.insertOne(Platform(url = receiverServer.versionsEndpoint, tokenA = tokenA)) + receiverServer.partnerCollection.insertOne(Partner(url = senderServer.versionsEndpoint, tokenA = tokenA)) + senderServer.partnerCollection.insertOne(Partner(url = receiverServer.versionsEndpoint, tokenA = tokenA)) // Start the servers receiverServer.transport.start() @@ -390,8 +390,8 @@ class CredentialsIntegrationTests : BaseServerIntegrationTest() { // Store token A on the receiver side, that will be used by the sender to begin registration and store it as // well in the client so that it knows what token to send val tokenA = UUID.randomUUID().toString() - receiverServer.platformCollection.insertOne(Platform(url = senderServer.versionsEndpoint, tokenA = tokenA)) - senderServer.platformCollection.insertOne(Platform(url = receiverServer.versionsEndpoint, tokenA = tokenA)) + receiverServer.partnerCollection.insertOne(Partner(url = senderServer.versionsEndpoint, tokenA = tokenA)) + senderServer.partnerCollection.insertOne(Partner(url = receiverServer.versionsEndpoint, tokenA = tokenA)) // Start the servers receiverServer.transport.start() @@ -403,7 +403,7 @@ class CredentialsIntegrationTests : BaseServerIntegrationTest() { val versionsClient = VersionsClient( transportClientBuilder = Http4kTransportClientBuilder(), serverVersionsEndpointUrl = receiverServer.versionsEndpoint, - platformRepository = PlatformMongoRepository(collection = senderServer.platformCollection) + partnerRepository = PartnerMongoRepository(collection = senderServer.partnerCollection) ) expectThat( @@ -425,11 +425,11 @@ class CredentialsIntegrationTests : BaseServerIntegrationTest() { } @Test - fun `should properly run registration process then delete credentials properly`() { + fun `should properly run registration process then delete credentials properly then re-register`() { val receiverServer = setupReceiver() val senderServer = setupSender() - val credentialsClientService = setupCredentialsSenderClient( + val senderCredentialsClientService = setupCredentialsSenderClient( senderServerSetupResult = senderServer, receiverServerSetupResult = receiverServer ) @@ -437,26 +437,31 @@ class CredentialsIntegrationTests : BaseServerIntegrationTest() { // Store token A on the receiver side, that will be used by the sender to begin registration and store it as // well in the client so that it knows what token to send val tokenA = UUID.randomUUID().toString() - receiverServer.platformCollection.insertOne(Platform(url = senderServer.versionsEndpoint, tokenA = tokenA)) - senderServer.platformCollection.insertOne(Platform(url = receiverServer.versionsEndpoint, tokenA = tokenA)) + receiverServer.partnerCollection.insertOne(Partner(url = senderServer.versionsEndpoint, tokenA = tokenA)) + senderServer.partnerCollection.insertOne(Partner(url = receiverServer.versionsEndpoint, tokenA = tokenA)) // Start the servers receiverServer.transport.start() senderServer.transport.start() runBlocking { - credentialsClientService.register() + senderCredentialsClientService.register() } - val versionsClient = VersionsClient( + val senderVersionsClient = VersionsClient( transportClientBuilder = Http4kTransportClientBuilder(), serverVersionsEndpointUrl = receiverServer.versionsEndpoint, - platformRepository = PlatformMongoRepository(collection = senderServer.platformCollection) + partnerRepository = PartnerMongoRepository(collection = senderServer.partnerCollection) + ) + val receiverVersionsClient = VersionsClient( + transportClientBuilder = Http4kTransportClientBuilder(), + serverVersionsEndpointUrl = senderServer.versionsEndpoint, + partnerRepository = PartnerMongoRepository(collection = receiverServer.partnerCollection) ) expectThat( runBlocking { - versionsClient.getVersions() + senderVersionsClient.getVersions() } ) { get { data } @@ -473,13 +478,63 @@ class CredentialsIntegrationTests : BaseServerIntegrationTest() { .isEqualTo(OcpiStatus.SUCCESS.code) } + // Sender unregisters, so ... runBlocking { - credentialsClientService.delete() + senderCredentialsClientService.delete() } - expectCatching { - versionsClient.getVersions() - }.isFailure() + // ... receiver should not be able to call sender ... + expectThrows { + // no token to use, so we should have an OCPI client error + runBlocking { + receiverVersionsClient.getVersions() + } + } + + // ... and sender should still be able to call receiver, and even register! + runBlocking { + senderCredentialsClientService.register() + } + + // ... and then, the receiver can send new requests ... + expectThat( + runBlocking { + receiverVersionsClient.getVersions() + } + ) { + get { data } + .isNotNull() + .isNotEmpty() + .isEqualTo( + runBlocking { + VersionsCacheRepository(baseUrl = senderServer.transport.baseUrl) + .getVersions() + } + ) + + get { status_code } + .isEqualTo(OcpiStatus.SUCCESS.code) + } + + // ... and sender can obviously still send requests + expectThat( + runBlocking { + senderVersionsClient.getVersions() + } + ) { + get { data } + .isNotNull() + .isNotEmpty() + .isEqualTo( + runBlocking { + VersionsCacheRepository(baseUrl = receiverServer.transport.baseUrl) + .getVersions() + } + ) + + get { status_code } + .isEqualTo(OcpiStatus.SUCCESS.code) + } } @Test @@ -487,7 +542,7 @@ class CredentialsIntegrationTests : BaseServerIntegrationTest() { val receiverServer = setupReceiver() val senderServer = setupSender() - val credentialsClientService = setupCredentialsSenderClient( + val senderCredentialsClientService = setupCredentialsSenderClient( senderServerSetupResult = senderServer, receiverServerSetupResult = receiverServer ) @@ -495,24 +550,29 @@ class CredentialsIntegrationTests : BaseServerIntegrationTest() { // Store token A on the receiver side, that will be used by the sender to begin registration and store it as // well in the client so that it knows what token to send val tokenA = UUID.randomUUID().toString() - receiverServer.platformCollection.insertOne(Platform(url = senderServer.versionsEndpoint, tokenA = tokenA)) - senderServer.platformCollection.insertOne(Platform(url = receiverServer.versionsEndpoint, tokenA = tokenA)) + receiverServer.partnerCollection.insertOne(Partner(url = senderServer.versionsEndpoint, tokenA = tokenA)) + senderServer.partnerCollection.insertOne(Partner(url = receiverServer.versionsEndpoint, tokenA = tokenA)) // Start the servers receiverServer.transport.start() senderServer.transport.start() - val credentialsAfterRegistration = runBlocking { credentialsClientService.register() } + val credentialsAfterRegistration = runBlocking { senderCredentialsClientService.register() } - val versionsClient = VersionsClient( + val senderVersionsClient = VersionsClient( transportClientBuilder = Http4kTransportClientBuilder(), serverVersionsEndpointUrl = receiverServer.versionsEndpoint, - platformRepository = PlatformMongoRepository(collection = senderServer.platformCollection) + partnerRepository = PartnerMongoRepository(collection = senderServer.partnerCollection) + ) + val receiverVersionsClient = VersionsClient( + transportClientBuilder = Http4kTransportClientBuilder(), + serverVersionsEndpointUrl = senderServer.versionsEndpoint, + partnerRepository = PartnerMongoRepository(collection = receiverServer.partnerCollection) ) expectThat( runBlocking { - versionsClient.getVersions() + senderVersionsClient.getVersions() } ) { get { data } @@ -531,17 +591,17 @@ class CredentialsIntegrationTests : BaseServerIntegrationTest() { expectThat( runBlocking { - credentialsClientService.get() + senderCredentialsClientService.get() } ).isEqualTo(credentialsAfterRegistration) runBlocking { - credentialsClientService.update() + senderCredentialsClientService.update() } expectThat( runBlocking { - versionsClient.getVersions() + senderVersionsClient.getVersions() } ) { get { data } @@ -558,15 +618,27 @@ class CredentialsIntegrationTests : BaseServerIntegrationTest() { .isEqualTo(OcpiStatus.SUCCESS.code) } + // Sender unregisters, so ... runBlocking { - credentialsClientService.delete() + senderCredentialsClientService.delete() } + // ... receiver should not be able to call sender ... expectThrows { // no token to use, so we should have an OCPI client error runBlocking { - versionsClient.getVersions() + receiverVersionsClient.getVersions() } } + + // ... and sender should still be able to call receiver + expectThat( + runBlocking { + senderVersionsClient.getVersions() + } + ) { + get { status_code } + .isEqualTo(OcpiStatus.SUCCESS.code) + } } } diff --git a/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/tests/integration/LocationsIntegrationTest.kt b/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/tests/integration/LocationsIntegrationTest.kt index 5b374db3..9608656d 100644 --- a/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/tests/integration/LocationsIntegrationTest.kt +++ b/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/tests/integration/LocationsIntegrationTest.kt @@ -28,11 +28,11 @@ class LocationsIntegrationTest : BaseServerIntegrationTest() { if (database == null) database = buildDBClient().getDatabase("ocpi-2-1-1-tests") val collection = database!!.getCollection("cpo-server-locations-${UUID.randomUUID()}") collection.insertMany(locations) - val server = buildTransportServer(DummyPlatformCacheRepository()) + val server = buildTransportServer(DummyPartnerCacheRepository()) runBlocking { LocationsCpoServer( LocationsCpoService( - service = LocationsCpoMongoRepository(collection), + service = LocationsCpoMongoRepository(collection) ) ).registerOn(server) } @@ -41,7 +41,6 @@ class LocationsIntegrationTest : BaseServerIntegrationTest() { @Test fun `getLocations test (paginated)`() { - // Start CPO server with dummy data val numberOfLocations = 500 val referenceDate = Instant.parse("2022-04-28T09:00:00.000Z") @@ -51,7 +50,7 @@ class LocationsIntegrationTest : BaseServerIntegrationTest() { locations = (0 until numberOfLocations).map { index -> validLocation.copy( evses = listOf(validEvse.copy(connectors = listOf(validConnector))), - last_updated = referenceDate.plusSeconds(3600L * index) + lastUpdated = referenceDate.plusSeconds(3600L * index) ) } ) @@ -59,7 +58,7 @@ class LocationsIntegrationTest : BaseServerIntegrationTest() { val cpoServerVersionsUrl = "${cpoServer.baseUrl}/versions" - val platformRepo = DummyPlatformCacheRepository().also { + val partnerRepo = DummyPartnerCacheRepository().also { val versionDetailsCpo = VersionDetailsCacheRepository(baseUrl = cpoServer.baseUrl) runBlocking { @@ -70,11 +69,10 @@ class LocationsIntegrationTest : BaseServerIntegrationTest() { } } - val locationsEmspClient = LocationsEmspClient( transportClientBuilder = Http4kTransportClientBuilder(), serverVersionsEndpointUrl = cpoServerVersionsUrl, - platformRepository = platformRepo + partnerRepository = partnerRepo ) // Tests @@ -177,14 +175,15 @@ class LocationsIntegrationTest : BaseServerIntegrationTest() { dateFrom = null dateTo = null - expectThat(runBlocking { - locationsEmspClient.getLocations( - dateFrom = dateFrom, - dateTo = dateTo, - offset = offset, - limit = limit - ) - } + expectThat( + runBlocking { + locationsEmspClient.getLocations( + dateFrom = dateFrom, + dateTo = dateTo, + offset = offset, + limit = limit + ) + } ) { get { status_code } .isEqualTo(OcpiStatus.SUCCESS.code) @@ -223,14 +222,15 @@ class LocationsIntegrationTest : BaseServerIntegrationTest() { dateFrom = referenceDate dateTo = lastDate - expectThat(runBlocking { - locationsEmspClient.getLocations( - dateFrom = dateFrom, - dateTo = dateTo, - offset = offset, - limit = limit - ) - } + expectThat( + runBlocking { + locationsEmspClient.getLocations( + dateFrom = dateFrom, + dateTo = dateTo, + offset = offset, + limit = limit + ) + } ) { get { status_code } .isEqualTo(OcpiStatus.SUCCESS.code) @@ -269,14 +269,15 @@ class LocationsIntegrationTest : BaseServerIntegrationTest() { dateFrom = referenceDate dateTo = null - expectThat(runBlocking { - locationsEmspClient.getLocations( - dateFrom = dateFrom, - dateTo = dateTo, - offset = offset, - limit = limit - ) - } + expectThat( + runBlocking { + locationsEmspClient.getLocations( + dateFrom = dateFrom, + dateTo = dateTo, + offset = offset, + limit = limit + ) + } ) { get { status_code } .isEqualTo(OcpiStatus.SUCCESS.code) @@ -315,14 +316,15 @@ class LocationsIntegrationTest : BaseServerIntegrationTest() { dateFrom = null dateTo = lastDate - expectThat(runBlocking { - locationsEmspClient.getLocations( - dateFrom = dateFrom, - dateTo = dateTo, - offset = offset, - limit = limit - ) - } + expectThat( + runBlocking { + locationsEmspClient.getLocations( + dateFrom = dateFrom, + dateTo = dateTo, + offset = offset, + limit = limit + ) + } ) { get { status_code } .isEqualTo(OcpiStatus.SUCCESS.code) @@ -361,14 +363,15 @@ class LocationsIntegrationTest : BaseServerIntegrationTest() { dateFrom = lastDate dateTo = null - expectThat(runBlocking { - locationsEmspClient.getLocations( - dateFrom = dateFrom, - dateTo = dateTo, - offset = offset, - limit = limit - ) - } + expectThat( + runBlocking { + locationsEmspClient.getLocations( + dateFrom = dateFrom, + dateTo = dateTo, + offset = offset, + limit = limit + ) + } ) { get { status_code } .isEqualTo(OcpiStatus.SUCCESS.code) @@ -407,14 +410,15 @@ class LocationsIntegrationTest : BaseServerIntegrationTest() { dateFrom = null dateTo = referenceDate - expectThat(runBlocking { - locationsEmspClient.getLocations( - dateFrom = dateFrom, - dateTo = dateTo, - offset = offset, - limit = limit - ) - } + expectThat( + runBlocking { + locationsEmspClient.getLocations( + dateFrom = dateFrom, + dateTo = dateTo, + offset = offset, + limit = limit + ) + } ) { get { status_code } .isEqualTo(OcpiStatus.SUCCESS.code) @@ -495,14 +499,15 @@ class LocationsIntegrationTest : BaseServerIntegrationTest() { dateFrom = null dateTo = lastDate.minusSeconds(3600L) - expectThat(runBlocking { - locationsEmspClient.getLocations( - dateFrom = dateFrom, - dateTo = dateTo, - offset = offset, - limit = limit - ) - } + expectThat( + runBlocking { + locationsEmspClient.getLocations( + dateFrom = dateFrom, + dateTo = dateTo, + offset = offset, + limit = limit + ) + } ) { get { status_code } .isEqualTo(OcpiStatus.SUCCESS.code) @@ -532,7 +537,9 @@ class LocationsIntegrationTest : BaseServerIntegrationTest() { } .and { get { nextPageUrl } - .isEqualTo("${cpoServer.baseUrl}/2.2.1/locations?date_to=${dateTo}&limit=$limit&offset=${offset + limit}") + .isEqualTo( + "${cpoServer.baseUrl}/2.2.1/locations?date_to=$dateTo&limit=$limit&offset=${offset + limit}" + ) } } } diff --git a/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/tests/integration/common/BaseDBIntegrationTest.kt b/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/tests/integration/common/BaseDBIntegrationTest.kt index 6934c32e..8b7f9ba4 100644 --- a/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/tests/integration/common/BaseDBIntegrationTest.kt +++ b/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/tests/integration/common/BaseDBIntegrationTest.kt @@ -14,4 +14,4 @@ abstract class BaseDBIntegrationTest { protected fun buildDBClient() = KMongo.createClient(mongoDBContainer.replicaSetUrl) -} \ No newline at end of file +} diff --git a/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/tests/integration/common/BaseServerIntegrationTest.kt b/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/tests/integration/common/BaseServerIntegrationTest.kt index 67daa1f6..3098e6fb 100644 --- a/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/tests/integration/common/BaseServerIntegrationTest.kt +++ b/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/tests/integration/common/BaseServerIntegrationTest.kt @@ -1,7 +1,7 @@ package com.izivia.ocpi.toolkit.tests.integration.common import com.izivia.ocpi.toolkit.common.checkToken -import com.izivia.ocpi.toolkit.modules.credentials.repositories.PlatformRepository +import com.izivia.ocpi.toolkit.modules.credentials.repositories.PartnerRepository import com.izivia.ocpi.toolkit.samples.common.Http4kTransportClient import com.izivia.ocpi.toolkit.samples.common.Http4kTransportServer import java.net.ServerSocket @@ -11,14 +11,14 @@ abstract class BaseServerIntegrationTest : BaseDBIntegrationTest() { private fun getFreeNetworkPort() = ServerSocket(0).use { it.localPort } protected fun buildTransportServer( - platformRepository: PlatformRepository? = null + partnerRepository: PartnerRepository? = null ): Http4kTransportServer { val port = getFreeNetworkPort() return Http4kTransportServer( baseUrl = "http://localhost:$port", port = port ) { - platformRepository?.checkToken(it) + partnerRepository?.checkToken(it) } } diff --git a/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/tests/integration/mock/LocationsCpoMongoRepository.kt b/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/tests/integration/mock/LocationsCpoMongoRepository.kt index cc170ec0..c49fa2a4 100644 --- a/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/tests/integration/mock/LocationsCpoMongoRepository.kt +++ b/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/tests/integration/mock/LocationsCpoMongoRepository.kt @@ -16,13 +16,18 @@ class LocationsCpoMongoRepository( private val collection: MongoCollection ) : LocationsCpoRepository { - override fun getLocations(dateFrom: Instant?, dateTo: Instant?, offset: Int, limit: Int?): SearchResult = + override suspend fun getLocations( + dateFrom: Instant?, + dateTo: Instant?, + offset: Int, + limit: Int? + ): SearchResult = collection .run { find( and( - dateFrom?.let { Location::last_updated gte dateFrom }, - dateTo?.let { Location::last_updated lte dateTo } + dateFrom?.let { Location::lastUpdated gte dateFrom }, + dateTo?.let { Location::lastUpdated lte dateTo } ) ) } @@ -37,15 +42,15 @@ class LocationsCpoMongoRepository( .toSearchResult(totalCount = size, limit = actualLimit, offset = offset) } - override fun getLocation(locationId: String): Location? { + override suspend fun getLocation(locationId: String): Location? { TODO("Not yet implemented") } - override fun getEvse(locationId: String, evseUid: String): Evse? { + override suspend fun getEvse(locationId: String, evseUid: String): Evse? { TODO("Not yet implemented") } - override fun getConnector(locationId: String, evseUid: String, connectorId: String): Connector? { + override suspend fun getConnector(locationId: String, evseUid: String, connectorId: String): Connector? { TODO("Not yet implemented") } } diff --git a/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/tests/integration/mock/PartnerMongoRepository.kt b/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/tests/integration/mock/PartnerMongoRepository.kt new file mode 100644 index 00000000..948b44b3 --- /dev/null +++ b/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/tests/integration/mock/PartnerMongoRepository.kt @@ -0,0 +1,102 @@ +package com.izivia.ocpi.toolkit.tests.integration.mock + +import com.izivia.ocpi.toolkit.modules.credentials.domain.CredentialRole +import com.izivia.ocpi.toolkit.modules.credentials.repositories.PartnerRepository +import com.izivia.ocpi.toolkit.modules.versions.domain.Endpoint +import com.izivia.ocpi.toolkit.modules.versions.domain.Version +import com.izivia.ocpi.toolkit.samples.common.Partner +import com.mongodb.client.MongoCollection +import com.mongodb.client.model.FindOneAndUpdateOptions +import com.mongodb.client.model.ReturnDocument +import org.litote.kmongo.* + +class PartnerMongoRepository( + private val collection: MongoCollection +) : PartnerRepository { + + override suspend fun savePartnerUrlForTokenA(tokenA: String, partnerUrl: String): String? = + collection + .findOneAndUpdate( + Partner::tokenA eq tokenA, + set(Partner::url setTo partnerUrl), + FindOneAndUpdateOptions().returnDocument(ReturnDocument.AFTER) + ) + ?.url + + override suspend fun saveCredentialsRoles( + partnerUrl: String, + credentialsRoles: List + ): List = + credentialsRoles.also { + collection + .updateOne(Partner::url eq partnerUrl, set(Partner::credentialsRoles setTo it)) + } + + override suspend fun saveVersion(partnerUrl: String, version: Version): Version = version.also { + collection + .updateOne(Partner::url eq partnerUrl, set(Partner::version setTo it)) + } + + override suspend fun saveEndpoints(partnerUrl: String, endpoints: List): List = endpoints.also { + collection + .updateOne(Partner::url eq partnerUrl, set(Partner::endpoints setTo it)) + } + + override suspend fun saveCredentialsClientToken(partnerUrl: String, credentialsClientToken: String): String = + credentialsClientToken.also { + collection + .updateOne(Partner::url eq partnerUrl, set(Partner::clientToken setTo it)) + } + + override suspend fun saveCredentialsServerToken(partnerUrl: String, credentialsServerToken: String): String = + credentialsServerToken.also { + collection + .updateOne(Partner::url eq partnerUrl, set(Partner::serverToken setTo it)) + } + + override suspend fun getCredentialsTokenA(partnerUrl: String): String? = collection + .findOne(Partner::url eq partnerUrl)?.tokenA + + override suspend fun getCredentialsClientToken(partnerUrl: String): String? = collection + .findOne(Partner::url eq partnerUrl)?.clientToken + + override suspend fun isCredentialsTokenAValid(credentialsTokenA: String): Boolean = collection + .findOne(Partner::tokenA eq credentialsTokenA) != null + + override suspend fun isCredentialsServerTokenValid(credentialsServerToken: String): Boolean = collection + .findOne(Partner::serverToken eq credentialsServerToken) != null + + override suspend fun getPartnerUrlByCredentialsServerToken(credentialsServerToken: String): String? = collection + .findOne(Partner::serverToken eq credentialsServerToken)?.url + + override suspend fun getEndpoints(partnerUrl: String): List = collection + .findOne(Partner::url eq partnerUrl)?.endpoints ?: emptyList() + + override suspend fun getVersion(partnerUrl: String): Version? = collection + .findOne(Partner::url eq partnerUrl)?.version + + override suspend fun invalidateCredentialsTokenA(partnerUrl: String): Boolean = + collection + .updateOne(Partner::url eq partnerUrl, set(Partner::tokenA setTo null)) + .matchedCount == 1L + + override suspend fun invalidateCredentialsClientToken(partnerUrl: String): Boolean = + collection + .updateOne( + Partner::url eq partnerUrl, + combine( + set(Partner::clientToken setTo null) + ) + ) + .matchedCount == 1L + + override suspend fun invalidateCredentialsServerToken(partnerUrl: String): Boolean = + collection + .updateOne( + Partner::url eq partnerUrl, + combine( + set(Partner::serverToken setTo null) + ) + ) + .matchedCount == 1L +} diff --git a/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/tests/integration/mock/PlatformMongoRepository.kt b/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/tests/integration/mock/PlatformMongoRepository.kt deleted file mode 100644 index 6af6c27a..00000000 --- a/ocpi-toolkit-2.2.1/src/test/kotlin/com/izivia/ocpi/toolkit/tests/integration/mock/PlatformMongoRepository.kt +++ /dev/null @@ -1,86 +0,0 @@ -package com.izivia.ocpi.toolkit.tests.integration.mock - -import com.izivia.ocpi.toolkit.modules.credentials.repositories.PlatformRepository -import com.izivia.ocpi.toolkit.modules.versions.domain.Endpoint -import com.izivia.ocpi.toolkit.modules.versions.domain.Version -import com.izivia.ocpi.toolkit.samples.common.Platform -import com.mongodb.client.MongoCollection -import com.mongodb.client.model.FindOneAndUpdateOptions -import com.mongodb.client.model.ReturnDocument -import org.litote.kmongo.* - -class PlatformMongoRepository( - private val collection: MongoCollection -) : PlatformRepository { - - override suspend fun savePlatformUrlForTokenA(tokenA: String, platformUrl: String): String? = - collection - .findOneAndUpdate( - Platform::tokenA eq tokenA, - set(Platform::url setTo platformUrl), - FindOneAndUpdateOptions().returnDocument(ReturnDocument.AFTER) - ) - ?.url - - override suspend fun saveVersion(platformUrl: String, version: Version): Version = version.also { - collection - .updateOne(Platform::url eq platformUrl, set(Platform::version setTo it)) - } - - override suspend fun saveEndpoints(platformUrl: String, endpoints: List): List = endpoints.also { - collection - .updateOne(Platform::url eq platformUrl, set(Platform::endpoints setTo it)) - } - - override suspend fun saveCredentialsClientToken(platformUrl: String, credentialsClientToken: String): String = - credentialsClientToken.also { - collection - .updateOne(Platform::url eq platformUrl, set(Platform::clientToken setTo it)) - } - - override suspend fun saveCredentialsServerToken(platformUrl: String, credentialsServerToken: String): String = - credentialsServerToken.also { - collection - .updateOne(Platform::url eq platformUrl, set(Platform::serverToken setTo it)) - } - - override suspend fun getCredentialsTokenA(platformUrl: String): String? = collection - .findOne(Platform::url eq platformUrl)?.tokenA - - override suspend fun getCredentialsClientToken(platformUrl: String): String? = collection - .findOne(Platform::url eq platformUrl)?.clientToken - - override suspend fun isCredentialsTokenAValid(credentialsTokenA: String): Boolean = collection - .findOne(Platform::tokenA eq credentialsTokenA) != null - - override suspend fun isCredentialsServerTokenValid(credentialsServerToken: String): Boolean = collection - .findOne(Platform::serverToken eq credentialsServerToken) != null - - override suspend fun getPlatformUrlByCredentialsServerToken(credentialsServerToken: String): String? = collection - .findOne(Platform::serverToken eq credentialsServerToken)?.url - - override suspend fun getEndpoints(platformUrl: String): List = collection - .findOne(Platform::url eq platformUrl)?.endpoints ?: emptyList() - - override suspend fun getVersion(platformUrl: String): Version? = collection - .findOne(Platform::url eq platformUrl)?.version - - override suspend fun invalidateCredentialsTokenA(platformUrl: String): Boolean = - collection - .updateOne(Platform::url eq platformUrl, set(Platform::tokenA setTo null)) - .matchedCount == 1L - - override suspend fun unregisterPlatform(platformUrl: String): Boolean = - collection - .updateOne( - Platform::url eq platformUrl, - combine( - set(Platform::tokenA setTo null), - set(Platform::clientToken setTo null), - set(Platform::serverToken setTo null), - set(Platform::version setTo null), - set(Platform::endpoints setTo null) - ) - ) - .matchedCount == 1L -} diff --git a/settings.gradle.kts b/settings.gradle.kts index 42ddb13c..d0fb6b4f 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -1,10 +1,14 @@ rootProject.name = "ocpi-toolkit" +pluginManagement { + repositories { + gradlePluginPortal() + } +} + include( "common", "annotation-processor", "transport", - "ocpi-toolkit-2.1.1", - "ocpi-toolkit-2.2.1", - "ocpi-toolkit-2.1.1-gireve" + "ocpi-toolkit-2.2.1" ) diff --git a/transport/src/main/kotlin/com/izivia/ocpi/toolkit/transport/domain/HttpException.kt b/transport/src/main/kotlin/com/izivia/ocpi/toolkit/transport/domain/HttpException.kt index 72ba7144..a05a14f3 100644 --- a/transport/src/main/kotlin/com/izivia/ocpi/toolkit/transport/domain/HttpException.kt +++ b/transport/src/main/kotlin/com/izivia/ocpi/toolkit/transport/domain/HttpException.kt @@ -1,4 +1,4 @@ package com.izivia.ocpi.toolkit.transport.domain class HttpException(val status: HttpStatus, val reason: String) : - Exception("HTTP Error, status $status, message: $reason") \ No newline at end of file + Exception("HTTP Error, status $status, message: $reason") diff --git a/transport/src/main/kotlin/com/izivia/ocpi/toolkit/transport/domain/HttpMethod.kt b/transport/src/main/kotlin/com/izivia/ocpi/toolkit/transport/domain/HttpMethod.kt index 75c196c8..33b48c82 100644 --- a/transport/src/main/kotlin/com/izivia/ocpi/toolkit/transport/domain/HttpMethod.kt +++ b/transport/src/main/kotlin/com/izivia/ocpi/toolkit/transport/domain/HttpMethod.kt @@ -2,4 +2,4 @@ package com.izivia.ocpi.toolkit.transport.domain enum class HttpMethod { GET, POST, PUT, PATCH, DELETE -} \ No newline at end of file +} diff --git a/transport/src/main/kotlin/com/izivia/ocpi/toolkit/transport/domain/HttpStatus.kt b/transport/src/main/kotlin/com/izivia/ocpi/toolkit/transport/domain/HttpStatus.kt index 19c6ffd0..70f45546 100644 --- a/transport/src/main/kotlin/com/izivia/ocpi/toolkit/transport/domain/HttpStatus.kt +++ b/transport/src/main/kotlin/com/izivia/ocpi/toolkit/transport/domain/HttpStatus.kt @@ -1,13 +1,13 @@ package com.izivia.ocpi.toolkit.transport.domain enum class HttpStatus(val code: Int, val label: String) { - //1xx: Informational + // 1xx: Informational CONTINUE(100, "Continue"), SWITCHING_PROTOCOLS(101, "Switching Protocols"), PROCESSING(102, "Processing"), EARLY_HINTS(103, "Early Hints"), - //2xx: Success + // 2xx: Success OK(200, "OK"), CREATED(201, "Created"), ACCEPTED(202, "Accepted"), @@ -19,7 +19,7 @@ enum class HttpStatus(val code: Int, val label: String) { ALREADY_REPORTED(208, "Already Reported"), IM_USED(226, "IM Used"), - //3xx: Redirection + // 3xx: Redirection MULTIPLE_CHOICES(300, "Multiple Choice"), MOVED_PERMANENTLY(301, "Moved Permanently"), FOUND(302, "Found"), @@ -29,7 +29,7 @@ enum class HttpStatus(val code: Int, val label: String) { TEMPORARY_REDIRECT(307, "Temporary Redirect"), PERMANENT_REDIRECT(308, "Permanent Redirect"), - //4xx: Client Error + // 4xx: Client Error BAD_REQUEST(400, "Bad Request"), UNAUTHORIZED(401, "Unauthorized"), PAYMENT_REQUIRED(402, "Payment Required"), @@ -59,7 +59,7 @@ enum class HttpStatus(val code: Int, val label: String) { REQUEST_HEADER_FIELDS_TOO_LARGE(431, "Request Header Fields Too Large"), UNAVAILABLE_FOR_LEGAL_REASONS(451, "Unavailable For Legal Reasons"), - //5xx: Server Error + // 5xx: Server Error INTERNAL_SERVER_ERROR(500, "Internal Server Error"), NOT_IMPLEMENTED(501, "Not Implemented"), BAD_GATEWAY(502, "Bad Gateway"), @@ -70,9 +70,9 @@ enum class HttpStatus(val code: Int, val label: String) { INSUFFICIENT_STORAGE(507, "Insufficient Storage"), LOOP_DETECTED(508, "Loop Detected"), NOT_EXTENDED(510, "Not Extended"), - NETWORK_AUTHENTICATION_REQUIRED(511, "Network Authentication Required"); + NETWORK_AUTHENTICATION_REQUIRED(511, "Network Authentication Required") } fun parseHttpStatus(code: Int) = HttpStatus .values().firstOrNull { it.code == code } - ?: throw EnumConstantNotPresentException(HttpStatus::class.java, code.toString()) \ No newline at end of file + ?: throw EnumConstantNotPresentException(HttpStatus::class.java, code.toString()) diff --git a/transport/src/main/kotlin/com/izivia/ocpi/toolkit/transport/domain/PathSegment.kt b/transport/src/main/kotlin/com/izivia/ocpi/toolkit/transport/domain/PathSegment.kt index ff91a203..c070a59d 100644 --- a/transport/src/main/kotlin/com/izivia/ocpi/toolkit/transport/domain/PathSegment.kt +++ b/transport/src/main/kotlin/com/izivia/ocpi/toolkit/transport/domain/PathSegment.kt @@ -11,5 +11,3 @@ data class FixedPathSegment( data class VariablePathSegment( override val path: String ) : PathSegment - -