r65535 commented on code in PR #6337:
URL: https://github.com/apache/nifi/pull/6337#discussion_r981135645


##########
nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/ValidateJson.java:
##########
@@ -0,0 +1,203 @@
+/*
+ * 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.processors.standard;
+
+import org.apache.nifi.components.AllowableValue;
+import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.expression.ExpressionLanguageScope;
+import org.apache.nifi.flowfile.FlowFile;
+import org.apache.nifi.annotation.behavior.EventDriven;
+import org.apache.nifi.annotation.behavior.InputRequirement;
+import org.apache.nifi.annotation.behavior.SideEffectFree;
+import org.apache.nifi.annotation.behavior.SupportsBatching;
+import org.apache.nifi.annotation.behavior.WritesAttribute;
+import org.apache.nifi.annotation.behavior.WritesAttributes;
+import org.apache.nifi.annotation.behavior.InputRequirement.Requirement;
+import org.apache.nifi.annotation.documentation.CapabilityDescription;
+import org.apache.nifi.annotation.documentation.Tags;
+import org.apache.nifi.annotation.lifecycle.OnScheduled;
+import org.apache.nifi.processor.exception.ProcessException;
+import org.apache.nifi.processor.AbstractProcessor;
+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.processor.util.StandardValidators;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.networknt.schema.JsonSchema;
+import com.networknt.schema.JsonSchemaFactory;
+import com.networknt.schema.ValidationMessage;
+import com.networknt.schema.SpecVersion.VersionFlag;
+
+@EventDriven
+@SideEffectFree
+@SupportsBatching
+@InputRequirement(Requirement.INPUT_REQUIRED)
+@Tags({"JSON", "schema", "validation"})
+@WritesAttributes({
+    @WritesAttribute(attribute = "validatejson.invalid.error", description = 
"If the flow file is routed to the invalid relationship "
+            + "the attribute will contain the error message resulting from the 
validation failure.")
+})
+@CapabilityDescription("Validates the contents of FlowFiles against a 
user-specified JSON Schema file")
+public class ValidateJson extends AbstractProcessor {
+
+    public static final String ERROR_ATTRIBUTE_KEY = 
"validatejson.invalid.error";
+
+    public static final AllowableValue SCHEMA_VERSION_4 = new 
AllowableValue("V4");
+    public static final AllowableValue SCHEMA_VERSION_6 = new 
AllowableValue("V6");
+    public static final AllowableValue SCHEMA_VERSION_7 = new 
AllowableValue("V7");
+    public static final AllowableValue SCHEMA_VERSION_V201909 = new 
AllowableValue("V201909");
+
+    public static final PropertyDescriptor SCHEMA_VERSION = new 
PropertyDescriptor
+        .Builder().name("SCHEMA_VERSION")
+        .displayName("Schema Version")
+        .description("The JSON schema specification")
+        .required(true)
+        .allowableValues(SCHEMA_VERSION_4, SCHEMA_VERSION_6, SCHEMA_VERSION_7, 
SCHEMA_VERSION_V201909)
+        .defaultValue(SCHEMA_VERSION_V201909.getValue())
+        .build();
+
+    public static final PropertyDescriptor SCHEMA_TEXT = new PropertyDescriptor
+        .Builder().name("SCHEMA_TEXT")
+        .displayName("Schema Text")
+        .description("The text of a JSON schema")
+        .required(true)
+        .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+        .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+        .build();
+
+    public static final Relationship REL_VALID = new Relationship.Builder()
+        .name("valid")
+        .description("FlowFiles that are successfully validated against the 
schema are routed to this relationship")
+        .build();
+
+    public static final Relationship REL_INVALID = new Relationship.Builder()
+        .name("invalid")
+        .description("FlowFiles that are not valid according to the specified 
schema are routed to this relationship")
+        .build();
+
+    public static final Relationship REL_FAILURE = new Relationship.Builder()
+        .name("failure")
+        .description("FlowFiles that cannot be read as JSON are routed to this 
relationship")
+        .build();
+
+    private List<PropertyDescriptor> descriptors;
+
+    private Set<Relationship> relationships;
+
+    private List<AllowableValue> allowableValues;

Review Comment:
   I'll keep this in so it's consistent with other processors (as a lot seem to 
do this)



-- 
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: issues-unsubscr...@nifi.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to