markap14 commented on code in PR #10667:
URL: https://github.com/apache/nifi/pull/10667#discussion_r2632499743
##########
nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/manifest/StandardRuntimeManifestService.java:
##########
@@ -401,6 +401,55 @@ private Map<String, File> discoverAdditionalDetails(final
BundleDetails bundleDe
return additionalDetailsMap;
}
+ @Override
+ public Map<String, File> discoverStepDocumentation(final String group,
final String artifact, final String version, final String connectorType) {
+ final BundleCoordinate bundleCoordinate = new BundleCoordinate(group,
artifact, version);
+ final Bundle bundle = extensionManager.getBundle(bundleCoordinate);
+
+ if (bundle == null) {
+ throw new ResourceNotFoundException("Unable to find bundle [" +
bundleCoordinate + "]");
+ }
+
+ return discoverStepDocumentation(bundle.getBundleDetails(),
connectorType);
+ }
+
+ private Map<String, File> discoverStepDocumentation(final BundleDetails
bundleDetails, final String connectorType) {
+ final Map<String, File> stepDocsMap = new LinkedHashMap<>();
+
+ final File stepDocsDir = new File(bundleDetails.getWorkingDirectory(),
"META-INF/docs/step-documentation/" + connectorType);
+ if (!stepDocsDir.exists()) {
+ LOGGER.debug("No step-documentation directory found for [{}] under
[{}]", connectorType, bundleDetails.getWorkingDirectory().getAbsolutePath());
+ return stepDocsMap;
+ }
+
+ final File[] stepDocFiles = stepDocsDir.listFiles();
+ if (stepDocFiles == null) {
+ return stepDocsMap;
+ }
+
+ for (final File stepDocFile : stepDocFiles) {
+ if (!stepDocFile.isFile() ||
!stepDocFile.getName().endsWith(".md")) {
+ LOGGER.debug("Skipping [{}], not a markdown file...",
stepDocFile.getAbsolutePath());
+ continue;
+ }
+
+ final String fileName = stepDocFile.getName().substring(0,
stepDocFile.getName().length() - 3);
+ final String stepName = fileNameToStepName(fileName);
+ stepDocsMap.put(stepName, stepDocFile);
+ LOGGER.debug("Discovered step documentation for step [{}] at
[{}]", stepName, stepDocFile.getAbsolutePath());
+ }
+
+ return stepDocsMap;
+ }
+
+ private String stepNameToFileName(final String stepName) {
+ return stepName.replace(" ", "-");
+ }
+
+ private String fileNameToStepName(final String fileName) {
+ return fileName.replace("-", " ");
+ }
Review Comment:
Is a bit of an awkward convention to replace spaces with dashes in a
filename, especially if we do no other translation. I'd be more inclined to
either:
- Replace non-alphanumeric with empty string, and then map back by detecting
change in case, replacing that with a space, and then adding a restriction on
Step Name that it can only contain spaces and alphanumeric characters (but that
may be less ideal for anyone whose native language uses unicode characters)
- Not associating filename with Step Name but instead read the markdown and
find the first-level title (i.e., the first line that is not a comment and not
empty and starts with a `# ` followed by title
Thoughts on these approaches?
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]