[ofbiz-plugins] branch trunk updated: Improved: Added a method to extract path parameters from paths declared in REST DSL.(OFBIZ-11328)

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[ofbiz-plugins] branch trunk updated: Improved: Added a method to extract path parameters from paths declared in REST DSL.(OFBIZ-11328)

grv-2
This is an automated email from the ASF dual-hosted git repository.

grv pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/ofbiz-plugins.git


The following commit(s) were added to refs/heads/trunk by this push:
     new c4c2a28  Improved: Added a method to extract path parameters from paths declared in REST DSL.(OFBIZ-11328)
c4c2a28 is described below

commit c4c2a28741e541dfc436aab465db258eac5ab735
Author: Girish Vasmatkar <[hidden email]>
AuthorDate: Mon Oct 5 09:58:47 2020 +0530

    Improved: Added a method to extract path parameters from paths declared in REST DSL.(OFBIZ-11328)
---
 .../org/apache/ofbiz/ws/rs/util/RestApiUtil.java    | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/ofbiz-rest-impl/src/main/java/org/apache/ofbiz/ws/rs/util/RestApiUtil.java b/ofbiz-rest-impl/src/main/java/org/apache/ofbiz/ws/rs/util/RestApiUtil.java
index 2cbde9d..3cce43c 100644
--- a/ofbiz-rest-impl/src/main/java/org/apache/ofbiz/ws/rs/util/RestApiUtil.java
+++ b/ofbiz-rest-impl/src/main/java/org/apache/ofbiz/ws/rs/util/RestApiUtil.java
@@ -18,7 +18,9 @@
  *******************************************************************************/
 package org.apache.ofbiz.ws.rs.util;
 
+import java.util.ArrayList;
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 
 import javax.ws.rs.core.MediaType;
@@ -68,4 +70,23 @@ public final class RestApiUtil {
         });
         return result;
     }
+
+    /**
+     * Extracts path parameters from resource pathInfo
+     * @param pathInfo
+     * @return
+     */
+    public static List<String> getPathParameters(String pathInfo) {
+        List<String> pathParams = new ArrayList<>();
+        if (pathInfo == null) {
+            return pathParams;
+        }
+        String[] pathParts = pathInfo.split("/");
+        for (String pathSegement : pathParts) {
+            if (pathSegement.startsWith("{") && pathSegement.endsWith("}")) {
+                pathParams.add(pathSegement);
+            }
+        }
+        return pathParams;
+    }
 }