You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by gr...@apache.org on 2020/09/15 08:05:59 UTC

[ofbiz-plugins] branch trunk updated: Model classes added corresponding to REST XMl schema (#42)

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 290f0b8  Model classes added corresponding to REST XMl schema (#42)
290f0b8 is described below

commit 290f0b8af93d28d88f4e687763d122d40ac2df10
Author: girishvasmatkar <47...@users.noreply.github.com>
AuthorDate: Tue Sep 15 13:35:50 2020 +0530

    Model classes added corresponding to REST XMl schema (#42)
---
 .../org/apache/ofbiz/ws/rs/model/ModelApi.java     | 113 +++++++++++
 .../apache/ofbiz/ws/rs/model/ModelApiReader.java   |  77 ++++++++
 .../apache/ofbiz/ws/rs/model/ModelOperation.java   | 214 +++++++++++++++++++++
 .../apache/ofbiz/ws/rs/model/ModelResource.java    | 177 +++++++++++++++++
 4 files changed, 581 insertions(+)

diff --git a/ofbiz-rest-impl/src/main/java/org/apache/ofbiz/ws/rs/model/ModelApi.java b/ofbiz-rest-impl/src/main/java/org/apache/ofbiz/ws/rs/model/ModelApi.java
new file mode 100644
index 0000000..2381e5a
--- /dev/null
+++ b/ofbiz-rest-impl/src/main/java/org/apache/ofbiz/ws/rs/model/ModelApi.java
@@ -0,0 +1,113 @@
+/*******************************************************************************
+ * 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.model;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class ModelApi {
+
+    private List<ModelResource> resources;
+    private String name;
+    private String displayName;
+    private String description;
+
+    /**
+     * @return
+     */
+    public List<ModelResource> getResources() {
+        if (resources == null) {
+            resources = new ArrayList<ModelResource>();
+        }
+        return this.resources;
+    }
+
+    /**
+     * @param resource
+     * @return
+     */
+    public ModelApi addResource(ModelResource resource) {
+        if (this.resources == null) {
+            this.resources = new ArrayList<>();
+        }
+        this.resources.add(resource);
+        return this;
+    }
+
+    /**
+     * Gets the value of the name property.
+     *
+     * @return possible object is {@link String }
+     *
+     */
+    public String getName() {
+        return name;
+    }
+
+    /**
+     * Sets the value of the name property.
+     *
+     * @param value allowed object is {@link String }
+     *
+     */
+    public void setName(String value) {
+        this.name = value;
+    }
+
+    /**
+     * Gets the value of the displayName property.
+     *
+     * @return possible object is {@link String }
+     *
+     */
+    public String getDisplayName() {
+        return displayName;
+    }
+
+    /**
+     * Sets the value of the displayName property.
+     *
+     * @param value allowed object is {@link String }
+     *
+     */
+    public void setDisplayName(String value) {
+        this.displayName = value;
+    }
+
+    /**
+     * Gets the value of the description property.
+     *
+     * @return possible object is {@link String }
+     *
+     */
+    public String getDescription() {
+        return description;
+    }
+
+    /**
+     * Sets the value of the description property.
+     *
+     * @param value allowed object is {@link String }
+     *
+     */
+    public void setDescription(String value) {
+        this.description = value;
+    }
+
+}
diff --git a/ofbiz-rest-impl/src/main/java/org/apache/ofbiz/ws/rs/model/ModelApiReader.java b/ofbiz-rest-impl/src/main/java/org/apache/ofbiz/ws/rs/model/ModelApiReader.java
new file mode 100644
index 0000000..208e3af
--- /dev/null
+++ b/ofbiz-rest-impl/src/main/java/org/apache/ofbiz/ws/rs/model/ModelApiReader.java
@@ -0,0 +1,77 @@
+/*******************************************************************************
+ * 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.model;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+
+import javax.xml.parsers.ParserConfigurationException;
+
+import org.apache.ofbiz.base.util.Debug;
+import org.apache.ofbiz.base.util.UtilXml;
+import org.w3c.dom.Element;
+import org.xml.sax.SAXException;
+
+public final class ModelApiReader {
+    private static final String MODULE = ModelApiReader.class.getName();
+
+    private ModelApiReader() {
+
+    }
+    public static ModelApi getModelApi(final File apiDef) {
+        Element docElement;
+        try {
+            docElement = UtilXml.readXmlDocument(new FileInputStream(apiDef), true, "REST API file", true)
+                    .getDocumentElement();
+        } catch (SAXException | ParserConfigurationException | IOException e) {
+            e.printStackTrace();
+            return null;
+        }
+        docElement.normalize();
+        ModelApi api = new ModelApi();
+        for (Element resourceEle : UtilXml.childElementList(docElement, "resource")) {
+            ModelResource resource = new ModelResource()
+                    .name(UtilXml.checkEmpty(resourceEle.getAttribute("name")).intern())
+                    .description(UtilXml.checkEmpty(resourceEle.getAttribute("description")).intern())
+                    .displayName(UtilXml.checkEmpty(resourceEle.getAttribute("displayName")).intern())
+                    .path(UtilXml.checkEmpty(resourceEle.getAttribute("path")).intern())
+                    .enabled(Boolean.parseBoolean(UtilXml.checkEmpty(resourceEle.getAttribute("name")).intern()));
+            createOperations(resourceEle, resource);
+            Debug.logInfo(resource.toString(), MODULE);
+            api.addResource(resource);
+        }
+        return api;
+    }
+
+    private static void createOperations(Element resourceEle, ModelResource resource) {
+        for (Element operationEle : UtilXml.childElementList(resourceEle, "operation")) {
+            Element serviceEle = UtilXml.firstChildElement(operationEle, "service");
+            String serviceName = UtilXml.checkEmpty(serviceEle.getAttribute("name")).intern();
+            ModelOperation op = new ModelOperation()
+                    .path(UtilXml.checkEmpty(operationEle.getAttribute("path")).intern())
+                    .verb(UtilXml.checkEmpty(operationEle.getAttribute("verb")).intern()).service(serviceName)
+                    .produces(UtilXml.checkEmpty(operationEle.getAttribute("produces")).intern())
+                    .consumes(UtilXml.checkEmpty(operationEle.getAttribute("consumes")).intern())
+                    .description(UtilXml.checkEmpty(operationEle.getAttribute("description")).intern());
+            resource.addOperation(op);
+        }
+    }
+
+}
diff --git a/ofbiz-rest-impl/src/main/java/org/apache/ofbiz/ws/rs/model/ModelOperation.java b/ofbiz-rest-impl/src/main/java/org/apache/ofbiz/ws/rs/model/ModelOperation.java
new file mode 100644
index 0000000..88cf914
--- /dev/null
+++ b/ofbiz-rest-impl/src/main/java/org/apache/ofbiz/ws/rs/model/ModelOperation.java
@@ -0,0 +1,214 @@
+/*******************************************************************************
+ * 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.model;
+
+public class ModelOperation {
+
+    private String service;
+    private String verb;
+    private String produces;
+    private String consumes;
+    private String path;
+    private String description;
+
+    /**
+     * Gets the value of the service property.
+     *
+     * @return possible object is {@link Service }
+     *
+     */
+    public String getService() {
+        return service;
+    }
+
+    /**
+     * Sets the value of the service property.
+     *
+     * @param value allowed object is {@link Service }
+     *
+     */
+    public void setService(String value) {
+        this.service = value;
+    }
+
+    /**
+     * @param value
+     * @return
+     */
+    public ModelOperation service(String value) {
+        this.service = value;
+        return this;
+    }
+
+    /**
+     * Gets the value of the verb property.
+     *
+     * @return possible object is {@link String }
+     *
+     */
+    public String getVerb() {
+        return verb;
+    }
+
+    /**
+     * Sets the value of the verb property.
+     *
+     * @param value allowed object is {@link String }
+     *
+     */
+    public void setVerb(String value) {
+        this.verb = value;
+    }
+
+    /**
+     * @param value
+     * @return
+     */
+    public ModelOperation verb(String value) {
+        this.verb = value;
+        return this;
+    }
+
+    /**
+     * Gets the value of the produces property.
+     *
+     * @return possible object is {@link String }
+     *
+     */
+    public String getProduces() {
+        return produces;
+    }
+
+    /**
+     * Sets the value of the produces property.
+     *
+     * @param value allowed object is {@link String }
+     *
+     */
+    public void setProduces(String value) {
+        this.produces = value;
+    }
+
+    /**
+     * @param value
+     * @return
+     */
+    public ModelOperation produces(String value) {
+        this.produces = value;
+        return this;
+    }
+
+    /**
+     * Gets the value of the consumes property.
+     *
+     * @return possible object is {@link String }
+     *
+     */
+    public String getConsumes() {
+        return consumes;
+    }
+
+    /**
+     * Sets the value of the consumes property.
+     *
+     * @param value allowed object is {@link String }
+     *
+     */
+    public void setConsumes(String value) {
+        this.consumes = value;
+    }
+
+    /**
+     * @param value
+     * @return
+     */
+    public ModelOperation consumes(String value) {
+        this.consumes = value;
+        return this;
+    }
+
+    /**
+     * Gets the value of the path property.
+     *
+     * @return possible object is {@link String }
+     *
+     */
+    public String getPath() {
+        return path;
+    }
+
+    /**
+     * Sets the value of the path property.
+     *
+     * @param value allowed object is {@link String }
+     *
+     */
+    public void setPath(String value) {
+        this.path = value;
+    }
+
+    /**
+     * @param value
+     * @return
+     */
+    public ModelOperation path(String value) {
+        this.path = value;
+        return this;
+    }
+
+    /**
+     * Gets the value of the description property.
+     *
+     * @return possible object is {@link String }
+     *
+     */
+    public String getDescription() {
+        return description;
+    }
+
+    /**
+     * Sets the value of the description property.
+     *
+     * @param value allowed object is {@link String }
+     *
+     */
+    public void setDescription(String value) {
+        this.description = value;
+    }
+
+    /**
+     * @param value
+     * @return
+     */
+    public ModelOperation description(String value) {
+        this.description = value;
+        return this;
+    }
+
+    /**
+     * @return
+     */
+    @Override
+    public String toString() {
+        // TODO Auto-generated method stub
+        return "service: " + service + ", path: " + path + ", verb: " + verb + ", description: " + description
+                + ", produces: " + produces;
+    }
+
+}
diff --git a/ofbiz-rest-impl/src/main/java/org/apache/ofbiz/ws/rs/model/ModelResource.java b/ofbiz-rest-impl/src/main/java/org/apache/ofbiz/ws/rs/model/ModelResource.java
new file mode 100644
index 0000000..0103f6f
--- /dev/null
+++ b/ofbiz-rest-impl/src/main/java/org/apache/ofbiz/ws/rs/model/ModelResource.java
@@ -0,0 +1,177 @@
+/*******************************************************************************
+ * 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.model;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class ModelResource {
+
+    private List<ModelOperation> operations;
+    private String name;
+    private String path;
+    private String displayName;
+    private String description;
+    private boolean enabled;
+
+    /**
+     * @return the operation
+     */
+    public List<ModelOperation> getOperations() {
+        return operations == null ? new ArrayList<ModelOperation>() : operations;
+    }
+
+    /**
+     * @param operation
+     * @return
+     */
+    public ModelResource addOperation(ModelOperation operation) {
+        if (this.operations == null) {
+            this.operations = new ArrayList<>();
+        }
+        this.operations.add(operation);
+        return this;
+    }
+
+    /**
+     * @return the name
+     */
+    public String getName() {
+        return name;
+    }
+
+    /**
+     * @param name the name to set
+     */
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    /**
+     * @param name
+     * @return
+     */
+    public ModelResource name(String name) {
+        this.name = name;
+        return this;
+    }
+
+    /**
+     * @param path
+     * @return
+     */
+    public ModelResource path(String path) {
+        this.path = path;
+        return this;
+    }
+
+    /**
+     * @return the path
+     */
+    public String getPath() {
+        return path;
+    }
+
+    /**
+     * @param path the path to set
+     */
+    public void setPath(String path) {
+        this.path = path;
+    }
+
+    /**
+     * @return the displayName
+     */
+    public String getDisplayName() {
+        return displayName;
+    }
+
+    /**
+     * @param displayName
+     * @return
+     */
+    public ModelResource displayName(String displayName) {
+        this.displayName = displayName;
+        return this;
+    }
+
+    /**
+     * @param displayName the displayName to set
+     */
+    public void setDisplayName(String displayName) {
+        this.displayName = displayName;
+    }
+
+    /**
+     * @return the description
+     */
+    public String getDescription() {
+        return description;
+    }
+
+    /**
+     * @param description the description to set
+     */
+    public void setDescription(String description) {
+        this.description = description;
+    }
+
+    /**
+     * @param description
+     * @return
+     */
+    public ModelResource description(String description) {
+        this.description = description;
+        return this;
+    }
+
+    /**
+     * @return the enabled
+     */
+    public Boolean getEnabled() {
+        return enabled;
+    }
+
+    /**
+     * @param enabled the enabled to set
+     */
+    public void setEnabled(Boolean enabled) {
+        this.enabled = enabled;
+    }
+
+    /**
+     * @param enabled
+     * @return
+     */
+    public ModelResource enabled(boolean enabled) {
+        this.enabled = enabled;
+        return this;
+    }
+
+    /**
+     * @return
+     */
+    @Override
+    public String toString() {
+        // TODO Auto-generated method stub
+        return "name: " + name + ", path: " + path + ", displayName: " + displayName + ", description: " + description
+                + ", enabled: " + enabled;
+    }
+
+}