From 4faad38c16560a47fe408122c51f52069b19ba90 Mon Sep 17 00:00:00 2001 From: bob Date: Wed, 8 May 2024 20:28:36 -0500 Subject: [PATCH] NIFI-13187 - Modernize Archetypes This closes #8783. Signed-off-by: Joseph Witt --- .../src/main/java/MyProcessor.java | 24 ++++++++----------- .../src/main/java/StandardMyService.java | 13 +++------- 2 files changed, 13 insertions(+), 24 deletions(-) diff --git a/nifi-maven-archetypes/nifi-processor-bundle-archetype/src/main/resources/archetype-resources/nifi-__artifactBaseName__-processors/src/main/java/MyProcessor.java b/nifi-maven-archetypes/nifi-processor-bundle-archetype/src/main/resources/archetype-resources/nifi-__artifactBaseName__-processors/src/main/java/MyProcessor.java index 56432c1a15..7ecf9c15a5 100644 --- a/nifi-maven-archetypes/nifi-processor-bundle-archetype/src/main/resources/archetype-resources/nifi-__artifactBaseName__-processors/src/main/java/MyProcessor.java +++ b/nifi-maven-archetypes/nifi-processor-bundle-archetype/src/main/resources/archetype-resources/nifi-__artifactBaseName__-processors/src/main/java/MyProcessor.java @@ -33,9 +33,6 @@ import org.apache.nifi.processor.ProcessorInitializationContext; import org.apache.nifi.processor.Relationship; import org.apache.nifi.processor.util.StandardValidators; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashSet; import java.util.List; import java.util.Set; @@ -47,16 +44,17 @@ import java.util.Set; public class MyProcessor extends AbstractProcessor { public static final PropertyDescriptor MY_PROPERTY = new PropertyDescriptor - .Builder().name("MY_PROPERTY") - .displayName("My property") + .Builder() + .name("My Property") + .displayName("My Property") .description("Example Property") .required(true) .addValidator(StandardValidators.NON_EMPTY_VALIDATOR) .build(); - public static final Relationship MY_RELATIONSHIP = new Relationship.Builder() - .name("MY_RELATIONSHIP") - .description("Example relationship") + public static final Relationship REL_SUCCESS = new Relationship.Builder() + .name("success") + .description("Example success relationship") .build(); private List descriptors; @@ -65,13 +63,9 @@ public class MyProcessor extends AbstractProcessor { @Override protected void init(final ProcessorInitializationContext context) { - descriptors = new ArrayList<>(); - descriptors.add(MY_PROPERTY); - descriptors = Collections.unmodifiableList(descriptors); + descriptors = List.of(MY_PROPERTY); - relationships = new HashSet<>(); - relationships.add(MY_RELATIONSHIP); - relationships = Collections.unmodifiableSet(relationships); + relationships = Set.of(REL_SUCCESS); } @Override @@ -96,5 +90,7 @@ public class MyProcessor extends AbstractProcessor { return; } // TODO implement + + session.transfer(flowFile, REL_SUCCESS); } } diff --git a/nifi-maven-archetypes/nifi-service-bundle-archetype/src/main/resources/archetype-resources/nifi-__artifactBaseName__/src/main/java/StandardMyService.java b/nifi-maven-archetypes/nifi-service-bundle-archetype/src/main/resources/archetype-resources/nifi-__artifactBaseName__/src/main/java/StandardMyService.java index 688004da52..6f4698831a 100644 --- a/nifi-maven-archetypes/nifi-service-bundle-archetype/src/main/resources/archetype-resources/nifi-__artifactBaseName__/src/main/java/StandardMyService.java +++ b/nifi-maven-archetypes/nifi-service-bundle-archetype/src/main/resources/archetype-resources/nifi-__artifactBaseName__/src/main/java/StandardMyService.java @@ -16,8 +16,6 @@ */ package ${package}; -import java.util.ArrayList; -import java.util.Collections; import java.util.List; import org.apache.nifi.annotation.documentation.CapabilityDescription; @@ -35,20 +33,15 @@ import org.apache.nifi.reporting.InitializationException; public class StandardMyService extends AbstractControllerService implements MyService { public static final PropertyDescriptor MY_PROPERTY = new PropertyDescriptor - .Builder().name("MY_PROPERTY") + .Builder() + .name("My Property") .displayName("My Property") .description("Example Property") .required(true) .addValidator(StandardValidators.NON_EMPTY_VALIDATOR) .build(); - private static final List properties; - - static { - final List props = new ArrayList<>(); - props.add(MY_PROPERTY); - properties = Collections.unmodifiableList(props); - } + private static final List properties = List.of(MY_PROPERTY); @Override protected List getSupportedPropertyDescriptors() {