Repository: incubator-nifi Updated Branches: refs/heads/develop e88ed13d8 -> 0bd27847a
NIFI-309 - Adding support for Reads/Writes Attributes Project: http://git-wip-us.apache.org/repos/asf/incubator-nifi/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-nifi/commit/3ac9cbaa Tree: http://git-wip-us.apache.org/repos/asf/incubator-nifi/tree/3ac9cbaa Diff: http://git-wip-us.apache.org/repos/asf/incubator-nifi/diff/3ac9cbaa Branch: refs/heads/develop Commit: 3ac9cbaa21c5c53a575f4086b2d7456ca22bfa17 Parents: e88ed13 Author: danbress <[email protected]> Authored: Thu Mar 5 11:04:16 2015 -0500 Committer: danbress <[email protected]> Committed: Fri Mar 20 09:38:44 2015 -0400 ---------------------------------------------------------------------- .../documentation/ReadsAttribute.java | 41 +++++++ .../documentation/ReadsAttributes.java | 39 +++++++ .../nifi/annotation/documentation/SeeAlso.java | 43 +++++++ .../documentation/WritesAttribute.java | 41 +++++++ .../documentation/WritesAttributes.java | 40 +++++++ .../html/HtmlProcessorDocumentationWriter.java | 115 ++++++++++++++++++- .../example/FullyDocumentedProcessor.java | 9 +- .../html/ProcessorDocumentationWriterTest.java | 1 + 8 files changed, 325 insertions(+), 4 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/3ac9cbaa/nifi/nifi-api/src/main/java/org/apache/nifi/annotation/documentation/ReadsAttribute.java ---------------------------------------------------------------------- diff --git a/nifi/nifi-api/src/main/java/org/apache/nifi/annotation/documentation/ReadsAttribute.java b/nifi/nifi-api/src/main/java/org/apache/nifi/annotation/documentation/ReadsAttribute.java new file mode 100644 index 0000000..d644d94 --- /dev/null +++ b/nifi/nifi-api/src/main/java/org/apache/nifi/annotation/documentation/ReadsAttribute.java @@ -0,0 +1,41 @@ +/* + * 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.annotation.documentation; + +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Inherited; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Annotation that may be placed on a {@link org.apache.nifi.processor.Processor Processor} + * indicating that this processor reads a specific FlowFile attribute. + * + * @author + * + */ + +@Documented +@Target({ElementType.TYPE}) +@Retention(RetentionPolicy.RUNTIME) +@Inherited +public @interface ReadsAttribute { + public String attribute(); + public String description() default ""; +} http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/3ac9cbaa/nifi/nifi-api/src/main/java/org/apache/nifi/annotation/documentation/ReadsAttributes.java ---------------------------------------------------------------------- diff --git a/nifi/nifi-api/src/main/java/org/apache/nifi/annotation/documentation/ReadsAttributes.java b/nifi/nifi-api/src/main/java/org/apache/nifi/annotation/documentation/ReadsAttributes.java new file mode 100644 index 0000000..9edd06f --- /dev/null +++ b/nifi/nifi-api/src/main/java/org/apache/nifi/annotation/documentation/ReadsAttributes.java @@ -0,0 +1,39 @@ +/* + * 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.annotation.documentation; + +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Inherited; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Annotation that may be placed on a {@link org.apache.nifi.processor.Processor Processor} + * indicating that this processor reads specific FlowFile attributes. + * + * @author + * + */ +@Documented +@Target({ElementType.TYPE}) +@Retention(RetentionPolicy.RUNTIME) +@Inherited +public @interface ReadsAttributes { + public ReadsAttribute[] value(); +} http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/3ac9cbaa/nifi/nifi-api/src/main/java/org/apache/nifi/annotation/documentation/SeeAlso.java ---------------------------------------------------------------------- diff --git a/nifi/nifi-api/src/main/java/org/apache/nifi/annotation/documentation/SeeAlso.java b/nifi/nifi-api/src/main/java/org/apache/nifi/annotation/documentation/SeeAlso.java new file mode 100644 index 0000000..78daa58 --- /dev/null +++ b/nifi/nifi-api/src/main/java/org/apache/nifi/annotation/documentation/SeeAlso.java @@ -0,0 +1,43 @@ +/* + * 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.annotation.documentation; + +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Inherited; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import org.apache.nifi.components.ConfigurableComponent; + +/** + * Annotation that may be placed on a {@link org.apache.nifi.processor.Processor Processor}, + * {@link org.apache.nifi.controller.ControllerService ControllerService}, or + * {@link org.apache.nifi.reporting.ReportingTask ReportingTask} that indicates this component is related + * to the components listed. + * @author + * + */ + +@Documented +@Target({ElementType.TYPE}) +@Retention(RetentionPolicy.RUNTIME) +@Inherited +public @interface SeeAlso { + public Class<? extends ConfigurableComponent>[] value(); +} http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/3ac9cbaa/nifi/nifi-api/src/main/java/org/apache/nifi/annotation/documentation/WritesAttribute.java ---------------------------------------------------------------------- diff --git a/nifi/nifi-api/src/main/java/org/apache/nifi/annotation/documentation/WritesAttribute.java b/nifi/nifi-api/src/main/java/org/apache/nifi/annotation/documentation/WritesAttribute.java new file mode 100644 index 0000000..16ef56b --- /dev/null +++ b/nifi/nifi-api/src/main/java/org/apache/nifi/annotation/documentation/WritesAttribute.java @@ -0,0 +1,41 @@ +/* + * 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.annotation.documentation; + +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Inherited; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Annotation that may be placed on a {@link org.apache.nifi.processor.Processor Processor} + * indicating that this processor writes/updates a specific FlowFile attribute. + * + * @author + * + */ + +@Documented +@Target({ElementType.TYPE}) +@Retention(RetentionPolicy.RUNTIME) +@Inherited +public @interface WritesAttribute { + public String attribute(); + public String description() default ""; +} http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/3ac9cbaa/nifi/nifi-api/src/main/java/org/apache/nifi/annotation/documentation/WritesAttributes.java ---------------------------------------------------------------------- diff --git a/nifi/nifi-api/src/main/java/org/apache/nifi/annotation/documentation/WritesAttributes.java b/nifi/nifi-api/src/main/java/org/apache/nifi/annotation/documentation/WritesAttributes.java new file mode 100644 index 0000000..d9d2380 --- /dev/null +++ b/nifi/nifi-api/src/main/java/org/apache/nifi/annotation/documentation/WritesAttributes.java @@ -0,0 +1,40 @@ +/* + * 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.annotation.documentation; + +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Inherited; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Annotation that may be placed on a {@link org.apache.nifi.processor.Processor Processor} + * indicating that this processor writes/updates specific FlowFile attributes. + * + * @author + * + */ + +@Documented +@Target({ElementType.TYPE}) +@Retention(RetentionPolicy.RUNTIME) +@Inherited +public @interface WritesAttributes { + public WritesAttribute[] value(); +} http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/3ac9cbaa/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/main/java/org/apache/nifi/documentation/html/HtmlProcessorDocumentationWriter.java ---------------------------------------------------------------------- diff --git a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/main/java/org/apache/nifi/documentation/html/HtmlProcessorDocumentationWriter.java b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/main/java/org/apache/nifi/documentation/html/HtmlProcessorDocumentationWriter.java index 412ebf6..74615f5 100644 --- a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/main/java/org/apache/nifi/documentation/html/HtmlProcessorDocumentationWriter.java +++ b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/main/java/org/apache/nifi/documentation/html/HtmlProcessorDocumentationWriter.java @@ -16,25 +16,136 @@ */ package org.apache.nifi.documentation.html; +import java.util.ArrayList; +import java.util.List; + import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamWriter; +import org.apache.commons.lang3.StringUtils; +import org.apache.nifi.annotation.documentation.ReadsAttribute; +import org.apache.nifi.annotation.documentation.ReadsAttributes; +import org.apache.nifi.annotation.documentation.WritesAttribute; +import org.apache.nifi.annotation.documentation.WritesAttributes; import org.apache.nifi.components.ConfigurableComponent; import org.apache.nifi.processor.Processor; import org.apache.nifi.processor.Relationship; /** * Writes documentation specific for a Processor. This includes everything for a - * ConfigurableComponent as well as Relationship information. - * + * ConfigurableComponent as well as Relationship information. * + * */ public class HtmlProcessorDocumentationWriter extends HtmlDocumentationWriter { @Override protected void writeAdditionalBodyInfo(final ConfigurableComponent configurableComponent, final XMLStreamWriter xmlStreamWriter) throws XMLStreamException { + final Processor processor = (Processor) configurableComponent; + writeRelationships(processor, xmlStreamWriter); + writeAttributeInfo(processor, xmlStreamWriter); + } + + private void writeAttributeInfo(ConfigurableComponent configurableComponent, + XMLStreamWriter xmlStreamWriter) throws XMLStreamException { final Processor processor = (Processor) configurableComponent; + + handleReadsAttributes(xmlStreamWriter, processor); + handleWritesAttributes(xmlStreamWriter, processor); + } + + private void handleReadsAttributes(XMLStreamWriter xmlStreamWriter, final Processor processor) + throws XMLStreamException { + List<ReadsAttribute> attributesRead = getReadsAttributes(processor); + + writeSimpleElement(xmlStreamWriter, "h3", "Reads Attributes: "); + if (attributesRead.size() > 0) { + xmlStreamWriter.writeStartElement("table"); + xmlStreamWriter.writeStartElement("tr"); + writeSimpleElement(xmlStreamWriter, "th", "Name"); + writeSimpleElement(xmlStreamWriter, "th", "Description"); + xmlStreamWriter.writeEndElement(); + for (ReadsAttribute attribute : attributesRead) { + xmlStreamWriter.writeStartElement("tr"); + writeSimpleElement(xmlStreamWriter, "td", + StringUtils.defaultIfBlank(attribute.attribute(), "Not Specified")); + writeSimpleElement(xmlStreamWriter, "td", + StringUtils.defaultIfBlank(attribute.description(), "Not Specified")); + xmlStreamWriter.writeEndElement(); + } + xmlStreamWriter.writeEndElement(); + + } else { + xmlStreamWriter.writeCharacters("None specified."); + } + } + + private void handleWritesAttributes(XMLStreamWriter xmlStreamWriter, final Processor processor) + throws XMLStreamException { + List<WritesAttribute> attributesRead = getWritesAttributes(processor); + + writeSimpleElement(xmlStreamWriter, "h3", "Writes Attributes: "); + if (attributesRead.size() > 0) { + xmlStreamWriter.writeStartElement("table"); + xmlStreamWriter.writeStartElement("tr"); + writeSimpleElement(xmlStreamWriter, "th", "Name"); + writeSimpleElement(xmlStreamWriter, "th", "Description"); + xmlStreamWriter.writeEndElement(); + for (WritesAttribute attribute : attributesRead) { + xmlStreamWriter.writeStartElement("tr"); + writeSimpleElement(xmlStreamWriter, "td", + StringUtils.defaultIfBlank(attribute.attribute(), "Not Specified")); + writeSimpleElement(xmlStreamWriter, "td", + StringUtils.defaultIfBlank(attribute.description(), "Not Specified")); + xmlStreamWriter.writeEndElement(); + } + xmlStreamWriter.writeEndElement(); + + } else { + xmlStreamWriter.writeCharacters("None specified."); + } + } + + private List<ReadsAttribute> getReadsAttributes(Processor processor) { + List<ReadsAttribute> attributes = new ArrayList<>(); + + ReadsAttributes readsAttributes = processor.getClass().getAnnotation(ReadsAttributes.class); + if (readsAttributes != null) { + for (ReadsAttribute readAttribute : readsAttributes.value()) { + attributes.add(readAttribute); + } + } + + ReadsAttribute readsAttribute = processor.getClass().getAnnotation(ReadsAttribute.class); + if (readsAttribute != null) { + attributes.add(readsAttribute); + } + + return attributes; + } + + private List<WritesAttribute> getWritesAttributes(Processor processor) { + List<WritesAttribute> attributes = new ArrayList<>(); + + WritesAttributes writesAttributes = processor.getClass().getAnnotation(WritesAttributes.class); + if (writesAttributes != null) { + for (WritesAttribute writeAttribute : writesAttributes.value()) { + attributes.add(writeAttribute); + } + } + + WritesAttribute writeAttribute = processor.getClass().getAnnotation(WritesAttribute.class); + if (writeAttribute != null) { + attributes.add(writeAttribute); + } + + return attributes; + } + + private void writeRelationships(final Processor processor, final XMLStreamWriter xmlStreamWriter) + throws XMLStreamException { + writeSimpleElement(xmlStreamWriter, "h3", "Relationships: "); if (processor.getRelationships().size() > 0) { http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/3ac9cbaa/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/test/java/org/apache/nifi/documentation/example/FullyDocumentedProcessor.java ---------------------------------------------------------------------- diff --git a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/test/java/org/apache/nifi/documentation/example/FullyDocumentedProcessor.java b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/test/java/org/apache/nifi/documentation/example/FullyDocumentedProcessor.java index c2c7657..20307e8 100644 --- a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/test/java/org/apache/nifi/documentation/example/FullyDocumentedProcessor.java +++ b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/test/java/org/apache/nifi/documentation/example/FullyDocumentedProcessor.java @@ -22,6 +22,11 @@ import java.util.HashSet; import java.util.List; import java.util.Set; +import org.apache.nifi.annotation.documentation.CapabilityDescription; +import org.apache.nifi.annotation.documentation.ReadsAttribute; +import org.apache.nifi.annotation.documentation.Tags; +import org.apache.nifi.annotation.documentation.WritesAttribute; +import org.apache.nifi.annotation.documentation.WritesAttributes; import org.apache.nifi.components.AllowableValue; import org.apache.nifi.components.PropertyDescriptor; import org.apache.nifi.processor.AbstractProcessor; @@ -29,13 +34,13 @@ import org.apache.nifi.processor.ProcessContext; import org.apache.nifi.processor.ProcessSession; import org.apache.nifi.processor.ProcessorInitializationContext; import org.apache.nifi.processor.Relationship; -import org.apache.nifi.annotation.documentation.CapabilityDescription; -import org.apache.nifi.annotation.documentation.Tags; import org.apache.nifi.processor.exception.ProcessException; import org.apache.nifi.processor.util.StandardValidators; @Tags({ "one", "two", "three" }) @CapabilityDescription("This is a processor that is used to test documentation.") +@WritesAttributes({@WritesAttribute(attribute="first", description="this is the first attribute i write"), @WritesAttribute(attribute="second")}) +@ReadsAttribute(attribute = "incoming", description="this specifies the format of the thing") public class FullyDocumentedProcessor extends AbstractProcessor { public static final PropertyDescriptor DIRECTORY = new PropertyDescriptor.Builder().name("Input Directory") http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/3ac9cbaa/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/test/java/org/apache/nifi/documentation/html/ProcessorDocumentationWriterTest.java ---------------------------------------------------------------------- diff --git a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/test/java/org/apache/nifi/documentation/html/ProcessorDocumentationWriterTest.java b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/test/java/org/apache/nifi/documentation/html/ProcessorDocumentationWriterTest.java index 5306ddf..ffd31d8 100644 --- a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/test/java/org/apache/nifi/documentation/html/ProcessorDocumentationWriterTest.java +++ b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/test/java/org/apache/nifi/documentation/html/ProcessorDocumentationWriterTest.java @@ -69,6 +69,7 @@ public class ProcessorDocumentationWriterTest { assertNotContains(results, "No description provided."); assertNotContains(results, "No Tags provided."); assertNotContains(results, "Additional Details..."); + System.out.println(results); } @Test
