This is an automated email from the ASF dual-hosted git repository.
kdoran pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nifi-registry.git
The following commit(s) were added to refs/heads/master by this push:
new 81ee541 NIFIREG-248 Fixing usage of the JAX-RS Link class so that it
works correctly with swagger code-gen
81ee541 is described below
commit 81ee541db3b9e89a786e0a6a33dadadb1e892bd7
Author: Bryan Bende <[email protected]>
AuthorDate: Tue Apr 2 12:05:47 2019 -0400
NIFIREG-248 Fixing usage of the JAX-RS Link class so that it works
correctly with swagger code-gen
- Changing JaxbLink params map to be strings to better align with swagger
code-gen, and fixing overloaded method names
This closes #167.
Signed-off-by: Kevin Doran <[email protected]>
---
.../extension/component/ExtensionMetadata.java | 3 +-
.../repo/ExtensionRepoExtensionMetadata.java | 3 +-
.../extension/repo/ExtensionRepoVersion.java | 12 +-
.../org/apache/nifi/registry/link/JaxbLink.java | 139 +++++++++++++++++++++
.../org/apache/nifi/registry/link/LinkAdapter.java | 30 ++---
.../apache/nifi/registry/link/LinkableEntity.java | 3 +-
.../registry/web/api/ExtensionRepoResource.java | 2 +-
7 files changed, 170 insertions(+), 22 deletions(-)
diff --git
a/nifi-registry-core/nifi-registry-data-model/src/main/java/org/apache/nifi/registry/extension/component/ExtensionMetadata.java
b/nifi-registry-core/nifi-registry-data-model/src/main/java/org/apache/nifi/registry/extension/component/ExtensionMetadata.java
index 64146ea..a41198b 100644
---
a/nifi-registry-core/nifi-registry-data-model/src/main/java/org/apache/nifi/registry/extension/component/ExtensionMetadata.java
+++
b/nifi-registry-core/nifi-registry-data-model/src/main/java/org/apache/nifi/registry/extension/component/ExtensionMetadata.java
@@ -142,7 +142,8 @@ public class ExtensionMetadata extends LinkableEntity
implements LinkableDocs, C
@Override
@XmlElement
@XmlJavaTypeAdapter(LinkAdapter.class)
- @ApiModelProperty(value = "A WebLink to the documentation for this
extension.", readOnly = true)
+ @ApiModelProperty(value = "A WebLink to the documentation for this
extension.",
+ dataType = "org.apache.nifi.registry.link.JaxbLink", readOnly =
true)
public Link getLinkDocs() {
return linkDocs;
}
diff --git
a/nifi-registry-core/nifi-registry-data-model/src/main/java/org/apache/nifi/registry/extension/repo/ExtensionRepoExtensionMetadata.java
b/nifi-registry-core/nifi-registry-data-model/src/main/java/org/apache/nifi/registry/extension/repo/ExtensionRepoExtensionMetadata.java
index bf4d4ae..737b6c0 100644
---
a/nifi-registry-core/nifi-registry-data-model/src/main/java/org/apache/nifi/registry/extension/repo/ExtensionRepoExtensionMetadata.java
+++
b/nifi-registry-core/nifi-registry-data-model/src/main/java/org/apache/nifi/registry/extension/repo/ExtensionRepoExtensionMetadata.java
@@ -53,7 +53,8 @@ public class ExtensionRepoExtensionMetadata extends
LinkableEntity implements Li
@Override
@XmlElement
@XmlJavaTypeAdapter(LinkAdapter.class)
- @ApiModelProperty(value = "A WebLink to the documentation for this
extension.", readOnly = true)
+ @ApiModelProperty(value = "A WebLink to the documentation for this
extension.",
+ dataType = "org.apache.nifi.registry.link.JaxbLink", readOnly =
true)
public Link getLinkDocs() {
return linkDocs;
}
diff --git
a/nifi-registry-core/nifi-registry-data-model/src/main/java/org/apache/nifi/registry/extension/repo/ExtensionRepoVersion.java
b/nifi-registry-core/nifi-registry-data-model/src/main/java/org/apache/nifi/registry/extension/repo/ExtensionRepoVersion.java
index dea1eda..1b29985 100644
---
a/nifi-registry-core/nifi-registry-data-model/src/main/java/org/apache/nifi/registry/extension/repo/ExtensionRepoVersion.java
+++
b/nifi-registry-core/nifi-registry-data-model/src/main/java/org/apache/nifi/registry/extension/repo/ExtensionRepoVersion.java
@@ -36,7 +36,8 @@ public class ExtensionRepoVersion {
@XmlElement
@XmlJavaTypeAdapter(LinkAdapter.class)
- @ApiModelProperty(value = "The WebLink to view the metadata about the
extensions contained in the extension bundle.", readOnly = true)
+ @ApiModelProperty(value = "The WebLink to view the metadata about the
extensions contained in the extension bundle.",
+ dataType = "org.apache.nifi.registry.link.JaxbLink", readOnly =
true)
public Link getExtensionsLink() {
return extensionsLink;
}
@@ -47,7 +48,8 @@ public class ExtensionRepoVersion {
@XmlElement
@XmlJavaTypeAdapter(LinkAdapter.class)
- @ApiModelProperty(value = "The WebLink to download this version of the
extension bundle.", readOnly = true)
+ @ApiModelProperty(value = "The WebLink to download this version of the
extension bundle.",
+ dataType = "org.apache.nifi.registry.link.JaxbLink", readOnly =
true)
public Link getDownloadLink() {
return downloadLink;
}
@@ -58,7 +60,8 @@ public class ExtensionRepoVersion {
@XmlElement
@XmlJavaTypeAdapter(LinkAdapter.class)
- @ApiModelProperty(value = "The WebLink to retrieve the SHA-256 digest for
this version of the extension bundle.", readOnly = true)
+ @ApiModelProperty(value = "The WebLink to retrieve the SHA-256 digest for
this version of the extension bundle.",
+ dataType = "org.apache.nifi.registry.link.JaxbLink", readOnly =
true)
public Link getSha256Link() {
return sha256Link;
}
@@ -67,7 +70,8 @@ public class ExtensionRepoVersion {
this.sha256Link = sha256Link;
}
- @ApiModelProperty(value = "Indicates if the client supplied a SHA-256 when
uploading this version of the extension bundle.", readOnly = true)
+ @ApiModelProperty(value = "Indicates if the client supplied a SHA-256 when
uploading this version of the extension bundle.",
+ dataType = "org.apache.nifi.registry.link.JaxbLink", readOnly =
true)
public Boolean getSha256Supplied() {
return sha256Supplied;
}
diff --git
a/nifi-registry-core/nifi-registry-data-model/src/main/java/org/apache/nifi/registry/link/JaxbLink.java
b/nifi-registry-core/nifi-registry-data-model/src/main/java/org/apache/nifi/registry/link/JaxbLink.java
new file mode 100644
index 0000000..e36b724
--- /dev/null
+++
b/nifi-registry-core/nifi-registry-data-model/src/main/java/org/apache/nifi/registry/link/JaxbLink.java
@@ -0,0 +1,139 @@
+/*
+ * 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.nifi.registry.link;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+
+import javax.xml.bind.annotation.XmlAnyAttribute;
+import javax.xml.bind.annotation.XmlAttribute;
+import java.net.URI;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Copy of JAX-RS Link.JaxbLink so that Swagger annotations can be applied
properly so that getUri() lines up with "href".
+ */
+@ApiModel
+public class JaxbLink {
+
+ private URI uri;
+ private Map<String,String> params;
+
+ /**
+ * Default constructor needed during unmarshalling.
+ */
+ public JaxbLink() {
+ }
+
+ /**
+ * Construct an instance from a URI and no parameters.
+ *
+ * @param uri underlying URI.
+ */
+ public JaxbLink(URI uri) {
+ this.uri = uri;
+ }
+
+ /**
+ * Construct an instance from a URI and some parameters.
+ *
+ * @param uri underlying URI.
+ * @param params parameters of this link.
+ */
+ public JaxbLink(URI uri, Map<String,String> params) {
+ this.uri = uri;
+ this.params = params;
+ }
+
+ /**
+ * Get the underlying URI for this link.
+ *
+ * @return underlying URI.
+ */
+ @XmlAttribute(name = "href")
+ @ApiModelProperty(name = "href", value = "The href for the link")
+ public URI getUri() {
+ return uri;
+ }
+
+ /**
+ * Get the parameter map for this link.
+ *
+ * @return parameter map.
+ */
+ @XmlAnyAttribute
+ @ApiModelProperty(name = "params", value = "The params for the link")
+ public Map<String,String> getParams() {
+ if (params == null) {
+ params = new HashMap<>();
+ }
+ return params;
+ }
+
+ /**
+ * Set the underlying URI for this link.
+ *
+ * This setter is needed for JAXB unmarshalling.
+ */
+ void setUri(URI uri) {
+ this.uri = uri;
+ }
+
+ /**
+ * Set the parameter map for this link.
+ *
+ * This setter is needed for JAXB unmarshalling.
+ */
+ void setParams(Map<String,String> params) {
+ this.params = params;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (!(o instanceof JaxbLink)) return false;
+
+ JaxbLink jaxbLink = (JaxbLink) o;
+
+ if (uri != null ? !uri.equals(jaxbLink.uri) : jaxbLink.uri != null) {
+ return false;
+ }
+
+ if (params == jaxbLink.params) {
+ return true;
+ }
+ if (params == null) {
+ // if this.params is 'null', consider other.params equal to empty
+ return jaxbLink.params.isEmpty();
+ }
+ if (jaxbLink.params == null) {
+ // if other.params is 'null', consider this.params equal to empty
+ return params.isEmpty();
+ }
+
+ return params.equals(jaxbLink.params);
+ }
+
+ @Override
+ public int hashCode() {
+ int result = uri != null ? uri.hashCode() : 0;
+ result = 31 * result + (params != null && !params.isEmpty() ?
params.hashCode() : 0);
+ return result;
+ }
+
+}
diff --git
a/nifi-registry-core/nifi-registry-data-model/src/main/java/org/apache/nifi/registry/link/LinkAdapter.java
b/nifi-registry-core/nifi-registry-data-model/src/main/java/org/apache/nifi/registry/link/LinkAdapter.java
index c3dae90..76bd708 100644
---
a/nifi-registry-core/nifi-registry-data-model/src/main/java/org/apache/nifi/registry/link/LinkAdapter.java
+++
b/nifi-registry-core/nifi-registry-data-model/src/main/java/org/apache/nifi/registry/link/LinkAdapter.java
@@ -18,49 +18,51 @@ package org.apache.nifi.registry.link;
import javax.ws.rs.core.Link;
import javax.xml.bind.annotation.adapters.XmlAdapter;
-import javax.xml.namespace.QName;
import java.util.Map;
/**
* This class is a modified version of Jersey's Link.JaxbAdapter that adds
protection against nulls.
*/
-public class LinkAdapter extends XmlAdapter<Link.JaxbLink, Link> {
+public class LinkAdapter extends XmlAdapter<JaxbLink, Link> {
/**
- * Convert a {@link Link.JaxbLink} into a {@link Link}.
+ * Convert a {@link JaxbLink} into a {@link Link}.
*
- * @param v instance of type {@link Link.JaxbLink}.
+ * @param v instance of type {@link JaxbLink}.
* @return mapped instance of type {@link Link.JaxbLink}
*/
@Override
- public Link unmarshal(Link.JaxbLink v) {
+ public Link unmarshal(JaxbLink v) {
if (v == null) {
return null;
}
Link.Builder lb = Link.fromUri(v.getUri());
- for (Map.Entry<QName, Object> e : v.getParams().entrySet()) {
- lb.param(e.getKey().getLocalPart(), e.getValue().toString());
+ if (v.getParams() != null) {
+ for (Map.Entry<String,String> e : v.getParams().entrySet()) {
+ lb.param(e.getKey(), e.getValue());
+ }
}
return lb.build();
}
/**
- * Convert a {@link Link} into a {@link Link.JaxbLink}.
+ * Convert a {@link Link} into a {@link JaxbLink}.
*
* @param v instance of type {@link Link}.
- * @return mapped instance of type {@link Link.JaxbLink}.
+ * @return mapped instance of type {@link JaxbLink}.
*/
@Override
- public Link.JaxbLink marshal(Link v) {
+ public JaxbLink marshal(Link v) {
if (v == null) {
return null;
}
- Link.JaxbLink jl = new Link.JaxbLink(v.getUri());
- for (Map.Entry<String, String> e : v.getParams().entrySet()) {
- final String name = e.getKey();
- jl.getParams().put(new QName("", name), e.getValue());
+ final JaxbLink jl = new JaxbLink(v.getUri());
+ if (v.getParams() != null) {
+ for (Map.Entry<String, String> e : v.getParams().entrySet()) {
+ jl.getParams().put(e.getKey(), e.getValue());
+ }
}
return jl;
}
diff --git
a/nifi-registry-core/nifi-registry-data-model/src/main/java/org/apache/nifi/registry/link/LinkableEntity.java
b/nifi-registry-core/nifi-registry-data-model/src/main/java/org/apache/nifi/registry/link/LinkableEntity.java
index 0d09066..3814e74 100644
---
a/nifi-registry-core/nifi-registry-data-model/src/main/java/org/apache/nifi/registry/link/LinkableEntity.java
+++
b/nifi-registry-core/nifi-registry-data-model/src/main/java/org/apache/nifi/registry/link/LinkableEntity.java
@@ -33,7 +33,8 @@ public abstract class LinkableEntity {
@XmlElement
@XmlJavaTypeAdapter(LinkAdapter.class)
- @ApiModelProperty(value = "An WebLink to this entity.", readOnly = true)
+ @ApiModelProperty(value = "An WebLink to this entity.",
+ dataType = "org.apache.nifi.registry.link.JaxbLink", readOnly =
true)
public Link getLink() {
return link;
}
diff --git
a/nifi-registry-core/nifi-registry-web-api/src/main/java/org/apache/nifi/registry/web/api/ExtensionRepoResource.java
b/nifi-registry-core/nifi-registry-web-api/src/main/java/org/apache/nifi/registry/web/api/ExtensionRepoResource.java
index d2dbeb8..1297dad 100644
---
a/nifi-registry-core/nifi-registry-web-api/src/main/java/org/apache/nifi/registry/web/api/ExtensionRepoResource.java
+++
b/nifi-registry-core/nifi-registry-web-api/src/main/java/org/apache/nifi/registry/web/api/ExtensionRepoResource.java
@@ -585,7 +585,7 @@ public class ExtensionRepoResource extends
AuthorizableApplicationResource {
@ApiResponse(code = 403, message = HttpStatusMessages.MESSAGE_403),
@ApiResponse(code = 404, message = HttpStatusMessages.MESSAGE_404),
@ApiResponse(code = 409, message = HttpStatusMessages.MESSAGE_409)
})
- public Response getExtensionRepoVersionSha256(
+ public Response getGlobalExtensionRepoVersionSha256(
@PathParam("groupId")
@ApiParam("The group identifier")
final String groupId,