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 583d0a6 Implemented: Addes a new 'publish' attribute to API element allowing a specific API to be disabled from publishing(OFBIZ-11328) 583d0a6 is described below commit 583d0a64ee19b5c975ffaae22c23f37c81913b2b Author: Girish Vasmatkar <[hidden email]> AuthorDate: Tue Oct 13 08:36:34 2020 +0530 Implemented: Addes a new 'publish' attribute to API element allowing a specific API to be disabled from publishing(OFBIZ-11328) --- ofbiz-rest-impl/dtd/rest-api.xsd | 1 + .../apache/ofbiz/ws/rs/core/OFBizApiConfig.java | 4 ++++ .../org/apache/ofbiz/ws/rs/model/ModelApi.java | 15 ++++++++++++ .../apache/ofbiz/ws/rs/model/ModelApiReader.java | 27 ++++++++++++++-------- .../ofbiz/ws/rs/openapi/OFBizOpenApiReader.java | 3 +++ 5 files changed, 40 insertions(+), 10 deletions(-) diff --git a/ofbiz-rest-impl/dtd/rest-api.xsd b/ofbiz-rest-impl/dtd/rest-api.xsd index 972dfcf..2b7f4a2 100644 --- a/ofbiz-rest-impl/dtd/rest-api.xsd +++ b/ofbiz-rest-impl/dtd/rest-api.xsd @@ -27,6 +27,7 @@ under the License. <xs:attribute name="name" type="xs:string" use="required"/> <xs:attribute name="displayName" type="xs:string"/> <xs:attribute name="description" type="xs:string"/> + <xs:attribute name="publish" type="xs:boolean" default="true"/> </xs:complexType> </xs:element> <xs:element name="resource"> diff --git a/ofbiz-rest-impl/src/main/java/org/apache/ofbiz/ws/rs/core/OFBizApiConfig.java b/ofbiz-rest-impl/src/main/java/org/apache/ofbiz/ws/rs/core/OFBizApiConfig.java index 4e16d3f..0e2d13a 100644 --- a/ofbiz-rest-impl/src/main/java/org/apache/ofbiz/ws/rs/core/OFBizApiConfig.java +++ b/ofbiz-rest-impl/src/main/java/org/apache/ofbiz/ws/rs/core/OFBizApiConfig.java @@ -100,6 +100,10 @@ public class OFBizApiConfig extends ResourceConfig { return; } MICRO_APIS.forEach((k, v) -> { + if (!v.isPublish()) { + Debug.logInfo("API '" + v.getName() + "' is declared to be a non-publish, ignoring...", MODULE); + return; + } Debug.logInfo("Registring Resource Definitions from API - " + k, MODULE); List<ModelResource> resources = v.getResources(); resources.forEach(modelResource -> { 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 index 2381e5a..d57a805 100644 --- 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 @@ -27,6 +27,7 @@ public class ModelApi { private String name; private String displayName; private String description; + private boolean publish; /** * @return @@ -110,4 +111,18 @@ public class ModelApi { this.description = value; } + /** + * @return the publish + */ + public boolean isPublish() { + return publish; + } + + /** + * @param publish the publish to set + */ + public void setPublish(boolean publish) { + this.publish = publish; + } + } 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 index 0bfe9da..0bc8c3c 100644 --- 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 @@ -46,21 +46,28 @@ public final class ModelApiReader { } docElement.normalize(); ModelApi api = new ModelApi(); + api.setDisplayName(UtilXml.checkEmpty(docElement.getAttribute("displayName")).intern()); + api.setName(UtilXml.checkEmpty(docElement.getAttribute("name")).intern()); + api.setDescription(UtilXml.checkEmpty(docElement.getAttribute("description")).intern()); + api.setPublish(Boolean.parseBoolean(UtilXml.checkEmpty(docElement.getAttribute("publish")).intern())); 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()) - .publish(Boolean.parseBoolean(UtilXml.checkEmpty(resourceEle.getAttribute("publish")).intern())) - .auth(Boolean.parseBoolean(UtilXml.checkEmpty(resourceEle.getAttribute("auth")).intern())); - createOperations(resourceEle, resource); - Debug.logInfo(resource.toString(), MODULE); - api.addResource(resource); + createModelResource(resourceEle, api); } return api; } + private static void createModelResource(Element resourceEle, ModelApi modelApi) { + 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()) + .publish(Boolean.parseBoolean(UtilXml.checkEmpty(resourceEle.getAttribute("publish")).intern())) + .auth(Boolean.parseBoolean(UtilXml.checkEmpty(resourceEle.getAttribute("auth")).intern())); + createOperations(resourceEle, resource); + Debug.logInfo(resource.toString(), MODULE); + modelApi.addResource(resource); + } + private static void createOperations(Element resourceEle, ModelResource resource) { for (Element operationEle : UtilXml.childElementList(resourceEle, "operation")) { Element serviceEle = UtilXml.firstChildElement(operationEle, "service"); diff --git a/ofbiz-rest-impl/src/main/java/org/apache/ofbiz/ws/rs/openapi/OFBizOpenApiReader.java b/ofbiz-rest-impl/src/main/java/org/apache/ofbiz/ws/rs/openapi/OFBizOpenApiReader.java index 95c9a6f..87aebe5 100644 --- a/ofbiz-rest-impl/src/main/java/org/apache/ofbiz/ws/rs/openapi/OFBizOpenApiReader.java +++ b/ofbiz-rest-impl/src/main/java/org/apache/ofbiz/ws/rs/openapi/OFBizOpenApiReader.java @@ -101,6 +101,9 @@ public final class OFBizOpenApiReader extends Reader implements OpenApiReader { SecurityRequirement security = new SecurityRequirement(); security.addList("jwtToken"); apis.forEach((k, v) -> { + if (!v.isPublish()) { + return; + } List<ModelResource> resources = v.getResources(); resources.forEach(modelResource -> { Tag resourceTab = new Tag().name(modelResource.getDisplayName()).description(modelResource.getDescription()); |
Free forum by Nabble | Edit this page |