[ofbiz-plugins] branch trunk updated: Implemented: Added support for other HTTP methods for exportable services endpoints. 2. Added Messages class holding keys for the error and success messages. The keys will be referenced in UiLabels XMLs (OFBIZ-11995)

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: Implemented: Added support for other HTTP methods for exportable services endpoints. 2. Added Messages class holding keys for the error and success messages. The keys will be referenced in UiLabels XMLs (OFBIZ-11995)

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 5bcb7af  Implemented: Added support for other HTTP methods for exportable services endpoints. 2. Added Messages class holding keys for the error and success messages. The keys will be referenced in UiLabels XMLs (OFBIZ-11995)
5bcb7af is described below

commit 5bcb7af25acca71dd83147d3281469807cb239f6
Author: Girish Vasmatkar <[hidden email]>
AuthorDate: Thu Sep 17 15:32:33 2020 +0530

    Implemented: Added support for other HTTP methods for exportable services endpoints.
    2. Added Messages class holding keys for the error and success messages. The keys will be referenced in UiLabels XMLs (OFBIZ-11995)
---
 .../ws/rs/resources/OFBizServiceResource.java      | 73 +++++++++++++++++++++-
 .../org/apache/ofbiz/ws/rs/response/Messages.java  | 62 ++++++++++++++++++
 2 files changed, 133 insertions(+), 2 deletions(-)

diff --git a/ofbiz-rest-impl/src/main/java/org/apache/ofbiz/ws/rs/resources/OFBizServiceResource.java b/ofbiz-rest-impl/src/main/java/org/apache/ofbiz/ws/rs/resources/OFBizServiceResource.java
index b55b16f..9eb0a3b 100644
--- a/ofbiz-rest-impl/src/main/java/org/apache/ofbiz/ws/rs/resources/OFBizServiceResource.java
+++ b/ofbiz-rest-impl/src/main/java/org/apache/ofbiz/ws/rs/resources/OFBizServiceResource.java
@@ -28,9 +28,12 @@ import java.util.Set;
 
 import javax.servlet.http.HttpServletRequest;
 import javax.ws.rs.BadRequestException;
+import javax.ws.rs.DELETE;
 import javax.ws.rs.GET;
 import javax.ws.rs.HttpMethod;
+import javax.ws.rs.PATCH;
 import javax.ws.rs.POST;
+import javax.ws.rs.PUT;
 import javax.ws.rs.Path;
 import javax.ws.rs.PathParam;
 import javax.ws.rs.Produces;
