From 00b546c3b9df47b8c1d3cc5d80ea8c4028706033 Mon Sep 17 00:00:00 2001 From: Sandro Date: Mon, 10 Nov 2025 18:54:01 +0100 Subject: [PATCH 1/9] Add AtomicFactory class and refactor JobGetInfos response method --- build.gradle | 2 +- .../github/example/ExampleUsages.java | 107 ------------------ .../fr/sandro642/github/jobs/JobGetInfos.java | 2 +- .../github/provider/AtomicFactory.java | 18 +++ .../fr/sandro642/github/test/MainTest.java | 43 ++++--- 5 files changed, 46 insertions(+), 126 deletions(-) delete mode 100644 src/main/java/fr/sandro642/github/example/ExampleUsages.java create mode 100644 src/main/java/fr/sandro642/github/provider/AtomicFactory.java diff --git a/build.gradle b/build.gradle index c8ed704..4263845 100644 --- a/build.gradle +++ b/build.gradle @@ -5,7 +5,7 @@ plugins { } group = 'fr.sandro642.github' -version = '0.4.3.1-STABLE' +version = '0.4.4-DEV_BUILD' // Générer une classe de version automatiquement task generateVersionClass { diff --git a/src/main/java/fr/sandro642/github/example/ExampleUsages.java b/src/main/java/fr/sandro642/github/example/ExampleUsages.java deleted file mode 100644 index 2caacea..0000000 --- a/src/main/java/fr/sandro642/github/example/ExampleUsages.java +++ /dev/null @@ -1,107 +0,0 @@ -package fr.sandro642.github.example; - -import fr.sandro642.github.ConnectLib; -import fr.sandro642.github.api.ApiFactory; -import fr.sandro642.github.enums.LangType; -import fr.sandro642.github.enums.MethodType; -import fr.sandro642.github.enums.ResourceType; -import fr.sandro642.github.enums.VersionType; -import fr.sandro642.github.provider.RouteImport; - -import java.util.Map; -import java.util.concurrent.CompletableFuture; -import java.util.concurrent.TimeUnit; - -/** - * ExampleUsages is a placeholder class that can be used to demonstrate how to use the ConnectLib library. - * It can contain example methods or code snippets that show how to interact with the API, handle responses, - * and utilize the features provided by the ConnectLib library. - * - * @author Sandro642 - * @version 1.0 - */ - -public class ExampleUsages { - - private ConnectLib connectLib = new ConnectLib(); - - public enum ExampleRoutes implements RouteImport { - EXAMPLE_ROUTE("/api/example/route"); - - final String route; - - ExampleRoutes(String route) { - this.route = route; - } - - @Override - public String getRoute() { - return route; - } - } - - public void initializeLib() { - - // Optionally, you can specify routes if needed - connectLib.init(ResourceType.MAIN_RESOURCES, LangType.FRENCH, ExampleRoutes.class); - // You can also initialize without specifying routes - connectLib.init(ResourceType.MAIN_RESOURCES, LangType.FRENCH); - } - - // Example method to demonstrate usage - public void exampleMethodSync() { - try { - // This method can be used to demonstrate how to interact with the API - // For example, making a GET request to the EXAMPLE_ROUTE - CompletableFuture apiFactoryCompletableFuture = connectLib.JobGetInfos() - .getRoutes(VersionType.V1_BRANCH, MethodType.GET, ExampleRoutes.EXAMPLE_ROUTE) - .getResponse(); - - ApiFactory response = apiFactoryCompletableFuture.get(5, TimeUnit.SECONDS); - - System.out.println(response.display()); - System.out.println("Response Code: " + response.getData("code")); - System.out.println("Response Message: " + response.getData("message")); - System.out.println("Response Data: " + response.getSpecData("data", "exampleKey")); - System.out.println("Status Code: " + response.getStatusCode()); - } catch (Exception e) { - e.printStackTrace(); - } - } - - // Example method to demonstrate asynchronous usage - public void exampleMethodAsync() { - try { - // This method can be used to demonstrate how to interact with the API asynchronously - - CompletableFuture apiFactoryCompletableFuture = connectLib.JobGetInfos() - .getRoutes(VersionType.V1_BRANCH, MethodType.GET, ExampleRoutes.EXAMPLE_ROUTE) - .getResponse(); - - ApiFactory response = apiFactoryCompletableFuture.get(5, TimeUnit.SECONDS); - - System.out.println(response.display()); - System.out.println("Response Code: " + response.getData("code")); - System.out.println("Response Message: " + response.getData("message")); - System.out.println("Response Data: " + response.getSpecData("data", "exampleKey")); - } catch (Exception e) { - e.printStackTrace(); - } - } - - // Example to use all methods in JobGetInfos - public void exampleJobGetInfos() { - Map body = Map.of(); - Map params = Map.of(); - Map query = Map.of(); - - connectLib.JobGetInfos().getRoutes(VersionType.V1_BRANCH, MethodType.GET, ExampleRoutes.EXAMPLE_ROUTE, body, params, query); - connectLib.JobGetInfos().getRoutes(VersionType.V1_BRANCH, MethodType.POST, ExampleRoutes.EXAMPLE_ROUTE, body); - connectLib.JobGetInfos().getRoutes(VersionType.V1_BRANCH, MethodType.PUT, ExampleRoutes.EXAMPLE_ROUTE, null, params, query); - connectLib.JobGetInfos().getRoutes(VersionType.V1_BRANCH, MethodType.PATCH, ExampleRoutes.EXAMPLE_ROUTE); - connectLib.JobGetInfos().getRoutes(MethodType.GET, ExampleRoutes.EXAMPLE_ROUTE, body, params); - connectLib.JobGetInfos().getRoutes(MethodType.POST, ExampleRoutes.EXAMPLE_ROUTE, body); - connectLib.JobGetInfos().getRoutes(MethodType.DELETE, ExampleRoutes.EXAMPLE_ROUTE); - } - -} diff --git a/src/main/java/fr/sandro642/github/jobs/JobGetInfos.java b/src/main/java/fr/sandro642/github/jobs/JobGetInfos.java index 0f04bf3..fc972ac 100644 --- a/src/main/java/fr/sandro642/github/jobs/JobGetInfos.java +++ b/src/main/java/fr/sandro642/github/jobs/JobGetInfos.java @@ -270,7 +270,7 @@ public JobGetInfos urlBranch(URLProvider urlBranch) { * makes the API call, and returns the response as an ApiFactory object. * @return ApiFactory containing the response from the API, or null if an error occurs. */ - public CompletableFuture getResponse() { + public CompletableFuture execute() { try { String route = (String) connectLib.StoreAndRetrieve().store.get("currentRoute"); MethodType method = (MethodType) connectLib.StoreAndRetrieve().store.get("currentMethod"); diff --git a/src/main/java/fr/sandro642/github/provider/AtomicFactory.java b/src/main/java/fr/sandro642/github/provider/AtomicFactory.java new file mode 100644 index 0000000..fb272da --- /dev/null +++ b/src/main/java/fr/sandro642/github/provider/AtomicFactory.java @@ -0,0 +1,18 @@ +package fr.sandro642.github.provider; + +import fr.sandro642.github.api.ApiFactory; + +import java.util.Map; + +public abstract class AtomicFactory { + + private ApiFactory apiFactory; + + protected void getPhysx(ApiFactory apiFactory) { + this.apiFactory = apiFactory; + } + + protected Map rawPhysx() { + return apiFactory.getRawData(); + } +} diff --git a/src/test/java/fr/sandro642/github/test/MainTest.java b/src/test/java/fr/sandro642/github/test/MainTest.java index f284d4a..5ddba4e 100644 --- a/src/test/java/fr/sandro642/github/test/MainTest.java +++ b/src/test/java/fr/sandro642/github/test/MainTest.java @@ -6,6 +6,7 @@ import fr.sandro642.github.enums.LangType; import fr.sandro642.github.enums.MethodType; import fr.sandro642.github.enums.ResourceType; +import fr.sandro642.github.provider.AtomicFactory; import fr.sandro642.github.provider.RouteImport; import fr.sandro642.github.provider.URLProvider; import fr.sandro642.github.provider.VersionProvider; @@ -43,6 +44,19 @@ public String getRoute() { } } + public class ClassheritFromFactory extends AtomicFactory { + + + + public ClassheritFromFactory(ApiFactory apiFactory) { + getPhysx(apiFactory); + } + + public Object getContent() { + return rawPhysx().get("content"); + } + } + /** * Example of URL branches, you can add multiple branches if you have multiple environments (dev, prod, etc.) */ @@ -94,7 +108,7 @@ public static void main(String[] args) { CompletableFuture apiFactoryCompletableFuture = connectLib.JobGetInfos() .getRoutes(MethodType.GET, TestRoutes.HELLO) - .getResponse(); + .execute(); ApiFactory response = apiFactoryCompletableFuture.get(5, TimeUnit.SECONDS); @@ -118,7 +132,7 @@ public void testUseFullRoute() { CompletableFuture factoryCompletableFuture = connectLib.JobGetInfos() .getRoutes(MethodType.GET, TestRoutes.GREET, null, null, query) - .getResponse(); + .execute(); ApiFactory response = factoryCompletableFuture.get(5, TimeUnit.SECONDS); @@ -145,7 +159,7 @@ public void testLangType() { */ //.urlBranch(ExampleUrlBranch.LOCALHOST) - .getResponse(); + .execute(); ApiFactory response = factoryCompletableFuture.get(5, TimeUnit.SECONDS); @@ -167,7 +181,7 @@ public void testSpecData() { CompletableFuture apiFactoryCompletableFuture = connectLib.JobGetInfos() .getRoutes(TestCustomVersion.V1_API, MethodType.GET, TestRoutes.REQUEST_TOKEN) .urlBranch(ExampleUrlBranch.PROD) - .getResponse(); + .execute(); ApiFactory apiFactory = apiFactoryCompletableFuture.get(5, TimeUnit.SECONDS); @@ -186,23 +200,18 @@ public void testSpecData() { public void startAppServices() { try { connectLib.Logger().showLogs(); - connectLib.init(ResourceType.TEST_RESOURCES, LangType.ENGLISH, TestRoutes.class) - .webServices(8080, "TestDashboard"); + connectLib.init(ResourceType.TEST_RESOURCES, LangType.ENGLISH, TestRoutes.class); + //.webServices(8080, "TestDashboard"); - CompletableFuture apiFactoryCompletableFuture = connectLib.JobGetInfos() + CompletableFuture apiFactoryCompletableFuture = connectLib.JobGetInfos() .getRoutes(MethodType.GET, TestRoutes.HELLO) - .getResponse(); - - apiFactoryCompletableFuture = connectLib.JobGetInfos() - .getRoutes(TestCustomVersion.V1_API ,MethodType.GET, TestRoutes.REQUEST_TOKEN) - .urlBranch(ExampleUrlBranch.PROD) - .getResponse(); - - ApiFactory apiFactory = apiFactoryCompletableFuture.get(5, TimeUnit.SECONDS); + .urlBranch(ExampleUrlBranch.POST_PROD) + .execute() + .thenApply(ClassheritFromFactory::new); - System.out.println("Response: " + apiFactory.display()); + ClassheritFromFactory classheritFromFactory = apiFactoryCompletableFuture.get(5, TimeUnit.SECONDS); - Thread.sleep(20000); + System.out.println("Response: " + classheritFromFactory.getContent()); } catch (Exception e) { e.printStackTrace(); From 867b793e9d3f95e7bb1769db89085c03f4cc448b Mon Sep 17 00:00:00 2001 From: Sandro Soria Date: Mon, 10 Nov 2025 18:57:15 +0100 Subject: [PATCH 2/9] Fix branch name case in workflow configuration --- .github/workflows/work-jar.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/work-jar.yml b/.github/workflows/work-jar.yml index 207f555..c2e888f 100644 --- a/.github/workflows/work-jar.yml +++ b/.github/workflows/work-jar.yml @@ -3,7 +3,7 @@ on: push: branches: - main - - Feature/AtomicFactory + - feature/AtomicFactory permissions: contents: write pages: write From bf2b6e2252e6512989de1e2db82747cfa4ff7d81 Mon Sep 17 00:00:00 2001 From: Sandro Soria Date: Sat, 15 Nov 2025 11:51:58 +0100 Subject: [PATCH 3/9] Update README.md --- README.md | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index c85e4b7..74c71a4 100644 --- a/README.md +++ b/README.md @@ -65,7 +65,7 @@ Changelog: --- -## 🌟 Why ConnectLib? +## Why ConnectLib? Imagine an API that doesn't just connect services, but becomes the conductor of your integrations. ConnectLib is designed to: @@ -76,17 +76,17 @@ Imagine an API that doesn't just connect services, but becomes the conductor of --- -## 🛠️ Main Features +## Main Features -- 🔌 **Centralized connector management** -- ⚡ **Automated job execution** -- 🧩 **Extensible and modular** -- 📊 **Detailed logs and monitoring** -- 🔒 **Built-in security** +- **Centralized connector management** +- **Automated job execution** +- **Extensible and modular** +- **Detailed logs and monitoring** +- **Built-in security** --- -## 🚦 Quick Start +## Quick Start 1. **Clone the project** ```bash @@ -104,13 +104,13 @@ Imagine an API that doesn't just connect services, but becomes the conductor of --- -## 🧑‍💻 Usage Example +## Usage Example More examples HERE: [ExampleUsages.java](src/main/java/fr/sandro642/github/example/ExampleUsages.java) --- [build.gradle](build.gradle) -## 📚 Project Structure +## Project Structure - `src/main/java/fr/sandro642/github/` : main source code - `src/test/java/fr/sandro642/github/test/` : unit tests @@ -118,7 +118,7 @@ More examples HERE: [ExampleUsages.java](src/main/java/fr/sandro642/github/examp --- -## 🤝 Contributing +## Contributing 1. Fork the repo 2. Create a branch (`feature/my-feature`) @@ -126,7 +126,7 @@ More examples HERE: [ExampleUsages.java](src/main/java/fr/sandro642/github/examp --- -## 📞 Contact +## Contact For any questions or suggestions: [sandro33810@gmail.com](mailto:sandro33810@gmail.com) From 0e749b9e2f3c4e2ab063c1a68d5b1ad77db51729 Mon Sep 17 00:00:00 2001 From: Sandro Date: Sat, 15 Nov 2025 12:29:32 +0100 Subject: [PATCH 4/9] Refactor JobGetInfos to streamline route handling; add support for session push and improve query parameter processing --- .../github/example/ExampleUsages.java | 107 --------- .../fr/sandro642/github/jobs/JobGetInfos.java | 213 +++++------------- .../fr/sandro642/github/test/MainTest.java | 45 +++- 3 files changed, 95 insertions(+), 270 deletions(-) delete mode 100644 src/main/java/fr/sandro642/github/example/ExampleUsages.java diff --git a/src/main/java/fr/sandro642/github/example/ExampleUsages.java b/src/main/java/fr/sandro642/github/example/ExampleUsages.java deleted file mode 100644 index 2caacea..0000000 --- a/src/main/java/fr/sandro642/github/example/ExampleUsages.java +++ /dev/null @@ -1,107 +0,0 @@ -package fr.sandro642.github.example; - -import fr.sandro642.github.ConnectLib; -import fr.sandro642.github.api.ApiFactory; -import fr.sandro642.github.enums.LangType; -import fr.sandro642.github.enums.MethodType; -import fr.sandro642.github.enums.ResourceType; -import fr.sandro642.github.enums.VersionType; -import fr.sandro642.github.provider.RouteImport; - -import java.util.Map; -import java.util.concurrent.CompletableFuture; -import java.util.concurrent.TimeUnit; - -/** - * ExampleUsages is a placeholder class that can be used to demonstrate how to use the ConnectLib library. - * It can contain example methods or code snippets that show how to interact with the API, handle responses, - * and utilize the features provided by the ConnectLib library. - * - * @author Sandro642 - * @version 1.0 - */ - -public class ExampleUsages { - - private ConnectLib connectLib = new ConnectLib(); - - public enum ExampleRoutes implements RouteImport { - EXAMPLE_ROUTE("/api/example/route"); - - final String route; - - ExampleRoutes(String route) { - this.route = route; - } - - @Override - public String getRoute() { - return route; - } - } - - public void initializeLib() { - - // Optionally, you can specify routes if needed - connectLib.init(ResourceType.MAIN_RESOURCES, LangType.FRENCH, ExampleRoutes.class); - // You can also initialize without specifying routes - connectLib.init(ResourceType.MAIN_RESOURCES, LangType.FRENCH); - } - - // Example method to demonstrate usage - public void exampleMethodSync() { - try { - // This method can be used to demonstrate how to interact with the API - // For example, making a GET request to the EXAMPLE_ROUTE - CompletableFuture apiFactoryCompletableFuture = connectLib.JobGetInfos() - .getRoutes(VersionType.V1_BRANCH, MethodType.GET, ExampleRoutes.EXAMPLE_ROUTE) - .getResponse(); - - ApiFactory response = apiFactoryCompletableFuture.get(5, TimeUnit.SECONDS); - - System.out.println(response.display()); - System.out.println("Response Code: " + response.getData("code")); - System.out.println("Response Message: " + response.getData("message")); - System.out.println("Response Data: " + response.getSpecData("data", "exampleKey")); - System.out.println("Status Code: " + response.getStatusCode()); - } catch (Exception e) { - e.printStackTrace(); - } - } - - // Example method to demonstrate asynchronous usage - public void exampleMethodAsync() { - try { - // This method can be used to demonstrate how to interact with the API asynchronously - - CompletableFuture apiFactoryCompletableFuture = connectLib.JobGetInfos() - .getRoutes(VersionType.V1_BRANCH, MethodType.GET, ExampleRoutes.EXAMPLE_ROUTE) - .getResponse(); - - ApiFactory response = apiFactoryCompletableFuture.get(5, TimeUnit.SECONDS); - - System.out.println(response.display()); - System.out.println("Response Code: " + response.getData("code")); - System.out.println("Response Message: " + response.getData("message")); - System.out.println("Response Data: " + response.getSpecData("data", "exampleKey")); - } catch (Exception e) { - e.printStackTrace(); - } - } - - // Example to use all methods in JobGetInfos - public void exampleJobGetInfos() { - Map body = Map.of(); - Map params = Map.of(); - Map query = Map.of(); - - connectLib.JobGetInfos().getRoutes(VersionType.V1_BRANCH, MethodType.GET, ExampleRoutes.EXAMPLE_ROUTE, body, params, query); - connectLib.JobGetInfos().getRoutes(VersionType.V1_BRANCH, MethodType.POST, ExampleRoutes.EXAMPLE_ROUTE, body); - connectLib.JobGetInfos().getRoutes(VersionType.V1_BRANCH, MethodType.PUT, ExampleRoutes.EXAMPLE_ROUTE, null, params, query); - connectLib.JobGetInfos().getRoutes(VersionType.V1_BRANCH, MethodType.PATCH, ExampleRoutes.EXAMPLE_ROUTE); - connectLib.JobGetInfos().getRoutes(MethodType.GET, ExampleRoutes.EXAMPLE_ROUTE, body, params); - connectLib.JobGetInfos().getRoutes(MethodType.POST, ExampleRoutes.EXAMPLE_ROUTE, body); - connectLib.JobGetInfos().getRoutes(MethodType.DELETE, ExampleRoutes.EXAMPLE_ROUTE); - } - -} diff --git a/src/main/java/fr/sandro642/github/jobs/JobGetInfos.java b/src/main/java/fr/sandro642/github/jobs/JobGetInfos.java index 0f04bf3..eea843b 100644 --- a/src/main/java/fr/sandro642/github/jobs/JobGetInfos.java +++ b/src/main/java/fr/sandro642/github/jobs/JobGetInfos.java @@ -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,29 +61,6 @@ 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 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) @@ -89,166 +68,84 @@ public JobGetInfos getRoutes(VersionProvider versionType, MethodType methodType, * @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 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 body, Map 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 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 body, Map params, Map 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 body, Map params, Map 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 JobGetInfos getRoutes(VersionProvider versionType, MethodType methodType, R routeName, Map body, Map params, Map query) { + public 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; } else { - fullRoute = route; + this.fullRoute = route; } - if (params != null && !params.isEmpty()) { - for (Map.Entry entry : params.entrySet()) { - String paramKey = "{" + entry.getKey() + "}"; - String paramValue = entry.getValue().toString(); - fullRoute = fullRoute.replace(paramKey, paramValue); - } - } + connectLib.StoreAndRetrieve().store.put("currentRoute", this.fullRoute); + connectLib.StoreAndRetrieve().store.put("currentMethod", methodType); - // New query string handling logic - if (query != null && !query.isEmpty()) { - // Pattern for capturing parameters between $ - Pattern pattern = Pattern.compile("\\$([^$]+)\\$"); - Matcher matcher = pattern.matcher(fullRoute); - - StringBuilder queryString = new StringBuilder("?"); - boolean firstParam = true; - - // Iterate through all matches (parameters between $) - while (matcher.find()) { - String paramName = matcher.group(1); // Get parameter name without $ - - // Check if this parameter exists in the query map - if (query.containsKey(paramName)) { - if (!firstParam) { - queryString.append("&"); - } - queryString.append(paramName).append("=").append(query.get(paramName)); - firstParam = false; - } - } + connectLib.Logger().INFO(connectLib.LangManager().getMessage(CategoriesType.JOBS_PACKAGE, "getroutes.maderoute", "route", fullRoute)); + } catch (Exception e) { + connectLib.Logger().ERROR(connectLib.LangManager().getMessage(CategoriesType.JOBS_PACKAGE, "getroutes.error", "exception", e.getMessage())); + } + return this; + } - // Append query string to the route only if parameters were added - if (queryString.length() > 1) { - // Clean the route by removing $parameter$ placeholders and extra & - String cleanRoute = fullRoute.replaceAll("\\$[^$]+\\$", "").replaceAll("&+", ""); - fullRoute = cleanRoute + queryString.toString(); - } - } + public JobGetInfos body(Map body) { + connectLib.StoreAndRetrieve().store.put("currentBody", body); + return this; + } - connectLib.StoreAndRetrieve().store.put("currentRoute", fullRoute); - connectLib.StoreAndRetrieve().store.put("currentMethod", methodType); + public JobGetInfos params(Map params) { + if (params == null || params.isEmpty()) return this; - if (body != null) { - connectLib.StoreAndRetrieve().store.put("currentBody", body); - } + for (Map.Entry entry : params.entrySet()) { + String paramKey = "{" + entry.getKey() + "}"; + String paramValue = entry.getValue() == null ? "" : entry.getValue().toString(); + this.fullRoute = this.fullRoute.replace(paramKey, paramValue); + } + + connectLib.StoreAndRetrieve().store.put("currentParams", params); + connectLib.StoreAndRetrieve().store.put("currentRoute", this.fullRoute); + return this; + } + + public JobGetInfos query(Map query) { + if (query == null || query.isEmpty()) return this; - if (params != null) { - connectLib.StoreAndRetrieve().store.put("currentParams", params); + Pattern pattern = Pattern.compile("\\$([^$]+)\\$"); + Matcher matcher = pattern.matcher(this.fullRoute); + + StringBuilder queryString = new StringBuilder("?"); + boolean firstParam = true; + + while (matcher.find()) { + String paramName = matcher.group(1); + if (query.containsKey(paramName)) { + if (!firstParam) { + queryString.append("&"); + } + Object value = query.get(paramName); + queryString.append(paramName).append("=").append(value == null ? "" : value.toString()); + firstParam = false; } + } - connectLib.Logger().INFO(connectLib.LangManager().getMessage(CategoriesType.JOBS_PACKAGE, "getroutes.maderoute", "route", fullRoute)); - } catch (Exception e) { - connectLib.Logger().ERROR(connectLib.LangManager().getMessage(CategoriesType.JOBS_PACKAGE, "getroutes.error", "exception", e.getMessage())); + if (queryString.length() > 1) { + String cleanRoute = this.fullRoute.replaceAll("\\$[^$]+\\$", "").replaceAll("&+", ""); + this.fullRoute = cleanRoute + queryString.toString(); } + + connectLib.StoreAndRetrieve().store.put("currentRoute", this.fullRoute); + connectLib.StoreAndRetrieve().store.put("currentQuery", query); return this; } diff --git a/src/test/java/fr/sandro642/github/test/MainTest.java b/src/test/java/fr/sandro642/github/test/MainTest.java index f284d4a..81aa843 100644 --- a/src/test/java/fr/sandro642/github/test/MainTest.java +++ b/src/test/java/fr/sandro642/github/test/MainTest.java @@ -28,7 +28,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; @@ -93,7 +94,7 @@ public static void main(String[] args) { connectLib.Logger().showLogs(); CompletableFuture apiFactoryCompletableFuture = connectLib.JobGetInfos() - .getRoutes(MethodType.GET, TestRoutes.HELLO) + .getRoutes(null, MethodType.GET, TestRoutes.HELLO) .getResponse(); ApiFactory response = apiFactoryCompletableFuture.get(5, TimeUnit.SECONDS); @@ -117,7 +118,9 @@ public void testUseFullRoute() { ); CompletableFuture factoryCompletableFuture = connectLib.JobGetInfos() - .getRoutes(MethodType.GET, TestRoutes.GREET, null, null, query) + .getRoutes(null, MethodType.GET, TestRoutes.GREET) + .urlBranch(ExampleUrlBranch.POST_PROD) + .query(query) .getResponse(); ApiFactory response = factoryCompletableFuture.get(5, TimeUnit.SECONDS); @@ -157,6 +160,14 @@ public void testLangType() { } } + private String code_session; + + @Test + public void testProd() { + testSpecData(); + + pushsession(); + } @Test public void testSpecData() { @@ -177,6 +188,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 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(); } @@ -190,7 +226,7 @@ public void startAppServices() { .webServices(8080, "TestDashboard"); CompletableFuture apiFactoryCompletableFuture = connectLib.JobGetInfos() - .getRoutes(MethodType.GET, TestRoutes.HELLO) + .getRoutes(null, MethodType.GET, TestRoutes.HELLO) .getResponse(); apiFactoryCompletableFuture = connectLib.JobGetInfos() @@ -209,5 +245,4 @@ public void startAppServices() { } } - } From e896dfc51548e2b0cec4b50eb49625c9bb4c8809 Mon Sep 17 00:00:00 2001 From: Sandro Date: Sat, 15 Nov 2025 12:35:09 +0100 Subject: [PATCH 5/9] Update version to 0.4.5-STABLE in build.gradle --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 4263845..076fca0 100644 --- a/build.gradle +++ b/build.gradle @@ -5,7 +5,7 @@ plugins { } group = 'fr.sandro642.github' -version = '0.4.4-DEV_BUILD' +version = '0.4.5-STABLE' // Générer une classe de version automatiquement task generateVersionClass { From d6635cada91370ea5d9eea6349e2089380395f7e Mon Sep 17 00:00:00 2001 From: Sandro Date: Sat, 15 Nov 2025 12:36:04 +0100 Subject: [PATCH 6/9] Remove feature/AtomicFactory branch from workflow configuration --- .github/workflows/work-jar.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/work-jar.yml b/.github/workflows/work-jar.yml index c2e888f..f6222b4 100644 --- a/.github/workflows/work-jar.yml +++ b/.github/workflows/work-jar.yml @@ -3,7 +3,6 @@ on: push: branches: - main - - feature/AtomicFactory permissions: contents: write pages: write From 9ba9962e662440a1b4997c7cd4e69a31618d2bef Mon Sep 17 00:00:00 2001 From: Sandro Date: Sat, 15 Nov 2025 12:39:57 +0100 Subject: [PATCH 7/9] Update version to 0.4.6-STABLE in build.gradle --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 076fca0..42e5508 100644 --- a/build.gradle +++ b/build.gradle @@ -5,7 +5,7 @@ plugins { } group = 'fr.sandro642.github' -version = '0.4.5-STABLE' +version = '0.4.6-STABLE' // Générer une classe de version automatiquement task generateVersionClass { From 764e022de3778a13bf7170c293b222b876525326 Mon Sep 17 00:00:00 2001 From: Sandro Date: Sat, 15 Nov 2025 13:08:57 +0100 Subject: [PATCH 8/9] Add default inspection profile and update test initialization in MainTest --- .idea/inspectionProfiles/Project_Default.xml | 8 ++++++++ src/test/java/fr/sandro642/github/test/MainTest.java | 6 +++--- 2 files changed, 11 insertions(+), 3 deletions(-) create mode 100644 .idea/inspectionProfiles/Project_Default.xml diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..6fea68f --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,8 @@ + + + + \ No newline at end of file diff --git a/src/test/java/fr/sandro642/github/test/MainTest.java b/src/test/java/fr/sandro642/github/test/MainTest.java index 6e26e3d..857d808 100644 --- a/src/test/java/fr/sandro642/github/test/MainTest.java +++ b/src/test/java/fr/sandro642/github/test/MainTest.java @@ -176,6 +176,8 @@ public void testLangType() { @Test public void testProd() { + connectLib.init(ResourceType.TEST_RESOURCES, LangType.ENGLISH, TestRoutes.class); + testSpecData(); pushsession(); @@ -185,8 +187,6 @@ public void testProd() { public void testSpecData() { try { - connectLib.init(ResourceType.MAIN_RESOURCES, LangType.ENGLISH, TestRoutes.class); - CompletableFuture apiFactoryCompletableFuture = connectLib.JobGetInfos() .getRoutes(TestCustomVersion.V1_API, MethodType.GET, TestRoutes.REQUEST_TOKEN) .urlBranch(ExampleUrlBranch.PROD) @@ -219,7 +219,7 @@ public void pushsession() { .getRoutes(TestCustomVersion.V1_API, MethodType.POST, TestRoutes.SESSION_PUSH) .urlBranch(ExampleUrlBranch.PROD) .params(params) - .getResponse(); + .execute(); ApiFactory apiFactory = apiFactoryCompletableFuture.get(5, TimeUnit.SECONDS); From f4df50349650d87e721cd699f4a68c86cb87aed3 Mon Sep 17 00:00:00 2001 From: Sandro Soria Date: Sun, 16 Nov 2025 12:15:54 +0100 Subject: [PATCH 9/9] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 74c71a4..a4a5dcc 100644 --- a/README.md +++ b/README.md @@ -109,7 +109,7 @@ Imagine an API that doesn't just connect services, but becomes the conductor of More examples HERE: [ExampleUsages.java](src/main/java/fr/sandro642/github/example/ExampleUsages.java) --- -[build.gradle](build.gradle) + ## Project Structure - `src/main/java/fr/sandro642/github/` : main source code