NIFI-463 adding links to controller service implementations

This commit is contained in:
danbress 2015-03-24 10:54:32 -04:00
parent 14e73bc24d
commit d9a86e5b2e
3 changed files with 63 additions and 12 deletions

View File

@ -20,6 +20,7 @@ import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import javax.xml.stream.FactoryConfigurationError;
import javax.xml.stream.XMLOutputFactory;
@ -36,6 +37,7 @@ import org.apache.nifi.components.ConfigurableComponent;
import org.apache.nifi.components.PropertyDescriptor;
import org.apache.nifi.controller.ControllerService;
import org.apache.nifi.documentation.DocumentationWriter;
import org.apache.nifi.nar.ExtensionManager;
/**
* Generates HTML documentation for a ConfigurableComponent. This class is used
@ -148,9 +150,7 @@ public class HtmlDocumentationWriter implements DocumentationWriter {
xmlStreamWriter.writeCharacters(", ");
}
final String link = "../" + linkedComponent.getCanonicalName() + "/index.html";
writeLink(xmlStreamWriter, linkedComponent.getSimpleName(), link);
writeLinkForComponent(xmlStreamWriter, linkedComponent);
++index;
}
@ -434,12 +434,24 @@ public class HtmlDocumentationWriter implements DocumentationWriter {
}
xmlStreamWriter.writeEndElement();
} else if (property.getControllerServiceDefinition() != null) {
Class<? extends ControllerService> controllerServiceClass = property
.getControllerServiceDefinition();
Class<? extends ControllerService> controllerServiceClass = property.getControllerServiceDefinition();
writeSimpleElement(xmlStreamWriter, "strong", "Controller Service: ");
writeSimpleElement(xmlStreamWriter, "strong", "Controller Service API: ");
xmlStreamWriter.writeEmptyElement("br");
xmlStreamWriter.writeCharacters(controllerServiceClass.getSimpleName());
final List<Class<? extends ControllerService>> implementations = lookupControllerServiceImpls(controllerServiceClass);
xmlStreamWriter.writeEmptyElement("br");
if (implementations.size() > 0) {
final String title = implementations.size() > 1 ? "Implementations: " : "Implementation:";
writeSimpleElement(xmlStreamWriter, "strong", title);
for (int i = 0; i < implementations.size(); i++) {
xmlStreamWriter.writeEmptyElement("br");
writeLinkForComponent(xmlStreamWriter, implementations.get(i));
}
} else {
xmlStreamWriter.writeCharacters("No implementations found.");
}
}
}
@ -519,4 +531,37 @@ public class HtmlDocumentationWriter implements DocumentationWriter {
xmlStreamWriter.writeCharacters(text);
xmlStreamWriter.writeEndElement();
}
/**
* Writes a link to another configurable component
*
* @param xmlStreamWriter the xml stream writer
* @param clazz the configurable component to link to
* @throws XMLStreamException thrown if there is a problem writing the XML
*/
protected void writeLinkForComponent(final XMLStreamWriter xmlStreamWriter, final Class<?> clazz) throws XMLStreamException {
writeLink(xmlStreamWriter, clazz.getSimpleName(), "../" + clazz.getCanonicalName() + "/index.html");
}
/**
* Uses the {@link ExtensionManager} to discover any controller service that implement the controller service
* API.
*
* @param parent the controller service API
* @return a list of controller services that implement the controller service API
*/
private List<Class<? extends ControllerService>> lookupControllerServiceImpls(
final Class<? extends ControllerService> parent) {
final Set<Class> controllerServices = ExtensionManager.getExtensions(ControllerService.class);
final List<Class<? extends ControllerService>> implementations = new ArrayList<>();
for (Class<? extends ControllerService> controllerServiceClass : controllerServices) {
if (parent.isAssignableFrom(controllerServiceClass)) {
implementations.add(controllerServiceClass);
}
}
return implementations;
}
}

View File

@ -26,9 +26,9 @@ import org.apache.nifi.components.PropertyDescriptor;
import org.apache.nifi.controller.AbstractControllerService;
import org.apache.nifi.processor.util.StandardValidators;
@CapabilityDescription("A documented controller service that can help you do things")
@CapabilityDescription("A documented controller service that can help you do things")
@Tags({"one", "two", "three"})
public class FullyDocumentedControllerService extends AbstractControllerService {
public class FullyDocumentedControllerService extends AbstractControllerService implements SampleService{
public static final PropertyDescriptor KEYSTORE = new PropertyDescriptor.Builder().name("Keystore Filename")
.description("The fully-qualified filename of the Keystore").defaultValue(null)
@ -53,6 +53,12 @@ public class FullyDocumentedControllerService extends AbstractControllerService
@Override
protected List<PropertyDescriptor> getSupportedPropertyDescriptors() {
return properties;
}
}
@Override
public void doSomething() {
// TODO Auto-generated method stub
}
}

View File

@ -30,7 +30,7 @@ import org.apache.nifi.documentation.mock.MockProcessorInitializationContext;
import org.junit.Test;
public class ProcessorDocumentationWriterTest {
@Test
public void testFullyDocumentedProcessor() throws IOException {
FullyDocumentedProcessor processor = new FullyDocumentedProcessor();
@ -59,7 +59,7 @@ public class ProcessorDocumentationWriterTest {
assertContains(results, FullyDocumentedProcessor.REL_SUCCESS.getDescription());
assertContains(results, FullyDocumentedProcessor.REL_FAILURE.getName());
assertContains(results, FullyDocumentedProcessor.REL_FAILURE.getDescription());
assertContains(results, "Controller Service: ");
assertContains(results, "Controller Service API: ");
assertContains(results, "SampleService");
assertNotContains(results, "iconSecure.png");
@ -97,6 +97,6 @@ public class ProcessorDocumentationWriterTest {
// relationships
assertContains(results, "This processor has no relationships.");
}
}
}