You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@nifi.apache.org by GitBox <gi...@apache.org> on 2019/04/02 13:12:22 UTC

[GitHub] [nifi-registry] bbende commented on a change in pull request #163: NIFIREG-233 Setup ExtensionDocWriter with HTML implementation and RES…

bbende commented on a change in pull request #163: NIFIREG-233 Setup ExtensionDocWriter with HTML implementation and RES…
URL: https://github.com/apache/nifi-registry/pull/163#discussion_r271295544
 
 

 ##########
 File path: nifi-registry-core/nifi-registry-framework/src/main/java/org/apache/nifi/registry/service/extension/StandardExtensionService.java
 ##########
 @@ -726,6 +733,79 @@ public Extension getExtension(final BundleVersion bundleVersion, final String na
         return ExtensionMappings.map(entity, extensionSerializer);
     }
 
+    @Override
+    public void writeExtensionDocs(final BundleVersion bundleVersion, final String name, final OutputStream outputStream)
+            throws IOException {
+        if (bundleVersion == null) {
+            throw new IllegalArgumentException("Bundle version cannot be null");
+        }
+
+        if (bundleVersion.getVersionMetadata() == null || StringUtils.isBlank(bundleVersion.getVersionMetadata().getId())) {
+            throw new IllegalArgumentException("Bundle version must contain a version metadata with a bundle version id");
+        }
+
+        if (StringUtils.isBlank(name)) {
+            throw new IllegalArgumentException("Extension name cannot be null or blank");
+        }
+
+        if (outputStream == null) {
+            throw new IllegalArgumentException("Output stream cannot be null");
+        }
+
+        final ExtensionEntity entity = metadataService.getExtensionByName(bundleVersion.getVersionMetadata().getId(), name);
+        if (entity == null) {
+            LOGGER.warn("The specified extension [{}] does not exist in the specified bundle version [{}].",
+                    new Object[]{name, bundleVersion.getVersionMetadata().getId()});
+            throw new ResourceNotFoundException("The specified extension does not exist in this registry.");
+        }
+
+        final ExtensionMetadata extensionMetadata = ExtensionMappings.mapToMetadata(entity, extensionSerializer);
+        final Extension extension = ExtensionMappings.map(entity, extensionSerializer);
+        extensionDocWriter.write(extensionMetadata, extension, outputStream);
+    }
+
+    @Override
+    public void writeAdditionalDetailsDocs(final BundleVersion bundleVersion, final String name, final OutputStream outputStream) throws IOException {
+        if (bundleVersion == null) {
+            throw new IllegalArgumentException("Bundle version cannot be null");
+        }
+
+        if (bundleVersion.getVersionMetadata() == null || StringUtils.isBlank(bundleVersion.getVersionMetadata().getId())) {
+            throw new IllegalArgumentException("Bundle version must contain a version metadata with a bundle version id");
+        }
+
+        if (StringUtils.isBlank(name)) {
+            throw new IllegalArgumentException("Extension name cannot be null or blank");
+        }
+
+        if (outputStream == null) {
+            throw new IllegalArgumentException("Output stream cannot be null");
+        }
+
+        final ExtensionAdditionalDetailsEntity additionalDetailsEntity = metadataService.getExtensionAdditionalDetails(
+                bundleVersion.getVersionMetadata().getId(), name);
+
+        if (additionalDetailsEntity == null) {
+            LOGGER.warn("The specified extension [{}] does not exist in the specified bundle version [{}].",
+                    new Object[]{name, bundleVersion.getVersionMetadata().getId()});
+            throw new ResourceNotFoundException("The specified extension does not exist in this registry.");
+        }
+
+        if (!additionalDetailsEntity.getAdditionalDetails().isPresent()) {
+            LOGGER.warn("The specified extension [{}] does not have additional details in the specified bundle version [{}].",
+                    new Object[]{name, bundleVersion.getVersionMetadata().getId()});
+            throw new IllegalStateException("The specified extension does not have additional details.");
+        }
+
+        final String additionalDetailsContent = additionalDetailsEntity.getAdditionalDetails().get();
+
+        // The additional details content may have come from NiFi which has a different path to the css so we need to fix the location
+        final String componentUsageCssRef = DocumentationConstants.CSS_PATH + "component-usage.css";
+        final String updatedContent = additionalDetailsContent.replace("../../../../../css/component-usage.css", componentUsageCssRef);
 
 Review comment:
   I know, this is definitely kind of hackey, but not sure what else we can do since all the additionalDetails.html are currently in NiFi and created to be displayed as part of the NiFi docs.
   
   If we can come up with something better in the future we can eventually run this logic conditionally based on bundle and API type, meaning "if type == NAR and api <= someVersion". 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services