dan-s1 commented on code in PR #6337:
URL: https://github.com/apache/nifi/pull/6337#discussion_r1017022649


##########
nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/ValidateJson.java:
##########
@@ -105,97 +140,54 @@ public class ValidateJson extends AbstractProcessor {
         .description("FlowFiles that cannot be read as JSON are routed to this 
relationship")
         .build();
 
-    private List<PropertyDescriptor> descriptors;
-
-    private Set<Relationship> relationships;
+    public static final Set<Relationship> RELATIONSHIPS =
+            Collections.unmodifiableSet(new 
HashSet<>(Arrays.asList(REL_FAILURE, REL_VALID, REL_INVALID)));
 
-    private List<AllowableValue> allowableValues;
-
-    @Override
-    protected void init(final ProcessorInitializationContext context) {
-        final List<PropertyDescriptor> descriptors = new 
ArrayList<PropertyDescriptor>();
-        descriptors.add(SCHEMA_TEXT);
-        descriptors.add(SCHEMA_VERSION);
-        this.descriptors = Collections.unmodifiableList(descriptors);
-
-        final Set<Relationship> relationships = new HashSet<Relationship>();
-        relationships.add(REL_VALID);
-        relationships.add(REL_INVALID);
-        relationships.add(REL_FAILURE);
-        this.relationships = Collections.unmodifiableSet(relationships);
-
-        final List<AllowableValue> allowableValues = new 
ArrayList<AllowableValue>();
-        allowableValues.add(SCHEMA_VERSION_4);
-        allowableValues.add(SCHEMA_VERSION_6);
-        allowableValues.add(SCHEMA_VERSION_7);
-        allowableValues.add(SCHEMA_VERSION_V201909);
-        this.allowableValues = Collections.unmodifiableList(allowableValues);
-
-    }
+    private static final ObjectMapper MAPPER = new ObjectMapper();
+    private JsonSchema schema;
 
     @Override
     public Set<Relationship> getRelationships() {
-        return this.relationships;
+        return RELATIONSHIPS;
     }
 
     @Override
     public final List<PropertyDescriptor> getSupportedPropertyDescriptors() {
-        return descriptors;
+        return PROPERTIES;
     }
 
-    private ObjectMapper mapper = new ObjectMapper();
-    private VersionFlag schemaVersion;
-
     @OnScheduled
-    public void onScheduled(final ProcessContext context) {
-        // Set JSON schema version to use from processor property
-        this.schemaVersion = VersionFlag.V201909;
-        if (context.getProperty(SCHEMA_VERSION).getValue() == 
SCHEMA_VERSION_4.getValue()) {
-            this.schemaVersion = VersionFlag.V4;
-        }
-        if (context.getProperty(SCHEMA_VERSION).getValue() == 
SCHEMA_VERSION_6.getValue()) {
-            this.schemaVersion = VersionFlag.V6;
-        }
-        if (context.getProperty(SCHEMA_VERSION).getValue() == 
SCHEMA_VERSION_7.getValue()) {
-            this.schemaVersion = VersionFlag.V7;
-        }
-        if (context.getProperty(SCHEMA_VERSION).getValue() == 
SCHEMA_VERSION_V201909.getValue()) {
-            this.schemaVersion = VersionFlag.V201909;
+    public void onScheduled(final ProcessContext context) throws IOException {
+        try (final InputStream inputStream = 
context.getProperty(SCHEMA_CONTENT).asResource().read()) {
+            String schemaText = IOUtils.toString(inputStream, 
StandardCharsets.UTF_8);
+            JsonSchemaVersion jsonSchemaVersion =
+                    
JsonSchemaVersion.valueOf(context.getProperty(SCHEMA_VERSION).getValue());
+            JsonSchemaFactory factory = 
JsonSchemaFactory.getInstance(jsonSchemaVersion.getVersionFlag());
+            schema = factory.getSchema(schemaText);

Review Comment:
   When I commit that change should I squash my commits to one or leave it as 
two separate commits?



##########
nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/ValidateJson.java:
##########
@@ -105,97 +140,54 @@ public class ValidateJson extends AbstractProcessor {
         .description("FlowFiles that cannot be read as JSON are routed to this 
relationship")
         .build();
 
-    private List<PropertyDescriptor> descriptors;
-
-    private Set<Relationship> relationships;
+    public static final Set<Relationship> RELATIONSHIPS =
+            Collections.unmodifiableSet(new 
HashSet<>(Arrays.asList(REL_FAILURE, REL_VALID, REL_INVALID)));
 
-    private List<AllowableValue> allowableValues;
-
-    @Override
-    protected void init(final ProcessorInitializationContext context) {
-        final List<PropertyDescriptor> descriptors = new 
ArrayList<PropertyDescriptor>();
-        descriptors.add(SCHEMA_TEXT);
-        descriptors.add(SCHEMA_VERSION);
-        this.descriptors = Collections.unmodifiableList(descriptors);
-
-        final Set<Relationship> relationships = new HashSet<Relationship>();
-        relationships.add(REL_VALID);
-        relationships.add(REL_INVALID);
-        relationships.add(REL_FAILURE);
-        this.relationships = Collections.unmodifiableSet(relationships);
-
-        final List<AllowableValue> allowableValues = new 
ArrayList<AllowableValue>();
-        allowableValues.add(SCHEMA_VERSION_4);
-        allowableValues.add(SCHEMA_VERSION_6);
-        allowableValues.add(SCHEMA_VERSION_7);
-        allowableValues.add(SCHEMA_VERSION_V201909);
-        this.allowableValues = Collections.unmodifiableList(allowableValues);
-
-    }
+    private static final ObjectMapper MAPPER = new ObjectMapper();
+    private JsonSchema schema;
 
     @Override
     public Set<Relationship> getRelationships() {
-        return this.relationships;
+        return RELATIONSHIPS;
     }
 
     @Override
     public final List<PropertyDescriptor> getSupportedPropertyDescriptors() {
-        return descriptors;
+        return PROPERTIES;
     }
 
-    private ObjectMapper mapper = new ObjectMapper();
-    private VersionFlag schemaVersion;
-
     @OnScheduled
-    public void onScheduled(final ProcessContext context) {
-        // Set JSON schema version to use from processor property
-        this.schemaVersion = VersionFlag.V201909;
-        if (context.getProperty(SCHEMA_VERSION).getValue() == 
SCHEMA_VERSION_4.getValue()) {
-            this.schemaVersion = VersionFlag.V4;
-        }
-        if (context.getProperty(SCHEMA_VERSION).getValue() == 
SCHEMA_VERSION_6.getValue()) {
-            this.schemaVersion = VersionFlag.V6;
-        }
-        if (context.getProperty(SCHEMA_VERSION).getValue() == 
SCHEMA_VERSION_7.getValue()) {
-            this.schemaVersion = VersionFlag.V7;
-        }
-        if (context.getProperty(SCHEMA_VERSION).getValue() == 
SCHEMA_VERSION_V201909.getValue()) {
-            this.schemaVersion = VersionFlag.V201909;
+    public void onScheduled(final ProcessContext context) throws IOException {
+        try (final InputStream inputStream = 
context.getProperty(SCHEMA_CONTENT).asResource().read()) {
+            String schemaText = IOUtils.toString(inputStream, 
StandardCharsets.UTF_8);
+            JsonSchemaVersion jsonSchemaVersion =
+                    
JsonSchemaVersion.valueOf(context.getProperty(SCHEMA_VERSION).getValue());
+            JsonSchemaFactory factory = 
JsonSchemaFactory.getInstance(jsonSchemaVersion.getVersionFlag());
+            schema = factory.getSchema(schemaText);

Review Comment:
   @exceptionfactory When I commit that change should I squash my commits to 
one or leave it as two separate commits?



-- 
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]

Reply via email to