-
Notifications
You must be signed in to change notification settings - Fork 0
Refactor JobGetInfos to streamline route handling; add support for se… #60
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -41,6 +41,8 @@ public class JobGetInfos { | |||||
| */ | ||||||
| private URLProvider urlBranch; | ||||||
|
|
||||||
| private String fullRoute = ""; | ||||||
|
|
||||||
| /** | ||||||
| * Constructor of JobGetInfos. | ||||||
| * Initializes the ApiClient and loads the YAML configuration. | ||||||
|
|
@@ -59,196 +61,91 @@ private String getRouteName(Enum<?> routeName) { | |||||
| return routeName.name().toLowerCase(); | ||||||
| } | ||||||
|
|
||||||
| /** | ||||||
| * Get routes from the YAML file and builds the full URL. | ||||||
| * @param versionType Version of the API (V1_BRANCH, V2_BRANCH) | ||||||
| * @param methodType Type of HTTP method (GET, POST) | ||||||
| * @param routeName Name of the route in the YAML file | ||||||
| * @param body Body of the request for POST (can be null for GET) | ||||||
| * @return JobGetInfos for chaining | ||||||
| */ | ||||||
| public JobGetInfos getRoutes(VersionProvider versionType, MethodType methodType, Enum<?> routeName, Map<String, ?> body) { | ||||||
| return getRoutes(versionType, methodType, getRouteName(routeName), body, null, null); | ||||||
| } | ||||||
|
|
||||||
| /** | ||||||
| * Get routes from the YAML file and builds the full URL with parameters. | ||||||
| * @param versionType Version of the API (V1_BRANCH, V2_BRANCH) | ||||||
| * @param methodType Type of HTTP method (GET, POST) | ||||||
| * @param routeName Name of the route in the YAML file | ||||||
| * @return JobGetInfos for chaining | ||||||
| */ | ||||||
| public JobGetInfos getRoutes(VersionProvider versionType, MethodType methodType, Enum<?> routeName) { | ||||||
| return getRoutes(versionType, methodType, getRouteName(routeName), null, null, null); | ||||||
| } | ||||||
|
|
||||||
| /** | ||||||
| * Get routes from the YAML file and builds the full URL with a request body. | ||||||
| * @param methodType Type of HTTP method (GET, POST) | ||||||
| * @param routeName Name of the route in the YAML file | ||||||
| * @return JobGetInfos for chaining | ||||||
| */ | ||||||
| public JobGetInfos getRoutes(MethodType methodType, Enum<?> routeName) { | ||||||
| return getRoutes(null, methodType, getRouteName(routeName), null, null, null); | ||||||
| } | ||||||
|
|
||||||
| /** | ||||||
| * Get routes from the YAML file and builds the full URL with a request body and parameters. | ||||||
| * @param methodType Type of HTTP method (GET, POST) | ||||||
| * @param routeName Name of the route in the YAML file | ||||||
| * @param body Body of the request for POST (can be null for GET) | ||||||
| * @return JobGetInfos for chaining | ||||||
| */ | ||||||
| public JobGetInfos getRoutes(MethodType methodType, Enum<?> routeName, Map<String, ?> body) { | ||||||
| return getRoutes(null, methodType, getRouteName(routeName), body, null, null); | ||||||
| } | ||||||
|
|
||||||
| /** | ||||||
| * Get routes from the YAML file and builds the full URL with additional parameters. | ||||||
| * @param methodType Type of HTTP method (GET, POST) | ||||||
| * @param routeName Name of the route in the YAML file | ||||||
| * @param params Additional parameters for the request | ||||||
| * @return JobGetInfos for chaining | ||||||
| */ | ||||||
| public JobGetInfos getRoutes(MethodType methodType, Enum<?> routeName, Map<String, ?> body, Map<String, ?> params) { | ||||||
| return getRoutes(null, methodType, getRouteName(routeName), body, params, null); | ||||||
| } | ||||||
|
|
||||||
| /** | ||||||
| * Get routes from the YAML file and builds the full URL. | ||||||
| * @param methodType Type of HTTP method (GET, POST) | ||||||
| * @param routeName Name of the route in the YAML file | ||||||
| * @return JobGetInfos for chaining | ||||||
| */ | ||||||
| public JobGetInfos getRoutes(MethodType methodType, String routeName) { | ||||||
| return getRoutes(null, methodType, routeName, null, null, null); | ||||||
| } | ||||||
|
|
||||||
| /** | ||||||
| * Récupère les routes depuis le fichier YAML et construit l'URL complète | ||||||
| * @param versionType Version de l'API (V1_BRANCH, V2_BRANCH) | ||||||
| * @param methodType Type de méthode HTTP (GET, POST) | ||||||
| * @param routeName Nom de la route dans le fichier YAML | ||||||
| * @return JobGetInfos pour chaînage | ||||||
| */ | ||||||
| public JobGetInfos getRoutes(VersionProvider versionType, MethodType methodType, String routeName) { | ||||||
| return getRoutes(versionType, methodType, routeName, null, null, null); | ||||||
| return getRoutes(null, methodType, getRouteName(routeName)); | ||||||
| } | ||||||
|
|
||||||
| /** | ||||||
| * Get routes from the YAML file and builds the full URL with a request body. | ||||||
| * @param versionType Version of the API (V1_BRANCH, V2_BRANCH) | ||||||
| * @param versionType VersionProvider to specify API versioning | ||||||
| * @param methodType Type of HTTP method (GET, POST) | ||||||
| * @param routeName Name of the route in the YAML file | ||||||
| * @param body Body of the request for POST (can be null for GET) | ||||||
| * @return JobGetInfos for chaining | ||||||
| */ | ||||||
| public JobGetInfos getRoutes(VersionProvider versionType, MethodType methodType, String routeName, Map<String, ?> body) { | ||||||
| return getRoutes(versionType, methodType, routeName, body, null, null); | ||||||
| } | ||||||
|
|
||||||
| /** | ||||||
| * Get routes from the YAML file and builds the full URL with a request body and parameters. | ||||||
| * @param methodType Type of HTTP method (GET, POST) | ||||||
| * @param routeName Name of the route in the YAML file | ||||||
| * @param body Body of the request for POST (can be null for GET) | ||||||
| * @param params Additional parameters for the request | ||||||
| * @param query Additional query parameters for the request | ||||||
| * @return JobGetInfos for chaining | ||||||
| */ | ||||||
| public JobGetInfos getRoutes(MethodType methodType, String routeName, Map<String, ?> body, Map<String, ?> params, Map<String, ?> query) { | ||||||
| return getRoutes(null, methodType, routeName, body, params, query); | ||||||
| } | ||||||
|
|
||||||
| /** | ||||||
| * Get routes from the YAML file and builds the full URL with additional parameters. | ||||||
| * @param methodType Type of HTTP method (GET, POST) | ||||||
| * @param routeName Name of the route in the YAML file | ||||||
| * @param body Body of the request for POST (can be null for GET) | ||||||
| * @param params Additional parameters for the request | ||||||
| * @param query Additional query parameters for the request | ||||||
| * @return JobGetInfos for chaining | ||||||
| */ | ||||||
| public JobGetInfos getRoutes(MethodType methodType, Enum<?> routeName, Map<String, ?> body, Map<String, ?> params, Map<String, ?> query) { | ||||||
| return getRoutes(null, methodType, getRouteName(routeName), body, params, query); | ||||||
| } | ||||||
|
|
||||||
| /** | ||||||
| * Get routes from the YAML file and builds the full URL with additional parameters. | ||||||
| * @param versionType Version of the API (V1_BRANCH, V2_BRANCH) | ||||||
| * @param methodType Type of HTTP method (GET, POST) | ||||||
| * @param routeName Name of the route in the YAML file | ||||||
| * @param params Additional parameters for the request | ||||||
| * @param query Additional query parameters for the request | ||||||
| * @return JobGetInfos for chaining | ||||||
| */ | ||||||
| public <R> JobGetInfos getRoutes(VersionProvider versionType, MethodType methodType, R routeName, Map<String, ?> body, Map<String, ?> params, Map<String, ?> query) { | ||||||
| public <R> JobGetInfos getRoutes(VersionProvider versionType, MethodType methodType, R routeName) { | ||||||
| try { | ||||||
| String route = connectLib.getRoute(routeName.toString().toLowerCase()); | ||||||
|
|
||||||
| String fullRoute; | ||||||
|
|
||||||
| if (versionType != null && versionType.getVersion() != null) { | ||||||
| String cleanRoute = route.startsWith("/") ? route.substring(1) : route; | ||||||
| fullRoute = "/" + versionType.getVersion() + "/" + cleanRoute; | ||||||
|
||||||
| fullRoute = "/" + versionType.getVersion() + "/" + cleanRoute; | |
| this.fullRoute = "/" + versionType.getVersion() + "/" + cleanRoute; |
Copilot
AI
Nov 15, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing documentation for the newly added public method body(). Add JavaDoc to describe its purpose, parameters, and return value to maintain consistency with the existing codebase documentation standards.
Copilot
AI
Nov 15, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing documentation for the newly added public method params(). Add JavaDoc to describe its purpose, parameters, and return value to maintain consistency with the existing codebase documentation standards.
Copilot
AI
Nov 15, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The params() method modifies this.fullRoute but will fail if getRoutes() hasn't been called first, as fullRoute is initialized to empty string. This creates a fragile method call order dependency. Consider validating that fullRoute is not empty or documenting the required call order.
Copilot
AI
Nov 15, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Query parameter values are not URL-encoded before being appended to the query string. Special characters in parameter values (e.g., spaces, &, =) will cause malformed URLs or incorrect query strings. Use URLEncoder.encode(value.toString(), StandardCharsets.UTF_8) to properly encode the values.
Copilot
AI
Nov 15, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing documentation for the newly added public method query(). Add JavaDoc to describe its purpose, parameters, and return value to maintain consistency with the existing codebase documentation standards.
Copilot
AI
Nov 15, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The query() method modifies this.fullRoute but will fail if getRoutes() hasn't been called first, as fullRoute is initialized to empty string. This creates a fragile method call order dependency. Consider validating that fullRoute is not empty or documenting the required call order.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -29,7 +29,8 @@ public class MainTest { | |
| public enum TestRoutes implements RouteImport { | ||
| HELLO("/hello"), | ||
| GREET("greet$name$"), | ||
| REQUEST_TOKEN("/auth/request/token") | ||
| REQUEST_TOKEN("/auth/request/token"), | ||
| SESSION_PUSH("/auth/link/app/{sessionId}") | ||
| ; | ||
|
|
||
| final String route; | ||
|
|
@@ -131,7 +132,7 @@ public void testUseFullRoute() { | |
| ); | ||
|
|
||
| CompletableFuture<ApiFactory> factoryCompletableFuture = connectLib.JobGetInfos() | ||
| .getRoutes(MethodType.GET, TestRoutes.GREET, null, null, query) | ||
| .getRoutes(MethodType.GET, TestRoutes.GREET) | ||
| .execute(); | ||
|
|
||
| ApiFactory response = factoryCompletableFuture.get(5, TimeUnit.SECONDS); | ||
|
|
@@ -171,6 +172,14 @@ public void testLangType() { | |
| } | ||
| } | ||
|
|
||
| private String code_session; | ||
|
|
||
| @Test | ||
| public void testProd() { | ||
| testSpecData(); | ||
|
|
||
| pushsession(); | ||
| } | ||
|
|
||
| @Test | ||
| public void testSpecData() { | ||
|
|
@@ -191,6 +200,31 @@ public void testSpecData() { | |
|
|
||
| System.out.println(apiFactory.getSpecData("data", "accessToken")); | ||
|
|
||
| this.code_session = (String) apiFactory.getSpecData("data", "sessionCode"); | ||
|
||
|
|
||
| } catch (Exception e) { | ||
| e.printStackTrace(); | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| public void pushsession() { | ||
| try { | ||
|
|
||
| Map<?,?> params = Map.of( | ||
| "sessionId", this.code_session | ||
| ); | ||
|
|
||
| CompletableFuture<ApiFactory> apiFactoryCompletableFuture = connectLib.JobGetInfos() | ||
| .getRoutes(TestCustomVersion.V1_API, MethodType.POST, TestRoutes.SESSION_PUSH) | ||
| .urlBranch(ExampleUrlBranch.PROD) | ||
| .params(params) | ||
| .getResponse(); | ||
|
|
||
| ApiFactory apiFactory = apiFactoryCompletableFuture.get(5, TimeUnit.SECONDS); | ||
|
|
||
| System.out.println("Réponse brute: " + apiFactory.display()); | ||
|
|
||
| } catch (Exception e) { | ||
| e.printStackTrace(); | ||
| } | ||
|
|
@@ -218,5 +252,4 @@ public void startAppServices() { | |
| } | ||
| } | ||
|
|
||
|
|
||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The instance variable
fullRouteintroduces thread safety issues. Multiple threads could concurrently callgetRoutes(),params(), orquery()on the sameJobGetInfosinstance, leading to race conditions where threads overwrite each other's route values. Consider makingfullRoutea local variable passed between methods or using ThreadLocal storage.