@@ -104,7 +107,7 @@ public class OFBizServiceResource extends OFBizResource {
     @Path("/{serviceName}")
     @Produces(MediaType.APPLICATION_JSON)
     @Secured
-    public Response invokeServiceByGet(@QueryParam(value = "inParams") ApiServiceRequest serviceRequest,
+    public Response doGet(@QueryParam(value = "inParams") ApiServiceRequest serviceRequest,
                                        @PathParam(value = "serviceName") String serviceName) throws IOException, GenericServiceException {
         if (UtilValidate.isEmpty(serviceRequest) || UtilValidate.isEmpty(serviceRequest.getInParams())) {
             throw new BadRequestException("Missing Parameter: 'inParams'");
@@ -126,7 +129,7 @@ public class OFBizServiceResource extends OFBizResource {
     @POST
     @Path("/{serviceName}")
     @Produces(MediaType.APPLICATION_JSON)
-    public Response invokeServiceByPost(HashMap<String, Object> serviceInParams, @PathParam(value = "serviceName") String serviceName)
+    public Response doPost(HashMap<String, Object> serviceInParams, @PathParam(value = "serviceName") String serviceName)
             throws IOException, GenericEntityException, GenericServiceException {
         if (UtilValidate.isEmpty(serviceInParams)) {
             throw new BadRequestException("The request body is missing.");
@@ -136,4 +139,70 @@ public class OFBizServiceResource extends OFBizResource {
                 UtilMisc.toMap("serviceName", serviceName, "httpVerb", HttpMethod.POST, "requestMap", serviceInParams, "dispatcher", getDispatcher(),
                         "request", httpRequest));
     }
+
+    /**
+     * @param serviceInParams
+     * @param serviceName
+     * @return
+     * @throws IOException
+     * @throws GenericEntityException
+     * @throws GenericServiceException
+     */
+    @PUT
+    @Path("/{serviceName}")
+    @Produces(MediaType.APPLICATION_JSON)
+    public Response doPut(HashMap<String, Object> serviceInParams, @PathParam(value = "serviceName") String serviceName)
+            throws IOException, GenericEntityException, GenericServiceException {
+        if (UtilValidate.isEmpty(serviceInParams)) {
+            throw new BadRequestException("The request body is missing.");
+        }
+        ServiceRequestProcessor processor = new ServiceRequestProcessor();
+        return processor.process(
+                UtilMisc.toMap("serviceName", serviceName, "httpVerb", HttpMethod.PUT, "requestMap", serviceInParams, "dispatcher", getDispatcher(),
+                        "request", httpRequest));
+    }
+
+    /**
+     * @param serviceInParams
+     * @param serviceName
+     * @return
+     * @throws IOException
+     * @throws GenericEntityException
+     * @throws GenericServiceException
+     */
+    @PATCH
+    @Path("/{serviceName}")
+    @Produces(MediaType.APPLICATION_JSON)
+    public Response doPatch(HashMap<String, Object> serviceInParams, @PathParam(value = "serviceName") String serviceName)
+            throws IOException, GenericEntityException, GenericServiceException {
+        if (UtilValidate.isEmpty(serviceInParams)) {
+            throw new BadRequestException("The request body is missing.");
+        }
+        ServiceRequestProcessor processor = new ServiceRequestProcessor();
+        return processor.process(
+                UtilMisc.toMap("serviceName", serviceName, "httpVerb", HttpMethod.PATCH, "requestMap", serviceInParams, "dispatcher", getDispatcher(),
+                        "request", httpRequest));
+    }
+
+    /**
+     * @param serviceInParams
+     * @param serviceName
+     * @return
+     * @throws IOException
+     * @throws GenericEntityException
+     * @throws GenericServiceException
+     */
+    @DELETE
+    @Path("/{serviceName}")
+    @Produces(MediaType.APPLICATION_JSON)
+    public Response doDelete(HashMap<String, Object> serviceInParams, @PathParam(value = "serviceName") String serviceName)
+            throws IOException, GenericEntityException, GenericServiceException {
+        if (UtilValidate.isEmpty(serviceInParams)) {
+            throw new BadRequestException("The request body is missing.");
+        }
+        ServiceRequestProcessor processor = new ServiceRequestProcessor();
+        return processor.process(
+                UtilMisc.toMap("serviceName", serviceName, "httpVerb", HttpMethod.DELETE, "requestMap", serviceInParams, "dispatcher", getDispatcher(),
+                        "request", httpRequest));
+    }
 }
diff --git a/ofbiz-rest-impl/src/main/java/org/apache/ofbiz/ws/rs/response/Messages.java b/ofbiz-rest-impl/src/main/java/org/apache/ofbiz/ws/rs/response/Messages.java
new file mode 100644
index 0000000..dd607ce
--- /dev/null
+++ b/ofbiz-rest-impl/src/main/java/org/apache/ofbiz/ws/rs/response/Messages.java
@@ -0,0 +1,62 @@
+/*******************************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *******************************************************************************/
+package org.apache.ofbiz.ws.rs.response;
+
+public class Messages {
+
+    private String successMsgKey;
+    private String errorMsgKey;
+
+    public Messages(String successMessageVal, String errorMessageVal) {
+        successMsgKey = successMessageVal;
+        errorMsgKey = errorMessageVal;
+    }
+
+    /**
+     * @param successKey
+     * @return
+     */
+    public Messages successKey(String successKey) {
+        successMsgKey = successKey;
+        return this;
+    }
+
+    /**
+     * @param errorKey
+     * @return
+     */
+    public Messages errorKey(String errorKey) {
+        errorMsgKey = errorKey;
+        return this;
+    }
+
+    /**
+     * @return the successMsgKey
+     */
+    public String getSuccessMsgKey() {
+        return successMsgKey;
+    }
+
+    /**
+     * @return the errorMsgKey
+     */
+    public String getErrorMsgKey() {
+        return errorMsgKey;
+    }
+}