99import java .util .Map ;
1010import java .util .concurrent .CompletableFuture ;
1111import java .util .function .Consumer ;
12+ import java .util .regex .Matcher ;
13+ import java .util .regex .Pattern ;
1214
1315/**
1416 * JobGetInfos is a utility class for managing API requests in the ConnectLib library.
@@ -54,7 +56,7 @@ private String getRouteName(Enum<?> routeName) {
5456 * @return JobGetInfos for chaining
5557 */
5658 public JobGetInfos getRoutes (VersionType versionType , MethodType methodType , Enum <?> routeName , Map <String , ?> body ) {
57- return getRoutes (versionType , methodType , getRouteName (routeName ), body , null );
59+ return getRoutes (versionType , methodType , getRouteName (routeName ), body , null , null );
5860 }
5961
6062 /**
@@ -65,7 +67,7 @@ public JobGetInfos getRoutes(VersionType versionType, MethodType methodType, Enu
6567 * @return JobGetInfos for chaining
6668 */
6769 public JobGetInfos getRoutes (VersionType versionType , MethodType methodType , Enum <?> routeName ) {
68- return getRoutes (versionType , methodType , getRouteName (routeName ), null , null );
70+ return getRoutes (versionType , methodType , getRouteName (routeName ), null , null , null );
6971 }
7072
7173 /**
@@ -75,7 +77,7 @@ public JobGetInfos getRoutes(VersionType versionType, MethodType methodType, Enu
7577 * @return JobGetInfos for chaining
7678 */
7779 public JobGetInfos getRoutes (MethodType methodType , Enum <?> routeName ) {
78- return getRoutes (null , methodType , getRouteName (routeName ), null , null );
80+ return getRoutes (null , methodType , getRouteName (routeName ), null , null , null );
7981 }
8082
8183 /**
@@ -86,7 +88,7 @@ public JobGetInfos getRoutes(MethodType methodType, Enum<?> routeName) {
8688 * @return JobGetInfos for chaining
8789 */
8890 public JobGetInfos getRoutes (MethodType methodType , Enum <?> routeName , Map <String , ?> body ) {
89- return getRoutes (null , methodType , getRouteName (routeName ), body , null );
91+ return getRoutes (null , methodType , getRouteName (routeName ), body , null , null );
9092 }
9193
9294 /**
@@ -97,7 +99,7 @@ public JobGetInfos getRoutes(MethodType methodType, Enum<?> routeName, Map<Strin
9799 * @return JobGetInfos for chaining
98100 */
99101 public JobGetInfos getRoutes (MethodType methodType , Enum <?> routeName , Map <String , ?> body , Map <String , ?> params ) {
100- return getRoutes (null , methodType , getRouteName (routeName ), body , params );
102+ return getRoutes (null , methodType , getRouteName (routeName ), body , params , null );
101103 }
102104
103105 /**
@@ -107,7 +109,7 @@ public JobGetInfos getRoutes(MethodType methodType, Enum<?> routeName, Map<Strin
107109 * @return JobGetInfos for chaining
108110 */
109111 public JobGetInfos getRoutes (MethodType methodType , String routeName ) {
110- return getRoutes (null , methodType , routeName , null , null );
112+ return getRoutes (null , methodType , routeName , null , null , null );
111113 }
112114
113115 /**
@@ -118,7 +120,7 @@ public JobGetInfos getRoutes(MethodType methodType, String routeName) {
118120 * @return JobGetInfos pour chaînage
119121 */
120122 public JobGetInfos getRoutes (VersionType versionType , MethodType methodType , String routeName ) {
121- return getRoutes (versionType , methodType , routeName , null , null );
123+ return getRoutes (versionType , methodType , routeName , null , null , null );
122124 }
123125
124126 /**
@@ -130,7 +132,33 @@ public JobGetInfos getRoutes(VersionType versionType, MethodType methodType, Str
130132 * @return JobGetInfos for chaining
131133 */
132134 public JobGetInfos getRoutes (VersionType versionType , MethodType methodType , String routeName , Map <String , ?> body ) {
133- return getRoutes (versionType , methodType , routeName , body , null );
135+ return getRoutes (versionType , methodType , routeName , body , null , null );
136+ }
137+
138+ /**
139+ * Get routes from the YAML file and builds the full URL with a request body and parameters.
140+ * @param methodType Type of HTTP method (GET, POST)
141+ * @param routeName Name of the route in the YAML file
142+ * @param body Body of the request for POST (can be null for GET)
143+ * @param params Additional parameters for the request
144+ * @param query Additional query parameters for the request
145+ * @return JobGetInfos for chaining
146+ */
147+ public JobGetInfos getRoutes (MethodType methodType , String routeName , Map <String , ?> body , Map <String , ?> params , Map <String , ?> query ) {
148+ return getRoutes (null , methodType , routeName , body , params , query );
149+ }
150+
151+ /**
152+ * Get routes from the YAML file and builds the full URL with additional parameters.
153+ * @param methodType Type of HTTP method (GET, POST)
154+ * @param routeName Name of the route in the YAML file
155+ * @param body Body of the request for POST (can be null for GET)
156+ * @param params Additional parameters for the request
157+ * @param query Additional query parameters for the request
158+ * @return JobGetInfos for chaining
159+ */
160+ public JobGetInfos getRoutes (MethodType methodType , Enum <?> routeName , Map <String , ?> body , Map <String , ?> params , Map <String , ?> query ) {
161+ return getRoutes (null , methodType , getRouteName (routeName ), body , params , query );
134162 }
135163
136164 /**
@@ -139,9 +167,10 @@ public JobGetInfos getRoutes(VersionType versionType, MethodType methodType, Str
139167 * @param methodType Type of HTTP method (GET, POST)
140168 * @param routeName Name of the route in the YAML file
141169 * @param params Additional parameters for the request
170+ * @param query Additional query parameters for the request
142171 * @return JobGetInfos for chaining
143172 */
144- public <R > JobGetInfos getRoutes (VersionType versionType , MethodType methodType , R routeName , Map <String , ?> body , Map <String , ?> params ) {
173+ public <R > JobGetInfos getRoutes (VersionType versionType , MethodType methodType , R routeName , Map <String , ?> body , Map <String , ?> params , Map < String , ?> query ) {
145174 try {
146175 String route = ConnectLib .getRoute (routeName .toString ().toLowerCase ());
147176
@@ -157,11 +186,41 @@ public <R> JobGetInfos getRoutes(VersionType versionType, MethodType methodType,
157186 for (Map .Entry <String , ?> entry : params .entrySet ()) {
158187 String paramKey = "{" + entry .getKey () + "}" ;
159188 String paramValue = entry .getValue ().toString ();
160-
161189 fullRoute = fullRoute .replace (paramKey , paramValue );
162190 }
163191 }
164192
193+ // New query string handling logic
194+ if (query != null && !query .isEmpty ()) {
195+ // Pattern for capturing parameters between $
196+ Pattern pattern = Pattern .compile ("\\ $([^$]+)\\ $" );
197+ Matcher matcher = pattern .matcher (fullRoute );
198+
199+ StringBuilder queryString = new StringBuilder ("?" );
200+ boolean firstParam = true ;
201+
202+ // Iterate through all matches (parameters between $)
203+ while (matcher .find ()) {
204+ String paramName = matcher .group (1 ); // Get parameter name without $
205+
206+ // Check if this parameter exists in the query map
207+ if (query .containsKey (paramName )) {
208+ if (!firstParam ) {
209+ queryString .append ("&" );
210+ }
211+ queryString .append (paramName ).append ("=" ).append (query .get (paramName ));
212+ firstParam = false ;
213+ }
214+ }
215+
216+ // Append query string to the route only if parameters were added
217+ if (queryString .length () > 1 ) {
218+ // Clean the route by removing $parameter$ placeholders and extra &
219+ String cleanRoute = fullRoute .replaceAll ("\\ $[^$]+\\ $" , "" ).replaceAll ("&+" , "" );
220+ fullRoute = cleanRoute + queryString .toString ();
221+ }
222+ }
223+
165224 ConnectLib .StoreAndRetrieve ().store .put ("currentRoute" , fullRoute );
166225 ConnectLib .StoreAndRetrieve ().store .put ("currentMethod" , methodType );
167226
0 commit comments