kevdoran 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_r271048364
 
 

 ##########
 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 don't have a better idea (I know that is not helpful. But this feels like 
a vert brittle coupling between NiFi and Registry.

----------------------------------------------------------------
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:
[email protected]


With regards,
Apache Git Services

Reply via email to