Skip to content

Conversation

@Sandro642
Copy link
Collaborator

…ssion push and improve query parameter processing

…ssion push and improve query parameter processing
@Sandro642 Sandro642 merged commit 758195e into main Nov 15, 2025
@Sandro642 Sandro642 deleted the feature/easy-rts branch November 15, 2025 11:40
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR refactors the JobGetInfos class to streamline route handling by introducing a fluent API pattern with separate methods for body, params, and query parameters. It also adds support for session push functionality through a new route and improves query parameter processing.

  • Simplified getRoutes() method overloads from ~15 methods to 2, replacing them with a fluent API using chained body(), params(), and query() methods
  • Added SESSION_PUSH route for authentication flow and corresponding test methods
  • Removed ExampleUsages.java file containing example code

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 9 comments.

File Description
src/main/java/fr/sandro642/github/jobs/JobGetInfos.java Refactored to use fluent API with instance variable fullRoute and separate methods for body, params, and query; removed multiple overloaded getRoutes() methods
src/test/java/fr/sandro642/github/test/MainTest.java Added SESSION_PUSH route, new test methods (testProd, pushsession), and updated existing test calls to use new API pattern
src/main/java/fr/sandro642/github/example/ExampleUsages.java Deleted example usage file
Comments suppressed due to low confidence (3)

src/test/java/fr/sandro642/github/test/MainTest.java:199

  • Method name pushsession() does not follow Java naming conventions for multi-word identifiers. It should be in camelCase (e.g., pushSession() or testPushSession() to match the test naming pattern).
            System.out.println("Data: " + apiFactory.getData("data"));

src/test/java/fr/sandro642/github/test/MainTest.java:163

  • Variable name code_session does not follow Java naming conventions. It should be in camelCase (e.g., codeSession or sessionCode) instead of snake_case.
                    .execute();

src/test/java/fr/sandro642/github/test/MainTest.java:170

  • The test testProd() directly calls other test methods (testSpecData() and pushsession()), creating test dependencies. This violates test independence principles - tests should be atomic and executable in any order. Consider using a test suite, @beforeeach setup, or refactoring shared logic into helper methods instead.
            ApiFactory response = factoryCompletableFuture.get(5, TimeUnit.SECONDS);

            System.out.println("Response: " + response.display());
            System.out.println("Status Code: " + response.getStatusCode());

        } catch (Exception e) {

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +107 to +119
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;
}
Copy link

Copilot AI Nov 15, 2025

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 uses AI. Check for mistakes.
queryString.append("&");
}
Object value = query.get(paramName);
queryString.append(paramName).append("=").append(value == null ? "" : value.toString());
Copy link

Copilot AI Nov 15, 2025

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 uses AI. Check for mistakes.
Comment on lines +107 to +119
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;
}
Copy link

Copilot AI Nov 15, 2025

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 uses AI. Check for mistakes.
*/
private URLProvider urlBranch;

private String fullRoute = "";
Copy link

Copilot AI Nov 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The instance variable fullRoute introduces thread safety issues. Multiple threads could concurrently call getRoutes(), params(), or query() on the same JobGetInfos instance, leading to race conditions where threads overwrite each other's route values. Consider making fullRoute a local variable passed between methods or using ThreadLocal storage.

Suggested change
private String fullRoute = "";
// Removed fullRoute instance variable for thread safety.

Copilot uses AI. Check for mistakes.
Comment on lines +121 to 150
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;
}
Copy link

Copilot AI Nov 15, 2025

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 uses AI. Check for mistakes.

System.out.println(apiFactory.getSpecData("data", "accessToken"));

this.code_session = (String) apiFactory.getSpecData("data", "sessionCode");
Copy link

Copilot AI Nov 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Potential NullPointerException: this.code_session could be null if testSpecData() hasn't been executed first or if the API response doesn't contain the expected data. Add null checking before using this variable, especially since test execution order isn't guaranteed.

Copilot uses AI. Check for mistakes.
Comment on lines +121 to 150
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;
}
Copy link

Copilot AI Nov 15, 2025

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.

Copilot uses AI. Check for mistakes.

if (versionType != null && versionType.getVersion() != null) {
String cleanRoute = route.startsWith("/") ? route.substring(1) : route;
fullRoute = "/" + versionType.getVersion() + "/" + cleanRoute;
Copy link

Copilot AI Nov 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Inconsistent use of this keyword: line 87 assigns to fullRoute without this, while line 89 uses this.fullRoute. For better code consistency and readability, use this.fullRoute in both places.

Suggested change
fullRoute = "/" + versionType.getVersion() + "/" + cleanRoute;
this.fullRoute = "/" + versionType.getVersion() + "/" + cleanRoute;

Copilot uses AI. Check for mistakes.
Comment on lines +102 to +105
public JobGetInfos body(Map<?, ?> body) {
connectLib.StoreAndRetrieve().store.put("currentBody", body);
return this;
}
Copy link

Copilot AI Nov 15, 2025

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 uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants