You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nifi.apache.org by mc...@apache.org on 2016/06/21 00:31:04 UTC
[1/5] nifi git commit: NIFI-1850 - Initial Commit for JSON-to-JSON
Schema Converter Editor (merge from 0.7.0 - refactor for masterless cluster).
This closes #511
Repository: nifi
Updated Branches:
refs/heads/master 274dc0902 -> cb3aa8f5c
http://git-wip-us.apache.org/repos/asf/nifi/blob/cb3aa8f5/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestTransformJSON.java
----------------------------------------------------------------------
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestTransformJSON.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestTransformJSON.java
deleted file mode 100644
index e19d320..0000000
--- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestTransformJSON.java
+++ /dev/null
@@ -1,318 +0,0 @@
-/*
- * 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 java.io.IOException;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.nio.file.Paths;
-import java.util.Arrays;
-import java.util.List;
-import java.util.Set;
-
-import org.apache.nifi.flowfile.attributes.CoreAttributes;
-import org.apache.nifi.processor.Processor;
-import org.apache.nifi.processor.Relationship;
-import org.apache.nifi.stream.io.ByteArrayInputStream;
-import org.apache.nifi.util.MockFlowFile;
-import org.apache.nifi.util.StringUtils;
-import org.apache.nifi.util.TestRunner;
-import org.apache.nifi.util.TestRunners;
-import org.junit.Test;
-
-import com.bazaarvoice.jolt.CardinalityTransform;
-import com.bazaarvoice.jolt.Chainr;
-import com.bazaarvoice.jolt.Defaultr;
-import com.bazaarvoice.jolt.Diffy;
-import com.bazaarvoice.jolt.JsonUtils;
-import com.bazaarvoice.jolt.Removr;
-import com.bazaarvoice.jolt.Shiftr;
-import com.bazaarvoice.jolt.Sortr;
-import com.bazaarvoice.jolt.Transform;
-
-import static org.junit.Assert.assertTrue;
-
-public class TestTransformJSON {
-
- final static Path JSON_INPUT = Paths.get("src/test/resources/TestTransformJson/input.json");
- final static Diffy DIFFY = new Diffy();
-
- @Test
- public void testRelationshipsCreated() throws IOException{
- Processor processor= new TransformJSON();
- final TestRunner runner = TestRunners.newTestRunner(processor);
- final String spec = new String(Files.readAllBytes(Paths.get("src/test/resources/TestTransformJson/chainrSpec.json")));
- runner.setProperty(TransformJSON.JOLT_SPEC, spec);
- runner.enqueue(JSON_INPUT);
- Set<Relationship> relationships = processor.getRelationships();
- assertTrue(relationships.contains(TransformJSON.REL_FAILURE));
- assertTrue(relationships.contains(TransformJSON.REL_SUCCESS));
- assertTrue(relationships.size() == 2);
- }
-
- @Test
- public void testInvalidJOLTSpec() throws IOException {
- final TestRunner runner = TestRunners.newTestRunner(new TransformJSON());
- final String spec = "[{}]";
- runner.setProperty(TransformJSON.JOLT_SPEC, spec);
- runner.assertNotValid();
- }
-
- @Test
- public void testIncorrectJOLTSpec() throws IOException {
- final TestRunner runner = TestRunners.newTestRunner(new TransformJSON());
- final String chainrSpec = new String(Files.readAllBytes(Paths.get("src/test/resources/TestTransformJson/chainrSpec.json")));
- runner.setProperty(TransformJSON.JOLT_SPEC, chainrSpec);
- runner.setProperty(TransformJSON.JOLT_TRANSFORM, TransformJSON.SHIFTR);
- runner.assertNotValid();
- }
-
- @Test
- public void testSpecIsNotSet() throws IOException {
- final TestRunner runner = TestRunners.newTestRunner(new TransformJSON());
- runner.setProperty(TransformJSON.JOLT_TRANSFORM, TransformJSON.SHIFTR);
- runner.assertNotValid();
- }
-
- @Test
- public void testSpecIsEmpty() throws IOException {
- final TestRunner runner = TestRunners.newTestRunner(new TransformJSON());
- runner.setProperty(TransformJSON.JOLT_SPEC, StringUtils.EMPTY);
- runner.setProperty(TransformJSON.JOLT_TRANSFORM, TransformJSON.SHIFTR);
- runner.assertNotValid();
- }
-
- @Test
- public void testSpecNotRequired() throws IOException {
- final TestRunner runner = TestRunners.newTestRunner(new TransformJSON());
- runner.setProperty(TransformJSON.JOLT_TRANSFORM, TransformJSON.SORTR);
- runner.assertValid();
- }
-
- @Test
- public void testNoFlowFileContent() throws IOException {
- final TestRunner runner = TestRunners.newTestRunner(new TransformJSON());
- final String spec = new String(Files.readAllBytes(Paths.get("src/test/resources/TestTransformJson/chainrSpec.json")));
- runner.setProperty(TransformJSON.JOLT_SPEC, spec);
- runner.run();
- runner.assertQueueEmpty();
- runner.assertTransferCount(TransformJSON.REL_FAILURE,0);
- runner.assertTransferCount(TransformJSON.REL_SUCCESS,0);
- }
-
- @Test
- public void testInvalidFlowFileContentJson() throws IOException {
- final TestRunner runner = TestRunners.newTestRunner(new TransformJSON());
- final String spec = new String(Files.readAllBytes(Paths.get("src/test/resources/TestTransformJson/chainrSpec.json")));
- runner.setProperty(TransformJSON.JOLT_SPEC, spec);
- runner.enqueue("invalid json");
- runner.run();
- runner.assertAllFlowFilesTransferred(TransformJSON.REL_FAILURE);
- }
-
- @Test
- @SuppressWarnings("unchecked")
- public void testGetChainTransform() throws NoSuchMethodException, IOException,InvocationTargetException, IllegalAccessException{
-
- final String chainrSpec = new String(Files.readAllBytes(Paths.get("src/test/resources/TestTransformJson/chainrSpec.json")));
- List<Class> classes = Arrays.<Class>asList(TransformJSON.class.getDeclaredClasses());
- Class factory = classes.stream().filter(clazz -> clazz.getSimpleName().equals("TransformationFactory")).findFirst().get();
- Method method = factory.getDeclaredMethod("getTransform", String.class, Object.class);
- method.setAccessible(true);
- Transform transform = (Transform) method.invoke(null,TransformJSON.CHAINR.getValue(),JsonUtils.jsonToObject(chainrSpec));
- assertTrue(transform instanceof Chainr);
-
- }
-
- @Test
- @SuppressWarnings("unchecked")
- public void testGetRemoveTransform() throws NoSuchMethodException, IOException,InvocationTargetException, IllegalAccessException{
-
- final String removrSpec = new String(Files.readAllBytes(Paths.get("src/test/resources/TestTransformJson/removrSpec.json")));
- List<Class> classes = Arrays.<Class>asList(TransformJSON.class.getDeclaredClasses());
- Class factory = classes.stream().filter(clazz -> clazz.getSimpleName().equals("TransformationFactory")).findFirst().get();
- Method method = factory.getDeclaredMethod("getTransform", String.class, Object.class);
- method.setAccessible(true);
- Transform transform = (Transform) method.invoke(null,TransformJSON.REMOVR.getValue(),JsonUtils.jsonToObject(removrSpec));
- assertTrue(transform instanceof Removr);
-
- }
-
- @Test
- @SuppressWarnings("unchecked")
- public void testGetShiftTransform() throws NoSuchMethodException, IOException,InvocationTargetException, IllegalAccessException{
-
- final String shiftrSpec = new String(Files.readAllBytes(Paths.get("src/test/resources/TestTransformJson/shiftrSpec.json")));
- List<Class> classes = Arrays.<Class>asList(TransformJSON.class.getDeclaredClasses());
- Class factory = classes.stream().filter(clazz -> clazz.getSimpleName().equals("TransformationFactory")).findFirst().get();
- Method method = factory.getDeclaredMethod("getTransform", String.class, Object.class);
- method.setAccessible(true);
- Transform transform = (Transform) method.invoke(null,TransformJSON.SHIFTR.getValue(),JsonUtils.jsonToObject(shiftrSpec));
- assertTrue(transform instanceof Shiftr);
- }
-
- @Test
- @SuppressWarnings("unchecked")
- public void testGetDefaultTransform() throws NoSuchMethodException, IOException,InvocationTargetException, IllegalAccessException{
-
- final String defaultrSpec = new String(Files.readAllBytes(Paths.get("src/test/resources/TestTransformJson/defaultrSpec.json")));
- List<Class> classes = Arrays.<Class>asList(TransformJSON.class.getDeclaredClasses());
- Class factory = classes.stream().filter(clazz -> clazz.getSimpleName().equals("TransformationFactory")).findFirst().get();
- Method method = factory.getDeclaredMethod("getTransform", String.class, Object.class);
- method.setAccessible(true);
- Transform transform = (Transform) method.invoke(null,TransformJSON.DEFAULTR.getValue(),JsonUtils.jsonToObject(defaultrSpec));
- assertTrue(transform instanceof Defaultr);
- }
-
- @Test
- @SuppressWarnings("unchecked")
- public void testGetCardinalityTransform() throws NoSuchMethodException, IOException,InvocationTargetException, IllegalAccessException{
-
- final String cardrSpec = new String(Files.readAllBytes(Paths.get("src/test/resources/TestTransformJson/cardrSpec.json")));
- List<Class> classes = Arrays.<Class>asList(TransformJSON.class.getDeclaredClasses());
- Class factory = classes.stream().filter(clazz -> clazz.getSimpleName().equals("TransformationFactory")).findFirst().get();
- Method method = factory.getDeclaredMethod("getTransform", String.class, Object.class);
- method.setAccessible(true);
- Transform transform = (Transform) method.invoke(null,TransformJSON.CARDINALITY.getValue(),JsonUtils.jsonToObject(cardrSpec));
- assertTrue(transform instanceof CardinalityTransform);
- }
-
- @Test
- @SuppressWarnings("unchecked")
- public void testGetSortrTransform() throws NoSuchMethodException, IOException,InvocationTargetException, IllegalAccessException{
- List<Class> classes = Arrays.<Class>asList(TransformJSON.class.getDeclaredClasses());
- Class factory = classes.stream().filter(clazz -> clazz.getSimpleName().equals("TransformationFactory")).findFirst().get();
- Method method = factory.getDeclaredMethod("getTransform", String.class, Object.class);
- method.setAccessible(true);
- Transform transform = (Transform) method.invoke(null,TransformJSON.SORTR.getValue(),null);
- assertTrue(transform instanceof Sortr);
- }
-
-
- @Test
- @SuppressWarnings("unchecked")
- public void testGetInvalidTransformWithNoSpec() throws NoSuchMethodException, IOException,InvocationTargetException, IllegalAccessException{
- List<Class> classes = Arrays.<Class>asList(TransformJSON.class.getDeclaredClasses());
- Class factory = classes.stream().filter(clazz -> clazz.getSimpleName().equals("TransformationFactory")).findFirst().get();
- Method method = factory.getDeclaredMethod("getTransform", String.class, Object.class);
- method.setAccessible(true);
- try {
- method.invoke(null, TransformJSON.CHAINR.getValue(), null);
- }catch (InvocationTargetException ite){
- assertTrue(ite.getTargetException().getLocalizedMessage().equals("JOLT Chainr expects a JSON array of objects - Malformed spec."));
- }
- }
-
- @Test
- public void testTransformInputWithChainr() throws IOException {
- final TestRunner runner = TestRunners.newTestRunner(new TransformJSON());
- final String spec = new String(Files.readAllBytes(Paths.get("src/test/resources/TestTransformJson/chainrSpec.json")));
- runner.setProperty(TransformJSON.JOLT_SPEC, spec);
- runner.enqueue(JSON_INPUT);
- runner.run();
- runner.assertAllFlowFilesTransferred(TransformJSON.REL_SUCCESS);
- final MockFlowFile transformed = runner.getFlowFilesForRelationship(TransformJSON.REL_SUCCESS).get(0);
- transformed.assertAttributeExists(CoreAttributes.MIME_TYPE.key());
- transformed.assertAttributeEquals(CoreAttributes.MIME_TYPE.key(),"application/json");
- Object transformedJson = JsonUtils.jsonToObject(new ByteArrayInputStream(transformed.toByteArray()));
- Object compareJson = JsonUtils.jsonToObject(Files.newInputStream(Paths.get("src/test/resources/TestTransformJson/chainrOutput.json")));
- assertTrue(DIFFY.diff(compareJson, transformedJson).isEmpty());
- }
-
- @Test
- public void testTransformInputWithShiftr() throws IOException {
- final TestRunner runner = TestRunners.newTestRunner(new TransformJSON());
- final String spec = new String(Files.readAllBytes(Paths.get("src/test/resources/TestTransformJson/shiftrSpec.json")));
- runner.setProperty(TransformJSON.JOLT_SPEC, spec);
- runner.setProperty(TransformJSON.JOLT_TRANSFORM, TransformJSON.SHIFTR);
- runner.enqueue(JSON_INPUT);
- runner.run();
- runner.assertAllFlowFilesTransferred(TransformJSON.REL_SUCCESS);
- final MockFlowFile transformed = runner.getFlowFilesForRelationship(TransformJSON.REL_SUCCESS).get(0);
- transformed.assertAttributeExists(CoreAttributes.MIME_TYPE.key());
- transformed.assertAttributeEquals(CoreAttributes.MIME_TYPE.key(),"application/json");
- Object transformedJson = JsonUtils.jsonToObject(new ByteArrayInputStream(transformed.toByteArray()));
- Object compareJson = JsonUtils.jsonToObject(Files.newInputStream(Paths.get("src/test/resources/TestTransformJson/shiftrOutput.json")));
- assertTrue(DIFFY.diff(compareJson, transformedJson).isEmpty());
- }
-
- @Test
- public void testTransformInputWithDefaultr() throws IOException {
- final TestRunner runner = TestRunners.newTestRunner(new TransformJSON());
- final String spec = new String(Files.readAllBytes(Paths.get("src/test/resources/TestTransformJson/defaultrSpec.json")));
- runner.setProperty(TransformJSON.JOLT_SPEC, spec);
- runner.setProperty(TransformJSON.JOLT_TRANSFORM, TransformJSON.DEFAULTR);
- runner.enqueue(JSON_INPUT);
- runner.run();
- runner.assertAllFlowFilesTransferred(TransformJSON.REL_SUCCESS);
- final MockFlowFile transformed = runner.getFlowFilesForRelationship(TransformJSON.REL_SUCCESS).get(0);
- Object transformedJson = JsonUtils.jsonToObject(new ByteArrayInputStream(transformed.toByteArray()));
- Object compareJson = JsonUtils.jsonToObject(Files.newInputStream(Paths.get("src/test/resources/TestTransformJson/defaultrOutput.json")));
- assertTrue(DIFFY.diff(compareJson, transformedJson).isEmpty());
- }
-
- @Test
- public void testTransformInputWithRemovr() throws IOException {
- final TestRunner runner = TestRunners.newTestRunner(new TransformJSON());
- final String spec = new String(Files.readAllBytes(Paths.get("src/test/resources/TestTransformJson/removrSpec.json")));
- runner.setProperty(TransformJSON.JOLT_SPEC, spec);
- runner.setProperty(TransformJSON.JOLT_TRANSFORM, TransformJSON.REMOVR);
- runner.enqueue(JSON_INPUT);
- runner.run();
- runner.assertAllFlowFilesTransferred(TransformJSON.REL_SUCCESS);
- final MockFlowFile transformed = runner.getFlowFilesForRelationship(TransformJSON.REL_SUCCESS).get(0);
- Object transformedJson = JsonUtils.jsonToObject(new ByteArrayInputStream(transformed.toByteArray()));
- Object compareJson = JsonUtils.jsonToObject(Files.newInputStream(Paths.get("src/test/resources/TestTransformJson/removrOutput.json")));
- assertTrue(DIFFY.diff(compareJson, transformedJson).isEmpty());
- }
-
- @Test
- public void testTransformInputWithCardinality() throws IOException {
- final TestRunner runner = TestRunners.newTestRunner(new TransformJSON());
- final String spec = new String(Files.readAllBytes(Paths.get("src/test/resources/TestTransformJson/cardrSpec.json")));
- runner.setProperty(TransformJSON.JOLT_SPEC, spec);
- runner.setProperty(TransformJSON.JOLT_TRANSFORM, TransformJSON.CARDINALITY);
- runner.enqueue(JSON_INPUT);
- runner.run();
- runner.assertAllFlowFilesTransferred(TransformJSON.REL_SUCCESS);
- final MockFlowFile transformed = runner.getFlowFilesForRelationship(TransformJSON.REL_SUCCESS).get(0);
- Object transformedJson = JsonUtils.jsonToObject(new ByteArrayInputStream(transformed.toByteArray()));
- Object compareJson = JsonUtils.jsonToObject(Files.newInputStream(Paths.get("src/test/resources/TestTransformJson/cardrOutput.json")));
- assertTrue(DIFFY.diff(compareJson, transformedJson).isEmpty());
- }
-
- @Test
- public void testTransformInputWithSortr() throws IOException {
- final TestRunner runner = TestRunners.newTestRunner(new TransformJSON());
- runner.setProperty(TransformJSON.JOLT_TRANSFORM, TransformJSON.SORTR);
- runner.enqueue(JSON_INPUT);
- runner.run();
- runner.assertAllFlowFilesTransferred(TransformJSON.REL_SUCCESS);
- final MockFlowFile transformed = runner.getFlowFilesForRelationship(TransformJSON.REL_SUCCESS).get(0);
- transformed.assertAttributeExists(CoreAttributes.MIME_TYPE.key());
- transformed.assertAttributeEquals(CoreAttributes.MIME_TYPE.key(),"application/json");
- Object transformedJson = JsonUtils.jsonToObject(new ByteArrayInputStream(transformed.toByteArray()));
- Object compareJson = JsonUtils.jsonToObject(Files.newInputStream(Paths.get("src/test/resources/TestTransformJson/sortrOutput.json")));
- String transformedJsonString = JsonUtils.toJsonString(transformedJson);
- String compareJsonString = JsonUtils.toJsonString(compareJson);
- assertTrue(compareJsonString.equals(transformedJsonString));
- }
-
-
-}
http://git-wip-us.apache.org/repos/asf/nifi/blob/cb3aa8f5/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/resources/TestJoltTransformJson/cardrOutput.json
----------------------------------------------------------------------
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/resources/TestJoltTransformJson/cardrOutput.json b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/resources/TestJoltTransformJson/cardrOutput.json
new file mode 100644
index 0000000..3dc53ab
--- /dev/null
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/resources/TestJoltTransformJson/cardrOutput.json
@@ -0,0 +1,13 @@
+{
+ "rating": {
+ "primary": {
+ "value": 3
+ },
+ "quality": {
+ "value": 3
+ },
+ "series": {
+ "value": 5
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/nifi/blob/cb3aa8f5/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/resources/TestJoltTransformJson/cardrSpec.json
----------------------------------------------------------------------
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/resources/TestJoltTransformJson/cardrSpec.json b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/resources/TestJoltTransformJson/cardrSpec.json
new file mode 100644
index 0000000..fc77f18
--- /dev/null
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/resources/TestJoltTransformJson/cardrSpec.json
@@ -0,0 +1,7 @@
+{
+ "rating" : {
+ "series" : {
+ "value" : "ONE"
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/nifi/blob/cb3aa8f5/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/resources/TestJoltTransformJson/chainrOutput.json
----------------------------------------------------------------------
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/resources/TestJoltTransformJson/chainrOutput.json b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/resources/TestJoltTransformJson/chainrOutput.json
new file mode 100644
index 0000000..2e8af88
--- /dev/null
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/resources/TestJoltTransformJson/chainrOutput.json
@@ -0,0 +1,16 @@
+{
+ "Range" : 5,
+ "Rating" : 3,
+ "SecondaryRatings" : {
+ "quality" : {
+ "Id" : "quality",
+ "Range" : 5,
+ "Value" : 3
+ },
+ "series" : {
+ "Id" : "series",
+ "Range" : 5,
+ "Value" : [5,4]
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/nifi/blob/cb3aa8f5/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/resources/TestJoltTransformJson/chainrSpec.json
----------------------------------------------------------------------
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/resources/TestJoltTransformJson/chainrSpec.json b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/resources/TestJoltTransformJson/chainrSpec.json
new file mode 100644
index 0000000..7884abf
--- /dev/null
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/resources/TestJoltTransformJson/chainrSpec.json
@@ -0,0 +1,29 @@
+[
+ {
+ "operation": "shift",
+ "spec": {
+ "rating": {
+ "primary": {
+ "value": "Rating",
+ "max": "RatingRange"
+ },
+ "*": {
+ "max": "SecondaryRatings.&1.Range",
+ "value": "SecondaryRatings.&1.Value",
+ "$": "SecondaryRatings.&1.Id"
+ }
+ }
+ }
+ },
+ {
+ "operation": "default",
+ "spec": {
+ "Range": 5,
+ "SecondaryRatings": {
+ "*": {
+ "Range": 5
+ }
+ }
+ }
+ }
+]
http://git-wip-us.apache.org/repos/asf/nifi/blob/cb3aa8f5/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/resources/TestJoltTransformJson/defaultrOutput.json
----------------------------------------------------------------------
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/resources/TestJoltTransformJson/defaultrOutput.json b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/resources/TestJoltTransformJson/defaultrOutput.json
new file mode 100644
index 0000000..87581f4
--- /dev/null
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/resources/TestJoltTransformJson/defaultrOutput.json
@@ -0,0 +1,24 @@
+{
+ "RatingRange" : 5,
+ "rating": {
+ "primary": {
+ "value": 3,
+ "MaxLabel": "High",
+ "MinLabel": "Low",
+ "DisplayType": "NORMAL"
+ },
+ "quality": {
+ "value": 3,
+ "MaxLabel": "High",
+ "MinLabel": "Low",
+ "DisplayType": "NORMAL"
+ },
+ "series": {
+ "value": [5,4],
+ "MaxLabel": "High",
+ "MinLabel": "Low",
+ "DisplayType": "NORMAL"
+ }
+
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/nifi/blob/cb3aa8f5/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/resources/TestJoltTransformJson/defaultrSpec.json
----------------------------------------------------------------------
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/resources/TestJoltTransformJson/defaultrSpec.json b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/resources/TestJoltTransformJson/defaultrSpec.json
new file mode 100644
index 0000000..2f2ea9f
--- /dev/null
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/resources/TestJoltTransformJson/defaultrSpec.json
@@ -0,0 +1,10 @@
+ {
+ "RatingRange" : 5,
+ "rating": {
+ "*": {
+ "MaxLabel": "High",
+ "MinLabel": "Low",
+ "DisplayType": "NORMAL"
+ }
+ }
+ }
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/nifi/blob/cb3aa8f5/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/resources/TestJoltTransformJson/input.json
----------------------------------------------------------------------
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/resources/TestJoltTransformJson/input.json b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/resources/TestJoltTransformJson/input.json
new file mode 100644
index 0000000..12d85db
--- /dev/null
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/resources/TestJoltTransformJson/input.json
@@ -0,0 +1,13 @@
+{
+ "rating": {
+ "primary": {
+ "value": 3
+ },
+ "series": {
+ "value": [5,4]
+ },
+ "quality": {
+ "value": 3
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/nifi/blob/cb3aa8f5/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/resources/TestJoltTransformJson/removrOutput.json
----------------------------------------------------------------------
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/resources/TestJoltTransformJson/removrOutput.json b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/resources/TestJoltTransformJson/removrOutput.json
new file mode 100644
index 0000000..da0de3a
--- /dev/null
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/resources/TestJoltTransformJson/removrOutput.json
@@ -0,0 +1,10 @@
+{
+ "rating": {
+ "primary": {
+ "value": 3
+ },
+ "series":{
+ "value":[5,4]
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/nifi/blob/cb3aa8f5/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/resources/TestJoltTransformJson/removrSpec.json
----------------------------------------------------------------------
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/resources/TestJoltTransformJson/removrSpec.json b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/resources/TestJoltTransformJson/removrSpec.json
new file mode 100644
index 0000000..a6bde70
--- /dev/null
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/resources/TestJoltTransformJson/removrSpec.json
@@ -0,0 +1,5 @@
+{
+ "rating": {
+ "quality": ""
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/nifi/blob/cb3aa8f5/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/resources/TestJoltTransformJson/shiftrOutput.json
----------------------------------------------------------------------
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/resources/TestJoltTransformJson/shiftrOutput.json b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/resources/TestJoltTransformJson/shiftrOutput.json
new file mode 100644
index 0000000..8fd6c3b
--- /dev/null
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/resources/TestJoltTransformJson/shiftrOutput.json
@@ -0,0 +1,8 @@
+{
+ "SecondaryRatings" : {
+ "quality" : {
+ "Value" : 3,
+ "RatingRange" : 3
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/nifi/blob/cb3aa8f5/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/resources/TestJoltTransformJson/shiftrSpec.json
----------------------------------------------------------------------
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/resources/TestJoltTransformJson/shiftrSpec.json b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/resources/TestJoltTransformJson/shiftrSpec.json
new file mode 100644
index 0000000..d292cdd
--- /dev/null
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/resources/TestJoltTransformJson/shiftrSpec.json
@@ -0,0 +1,10 @@
+{
+ "rating": {
+ "primary": {
+ "value": "SecondaryRatings.quality.RatingRange"
+ },
+ "quality": {
+ "value": "SecondaryRatings.quality.Value"
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/nifi/blob/cb3aa8f5/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/resources/TestJoltTransformJson/sortrOutput.json
----------------------------------------------------------------------
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/resources/TestJoltTransformJson/sortrOutput.json b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/resources/TestJoltTransformJson/sortrOutput.json
new file mode 100644
index 0000000..ee559da
--- /dev/null
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/resources/TestJoltTransformJson/sortrOutput.json
@@ -0,0 +1,13 @@
+{
+ "rating": {
+ "primary": {
+ "value": 3
+ },
+ "quality": {
+ "value": 3
+ },
+ "series": {
+ "value": [5,4]
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/nifi/blob/cb3aa8f5/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/resources/TestTransformJson/cardrOutput.json
----------------------------------------------------------------------
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/resources/TestTransformJson/cardrOutput.json b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/resources/TestTransformJson/cardrOutput.json
deleted file mode 100644
index 3dc53ab..0000000
--- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/resources/TestTransformJson/cardrOutput.json
+++ /dev/null
@@ -1,13 +0,0 @@
-{
- "rating": {
- "primary": {
- "value": 3
- },
- "quality": {
- "value": 3
- },
- "series": {
- "value": 5
- }
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/nifi/blob/cb3aa8f5/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/resources/TestTransformJson/cardrSpec.json
----------------------------------------------------------------------
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/resources/TestTransformJson/cardrSpec.json b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/resources/TestTransformJson/cardrSpec.json
deleted file mode 100644
index fc77f18..0000000
--- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/resources/TestTransformJson/cardrSpec.json
+++ /dev/null
@@ -1,7 +0,0 @@
-{
- "rating" : {
- "series" : {
- "value" : "ONE"
- }
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/nifi/blob/cb3aa8f5/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/resources/TestTransformJson/chainrOutput.json
----------------------------------------------------------------------
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/resources/TestTransformJson/chainrOutput.json b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/resources/TestTransformJson/chainrOutput.json
deleted file mode 100644
index 2e8af88..0000000
--- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/resources/TestTransformJson/chainrOutput.json
+++ /dev/null
@@ -1,16 +0,0 @@
-{
- "Range" : 5,
- "Rating" : 3,
- "SecondaryRatings" : {
- "quality" : {
- "Id" : "quality",
- "Range" : 5,
- "Value" : 3
- },
- "series" : {
- "Id" : "series",
- "Range" : 5,
- "Value" : [5,4]
- }
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/nifi/blob/cb3aa8f5/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/resources/TestTransformJson/chainrSpec.json
----------------------------------------------------------------------
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/resources/TestTransformJson/chainrSpec.json b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/resources/TestTransformJson/chainrSpec.json
deleted file mode 100644
index 7884abf..0000000
--- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/resources/TestTransformJson/chainrSpec.json
+++ /dev/null
@@ -1,29 +0,0 @@
-[
- {
- "operation": "shift",
- "spec": {
- "rating": {
- "primary": {
- "value": "Rating",
- "max": "RatingRange"
- },
- "*": {
- "max": "SecondaryRatings.&1.Range",
- "value": "SecondaryRatings.&1.Value",
- "$": "SecondaryRatings.&1.Id"
- }
- }
- }
- },
- {
- "operation": "default",
- "spec": {
- "Range": 5,
- "SecondaryRatings": {
- "*": {
- "Range": 5
- }
- }
- }
- }
-]
http://git-wip-us.apache.org/repos/asf/nifi/blob/cb3aa8f5/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/resources/TestTransformJson/defaultrOutput.json
----------------------------------------------------------------------
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/resources/TestTransformJson/defaultrOutput.json b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/resources/TestTransformJson/defaultrOutput.json
deleted file mode 100644
index 87581f4..0000000
--- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/resources/TestTransformJson/defaultrOutput.json
+++ /dev/null
@@ -1,24 +0,0 @@
-{
- "RatingRange" : 5,
- "rating": {
- "primary": {
- "value": 3,
- "MaxLabel": "High",
- "MinLabel": "Low",
- "DisplayType": "NORMAL"
- },
- "quality": {
- "value": 3,
- "MaxLabel": "High",
- "MinLabel": "Low",
- "DisplayType": "NORMAL"
- },
- "series": {
- "value": [5,4],
- "MaxLabel": "High",
- "MinLabel": "Low",
- "DisplayType": "NORMAL"
- }
-
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/nifi/blob/cb3aa8f5/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/resources/TestTransformJson/defaultrSpec.json
----------------------------------------------------------------------
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/resources/TestTransformJson/defaultrSpec.json b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/resources/TestTransformJson/defaultrSpec.json
deleted file mode 100644
index 2f2ea9f..0000000
--- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/resources/TestTransformJson/defaultrSpec.json
+++ /dev/null
@@ -1,10 +0,0 @@
- {
- "RatingRange" : 5,
- "rating": {
- "*": {
- "MaxLabel": "High",
- "MinLabel": "Low",
- "DisplayType": "NORMAL"
- }
- }
- }
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/nifi/blob/cb3aa8f5/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/resources/TestTransformJson/input.json
----------------------------------------------------------------------
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/resources/TestTransformJson/input.json b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/resources/TestTransformJson/input.json
deleted file mode 100644
index 12d85db..0000000
--- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/resources/TestTransformJson/input.json
+++ /dev/null
@@ -1,13 +0,0 @@
-{
- "rating": {
- "primary": {
- "value": 3
- },
- "series": {
- "value": [5,4]
- },
- "quality": {
- "value": 3
- }
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/nifi/blob/cb3aa8f5/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/resources/TestTransformJson/removrOutput.json
----------------------------------------------------------------------
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/resources/TestTransformJson/removrOutput.json b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/resources/TestTransformJson/removrOutput.json
deleted file mode 100644
index da0de3a..0000000
--- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/resources/TestTransformJson/removrOutput.json
+++ /dev/null
@@ -1,10 +0,0 @@
-{
- "rating": {
- "primary": {
- "value": 3
- },
- "series":{
- "value":[5,4]
- }
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/nifi/blob/cb3aa8f5/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/resources/TestTransformJson/removrSpec.json
----------------------------------------------------------------------
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/resources/TestTransformJson/removrSpec.json b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/resources/TestTransformJson/removrSpec.json
deleted file mode 100644
index a6bde70..0000000
--- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/resources/TestTransformJson/removrSpec.json
+++ /dev/null
@@ -1,5 +0,0 @@
-{
- "rating": {
- "quality": ""
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/nifi/blob/cb3aa8f5/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/resources/TestTransformJson/shiftrOutput.json
----------------------------------------------------------------------
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/resources/TestTransformJson/shiftrOutput.json b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/resources/TestTransformJson/shiftrOutput.json
deleted file mode 100644
index 8fd6c3b..0000000
--- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/resources/TestTransformJson/shiftrOutput.json
+++ /dev/null
@@ -1,8 +0,0 @@
-{
- "SecondaryRatings" : {
- "quality" : {
- "Value" : 3,
- "RatingRange" : 3
- }
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/nifi/blob/cb3aa8f5/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/resources/TestTransformJson/shiftrSpec.json
----------------------------------------------------------------------
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/resources/TestTransformJson/shiftrSpec.json b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/resources/TestTransformJson/shiftrSpec.json
deleted file mode 100644
index d292cdd..0000000
--- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/resources/TestTransformJson/shiftrSpec.json
+++ /dev/null
@@ -1,10 +0,0 @@
-{
- "rating": {
- "primary": {
- "value": "SecondaryRatings.quality.RatingRange"
- },
- "quality": {
- "value": "SecondaryRatings.quality.Value"
- }
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/nifi/blob/cb3aa8f5/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/resources/TestTransformJson/sortrOutput.json
----------------------------------------------------------------------
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/resources/TestTransformJson/sortrOutput.json b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/resources/TestTransformJson/sortrOutput.json
deleted file mode 100644
index ee559da..0000000
--- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/resources/TestTransformJson/sortrOutput.json
+++ /dev/null
@@ -1,13 +0,0 @@
-{
- "rating": {
- "primary": {
- "value": 3
- },
- "quality": {
- "value": 3
- },
- "series": {
- "value": [5,4]
- }
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/nifi/blob/cb3aa8f5/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-utils/pom.xml
----------------------------------------------------------------------
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-utils/pom.xml b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-utils/pom.xml
new file mode 100644
index 0000000..f8a149f
--- /dev/null
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-utils/pom.xml
@@ -0,0 +1,65 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- 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. -->
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <parent>
+ <artifactId>nifi-standard-bundle</artifactId>
+ <groupId>org.apache.nifi</groupId>
+ <version>1.0.0-SNAPSHOT</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+
+ <artifactId>nifi-standard-utils</artifactId>
+
+ <dependencies>
+ <dependency>
+ <groupId>com.bazaarvoice.jolt</groupId>
+ <artifactId>jolt-core</artifactId>
+ <version>0.0.20</version>
+ </dependency>
+ <dependency>
+ <groupId>com.bazaarvoice.jolt</groupId>
+ <artifactId>json-utils</artifactId>
+ <version>0.0.20</version>
+ </dependency>
+ <dependency>
+ <groupId>com.fasterxml.jackson.core</groupId>
+ <artifactId>jackson-core</artifactId>
+ <version>2.6.2</version>
+ </dependency>
+ <dependency>
+ <groupId>com.fasterxml.jackson.core</groupId>
+ <artifactId>jackson-annotations</artifactId>
+ <version>2.6.2</version>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.rat</groupId>
+ <artifactId>apache-rat-plugin</artifactId>
+ <configuration>
+ <excludes combine.children="append">
+ <exclude>src/test/resources/TestTransformFactory/chainrSpec.json</exclude>
+ <exclude>src/test/resources/TestTransformFactory/cardrSpec.json</exclude>
+ <exclude>src/test/resources/TestTransformFactory/defaultrSpec.json</exclude>
+ <exclude>src/test/resources/TestTransformFactory/shiftrSpec.json</exclude>
+ <exclude>src/test/resources/TestTransformFactory/removrSpec.json</exclude>
+ <exclude>src/test/resources/TestTransformJFactory/defaultrSpec.json</exclude>
+ </excludes>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/nifi/blob/cb3aa8f5/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-utils/src/main/java/org/apache/nifi/processors/standard/util/TransformFactory.java
----------------------------------------------------------------------
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-utils/src/main/java/org/apache/nifi/processors/standard/util/TransformFactory.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-utils/src/main/java/org/apache/nifi/processors/standard/util/TransformFactory.java
new file mode 100644
index 0000000..5bb8374
--- /dev/null
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-utils/src/main/java/org/apache/nifi/processors/standard/util/TransformFactory.java
@@ -0,0 +1,46 @@
+/*
+ * 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.util;
+
+import com.bazaarvoice.jolt.CardinalityTransform;
+import com.bazaarvoice.jolt.Chainr;
+import com.bazaarvoice.jolt.Defaultr;
+import com.bazaarvoice.jolt.Removr;
+import com.bazaarvoice.jolt.Shiftr;
+import com.bazaarvoice.jolt.Sortr;
+import com.bazaarvoice.jolt.Transform;
+
+public class TransformFactory {
+
+ public static Transform getTransform(String transform, Object specJson) {
+ if (transform.equals("jolt-transform-default")) {
+ return new Defaultr(specJson);
+ } else if (transform.equals("jolt-transform-shift")) {
+ return new Shiftr(specJson);
+ } else if (transform.equals("jolt-transform-remove")) {
+ return new Removr(specJson);
+ } else if (transform.equals("jolt-transform-card")) {
+ return new CardinalityTransform(specJson);
+ } else if(transform.equals("jolt-transform-sort")){
+ return new Sortr();
+ } else {
+ return Chainr.fromSpec(specJson);
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/nifi/blob/cb3aa8f5/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-utils/src/test/java/org/apache/nifi/processors/standard/util/TestTransformFactory.java
----------------------------------------------------------------------
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-utils/src/test/java/org/apache/nifi/processors/standard/util/TestTransformFactory.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-utils/src/test/java/org/apache/nifi/processors/standard/util/TestTransformFactory.java
new file mode 100644
index 0000000..e2be189
--- /dev/null
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-utils/src/test/java/org/apache/nifi/processors/standard/util/TestTransformFactory.java
@@ -0,0 +1,89 @@
+/*
+ * 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.util;
+
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+
+import org.junit.Test;
+
+import com.bazaarvoice.jolt.CardinalityTransform;
+import com.bazaarvoice.jolt.Chainr;
+import com.bazaarvoice.jolt.Defaultr;
+import com.bazaarvoice.jolt.JsonUtils;
+import com.bazaarvoice.jolt.Removr;
+import com.bazaarvoice.jolt.Shiftr;
+import com.bazaarvoice.jolt.Sortr;
+import com.bazaarvoice.jolt.Transform;
+
+import static org.junit.Assert.assertTrue;
+
+public class TestTransformFactory {
+
+
+ @Test
+ public void testGetChainTransform() throws IOException{
+ final String chainrSpec = new String(Files.readAllBytes(Paths.get("src/test/resources/TestTransformFactory/chainrSpec.json")));
+ Transform transform = TransformFactory.getTransform("jolt-transform-chain",JsonUtils.jsonToObject(chainrSpec));
+ assertTrue(transform instanceof Chainr);
+ }
+
+ @Test
+ public void testGetDefaultTransform() throws IOException{
+ final String defaultrSpec = new String(Files.readAllBytes(Paths.get("src/test/resources/TestTransformFactory/defaultrSpec.json")));
+ Transform transform = TransformFactory.getTransform("jolt-transform-default",JsonUtils.jsonToObject(defaultrSpec));
+ assertTrue(transform instanceof Defaultr);
+ }
+
+ @Test
+ public void testGetSortTransform() throws IOException{
+ Transform transform = TransformFactory.getTransform("jolt-transform-sort",null);
+ assertTrue(transform instanceof Sortr);
+ }
+
+ @Test
+ public void testGetShiftTransform() throws IOException{
+ final String shiftrSpec = new String(Files.readAllBytes(Paths.get("src/test/resources/TestTransformFactory/shiftrSpec.json")));
+ Transform transform = TransformFactory.getTransform("jolt-transform-shift",JsonUtils.jsonToObject(shiftrSpec));
+ assertTrue(transform instanceof Shiftr);
+ }
+
+ @Test
+ public void testGetRemoveTransform() throws IOException{
+ final String removrSpec = new String(Files.readAllBytes(Paths.get("src/test/resources/TestTransformFactory/removrSpec.json")));
+ Transform transform = TransformFactory.getTransform("jolt-transform-remove",JsonUtils.jsonToObject(removrSpec));
+ assertTrue(transform instanceof Removr);
+ }
+
+ @Test
+ public void testGetCardinalityTransform() throws IOException{
+ final String cardrSpec = new String(Files.readAllBytes(Paths.get("src/test/resources/TestTransformFactory/cardrSpec.json")));
+ Transform transform = TransformFactory.getTransform("jolt-transform-card",JsonUtils.jsonToObject(cardrSpec));
+ assertTrue(transform instanceof CardinalityTransform);
+ }
+
+ public void testGetInvalidTransformWithNoSpec() {
+ try{
+ TransformFactory.getTransform("jolt-transform-chain",null);
+ }catch (Exception e){
+ assertTrue(e.toString().equals("JOLT Chainr expects a JSON array of objects - Malformed spec."));
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/nifi/blob/cb3aa8f5/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-utils/src/test/resources/TestTransformFactory/cardrSpec.json
----------------------------------------------------------------------
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-utils/src/test/resources/TestTransformFactory/cardrSpec.json b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-utils/src/test/resources/TestTransformFactory/cardrSpec.json
new file mode 100644
index 0000000..fc77f18
--- /dev/null
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-utils/src/test/resources/TestTransformFactory/cardrSpec.json
@@ -0,0 +1,7 @@
+{
+ "rating" : {
+ "series" : {
+ "value" : "ONE"
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/nifi/blob/cb3aa8f5/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-utils/src/test/resources/TestTransformFactory/chainrSpec.json
----------------------------------------------------------------------
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-utils/src/test/resources/TestTransformFactory/chainrSpec.json b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-utils/src/test/resources/TestTransformFactory/chainrSpec.json
new file mode 100644
index 0000000..7884abf
--- /dev/null
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-utils/src/test/resources/TestTransformFactory/chainrSpec.json
@@ -0,0 +1,29 @@
+[
+ {
+ "operation": "shift",
+ "spec": {
+ "rating": {
+ "primary": {
+ "value": "Rating",
+ "max": "RatingRange"
+ },
+ "*": {
+ "max": "SecondaryRatings.&1.Range",
+ "value": "SecondaryRatings.&1.Value",
+ "$": "SecondaryRatings.&1.Id"
+ }
+ }
+ }
+ },
+ {
+ "operation": "default",
+ "spec": {
+ "Range": 5,
+ "SecondaryRatings": {
+ "*": {
+ "Range": 5
+ }
+ }
+ }
+ }
+]
http://git-wip-us.apache.org/repos/asf/nifi/blob/cb3aa8f5/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-utils/src/test/resources/TestTransformFactory/defaultrSpec.json
----------------------------------------------------------------------
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-utils/src/test/resources/TestTransformFactory/defaultrSpec.json b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-utils/src/test/resources/TestTransformFactory/defaultrSpec.json
new file mode 100644
index 0000000..2f2ea9f
--- /dev/null
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-utils/src/test/resources/TestTransformFactory/defaultrSpec.json
@@ -0,0 +1,10 @@
+ {
+ "RatingRange" : 5,
+ "rating": {
+ "*": {
+ "MaxLabel": "High",
+ "MinLabel": "Low",
+ "DisplayType": "NORMAL"
+ }
+ }
+ }
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/nifi/blob/cb3aa8f5/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-utils/src/test/resources/TestTransformFactory/removrSpec.json
----------------------------------------------------------------------
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-utils/src/test/resources/TestTransformFactory/removrSpec.json b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-utils/src/test/resources/TestTransformFactory/removrSpec.json
new file mode 100644
index 0000000..a6bde70
--- /dev/null
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-utils/src/test/resources/TestTransformFactory/removrSpec.json
@@ -0,0 +1,5 @@
+{
+ "rating": {
+ "quality": ""
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/nifi/blob/cb3aa8f5/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-utils/src/test/resources/TestTransformFactory/shiftrSpec.json
----------------------------------------------------------------------
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-utils/src/test/resources/TestTransformFactory/shiftrSpec.json b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-utils/src/test/resources/TestTransformFactory/shiftrSpec.json
new file mode 100644
index 0000000..d292cdd
--- /dev/null
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-utils/src/test/resources/TestTransformFactory/shiftrSpec.json
@@ -0,0 +1,10 @@
+{
+ "rating": {
+ "primary": {
+ "value": "SecondaryRatings.quality.RatingRange"
+ },
+ "quality": {
+ "value": "SecondaryRatings.quality.Value"
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/nifi/blob/cb3aa8f5/nifi-nar-bundles/nifi-standard-bundle/pom.xml
----------------------------------------------------------------------
diff --git a/nifi-nar-bundles/nifi-standard-bundle/pom.xml b/nifi-nar-bundles/nifi-standard-bundle/pom.xml
index 04ab2f8..f9b5525 100644
--- a/nifi-nar-bundles/nifi-standard-bundle/pom.xml
+++ b/nifi-nar-bundles/nifi-standard-bundle/pom.xml
@@ -29,6 +29,8 @@
<module>nifi-standard-reporting-tasks</module>
<module>nifi-standard-content-viewer</module>
<module>nifi-standard-nar</module>
+ <module>nifi-jolt-transform-json-ui</module>
+ <module>nifi-standard-utils</module>
</modules>
<dependencyManagement>
<dependencies>
@@ -53,6 +55,12 @@
<type>war</type>
<version>1.0.0-SNAPSHOT</version>
</dependency>
+ <dependency>
+ <groupId>org.apache.nifi</groupId>
+ <artifactId>nifi-jolt-transform-json-ui</artifactId>
+ <type>war</type>
+ <version>1.0.0-SNAPSHOT</version>
+ </dependency>
</dependencies>
</dependencyManagement>
http://git-wip-us.apache.org/repos/asf/nifi/blob/cb3aa8f5/nifi-nar-bundles/nifi-update-attribute-bundle/nifi-update-attribute-ui/src/main/java/org/apache/nifi/update/attributes/api/RuleResource.java
----------------------------------------------------------------------
diff --git a/nifi-nar-bundles/nifi-update-attribute-bundle/nifi-update-attribute-ui/src/main/java/org/apache/nifi/update/attributes/api/RuleResource.java b/nifi-nar-bundles/nifi-update-attribute-bundle/nifi-update-attribute-ui/src/main/java/org/apache/nifi/update/attributes/api/RuleResource.java
index b211b72..8eddfbc 100644
--- a/nifi-nar-bundles/nifi-update-attribute-bundle/nifi-update-attribute-ui/src/main/java/org/apache/nifi/update/attributes/api/RuleResource.java
+++ b/nifi-nar-bundles/nifi-update-attribute-bundle/nifi-update-attribute-ui/src/main/java/org/apache/nifi/update/attributes/api/RuleResource.java
@@ -632,7 +632,7 @@ public class RuleResource {
try {
// save the annotation data
- configurationContext.setAnnotationData(requestContext, annotationData);
+ configurationContext.updateComponent(requestContext, annotationData, null);
} catch (final InvalidRevisionException ire) {
throw new WebApplicationException(ire, invalidRevision(ire.getMessage()));
} catch (final Exception e) {
[4/5] nifi git commit: NIFI-1850 - Initial Commit for JSON-to-JSON
Schema Converter Editor (merge from 0.7.0 - refactor for masterless cluster).
This closes #511
Posted by mc...@apache.org.
http://git-wip-us.apache.org/repos/asf/nifi/blob/cb3aa8f5/nifi-nar-bundles/nifi-standard-bundle/nifi-jolt-transform-json-ui/src/main/java/org/apache/nifi/web/standard/api/processor/ProcessorResource.java
----------------------------------------------------------------------
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-jolt-transform-json-ui/src/main/java/org/apache/nifi/web/standard/api/processor/ProcessorResource.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-jolt-transform-json-ui/src/main/java/org/apache/nifi/web/standard/api/processor/ProcessorResource.java
new file mode 100644
index 0000000..962c6fe
--- /dev/null
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-jolt-transform-json-ui/src/main/java/org/apache/nifi/web/standard/api/processor/ProcessorResource.java
@@ -0,0 +1,67 @@
+/*
+ * 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.web.standard.api.processor;
+
+import java.util.Map;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.GET;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
+import org.apache.nifi.web.ComponentDetails;
+import org.apache.nifi.web.NiFiWebConfigurationContext;
+
+import org.apache.nifi.web.NiFiWebConfigurationRequestContext;
+import org.apache.nifi.web.standard.api.AbstractStandardResource;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@Path("/standard/processor")
+public class ProcessorResource extends AbstractStandardResource {
+
+ private static final Logger logger = LoggerFactory.getLogger(ProcessorResource.class);
+
+ @GET
+ @Produces({MediaType.APPLICATION_JSON})
+ @Path("/details")
+ public Response getDetails(@QueryParam("processorId") final String processorId) {
+ final NiFiWebConfigurationContext nifiWebContext = getWebConfigurationContext();
+ final ComponentDetails componentDetails = ProcessorWebUtils.getComponentDetails(nifiWebContext, processorId, request);
+ final Response.ResponseBuilder response = ProcessorWebUtils.applyCacheControl(Response.ok(componentDetails));
+ return response.build();
+ }
+
+ @PUT
+ @Produces({MediaType.APPLICATION_JSON})
+ @Consumes({MediaType.APPLICATION_JSON})
+ @Path("/properties")
+ public Response setProperties(@QueryParam("processorId") final String processorId, @QueryParam("revisionId") final Long revisionId,
+ @QueryParam("clientId") final String clientId, Map<String,String> properties){
+ final NiFiWebConfigurationContext nifiWebContext = getWebConfigurationContext();
+ final NiFiWebConfigurationRequestContext niFiRequestContext = ProcessorWebUtils.getRequestContext(processorId,revisionId,clientId,request);
+ final ComponentDetails componentDetails = nifiWebContext.updateComponent(niFiRequestContext,null,properties);
+ final Response.ResponseBuilder response = ProcessorWebUtils.applyCacheControl(Response.ok(componentDetails));
+ return response.build();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/nifi/blob/cb3aa8f5/nifi-nar-bundles/nifi-standard-bundle/nifi-jolt-transform-json-ui/src/main/java/org/apache/nifi/web/standard/api/processor/ProcessorWebUtils.java
----------------------------------------------------------------------
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-jolt-transform-json-ui/src/main/java/org/apache/nifi/web/standard/api/processor/ProcessorWebUtils.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-jolt-transform-json-ui/src/main/java/org/apache/nifi/web/standard/api/processor/ProcessorWebUtils.java
new file mode 100644
index 0000000..bf81df3
--- /dev/null
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-jolt-transform-json-ui/src/main/java/org/apache/nifi/web/standard/api/processor/ProcessorWebUtils.java
@@ -0,0 +1,88 @@
+/*
+ * 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.web.standard.api.processor;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.core.CacheControl;
+import javax.ws.rs.core.Response;
+
+import org.apache.nifi.web.ComponentDetails;
+import org.apache.nifi.web.HttpServletConfigurationRequestContext;
+import org.apache.nifi.web.HttpServletRequestContext;
+import org.apache.nifi.web.NiFiWebConfigurationContext;
+import org.apache.nifi.web.NiFiWebConfigurationRequestContext;
+import org.apache.nifi.web.NiFiWebRequestContext;
+import org.apache.nifi.web.Revision;
+import org.apache.nifi.web.UiExtensionType;
+
+
+class ProcessorWebUtils {
+
+ static ComponentDetails getComponentDetails(final NiFiWebConfigurationContext configurationContext,final String processorId,
+ final Long revision, final String clientId, HttpServletRequest request){
+
+ final NiFiWebRequestContext requestContext;
+
+ if(processorId != null && revision != null && clientId != null){
+ requestContext = getRequestContext(processorId, revision, clientId, request) ;
+ } else{
+ requestContext = getRequestContext(processorId,request);
+ }
+
+ return configurationContext.getComponentDetails(requestContext);
+
+ }
+
+ static ComponentDetails getComponentDetails(final NiFiWebConfigurationContext configurationContext,final String processorId, HttpServletRequest request){
+ return getComponentDetails(configurationContext,processorId,null,null,request);
+ }
+
+ static Response.ResponseBuilder applyCacheControl(Response.ResponseBuilder response) {
+ CacheControl cacheControl = new CacheControl();
+ cacheControl.setPrivate(true);
+ cacheControl.setNoCache(true);
+ cacheControl.setNoStore(true);
+ return response.cacheControl(cacheControl);
+ }
+
+ static NiFiWebConfigurationRequestContext getRequestContext(final String processorId, final Long revision, final String clientId, HttpServletRequest request) {
+ return new HttpServletConfigurationRequestContext(UiExtensionType.ProcessorConfiguration, request) {
+ @Override
+ public String getId() {
+ return processorId;
+ }
+
+ @Override
+ public Revision getRevision() {
+ return new Revision(revision, clientId, processorId);
+ }
+ };
+ }
+
+
+ private static NiFiWebRequestContext getRequestContext(final String processorId, HttpServletRequest request) {
+ return new HttpServletRequestContext(UiExtensionType.ProcessorConfiguration, request) {
+ @Override
+ public String getId() {
+ return processorId;
+ }
+ };
+ }
+
+
+}
http://git-wip-us.apache.org/repos/asf/nifi/blob/cb3aa8f5/nifi-nar-bundles/nifi-standard-bundle/nifi-jolt-transform-json-ui/src/main/java/org/apache/nifi/web/standard/api/transformjson/TransformJSONResource.java
----------------------------------------------------------------------
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-jolt-transform-json-ui/src/main/java/org/apache/nifi/web/standard/api/transformjson/TransformJSONResource.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-jolt-transform-json-ui/src/main/java/org/apache/nifi/web/standard/api/transformjson/TransformJSONResource.java
new file mode 100644
index 0000000..861c120
--- /dev/null
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-jolt-transform-json-ui/src/main/java/org/apache/nifi/web/standard/api/transformjson/TransformJSONResource.java
@@ -0,0 +1,89 @@
+/*
+ * 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.web.standard.api.transformjson;
+
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.nifi.processors.standard.util.TransformFactory;
+import org.apache.nifi.web.standard.api.AbstractStandardResource;
+import org.apache.nifi.web.standard.api.transformjson.dto.JoltSpecificationDTO;
+import org.apache.nifi.web.standard.api.transformjson.dto.ValidationDTO;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.bazaarvoice.jolt.JsonUtils;
+import com.bazaarvoice.jolt.Transform;
+
+@Path("/standard/transformjson")
+public class TransformJSONResource extends AbstractStandardResource {
+
+ private static final Logger logger = LoggerFactory.getLogger(TransformJSONResource.class);
+
+ protected Object getSpecificationJsonObject(String specification){
+
+ if (!StringUtils.isEmpty(specification)){
+ return JsonUtils.jsonToObject(specification, "UTF-8");
+ }else{
+ return null;
+ }
+ }
+
+ @POST
+ @Produces({MediaType.APPLICATION_JSON})
+ @Path("/validate")
+ public Response validateSpec(JoltSpecificationDTO specificationDTO) {
+
+ Object specJson = getSpecificationJsonObject(specificationDTO.getSpecification());
+
+ try {
+ TransformFactory.getTransform(specificationDTO.getTransform(), specJson);
+ }catch(final Exception e){
+ logger.error("Validation Failed - " + e.toString());
+ return Response.ok(new ValidationDTO(false,"Validation Failed - Please verify the provided specification.")).build();
+ }
+
+ return Response.ok(new ValidationDTO(true,null)).build();
+ }
+
+ @POST
+ @Produces({MediaType.APPLICATION_JSON})
+ @Path("/execute")
+ public Response executeSpec(JoltSpecificationDTO specificationDTO) {
+
+ Object specJson = getSpecificationJsonObject(specificationDTO.getSpecification());
+
+ try {
+ Transform transform = TransformFactory.getTransform(specificationDTO.getTransform(), specJson);
+ Object inputJson = JsonUtils.jsonToObject(specificationDTO.getInput());
+ return Response.ok(JsonUtils.toJsonString(transform.transform(inputJson))).build();
+
+ }catch(final Exception e){
+ logger.error("Execute Specification Failed - " + e.toString());
+ return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
+ }
+
+ }
+
+
+
+}
http://git-wip-us.apache.org/repos/asf/nifi/blob/cb3aa8f5/nifi-nar-bundles/nifi-standard-bundle/nifi-jolt-transform-json-ui/src/main/java/org/apache/nifi/web/standard/api/transformjson/dto/JoltSpecificationDTO.java
----------------------------------------------------------------------
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-jolt-transform-json-ui/src/main/java/org/apache/nifi/web/standard/api/transformjson/dto/JoltSpecificationDTO.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-jolt-transform-json-ui/src/main/java/org/apache/nifi/web/standard/api/transformjson/dto/JoltSpecificationDTO.java
new file mode 100644
index 0000000..d189198
--- /dev/null
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-jolt-transform-json-ui/src/main/java/org/apache/nifi/web/standard/api/transformjson/dto/JoltSpecificationDTO.java
@@ -0,0 +1,63 @@
+/*
+ * 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.web.standard.api.transformjson.dto;
+
+import java.io.Serializable;
+
+import javax.xml.bind.annotation.XmlRootElement;
+
+@XmlRootElement
+public class JoltSpecificationDTO implements Serializable{
+
+
+ private String transform;
+ private String specification;
+ private String input;
+
+ public JoltSpecificationDTO() {
+ }
+
+ public JoltSpecificationDTO(String transform, String specification) {
+ this.transform = transform;
+ this.specification = specification;
+ }
+
+ public String getTransform() {
+ return transform;
+ }
+
+ public void setTransform(String transform) {
+ this.transform = transform;
+ }
+
+ public String getSpecification() {
+ return specification;
+ }
+
+ public void setSpecification(String specification) {
+ this.specification = specification;
+ }
+
+ public String getInput() {
+ return input;
+ }
+
+ public void setInput(String input) {
+ this.input = input;
+ }
+}
http://git-wip-us.apache.org/repos/asf/nifi/blob/cb3aa8f5/nifi-nar-bundles/nifi-standard-bundle/nifi-jolt-transform-json-ui/src/main/java/org/apache/nifi/web/standard/api/transformjson/dto/ValidationDTO.java
----------------------------------------------------------------------
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-jolt-transform-json-ui/src/main/java/org/apache/nifi/web/standard/api/transformjson/dto/ValidationDTO.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-jolt-transform-json-ui/src/main/java/org/apache/nifi/web/standard/api/transformjson/dto/ValidationDTO.java
new file mode 100644
index 0000000..fe1cef9
--- /dev/null
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-jolt-transform-json-ui/src/main/java/org/apache/nifi/web/standard/api/transformjson/dto/ValidationDTO.java
@@ -0,0 +1,54 @@
+/*
+ * 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.web.standard.api.transformjson.dto;
+
+import java.io.Serializable;
+
+import javax.xml.bind.annotation.XmlRootElement;
+
+
+@XmlRootElement
+public class ValidationDTO implements Serializable {
+
+ private Boolean valid;
+ private String message;
+
+ public ValidationDTO() {
+ }
+
+ public ValidationDTO(Boolean valid, String message) {
+ this.valid = valid;
+ this.message = message;
+ }
+
+ public Boolean isValid() {
+ return valid;
+ }
+
+ public void setValid(Boolean valid) {
+ this.valid = valid;
+ }
+
+ public String getMessage() {
+ return message;
+ }
+
+ public void setMessage(String message) {
+ this.message = message;
+ }
+}
http://git-wip-us.apache.org/repos/asf/nifi/blob/cb3aa8f5/nifi-nar-bundles/nifi-standard-bundle/nifi-jolt-transform-json-ui/src/main/resources/META-INF/LICENSE
----------------------------------------------------------------------
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-jolt-transform-json-ui/src/main/resources/META-INF/LICENSE b/nifi-nar-bundles/nifi-standard-bundle/nifi-jolt-transform-json-ui/src/main/resources/META-INF/LICENSE
new file mode 100644
index 0000000..1a72391
--- /dev/null
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-jolt-transform-json-ui/src/main/resources/META-INF/LICENSE
@@ -0,0 +1,320 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed 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.
+
+APACHE NIFI SUBCOMPONENTS:
+
+The Apache NiFi project contains subcomponents with separate copyright
+notices and license terms. Your use of the source code for the these
+subcomponents is subject to the terms and conditions of the following
+licenses.
+
+ The binary distribution of this product bundles 'Antlr 3' which is available
+ under a "3-clause BSD" license. For details see http://www.antlr3.org/license.html
+
+ Copyright (c) 2010 Terence Parr
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+ Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+ Neither the name of the author nor the names of its contributors may be used
+ to endorse or promote products derived from this software without specific
+ prior written permission.
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ THE POSSIBILITY OF SUCH DAMAGE.
+
+This product bundles 'Jolt' which is available under an Apache License. For details see https://github.com/bazaarvoice/jolt/blob/jolt-0.0.20/LICENSE
+
+ Copyright 2013-2014 Bazaarvoice, Inc.
+
+ Licensed 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.
+
+This product bundles 'AngularUI Codemirror' which is available under an MIT license.
+
+ Copyright (c) 2012 the AngularUI Team, http://angular-ui.github.com
+
+ Permission is hereby granted, free of charge, to any person obtaining a copy
+ of this software and associated documentation files (the "Software"), to deal
+ in the Software without restriction, including without limitation the rights
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ copies of the Software, and to permit persons to whom the Software is
+ furnished to do so, subject to the following conditions:
+
+ The above copyright notice and this permission notice shall be included in
+ all copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ THE SOFTWARE.
+
+This product bundles 'AngularUI Router' which is available under an MIT license.
+
+ Copyright (c) 2013-2015 The AngularUI Team, Karsten Sperling
+
+ Permission is hereby granted, free of charge, to any person obtaining a copy
+ of this software and associated documentation files (the "Software"), to deal
+ in the Software without restriction, including without limitation the rights
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ copies of the Software, and to permit persons to whom the Software is
+ furnished to do so, subject to the following conditions:
+
+ The above copyright notice and this permission notice shall be included in
+ all copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ THE SOFTWARE.
+
+This product bundles 'js-beautify' which is available under an MIT license.
+
+ Copyright (c) 2007-2013 Einar Lielmanis and contributors.
+
+ Permission is hereby granted, free of charge, to any person obtaining a copy
+ of this software and associated documentation files (the "Software"), to deal
+ in the Software without restriction, including without limitation the rights
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ copies of the Software, and to permit persons to whom the Software is
+ furnished to do so, subject to the following conditions:
+
+ The above copyright notice and this permission notice shall be included in
+ all copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ THE SOFTWARE.
http://git-wip-us.apache.org/repos/asf/nifi/blob/cb3aa8f5/nifi-nar-bundles/nifi-standard-bundle/nifi-jolt-transform-json-ui/src/main/resources/META-INF/NOTICE
----------------------------------------------------------------------
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-jolt-transform-json-ui/src/main/resources/META-INF/NOTICE b/nifi-nar-bundles/nifi-standard-bundle/nifi-jolt-transform-json-ui/src/main/resources/META-INF/NOTICE
new file mode 100644
index 0000000..c2786db
--- /dev/null
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-jolt-transform-json-ui/src/main/resources/META-INF/NOTICE
@@ -0,0 +1,53 @@
+nifi-transform-json-ui
+Copyright 2014-2016 The Apache Software Foundation
+
+This product includes software developed at
+The Apache Software Foundation (http://www.apache.org/).
+
+******************
+Apache Software License v2
+******************
+
+The following binary components are provided under the Apache Software License v2
+
+ (ASLv2) Apache Commons Lang
+ The following NOTICE information applies:
+ Apache Commons Lang
+ Copyright 2001-2014 The Apache Software Foundation
+
+ This product includes software from the Spring Framework,
+ under the Apache License 2.0 (see: StringUtils.containsWhitespace())
+
+ (ASLv2) Jettison
+ The following NOTICE information applies:
+ Copyright 2006 Envoi Solutions LLC
+
+ (ASLv2) Jolt
+ The following NOTICE information applies:
+ Copyright 2013-2014 Bazaarvoice, Inc
+
+************************
+Common Development and Distribution License 1.1
+************************
+
+The following binary components are provided under the Common Development and Distribution License 1.1. See project link for details.
+
+ (CDDL 1.1) (GPL2 w/ CPE) jersey-core (com.sun.jersey:jersey-core:jar:1.18.3 - https://jersey.java.net/jersey-core/)
+ (CDDL 1.1) (GPL2 w/ CPE) jersey-server (com.sun.jersey:jersey-server:jar:1.18.3 - https://jersey.java.net/jersey-server/)
+ (CDDL 1.1) (GPL2 w/ CPE) jersey-json (com.sun.jersey:jersey-json:jar:1.18.3 - https://jersey.java.net/index.html)
+ (CDDL 1.1) (GPL2 w/ CPE) jersey-servlet (com.sun.jersey:jersey-servlet:jar:1.18.3 - https://jersey.java.net/index.html)
+ (CDDL 1.1) (GPL2 w/ CPE) Old JAXB Runtime (com.sun.xml.bind:jaxb-impl:jar:2.2.3-1 - http://jaxb.java.net/)
+ (CDDL 1.1) (GPL2 w/ CPE) Java Architecture For XML Binding (javax.xml.bind:jaxb-api:jar:2.2.2 - https://jaxb.dev.java.net/)
+
+************************
+Common Development and Distribution License 1.0
+************************
+
+The following binary components are provided under the Common Development and Distribution License 1.0. See project link for details.
+
+ (CDDL 1.0) (GPL3) Streaming API For XML (javax.xml.stream:stax-api:jar:1.0-2 - no url provided)
+ (CDDL 1.0) JavaBeans Activation Framework (JAF) (javax.activation:activation:jar:1.1 - http://java.sun.com/products/javabeans/jaf/index.jsp)
+
+
+
+
http://git-wip-us.apache.org/repos/asf/nifi/blob/cb3aa8f5/nifi-nar-bundles/nifi-standard-bundle/nifi-jolt-transform-json-ui/src/main/webapp/META-INF/nifi-processor-configuration
----------------------------------------------------------------------
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-jolt-transform-json-ui/src/main/webapp/META-INF/nifi-processor-configuration b/nifi-nar-bundles/nifi-standard-bundle/nifi-jolt-transform-json-ui/src/main/webapp/META-INF/nifi-processor-configuration
new file mode 100644
index 0000000..14977f0
--- /dev/null
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-jolt-transform-json-ui/src/main/webapp/META-INF/nifi-processor-configuration
@@ -0,0 +1,15 @@
+# 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.
+org.apache.nifi.processors.standard.JoltTransformJSON
http://git-wip-us.apache.org/repos/asf/nifi/blob/cb3aa8f5/nifi-nar-bundles/nifi-standard-bundle/nifi-jolt-transform-json-ui/src/main/webapp/WEB-INF/jsp/index.jsp
----------------------------------------------------------------------
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-jolt-transform-json-ui/src/main/webapp/WEB-INF/jsp/index.jsp b/nifi-nar-bundles/nifi-standard-bundle/nifi-jolt-transform-json-ui/src/main/webapp/WEB-INF/jsp/index.jsp
new file mode 100644
index 0000000..750bd8b
--- /dev/null
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-jolt-transform-json-ui/src/main/webapp/WEB-INF/jsp/index.jsp
@@ -0,0 +1,67 @@
+<%--
+ 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.
+--%>
+<%@ page contentType="text/html" pageEncoding="UTF-8" session="false" %>
+<!DOCTYPE html>
+<html lang="en">
+<head>
+ <link rel="stylesheet" type="text/css" href="../nifi/js/codemirror/lib/codemirror.css"/>
+ <link rel="stylesheet" type="text/css" href="../nifi/js/codemirror/addon/lint/lint.css">
+ <link rel="stylesheet" type="text/css" href="../nifi/assets/angular-material/angular-material.css">
+ <link rel="stylesheet" type="text/css" href="css/main.css">
+</head>
+
+<body ng-app="standardUI" ng-cloak>
+
+<!--Parent Libraries-->
+<script type="text/javascript" src="../nifi/js/codemirror/lib/codemirror-compressed.js"></script>
+<script type="text/javascript" src="../nifi/js/codemirror/addon/lint/lint.js"></script>
+<script type="text/javascript" src="../nifi/js/codemirror/addon/lint/json-lint.js"></script>
+<script type="text/javascript" src="../nifi/js/jsonlint/jsonlint.min.js"></script>
+<script type="text/javascript" src="../nifi/assets/angular/angular.min.js"></script>
+<script type="text/javascript" src="../nifi/assets/angular-animate/angular-animate.min.js"></script>
+<script type="text/javascript" src="../nifi/assets/angular-aria/angular-aria.min.js"></script>
+<script type="text/javascript" src="../nifi/assets/angular-messages/angular-messages.min.js"></script>
+<script type="text/javascript" src="../nifi/assets/angular-material/angular-material.min.js"></script>
+
+<!--Bower Libraries-->
+<script type="text/javascript" src="assets/angular-ui-codemirror/ui-codemirror.min.js"></script>
+<script type="text/javascript" src="assets/angular-ui-router/release/angular-ui-router.min.js"></script>
+
+<!--Local Libraries-->
+<script type="text/javascript" src="js/js-beautify/beautify.js"></script>
+
+<!--Custom UI App-->
+<script type="text/javascript" src="app/app.js"></script>
+
+<!--Custom Global Components-->
+<script type="text/javascript" src="app/components/error/error.state.js"></script>
+<script type="text/javascript" src="app/components/processor/processor.service.js"></script>
+
+<!--Custom View Components-->
+<script type="text/javascript" src="app/main/main.state.js"></script>
+<script type="text/javascript" src="app/main/main.controller.js"></script>
+<script type="text/javascript" src="app/transformjson/transformjson.state.js"></script>
+<script type="text/javascript" src="app/transformjson/transformjson.controller.js"></script>
+<script type="text/javascript" src="app/transformjson/transformjson.service.js"></script>
+
+
+<div ui-view>
+
+</div>
+
+</body>
+</html>
http://git-wip-us.apache.org/repos/asf/nifi/blob/cb3aa8f5/nifi-nar-bundles/nifi-standard-bundle/nifi-jolt-transform-json-ui/src/main/webapp/WEB-INF/web.xml
----------------------------------------------------------------------
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-jolt-transform-json-ui/src/main/webapp/WEB-INF/web.xml b/nifi-nar-bundles/nifi-standard-bundle/nifi-jolt-transform-json-ui/src/main/webapp/WEB-INF/web.xml
new file mode 100644
index 0000000..13d0d41
--- /dev/null
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-jolt-transform-json-ui/src/main/webapp/WEB-INF/web.xml
@@ -0,0 +1,50 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+
+<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
+ <servlet>
+ <servlet-name>api</servlet-name>
+ <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
+ <init-param>
+ <param-name>com.sun.jersey.config.property.packages</param-name>
+ <param-value>org.apache.nifi.web.standard.api.processor,org.apache.nifi.web.standard.api.transformjson</param-value>
+ </init-param>
+ <init-param>
+ <param-name>com.sun.jersey.api.json.POJOMappingFeature</param-name>
+ <param-value>true</param-value>
+ </init-param>
+ </servlet>
+ <servlet-mapping>
+ <servlet-name>api</servlet-name>
+ <url-pattern>/api/*</url-pattern>
+ </servlet-mapping>
+
+ <servlet>
+ <servlet-name>index</servlet-name>
+ <jsp-file>/WEB-INF/jsp/index.jsp</jsp-file>
+ </servlet>
+
+ <servlet-mapping>
+ <servlet-name>index</servlet-name>
+ <url-pattern>/configure</url-pattern>
+ </servlet-mapping>
+
+ <welcome-file-list>
+ <welcome-file>configure</welcome-file>
+ </welcome-file-list>
+
+</web-app>
+
http://git-wip-us.apache.org/repos/asf/nifi/blob/cb3aa8f5/nifi-nar-bundles/nifi-standard-bundle/nifi-jolt-transform-json-ui/src/main/webapp/app/app.js
----------------------------------------------------------------------
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-jolt-transform-json-ui/src/main/webapp/app/app.js b/nifi-nar-bundles/nifi-standard-bundle/nifi-jolt-transform-json-ui/src/main/webapp/app/app.js
new file mode 100644
index 0000000..67c440c
--- /dev/null
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-jolt-transform-json-ui/src/main/webapp/app/app.js
@@ -0,0 +1,44 @@
+/*
+ * 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.
+ */
+
+'use strict';
+
+var AppRun = function($rootScope,$state){
+
+ $rootScope.$on('$stateChangeError', function(event, toState, toParams, fromState, fromParams, error){
+ event.preventDefault();
+ $state.go('error');
+ });
+
+};
+
+var AppConfig = function ($urlRouterProvider) {
+
+ $urlRouterProvider.otherwise(function($injector,$location){
+ var urlComponents = $location.absUrl().split("?");
+ return '/main?' + urlComponents[1];
+ });
+
+};
+
+AppRun.$inject = ['$rootScope','$state'];
+
+AppConfig.$inject = ['$urlRouterProvider'];
+
+angular.module('standardUI', ['ui.codemirror','ui.router'])
+ .run(AppRun)
+ .config(AppConfig);
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/nifi/blob/cb3aa8f5/nifi-nar-bundles/nifi-standard-bundle/nifi-jolt-transform-json-ui/src/main/webapp/app/components/error/error.state.js
----------------------------------------------------------------------
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-jolt-transform-json-ui/src/main/webapp/app/components/error/error.state.js b/nifi-nar-bundles/nifi-standard-bundle/nifi-jolt-transform-json-ui/src/main/webapp/app/components/error/error.state.js
new file mode 100644
index 0000000..ff4cf30
--- /dev/null
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-jolt-transform-json-ui/src/main/webapp/app/components/error/error.state.js
@@ -0,0 +1,30 @@
+/*
+ * 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.
+ */
+
+'use strict';
+
+var ErrorState = function($stateProvider) {
+
+ $stateProvider
+ .state('error', {
+ url: "/error",
+ templateUrl: "app/components/error/error.view.html"
+ })
+};
+
+ErrorState.$inject = ['$stateProvider'];
+angular.module('standardUI').config(ErrorState);
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/nifi/blob/cb3aa8f5/nifi-nar-bundles/nifi-standard-bundle/nifi-jolt-transform-json-ui/src/main/webapp/app/components/error/error.view.html
----------------------------------------------------------------------
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-jolt-transform-json-ui/src/main/webapp/app/components/error/error.view.html b/nifi-nar-bundles/nifi-standard-bundle/nifi-jolt-transform-json-ui/src/main/webapp/app/components/error/error.view.html
new file mode 100644
index 0000000..8908e67
--- /dev/null
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-jolt-transform-json-ui/src/main/webapp/app/components/error/error.view.html
@@ -0,0 +1,15 @@
+<!--
+ 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.
+-->
+<h2> An error has occurred loading the editor.</h2>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/nifi/blob/cb3aa8f5/nifi-nar-bundles/nifi-standard-bundle/nifi-jolt-transform-json-ui/src/main/webapp/app/components/processor/processor.service.js
----------------------------------------------------------------------
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-jolt-transform-json-ui/src/main/webapp/app/components/processor/processor.service.js b/nifi-nar-bundles/nifi-standard-bundle/nifi-jolt-transform-json-ui/src/main/webapp/app/components/processor/processor.service.js
new file mode 100644
index 0000000..ef1b6f2
--- /dev/null
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-jolt-transform-json-ui/src/main/webapp/app/components/processor/processor.service.js
@@ -0,0 +1,53 @@
+/*
+ * 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.
+ */
+
+'use strict';
+
+var ProcessorService = function ProcessorService($http) {
+
+ return {
+ 'setProperties': setProperties,
+ 'getType': getType,
+ 'getDetails' : getDetails
+ };
+
+ function setProperties(processorId,revisionId,clientId,properties){
+ var urlParams = 'processorId='+processorId+'&revisionId='+revisionId+'&clientId='+clientId;
+ return $http({url: 'api/standard/processor/properties?'+urlParams,method:'PUT',data:properties});
+ }
+
+ function getType(id) {
+ return $http({
+ url: 'api/standard/processor/details?processorId=' + id,
+ method: 'GET',
+ transformResponse: [function (data) {
+ var obj = JSON.parse(data)
+ var type = obj['type'];
+ return type;
+ }]
+ });
+ }
+
+ function getDetails(id) {
+ return $http({ url: 'api/standard/processor/details?processorId=' + id, method: 'GET'});
+ }
+
+};
+
+ProcessorService.$inject = ['$http'];
+
+angular.module('standardUI').factory('ProcessorService', ProcessorService);
http://git-wip-us.apache.org/repos/asf/nifi/blob/cb3aa8f5/nifi-nar-bundles/nifi-standard-bundle/nifi-jolt-transform-json-ui/src/main/webapp/app/main/main.controller.js
----------------------------------------------------------------------
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-jolt-transform-json-ui/src/main/webapp/app/main/main.controller.js b/nifi-nar-bundles/nifi-standard-bundle/nifi-jolt-transform-json-ui/src/main/webapp/app/main/main.controller.js
new file mode 100644
index 0000000..6f092f7
--- /dev/null
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-jolt-transform-json-ui/src/main/webapp/app/main/main.controller.js
@@ -0,0 +1,35 @@
+/*
+ * 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.
+ */
+
+'use strict';
+
+var MainController = function ($scope, $state, ProcessorService) {
+
+ ProcessorService.getType($state.params.id).then(function(response){
+ var type = response.data
+ var stateName = type.substring(type.lastIndexOf(".") + 1, type.length).toLowerCase();
+ var result = $state.go(stateName,$state.params);
+
+ }).catch(function(response) {
+ $state.go('error');
+ });
+
+};
+
+MainController.$inject = ['$scope','$state','ProcessorService'];
+
+angular.module('standardUI').controller('MainController', MainController);
http://git-wip-us.apache.org/repos/asf/nifi/blob/cb3aa8f5/nifi-nar-bundles/nifi-standard-bundle/nifi-jolt-transform-json-ui/src/main/webapp/app/main/main.state.js
----------------------------------------------------------------------
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-jolt-transform-json-ui/src/main/webapp/app/main/main.state.js b/nifi-nar-bundles/nifi-standard-bundle/nifi-jolt-transform-json-ui/src/main/webapp/app/main/main.state.js
new file mode 100644
index 0000000..e664ee8
--- /dev/null
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-jolt-transform-json-ui/src/main/webapp/app/main/main.state.js
@@ -0,0 +1,31 @@
+/*
+ * 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.
+ */
+
+'use strict';
+
+var MainState = function($stateProvider) {
+
+ $stateProvider
+ .state('main', {
+ url: "/main?id&revision&clientId&editable",
+ controller: 'MainController'
+ })
+};
+
+MainState.$inject = ['$stateProvider'];
+
+angular.module('standardUI').config(MainState);
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/nifi/blob/cb3aa8f5/nifi-nar-bundles/nifi-standard-bundle/nifi-jolt-transform-json-ui/src/main/webapp/app/transformjson/transformjson.controller.js
----------------------------------------------------------------------
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-jolt-transform-json-ui/src/main/webapp/app/transformjson/transformjson.controller.js b/nifi-nar-bundles/nifi-standard-bundle/nifi-jolt-transform-json-ui/src/main/webapp/app/transformjson/transformjson.controller.js
new file mode 100644
index 0000000..4c8b637
--- /dev/null
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-jolt-transform-json-ui/src/main/webapp/app/transformjson/transformjson.controller.js
@@ -0,0 +1,374 @@
+/*
+ * 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.
+ */
+'use strict';
+
+var TransformJsonController = function ($scope, $state, $q, TransformJsonService, ProcessorService, details) {
+
+ $scope.processorId = '';
+ $scope.clientId = '';
+ $scope.revisionId = '';
+ $scope.editable = false;
+ $scope.specEditor = {};
+ $scope.inputEditor = {};
+ $scope.jsonInput = '';
+ $scope.jsonOutput = '';
+ $scope.sortOutput = false;
+ $scope.validObj = {};
+ $scope.error = '';
+ $scope.disableCSS = '';
+ $scope.saveStatus = '';
+ $scope.specUpdated = false;
+
+ $scope.convertToArray= function (map){
+ var labelValueArray = [];
+ angular.forEach(map, function(value, key){
+ labelValueArray.push({'label' : value, 'value' : key});
+ });
+ return labelValueArray;
+ };
+
+ $scope.getJsonSpec = function(details){
+ if(details['properties']['jolt-spec'] != null && details['properties']['jolt-spec'] != "") {
+ return details['properties']['jolt-spec'];
+ }
+ else return '';
+ };
+
+ $scope.getTransform = function(details){
+ return details['properties']['jolt-transform'] ? details['properties']['jolt-transform'] :
+ details['descriptors']['jolt-transform']['defaultValue'] ;
+ };
+
+ $scope.getTransformOptions = function(details){
+ return $scope.convertToArray(details['descriptors']['jolt-transform']['allowableValues']);
+ };
+
+ $scope.populateScopeWithDetails = function(details){
+ $scope.jsonSpec = $scope.getJsonSpec(details);
+ $scope.transform = $scope.getTransform(details);
+ $scope.transformOptions = $scope.getTransformOptions(details);
+ };
+
+ $scope.populateScopeWithDetails(details.data);
+
+ $scope.clearValidation = function(){
+ $scope.validObj = {};
+ };
+
+ $scope.clearError = function(){
+ $scope.error = '';
+ };
+
+ $scope.clearSave = function(){
+ if($scope.saveStatus != ''){
+ $scope.saveStatus = '';
+ }
+ };
+
+ $scope.clearMessages = function(){
+ $scope.clearSave();
+ $scope.clearError();
+ $scope.clearValidation();
+ };
+
+ $scope.showError = function(message,detail){
+ $scope.error = message;
+ console.log('Error received:', detail);
+ };
+
+ $scope.initEditors = function(_editor) {
+
+ _editor.setOption('extraKeys',{
+
+ 'Shift-F': function(cm){
+ var jsonValue = js_beautify(cm.getDoc().getValue(), {
+ 'indent_size': 1,
+ 'indent_char': '\t'
+ });
+ cm.getDoc().setValue(jsonValue)
+ }
+
+ });
+
+ };
+
+ $scope.initSpecEditor = function(_editor){
+ $scope.initEditors(_editor);
+ $scope.specEditor = _editor;
+ _editor.on('update',function(cm){
+ if($scope.transform == 'jolt-transform-sort'){
+ $scope.toggleEditorErrors(_editor,'hide');
+ }
+ });
+
+ _editor.on('change',function(cm,changeObj){
+
+ if(!($scope.transform == 'jolt-transform-sort' && changeObj.text.toString() == "")){
+ $scope.clearMessages();
+ if(changeObj.text.toString() != changeObj.removed.toString()){
+ $scope.specUpdated = true;
+ }
+ }
+ });
+
+ };
+
+ $scope.initInputEditor = function(_editor){
+ $scope.initEditors(_editor);
+ $scope.inputEditor = _editor;
+
+ _editor.on('change',function(cm,changeObj){
+ $scope.clearMessages();
+ });
+
+ _editor.clearGutter('CodeMirror-lint-markers');
+ };
+
+ $scope.editorProperties = {
+ lineNumbers: true,
+ gutters: ['CodeMirror-lint-markers'],
+ mode: 'application/json',
+ lint: true,
+ value: $scope.jsonSpec,
+ onLoad: $scope.initSpecEditor
+ };
+
+ $scope.inputProperties = {
+ lineNumbers: true,
+ gutters: ['CodeMirror-lint-markers'],
+ mode: 'application/json',
+ lint: true,
+ value: "",
+ onLoad: $scope.initInputEditor
+ };
+
+ $scope.outputProperties = {
+ lineNumbers: true,
+ gutters: ['CodeMirror-lint-markers'],
+ mode: 'application/json',
+ lint: false,
+ readOnly: true
+ };
+
+ $scope.formatEditor = function(editor){
+
+ var jsonValue = js_beautify(editor.getDoc().getValue(), {
+ 'indent_size': 1,
+ 'indent_char': '\t'
+ });
+ editor.getDoc().setValue(jsonValue);
+
+ };
+
+ $scope.hasJsonErrors = function(input, transform){
+ try{
+ jsonlint.parse(input);
+ }catch(e){
+ return true;
+ }
+ return false;
+ };
+
+ $scope.toggleEditorErrors = function(editor,toggle){
+ var display = editor.display.wrapper;
+ var errors = display.getElementsByClassName("CodeMirror-lint-marker-error");
+
+ if(toggle == 'hide'){
+
+ angular.forEach(errors,function(error){
+ var element = angular.element(error);
+ element.addClass('hide');
+ });
+
+ var markErrors = display.getElementsByClassName("CodeMirror-lint-mark-error");
+ angular.forEach(markErrors,function(error){
+ var element = angular.element(error);
+ element.addClass('CodeMirror-lint-mark-error-hide');
+ element.removeClass('CodeMirror-lint-mark-error');
+ });
+
+ }else{
+
+ angular.forEach(errors,function(error){
+ var element = angular.element(error);
+ element.removeClass('hide');
+ });
+
+ var markErrors = display.getElementsByClassName("CodeMirror-lint-mark-error-hide");
+ angular.forEach(markErrors,function(error){
+ var element = angular.element(error);
+ element.addClass('CodeMirror-lint-mark-error');
+ element.removeClass('CodeMirror-lint-mark-error-hide');
+ });
+
+ }
+
+ };
+
+ $scope.toggleEditor = function(editor,transform,specUpdated){
+
+ if(transform == 'jolt-transform-sort'){
+ editor.setOption("readOnly","nocursor");
+ $scope.disableCSS = "trans";
+ $scope.toggleEditorErrors(editor,'hide');
+ }
+ else{
+ editor.setOption("readOnly",false);
+ $scope.disableCSS = "";
+ $scope.toggleEditorErrors(editor,'show');
+ }
+
+ $scope.specUpdated = specUpdated;
+
+ $scope.clearMessages();
+
+ }
+
+ $scope.getJoltSpec = function(transform,jsonSpec,jsonInput){
+
+ return {
+ "transform": transform,
+ "specification" : jsonSpec,
+ "input" : jsonInput
+ };
+ };
+
+ $scope.getProperties = function(transform,jsonSpec){
+
+ return {
+ "jolt-transform" : transform != "" ? transform : null,
+ "jolt-spec": jsonSpec != "" ? jsonSpec : null
+ };
+
+ };
+
+ $scope.getSpec = function(transform,jsonSpec){
+ if(transform != 'jolt-transform-sort'){
+ return jsonSpec;
+ }else{
+ return null;
+ }
+ };
+
+ $scope.validateJson = function(jsonInput,jsonSpec,transform){
+
+ var deferred = $q.defer();
+
+ $scope.clearError();
+
+ if( transform == 'jolt-transform-sort' ||!$scope.hasJsonErrors(jsonSpec,transform) ){
+ var joltSpec = $scope.getJoltSpec(transform,jsonSpec,jsonInput);
+
+ TransformJsonService.validate(joltSpec).then(function(response){
+ $scope.validObj = response.data;
+ deferred.resolve($scope.validObj);
+ }).catch(function(response) {
+ $scope.showError("Error occurred during validation",response.statusText)
+ deferred.reject($scope.error);
+ });
+
+ }else{
+ $scope.validObj = {"valid":false,"message":"JSON Spec provided is not valid JSON format"};
+ deferred.resolve($scope.validObj);
+ }
+
+ return deferred.promise;
+
+ };
+
+ $scope.transformJson = function(jsonInput,jsonSpec,transform){
+
+
+ if( !$scope.hasJsonErrors(jsonInput,transform) ){
+
+ $scope.validateJson(jsonInput,jsonSpec,transform).then(function(response){
+
+ var validObj = response;
+
+ if(validObj.valid == true){
+
+ var joltSpec = $scope.getJoltSpec(transform,jsonSpec,jsonInput);
+
+ TransformJsonService.execute(joltSpec).then(function(response){
+
+ $scope.jsonOutput = js_beautify(response.data, {
+ 'indent_size': 1,
+ 'indent_char': '\t'
+ });
+
+ })
+ .catch(function(response) {
+ $scope.showError("Error occurred during transformation",response.statusText)
+ });
+
+ }
+
+ });
+
+ }else{
+ $scope.validObj = {"valid":false,"message":"JSON Input provided is not valid JSON format"};
+ }
+ };
+
+ $scope.saveSpec = function(jsonInput,jsonSpec,transform,processorId,clientId,revisionId){
+
+ $scope.clearError();
+
+ var properties = $scope.getProperties(transform,jsonSpec);
+
+ ProcessorService.setProperties(processorId,revisionId,clientId,properties)
+ .then(function(response) {
+ var details = response.data;
+ $scope.populateScopeWithDetails(details);
+ $scope.saveStatus = "Changes saved successfully";
+ $scope.specUpdated = false;
+ })
+ .catch(function(response) {
+ $scope.showError("Error occurred during save properties",response.statusText);
+ });
+
+ };
+
+ $scope.initController = function(params){
+
+ $scope.processorId = params.id;
+ $scope.clientId = params.clientId;
+ $scope.revisionId = params.revision;
+ $scope.editable = eval(params.editable);
+
+ var jsonSpec = $scope.getSpec($scope.transform,$scope.jsonSpec);
+ if(jsonSpec != null && jsonSpec != ""){
+ setTimeout(function(){
+ $scope.$apply(function(){
+ $scope.validateJson($scope.jsonInput,jsonSpec,$scope.transform);
+ });
+ });
+ }
+
+ };
+
+ $scope.$watch("specEditor", function (newValue, oldValue ) {
+ $scope.toggleEditor(newValue,$scope.transform,false);
+ });
+
+ $scope.initController($state.params);
+
+
+};
+
+TransformJsonController.$inject = ['$scope', '$state', '$q', 'TransformJsonService', 'ProcessorService','details'];
+angular.module('standardUI').controller('TransformJsonController', TransformJsonController);
http://git-wip-us.apache.org/repos/asf/nifi/blob/cb3aa8f5/nifi-nar-bundles/nifi-standard-bundle/nifi-jolt-transform-json-ui/src/main/webapp/app/transformjson/transformjson.service.js
----------------------------------------------------------------------
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-jolt-transform-json-ui/src/main/webapp/app/transformjson/transformjson.service.js b/nifi-nar-bundles/nifi-standard-bundle/nifi-jolt-transform-json-ui/src/main/webapp/app/transformjson/transformjson.service.js
new file mode 100644
index 0000000..1e8bdcb
--- /dev/null
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-jolt-transform-json-ui/src/main/webapp/app/transformjson/transformjson.service.js
@@ -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.
+ */
+'use strict';
+
+var TransformJsonService = function TransformJsonService($http) {
+
+ return {
+ 'validate': validate,
+ 'execute' : execute
+ };
+
+
+ function validate(spec){
+ return $http({ url:'api/standard/transformjson/validate',method:'POST', data:spec });
+ }
+
+ function execute(spec){
+ return $http({ url:'api/standard/transformjson/execute',method:'POST', data:spec,
+ transformResponse: [function (data) {
+ return data;
+ }]});
+ }
+
+};
+
+TransformJsonService.$inject = ['$http'];
+angular.module('standardUI').factory('TransformJsonService', TransformJsonService);
http://git-wip-us.apache.org/repos/asf/nifi/blob/cb3aa8f5/nifi-nar-bundles/nifi-standard-bundle/nifi-jolt-transform-json-ui/src/main/webapp/app/transformjson/transformjson.state.js
----------------------------------------------------------------------
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-jolt-transform-json-ui/src/main/webapp/app/transformjson/transformjson.state.js b/nifi-nar-bundles/nifi-standard-bundle/nifi-jolt-transform-json-ui/src/main/webapp/app/transformjson/transformjson.state.js
new file mode 100644
index 0000000..7e580a6
--- /dev/null
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-jolt-transform-json-ui/src/main/webapp/app/transformjson/transformjson.state.js
@@ -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.
+ */
+'use strict';
+
+var TransformJsonState = function($stateProvider) {
+
+ $stateProvider
+ .state('jolttransformjson', {
+ url: "/transformjson?id&revision&clientId&editable",
+ templateUrl: "app/transformjson/transformjson.view.html",
+ controller: 'TransformJsonController',
+ resolve: {
+ details: ['ProcessorService','$stateParams',
+ function (ProcessorService,$stateParams) {
+ return ProcessorService.getDetails($stateParams.id);
+ }
+ ]
+ }
+ })
+
+};
+
+TransformJsonState.$inject = ['$stateProvider'];
+
+angular.module('standardUI').config(TransformJsonState);
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/nifi/blob/cb3aa8f5/nifi-nar-bundles/nifi-standard-bundle/nifi-jolt-transform-json-ui/src/main/webapp/app/transformjson/transformjson.view.html
----------------------------------------------------------------------
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-jolt-transform-json-ui/src/main/webapp/app/transformjson/transformjson.view.html b/nifi-nar-bundles/nifi-standard-bundle/nifi-jolt-transform-json-ui/src/main/webapp/app/transformjson/transformjson.view.html
new file mode 100644
index 0000000..5e12c1c
--- /dev/null
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-jolt-transform-json-ui/src/main/webapp/app/transformjson/transformjson.view.html
@@ -0,0 +1,117 @@
+<!--
+ 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.
+-->
+<div layout="column">
+
+ <div layout="column" layout>
+ <md-toolbar>
+ <div class="md-toolbar-tools large-label">
+ <span>
+ Jolt Transformation DSL
+ </span>
+ <span flex></span>
+ <span ng-show="(jsonSpec || transform == 'jolt-transform-sort') && !validObj.valid && !error">{{validObj.message}}</span>
+ <span ng-show="jsonSpec && validObj.valid && !error">Specification is Valid</span>
+ <span ng-show="error">{{error}}</span>
+ <span>
+
+ <button ng-click="validateJson(jsonInput,getSpec(transform,jsonSpec),transform)" ng-disabled="!(jsonSpec)">
+ Validate
+ </button>
+ </span>
+ </div>
+ <div class="md-toolbar-tools large-label">
+ <select ng-model="transform" ng-options="option.value as option.label for option in transformOptions | orderBy: 'label'" ng-change="toggleEditor(specEditor,transform,true)"></select>
+ </div>
+ <div class="md-toolbar-tools large-label">
+ <span>
+ Jolt Specification
+ </span>
+ <span flex></span>
+ <span class="info">
+
+ <button ng-click="formatEditor(specEditor)" ng-disabled="!jsonSpec || transform == 'jolt-transform-sort'">
+ Format
+ </button>
+ </span>
+ </div>
+ </md-toolbar>
+ <div id="specEditor" ui-refresh="true" ng-model="jsonSpec" ui-codemirror="editorProperties" class="code-mirror-editor {{disableCSS}}" >
+ </div>
+ </div>
+
+</div>
+
+<div layout="column">
+ <div layout="row">
+ <div flex></div>
+ <div class="large-label">
+ <br/>
+ <span ng-show="error">{{error}}</span>
+ <span ng-show="saveStatus && !error">{{saveStatus}}</span>
+ <span>
+ <button ng-click="saveSpec(jsonInput,getSpec(transform,jsonSpec),transform,processorId,clientId,revisionId)" ng-disabled="(!jsonSpec && transform != 'jolt-transform-sort') || !editable || !specUpdated">
+ Save
+ </button>
+ </span>
+ </div>
+ </div>
+</div>
+
+<div layout="column">
+
+ <div layout="row">
+ <div flex="45">
+ <md-toolbar>
+ <div class="md-toolbar-tools large-label">
+ <span>
+ JSON Input
+ </span>
+ <span flex></span>
+ <span class="info">
+
+ <button ng-click="formatEditor(inputEditor)" ng-disabled="!(jsonInput) || (!jsonSpec && transform != 'jolt-transform-sort')">
+ Format
+ </button>
+
+ </span>
+ </div>
+
+ </md-toolbar>
+ <div id="inputJson" ng-model="jsonInput" ui-refresh="true" ui-codemirror="inputProperties" class="code-mirror-editor"></div>
+ </div>
+
+ <div flex="10" layout="column" layout-align="center center">
+
+ <div class="large-label">
+ <button ng-click="transformJson(jsonInput,getSpec(transform,jsonSpec),transform)" ng-disabled="!(jsonInput) || (!jsonSpec && transform != 'jolt-transform-sort')">
+ Transform
+ </button>
+ </div>
+
+ </div>
+
+ <div flex="45">
+ <md-toolbar>
+ <div class="md-toolbar-tools large-label">
+ JSON Output
+ </div>
+ </md-toolbar>
+ <div id="outputJson" ng-model="jsonOutput" ui-refresh="true" ui-codemirror="outputProperties" class="code-mirror-editor"></div>
+ </div>
+
+ </div>
+
+</div>
+
http://git-wip-us.apache.org/repos/asf/nifi/blob/cb3aa8f5/nifi-nar-bundles/nifi-standard-bundle/nifi-jolt-transform-json-ui/src/main/webapp/css/main.css
----------------------------------------------------------------------
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-jolt-transform-json-ui/src/main/webapp/css/main.css b/nifi-nar-bundles/nifi-standard-bundle/nifi-jolt-transform-json-ui/src/main/webapp/css/main.css
new file mode 100644
index 0000000..59a7663
--- /dev/null
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-jolt-transform-json-ui/src/main/webapp/css/main.css
@@ -0,0 +1,55 @@
+/*
+ * 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.
+ */
+
+body {
+ font-family: Verdana, Arial, Helvetica, sans-serif;
+}
+
+div.code-mirror-editor {
+ border: 1px solid rgba(79, 70, 70, 0.13);
+}
+
+div.code-mirror-editor.trans {
+ opacity: 0.4;
+ filter: alpha(opacity=40); /* For IE8 and earlier */
+}
+
+.large-label {
+ color: #527991;
+ font-size: 13px;
+ font-weight: bold;
+ line-height: 19px;
+}
+
+div.md-toolbar-tools{
+ height: 30px;
+}
+
+md-toolbar {
+ min-height: 30px;
+}
+
+.CodeMirror {
+ border: 1px solid #eee;
+ height: 40vh;
+}
+
+.info {
+ font-style: italic;
+ color: rgb(170, 170, 170);
+ font-size: 75%;
+}
http://git-wip-us.apache.org/repos/asf/nifi/blob/cb3aa8f5/nifi-nar-bundles/nifi-standard-bundle/nifi-jolt-transform-json-ui/src/main/webapp/js/js-beautify/LICENSE
----------------------------------------------------------------------
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-jolt-transform-json-ui/src/main/webapp/js/js-beautify/LICENSE b/nifi-nar-bundles/nifi-standard-bundle/nifi-jolt-transform-json-ui/src/main/webapp/js/js-beautify/LICENSE
new file mode 100644
index 0000000..51da268
--- /dev/null
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-jolt-transform-json-ui/src/main/webapp/js/js-beautify/LICENSE
@@ -0,0 +1,21 @@
+The MIT License (MIT)
+
+Copyright (c) 2007-2013 Einar Lielmanis and contributors.
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
[5/5] nifi git commit: NIFI-1850 - Initial Commit for JSON-to-JSON
Schema Converter Editor (merge from 0.7.0 - refactor for masterless cluster).
This closes #511
Posted by mc...@apache.org.
NIFI-1850 - Initial Commit for JSON-to-JSON Schema Converter Editor (merge from 0.7.0 - refactor for masterless cluster). This closes #511
Project: http://git-wip-us.apache.org/repos/asf/nifi/repo
Commit: http://git-wip-us.apache.org/repos/asf/nifi/commit/cb3aa8f5
Tree: http://git-wip-us.apache.org/repos/asf/nifi/tree/cb3aa8f5
Diff: http://git-wip-us.apache.org/repos/asf/nifi/diff/cb3aa8f5
Branch: refs/heads/master
Commit: cb3aa8f5c9bd8632ad2f454dd3d73e33063e05e8
Parents: 274dc09
Author: Yolanda M. Davis <yo...@gmail.com>
Authored: Wed Jun 8 00:53:38 2016 -0400
Committer: Matt Gilman <ma...@gmail.com>
Committed: Mon Jun 20 20:30:25 2016 -0400
----------------------------------------------------------------------
LICENSE | 45 +
.../apache/nifi/web/ComponentDescriptor.java | 93 +
.../org/apache/nifi/web/ComponentDetails.java | 19 +
.../nifi/web/NiFiWebConfigurationContext.java | 5 +-
nifi-assembly/LICENSE | 90 +-
.../endpoints/ComponentStateEndpointMerger.java | 4 +-
.../org/apache/nifi/web/NiFiServiceFacade.java | 10 -
.../nifi/web/StandardNiFiServiceFacade.java | 39 -
.../StandardNiFiWebConfigurationContext.java | 91 +-
.../nifi-framework/nifi-web/nifi-web-ui/pom.xml | 2 +
.../src/main/resources/META-INF/LICENSE | 21 +
.../js/codemirror/addon/lint/json-lint.js | 31 +
.../webapp/js/codemirror/addon/lint/lint.css | 73 +
.../webapp/js/codemirror/addon/lint/lint.js | 239 ++
.../src/main/webapp/js/jsonlint/LICENSE | 21 +
.../src/main/webapp/js/jsonlint/jsonlint.min.js | 1 +
.../nifi-jolt-transform-json-ui/pom.xml | 227 ++
.../src/main/frontend/.bowerrc | 6 +
.../src/main/frontend/bower.json | 15 +
.../standard/api/AbstractStandardResource.java | 39 +
.../api/processor/ProcessorResource.java | 67 +
.../api/processor/ProcessorWebUtils.java | 88 +
.../transformjson/TransformJSONResource.java | 89 +
.../transformjson/dto/JoltSpecificationDTO.java | 63 +
.../api/transformjson/dto/ValidationDTO.java | 54 +
.../src/main/resources/META-INF/LICENSE | 320 +++
.../src/main/resources/META-INF/NOTICE | 53 +
.../META-INF/nifi-processor-configuration | 15 +
.../src/main/webapp/WEB-INF/jsp/index.jsp | 67 +
.../src/main/webapp/WEB-INF/web.xml | 50 +
.../src/main/webapp/app/app.js | 44 +
.../webapp/app/components/error/error.state.js | 30 +
.../webapp/app/components/error/error.view.html | 15 +
.../components/processor/processor.service.js | 53 +
.../src/main/webapp/app/main/main.controller.js | 35 +
.../src/main/webapp/app/main/main.state.js | 31 +
.../transformjson/transformjson.controller.js | 374 +++
.../app/transformjson/transformjson.service.js | 41 +
.../app/transformjson/transformjson.state.js | 39 +
.../app/transformjson/transformjson.view.html | 117 +
.../src/main/webapp/css/main.css | 55 +
.../src/main/webapp/js/js-beautify/LICENSE | 21 +
.../src/main/webapp/js/js-beautify/beautify.js | 2333 ++++++++++++++++++
.../api/processor/TestProcessorResource.java | 148 ++
.../api/processor/TestProcessorWebUtils.java | 94 +
.../TestTransformJSONResource.java | 178 ++
.../nifi-standard-nar/pom.xml | 5 +
.../src/main/resources/META-INF/LICENSE | 70 +-
.../nifi-standard-processors/pom.xml | 38 +-
.../processors/standard/JoltTransformJSON.java | 223 ++
.../nifi/processors/standard/TransformJSON.java | 247 --
.../org.apache.nifi.processor.Processor | 2 +-
.../additionalDetails.html | 36 +
.../additionalDetails.html | 36 -
.../standard/TestJoltTransformJSON.java | 232 ++
.../processors/standard/TestTransformJSON.java | 318 ---
.../TestJoltTransformJson/cardrOutput.json | 13 +
.../TestJoltTransformJson/cardrSpec.json | 7 +
.../TestJoltTransformJson/chainrOutput.json | 16 +
.../TestJoltTransformJson/chainrSpec.json | 29 +
.../TestJoltTransformJson/defaultrOutput.json | 24 +
.../TestJoltTransformJson/defaultrSpec.json | 10 +
.../resources/TestJoltTransformJson/input.json | 13 +
.../TestJoltTransformJson/removrOutput.json | 10 +
.../TestJoltTransformJson/removrSpec.json | 5 +
.../TestJoltTransformJson/shiftrOutput.json | 8 +
.../TestJoltTransformJson/shiftrSpec.json | 10 +
.../TestJoltTransformJson/sortrOutput.json | 13 +
.../TestTransformJson/cardrOutput.json | 13 -
.../resources/TestTransformJson/cardrSpec.json | 7 -
.../TestTransformJson/chainrOutput.json | 16 -
.../resources/TestTransformJson/chainrSpec.json | 29 -
.../TestTransformJson/defaultrOutput.json | 24 -
.../TestTransformJson/defaultrSpec.json | 10 -
.../test/resources/TestTransformJson/input.json | 13 -
.../TestTransformJson/removrOutput.json | 10 -
.../resources/TestTransformJson/removrSpec.json | 5 -
.../TestTransformJson/shiftrOutput.json | 8 -
.../resources/TestTransformJson/shiftrSpec.json | 10 -
.../TestTransformJson/sortrOutput.json | 13 -
.../nifi-standard-utils/pom.xml | 65 +
.../standard/util/TransformFactory.java | 46 +
.../standard/util/TestTransformFactory.java | 89 +
.../TestTransformFactory/cardrSpec.json | 7 +
.../TestTransformFactory/chainrSpec.json | 29 +
.../TestTransformFactory/defaultrSpec.json | 10 +
.../TestTransformFactory/removrSpec.json | 5 +
.../TestTransformFactory/shiftrSpec.json | 10 +
nifi-nar-bundles/nifi-standard-bundle/pom.xml | 8 +
.../update/attributes/api/RuleResource.java | 2 +-
90 files changed, 6488 insertions(+), 851 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/nifi/blob/cb3aa8f5/LICENSE
----------------------------------------------------------------------
diff --git a/LICENSE b/LICENSE
index 8ea8b3c..74473f9 100644
--- a/LICENSE
+++ b/LICENSE
@@ -538,3 +538,48 @@ This product bundles 'Fontello' which is available under an MIT license.
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
+
+This product bundles 'js-beautify' which is available under an MIT license.
+
+ Copyright (c) 2007-2013 Einar Lielmanis and contributors.
+
+ Permission is hereby granted, free of charge, to any person obtaining a copy
+ of this software and associated documentation files (the "Software"), to deal
+ in the Software without restriction, including without limitation the rights
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ copies of the Software, and to permit persons to whom the Software is
+ furnished to do so, subject to the following conditions:
+
+ The above copyright notice and this permission notice shall be included in
+ all copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ THE SOFTWARE.
+
+
+This product bundles 'jsonlint' which is available under an MIT license.
+
+ Copyright (C) 2012 Zachary Carter
+
+ Permission is hereby granted, free of charge, to any person obtaining a copy
+ of this software and associated documentation files (the "Software"), to deal
+ in the Software without restriction, including without limitation the rights
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ copies of the Software, and to permit persons to whom the Software is
+ furnished to do so, subject to the following conditions:
+
+ The above copyright notice and this permission notice shall be included in
+ all copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ THE SOFTWARE.
http://git-wip-us.apache.org/repos/asf/nifi/blob/cb3aa8f5/nifi-api/src/main/java/org/apache/nifi/web/ComponentDescriptor.java
----------------------------------------------------------------------
diff --git a/nifi-api/src/main/java/org/apache/nifi/web/ComponentDescriptor.java b/nifi-api/src/main/java/org/apache/nifi/web/ComponentDescriptor.java
new file mode 100644
index 0000000..9412ee1
--- /dev/null
+++ b/nifi-api/src/main/java/org/apache/nifi/web/ComponentDescriptor.java
@@ -0,0 +1,93 @@
+/*
+ * 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.web;
+
+import java.util.Map;
+
+public class ComponentDescriptor {
+
+ private final String name;
+ private final String displayName;
+ private final String description;
+ private final String defaultValue;
+ private final Map<String,String> allowableValues;
+
+ private ComponentDescriptor(Builder builder){
+ this.name = builder.name;
+ this.displayName = builder.displayName;
+ this.description = builder.description;
+ this.defaultValue = builder.defaultValue;
+ this.allowableValues = builder.allowableValues;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public String getDisplayName() {
+ return displayName;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+
+ public String getDefaultValue() {
+ return defaultValue;
+ }
+
+ public Map<String,String> getAllowableValues() {
+ return allowableValues;
+ }
+
+ public static final class Builder{
+ private String name;
+ private String displayName;
+ private String description;
+ private String defaultValue;
+ private Map<String,String> allowableValues;
+
+ public Builder name(String name){
+ this.name = name;
+ return this;
+ }
+
+ public Builder displayName(String displayName){
+ this.displayName = displayName;
+ return this;
+ }
+
+ public Builder description(String description){
+ this.description = description;
+ return this;
+ }
+
+ public Builder defaultValue(String defaultValue){
+ this.defaultValue = defaultValue;
+ return this;
+ }
+
+ public Builder allowableValues(Map<String,String> allowableValues){
+ this.allowableValues = allowableValues;
+ return this;
+ }
+
+ public ComponentDescriptor build(){
+ return new ComponentDescriptor(this);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/nifi/blob/cb3aa8f5/nifi-api/src/main/java/org/apache/nifi/web/ComponentDetails.java
----------------------------------------------------------------------
diff --git a/nifi-api/src/main/java/org/apache/nifi/web/ComponentDetails.java b/nifi-api/src/main/java/org/apache/nifi/web/ComponentDetails.java
index 5614fc2..9d163e4 100644
--- a/nifi-api/src/main/java/org/apache/nifi/web/ComponentDetails.java
+++ b/nifi-api/src/main/java/org/apache/nifi/web/ComponentDetails.java
@@ -31,6 +31,8 @@ public class ComponentDetails {
private final String state;
private final String annotationData;
private final Map<String, String> properties;
+ private final Map<String, ComponentDescriptor> descriptors;
+
private final Collection<String> validationErrors;
private ComponentDetails(final Builder builder) {
@@ -40,7 +42,9 @@ public class ComponentDetails {
this.state = builder.state;
this.annotationData = builder.annotationData;
this.properties = builder.properties;
+ this.descriptors = builder.descriptors;
this.validationErrors = builder.validationErrors;
+
}
/**
@@ -85,6 +89,14 @@ public class ComponentDetails {
return properties;
}
+
+ /**
+ * @return Mapping of component descriptors
+ */
+ public Map<String,ComponentDescriptor> getDescriptors(){
+ return descriptors;
+ }
+
/**
* @return Current validation errors for the component
*/
@@ -100,6 +112,8 @@ public class ComponentDetails {
private String state;
private String annotationData;
private Map<String, String> properties;
+ private Map<String,ComponentDescriptor> descriptors;
+
private Collection<String> validationErrors;
public Builder id(final String id) {
@@ -137,6 +151,11 @@ public class ComponentDetails {
return this;
}
+ public Builder descriptors(final Map<String,ComponentDescriptor> descriptors){
+ this.descriptors = descriptors;
+ return this;
+ }
+
public ComponentDetails build() {
return new ComponentDetails(this);
}
http://git-wip-us.apache.org/repos/asf/nifi/blob/cb3aa8f5/nifi-api/src/main/java/org/apache/nifi/web/NiFiWebConfigurationContext.java
----------------------------------------------------------------------
diff --git a/nifi-api/src/main/java/org/apache/nifi/web/NiFiWebConfigurationContext.java b/nifi-api/src/main/java/org/apache/nifi/web/NiFiWebConfigurationContext.java
index e2689af..a0a605c 100644
--- a/nifi-api/src/main/java/org/apache/nifi/web/NiFiWebConfigurationContext.java
+++ b/nifi-api/src/main/java/org/apache/nifi/web/NiFiWebConfigurationContext.java
@@ -17,6 +17,7 @@
package org.apache.nifi.web;
import java.util.Collection;
+import java.util.Map;
import org.apache.nifi.controller.ControllerService;
@@ -69,6 +70,7 @@ public interface NiFiWebConfigurationContext {
*
* @param configurationContext config context
* @param annotationData the data
+ * @param properties component properties
* @return the configuration for the underlying component
* @throws ResourceNotFoundException if the underlying component does not
* exit
@@ -80,9 +82,10 @@ public interface NiFiWebConfigurationContext {
* @throws IllegalArgumentException When the requestContext isn't fully
* populated or isn't appropriate for the given request
*/
- ComponentDetails setAnnotationData(NiFiWebConfigurationRequestContext configurationContext, String annotationData)
+ ComponentDetails updateComponent(NiFiWebConfigurationRequestContext configurationContext, String annotationData, Map<String, String> properties)
throws ResourceNotFoundException, InvalidRevisionException, ClusterRequestException;
+
/**
* Gets the details for the underlying component (including configuration,
* validation errors, and annotation data).
http://git-wip-us.apache.org/repos/asf/nifi/blob/cb3aa8f5/nifi-assembly/LICENSE
----------------------------------------------------------------------
diff --git a/nifi-assembly/LICENSE b/nifi-assembly/LICENSE
index dcf296d..477b745 100644
--- a/nifi-assembly/LICENSE
+++ b/nifi-assembly/LICENSE
@@ -679,6 +679,50 @@ This product bundles 'Angular Messages' which is available under an MIT license.
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+This product bundles 'AngularUI Codemirror' which is available under an MIT license.
+
+ Copyright (c) 2012 the AngularUI Team, http://angular-ui.github.com
+
+ Permission is hereby granted, free of charge, to any person obtaining a copy
+ of this software and associated documentation files (the "Software"), to deal
+ in the Software without restriction, including without limitation the rights
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ copies of the Software, and to permit persons to whom the Software is
+ furnished to do so, subject to the following conditions:
+
+ The above copyright notice and this permission notice shall be included in
+ all copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ THE SOFTWARE.
+
+This product bundles 'AngularUI Router' which is available under an MIT license.
+
+ Copyright (c) 2013-2015 The AngularUI Team, Karsten Sperling
+
+ Permission is hereby granted, free of charge, to any person obtaining a copy
+ of this software and associated documentation files (the "Software"), to deal
+ in the Software without restriction, including without limitation the rights
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ copies of the Software, and to permit persons to whom the Software is
+ furnished to do so, subject to the following conditions:
+
+ The above copyright notice and this permission notice shall be included in
+ all copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ THE SOFTWARE.
+
This product bundles 'Fontello' which is available under an MIT license.
Copyright (C) 2011 by Vitaly Puzrin
@@ -1358,4 +1402,48 @@ For details see https://github.com/bazaarvoice/jolt/blob/jolt-0.0.20/LICENSE
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.
\ No newline at end of file
+ limitations under the License.
+
+This product bundles 'js-beautify' which is available under an MIT license.
+
+ Copyright (c) 2007-2013 Einar Lielmanis and contributors.
+
+ Permission is hereby granted, free of charge, to any person obtaining a copy
+ of this software and associated documentation files (the "Software"), to deal
+ in the Software without restriction, including without limitation the rights
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ copies of the Software, and to permit persons to whom the Software is
+ furnished to do so, subject to the following conditions:
+
+ The above copyright notice and this permission notice shall be included in
+ all copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ THE SOFTWARE.
+
+This product bundles 'jsonlint' which is available under an MIT license.
+
+ Copyright (C) 2012 Zachary Carter
+
+ Permission is hereby granted, free of charge, to any person obtaining a copy
+ of this software and associated documentation files (the "Software"), to deal
+ in the Software without restriction, including without limitation the rights
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ copies of the Software, and to permit persons to whom the Software is
+ furnished to do so, subject to the following conditions:
+
+ The above copyright notice and this permission notice shall be included in
+ all copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ THE SOFTWARE.
http://git-wip-us.apache.org/repos/asf/nifi/blob/cb3aa8f5/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/main/java/org/apache/nifi/cluster/coordination/http/endpoints/ComponentStateEndpointMerger.java
----------------------------------------------------------------------
diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/main/java/org/apache/nifi/cluster/coordination/http/endpoints/ComponentStateEndpointMerger.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/main/java/org/apache/nifi/cluster/coordination/http/endpoints/ComponentStateEndpointMerger.java
index 9976de2..5ab71c9 100644
--- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/main/java/org/apache/nifi/cluster/coordination/http/endpoints/ComponentStateEndpointMerger.java
+++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/main/java/org/apache/nifi/cluster/coordination/http/endpoints/ComponentStateEndpointMerger.java
@@ -35,8 +35,8 @@ import org.apache.nifi.web.api.entity.ComponentStateEntity;
public class ComponentStateEndpointMerger extends AbstractSingleDTOEndpoint<ComponentStateEntity, ComponentStateDTO> {
public static final Pattern PROCESSOR_STATE_URI_PATTERN = Pattern.compile("/nifi-api/processors/[a-f0-9\\-]{36}/state");
- public static final Pattern CONTROLLER_SERVICE_STATE_URI_PATTERN = Pattern.compile("/nifi-api/controller-services/node/[a-f0-9\\-]{36}/state");
- public static final Pattern REPORTING_TASK_STATE_URI_PATTERN = Pattern.compile("/nifi-api/reporting-tasks/node/[a-f0-9\\-]{36}/state");
+ public static final Pattern CONTROLLER_SERVICE_STATE_URI_PATTERN = Pattern.compile("/nifi-api/controller-services/[a-f0-9\\-]{36}/state");
+ public static final Pattern REPORTING_TASK_STATE_URI_PATTERN = Pattern.compile("/nifi-api/reporting-tasks/[a-f0-9\\-]{36}/state");
@Override
public boolean canHandle(URI uri, String method) {
http://git-wip-us.apache.org/repos/asf/nifi/blob/cb3aa8f5/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/NiFiServiceFacade.java
----------------------------------------------------------------------
diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/NiFiServiceFacade.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/NiFiServiceFacade.java
index ecd6d34..cd27e0d 100644
--- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/NiFiServiceFacade.java
+++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/NiFiServiceFacade.java
@@ -299,16 +299,6 @@ public interface NiFiServiceFacade {
*/
ProcessGroupEntity createArchive();
- /**
- * Sets the annotation data for a processor.
- *
- * @param revision the revision to compare with current base revision
- * @param processorId the id of the processor to update
- * @param annotationData the annotation data
- *
- * @return snapshot
- */
- ProcessorEntity setProcessorAnnotationData(Revision revision, String processorId, String annotationData);
/**
* Returns the process group status.
http://git-wip-us.apache.org/repos/asf/nifi/blob/cb3aa8f5/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/StandardNiFiServiceFacade.java
----------------------------------------------------------------------
diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/StandardNiFiServiceFacade.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/StandardNiFiServiceFacade.java
index 3d5f650..21ea757 100644
--- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/StandardNiFiServiceFacade.java
+++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/StandardNiFiServiceFacade.java
@@ -124,7 +124,6 @@ import org.apache.nifi.web.api.dto.NodeDTO;
import org.apache.nifi.web.api.dto.PortDTO;
import org.apache.nifi.web.api.dto.PreviousValueDTO;
import org.apache.nifi.web.api.dto.ProcessGroupDTO;
-import org.apache.nifi.web.api.dto.ProcessorConfigDTO;
import org.apache.nifi.web.api.dto.ProcessorDTO;
import org.apache.nifi.web.api.dto.PropertyDescriptorDTO;
import org.apache.nifi.web.api.dto.PropertyHistoryDTO;
@@ -1587,44 +1586,6 @@ public class StandardNiFiServiceFacade implements NiFiServiceFacade {
}
@Override
- public ProcessorEntity setProcessorAnnotationData(final Revision revision, final String processorId, final String annotationData) {
- final NiFiUser user = NiFiUserUtils.getNiFiUser();
- final String modifier = user.getUserName();
-
- final RevisionUpdate<ProcessorEntity> update = revisionManager.updateRevision(new StandardRevisionClaim(revision), user, new UpdateRevisionTask<ProcessorEntity>() {
- @Override
- public RevisionUpdate<ProcessorEntity> update() {
- // create the processor config
- final ProcessorConfigDTO config = new ProcessorConfigDTO();
- config.setAnnotationData(annotationData);
-
- // create the processor dto
- final ProcessorDTO processorDTO = new ProcessorDTO();
- processorDTO.setId(processorId);
- processorDTO.setConfig(config);
-
- // update the processor configuration
- final ProcessorNode processor = processorDAO.updateProcessor(processorDTO);
-
- final ProcessorDTO updatedProcDto = dtoFactory.createProcessorDto(processor);
-
- // save the flow
- controllerFacade.save();
-
- final AccessPolicyDTO accessPolicy = dtoFactory.createAccessPolicyDto(processor);
- final FlowModification lastMod = new FlowModification(incrementRevision(revision), modifier);
- final ProcessorStatusDTO status = dtoFactory.createProcessorStatusDto(controllerFacade.getProcessorStatus(processor.getIdentifier()));
- final List<BulletinDTO> bulletins = dtoFactory.createBulletinDtos(bulletinRepository.findBulletinsForSource(processor.getIdentifier()));
- final ProcessorEntity entity = entityFactory.createProcessorEntity(updatedProcDto, dtoFactory.createRevisionDTO(lastMod), accessPolicy, status, bulletins);
-
- return new StandardRevisionUpdate<>(entity, lastMod);
- }
- });
-
- return update.getComponent();
- }
-
- @Override
public ControllerServiceEntity createControllerService(final String groupId, final ControllerServiceDTO controllerServiceDTO) {
controllerServiceDTO.setParentGroupId(groupId);
http://git-wip-us.apache.org/repos/asf/nifi/blob/cb3aa8f5/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/StandardNiFiWebConfigurationContext.java
----------------------------------------------------------------------
diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/StandardNiFiWebConfigurationContext.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/StandardNiFiWebConfigurationContext.java
index 6bcdf61..1dc9b89 100644
--- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/StandardNiFiWebConfigurationContext.java
+++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/StandardNiFiWebConfigurationContext.java
@@ -47,6 +47,7 @@ import org.apache.nifi.util.NiFiProperties;
import org.apache.nifi.web.api.dto.ControllerServiceDTO;
import org.apache.nifi.web.api.dto.ProcessorConfigDTO;
import org.apache.nifi.web.api.dto.ProcessorDTO;
+import org.apache.nifi.web.api.dto.PropertyDescriptorDTO;
import org.apache.nifi.web.api.dto.ReportingTaskDTO;
import org.apache.nifi.web.api.dto.RevisionDTO;
import org.apache.nifi.web.api.entity.ControllerServiceEntity;
@@ -71,6 +72,7 @@ import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
+import java.util.List;
import java.util.Map;
import java.util.Objects;
@@ -249,7 +251,7 @@ public class StandardNiFiWebConfigurationContext implements NiFiWebConfiguration
}
@Override
- public ComponentDetails setAnnotationData(final NiFiWebConfigurationRequestContext requestContext, final String annotationData)
+ public ComponentDetails updateComponent(final NiFiWebConfigurationRequestContext requestContext, final String annotationData, Map<String, String> properties)
throws ResourceNotFoundException, InvalidRevisionException, ClusterRequestException {
final String id = requestContext.getId();
@@ -281,7 +283,7 @@ public class StandardNiFiWebConfigurationContext implements NiFiWebConfiguration
throw new IllegalArgumentException("UI extension type must support Processor, ControllerService, or ReportingTask configuration.");
}
- return componentFacade.setAnnotationData(requestContext, annotationData);
+ return componentFacade.updateComponent(requestContext, annotationData, properties);
}
/**
@@ -302,9 +304,10 @@ public class StandardNiFiWebConfigurationContext implements NiFiWebConfiguration
*
* @param requestContext context
* @param annotationData data
+ * @param properties properties
* @return details
*/
- ComponentDetails setAnnotationData(NiFiWebConfigurationRequestContext requestContext, String annotationData);
+ ComponentDetails updateComponent(NiFiWebConfigurationRequestContext requestContext, String annotationData, Map<String, String> properties);
}
/**
@@ -363,7 +366,7 @@ public class StandardNiFiWebConfigurationContext implements NiFiWebConfiguration
}
@Override
- public ComponentDetails setAnnotationData(final NiFiWebConfigurationRequestContext requestContext, final String annotationData) {
+ public ComponentDetails updateComponent(final NiFiWebConfigurationRequestContext requestContext, final String annotationData, Map<String, String> properties) {
final NiFiUser user = NiFiUserUtils.getNiFiUser();
final Revision revision = requestContext.getRevision();
final String id = requestContext.getId();
@@ -375,7 +378,7 @@ public class StandardNiFiWebConfigurationContext implements NiFiWebConfiguration
});
final ProcessorDTO processor;
- if (properties.isClustered()) {
+ if (StandardNiFiWebConfigurationContext.this.properties.isClustered()) {
// create the request URL
URI requestUrl;
try {
@@ -395,14 +398,8 @@ public class StandardNiFiWebConfigurationContext implements NiFiWebConfiguration
processorEntity.setRevision(revisionDto);
// create the processor dto
- final ProcessorDTO processorDto = new ProcessorDTO();
+ ProcessorDTO processorDto = buildProcessorDto(id,annotationData,properties);
processorEntity.setComponent(processorDto);
- processorDto.setId(id);
-
- // create the processor configuration with the given annotation data
- final ProcessorConfigDTO configDto = new ProcessorConfigDTO();
- processorDto.setConfig(configDto);
- configDto.setAnnotationData(annotationData);
// set the content type to json
final Map<String, String> headers = getHeaders(requestContext);
@@ -429,8 +426,11 @@ public class StandardNiFiWebConfigurationContext implements NiFiWebConfiguration
// claim the revision
serviceFacade.claimRevision(revision, user);
try {
- final ProcessorEntity entity = serviceFacade.setProcessorAnnotationData(revision, id, annotationData);
- processor = entity.getComponent();
+
+ ProcessorDTO processorDTO = buildProcessorDto(id,annotationData,properties);
+ final UpdateResult<ProcessorEntity> entity = serviceFacade.updateProcessor(revision,processorDTO);
+ processor = entity.getResult().getComponent();
+
} finally {
// ensure the revision is canceled.. if the operation succeed, this is a noop
serviceFacade.cancelRevision(revision);
@@ -441,6 +441,17 @@ public class StandardNiFiWebConfigurationContext implements NiFiWebConfiguration
return getComponentConfiguration(processor);
}
+ private ProcessorDTO buildProcessorDto(String id, final String annotationData, Map<String, String> properties){
+ ProcessorDTO processorDto = new ProcessorDTO();
+ processorDto.setId(id);
+ ProcessorConfigDTO configDto = new ProcessorConfigDTO();
+ processorDto.setConfig(configDto);
+ configDto.setAnnotationData(annotationData);
+ configDto.setProperties(properties);
+ return processorDto;
+
+ }
+
private ComponentDetails getComponentConfiguration(final ProcessorDTO processor) {
final ProcessorConfigDTO processorConfig = processor.getConfig();
return new ComponentDetails.Builder()
@@ -450,8 +461,40 @@ public class StandardNiFiWebConfigurationContext implements NiFiWebConfiguration
.state(processor.getState())
.annotationData(processorConfig.getAnnotationData())
.properties(processorConfig.getProperties())
+ .descriptors(buildComponentDescriptorMap(processorConfig))
.validateErrors(processor.getValidationErrors()).build();
}
+
+ private Map<String,ComponentDescriptor> buildComponentDescriptorMap(final ProcessorConfigDTO processorConfig){
+
+ final Map<String, ComponentDescriptor> descriptors = new HashMap<>();
+
+ for(String key : processorConfig.getDescriptors().keySet()){
+
+ PropertyDescriptorDTO descriptor = processorConfig.getDescriptors().get(key);
+ List<PropertyDescriptorDTO.AllowableValueDTO> allowableValuesDTO = descriptor.getAllowableValues();
+ Map<String,String> allowableValues = new HashMap<>();
+
+ if(allowableValuesDTO != null) {
+ for (PropertyDescriptorDTO.AllowableValueDTO value : allowableValuesDTO) {
+ allowableValues.put(value.getValue(), value.getDisplayName());
+ }
+ }
+
+ ComponentDescriptor componentDescriptor = new ComponentDescriptor.Builder()
+ .name(descriptor.getName())
+ .displayName(descriptor.getDisplayName())
+ .defaultValue(descriptor.getDefaultValue())
+ .allowableValues(allowableValues)
+ .build();
+
+
+ descriptors.put(key,componentDescriptor);
+ }
+
+ return descriptors;
+ }
+
}
/**
@@ -484,7 +527,7 @@ public class StandardNiFiWebConfigurationContext implements NiFiWebConfiguration
// create the request URL
URI requestUrl;
try {
- final String path = "/nifi-api/controller-services/node/" + URLEncoder.encode(id, "UTF-8");
+ String path = "/nifi-api/controller-services/" + URLEncoder.encode(id, "UTF-8");
requestUrl = new URI(requestContext.getScheme(), null, "localhost", 0, path, null, null);
} catch (final URISyntaxException | UnsupportedEncodingException use) {
throw new ClusterRequestException(use);
@@ -517,7 +560,7 @@ public class StandardNiFiWebConfigurationContext implements NiFiWebConfiguration
}
@Override
- public ComponentDetails setAnnotationData(final NiFiWebConfigurationRequestContext requestContext, final String annotationData) {
+ public ComponentDetails updateComponent(final NiFiWebConfigurationRequestContext requestContext, final String annotationData, Map<String, String> properties) {
final NiFiUser user = NiFiUserUtils.getNiFiUser();
final Revision revision = requestContext.getRevision();
final String id = requestContext.getId();
@@ -533,6 +576,7 @@ public class StandardNiFiWebConfigurationContext implements NiFiWebConfiguration
final ControllerServiceDTO controllerServiceDto = new ControllerServiceDTO();
controllerServiceDto.setId(id);
controllerServiceDto.setAnnotationData(annotationData);
+ controllerServiceDto.setProperties(properties);
// claim the revision
serviceFacade.claimRevision(revision, user);
@@ -547,7 +591,7 @@ public class StandardNiFiWebConfigurationContext implements NiFiWebConfiguration
} else {
// if this is a standalone instance the service should have been found above... there should
// no cluster to replicate the request to
- if (!properties.isClustered()) {
+ if (!StandardNiFiWebConfigurationContext.this.properties.isClustered()) {
throw new ResourceNotFoundException(String.format("Controller service[%s] could not be found on this NiFi.", id));
}
@@ -560,7 +604,7 @@ public class StandardNiFiWebConfigurationContext implements NiFiWebConfiguration
// create the request URL
URI requestUrl;
try {
- final String path = "/nifi-api/controller-services/node/" + URLEncoder.encode(id, "UTF-8");
+ String path = "/nifi-api/controller-services/" + URLEncoder.encode(id, "UTF-8");
requestUrl = new URI(requestContext.getScheme(), null, "localhost", 0, path, null, null);
} catch (final URISyntaxException | UnsupportedEncodingException use) {
throw new ClusterRequestException(use);
@@ -580,6 +624,7 @@ public class StandardNiFiWebConfigurationContext implements NiFiWebConfiguration
controllerServiceEntity.setComponent(controllerServiceDto);
controllerServiceDto.setId(id);
controllerServiceDto.setAnnotationData(annotationData);
+ controllerServiceDto.setProperties(properties);
// set the content type to json
final Map<String, String> headers = getHeaders(requestContext);
@@ -650,7 +695,7 @@ public class StandardNiFiWebConfigurationContext implements NiFiWebConfiguration
// create the request URL
URI requestUrl;
try {
- final String path = "/nifi-api/reporting-tasks/node/" + URLEncoder.encode(id, "UTF-8");
+ String path = "/nifi-api/reporting-tasks/" + URLEncoder.encode(id, "UTF-8");
requestUrl = new URI(requestContext.getScheme(), null, "localhost", 0, path, null, null);
} catch (final URISyntaxException | UnsupportedEncodingException use) {
throw new ClusterRequestException(use);
@@ -683,7 +728,7 @@ public class StandardNiFiWebConfigurationContext implements NiFiWebConfiguration
}
@Override
- public ComponentDetails setAnnotationData(final NiFiWebConfigurationRequestContext requestContext, final String annotationData) {
+ public ComponentDetails updateComponent(final NiFiWebConfigurationRequestContext requestContext, final String annotationData, Map<String, String> properties) {
final NiFiUser user = NiFiUserUtils.getNiFiUser();
final Revision revision = requestContext.getRevision();
final String id = requestContext.getId();
@@ -699,6 +744,7 @@ public class StandardNiFiWebConfigurationContext implements NiFiWebConfiguration
final ReportingTaskDTO reportingTaskDto = new ReportingTaskDTO();
reportingTaskDto.setId(id);
reportingTaskDto.setAnnotationData(annotationData);
+ reportingTaskDto.setProperties(properties);
// claim the revision
serviceFacade.claimRevision(revision, user);
@@ -712,7 +758,7 @@ public class StandardNiFiWebConfigurationContext implements NiFiWebConfiguration
} else {
// if this is a standalone instance the task should have been found above... there should
// no cluster to replicate the request to
- if (!properties.isClustered()) {
+ if (!StandardNiFiWebConfigurationContext.this.properties.isClustered()) {
throw new ResourceNotFoundException(String.format("Reporting task[%s] could not be found on this NiFi.", id));
}
@@ -725,7 +771,7 @@ public class StandardNiFiWebConfigurationContext implements NiFiWebConfiguration
// create the request URL
URI requestUrl;
try {
- final String path = "/nifi-api/reporting-tasks/node/" + URLEncoder.encode(id, "UTF-8");
+ String path = "/nifi-api/reporting-tasks/" + URLEncoder.encode(id, "UTF-8");
requestUrl = new URI(requestContext.getScheme(), null, "localhost", 0, path, null, null);
} catch (final URISyntaxException | UnsupportedEncodingException use) {
throw new ClusterRequestException(use);
@@ -745,6 +791,7 @@ public class StandardNiFiWebConfigurationContext implements NiFiWebConfiguration
reportingTaskEntity.setComponent(reportingTaskDto);
reportingTaskDto.setId(id);
reportingTaskDto.setAnnotationData(annotationData);
+ reportingTaskDto.setProperties(properties);
// set the content type to json
final Map<String, String> headers = getHeaders(requestContext);
http://git-wip-us.apache.org/repos/asf/nifi/blob/cb3aa8f5/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/pom.xml
----------------------------------------------------------------------
diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/pom.xml b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/pom.xml
index c52f6f0..cf3edcc 100644
--- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/pom.xml
+++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/pom.xml
@@ -675,6 +675,7 @@
js/d3/**/*,
js/codemirror/**/*,
js/jquery/**/*,
+ js/jsonlint/**/*,
js/nf/nf-namespace.js,
js/nf/nf-namespace.js.gz,
js/nf/nf-ng-namespace.js,
@@ -729,6 +730,7 @@
<exclude>src/main/webapp/js/jquery/</exclude>
<exclude>src/main/webapp/js/d3/d3.min.js</exclude>
<exclude>src/main/webapp/js/codemirror/</exclude>
+ <exclude>src/main/webapp/js/jsonlint/</exclude>
<exclude>src/main/webapp/css/reset.css</exclude>
<exclude>src/main/webapp/js/angular/**/*</exclude>
<exclude>src/main/webapp/fonts/**/*</exclude>
http://git-wip-us.apache.org/repos/asf/nifi/blob/cb3aa8f5/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/resources/META-INF/LICENSE
----------------------------------------------------------------------
diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/resources/META-INF/LICENSE b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/resources/META-INF/LICENSE
index a2592fe..16b808d 100644
--- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/resources/META-INF/LICENSE
+++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/resources/META-INF/LICENSE
@@ -646,3 +646,24 @@ This product bundles 'Fontello' which is available under an MIT license.
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
+This product bundles 'jsonlint' which is available under an MIT license.
+
+ Copyright (C) 2012 Zachary Carter
+
+ Permission is hereby granted, free of charge, to any person obtaining a copy
+ of this software and associated documentation files (the "Software"), to deal
+ in the Software without restriction, including without limitation the rights
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ copies of the Software, and to permit persons to whom the Software is
+ furnished to do so, subject to the following conditions:
+
+ The above copyright notice and this permission notice shall be included in
+ all copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ THE SOFTWARE.
http://git-wip-us.apache.org/repos/asf/nifi/blob/cb3aa8f5/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/webapp/js/codemirror/addon/lint/json-lint.js
----------------------------------------------------------------------
diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/webapp/js/codemirror/addon/lint/json-lint.js b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/webapp/js/codemirror/addon/lint/json-lint.js
new file mode 100644
index 0000000..9dbb616
--- /dev/null
+++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/webapp/js/codemirror/addon/lint/json-lint.js
@@ -0,0 +1,31 @@
+// CodeMirror, copyright (c) by Marijn Haverbeke and others
+// Distributed under an MIT license: http://codemirror.net/LICENSE
+
+// Depends on jsonlint.js from https://github.com/zaach/jsonlint
+
+// declare global: jsonlint
+
+(function(mod) {
+ if (typeof exports == "object" && typeof module == "object") // CommonJS
+ mod(require("../../lib/codemirror"));
+ else if (typeof define == "function" && define.amd) // AMD
+ define(["../../lib/codemirror"], mod);
+ else // Plain browser env
+ mod(CodeMirror);
+})(function(CodeMirror) {
+"use strict";
+
+CodeMirror.registerHelper("lint", "json", function(text) {
+ var found = [];
+ jsonlint.parseError = function(str, hash) {
+ var loc = hash.loc;
+ found.push({from: CodeMirror.Pos(loc.first_line - 1, loc.first_column),
+ to: CodeMirror.Pos(loc.last_line - 1, loc.last_column),
+ message: str});
+ };
+ try { jsonlint.parse(text); }
+ catch(e) {}
+ return found;
+});
+
+});
http://git-wip-us.apache.org/repos/asf/nifi/blob/cb3aa8f5/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/webapp/js/codemirror/addon/lint/lint.css
----------------------------------------------------------------------
diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/webapp/js/codemirror/addon/lint/lint.css b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/webapp/js/codemirror/addon/lint/lint.css
new file mode 100644
index 0000000..414a9a0
--- /dev/null
+++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/webapp/js/codemirror/addon/lint/lint.css
@@ -0,0 +1,73 @@
+/* The lint marker gutter */
+.CodeMirror-lint-markers {
+ width: 16px;
+}
+
+.CodeMirror-lint-tooltip {
+ background-color: infobackground;
+ border: 1px solid black;
+ border-radius: 4px 4px 4px 4px;
+ color: infotext;
+ font-family: monospace;
+ font-size: 10pt;
+ overflow: hidden;
+ padding: 2px 5px;
+ position: fixed;
+ white-space: pre;
+ white-space: pre-wrap;
+ z-index: 100;
+ max-width: 600px;
+ opacity: 0;
+ transition: opacity .4s;
+ -moz-transition: opacity .4s;
+ -webkit-transition: opacity .4s;
+ -o-transition: opacity .4s;
+ -ms-transition: opacity .4s;
+}
+
+.CodeMirror-lint-mark-error, .CodeMirror-lint-mark-warning {
+ background-position: left bottom;
+ background-repeat: repeat-x;
+}
+
+.CodeMirror-lint-mark-error {
+ background-image:
+ url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAQAAAADCAYAAAC09K7GAAAAAXNSR0IArs4c6QAAAAZiS0dEAP8A/wD/oL2nkwAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB9sJDw4cOCW1/KIAAAAZdEVYdENvbW1lbnQAQ3JlYXRlZCB3aXRoIEdJTVBXgQ4XAAAAHElEQVQI12NggIL/DAz/GdA5/xkY/qPKMDAwAADLZwf5rvm+LQAAAABJRU5ErkJggg==")
+ ;
+}
+
+.CodeMirror-lint-mark-warning {
+ background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAQAAAADCAYAAAC09K7GAAAAAXNSR0IArs4c6QAAAAZiS0dEAP8A/wD/oL2nkwAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB9sJFhQXEbhTg7YAAAAZdEVYdENvbW1lbnQAQ3JlYXRlZCB3aXRoIEdJTVBXgQ4XAAAAMklEQVQI12NkgIIvJ3QXMjAwdDN+OaEbysDA4MPAwNDNwMCwiOHLCd1zX07o6kBVGQEAKBANtobskNMAAAAASUVORK5CYII=");
+}
+
+.CodeMirror-lint-marker-error, .CodeMirror-lint-marker-warning {
+ background-position: center center;
+ background-repeat: no-repeat;
+ cursor: pointer;
+ display: inline-block;
+ height: 16px;
+ width: 16px;
+ vertical-align: middle;
+ position: relative;
+}
+
+.CodeMirror-lint-message-error, .CodeMirror-lint-message-warning {
+ padding-left: 18px;
+ background-position: top left;
+ background-repeat: no-repeat;
+}
+
+.CodeMirror-lint-marker-error, .CodeMirror-lint-message-error {
+ background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAMAAAAoLQ9TAAAAHlBMVEW7AAC7AACxAAC7AAC7AAAAAAC4AAC5AAD///+7AAAUdclpAAAABnRSTlMXnORSiwCK0ZKSAAAATUlEQVR42mWPOQ7AQAgDuQLx/z8csYRmPRIFIwRGnosRrpamvkKi0FTIiMASR3hhKW+hAN6/tIWhu9PDWiTGNEkTtIOucA5Oyr9ckPgAWm0GPBog6v4AAAAASUVORK5CYII=");
+}
+
+.CodeMirror-lint-marker-warning, .CodeMirror-lint-message-warning {
+ background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAMAAAAoLQ9TAAAANlBMVEX/uwDvrwD/uwD/uwD/uwD/uwD/uwD/uwD/uwD6twD/uwAAAADurwD2tQD7uAD+ugAAAAD/uwDhmeTRAAAADHRSTlMJ8mN1EYcbmiixgACm7WbuAAAAVklEQVR42n3PUQqAIBBFUU1LLc3u/jdbOJoW1P08DA9Gba8+YWJ6gNJoNYIBzAA2chBth5kLmG9YUoG0NHAUwFXwO9LuBQL1giCQb8gC9Oro2vp5rncCIY8L8uEx5ZkAAAAASUVORK5CYII=");
+}
+
+.CodeMirror-lint-marker-multiple {
+ background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAcAAAAHCAMAAADzjKfhAAAACVBMVEUAAAAAAAC/v7914kyHAAAAAXRSTlMAQObYZgAAACNJREFUeNo1ioEJAAAIwmz/H90iFFSGJgFMe3gaLZ0od+9/AQZ0ADosbYraAAAAAElFTkSuQmCC");
+ background-repeat: no-repeat;
+ background-position: right bottom;
+ width: 100%; height: 100%;
+}
http://git-wip-us.apache.org/repos/asf/nifi/blob/cb3aa8f5/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/webapp/js/codemirror/addon/lint/lint.js
----------------------------------------------------------------------
diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/webapp/js/codemirror/addon/lint/lint.js b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/webapp/js/codemirror/addon/lint/lint.js
new file mode 100644
index 0000000..e3a4527
--- /dev/null
+++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/webapp/js/codemirror/addon/lint/lint.js
@@ -0,0 +1,239 @@
+// CodeMirror, copyright (c) by Marijn Haverbeke and others
+// Distributed under an MIT license: http://codemirror.net/LICENSE
+
+(function(mod) {
+ if (typeof exports == "object" && typeof module == "object") // CommonJS
+ mod(require("../../lib/codemirror"));
+ else if (typeof define == "function" && define.amd) // AMD
+ define(["../../lib/codemirror"], mod);
+ else // Plain browser env
+ mod(CodeMirror);
+})(function(CodeMirror) {
+ "use strict";
+ var GUTTER_ID = "CodeMirror-lint-markers";
+
+ function showTooltip(e, content) {
+ var tt = document.createElement("div");
+ tt.className = "CodeMirror-lint-tooltip";
+ tt.appendChild(content.cloneNode(true));
+ document.body.appendChild(tt);
+
+ function position(e) {
+ if (!tt.parentNode) return CodeMirror.off(document, "mousemove", position);
+ tt.style.top = Math.max(0, e.clientY - tt.offsetHeight - 5) + "px";
+ tt.style.left = (e.clientX + 5) + "px";
+ }
+ CodeMirror.on(document, "mousemove", position);
+ position(e);
+ if (tt.style.opacity != null) tt.style.opacity = 1;
+ return tt;
+ }
+ function rm(elt) {
+ if (elt.parentNode) elt.parentNode.removeChild(elt);
+ }
+ function hideTooltip(tt) {
+ if (!tt.parentNode) return;
+ if (tt.style.opacity == null) rm(tt);
+ tt.style.opacity = 0;
+ setTimeout(function() { rm(tt); }, 600);
+ }
+
+ function showTooltipFor(e, content, node) {
+ var tooltip = showTooltip(e, content);
+ function hide() {
+ CodeMirror.off(node, "mouseout", hide);
+ if (tooltip) { hideTooltip(tooltip); tooltip = null; }
+ }
+ var poll = setInterval(function() {
+ if (tooltip) for (var n = node;; n = n.parentNode) {
+ if (n && n.nodeType == 11) n = n.host;
+ if (n == document.body) return;
+ if (!n) { hide(); break; }
+ }
+ if (!tooltip) return clearInterval(poll);
+ }, 400);
+ CodeMirror.on(node, "mouseout", hide);
+ }
+
+ function LintState(cm, options, hasGutter) {
+ this.marked = [];
+ this.options = options;
+ this.timeout = null;
+ this.hasGutter = hasGutter;
+ this.onMouseOver = function(e) { onMouseOver(cm, e); };
+ this.waitingFor = 0
+ }
+
+ function parseOptions(_cm, options) {
+ if (options instanceof Function) return {getAnnotations: options};
+ if (!options || options === true) options = {};
+ return options;
+ }
+
+ function clearMarks(cm) {
+ var state = cm.state.lint;
+ if (state.hasGutter) cm.clearGutter(GUTTER_ID);
+ for (var i = 0; i < state.marked.length; ++i)
+ state.marked[i].clear();
+ state.marked.length = 0;
+ }
+
+ function makeMarker(labels, severity, multiple, tooltips) {
+ var marker = document.createElement("div"), inner = marker;
+ marker.className = "CodeMirror-lint-marker-" + severity;
+ if (multiple) {
+ inner = marker.appendChild(document.createElement("div"));
+ inner.className = "CodeMirror-lint-marker-multiple";
+ }
+
+ if (tooltips != false) CodeMirror.on(inner, "mouseover", function(e) {
+ showTooltipFor(e, labels, inner);
+ });
+
+ return marker;
+ }
+
+ function getMaxSeverity(a, b) {
+ if (a == "error") return a;
+ else return b;
+ }
+
+ function groupByLine(annotations) {
+ var lines = [];
+ for (var i = 0; i < annotations.length; ++i) {
+ var ann = annotations[i], line = ann.from.line;
+ (lines[line] || (lines[line] = [])).push(ann);
+ }
+ return lines;
+ }
+
+ function annotationTooltip(ann) {
+ var severity = ann.severity;
+ if (!severity) severity = "error";
+ var tip = document.createElement("div");
+ tip.className = "CodeMirror-lint-message-" + severity;
+ tip.appendChild(document.createTextNode(ann.message));
+ return tip;
+ }
+
+ function lintAsync(cm, getAnnotations, passOptions) {
+ var state = cm.state.lint
+ var id = ++state.waitingFor
+ function abort() {
+ id = -1
+ cm.off("change", abort)
+ }
+ cm.on("change", abort)
+ getAnnotations(cm.getValue(), function(annotations, arg2) {
+ cm.off("change", abort)
+ if (state.waitingFor != id) return
+ if (arg2 && annotations instanceof CodeMirror) annotations = arg2
+ updateLinting(cm, annotations)
+ }, passOptions, cm);
+ }
+
+ function startLinting(cm) {
+ var state = cm.state.lint, options = state.options;
+ var passOptions = options.options || options; // Support deprecated passing of `options` property in options
+ var getAnnotations = options.getAnnotations || cm.getHelper(CodeMirror.Pos(0, 0), "lint");
+ if (!getAnnotations) return;
+ if (options.async || getAnnotations.async) {
+ lintAsync(cm, getAnnotations, passOptions)
+ } else {
+ updateLinting(cm, getAnnotations(cm.getValue(), passOptions, cm));
+ }
+ }
+
+ function updateLinting(cm, annotationsNotSorted) {
+ clearMarks(cm);
+ var state = cm.state.lint, options = state.options;
+
+ var annotations = groupByLine(annotationsNotSorted);
+
+ for (var line = 0; line < annotations.length; ++line) {
+ var anns = annotations[line];
+ if (!anns) continue;
+
+ var maxSeverity = null;
+ var tipLabel = state.hasGutter && document.createDocumentFragment();
+
+ for (var i = 0; i < anns.length; ++i) {
+ var ann = anns[i];
+ var severity = ann.severity;
+ if (!severity) severity = "error";
+ maxSeverity = getMaxSeverity(maxSeverity, severity);
+
+ if (options.formatAnnotation) ann = options.formatAnnotation(ann);
+ if (state.hasGutter) tipLabel.appendChild(annotationTooltip(ann));
+
+ if (ann.to) state.marked.push(cm.markText(ann.from, ann.to, {
+ className: "CodeMirror-lint-mark-" + severity,
+ __annotation: ann
+ }));
+ }
+
+ if (state.hasGutter)
+ cm.setGutterMarker(line, GUTTER_ID, makeMarker(tipLabel, maxSeverity, anns.length > 1,
+ state.options.tooltips));
+ }
+ if (options.onUpdateLinting) options.onUpdateLinting(annotationsNotSorted, annotations, cm);
+ }
+
+ function onChange(cm) {
+ var state = cm.state.lint;
+ if (!state) return;
+ clearTimeout(state.timeout);
+ state.timeout = setTimeout(function(){startLinting(cm);}, state.options.delay || 500);
+ }
+
+ function popupTooltips(annotations, e) {
+ var target = e.target || e.srcElement;
+ var tooltip = document.createDocumentFragment();
+ for (var i = 0; i < annotations.length; i++) {
+ var ann = annotations[i];
+ tooltip.appendChild(annotationTooltip(ann));
+ }
+ showTooltipFor(e, tooltip, target);
+ }
+
+ function onMouseOver(cm, e) {
+ var target = e.target || e.srcElement;
+ if (!/\bCodeMirror-lint-mark-/.test(target.className)) return;
+ var box = target.getBoundingClientRect(), x = (box.left + box.right) / 2, y = (box.top + box.bottom) / 2;
+ var spans = cm.findMarksAt(cm.coordsChar({left: x, top: y}, "client"));
+
+ var annotations = [];
+ for (var i = 0; i < spans.length; ++i) {
+ var ann = spans[i].__annotation;
+ if (ann) annotations.push(ann);
+ }
+ if (annotations.length) popupTooltips(annotations, e);
+ }
+
+ CodeMirror.defineOption("lint", false, function(cm, val, old) {
+ if (old && old != CodeMirror.Init) {
+ clearMarks(cm);
+ if (cm.state.lint.options.lintOnChange !== false)
+ cm.off("change", onChange);
+ CodeMirror.off(cm.getWrapperElement(), "mouseover", cm.state.lint.onMouseOver);
+ clearTimeout(cm.state.lint.timeout);
+ delete cm.state.lint;
+ }
+
+ if (val) {
+ var gutters = cm.getOption("gutters"), hasLintGutter = false;
+ for (var i = 0; i < gutters.length; ++i) if (gutters[i] == GUTTER_ID) hasLintGutter = true;
+ var state = cm.state.lint = new LintState(cm, parseOptions(cm, val), hasLintGutter);
+ if (state.options.lintOnChange !== false)
+ cm.on("change", onChange);
+ if (state.options.tooltips != false)
+ CodeMirror.on(cm.getWrapperElement(), "mouseover", state.onMouseOver);
+
+ startLinting(cm);
+ }
+ });
+
+ CodeMirror.defineExtension("performLint", function() {
+ if (this.state.lint) startLinting(this);
+ });
+});
http://git-wip-us.apache.org/repos/asf/nifi/blob/cb3aa8f5/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/webapp/js/jsonlint/LICENSE
----------------------------------------------------------------------
diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/webapp/js/jsonlint/LICENSE b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/webapp/js/jsonlint/LICENSE
new file mode 100644
index 0000000..43f0ed5
--- /dev/null
+++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/webapp/js/jsonlint/LICENSE
@@ -0,0 +1,21 @@
+The MIT License
+
+Copyright (C) 2012 Zachary Carter
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/nifi/blob/cb3aa8f5/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/webapp/js/jsonlint/jsonlint.min.js
----------------------------------------------------------------------
diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/webapp/js/jsonlint/jsonlint.min.js b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/webapp/js/jsonlint/jsonlint.min.js
new file mode 100644
index 0000000..89b1b4a
--- /dev/null
+++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/webapp/js/jsonlint/jsonlint.min.js
@@ -0,0 +1 @@
+var jsonlint=function(){var a={trace:function(){},yy:{},symbols_:{error:2,JSONString:3,STRING:4,JSONNumber:5,NUMBER:6,JSONNullLiteral:7,NULL:8,JSONBooleanLiteral:9,TRUE:10,FALSE:11,JSONText:12,JSONValue:13,EOF:14,JSONObject:15,JSONArray:16,"{":17,"}":18,JSONMemberList:19,JSONMember:20,":":21,",":22,"[":23,"]":24,JSONElementList:25,$accept:0,$end:1},terminals_:{2:"error",4:"STRING",6:"NUMBER",8:"NULL",10:"TRUE",11:"FALSE",14:"EOF",17:"{",18:"}",21:":",22:",",23:"[",24:"]"},productions_:[0,[3,1],[5,1],[7,1],[9,1],[9,1],[12,2],[13,1],[13,1],[13,1],[13,1],[13,1],[13,1],[15,2],[15,3],[20,3],[19,1],[19,3],[16,2],[16,3],[25,1],[25,3]],performAction:function(a,b,c,d,e,f){var h=f.length-1;switch(e){case 1:this.$=a.replace(/\\(\\|")/g,"$1").replace(/\\n/g,"\n").replace(/\\r/g,"\r").replace(/\\t/g," ").replace(/\\v/g,"").replace(/\\f/g,"\f").replace(/\\b/g,"\b");break;case 2:this.$=Number(a);break;case 3:this.$=null;break;case 4:this.$=!0;break;case 5:this.$=!1;break;case 6:return this.$=f[h-1
];case 13:this.$={};break;case 14:this.$=f[h-1];break;case 15:this.$=[f[h-2],f[h]];break;case 16:this.$={},this.$[f[h][0]]=f[h][1];break;case 17:this.$=f[h-2],f[h-2][f[h][0]]=f[h][1];break;case 18:this.$=[];break;case 19:this.$=f[h-1];break;case 20:this.$=[f[h]];break;case 21:this.$=f[h-2],f[h-2].push(f[h])}},table:[{3:5,4:[1,12],5:6,6:[1,13],7:3,8:[1,9],9:4,10:[1,10],11:[1,11],12:1,13:2,15:7,16:8,17:[1,14],23:[1,15]},{1:[3]},{14:[1,16]},{14:[2,7],18:[2,7],22:[2,7],24:[2,7]},{14:[2,8],18:[2,8],22:[2,8],24:[2,8]},{14:[2,9],18:[2,9],22:[2,9],24:[2,9]},{14:[2,10],18:[2,10],22:[2,10],24:[2,10]},{14:[2,11],18:[2,11],22:[2,11],24:[2,11]},{14:[2,12],18:[2,12],22:[2,12],24:[2,12]},{14:[2,3],18:[2,3],22:[2,3],24:[2,3]},{14:[2,4],18:[2,4],22:[2,4],24:[2,4]},{14:[2,5],18:[2,5],22:[2,5],24:[2,5]},{14:[2,1],18:[2,1],21:[2,1],22:[2,1],24:[2,1]},{14:[2,2],18:[2,2],22:[2,2],24:[2,2]},{3:20,4:[1,12],18:[1,17],19:18,20:19},{3:5,4:[1,12],5:6,6:[1,13],7:3,8:[1,9],9:4,10:[1,10],11:[1,11],13:23,15:7,16:8
,17:[1,14],23:[1,15],24:[1,21],25:22},{1:[2,6]},{14:[2,13],18:[2,13],22:[2,13],24:[2,13]},{18:[1,24],22:[1,25]},{18:[2,16],22:[2,16]},{21:[1,26]},{14:[2,18],18:[2,18],22:[2,18],24:[2,18]},{22:[1,28],24:[1,27]},{22:[2,20],24:[2,20]},{14:[2,14],18:[2,14],22:[2,14],24:[2,14]},{3:20,4:[1,12],20:29},{3:5,4:[1,12],5:6,6:[1,13],7:3,8:[1,9],9:4,10:[1,10],11:[1,11],13:30,15:7,16:8,17:[1,14],23:[1,15]},{14:[2,19],18:[2,19],22:[2,19],24:[2,19]},{3:5,4:[1,12],5:6,6:[1,13],7:3,8:[1,9],9:4,10:[1,10],11:[1,11],13:31,15:7,16:8,17:[1,14],23:[1,15]},{18:[2,17],22:[2,17]},{18:[2,15],22:[2,15]},{22:[2,21],24:[2,21]}],defaultActions:{16:[2,6]},parseError:function(a){throw new Error(a)},parse:function(a){function n(a){c.length=c.length-2*a,d.length=d.length-a,e.length=e.length-a}function o(){var a;return a=b.lexer.lex()||1,"number"!=typeof a&&(a=b.symbols_[a]||a),a}var b=this,c=[0],d=[null],e=[],f=this.table,g="",h=0,i=0,j=0,k=2,l=1;this.lexer.setInput(a),this.lexer.yy=this.yy,this.yy.lexer=this.lexer,"u
ndefined"==typeof this.lexer.yylloc&&(this.lexer.yylloc={});var m=this.lexer.yylloc;e.push(m),"function"==typeof this.yy.parseError&&(this.parseError=this.yy.parseError);for(var p,q,r,s,u,w,x,y,z,v={};;){if(r=c[c.length-1],this.defaultActions[r]?s=this.defaultActions[r]:(null==p&&(p=o()),s=f[r]&&f[r][p]),"undefined"==typeof s||!s.length||!s[0]){if(!j){z=[];for(w in f[r])this.terminals_[w]&&w>2&&z.push("'"+this.terminals_[w]+"'");var A="";A=this.lexer.showPosition?"Parse error on line "+(h+1)+":\n"+this.lexer.showPosition()+"\nExpecting "+z.join(", ")+", got '"+this.terminals_[p]+"'":"Parse error on line "+(h+1)+": Unexpected "+(1==p?"end of input":"'"+(this.terminals_[p]||p)+"'"),this.parseError(A,{text:this.lexer.match,token:this.terminals_[p]||p,line:this.lexer.yylineno,loc:m,expected:z})}if(3==j){if(p==l)throw new Error(A||"Parsing halted.");i=this.lexer.yyleng,g=this.lexer.yytext,h=this.lexer.yylineno,m=this.lexer.yylloc,p=o()}for(;;){if(k.toString()in f[r])break;if(0==r)throw n
ew Error(A||"Parsing halted.");n(1),r=c[c.length-1]}q=p,p=k,r=c[c.length-1],s=f[r]&&f[r][k],j=3}if(s[0]instanceof Array&&s.length>1)throw new Error("Parse Error: multiple actions possible at state: "+r+", token: "+p);switch(s[0]){case 1:c.push(p),d.push(this.lexer.yytext),e.push(this.lexer.yylloc),c.push(s[1]),p=null,q?(p=q,q=null):(i=this.lexer.yyleng,g=this.lexer.yytext,h=this.lexer.yylineno,m=this.lexer.yylloc,j>0&&j--);break;case 2:if(x=this.productions_[s[1]][1],v.$=d[d.length-x],v._$={first_line:e[e.length-(x||1)].first_line,last_line:e[e.length-1].last_line,first_column:e[e.length-(x||1)].first_column,last_column:e[e.length-1].last_column},u=this.performAction.call(v,g,i,h,this.yy,s[1],d,e),"undefined"!=typeof u)return u;x&&(c=c.slice(0,2*-1*x),d=d.slice(0,-1*x),e=e.slice(0,-1*x)),c.push(this.productions_[s[1]][0]),d.push(v.$),e.push(v._$),y=f[c[c.length-2]][c[c.length-1]],c.push(y);break;case 3:return!0}}return!0}},b=function(){var a={EOF:1,parseError:function(a,b){if(!this.
yy.parseError)throw new Error(a);this.yy.parseError(a,b)},setInput:function(a){return this._input=a,this._more=this._less=this.done=!1,this.yylineno=this.yyleng=0,this.yytext=this.matched=this.match="",this.conditionStack=["INITIAL"],this.yylloc={first_line:1,first_column:0,last_line:1,last_column:0},this},input:function(){var a=this._input[0];this.yytext+=a,this.yyleng++,this.match+=a,this.matched+=a;var b=a.match(/\n/);return b&&this.yylineno++,this._input=this._input.slice(1),a},unput:function(a){return this._input=a+this._input,this},more:function(){return this._more=!0,this},less:function(a){this._input=this.match.slice(a)+this._input},pastInput:function(){var a=this.matched.substr(0,this.matched.length-this.match.length);return(a.length>20?"...":"")+a.substr(-20).replace(/\n/g,"")},upcomingInput:function(){var a=this.match;return a.length<20&&(a+=this._input.substr(0,20-a.length)),(a.substr(0,20)+(a.length>20?"...":"")).replace(/\n/g,"")},showPosition:function(){var a=this.pas
tInput(),b=new Array(a.length+1).join("-");return a+this.upcomingInput()+"\n"+b+"^"},next:function(){if(this.done)return this.EOF;this._input||(this.done=!0);var a,b,c,d,f;this._more||(this.yytext="",this.match="");for(var g=this._currentRules(),h=0;h<g.length&&(c=this._input.match(this.rules[g[h]]),!c||b&&!(c[0].length>b[0].length)||(b=c,d=h,this.options.flex));h++);return b?(f=b[0].match(/\n.*/g),f&&(this.yylineno+=f.length),this.yylloc={first_line:this.yylloc.last_line,last_line:this.yylineno+1,first_column:this.yylloc.last_column,last_column:f?f[f.length-1].length-1:this.yylloc.last_column+b[0].length},this.yytext+=b[0],this.match+=b[0],this.yyleng=this.yytext.length,this._more=!1,this._input=this._input.slice(b[0].length),this.matched+=b[0],a=this.performAction.call(this,this.yy,this,g[d],this.conditionStack[this.conditionStack.length-1]),this.done&&this._input&&(this.done=!1),a?a:void 0):""===this._input?this.EOF:(this.parseError("Lexical error on line "+(this.yylineno+1)+". U
nrecognized text.\n"+this.showPosition(),{text:"",token:null,line:this.yylineno}),void 0)},lex:function(){var a=this.next();return"undefined"!=typeof a?a:this.lex()},begin:function(a){this.conditionStack.push(a)},popState:function(){return this.conditionStack.pop()},_currentRules:function(){return this.conditions[this.conditionStack[this.conditionStack.length-1]].rules},topState:function(){return this.conditionStack[this.conditionStack.length-2]},pushState:function(a){this.begin(a)}};return a.options={},a.performAction=function(a,b,c,d){switch(c){case 0:break;case 1:return 6;case 2:return b.yytext=b.yytext.substr(1,b.yyleng-2),4;case 3:return 17;case 4:return 18;case 5:return 23;case 6:return 24;case 7:return 22;case 8:return 21;case 9:return 10;case 10:return 11;case 11:return 8;case 12:return 14;case 13:return"INVALID"}},a.rules=[/^(?:\s+)/,/^(?:(-?([0-9]|[1-9][0-9]+))(\.[0-9]+)?([eE][-+]?[0-9]+)?\b)/,/^(?:"(?:\\[\\"bfnrt/]|\\u[a-fA-F0-9]{4}|[^\\\0-\x09\x0a-\x1f"])*")/,/^(?:\{)/,/
^(?:\})/,/^(?:\[)/,/^(?:\])/,/^(?:,)/,/^(?::)/,/^(?:true\b)/,/^(?:false\b)/,/^(?:null\b)/,/^(?:$)/,/^(?:.)/],a.conditions={INITIAL:{rules:[0,1,2,3,4,5,6,7,8,9,10,11,12,13],inclusive:!0}},a}();return a.lexer=b,a}();"undefined"!=typeof require&&"undefined"!=typeof exports&&(exports.parser=jsonlint,exports.parse=function(){return jsonlint.parse.apply(jsonlint,arguments)},exports.main=function(a){if(!a[1])throw new Error("Usage: "+a[0]+" FILE");if("undefined"!=typeof process)var b=require("fs").readFileSync(require("path").join(process.cwd(),a[1]),"utf8");else var c=require("file").path(require("file").cwd()),b=c.join(a[1]).read({charset:"utf-8"});return exports.parser.parse(b)},"undefined"!=typeof module&&require.main===module&&exports.main("undefined"!=typeof process?process.argv.slice(1):require("system").args));
http://git-wip-us.apache.org/repos/asf/nifi/blob/cb3aa8f5/nifi-nar-bundles/nifi-standard-bundle/nifi-jolt-transform-json-ui/pom.xml
----------------------------------------------------------------------
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-jolt-transform-json-ui/pom.xml b/nifi-nar-bundles/nifi-standard-bundle/nifi-jolt-transform-json-ui/pom.xml
new file mode 100644
index 0000000..a04432e
--- /dev/null
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-jolt-transform-json-ui/pom.xml
@@ -0,0 +1,227 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- 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. -->
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <parent>
+ <artifactId>nifi-standard-bundle</artifactId>
+ <groupId>org.apache.nifi</groupId>
+ <version>1.0.0-SNAPSHOT</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+
+ <artifactId>nifi-jolt-transform-json-ui</artifactId>
+
+ <packaging>war</packaging>
+ <properties>
+ <maven.javadoc.skip>true</maven.javadoc.skip>
+ <source.skip>true</source.skip>
+ <jersey.version>1.19.1</jersey.version>
+ <jolt.version>0.0.20</jolt.version>
+ <frontend.dependency.configs>${basedir}/src/main/frontend</frontend.dependency.configs>
+ <frontend.working.dir>${project.build.directory}/frontend-working-directory</frontend.working.dir>
+ <frontend.assets>${project.build.directory}/${project.build.finalName}/assets</frontend.assets>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.nifi</groupId>
+ <artifactId>nifi-api</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.nifi</groupId>
+ <artifactId>nifi-utils</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.nifi</groupId>
+ <artifactId>nifi-custom-ui-utilities</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.nifi</groupId>
+ <artifactId>nifi-processor-utils</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.nifi</groupId>
+ <artifactId>nifi-standard-utils</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>javax.servlet.jsp</groupId>
+ <artifactId>javax.servlet.jsp-api</artifactId>
+ <version>2.3.1</version>
+ </dependency>
+ <dependency>
+ <groupId>javax.el</groupId>
+ <artifactId>javax.el-api</artifactId>
+ <version>3.0.0</version>
+ </dependency>
+ <dependency>
+ <groupId>javax.servlet.jsp.jstl</groupId>
+ <artifactId>javax.servlet.jsp.jstl-api</artifactId>
+ <version>1.2.1</version>
+ </dependency>
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>javax.servlet-api</artifactId>
+ <version>3.1.0</version>
+ </dependency>
+ <dependency>
+ <groupId>com.sun.jersey</groupId>
+ <artifactId>jersey-server</artifactId>
+ <version>${jersey.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>com.sun.jersey</groupId>
+ <artifactId>jersey-core</artifactId>
+ <version>${jersey.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>com.sun.jersey</groupId>
+ <artifactId>jersey-json</artifactId>
+ <version>${jersey.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>com.sun.jersey</groupId>
+ <artifactId>jersey-servlet</artifactId>
+ <version>${jersey.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>com.sun.jersey</groupId>
+ <artifactId>jersey-client</artifactId>
+ <version>${jersey.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-lang3</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>com.bazaarvoice.jolt</groupId>
+ <artifactId>jolt-core</artifactId>
+ <version>${jolt.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>com.bazaarvoice.jolt</groupId>
+ <artifactId>json-utils</artifactId>
+ <version>${jolt.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>com.fasterxml.jackson.core</groupId>
+ <artifactId>jackson-core</artifactId>
+ <version>2.6.2</version>
+ </dependency>
+ <dependency>
+ <groupId>com.fasterxml.jackson.core</groupId>
+ <artifactId>jackson-annotations</artifactId>
+ <version>2.6.2</version>
+ </dependency>
+ <dependency>
+ <groupId>com.sun.jersey.jersey-test-framework</groupId>
+ <artifactId>jersey-test-framework-inmemory</artifactId>
+ <version>${jersey.version}</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-resources-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>copy-bower-json</id>
+ <phase>generate-sources</phase>
+ <goals>
+ <goal>copy-resources</goal>
+ </goals>
+ <configuration>
+ <outputDirectory>${frontend.working.dir}</outputDirectory>
+ <resources>
+ <resource>
+ <directory>${frontend.dependency.configs}</directory>
+ <filtering>false</filtering>
+ <includes>
+ <include>bower.json</include>
+ <include>.bowerrc</include>
+ </includes>
+ </resource>
+ </resources>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>com.github.eirslett</groupId>
+ <artifactId>frontend-maven-plugin</artifactId>
+ <version>1.0</version>
+ <configuration>
+ <installDirectory>${frontend.working.dir}</installDirectory>
+ </configuration>
+
+ <executions>
+ <execution>
+ <id>install-node-and-npm</id>
+ <goals>
+ <goal>install-node-and-npm</goal>
+ </goals>
+ <phase>generate-resources</phase>
+ <configuration>
+ <nodeVersion>v0.10.18</nodeVersion>
+ <npmVersion>1.3.8</npmVersion>
+ </configuration>
+ </execution>
+ <execution>
+ <id>install-bower</id>
+ <goals>
+ <goal>npm</goal>
+ </goals>
+ <configuration>
+ <arguments>install bower</arguments>
+ <workingDirectory>${frontend.working.dir}</workingDirectory>
+ </configuration>
+ </execution>
+ <execution>
+ <id>bower-install</id>
+ <goals>
+ <goal>bower</goal>
+ </goals>
+ <configuration>
+ <arguments>install --config.directory=${frontend.assets}</arguments>
+ <workingDirectory>${frontend.working.dir}</workingDirectory>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.rat</groupId>
+ <artifactId>apache-rat-plugin</artifactId>
+ <configuration>
+ <excludes combine.children="append">
+ <exclude>src/main/frontend/.bowerrc</exclude>
+ <exclude>src/main/frontend/bower.json</exclude>
+ <exclude>src/main/webapp/css/main.css</exclude>
+ <exclude>src/main/webapp/js/jsonlint/*</exclude>
+ <exclude>src/main/webapp/js/js-beautify/*</exclude>
+ <exclude>src/main/webapp/js/jquery/*</exclude>
+ <exclude>src/main/webapp/js/codemirror/</exclude>
+ <exclude>src/main/webapp/js/angular/**/*</exclude>
+ <exclude>src/main/webapp/js/angular-ui/**/*</exclude>
+ </excludes>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/nifi/blob/cb3aa8f5/nifi-nar-bundles/nifi-standard-bundle/nifi-jolt-transform-json-ui/src/main/frontend/.bowerrc
----------------------------------------------------------------------
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-jolt-transform-json-ui/src/main/frontend/.bowerrc b/nifi-nar-bundles/nifi-standard-bundle/nifi-jolt-transform-json-ui/src/main/frontend/.bowerrc
new file mode 100644
index 0000000..31190ed
--- /dev/null
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-jolt-transform-json-ui/src/main/frontend/.bowerrc
@@ -0,0 +1,6 @@
+{
+ "ignoredDependencies": [
+ "angular",
+ "codemirror"
+ ]
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/nifi/blob/cb3aa8f5/nifi-nar-bundles/nifi-standard-bundle/nifi-jolt-transform-json-ui/src/main/frontend/bower.json
----------------------------------------------------------------------
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-jolt-transform-json-ui/src/main/frontend/bower.json b/nifi-nar-bundles/nifi-standard-bundle/nifi-jolt-transform-json-ui/src/main/frontend/bower.json
new file mode 100644
index 0000000..08f08c6
--- /dev/null
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-jolt-transform-json-ui/src/main/frontend/bower.json
@@ -0,0 +1,15 @@
+{
+ "name": "apache-nifi",
+ "private": true,
+ "ignore": [
+ "**/.*",
+ "node_modules",
+ "bower_components",
+ "test",
+ "tests"
+ ],
+ "dependencies": {
+ "angular-ui-codemirror": "^0.3.0",
+ "angular-ui-router": "^0.2.18"
+ }
+}
http://git-wip-us.apache.org/repos/asf/nifi/blob/cb3aa8f5/nifi-nar-bundles/nifi-standard-bundle/nifi-jolt-transform-json-ui/src/main/java/org/apache/nifi/web/standard/api/AbstractStandardResource.java
----------------------------------------------------------------------
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-jolt-transform-json-ui/src/main/java/org/apache/nifi/web/standard/api/AbstractStandardResource.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-jolt-transform-json-ui/src/main/java/org/apache/nifi/web/standard/api/AbstractStandardResource.java
new file mode 100644
index 0000000..3fb1a6b
--- /dev/null
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-jolt-transform-json-ui/src/main/java/org/apache/nifi/web/standard/api/AbstractStandardResource.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.web.standard.api;
+
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.core.Context;
+
+import org.apache.nifi.web.NiFiWebConfigurationContext;
+
+
+public abstract class AbstractStandardResource {
+
+ @Context
+ protected ServletContext servletContext;
+
+ @Context
+ protected HttpServletRequest request;
+
+
+ protected NiFiWebConfigurationContext getWebConfigurationContext(){
+ return (NiFiWebConfigurationContext) servletContext.getAttribute("nifi-web-configuration-context");
+ }
+}
[3/5] nifi git commit: NIFI-1850 - Initial Commit for JSON-to-JSON
Schema Converter Editor (merge from 0.7.0 - refactor for masterless cluster).
This closes #511
Posted by mc...@apache.org.
http://git-wip-us.apache.org/repos/asf/nifi/blob/cb3aa8f5/nifi-nar-bundles/nifi-standard-bundle/nifi-jolt-transform-json-ui/src/main/webapp/js/js-beautify/beautify.js
----------------------------------------------------------------------
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-jolt-transform-json-ui/src/main/webapp/js/js-beautify/beautify.js b/nifi-nar-bundles/nifi-standard-bundle/nifi-jolt-transform-json-ui/src/main/webapp/js/js-beautify/beautify.js
new file mode 100644
index 0000000..6e9985b
--- /dev/null
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-jolt-transform-json-ui/src/main/webapp/js/js-beautify/beautify.js
@@ -0,0 +1,2333 @@
+/*jshint curly:true, eqeqeq:true, laxbreak:true, noempty:false */
+/*
+
+ The MIT License (MIT)
+
+ Copyright (c) 2007-2013 Einar Lielmanis and contributors.
+
+ Permission is hereby granted, free of charge, to any person
+ obtaining a copy of this software and associated documentation files
+ (the "Software"), to deal in the Software without restriction,
+ including without limitation the rights to use, copy, modify, merge,
+ publish, distribute, sublicense, and/or sell copies of the Software,
+ and to permit persons to whom the Software is furnished to do so,
+ subject to the following conditions:
+
+ The above copyright notice and this permission notice shall be
+ included in all copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ SOFTWARE.
+
+ JS Beautifier
+---------------
+
+
+ Written by Einar Lielmanis, <ei...@jsbeautifier.org>
+ http://jsbeautifier.org/
+
+ Originally converted to javascript by Vital, <vi...@gmail.com>
+ "End braces on own line" added by Chris J. Shull, <ch...@gmail.com>
+ Parsing improvements for brace-less statements by Liam Newman <bi...@gmail.com>
+
+
+ Usage:
+ js_beautify(js_source_text);
+ js_beautify(js_source_text, options);
+
+ The options are:
+ indent_size (default 4) - indentation size,
+ indent_char (default space) - character to indent with,
+ preserve_newlines (default true) - whether existing line breaks should be preserved,
+ max_preserve_newlines (default unlimited) - maximum number of line breaks to be preserved in one chunk,
+
+ jslint_happy (default false) - if true, then jslint-stricter mode is enforced.
+
+ jslint_happy !jslint_happy
+ ---------------------------------
+ function () function()
+
+ switch () { switch() {
+ case 1: case 1:
+ break; break;
+ } }
+
+ space_after_anon_function (default false) - should the space before an anonymous function's parens be added, "function()" vs "function ()",
+ NOTE: This option is overriden by jslint_happy (i.e. if jslint_happy is true, space_after_anon_function is true by design)
+
+ brace_style (default "collapse") - "collapse-preserve-inline" | "collapse" | "expand" | "end-expand" | "none"
+ put braces on the same line as control statements (default), or put braces on own line (Allman / ANSI style), or just put end braces on own line, or attempt to keep them where they are.
+
+ space_before_conditional (default true) - should the space before conditional statement be added, "if(true)" vs "if (true)",
+
+ unescape_strings (default false) - should printable characters in strings encoded in \xNN notation be unescaped, "example" vs "\x65\x78\x61\x6d\x70\x6c\x65"
+
+ wrap_line_length (default unlimited) - lines should wrap at next opportunity after this number of characters.
+ NOTE: This is not a hard limit. Lines will continue until a point where a newline would
+ be preserved if it were present.
+
+ end_with_newline (default false) - end output with a newline
+
+
+ e.g
+
+ js_beautify(js_source_text, {
+ 'indent_size': 1,
+ 'indent_char': '\t'
+ });
+
+*/
+
+// Object.values polyfill found here:
+// http://tokenposts.blogspot.com.au/2012/04/javascript-objectkeys-browser.html
+if (!Object.values) {
+ Object.values = function(o) {
+ if (o !== Object(o)) {
+ throw new TypeError('Object.values called on a non-object');
+ }
+ var k = [],
+ p;
+ for (p in o) {
+ if (Object.prototype.hasOwnProperty.call(o, p)) {
+ k.push(o[p]);
+ }
+ }
+ return k;
+ };
+}
+
+(function() {
+
+ var acorn = {};
+ (function(exports) {
+ /* jshint curly: false */
+ // This section of code is taken from acorn.
+ //
+ // Acorn was written by Marijn Haverbeke and released under an MIT
+ // license. The Unicode regexps (for identifiers and whitespace) were
+ // taken from [Esprima](http://esprima.org) by Ariya Hidayat.
+ //
+ // Git repositories for Acorn are available at
+ //
+ // http://marijnhaverbeke.nl/git/acorn
+ // https://github.com/marijnh/acorn.git
+
+ // ## Character categories
+
+ // Big ugly regular expressions that match characters in the
+ // whitespace, identifier, and identifier-start categories. These
+ // are only applied when a character is found to actually have a
+ // code point above 128.
+
+ var nonASCIIwhitespace = /[\u1680\u180e\u2000-\u200a\u202f\u205f\u3000\ufeff]/; // jshint ignore:line
+ var nonASCIIidentifierStartChars = "\xaa\xb5\xba\xc0-\xd6\xd8-\xf6\xf8-\u02c1\u02c6-\u02d1\u02e0-\u02e4\u02ec\u02ee\u0370-\u0374\u0376\u0377\u037a-\u037d\u0386\u0388-\u038a\u038c\u038e-\u03a1\u03a3-\u03f5\u03f7-\u0481\u048a-\u0527\u0531-\u0556\u0559\u0561-\u0587\u05d0-\u05ea\u05f0-\u05f2\u0620-\u064a\u066e\u066f\u0671-\u06d3\u06d5\u06e5\u06e6\u06ee\u06ef\u06fa-\u06fc\u06ff\u0710\u0712-\u072f\u074d-\u07a5\u07b1\u07ca-\u07ea\u07f4\u07f5\u07fa\u0800-\u0815\u081a\u0824\u0828\u0840-\u0858\u08a0\u08a2-\u08ac\u0904-\u0939\u093d\u0950\u0958-\u0961\u0971-\u0977\u0979-\u097f\u0985-\u098c\u098f\u0990\u0993-\u09a8\u09aa-\u09b0\u09b2\u09b6-\u09b9\u09bd\u09ce\u09dc\u09dd\u09df-\u09e1\u09f0\u09f1\u0a05-\u0a0a\u0a0f\u0a10\u0a13-\u0a28\u0a2a-\u0a30\u0a32\u0a33\u0a35\u0a36\u0a38\u0a39\u0a59-\u0a5c\u0a5e\u0a72-\u0a74\u0a85-\u0a8d\u0a8f-\u0a91\u0a93-\u0aa8\u0aaa-\u0ab0\u0ab2\u0ab3\u0ab5-\u0ab9\u0abd\u0ad0\u0ae0\u0ae1\u0b05-\u0b0c\u0b0f\u0b10\u0b13-\u0b28\u0b2a-\u0b30\u0b32\u0b33\u0b35-\u0b39\u0
b3d\u0b5c\u0b5d\u0b5f-\u0b61\u0b71\u0b83\u0b85-\u0b8a\u0b8e-\u0b90\u0b92-\u0b95\u0b99\u0b9a\u0b9c\u0b9e\u0b9f\u0ba3\u0ba4\u0ba8-\u0baa\u0bae-\u0bb9\u0bd0\u0c05-\u0c0c\u0c0e-\u0c10\u0c12-\u0c28\u0c2a-\u0c33\u0c35-\u0c39\u0c3d\u0c58\u0c59\u0c60\u0c61\u0c85-\u0c8c\u0c8e-\u0c90\u0c92-\u0ca8\u0caa-\u0cb3\u0cb5-\u0cb9\u0cbd\u0cde\u0ce0\u0ce1\u0cf1\u0cf2\u0d05-\u0d0c\u0d0e-\u0d10\u0d12-\u0d3a\u0d3d\u0d4e\u0d60\u0d61\u0d7a-\u0d7f\u0d85-\u0d96\u0d9a-\u0db1\u0db3-\u0dbb\u0dbd\u0dc0-\u0dc6\u0e01-\u0e30\u0e32\u0e33\u0e40-\u0e46\u0e81\u0e82\u0e84\u0e87\u0e88\u0e8a\u0e8d\u0e94-\u0e97\u0e99-\u0e9f\u0ea1-\u0ea3\u0ea5\u0ea7\u0eaa\u0eab\u0ead-\u0eb0\u0eb2\u0eb3\u0ebd\u0ec0-\u0ec4\u0ec6\u0edc-\u0edf\u0f00\u0f40-\u0f47\u0f49-\u0f6c\u0f88-\u0f8c\u1000-\u102a\u103f\u1050-\u1055\u105a-\u105d\u1061\u1065\u1066\u106e-\u1070\u1075-\u1081\u108e\u10a0-\u10c5\u10c7\u10cd\u10d0-\u10fa\u10fc-\u1248\u124a-\u124d\u1250-\u1256\u1258\u125a-\u125d\u1260-\u1288\u128a-\u128d\u1290-\u12b0\u12b2-\u12b5\u12b8-\u12be\u12c0\
u12c2-\u12c5\u12c8-\u12d6\u12d8-\u1310\u1312-\u1315\u1318-\u135a\u1380-\u138f\u13a0-\u13f4\u1401-\u166c\u166f-\u167f\u1681-\u169a\u16a0-\u16ea\u16ee-\u16f0\u1700-\u170c\u170e-\u1711\u1720-\u1731\u1740-\u1751\u1760-\u176c\u176e-\u1770\u1780-\u17b3\u17d7\u17dc\u1820-\u1877\u1880-\u18a8\u18aa\u18b0-\u18f5\u1900-\u191c\u1950-\u196d\u1970-\u1974\u1980-\u19ab\u19c1-\u19c7\u1a00-\u1a16\u1a20-\u1a54\u1aa7\u1b05-\u1b33\u1b45-\u1b4b\u1b83-\u1ba0\u1bae\u1baf\u1bba-\u1be5\u1c00-\u1c23\u1c4d-\u1c4f\u1c5a-\u1c7d\u1ce9-\u1cec\u1cee-\u1cf1\u1cf5\u1cf6\u1d00-\u1dbf\u1e00-\u1f15\u1f18-\u1f1d\u1f20-\u1f45\u1f48-\u1f4d\u1f50-\u1f57\u1f59\u1f5b\u1f5d\u1f5f-\u1f7d\u1f80-\u1fb4\u1fb6-\u1fbc\u1fbe\u1fc2-\u1fc4\u1fc6-\u1fcc\u1fd0-\u1fd3\u1fd6-\u1fdb\u1fe0-\u1fec\u1ff2-\u1ff4\u1ff6-\u1ffc\u2071\u207f\u2090-\u209c\u2102\u2107\u210a-\u2113\u2115\u2119-\u211d\u2124\u2126\u2128\u212a-\u212d\u212f-\u2139\u213c-\u213f\u2145-\u2149\u214e\u2160-\u2188\u2c00-\u2c2e\u2c30-\u2c5e\u2c60-\u2ce4\u2ceb-\u2cee\u2cf2\u2cf3\u
2d00-\u2d25\u2d27\u2d2d\u2d30-\u2d67\u2d6f\u2d80-\u2d96\u2da0-\u2da6\u2da8-\u2dae\u2db0-\u2db6\u2db8-\u2dbe\u2dc0-\u2dc6\u2dc8-\u2dce\u2dd0-\u2dd6\u2dd8-\u2dde\u2e2f\u3005-\u3007\u3021-\u3029\u3031-\u3035\u3038-\u303c\u3041-\u3096\u309d-\u309f\u30a1-\u30fa\u30fc-\u30ff\u3105-\u312d\u3131-\u318e\u31a0-\u31ba\u31f0-\u31ff\u3400-\u4db5\u4e00-\u9fcc\ua000-\ua48c\ua4d0-\ua4fd\ua500-\ua60c\ua610-\ua61f\ua62a\ua62b\ua640-\ua66e\ua67f-\ua697\ua6a0-\ua6ef\ua717-\ua71f\ua722-\ua788\ua78b-\ua78e\ua790-\ua793\ua7a0-\ua7aa\ua7f8-\ua801\ua803-\ua805\ua807-\ua80a\ua80c-\ua822\ua840-\ua873\ua882-\ua8b3\ua8f2-\ua8f7\ua8fb\ua90a-\ua925\ua930-\ua946\ua960-\ua97c\ua984-\ua9b2\ua9cf\uaa00-\uaa28\uaa40-\uaa42\uaa44-\uaa4b\uaa60-\uaa76\uaa7a\uaa80-\uaaaf\uaab1\uaab5\uaab6\uaab9-\uaabd\uaac0\uaac2\uaadb-\uaadd\uaae0-\uaaea\uaaf2-\uaaf4\uab01-\uab06\uab09-\uab0e\uab11-\uab16\uab20-\uab26\uab28-\uab2e\uabc0-\uabe2\uac00-\ud7a3\ud7b0-\ud7c6\ud7cb-\ud7fb\uf900-\ufa6d\ufa70-\ufad9\ufb00-\ufb06\ufb13-\ufb17\ufb1
d\ufb1f-\ufb28\ufb2a-\ufb36\ufb38-\ufb3c\ufb3e\ufb40\ufb41\ufb43\ufb44\ufb46-\ufbb1\ufbd3-\ufd3d\ufd50-\ufd8f\ufd92-\ufdc7\ufdf0-\ufdfb\ufe70-\ufe74\ufe76-\ufefc\uff21-\uff3a\uff41-\uff5a\uff66-\uffbe\uffc2-\uffc7\uffca-\uffcf\uffd2-\uffd7\uffda-\uffdc";
+ var nonASCIIidentifierChars = "\u0300-\u036f\u0483-\u0487\u0591-\u05bd\u05bf\u05c1\u05c2\u05c4\u05c5\u05c7\u0610-\u061a\u0620-\u0649\u0672-\u06d3\u06e7-\u06e8\u06fb-\u06fc\u0730-\u074a\u0800-\u0814\u081b-\u0823\u0825-\u0827\u0829-\u082d\u0840-\u0857\u08e4-\u08fe\u0900-\u0903\u093a-\u093c\u093e-\u094f\u0951-\u0957\u0962-\u0963\u0966-\u096f\u0981-\u0983\u09bc\u09be-\u09c4\u09c7\u09c8\u09d7\u09df-\u09e0\u0a01-\u0a03\u0a3c\u0a3e-\u0a42\u0a47\u0a48\u0a4b-\u0a4d\u0a51\u0a66-\u0a71\u0a75\u0a81-\u0a83\u0abc\u0abe-\u0ac5\u0ac7-\u0ac9\u0acb-\u0acd\u0ae2-\u0ae3\u0ae6-\u0aef\u0b01-\u0b03\u0b3c\u0b3e-\u0b44\u0b47\u0b48\u0b4b-\u0b4d\u0b56\u0b57\u0b5f-\u0b60\u0b66-\u0b6f\u0b82\u0bbe-\u0bc2\u0bc6-\u0bc8\u0bca-\u0bcd\u0bd7\u0be6-\u0bef\u0c01-\u0c03\u0c46-\u0c48\u0c4a-\u0c4d\u0c55\u0c56\u0c62-\u0c63\u0c66-\u0c6f\u0c82\u0c83\u0cbc\u0cbe-\u0cc4\u0cc6-\u0cc8\u0cca-\u0ccd\u0cd5\u0cd6\u0ce2-\u0ce3\u0ce6-\u0cef\u0d02\u0d03\u0d46-\u0d48\u0d57\u0d62-\u0d63\u0d66-\u0d6f\u0d82\u0d83\u0dca\u0dcf-\u0dd4\
u0dd6\u0dd8-\u0ddf\u0df2\u0df3\u0e34-\u0e3a\u0e40-\u0e45\u0e50-\u0e59\u0eb4-\u0eb9\u0ec8-\u0ecd\u0ed0-\u0ed9\u0f18\u0f19\u0f20-\u0f29\u0f35\u0f37\u0f39\u0f41-\u0f47\u0f71-\u0f84\u0f86-\u0f87\u0f8d-\u0f97\u0f99-\u0fbc\u0fc6\u1000-\u1029\u1040-\u1049\u1067-\u106d\u1071-\u1074\u1082-\u108d\u108f-\u109d\u135d-\u135f\u170e-\u1710\u1720-\u1730\u1740-\u1750\u1772\u1773\u1780-\u17b2\u17dd\u17e0-\u17e9\u180b-\u180d\u1810-\u1819\u1920-\u192b\u1930-\u193b\u1951-\u196d\u19b0-\u19c0\u19c8-\u19c9\u19d0-\u19d9\u1a00-\u1a15\u1a20-\u1a53\u1a60-\u1a7c\u1a7f-\u1a89\u1a90-\u1a99\u1b46-\u1b4b\u1b50-\u1b59\u1b6b-\u1b73\u1bb0-\u1bb9\u1be6-\u1bf3\u1c00-\u1c22\u1c40-\u1c49\u1c5b-\u1c7d\u1cd0-\u1cd2\u1d00-\u1dbe\u1e01-\u1f15\u200c\u200d\u203f\u2040\u2054\u20d0-\u20dc\u20e1\u20e5-\u20f0\u2d81-\u2d96\u2de0-\u2dff\u3021-\u3028\u3099\u309a\ua640-\ua66d\ua674-\ua67d\ua69f\ua6f0-\ua6f1\ua7f8-\ua800\ua806\ua80b\ua823-\ua827\ua880-\ua881\ua8b4-\ua8c4\ua8d0-\ua8d9\ua8f3-\ua8f7\ua900-\ua909\ua926-\ua92d\ua930-\ua945\u
a980-\ua983\ua9b3-\ua9c0\uaa00-\uaa27\uaa40-\uaa41\uaa4c-\uaa4d\uaa50-\uaa59\uaa7b\uaae0-\uaae9\uaaf2-\uaaf3\uabc0-\uabe1\uabec\uabed\uabf0-\uabf9\ufb20-\ufb28\ufe00-\ufe0f\ufe20-\ufe26\ufe33\ufe34\ufe4d-\ufe4f\uff10-\uff19\uff3f";
+ var nonASCIIidentifierStart = new RegExp("[" + nonASCIIidentifierStartChars + "]");
+ var nonASCIIidentifier = new RegExp("[" + nonASCIIidentifierStartChars + nonASCIIidentifierChars + "]");
+
+ // Whether a single character denotes a newline.
+
+ exports.newline = /[\n\r\u2028\u2029]/;
+
+ // Matches a whole line break (where CRLF is considered a single
+ // line break). Used to count lines.
+
+ // in javascript, these two differ
+ // in python they are the same, different methods are called on them
+ exports.lineBreak = new RegExp('\r\n|' + exports.newline.source);
+ exports.allLineBreaks = new RegExp(exports.lineBreak.source, 'g');
+
+
+ // Test whether a given character code starts an identifier.
+
+ exports.isIdentifierStart = function(code) {
+ // permit $ (36) and @ (64). @ is used in ES7 decorators.
+ if (code < 65) return code === 36 || code === 64;
+ // 65 through 91 are uppercase letters.
+ if (code < 91) return true;
+ // permit _ (95).
+ if (code < 97) return code === 95;
+ // 97 through 123 are lowercase letters.
+ if (code < 123) return true;
+ return code >= 0xaa && nonASCIIidentifierStart.test(String.fromCharCode(code));
+ };
+
+ // Test whether a given character is part of an identifier.
+
+ exports.isIdentifierChar = function(code) {
+ if (code < 48) return code === 36;
+ if (code < 58) return true;
+ if (code < 65) return false;
+ if (code < 91) return true;
+ if (code < 97) return code === 95;
+ if (code < 123) return true;
+ return code >= 0xaa && nonASCIIidentifier.test(String.fromCharCode(code));
+ };
+ })(acorn);
+ /* jshint curly: true */
+
+ function in_array(what, arr) {
+ for (var i = 0; i < arr.length; i += 1) {
+ if (arr[i] === what) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ function trim(s) {
+ return s.replace(/^\s+|\s+$/g, '');
+ }
+
+ function ltrim(s) {
+ return s.replace(/^\s+/g, '');
+ }
+
+ // function rtrim(s) {
+ // return s.replace(/\s+$/g, '');
+ // }
+
+ function js_beautify(js_source_text, options) {
+ "use strict";
+ var beautifier = new Beautifier(js_source_text, options);
+ return beautifier.beautify();
+ }
+
+ function sanitizeOperatorPosition(opPosition) {
+ opPosition = opPosition || OPERATOR_POSITION.before_newline;
+
+ var validPositionValues = Object.values(OPERATOR_POSITION);
+
+ if (!in_array(opPosition, validPositionValues)) {
+ throw new Error("Invalid Option Value: The option 'operator_position' must be one of the following values\n" +
+ validPositionValues +
+ "\nYou passed in: '" + opPosition + "'");
+ }
+
+ return opPosition;
+ }
+
+ var OPERATOR_POSITION = {
+ before_newline: 'before-newline',
+ after_newline: 'after-newline',
+ preserve_newline: 'preserve-newline',
+ };
+
+ var OPERATOR_POSITION_BEFORE_OR_PRESERVE = [OPERATOR_POSITION.before_newline, OPERATOR_POSITION.preserve_newline];
+
+ var MODE = {
+ BlockStatement: 'BlockStatement', // 'BLOCK'
+ Statement: 'Statement', // 'STATEMENT'
+ ObjectLiteral: 'ObjectLiteral', // 'OBJECT',
+ ArrayLiteral: 'ArrayLiteral', //'[EXPRESSION]',
+ ForInitializer: 'ForInitializer', //'(FOR-EXPRESSION)',
+ Conditional: 'Conditional', //'(COND-EXPRESSION)',
+ Expression: 'Expression' //'(EXPRESSION)'
+ };
+
+ function Beautifier(js_source_text, options) {
+ "use strict";
+ var output;
+ var tokens = [],
+ token_pos;
+ var Tokenizer;
+ var current_token;
+ var last_type, last_last_text, indent_string;
+ var flags, previous_flags, flag_store;
+ var prefix;
+
+ var handlers, opt;
+ var baseIndentString = '';
+
+ handlers = {
+ 'TK_START_EXPR': handle_start_expr,
+ 'TK_END_EXPR': handle_end_expr,
+ 'TK_START_BLOCK': handle_start_block,
+ 'TK_END_BLOCK': handle_end_block,
+ 'TK_WORD': handle_word,
+ 'TK_RESERVED': handle_word,
+ 'TK_SEMICOLON': handle_semicolon,
+ 'TK_STRING': handle_string,
+ 'TK_EQUALS': handle_equals,
+ 'TK_OPERATOR': handle_operator,
+ 'TK_COMMA': handle_comma,
+ 'TK_BLOCK_COMMENT': handle_block_comment,
+ 'TK_COMMENT': handle_comment,
+ 'TK_DOT': handle_dot,
+ 'TK_UNKNOWN': handle_unknown,
+ 'TK_EOF': handle_eof
+ };
+
+ function create_flags(flags_base, mode) {
+ var next_indent_level = 0;
+ if (flags_base) {
+ next_indent_level = flags_base.indentation_level;
+ if (!output.just_added_newline() &&
+ flags_base.line_indent_level > next_indent_level) {
+ next_indent_level = flags_base.line_indent_level;
+ }
+ }
+
+ var next_flags = {
+ mode: mode,
+ parent: flags_base,
+ last_text: flags_base ? flags_base.last_text : '', // last token text
+ last_word: flags_base ? flags_base.last_word : '', // last 'TK_WORD' passed
+ declaration_statement: false,
+ declaration_assignment: false,
+ multiline_frame: false,
+ inline_frame: false,
+ if_block: false,
+ else_block: false,
+ do_block: false,
+ do_while: false,
+ import_block: false,
+ in_case_statement: false, // switch(..){ INSIDE HERE }
+ in_case: false, // we're on the exact line with "case 0:"
+ case_body: false, // the indented case-action block
+ indentation_level: next_indent_level,
+ line_indent_level: flags_base ? flags_base.line_indent_level : next_indent_level,
+ start_line_index: output.get_line_number(),
+ ternary_depth: 0
+ };
+ return next_flags;
+ }
+
+ // Some interpreters have unexpected results with foo = baz || bar;
+ options = options ? options : {};
+ opt = {};
+
+ // compatibility
+ if (options.braces_on_own_line !== undefined) { //graceful handling of deprecated option
+ opt.brace_style = options.braces_on_own_line ? "expand" : "collapse";
+ }
+ opt.brace_style = options.brace_style ? options.brace_style : (opt.brace_style ? opt.brace_style : "collapse");
+
+ // graceful handling of deprecated option
+ if (opt.brace_style === "expand-strict") {
+ opt.brace_style = "expand";
+ }
+
+ opt.indent_size = options.indent_size ? parseInt(options.indent_size, 10) : 4;
+ opt.indent_char = options.indent_char ? options.indent_char : ' ';
+ opt.eol = options.eol ? options.eol : 'auto';
+ opt.preserve_newlines = (options.preserve_newlines === undefined) ? true : options.preserve_newlines;
+ opt.break_chained_methods = (options.break_chained_methods === undefined) ? false : options.break_chained_methods;
+ opt.max_preserve_newlines = (options.max_preserve_newlines === undefined) ? 0 : parseInt(options.max_preserve_newlines, 10);
+ opt.space_in_paren = (options.space_in_paren === undefined) ? false : options.space_in_paren;
+ opt.space_in_empty_paren = (options.space_in_empty_paren === undefined) ? false : options.space_in_empty_paren;
+ opt.jslint_happy = (options.jslint_happy === undefined) ? false : options.jslint_happy;
+ opt.space_after_anon_function = (options.space_after_anon_function === undefined) ? false : options.space_after_anon_function;
+ opt.keep_array_indentation = (options.keep_array_indentation === undefined) ? false : options.keep_array_indentation;
+ opt.space_before_conditional = (options.space_before_conditional === undefined) ? true : options.space_before_conditional;
+ opt.unescape_strings = (options.unescape_strings === undefined) ? false : options.unescape_strings;
+ opt.wrap_line_length = (options.wrap_line_length === undefined) ? 0 : parseInt(options.wrap_line_length, 10);
+ opt.e4x = (options.e4x === undefined) ? false : options.e4x;
+ opt.end_with_newline = (options.end_with_newline === undefined) ? false : options.end_with_newline;
+ opt.comma_first = (options.comma_first === undefined) ? false : options.comma_first;
+ opt.operator_position = sanitizeOperatorPosition(options.operator_position);
+
+ // For testing of beautify ignore:start directive
+ opt.test_output_raw = (options.test_output_raw === undefined) ? false : options.test_output_raw;
+
+ // force opt.space_after_anon_function to true if opt.jslint_happy
+ if (opt.jslint_happy) {
+ opt.space_after_anon_function = true;
+ }
+
+ if (options.indent_with_tabs) {
+ opt.indent_char = '\t';
+ opt.indent_size = 1;
+ }
+
+ if (opt.eol === 'auto') {
+ opt.eol = '\n';
+ if (js_source_text && acorn.lineBreak.test(js_source_text || '')) {
+ opt.eol = js_source_text.match(acorn.lineBreak)[0];
+ }
+ }
+
+ opt.eol = opt.eol.replace(/\\r/, '\r').replace(/\\n/, '\n');
+
+ //----------------------------------
+ indent_string = '';
+ while (opt.indent_size > 0) {
+ indent_string += opt.indent_char;
+ opt.indent_size -= 1;
+ }
+
+ var preindent_index = 0;
+ if (js_source_text && js_source_text.length) {
+ while ((js_source_text.charAt(preindent_index) === ' ' ||
+ js_source_text.charAt(preindent_index) === '\t')) {
+ baseIndentString += js_source_text.charAt(preindent_index);
+ preindent_index += 1;
+ }
+ js_source_text = js_source_text.substring(preindent_index);
+ }
+
+ last_type = 'TK_START_BLOCK'; // last token type
+ last_last_text = ''; // pre-last token text
+ output = new Output(indent_string, baseIndentString);
+
+ // If testing the ignore directive, start with output disable set to true
+ output.raw = opt.test_output_raw;
+
+
+ // Stack of parsing/formatting states, including MODE.
+ // We tokenize, parse, and output in an almost purely a forward-only stream of token input
+ // and formatted output. This makes the beautifier less accurate than full parsers
+ // but also far more tolerant of syntax errors.
+ //
+ // For example, the default mode is MODE.BlockStatement. If we see a '{' we push a new frame of type
+ // MODE.BlockStatement on the the stack, even though it could be object literal. If we later
+ // encounter a ":", we'll switch to to MODE.ObjectLiteral. If we then see a ";",
+ // most full parsers would die, but the beautifier gracefully falls back to
+ // MODE.BlockStatement and continues on.
+ flag_store = [];
+ set_mode(MODE.BlockStatement);
+
+ this.beautify = function() {
+
+ /*jshint onevar:true */
+ var local_token, sweet_code;
+ Tokenizer = new tokenizer(js_source_text, opt, indent_string);
+ tokens = Tokenizer.tokenize();
+ token_pos = 0;
+
+ function get_local_token() {
+ local_token = get_token();
+ return local_token;
+ }
+
+ while (get_local_token()) {
+ for (var i = 0; i < local_token.comments_before.length; i++) {
+ // The cleanest handling of inline comments is to treat them as though they aren't there.
+ // Just continue formatting and the behavior should be logical.
+ // Also ignore unknown tokens. Again, this should result in better behavior.
+ handle_token(local_token.comments_before[i]);
+ }
+ handle_token(local_token);
+
+ last_last_text = flags.last_text;
+ last_type = local_token.type;
+ flags.last_text = local_token.text;
+
+ token_pos += 1;
+ }
+
+ sweet_code = output.get_code();
+ if (opt.end_with_newline) {
+ sweet_code += '\n';
+ }
+
+ if (opt.eol !== '\n') {
+ sweet_code = sweet_code.replace(/[\n]/g, opt.eol);
+ }
+
+ return sweet_code;
+ };
+
+ function handle_token(local_token) {
+ var newlines = local_token.newlines;
+ var keep_whitespace = opt.keep_array_indentation && is_array(flags.mode);
+
+ if (keep_whitespace) {
+ for (var i = 0; i < newlines; i += 1) {
+ print_newline(i > 0);
+ }
+ } else {
+ if (opt.max_preserve_newlines && newlines > opt.max_preserve_newlines) {
+ newlines = opt.max_preserve_newlines;
+ }
+
+ if (opt.preserve_newlines) {
+ if (local_token.newlines > 1) {
+ print_newline();
+ for (var j = 1; j < newlines; j += 1) {
+ print_newline(true);
+ }
+ }
+ }
+ }
+
+ current_token = local_token;
+ handlers[current_token.type]();
+ }
+
+ // we could use just string.split, but
+ // IE doesn't like returning empty strings
+ function split_linebreaks(s) {
+ //return s.split(/\x0d\x0a|\x0a/);
+
+ s = s.replace(acorn.allLineBreaks, '\n');
+ var out = [],
+ idx = s.indexOf("\n");
+ while (idx !== -1) {
+ out.push(s.substring(0, idx));
+ s = s.substring(idx + 1);
+ idx = s.indexOf("\n");
+ }
+ if (s.length) {
+ out.push(s);
+ }
+ return out;
+ }
+
+ var newline_restricted_tokens = ['break', 'contiue', 'return', 'throw'];
+
+ function allow_wrap_or_preserved_newline(force_linewrap) {
+ force_linewrap = (force_linewrap === undefined) ? false : force_linewrap;
+
+ // Never wrap the first token on a line
+ if (output.just_added_newline()) {
+ return;
+ }
+
+ var shouldPreserveOrForce = (opt.preserve_newlines && current_token.wanted_newline) || force_linewrap;
+ var operatorLogicApplies = in_array(flags.last_text, Tokenizer.positionable_operators) || in_array(current_token.text, Tokenizer.positionable_operators);
+
+ if (operatorLogicApplies) {
+ var shouldPrintOperatorNewline = (
+ in_array(flags.last_text, Tokenizer.positionable_operators) &&
+ in_array(opt.operator_position, OPERATOR_POSITION_BEFORE_OR_PRESERVE)
+ ) ||
+ in_array(current_token.text, Tokenizer.positionable_operators);
+ shouldPreserveOrForce = shouldPreserveOrForce && shouldPrintOperatorNewline;
+ }
+
+ if (shouldPreserveOrForce) {
+ print_newline(false, true);
+ } else if (opt.wrap_line_length) {
+ if (last_type === 'TK_RESERVED' && in_array(flags.last_text, newline_restricted_tokens)) {
+ // These tokens should never have a newline inserted
+ // between them and the following expression.
+ return;
+ }
+ var proposed_line_length = output.current_line.get_character_count() + current_token.text.length +
+ (output.space_before_token ? 1 : 0);
+ if (proposed_line_length >= opt.wrap_line_length) {
+ print_newline(false, true);
+ }
+ }
+ }
+
+ function print_newline(force_newline, preserve_statement_flags) {
+ if (!preserve_statement_flags) {
+ if (flags.last_text !== ';' && flags.last_text !== ',' && flags.last_text !== '=' && last_type !== 'TK_OPERATOR') {
+ while (flags.mode === MODE.Statement && !flags.if_block && !flags.do_block) {
+ restore_mode();
+ }
+ }
+ }
+
+ if (output.add_new_line(force_newline)) {
+ flags.multiline_frame = true;
+ }
+ }
+
+ function print_token_line_indentation() {
+ if (output.just_added_newline()) {
+ if (opt.keep_array_indentation && is_array(flags.mode) && current_token.wanted_newline) {
+ output.current_line.push(current_token.whitespace_before);
+ output.space_before_token = false;
+ } else if (output.set_indent(flags.indentation_level)) {
+ flags.line_indent_level = flags.indentation_level;
+ }
+ }
+ }
+
+ function print_token(printable_token) {
+ if (output.raw) {
+ output.add_raw_token(current_token);
+ return;
+ }
+
+ if (opt.comma_first && last_type === 'TK_COMMA' &&
+ output.just_added_newline()) {
+ if (output.previous_line.last() === ',') {
+ var popped = output.previous_line.pop();
+ // if the comma was already at the start of the line,
+ // pull back onto that line and reprint the indentation
+ if (output.previous_line.is_empty()) {
+ output.previous_line.push(popped);
+ output.trim(true);
+ output.current_line.pop();
+ output.trim();
+ }
+
+ // add the comma in front of the next token
+ print_token_line_indentation();
+ output.add_token(',');
+ output.space_before_token = true;
+ }
+ }
+
+ printable_token = printable_token || current_token.text;
+ print_token_line_indentation();
+ output.add_token(printable_token);
+ }
+
+ function indent() {
+ flags.indentation_level += 1;
+ }
+
+ function deindent() {
+ if (flags.indentation_level > 0 &&
+ ((!flags.parent) || flags.indentation_level > flags.parent.indentation_level)) {
+ flags.indentation_level -= 1;
+
+ }
+ }
+
+ function set_mode(mode) {
+ if (flags) {
+ flag_store.push(flags);
+ previous_flags = flags;
+ } else {
+ previous_flags = create_flags(null, mode);
+ }
+
+ flags = create_flags(previous_flags, mode);
+ }
+
+ function is_array(mode) {
+ return mode === MODE.ArrayLiteral;
+ }
+
+ function is_expression(mode) {
+ return in_array(mode, [MODE.Expression, MODE.ForInitializer, MODE.Conditional]);
+ }
+
+ function restore_mode() {
+ if (flag_store.length > 0) {
+ previous_flags = flags;
+ flags = flag_store.pop();
+ if (previous_flags.mode === MODE.Statement) {
+ output.remove_redundant_indentation(previous_flags);
+ }
+ }
+ }
+
+ function start_of_object_property() {
+ return flags.parent.mode === MODE.ObjectLiteral && flags.mode === MODE.Statement && (
+ (flags.last_text === ':' && flags.ternary_depth === 0) || (last_type === 'TK_RESERVED' && in_array(flags.last_text, ['get', 'set'])));
+ }
+
+ function start_of_statement() {
+ if (
+ (last_type === 'TK_RESERVED' && in_array(flags.last_text, ['var', 'let', 'const']) && current_token.type === 'TK_WORD') ||
+ (last_type === 'TK_RESERVED' && flags.last_text === 'do') ||
+ (last_type === 'TK_RESERVED' && in_array(flags.last_text, ['return', 'throw']) && !current_token.wanted_newline) ||
+ (last_type === 'TK_RESERVED' && flags.last_text === 'else' && !(current_token.type === 'TK_RESERVED' && current_token.text === 'if')) ||
+ (last_type === 'TK_END_EXPR' && (previous_flags.mode === MODE.ForInitializer || previous_flags.mode === MODE.Conditional)) ||
+ (last_type === 'TK_WORD' && flags.mode === MODE.BlockStatement &&
+ !flags.in_case &&
+ !(current_token.text === '--' || current_token.text === '++') &&
+ last_last_text !== 'function' &&
+ current_token.type !== 'TK_WORD' && current_token.type !== 'TK_RESERVED') ||
+ (flags.mode === MODE.ObjectLiteral && (
+ (flags.last_text === ':' && flags.ternary_depth === 0) || (last_type === 'TK_RESERVED' && in_array(flags.last_text, ['get', 'set']))))
+ ) {
+
+ set_mode(MODE.Statement);
+ indent();
+
+ if (last_type === 'TK_RESERVED' && in_array(flags.last_text, ['var', 'let', 'const']) && current_token.type === 'TK_WORD') {
+ flags.declaration_statement = true;
+ }
+
+ // Issue #276:
+ // If starting a new statement with [if, for, while, do], push to a new line.
+ // if (a) if (b) if(c) d(); else e(); else f();
+ if (!start_of_object_property()) {
+ allow_wrap_or_preserved_newline(
+ current_token.type === 'TK_RESERVED' && in_array(current_token.text, ['do', 'for', 'if', 'while']));
+ }
+
+ return true;
+ }
+ return false;
+ }
+
+ function all_lines_start_with(lines, c) {
+ for (var i = 0; i < lines.length; i++) {
+ var line = trim(lines[i]);
+ if (line.charAt(0) !== c) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ function each_line_matches_indent(lines, indent) {
+ var i = 0,
+ len = lines.length,
+ line;
+ for (; i < len; i++) {
+ line = lines[i];
+ // allow empty lines to pass through
+ if (line && line.indexOf(indent) !== 0) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ function is_special_word(word) {
+ return in_array(word, ['case', 'return', 'do', 'if', 'throw', 'else']);
+ }
+
+ function get_token(offset) {
+ var index = token_pos + (offset || 0);
+ return (index < 0 || index >= tokens.length) ? null : tokens[index];
+ }
+
+ function handle_start_expr() {
+ if (start_of_statement()) {
+ // The conditional starts the statement if appropriate.
+ }
+
+ var next_mode = MODE.Expression;
+ if (current_token.text === '[') {
+
+ if (last_type === 'TK_WORD' || flags.last_text === ')') {
+ // this is array index specifier, break immediately
+ // a[x], fn()[x]
+ if (last_type === 'TK_RESERVED' && in_array(flags.last_text, Tokenizer.line_starters)) {
+ output.space_before_token = true;
+ }
+ set_mode(next_mode);
+ print_token();
+ indent();
+ if (opt.space_in_paren) {
+ output.space_before_token = true;
+ }
+ return;
+ }
+
+ next_mode = MODE.ArrayLiteral;
+ if (is_array(flags.mode)) {
+ if (flags.last_text === '[' ||
+ (flags.last_text === ',' && (last_last_text === ']' || last_last_text === '}'))) {
+ // ], [ goes to new line
+ // }, [ goes to new line
+ if (!opt.keep_array_indentation) {
+ print_newline();
+ }
+ }
+ }
+
+ } else {
+ if (last_type === 'TK_RESERVED' && flags.last_text === 'for') {
+ next_mode = MODE.ForInitializer;
+ } else if (last_type === 'TK_RESERVED' && in_array(flags.last_text, ['if', 'while'])) {
+ next_mode = MODE.Conditional;
+ } else {
+ // next_mode = MODE.Expression;
+ }
+ }
+
+ if (flags.last_text === ';' || last_type === 'TK_START_BLOCK') {
+ print_newline();
+ } else if (last_type === 'TK_END_EXPR' || last_type === 'TK_START_EXPR' || last_type === 'TK_END_BLOCK' || flags.last_text === '.') {
+ // TODO: Consider whether forcing this is required. Review failing tests when removed.
+ allow_wrap_or_preserved_newline(current_token.wanted_newline);
+ // do nothing on (( and )( and ][ and ]( and .(
+ } else if (!(last_type === 'TK_RESERVED' && current_token.text === '(') && last_type !== 'TK_WORD' && last_type !== 'TK_OPERATOR') {
+ output.space_before_token = true;
+ } else if ((last_type === 'TK_RESERVED' && (flags.last_word === 'function' || flags.last_word === 'typeof')) ||
+ (flags.last_text === '*' && last_last_text === 'function')) {
+ // function() vs function ()
+ if (opt.space_after_anon_function) {
+ output.space_before_token = true;
+ }
+ } else if (last_type === 'TK_RESERVED' && (in_array(flags.last_text, Tokenizer.line_starters) || flags.last_text === 'catch')) {
+ if (opt.space_before_conditional) {
+ output.space_before_token = true;
+ }
+ }
+
+ // Should be a space between await and an IIFE
+ if (current_token.text === '(' && last_type === 'TK_RESERVED' && flags.last_word === 'await') {
+ output.space_before_token = true;
+ }
+
+ // Support of this kind of newline preservation.
+ // a = (b &&
+ // (c || d));
+ if (current_token.text === '(') {
+ if (last_type === 'TK_EQUALS' || last_type === 'TK_OPERATOR') {
+ if (!start_of_object_property()) {
+ allow_wrap_or_preserved_newline();
+ }
+ }
+ }
+
+ // Support preserving wrapped arrow function expressions
+ // a.b('c',
+ // () => d.e
+ // )
+ if (current_token.text === '(' && last_type !== 'TK_WORD' && last_type !== 'TK_RESERVED') {
+ allow_wrap_or_preserved_newline();
+ }
+
+ set_mode(next_mode);
+ print_token();
+ if (opt.space_in_paren) {
+ output.space_before_token = true;
+ }
+
+ // In all cases, if we newline while inside an expression it should be indented.
+ indent();
+ }
+
+ function handle_end_expr() {
+ // statements inside expressions are not valid syntax, but...
+ // statements must all be closed when their container closes
+ while (flags.mode === MODE.Statement) {
+ restore_mode();
+ }
+
+ if (flags.multiline_frame) {
+ allow_wrap_or_preserved_newline(current_token.text === ']' && is_array(flags.mode) && !opt.keep_array_indentation);
+ }
+
+ if (opt.space_in_paren) {
+ if (last_type === 'TK_START_EXPR' && !opt.space_in_empty_paren) {
+ // () [] no inner space in empty parens like these, ever, ref #320
+ output.trim();
+ output.space_before_token = false;
+ } else {
+ output.space_before_token = true;
+ }
+ }
+ if (current_token.text === ']' && opt.keep_array_indentation) {
+ print_token();
+ restore_mode();
+ } else {
+ restore_mode();
+ print_token();
+ }
+ output.remove_redundant_indentation(previous_flags);
+
+ // do {} while () // no statement required after
+ if (flags.do_while && previous_flags.mode === MODE.Conditional) {
+ previous_flags.mode = MODE.Expression;
+ flags.do_block = false;
+ flags.do_while = false;
+
+ }
+ }
+
+ function handle_start_block() {
+ // Check if this is should be treated as a ObjectLiteral
+ var next_token = get_token(1);
+ var second_token = get_token(2);
+ if (second_token && (
+ (in_array(second_token.text, [':', ',']) && in_array(next_token.type, ['TK_STRING', 'TK_WORD', 'TK_RESERVED'])) ||
+ (in_array(next_token.text, ['get', 'set']) && in_array(second_token.type, ['TK_WORD', 'TK_RESERVED']))
+ )) {
+ // We don't support TypeScript,but we didn't break it for a very long time.
+ // We'll try to keep not breaking it.
+ if (!in_array(last_last_text, ['class', 'interface'])) {
+ set_mode(MODE.ObjectLiteral);
+ } else {
+ set_mode(MODE.BlockStatement);
+ }
+ } else if (last_type === 'TK_OPERATOR' && flags.last_text === '=>') {
+ // arrow function: (param1, paramN) => { statements }
+ set_mode(MODE.BlockStatement);
+ } else if (in_array(last_type, ['TK_EQUALS', 'TK_START_EXPR', 'TK_COMMA', 'TK_OPERATOR']) ||
+ (last_type === 'TK_RESERVED' && in_array(flags.last_text, ['return', 'throw', 'import']))
+ ) {
+ // Detecting shorthand function syntax is difficult by scanning forward,
+ // so check the surrounding context.
+ // If the block is being returned, imported, passed as arg,
+ // assigned with = or assigned in a nested object, treat as an ObjectLiteral.
+ set_mode(MODE.ObjectLiteral);
+ } else {
+ set_mode(MODE.BlockStatement);
+ }
+
+ var empty_braces = !next_token.comments_before.length && next_token.text === '}';
+ var empty_anonymous_function = empty_braces && flags.last_word === 'function' &&
+ last_type === 'TK_END_EXPR';
+
+
+ if (opt.brace_style === "expand" ||
+ (opt.brace_style === "none" && current_token.wanted_newline)) {
+ if (last_type !== 'TK_OPERATOR' &&
+ (empty_anonymous_function ||
+ last_type === 'TK_EQUALS' ||
+ (last_type === 'TK_RESERVED' && is_special_word(flags.last_text) && flags.last_text !== 'else'))) {
+ output.space_before_token = true;
+ } else {
+ print_newline(false, true);
+ }
+ } else { // collapse
+ if (opt.brace_style === 'collapse-preserve-inline') {
+ // search forward for a newline wanted inside this block
+ var index = 0;
+ var check_token = null;
+ flags.inline_frame = true;
+ do {
+ index += 1;
+ check_token = get_token(index);
+ if (check_token.wanted_newline) {
+ flags.inline_frame = false;
+ break;
+ }
+ } while (check_token.type !== 'TK_EOF' &&
+ !(check_token.type === 'TK_END_BLOCK' && check_token.opened === current_token));
+ }
+
+ if (is_array(previous_flags.mode) && (last_type === 'TK_START_EXPR' || last_type === 'TK_COMMA')) {
+ // if we're preserving inline,
+ // allow newline between comma and next brace.
+ if (last_type === 'TK_COMMA' || opt.space_in_paren) {
+ output.space_before_token = true;
+ }
+
+ if (opt.brace_style === 'collapse-preserve-inline' &&
+ (last_type === 'TK_COMMA' || (last_type === 'TK_START_EXPR' && flags.inline_frame))) {
+ allow_wrap_or_preserved_newline();
+ previous_flags.multiline_frame = previous_flags.multiline_frame || flags.multiline_frame;
+ flags.multiline_frame = false;
+ }
+ } else if (last_type !== 'TK_OPERATOR' && last_type !== 'TK_START_EXPR') {
+ if (last_type === 'TK_START_BLOCK') {
+ print_newline();
+ } else {
+ output.space_before_token = true;
+ }
+ }
+ }
+ print_token();
+ indent();
+ }
+
+ function handle_end_block() {
+ // statements must all be closed when their container closes
+ while (flags.mode === MODE.Statement) {
+ restore_mode();
+ }
+ var empty_braces = last_type === 'TK_START_BLOCK';
+
+ if (opt.brace_style === "expand") {
+ if (!empty_braces) {
+ print_newline();
+ }
+ } else {
+ // skip {}
+ if (!empty_braces) {
+ if (flags.inline_frame) {
+ output.space_before_token = true;
+ } else if (is_array(flags.mode) && opt.keep_array_indentation) {
+ // we REALLY need a newline here, but newliner would skip that
+ opt.keep_array_indentation = false;
+ print_newline();
+ opt.keep_array_indentation = true;
+
+ } else {
+ print_newline();
+ }
+ }
+ }
+ restore_mode();
+ print_token();
+ }
+
+ function handle_word() {
+ if (current_token.type === 'TK_RESERVED') {
+ if (in_array(current_token.text, ['set', 'get']) && flags.mode !== MODE.ObjectLiteral) {
+ current_token.type = 'TK_WORD';
+ } else if (in_array(current_token.text, ['as', 'from']) && !flags.import_block) {
+ current_token.type = 'TK_WORD';
+ } else if (flags.mode === MODE.ObjectLiteral) {
+ var next_token = get_token(1);
+ if (next_token.text === ':') {
+ current_token.type = 'TK_WORD';
+ }
+ }
+ }
+
+ if (start_of_statement()) {
+ // The conditional starts the statement if appropriate.
+ } else if (current_token.wanted_newline && !is_expression(flags.mode) &&
+ (last_type !== 'TK_OPERATOR' || (flags.last_text === '--' || flags.last_text === '++')) &&
+ last_type !== 'TK_EQUALS' &&
+ (opt.preserve_newlines || !(last_type === 'TK_RESERVED' && in_array(flags.last_text, ['var', 'let', 'const', 'set', 'get'])))) {
+
+ print_newline();
+ }
+
+ if (flags.do_block && !flags.do_while) {
+ if (current_token.type === 'TK_RESERVED' && current_token.text === 'while') {
+ // do {} ## while ()
+ output.space_before_token = true;
+ print_token();
+ output.space_before_token = true;
+ flags.do_while = true;
+ return;
+ } else {
+ // do {} should always have while as the next word.
+ // if we don't see the expected while, recover
+ print_newline();
+ flags.do_block = false;
+ }
+ }
+
+ // if may be followed by else, or not
+ // Bare/inline ifs are tricky
+ // Need to unwind the modes correctly: if (a) if (b) c(); else d(); else e();
+ if (flags.if_block) {
+ if (!flags.else_block && (current_token.type === 'TK_RESERVED' && current_token.text === 'else')) {
+ flags.else_block = true;
+ } else {
+ while (flags.mode === MODE.Statement) {
+ restore_mode();
+ }
+ flags.if_block = false;
+ flags.else_block = false;
+ }
+ }
+
+ if (current_token.type === 'TK_RESERVED' && (current_token.text === 'case' || (current_token.text === 'default' && flags.in_case_statement))) {
+ print_newline();
+ if (flags.case_body || opt.jslint_happy) {
+ // switch cases following one another
+ deindent();
+ flags.case_body = false;
+ }
+ print_token();
+ flags.in_case = true;
+ flags.in_case_statement = true;
+ return;
+ }
+
+ if (current_token.type === 'TK_RESERVED' && current_token.text === 'function') {
+ if (in_array(flags.last_text, ['}', ';']) || (output.just_added_newline() && !in_array(flags.last_text, ['[', '{', ':', '=', ',']))) {
+ // make sure there is a nice clean space of at least one blank line
+ // before a new function definition
+ if (!output.just_added_blankline() && !current_token.comments_before.length) {
+ print_newline();
+ print_newline(true);
+ }
+ }
+ if (last_type === 'TK_RESERVED' || last_type === 'TK_WORD') {
+ if (last_type === 'TK_RESERVED' && in_array(flags.last_text, ['get', 'set', 'new', 'return', 'export', 'async'])) {
+ output.space_before_token = true;
+ } else if (last_type === 'TK_RESERVED' && flags.last_text === 'default' && last_last_text === 'export') {
+ output.space_before_token = true;
+ } else {
+ print_newline();
+ }
+ } else if (last_type === 'TK_OPERATOR' || flags.last_text === '=') {
+ // foo = function
+ output.space_before_token = true;
+ } else if (!flags.multiline_frame && (is_expression(flags.mode) || is_array(flags.mode))) {
+ // (function
+ } else {
+ print_newline();
+ }
+ }
+
+ if (last_type === 'TK_COMMA' || last_type === 'TK_START_EXPR' || last_type === 'TK_EQUALS' || last_type === 'TK_OPERATOR') {
+ if (!start_of_object_property()) {
+ allow_wrap_or_preserved_newline();
+ }
+ }
+
+ if (current_token.type === 'TK_RESERVED' && in_array(current_token.text, ['function', 'get', 'set'])) {
+ print_token();
+ flags.last_word = current_token.text;
+ return;
+ }
+
+ prefix = 'NONE';
+
+ if (last_type === 'TK_END_BLOCK') {
+
+ if (!(current_token.type === 'TK_RESERVED' && in_array(current_token.text, ['else', 'catch', 'finally', 'from']))) {
+ prefix = 'NEWLINE';
+ } else {
+ if (opt.brace_style === "expand" ||
+ opt.brace_style === "end-expand" ||
+ (opt.brace_style === "none" && current_token.wanted_newline)) {
+ prefix = 'NEWLINE';
+ } else {
+ prefix = 'SPACE';
+ output.space_before_token = true;
+ }
+ }
+ } else if (last_type === 'TK_SEMICOLON' && flags.mode === MODE.BlockStatement) {
+ // TODO: Should this be for STATEMENT as well?
+ prefix = 'NEWLINE';
+ } else if (last_type === 'TK_SEMICOLON' && is_expression(flags.mode)) {
+ prefix = 'SPACE';
+ } else if (last_type === 'TK_STRING') {
+ prefix = 'NEWLINE';
+ } else if (last_type === 'TK_RESERVED' || last_type === 'TK_WORD' ||
+ (flags.last_text === '*' && last_last_text === 'function')) {
+ prefix = 'SPACE';
+ } else if (last_type === 'TK_START_BLOCK') {
+ if (flags.inline_frame) {
+ prefix = 'SPACE';
+ } else {
+ prefix = 'NEWLINE';
+ }
+ } else if (last_type === 'TK_END_EXPR') {
+ output.space_before_token = true;
+ prefix = 'NEWLINE';
+ }
+
+ if (current_token.type === 'TK_RESERVED' && in_array(current_token.text, Tokenizer.line_starters) && flags.last_text !== ')') {
+ if (flags.last_text === 'else' || flags.last_text === 'export') {
+ prefix = 'SPACE';
+ } else {
+ prefix = 'NEWLINE';
+ }
+
+ }
+
+ if (current_token.type === 'TK_RESERVED' && in_array(current_token.text, ['else', 'catch', 'finally'])) {
+ if (!(last_type === 'TK_END_BLOCK' && previous_flags.mode === MODE.BlockStatement) ||
+ opt.brace_style === "expand" ||
+ opt.brace_style === "end-expand" ||
+ (opt.brace_style === "none" && current_token.wanted_newline)) {
+ print_newline();
+ } else {
+ output.trim(true);
+ var line = output.current_line;
+ // If we trimmed and there's something other than a close block before us
+ // put a newline back in. Handles '} // comment' scenario.
+ if (line.last() !== '}') {
+ print_newline();
+ }
+ output.space_before_token = true;
+ }
+ } else if (prefix === 'NEWLINE') {
+ if (last_type === 'TK_RESERVED' && is_special_word(flags.last_text)) {
+ // no newline between 'return nnn'
+ output.space_before_token = true;
+ } else if (last_type !== 'TK_END_EXPR') {
+ if ((last_type !== 'TK_START_EXPR' || !(current_token.type === 'TK_RESERVED' && in_array(current_token.text, ['var', 'let', 'const']))) && flags.last_text !== ':') {
+ // no need to force newline on 'var': for (var x = 0...)
+ if (current_token.type === 'TK_RESERVED' && current_token.text === 'if' && flags.last_text === 'else') {
+ // no newline for } else if {
+ output.space_before_token = true;
+ } else {
+ print_newline();
+ }
+ }
+ } else if (current_token.type === 'TK_RESERVED' && in_array(current_token.text, Tokenizer.line_starters) && flags.last_text !== ')') {
+ print_newline();
+ }
+ } else if (flags.multiline_frame && is_array(flags.mode) && flags.last_text === ',' && last_last_text === '}') {
+ print_newline(); // }, in lists get a newline treatment
+ } else if (prefix === 'SPACE') {
+ output.space_before_token = true;
+ }
+ print_token();
+ flags.last_word = current_token.text;
+
+ if (current_token.type === 'TK_RESERVED') {
+ if (current_token.text === 'do') {
+ flags.do_block = true;
+ } else if (current_token.text === 'if') {
+ flags.if_block = true;
+ } else if (current_token.text === 'import') {
+ flags.import_block = true;
+ } else if (flags.import_block && current_token.type === 'TK_RESERVED' && current_token.text === 'from') {
+ flags.import_block = false;
+ }
+ }
+ }
+
+ function handle_semicolon() {
+ if (start_of_statement()) {
+ // The conditional starts the statement if appropriate.
+ // Semicolon can be the start (and end) of a statement
+ output.space_before_token = false;
+ }
+ while (flags.mode === MODE.Statement && !flags.if_block && !flags.do_block) {
+ restore_mode();
+ }
+
+ // hacky but effective for the moment
+ if (flags.import_block) {
+ flags.import_block = false;
+ }
+ print_token();
+ }
+
+ function handle_string() {
+ if (start_of_statement()) {
+ // The conditional starts the statement if appropriate.
+ // One difference - strings want at least a space before
+ output.space_before_token = true;
+ } else if (last_type === 'TK_RESERVED' || last_type === 'TK_WORD' || flags.inline_frame) {
+ output.space_before_token = true;
+ } else if (last_type === 'TK_COMMA' || last_type === 'TK_START_EXPR' || last_type === 'TK_EQUALS' || last_type === 'TK_OPERATOR') {
+ if (!start_of_object_property()) {
+ allow_wrap_or_preserved_newline();
+ }
+ } else {
+ print_newline();
+ }
+ print_token();
+ }
+
+ function handle_equals() {
+ if (start_of_statement()) {
+ // The conditional starts the statement if appropriate.
+ }
+
+ if (flags.declaration_statement) {
+ // just got an '=' in a var-line, different formatting/line-breaking, etc will now be done
+ flags.declaration_assignment = true;
+ }
+ output.space_before_token = true;
+ print_token();
+ output.space_before_token = true;
+ }
+
+ function handle_comma() {
+ print_token();
+ output.space_before_token = true;
+ if (flags.declaration_statement) {
+ if (is_expression(flags.parent.mode)) {
+ // do not break on comma, for(var a = 1, b = 2)
+ flags.declaration_assignment = false;
+ }
+
+ if (flags.declaration_assignment) {
+ flags.declaration_assignment = false;
+ print_newline(false, true);
+ } else if (opt.comma_first) {
+ // for comma-first, we want to allow a newline before the comma
+ // to turn into a newline after the comma, which we will fixup later
+ allow_wrap_or_preserved_newline();
+ }
+ } else if (flags.mode === MODE.ObjectLiteral ||
+ (flags.mode === MODE.Statement && flags.parent.mode === MODE.ObjectLiteral)) {
+ if (flags.mode === MODE.Statement) {
+ restore_mode();
+ }
+
+ if (!flags.inline_frame) {
+ print_newline();
+ }
+ } else if (opt.comma_first) {
+ // EXPR or DO_BLOCK
+ // for comma-first, we want to allow a newline before the comma
+ // to turn into a newline after the comma, which we will fixup later
+ allow_wrap_or_preserved_newline();
+ }
+ }
+
+ function handle_operator() {
+ if (start_of_statement()) {
+ // The conditional starts the statement if appropriate.
+ }
+
+ if (last_type === 'TK_RESERVED' && is_special_word(flags.last_text)) {
+ // "return" had a special handling in TK_WORD. Now we need to return the favor
+ output.space_before_token = true;
+ print_token();
+ return;
+ }
+
+ // hack for actionscript's import .*;
+ if (current_token.text === '*' && last_type === 'TK_DOT') {
+ print_token();
+ return;
+ }
+
+ if (current_token.text === '::') {
+ // no spaces around exotic namespacing syntax operator
+ print_token();
+ return;
+ }
+
+ // Allow line wrapping between operators when operator_position is
+ // set to before or preserve
+ if (last_type === 'TK_OPERATOR' && in_array(opt.operator_position, OPERATOR_POSITION_BEFORE_OR_PRESERVE)) {
+ allow_wrap_or_preserved_newline();
+ }
+
+ if (current_token.text === ':' && flags.in_case) {
+ flags.case_body = true;
+ indent();
+ print_token();
+ print_newline();
+ flags.in_case = false;
+ return;
+ }
+
+ var space_before = true;
+ var space_after = true;
+ var in_ternary = false;
+ var isGeneratorAsterisk = current_token.text === '*' && last_type === 'TK_RESERVED' && flags.last_text === 'function';
+ var isUnary = in_array(current_token.text, ['-', '+']) && (
+ in_array(last_type, ['TK_START_BLOCK', 'TK_START_EXPR', 'TK_EQUALS', 'TK_OPERATOR']) ||
+ in_array(flags.last_text, Tokenizer.line_starters) ||
+ flags.last_text === ','
+ );
+
+ if (current_token.text === ':') {
+ if (flags.ternary_depth === 0) {
+ // Colon is invalid javascript outside of ternary and object, but do our best to guess what was meant.
+ space_before = false;
+ } else {
+ flags.ternary_depth -= 1;
+ in_ternary = true;
+ }
+ } else if (current_token.text === '?') {
+ flags.ternary_depth += 1;
+ }
+
+ // let's handle the operator_position option prior to any conflicting logic
+ if (!isUnary && !isGeneratorAsterisk && opt.preserve_newlines && in_array(current_token.text, Tokenizer.positionable_operators)) {
+ var isColon = current_token.text === ':';
+ var isTernaryColon = (isColon && in_ternary);
+ var isOtherColon = (isColon && !in_ternary);
+
+ switch (opt.operator_position) {
+ case OPERATOR_POSITION.before_newline:
+ // if the current token is : and it's not a ternary statement then we set space_before to false
+ output.space_before_token = !isOtherColon;
+
+ print_token();
+
+ if (!isColon || isTernaryColon) {
+ allow_wrap_or_preserved_newline();
+ }
+
+ output.space_before_token = true;
+ return;
+
+ case OPERATOR_POSITION.after_newline:
+ // if the current token is anything but colon, or (via deduction) it's a colon and in a ternary statement,
+ // then print a newline.
+
+ output.space_before_token = true;
+
+ if (!isColon || isTernaryColon) {
+ if (get_token(1).wanted_newline) {
+ print_newline(false, true);
+ } else {
+ allow_wrap_or_preserved_newline();
+ }
+ } else {
+ output.space_before_token = false;
+ }
+
+ print_token();
+
+ output.space_before_token = true;
+ return;
+
+ case OPERATOR_POSITION.preserve_newline:
+ if (!isOtherColon) {
+ allow_wrap_or_preserved_newline();
+ }
+
+ // if we just added a newline, or the current token is : and it's not a ternary statement,
+ // then we set space_before to false
+ space_before = !(output.just_added_newline() || isOtherColon);
+
+ output.space_before_token = space_before;
+ print_token();
+ output.space_before_token = true;
+ return;
+ }
+ }
+
+ if (in_array(current_token.text, ['--', '++', '!', '~']) || isUnary) {
+ // unary operators (and binary +/- pretending to be unary) special cases
+
+ space_before = false;
+ space_after = false;
+
+ // http://www.ecma-international.org/ecma-262/5.1/#sec-7.9.1
+ // if there is a newline between -- or ++ and anything else we should preserve it.
+ if (current_token.wanted_newline && (current_token.text === '--' || current_token.text === '++')) {
+ print_newline(false, true);
+ }
+
+ if (flags.last_text === ';' && is_expression(flags.mode)) {
+ // for (;; ++i)
+ // ^^^
+ space_before = true;
+ }
+
+ if (last_type === 'TK_RESERVED') {
+ space_before = true;
+ } else if (last_type === 'TK_END_EXPR') {
+ space_before = !(flags.last_text === ']' && (current_token.text === '--' || current_token.text === '++'));
+ } else if (last_type === 'TK_OPERATOR') {
+ // a++ + ++b;
+ // a - -b
+ space_before = in_array(current_token.text, ['--', '-', '++', '+']) && in_array(flags.last_text, ['--', '-', '++', '+']);
+ // + and - are not unary when preceeded by -- or ++ operator
+ // a-- + b
+ // a * +b
+ // a - -b
+ if (in_array(current_token.text, ['+', '-']) && in_array(flags.last_text, ['--', '++'])) {
+ space_after = true;
+ }
+ }
+
+
+ if (((flags.mode === MODE.BlockStatement && !flags.inline_frame) || flags.mode === MODE.Statement) &&
+ (flags.last_text === '{' || flags.last_text === ';')) {
+ // { foo; --i }
+ // foo(); --bar;
+ print_newline();
+ }
+ } else if (isGeneratorAsterisk) {
+ space_before = false;
+ space_after = false;
+ }
+ output.space_before_token = output.space_before_token || space_before;
+ print_token();
+ output.space_before_token = space_after;
+ }
+
+ function handle_block_comment() {
+ if (output.raw) {
+ output.add_raw_token(current_token);
+ if (current_token.directives && current_token.directives.preserve === 'end') {
+ // If we're testing the raw output behavior, do not allow a directive to turn it off.
+ output.raw = opt.test_output_raw;
+ }
+ return;
+ }
+
+ if (current_token.directives) {
+ print_newline(false, true);
+ print_token();
+ if (current_token.directives.preserve === 'start') {
+ output.raw = true;
+ }
+ print_newline(false, true);
+ return;
+ }
+
+ // inline block
+ if (!acorn.newline.test(current_token.text) && !current_token.wanted_newline) {
+ output.space_before_token = true;
+ print_token();
+ output.space_before_token = true;
+ return;
+ }
+
+ var lines = split_linebreaks(current_token.text);
+ var j; // iterator for this case
+ var javadoc = false;
+ var starless = false;
+ var lastIndent = current_token.whitespace_before;
+ var lastIndentLength = lastIndent.length;
+
+ // block comment starts with a new line
+ print_newline(false, true);
+ if (lines.length > 1) {
+ javadoc = all_lines_start_with(lines.slice(1), '*');
+ starless = each_line_matches_indent(lines.slice(1), lastIndent);
+ }
+
+ // first line always indented
+ print_token(lines[0]);
+ for (j = 1; j < lines.length; j++) {
+ print_newline(false, true);
+ if (javadoc) {
+ // javadoc: reformat and re-indent
+ print_token(' ' + ltrim(lines[j]));
+ } else if (starless && lines[j].length > lastIndentLength) {
+ // starless: re-indent non-empty content, avoiding trim
+ print_token(lines[j].substring(lastIndentLength));
+ } else {
+ // normal comments output raw
+ output.add_token(lines[j]);
+ }
+ }
+
+ // for comments of more than one line, make sure there's a new line after
+ print_newline(false, true);
+ }
+
+ function handle_comment() {
+ if (current_token.wanted_newline) {
+ print_newline(false, true);
+ } else {
+ output.trim(true);
+ }
+
+ output.space_before_token = true;
+ print_token();
+ print_newline(false, true);
+ }
+
+ function handle_dot() {
+ if (start_of_statement()) {
+ // The conditional starts the statement if appropriate.
+ }
+
+ if (last_type === 'TK_RESERVED' && is_special_word(flags.last_text)) {
+ output.space_before_token = true;
+ } else {
+ // allow preserved newlines before dots in general
+ // force newlines on dots after close paren when break_chained - for bar().baz()
+ allow_wrap_or_preserved_newline(flags.last_text === ')' && opt.break_chained_methods);
+ }
+
+ print_token();
+ }
+
+ function handle_unknown() {
+ print_token();
+
+ if (current_token.text[current_token.text.length - 1] === '\n') {
+ print_newline();
+ }
+ }
+
+ function handle_eof() {
+ // Unwind any open statements
+ while (flags.mode === MODE.Statement) {
+ restore_mode();
+ }
+ }
+ }
+
+
+ function OutputLine(parent) {
+ var _character_count = 0;
+ // use indent_count as a marker for lines that have preserved indentation
+ var _indent_count = -1;
+
+ var _items = [];
+ var _empty = true;
+
+ this.set_indent = function(level) {
+ _character_count = parent.baseIndentLength + level * parent.indent_length;
+ _indent_count = level;
+ };
+
+ this.get_character_count = function() {
+ return _character_count;
+ };
+
+ this.is_empty = function() {
+ return _empty;
+ };
+
+ this.last = function() {
+ if (!this._empty) {
+ return _items[_items.length - 1];
+ } else {
+ return null;
+ }
+ };
+
+ this.push = function(input) {
+ _items.push(input);
+ _character_count += input.length;
+ _empty = false;
+ };
+
+ this.pop = function() {
+ var item = null;
+ if (!_empty) {
+ item = _items.pop();
+ _character_count -= item.length;
+ _empty = _items.length === 0;
+ }
+ return item;
+ };
+
+ this.remove_indent = function() {
+ if (_indent_count > 0) {
+ _indent_count -= 1;
+ _character_count -= parent.indent_length;
+ }
+ };
+
+ this.trim = function() {
+ while (this.last() === ' ') {
+ _items.pop();
+ _character_count -= 1;
+ }
+ _empty = _items.length === 0;
+ };
+
+ this.toString = function() {
+ var result = '';
+ if (!this._empty) {
+ if (_indent_count >= 0) {
+ result = parent.indent_cache[_indent_count];
+ }
+ result += _items.join('');
+ }
+ return result;
+ };
+ }
+
+ function Output(indent_string, baseIndentString) {
+ baseIndentString = baseIndentString || '';
+ this.indent_cache = [baseIndentString];
+ this.baseIndentLength = baseIndentString.length;
+ this.indent_length = indent_string.length;
+ this.raw = false;
+
+ var lines = [];
+ this.baseIndentString = baseIndentString;
+ this.indent_string = indent_string;
+ this.previous_line = null;
+ this.current_line = null;
+ this.space_before_token = false;
+
+ this.add_outputline = function() {
+ this.previous_line = this.current_line;
+ this.current_line = new OutputLine(this);
+ lines.push(this.current_line);
+ };
+
+ // initialize
+ this.add_outputline();
+
+
+ this.get_line_number = function() {
+ return lines.length;
+ };
+
+ // Using object instead of string to allow for later expansion of info about each line
+ this.add_new_line = function(force_newline) {
+ if (this.get_line_number() === 1 && this.just_added_newline()) {
+ return false; // no newline on start of file
+ }
+
+ if (force_newline || !this.just_added_newline()) {
+ if (!this.raw) {
+ this.add_outputline();
+ }
+ return true;
+ }
+
+ return false;
+ };
+
+ this.get_code = function() {
+ var sweet_code = lines.join('\n').replace(/[\r\n\t ]+$/, '');
+ return sweet_code;
+ };
+
+ this.set_indent = function(level) {
+ // Never indent your first output indent at the start of the file
+ if (lines.length > 1) {
+ while (level >= this.indent_cache.length) {
+ this.indent_cache.push(this.indent_cache[this.indent_cache.length - 1] + this.indent_string);
+ }
+
+ this.current_line.set_indent(level);
+ return true;
+ }
+ this.current_line.set_indent(0);
+ return false;
+ };
+
+ this.add_raw_token = function(token) {
+ for (var x = 0; x < token.newlines; x++) {
+ this.add_outputline();
+ }
+ this.current_line.push(token.whitespace_before);
+ this.current_line.push(token.text);
+ this.space_before_token = false;
+ };
+
+ this.add_token = function(printable_token) {
+ this.add_space_before_token();
+ this.current_line.push(printable_token);
+ };
+
+ this.add_space_before_token = function() {
+ if (this.space_before_token && !this.just_added_newline()) {
+ this.current_line.push(' ');
+ }
+ this.space_before_token = false;
+ };
+
+ this.remove_redundant_indentation = function(frame) {
+ // This implementation is effective but has some issues:
+ // - can cause line wrap to happen too soon due to indent removal
+ // after wrap points are calculated
+ // These issues are minor compared to ugly indentation.
+
+ if (frame.multiline_frame ||
+ frame.mode === MODE.ForInitializer ||
+ frame.mode === MODE.Conditional) {
+ return;
+ }
+
+ // remove one indent from each line inside this section
+ var index = frame.start_line_index;
+
+ var output_length = lines.length;
+ while (index < output_length) {
+ lines[index].remove_indent();
+ index++;
+ }
+ };
+
+ this.trim = function(eat_newlines) {
+ eat_newlines = (eat_newlines === undefined) ? false : eat_newlines;
+
+ this.current_line.trim(indent_string, baseIndentString);
+
+ while (eat_newlines && lines.length > 1 &&
+ this.current_line.is_empty()) {
+ lines.pop();
+ this.current_line = lines[lines.length - 1];
+ this.current_line.trim();
+ }
+
+ this.previous_line = lines.length > 1 ? lines[lines.length - 2] : null;
+ };
+
+ this.just_added_newline = function() {
+ return this.current_line.is_empty();
+ };
+
+ this.just_added_blankline = function() {
+ if (this.just_added_newline()) {
+ if (lines.length === 1) {
+ return true; // start of the file and newline = blank
+ }
+
+ var line = lines[lines.length - 2];
+ return line.is_empty();
+ }
+ return false;
+ };
+ }
+
+
+ var Token = function(type, text, newlines, whitespace_before, parent) {
+ this.type = type;
+ this.text = text;
+ this.comments_before = [];
+ this.newlines = newlines || 0;
+ this.wanted_newline = newlines > 0;
+ this.whitespace_before = whitespace_before || '';
+ this.parent = parent || null;
+ this.opened = null;
+ this.directives = null;
+ };
+
+ function tokenizer(input, opts) {
+
+ var whitespace = "\n\r\t ".split('');
+ var digit = /[0-9]/;
+ var digit_bin = /[01]/;
+ var digit_oct = /[01234567]/;
+ var digit_hex = /[0123456789abcdefABCDEF]/;
+
+ this.positionable_operators = '!= !== % & && * ** + - / : < << <= == === > >= >> >>> ? ^ | ||'.split(' ');
+ var punct = this.positionable_operators.concat(
+ // non-positionable operators - these do not follow operator position settings
+ '! %= &= *= **= ++ += , -- -= /= :: <<= = => >>= >>>= ^= |= ~'.split(' '));
+
+ // words which should always start on new line.
+ this.line_starters = 'continue,try,throw,return,var,let,const,if,switch,case,default,for,while,break,function,import,export'.split(',');
+ var reserved_words = this.line_starters.concat(['do', 'in', 'else', 'get', 'set', 'new', 'catch', 'finally', 'typeof', 'yield', 'async', 'await', 'from', 'as']);
+
+ // /* ... */ comment ends with nearest */ or end of file
+ var block_comment_pattern = /([\s\S]*?)((?:\*\/)|$)/g;
+
+ // comment ends just before nearest linefeed or end of file
+ var comment_pattern = /([^\n\r\u2028\u2029]*)/g;
+
+ var directives_block_pattern = /\/\* beautify( \w+[:]\w+)+ \*\//g;
+ var directive_pattern = / (\w+)[:](\w+)/g;
+ var directives_end_ignore_pattern = /([\s\S]*?)((?:\/\*\sbeautify\signore:end\s\*\/)|$)/g;
+
+ var template_pattern = /((<\?php|<\?=)[\s\S]*?\?>)|(<%[\s\S]*?%>)/g;
+
+ var n_newlines, whitespace_before_token, in_html_comment, tokens, parser_pos;
+ var input_length;
+
+ this.tokenize = function() {
+ // cache the source's length.
+ input_length = input.length;
+ parser_pos = 0;
+ in_html_comment = false;
+ tokens = [];
+
+ var next, last;
+ var token_values;
+ var open = null;
+ var open_stack = [];
+ var comments = [];
+
+ while (!(last && last.type === 'TK_EOF')) {
+ token_values = tokenize_next();
+ next = new Token(token_values[1], token_values[0], n_newlines, whitespace_before_token);
+ while (next.type === 'TK_COMMENT' || next.type === 'TK_BLOCK_COMMENT' || next.type === 'TK_UNKNOWN') {
+ if (next.type === 'TK_BLOCK_COMMENT') {
+ next.directives = token_values[2];
+ }
+ comments.push(next);
+ token_values = tokenize_next();
+ next = new Token(token_values[1], token_values[0], n_newlines, whitespace_before_token);
+ }
+
+ if (comments.length) {
+ next.comments_before = comments;
+ comments = [];
+ }
+
+ if (next.type === 'TK_START_BLOCK' || next.type === 'TK_START_EXPR') {
+ next.parent = last;
+ open_stack.push(open);
+ open = next;
+ } else if ((next.type === 'TK_END_BLOCK' || next.type === 'TK_END_EXPR') &&
+ (open && (
+ (next.text === ']' && open.text === '[') ||
+ (next.text === ')' && open.text === '(') ||
+ (next.text === '}' && open.text === '{')))) {
+ next.parent = open.parent;
+ next.opened = open;
+
+ open = open_stack.pop();
+ }
+
+ tokens.push(next);
+ last = next;
+ }
+
+ return tokens;
+ };
+
+ function get_directives(text) {
+ if (!text.match(directives_block_pattern)) {
+ return null;
+ }
+
+ var directives = {};
+ directive_pattern.lastIndex = 0;
+ var directive_match = directive_pattern.exec(text);
+
+ while (directive_match) {
+ directives[directive_match[1]] = directive_match[2];
+ directive_match = directive_pattern.exec(text);
+ }
+
+ return directives;
+ }
+
+ function tokenize_next() {
+ var resulting_string;
+ var whitespace_on_this_line = [];
+
+ n_newlines = 0;
+ whitespace_before_token = '';
+
+ if (parser_pos >= input_length) {
+ return ['', 'TK_EOF'];
+ }
+
+ var last_token;
+ if (tokens.length) {
+ last_token = tokens[tokens.length - 1];
+ } else {
+ // For the sake of tokenizing we can pretend that there was on open brace to start
+ last_token = new Token('TK_START_BLOCK', '{');
+ }
+
+
+ var c = input.charAt(parser_pos);
+ parser_pos += 1;
+
+ while (in_array(c, whitespace)) {
+
+ if (acorn.newline.test(c)) {
+ if (!(c === '\n' && input.charAt(parser_pos - 2) === '\r')) {
+ n_newlines += 1;
+ whitespace_on_this_line = [];
+ }
+ } else {
+ whitespace_on_this_line.push(c);
+ }
+
+ if (parser_pos >= input_length) {
+ return ['', 'TK_EOF'];
+ }
+
+ c = input.charAt(parser_pos);
+ parser_pos += 1;
+ }
+
+ if (whitespace_on_this_line.length) {
+ whitespace_before_token = whitespace_on_this_line.join('');
+ }
+
+ if (digit.test(c) || (c === '.' && digit.test(input.charAt(parser_pos)))) {
+ var allow_decimal = true;
+ var allow_e = true;
+ var local_digit = digit;
+
+ if (c === '0' && parser_pos < input_length && /[XxOoBb]/.test(input.charAt(parser_pos))) {
+ // switch to hex/oct/bin number, no decimal or e, just hex/oct/bin digits
+ allow_decimal = false;
+ allow_e = false;
+ if (/[Bb]/.test(input.charAt(parser_pos))) {
+ local_digit = digit_bin;
+ } else if (/[Oo]/.test(input.charAt(parser_pos))) {
+ local_digit = digit_oct;
+ } else {
+ local_digit = digit_hex;
+ }
+ c += input.charAt(parser_pos);
+ parser_pos += 1;
+ } else if (c === '.') {
+ // Already have a decimal for this literal, don't allow another
+ allow_decimal = false;
+ } else {
+ // we know this first loop will run. It keeps the logic simpler.
+ c = '';
+ parser_pos -= 1;
+ }
+
+ // Add the digits
+ while (parser_pos < input_length && local_digit.test(input.charAt(parser_pos))) {
+ c += input.charAt(parser_pos);
+ parser_pos += 1;
+
+ if (allow_decimal && parser_pos < input_length && input.charAt(parser_pos) === '.') {
+ c += input.charAt(parser_pos);
+ parser_pos += 1;
+ allow_decimal = false;
+ } else if (allow_e && parser_pos < input_length && /[Ee]/.test(input.charAt(parser_pos))) {
+ c += input.charAt(parser_pos);
+ parser_pos += 1;
+
+ if (parser_pos < input_length && /[+-]/.test(input.charAt(parser_pos))) {
+ c += input.charAt(parser_pos);
+ parser_pos += 1;
+ }
+
+ allow_e = false;
+ allow_decimal = false;
+ }
+ }
+
+ return [c, 'TK_WORD'];
+ }
+
+ if (acorn.isIdentifierStart(input.charCodeAt(parser_pos - 1))) {
+ if (parser_pos < input_length) {
+ while (acorn.isIdentifierChar(input.charCodeAt(parser_pos))) {
+ c += input.charAt(parser_pos);
+ parser_pos += 1;
+ if (parser_pos === input_length) {
+ break;
+ }
+ }
+ }
+
+ if (!(last_token.type === 'TK_DOT' ||
+ (last_token.type === 'TK_RESERVED' && in_array(last_token.text, ['set', 'get']))) &&
+ in_array(c, reserved_words)) {
+ if (c === 'in') { // hack for 'in' operator
+ return [c, 'TK_OPERATOR'];
+
<TRUNCATED>
[2/5] nifi git commit: NIFI-1850 - Initial Commit for JSON-to-JSON
Schema Converter Editor (merge from 0.7.0 - refactor for masterless cluster).
This closes #511
Posted by mc...@apache.org.
http://git-wip-us.apache.org/repos/asf/nifi/blob/cb3aa8f5/nifi-nar-bundles/nifi-standard-bundle/nifi-jolt-transform-json-ui/src/test/java/org/apache/nifi/web/standard/api/processor/TestProcessorResource.java
----------------------------------------------------------------------
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-jolt-transform-json-ui/src/test/java/org/apache/nifi/web/standard/api/processor/TestProcessorResource.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-jolt-transform-json-ui/src/test/java/org/apache/nifi/web/standard/api/processor/TestProcessorResource.java
new file mode 100644
index 0000000..4bb39de
--- /dev/null
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-jolt-transform-json-ui/src/test/java/org/apache/nifi/web/standard/api/processor/TestProcessorResource.java
@@ -0,0 +1,148 @@
+/*
+ * 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.web.standard.api.processor;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.ext.Provider;
+
+import org.apache.nifi.web.ComponentDescriptor;
+import org.apache.nifi.web.ComponentDetails;
+import org.apache.nifi.web.NiFiWebConfigurationContext;
+import org.apache.nifi.web.NiFiWebConfigurationRequestContext;
+import org.apache.nifi.web.NiFiWebRequestContext;
+
+
+import org.codehaus.jettison.json.JSONException;
+import org.codehaus.jettison.json.JSONObject;
+import org.junit.Test;
+import org.mockito.Mockito;
+
+import com.bazaarvoice.jolt.JsonUtils;
+import com.sun.jersey.api.client.ClientResponse;
+import com.sun.jersey.api.core.ClassNamesResourceConfig;
+import com.sun.jersey.spi.container.servlet.WebComponent;
+import com.sun.jersey.spi.inject.SingletonTypeInjectableProvider;
+import com.sun.jersey.test.framework.AppDescriptor;
+import com.sun.jersey.test.framework.JerseyTest;
+import com.sun.jersey.test.framework.WebAppDescriptor;
+import com.sun.jersey.test.framework.spi.container.TestContainerFactory;
+import com.sun.jersey.test.framework.spi.container.inmemory.InMemoryTestContainerFactory;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.mock;
+
+public class TestProcessorResource extends JerseyTest {
+
+ public static final ServletContext servletContext = mock(ServletContext.class);
+ public static final HttpServletRequest requestContext = mock(HttpServletRequest.class);
+
+ @Override
+ protected AppDescriptor configure() {
+ return new WebAppDescriptor.Builder()
+ .initParam(WebComponent.RESOURCE_CONFIG_CLASS, ClassNamesResourceConfig.class.getName())
+ .initParam(ClassNamesResourceConfig.PROPERTY_CLASSNAMES,
+ ProcessorResource.class.getName() +
+ ";" + TestProcessorResource.MockServletContext.class.getName() +
+ ";" + TestProcessorResource.MockRequestContext.class.getName()+";")
+ .initParam("com.sun.jersey.api.json.POJOMappingFeature", "true")
+ .build();
+ }
+
+ @Override
+ public TestContainerFactory getTestContainerFactory() {
+ return new InMemoryTestContainerFactory();
+ }
+
+
+ @Test
+ public void testSetProperties() throws JSONException{
+
+ final NiFiWebConfigurationContext niFiWebConfigurationContext = mock(NiFiWebConfigurationContext.class);
+ final Map<String,String> properties = new HashMap<>();
+ properties.put("jolt-transform","jolt-transform-chain");
+ final ComponentDetails componentDetails = new ComponentDetails.Builder().properties(properties).build();
+
+ Mockito.when(servletContext.getAttribute(Mockito.anyString())).thenReturn(niFiWebConfigurationContext);
+ Mockito.when(niFiWebConfigurationContext.updateComponent(any(NiFiWebConfigurationRequestContext.class),any(String.class),any(Map.class))).thenReturn(componentDetails);
+
+ ClientResponse response = client().resource(getBaseURI()).path("/standard/processor/properties")
+ .queryParam("processorId","1")
+ .queryParam("clientId","1")
+ .queryParam("revisionId","1")
+ .type(MediaType.APPLICATION_JSON_TYPE)
+ .put(ClientResponse.class,JsonUtils.toJsonString(properties));
+ assertNotNull(response);
+ JSONObject jsonObject = response.getEntity(JSONObject.class);
+ assertNotNull(jsonObject);
+ assertTrue(jsonObject.getJSONObject("properties").get("jolt-transform").equals("jolt-transform-chain"));
+ }
+
+
+ @Test
+ public void testGetProcessorDetails() {
+ final NiFiWebConfigurationContext niFiWebConfigurationContext = mock(NiFiWebConfigurationContext.class);
+ final Map<String,String> allowableValues = new HashMap<>();
+ final ComponentDescriptor descriptor = new ComponentDescriptor.Builder().name("test-name").allowableValues(allowableValues).build();
+ final Map<String,ComponentDescriptor> descriptors = new HashMap<>();
+ descriptors.put("jolt-transform",descriptor);
+ final ComponentDetails componentDetails = new ComponentDetails.Builder().name("mytransform").type("org.apache.nifi.processors.standard.JoltTransformJSON")
+ .descriptors(descriptors)
+ .build();
+
+ Mockito.when(servletContext.getAttribute(Mockito.anyString())).thenReturn(niFiWebConfigurationContext);
+ Mockito.when(niFiWebConfigurationContext.getComponentDetails(any(NiFiWebRequestContext.class))).thenReturn(componentDetails);
+
+ JSONObject value = client().resource(getBaseURI()).path("/standard/processor/details").queryParam("processorId","1").get(JSONObject.class);
+ assertNotNull(value);
+
+ try{
+ assertTrue(value.get("name").equals("mytransform"));
+ } catch (Exception e){
+ fail("Failed due to: " + e.toString());
+ }
+
+ }
+
+ @Provider
+ public static class MockServletContext extends SingletonTypeInjectableProvider<Context, ServletContext> {
+
+ public MockServletContext(){
+ super(ServletContext.class, servletContext);
+ }
+
+ }
+
+ @Provider
+ public static class MockRequestContext extends SingletonTypeInjectableProvider<Context, HttpServletRequest> {
+
+ public MockRequestContext(){
+ super(HttpServletRequest.class, requestContext);
+ }
+
+ }
+
+
+}
http://git-wip-us.apache.org/repos/asf/nifi/blob/cb3aa8f5/nifi-nar-bundles/nifi-standard-bundle/nifi-jolt-transform-json-ui/src/test/java/org/apache/nifi/web/standard/api/processor/TestProcessorWebUtils.java
----------------------------------------------------------------------
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-jolt-transform-json-ui/src/test/java/org/apache/nifi/web/standard/api/processor/TestProcessorWebUtils.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-jolt-transform-json-ui/src/test/java/org/apache/nifi/web/standard/api/processor/TestProcessorWebUtils.java
new file mode 100644
index 0000000..87a058f
--- /dev/null
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-jolt-transform-json-ui/src/test/java/org/apache/nifi/web/standard/api/processor/TestProcessorWebUtils.java
@@ -0,0 +1,94 @@
+/*
+ * 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.web.standard.api.processor;
+
+
+import java.io.IOException;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.core.CacheControl;
+import javax.ws.rs.core.Response;
+
+import org.apache.nifi.web.ComponentDetails;
+import org.apache.nifi.web.HttpServletConfigurationRequestContext;
+import org.apache.nifi.web.HttpServletRequestContext;
+import org.apache.nifi.web.NiFiWebConfigurationContext;
+import org.apache.nifi.web.NiFiWebRequestContext;
+import org.apache.nifi.web.standard.api.processor.ProcessorWebUtils;
+import org.junit.Test;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+
+public class TestProcessorWebUtils {
+
+ @Test
+ public void testGetComponentDetailsForProcessor(){
+ HttpServletRequest request = mock(HttpServletRequest.class);
+ NiFiWebConfigurationContext configurationContext = mock(NiFiWebConfigurationContext.class);
+ when(configurationContext.getComponentDetails(any(HttpServletRequestContext.class))).thenReturn(new ComponentDetails.Builder().build());
+ ComponentDetails componentDetails = ProcessorWebUtils.getComponentDetails(configurationContext,"1",request);
+ assertNotNull(componentDetails);
+
+ }
+
+ @Test
+ public void testGetComponentDetailsForProcessorWithSpecificClientRevision(){
+ NiFiWebConfigurationContext configurationContext = mock(NiFiWebConfigurationContext.class);
+ when(configurationContext.getComponentDetails(any(HttpServletConfigurationRequestContext.class))).thenReturn(new ComponentDetails.Builder().build());
+ ComponentDetails componentDetails = ProcessorWebUtils.getComponentDetails(configurationContext,"1",1L, "client1",mock(HttpServletRequest.class));
+ assertNotNull(componentDetails);
+ }
+
+ @Test
+ public void testApplyCacheControl(){
+ Response.ResponseBuilder response = mock(Response.ResponseBuilder.class);
+ ProcessorWebUtils.applyCacheControl(response);
+ verify(response).cacheControl(any(CacheControl.class));
+ }
+
+ @Test
+ @SuppressWarnings("unchecked")
+ public void testGetRequestContextForProcessor() throws NoSuchMethodException, IOException,InvocationTargetException, IllegalAccessException{
+ Method method = ProcessorWebUtils.class.getDeclaredMethod("getRequestContext", String.class, HttpServletRequest.class);
+ method.setAccessible(true);
+ NiFiWebRequestContext requestContext = (NiFiWebRequestContext) method.invoke(null,"1",mock(HttpServletRequest.class));
+ assertTrue(requestContext instanceof HttpServletRequestContext);
+ assertTrue(requestContext.getId().equals("1"));
+
+ }
+
+ @Test
+ @SuppressWarnings("unchecked")
+ public void testGetRequestContextForProcessorWithSpecificClientRevision() throws NoSuchMethodException, IOException,InvocationTargetException, IllegalAccessException{
+ Method method = ProcessorWebUtils.class.getDeclaredMethod("getRequestContext", String.class, Long.class, String.class, HttpServletRequest.class);
+ method.setAccessible(true);
+ NiFiWebRequestContext requestContext = (NiFiWebRequestContext) method.invoke(null,"1",1L, "client1",mock(HttpServletRequest.class));
+ assertTrue(requestContext instanceof HttpServletConfigurationRequestContext);
+ assertTrue(requestContext.getId().equals("1"));
+ assertTrue(((HttpServletConfigurationRequestContext)requestContext).getRevision().getClientId().equals("client1"));
+ assertTrue(((HttpServletConfigurationRequestContext)requestContext).getRevision().getVersion().equals(1L));
+ }
+
+
+}
http://git-wip-us.apache.org/repos/asf/nifi/blob/cb3aa8f5/nifi-nar-bundles/nifi-standard-bundle/nifi-jolt-transform-json-ui/src/test/java/org/apache/nifi/web/standard/api/transformjson/TestTransformJSONResource.java
----------------------------------------------------------------------
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-jolt-transform-json-ui/src/test/java/org/apache/nifi/web/standard/api/transformjson/TestTransformJSONResource.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-jolt-transform-json-ui/src/test/java/org/apache/nifi/web/standard/api/transformjson/TestTransformJSONResource.java
new file mode 100644
index 0000000..ba00a15
--- /dev/null
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-jolt-transform-json-ui/src/test/java/org/apache/nifi/web/standard/api/transformjson/TestTransformJSONResource.java
@@ -0,0 +1,178 @@
+/*
+ * 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.web.standard.api.transformjson;
+
+import junit.framework.TestCase;
+
+import java.util.HashMap;
+import java.util.Map;
+
+
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.ext.Provider;
+
+
+import org.apache.nifi.web.ComponentDetails;
+import org.apache.nifi.web.NiFiWebConfigurationContext;
+import org.apache.nifi.web.NiFiWebRequestContext;
+import org.apache.nifi.web.standard.api.transformjson.dto.JoltSpecificationDTO;
+import org.apache.nifi.web.standard.api.transformjson.dto.ValidationDTO;
+
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.mockito.Mockito;
+
+
+import com.bazaarvoice.jolt.Diffy;
+import com.bazaarvoice.jolt.JsonUtils;
+import com.sun.jersey.api.client.UniformInterfaceException;
+import com.sun.jersey.api.core.ClassNamesResourceConfig;
+
+
+import com.sun.jersey.spi.container.servlet.WebComponent;
+import com.sun.jersey.spi.inject.SingletonTypeInjectableProvider;
+import com.sun.jersey.test.framework.AppDescriptor;
+import com.sun.jersey.test.framework.JerseyTest;
+import com.sun.jersey.test.framework.WebAppDescriptor;
+import com.sun.jersey.test.framework.spi.container.TestContainerFactory;
+import com.sun.jersey.test.framework.spi.container.inmemory.InMemoryTestContainerFactory;
+
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.mock;
+
+
+public class TestTransformJSONResource extends JerseyTest {
+
+ @Rule
+ public final ExpectedException exception = ExpectedException.none();
+
+ public static final ServletContext servletContext = mock(ServletContext.class);
+ public static final HttpServletRequest requestContext = mock(HttpServletRequest.class);
+
+ @Override
+ protected AppDescriptor configure() {
+ return new WebAppDescriptor.Builder()
+ .initParam(WebComponent.RESOURCE_CONFIG_CLASS, ClassNamesResourceConfig.class.getName())
+ .initParam(ClassNamesResourceConfig.PROPERTY_CLASSNAMES,
+ TransformJSONResource.class.getName() + ";" + MockServletContext.class.getName() + ";" + MockRequestContext.class.getName()+";")
+ .initParam("com.sun.jersey.api.json.POJOMappingFeature", "true")
+ .build();
+ }
+
+ @Override
+ public TestContainerFactory getTestContainerFactory() {
+ return new InMemoryTestContainerFactory();
+ }
+
+
+ @Test
+ public void testValidateWithInvalidSpec() {
+
+ final NiFiWebConfigurationContext niFiWebConfigurationContext = mock(NiFiWebConfigurationContext.class);
+ final Map<String,String> properties = new HashMap<>();
+ properties.put("jolt-transform","jolt-transform-chain");
+ final ComponentDetails componentDetails = new ComponentDetails.Builder().properties(properties).build();
+ Mockito.when(servletContext.getAttribute(Mockito.anyString())).thenReturn(niFiWebConfigurationContext);
+ Mockito.when(niFiWebConfigurationContext.getComponentDetails(any(NiFiWebRequestContext.class))).thenReturn(componentDetails);
+
+ JoltSpecificationDTO joltSpecificationDTO = new JoltSpecificationDTO("jolt-transform-chain","[]");
+ ValidationDTO validate = client().resource(getBaseURI()).path("/standard/transformjson/validate").post(ValidationDTO.class, joltSpecificationDTO);
+
+ assertNotNull(validate);
+ assertTrue(!validate.isValid());
+
+ }
+
+ @Test
+ public void testValidateWithValidSpec() {
+ JoltSpecificationDTO joltSpecificationDTO = new JoltSpecificationDTO("jolt-transform-remove","{\"rating\": {\"quality\": \"\"} }");
+ ValidationDTO validation = client().resource(getBaseURI()).path("/standard/transformjson/validate").post(ValidationDTO.class, joltSpecificationDTO);
+ TestCase.assertNotNull(validation);
+ assertTrue(validation.isValid());
+ }
+
+ @Test
+ public void testValidateWithValidEmptySpec() {
+ JoltSpecificationDTO joltSpecificationDTO = new JoltSpecificationDTO("jolt-transform-sort","");
+ ValidationDTO validation = client().resource(getBaseURI()).path("/standard/transformjson/validate").post(ValidationDTO.class, joltSpecificationDTO);
+ TestCase.assertNotNull(validation);
+ assertTrue(validation.isValid());
+ }
+
+ @Test
+ public void testValidateWithInvalidEmptySpec() {
+ JoltSpecificationDTO joltSpecificationDTO = new JoltSpecificationDTO("jolt-transform-remove","");
+ ValidationDTO validation = client().resource(getBaseURI()).path("/standard/transformjson/validate").post(ValidationDTO.class, joltSpecificationDTO);
+ TestCase.assertNotNull(validation);
+ assertTrue(!validation.isValid());
+ }
+
+ @Test
+ public void testValidateWithValidNullSpec() {
+ JoltSpecificationDTO joltSpecificationDTO = new JoltSpecificationDTO("jolt-transform-sort",null);
+ ValidationDTO validation = client().resource(getBaseURI()).path("/standard/transformjson/validate").post(ValidationDTO.class, joltSpecificationDTO);
+ TestCase.assertNotNull(validation);
+ assertTrue(validation.isValid());
+ }
+
+
+ @Test
+ public void testExecuteWithInvalidSpec() {
+ JoltSpecificationDTO joltSpecificationDTO = new JoltSpecificationDTO("jolt-transform-remove", "{\"rating\": {\"quality\": \"\"} }");
+ exception.expect(UniformInterfaceException.class);
+ client().resource(getBaseURI()).path("/standard/transformjson/execute").post(joltSpecificationDTO);
+ }
+
+ @Test
+ public void testExecuteWithValidSpec() {
+ final Diffy diffy = new Diffy();
+ JoltSpecificationDTO joltSpecificationDTO = new JoltSpecificationDTO("jolt-transform-remove","{\"rating\": {\"quality\": \"\"} }");
+ String inputJson = "{\"rating\":{\"quality\":2,\"count\":1}}";
+ joltSpecificationDTO.setInput(inputJson);
+ String responseString = client().resource(getBaseURI()).path("/standard/transformjson/execute").post(String.class, joltSpecificationDTO);
+ Object transformedJson = JsonUtils.jsonToObject(responseString);
+ Object compareJson = JsonUtils.jsonToObject("{\"rating\":{\"count\":1}}");
+ assertNotNull(transformedJson);
+ assertTrue(diffy.diff(compareJson, transformedJson).isEmpty());
+ }
+
+ @Provider
+ public static class MockServletContext extends SingletonTypeInjectableProvider<Context, ServletContext> {
+
+ public MockServletContext(){
+ super(ServletContext.class, servletContext);
+ }
+
+ }
+
+ @Provider
+ public static class MockRequestContext extends SingletonTypeInjectableProvider<Context, HttpServletRequest> {
+
+ public MockRequestContext(){
+ super(HttpServletRequest.class, requestContext);
+ }
+
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/nifi/blob/cb3aa8f5/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-nar/pom.xml
----------------------------------------------------------------------
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-nar/pom.xml b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-nar/pom.xml
index e95b071..03bbaba 100644
--- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-nar/pom.xml
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-nar/pom.xml
@@ -49,5 +49,10 @@
<artifactId>nifi-standard-content-viewer</artifactId>
<type>war</type>
</dependency>
+ <dependency>
+ <groupId>org.apache.nifi</groupId>
+ <artifactId>nifi-jolt-transform-json-ui</artifactId>
+ <type>war</type>
+ </dependency>
</dependencies>
</project>
http://git-wip-us.apache.org/repos/asf/nifi/blob/cb3aa8f5/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-nar/src/main/resources/META-INF/LICENSE
----------------------------------------------------------------------
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-nar/src/main/resources/META-INF/LICENSE b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-nar/src/main/resources/META-INF/LICENSE
index 18c9df1..32b25cf 100644
--- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-nar/src/main/resources/META-INF/LICENSE
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-nar/src/main/resources/META-INF/LICENSE
@@ -350,4 +350,72 @@ This product bundles 'Jolt' which is available under an Apache License. For deta
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.
\ No newline at end of file
+ limitations under the License.
+
+This product bundles 'AngularUI Codemirror' which is available under an MIT license.
+
+ Copyright (c) 2012 the AngularUI Team, http://angular-ui.github.com
+
+ Permission is hereby granted, free of charge, to any person obtaining a copy
+ of this software and associated documentation files (the "Software"), to deal
+ in the Software without restriction, including without limitation the rights
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ copies of the Software, and to permit persons to whom the Software is
+ furnished to do so, subject to the following conditions:
+
+ The above copyright notice and this permission notice shall be included in
+ all copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ THE SOFTWARE.
+
+This product bundles 'AngularUI Router' which is available under an MIT license.
+
+ Copyright (c) 2013-2015 The AngularUI Team, Karsten Sperling
+
+ Permission is hereby granted, free of charge, to any person obtaining a copy
+ of this software and associated documentation files (the "Software"), to deal
+ in the Software without restriction, including without limitation the rights
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ copies of the Software, and to permit persons to whom the Software is
+ furnished to do so, subject to the following conditions:
+
+ The above copyright notice and this permission notice shall be included in
+ all copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ THE SOFTWARE.
+
+This product bundles 'js-beautify' which is available under an MIT license.
+
+ Copyright (c) 2007-2013 Einar Lielmanis and contributors.
+
+ Permission is hereby granted, free of charge, to any person obtaining a copy
+ of this software and associated documentation files (the "Software"), to deal
+ in the Software without restriction, including without limitation the rights
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ copies of the Software, and to permit persons to whom the Software is
+ furnished to do so, subject to the following conditions:
+
+ The above copyright notice and this permission notice shall be included in
+ all copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ THE SOFTWARE.
+
+
http://git-wip-us.apache.org/repos/asf/nifi/blob/cb3aa8f5/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/pom.xml
----------------------------------------------------------------------
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/pom.xml b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/pom.xml
index 17e630a..247eff2 100644
--- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/pom.xml
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/pom.xml
@@ -235,6 +235,16 @@ language governing permissions and limitations under the License. -->
<artifactId>json-utils</artifactId>
<version>0.0.20</version>
</dependency>
+ <dependency>
+ <groupId>org.apache.nifi</groupId>
+ <artifactId>nifi-standard-utils</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.nifi</groupId>
+ <artifactId>nifi-standard-utils</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
+ </dependency>
</dependencies>
<build>
@@ -309,20 +319,20 @@ language governing permissions and limitations under the License. -->
<exclude>src/test/resources/TestSplitText/4.txt</exclude>
<exclude>src/test/resources/TestSplitText/5.txt</exclude>
<exclude>src/test/resources/TestSplitText/6.txt</exclude>
- <exclude>src/test/resources/TestTransformJson/input.json</exclude>
- <exclude>src/test/resources/TestTransformJson/chainrSpec.json</exclude>
- <exclude>src/test/resources/TestTransformJson/chainrOutput.json</exclude>
- <exclude>src/test/resources/TestTransformJson/cardrSpec.json</exclude>
- <exclude>src/test/resources/TestTransformJson/cardrOutput.json</exclude>
- <exclude>src/test/resources/TestTransformJson/defaultrSpec.json</exclude>
- <exclude>src/test/resources/TestTransformJson/defaultrOutput.json</exclude>
- <exclude>src/test/resources/TestTransformJson/shiftrSpec.json</exclude>
- <exclude>src/test/resources/TestTransformJson/sortrOutput.json</exclude>
- <exclude>src/test/resources/TestTransformJson/shiftrOutput.json</exclude>
- <exclude>src/test/resources/TestTransformJson/removrSpec.json</exclude>
- <exclude>src/test/resources/TestTransformJson/removrOutput.json</exclude>
- <exclude>src/test/resources/TestTransformJson/defaultrSpec.json</exclude>
- <exclude>src/test/resources/TestTransformJson/defaultrOutput.json</exclude>
+ <exclude>src/test/resources/TestJoltTransformJson/input.json</exclude>
+ <exclude>src/test/resources/TestJoltTransformJson/chainrSpec.json</exclude>
+ <exclude>src/test/resources/TestJoltTransformJson/chainrOutput.json</exclude>
+ <exclude>src/test/resources/TestJoltTransformJson/cardrSpec.json</exclude>
+ <exclude>src/test/resources/TestJoltTransformJson/cardrOutput.json</exclude>
+ <exclude>src/test/resources/TestJoltTransformJson/defaultrSpec.json</exclude>
+ <exclude>src/test/resources/TestJoltTransformJson/defaultrOutput.json</exclude>
+ <exclude>src/test/resources/TestJoltTransformJson/shiftrSpec.json</exclude>
+ <exclude>src/test/resources/TestJoltTransformJson/sortrOutput.json</exclude>
+ <exclude>src/test/resources/TestJoltTransformJson/shiftrOutput.json</exclude>
+ <exclude>src/test/resources/TestJoltTransformJson/removrSpec.json</exclude>
+ <exclude>src/test/resources/TestJoltTransformJson/removrOutput.json</exclude>
+ <exclude>src/test/resources/TestJoltTransformJson/defaultrSpec.json</exclude>
+ <exclude>src/test/resources/TestJoltTransformJson/defaultrOutput.json</exclude>
<exclude>src/test/resources/TestSplitText/original.txt</exclude>
<exclude>src/test/resources/TestTransformXml/math.html</exclude>
<exclude>src/test/resources/TestTransformXml/tokens.csv</exclude>
http://git-wip-us.apache.org/repos/asf/nifi/blob/cb3aa8f5/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/JoltTransformJSON.java
----------------------------------------------------------------------
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/JoltTransformJSON.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/JoltTransformJSON.java
new file mode 100644
index 0000000..3406b1f
--- /dev/null
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/JoltTransformJSON.java
@@ -0,0 +1,223 @@
+/*
+ * 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 java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+import java.util.concurrent.TimeUnit;
+
+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.documentation.CapabilityDescription;
+import org.apache.nifi.annotation.documentation.Tags;
+import org.apache.nifi.annotation.lifecycle.OnScheduled;
+import org.apache.nifi.components.AllowableValue;
+import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.components.ValidationContext;
+import org.apache.nifi.components.ValidationResult;
+import org.apache.nifi.flowfile.FlowFile;
+import org.apache.nifi.flowfile.attributes.CoreAttributes;
+import org.apache.nifi.logging.ComponentLog;
+import org.apache.nifi.processor.AbstractProcessor;
+import org.apache.nifi.processor.ProcessContext;
+import org.apache.nifi.processor.ProcessSession;
+import org.apache.nifi.processor.Relationship;
+import org.apache.nifi.processor.exception.ProcessException;
+import org.apache.nifi.processor.io.InputStreamCallback;
+import org.apache.nifi.processor.io.OutputStreamCallback;
+import org.apache.nifi.processor.util.StandardValidators;
+import org.apache.nifi.processors.standard.util.TransformFactory;
+import org.apache.nifi.stream.io.ByteArrayInputStream;
+import org.apache.nifi.stream.io.StreamUtils;
+import org.apache.nifi.util.StopWatch;
+import org.apache.nifi.util.StringUtils;
+
+import com.bazaarvoice.jolt.Transform;
+import com.bazaarvoice.jolt.JsonUtils;
+
+@EventDriven
+@SideEffectFree
+@SupportsBatching
+@Tags({"json", "jolt", "transform", "shiftr", "chainr", "defaultr", "removr","cardinality","sort"})
+@InputRequirement(InputRequirement.Requirement.INPUT_REQUIRED)
+@WritesAttribute(attribute = "mime.type",description = "Always set to application/json")
+@CapabilityDescription("Applies a list of Jolt specifications to the flowfile JSON payload. A new FlowFile is created "
+ + "with transformed content and is routed to the 'success' relationship. If the JSON transform "
+ + "fails, the original FlowFile is routed to the 'failure' relationship.")
+public class JoltTransformJSON extends AbstractProcessor {
+
+ public static final AllowableValue SHIFTR = new AllowableValue("jolt-transform-shift", "Shift", "Shift input JSON/data to create the output JSON.");
+ public static final AllowableValue CHAINR = new AllowableValue("jolt-transform-chain", "Chain", "Execute list of Jolt transformations.");
+ public static final AllowableValue DEFAULTR = new AllowableValue("jolt-transform-default", "Default", " Apply default values to the output JSON.");
+ public static final AllowableValue REMOVR = new AllowableValue("jolt-transform-remove", "Remove", " Remove values from input data to create the output JSON.");
+ public static final AllowableValue CARDINALITY = new AllowableValue("jolt-transform-card", "Cardinality", "Change the cardinality of input elements to create the output JSON.");
+ public static final AllowableValue SORTR = new AllowableValue("jolt-transform-sort", "Sort", "Sort input json key values alphabetically. Any specification set is ignored.");
+
+ public static final PropertyDescriptor JOLT_TRANSFORM = new PropertyDescriptor.Builder()
+ .name("jolt-transform")
+ .displayName("Jolt Transformation DSL")
+ .description("Specifies the Jolt Transformation that should be used with the provided specification.")
+ .required(true)
+ .allowableValues(CARDINALITY, CHAINR, DEFAULTR, REMOVR, SHIFTR, SORTR)
+ .defaultValue(CHAINR.getValue())
+ .build();
+
+ public static final PropertyDescriptor JOLT_SPEC = new PropertyDescriptor.Builder()
+ .name("jolt-spec")
+ .displayName("Jolt Specification")
+ .description("Jolt Specification for transform of JSON data. This value is ignored if the Jolt Sort Transformation is selected.")
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .required(false)
+ .build();
+
+ public static final Relationship REL_SUCCESS = new Relationship.Builder()
+ .name("success")
+ .description("The FlowFile with transformed content will be routed to this relationship")
+ .build();
+ public static final Relationship REL_FAILURE = new Relationship.Builder()
+ .name("failure")
+ .description("If a FlowFile fails processing for any reason (for example, the FlowFile is not valid JSON), it will be routed to this relationship")
+ .build();
+
+ private final static List<PropertyDescriptor> properties;
+ private final static Set<Relationship> relationships;
+ private volatile Transform transform;
+ private final static String DEFAULT_CHARSET = "UTF-8";
+
+ static{
+
+ final List<PropertyDescriptor> _properties = new ArrayList<>();
+ _properties.add(JOLT_TRANSFORM);
+ _properties.add(JOLT_SPEC);
+ properties = Collections.unmodifiableList(_properties);
+
+ final Set<Relationship> _relationships = new HashSet<>();
+ _relationships.add(REL_SUCCESS);
+ _relationships.add(REL_FAILURE);
+ relationships = Collections.unmodifiableSet(_relationships);
+
+ }
+
+ @Override
+ public Set<Relationship> getRelationships() {
+ return relationships;
+ }
+
+ @Override
+ protected List<PropertyDescriptor> getSupportedPropertyDescriptors() {
+ return properties;
+ }
+
+
+ @Override
+ protected Collection<ValidationResult> customValidate(ValidationContext validationContext) {
+ final List<ValidationResult> results = new ArrayList<>(super.customValidate(validationContext));
+ String transform = validationContext.getProperty(JOLT_TRANSFORM).getValue();
+ String specValue = validationContext.getProperty(JOLT_SPEC).isSet() ? validationContext.getProperty(JOLT_SPEC).getValue() : null;
+
+ if(StringUtils.isEmpty(specValue)){
+ if(!SORTR.getValue().equals(transform)) {
+ String message = "A specification is required for this transformation";
+ results.add(new ValidationResult.Builder().valid(false)
+ .explanation(message)
+ .build());
+ }
+ } else {
+ try {
+ Object specJson = SORTR.getValue().equals(transform) ? null : JsonUtils.jsonToObject(specValue, DEFAULT_CHARSET);
+ TransformFactory.getTransform(transform, specJson);
+ } catch (final Exception e) {
+ getLogger().info("Processor is not valid - " + e.toString());
+ String message = "Specification not valid for the selected transformation." ;
+ results.add(new ValidationResult.Builder().valid(false)
+ .explanation(message)
+ .build());
+ }
+ }
+ return results;
+ }
+
+ @Override
+ public void onTrigger(final ProcessContext context, ProcessSession session) throws ProcessException {
+
+ final FlowFile original = session.get();
+ if (original == null) {
+ return;
+ }
+
+ final ComponentLog logger = getLogger();
+ final StopWatch stopWatch = new StopWatch(true);
+
+ final byte[] originalContent = new byte[(int) original.getSize()];
+ session.read(original, new InputStreamCallback() {
+ @Override
+ public void process(final InputStream in) throws IOException {
+ StreamUtils.fillBuffer(in, originalContent, true);
+ }
+ });
+
+ final String jsonString;
+
+ try {
+ final ByteArrayInputStream bais = new ByteArrayInputStream(originalContent);
+ final Object inputJson = JsonUtils.jsonToObject(bais);
+ final Object transformedJson = transform.transform(inputJson);
+ jsonString = JsonUtils.toJsonString(transformedJson);
+
+ } catch (RuntimeException re) {
+ logger.error("Unable to transform {} due to {}", new Object[]{original, re});
+ session.transfer(original, REL_FAILURE);
+ return;
+ }
+
+ FlowFile transformed = session.write(original, new OutputStreamCallback() {
+ @Override
+ public void process(OutputStream out) throws IOException {
+ out.write(jsonString.getBytes(DEFAULT_CHARSET));
+ }
+ });
+
+ final String transformType = context.getProperty(JOLT_TRANSFORM).getValue();
+ transformed = session.putAttribute(transformed, CoreAttributes.MIME_TYPE.key(),"application/json");
+ session.transfer(transformed, REL_SUCCESS);
+ session.getProvenanceReporter().modifyContent(transformed,"Modified With " + transformType ,stopWatch.getElapsed(TimeUnit.MILLISECONDS));
+ logger.info("Transformed {}", new Object[]{original});
+
+ }
+
+ @OnScheduled
+ public void setup(final ProcessContext context) {
+ Object specJson = null;
+ if(context.getProperty(JOLT_SPEC).isSet() && !SORTR.getValue().equals(context.getProperty(JOLT_TRANSFORM).getValue())){
+ specJson = JsonUtils.jsonToObject(context.getProperty(JOLT_SPEC).getValue(), DEFAULT_CHARSET);
+ }
+ transform = TransformFactory.getTransform(context.getProperty(JOLT_TRANSFORM).getValue(), specJson);
+ }
+
+
+}
http://git-wip-us.apache.org/repos/asf/nifi/blob/cb3aa8f5/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/TransformJSON.java
----------------------------------------------------------------------
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/TransformJSON.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/TransformJSON.java
deleted file mode 100644
index 675b135..0000000
--- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/TransformJSON.java
+++ /dev/null
@@ -1,247 +0,0 @@
-/*
- * 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 java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-import java.util.concurrent.TimeUnit;
-
-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.documentation.CapabilityDescription;
-import org.apache.nifi.annotation.documentation.Tags;
-import org.apache.nifi.annotation.lifecycle.OnScheduled;
-import org.apache.nifi.components.AllowableValue;
-import org.apache.nifi.components.PropertyDescriptor;
-import org.apache.nifi.components.ValidationContext;
-import org.apache.nifi.components.ValidationResult;
-import org.apache.nifi.flowfile.FlowFile;
-import org.apache.nifi.flowfile.attributes.CoreAttributes;
-import org.apache.nifi.logging.ComponentLog;
-import org.apache.nifi.processor.AbstractProcessor;
-import org.apache.nifi.processor.ProcessContext;
-import org.apache.nifi.processor.ProcessSession;
-import org.apache.nifi.processor.Relationship;
-import org.apache.nifi.processor.exception.ProcessException;
-import org.apache.nifi.processor.io.InputStreamCallback;
-import org.apache.nifi.processor.io.OutputStreamCallback;
-import org.apache.nifi.processor.util.StandardValidators;
-import org.apache.nifi.stream.io.ByteArrayInputStream;
-import org.apache.nifi.stream.io.StreamUtils;
-import org.apache.nifi.util.StopWatch;
-import org.apache.nifi.util.StringUtils;
-
-import com.bazaarvoice.jolt.CardinalityTransform;
-import com.bazaarvoice.jolt.Chainr;
-import com.bazaarvoice.jolt.Defaultr;
-import com.bazaarvoice.jolt.JsonUtils;
-import com.bazaarvoice.jolt.Removr;
-import com.bazaarvoice.jolt.Shiftr;
-import com.bazaarvoice.jolt.Sortr;
-import com.bazaarvoice.jolt.Transform;
-
-@EventDriven
-@SideEffectFree
-@SupportsBatching
-@Tags({"json", "jolt", "transform", "shiftr", "chainr", "defaultr", "removr","cardinality","sort"})
-@InputRequirement(InputRequirement.Requirement.INPUT_REQUIRED)
-@WritesAttribute(attribute = "mime.type",description = "Always set to application/json")
-@CapabilityDescription("Applies a list of JOLT specifications to the flowfile JSON payload. A new FlowFile is created "
- + "with transformed content and is routed to the 'success' relationship. If the JSON transform "
- + "fails, the original FlowFile is routed to the 'failure' relationship.")
-public class TransformJSON extends AbstractProcessor {
-
- public static final AllowableValue SHIFTR = new AllowableValue("jolt-transform-shift", "Shift Transform DSL", "Shift input JSON/data to create the output JSON.");
- public static final AllowableValue CHAINR = new AllowableValue("jolt-transform-chain", "Chain Transform DSL", "Execute list of JOLT transformations.");
- public static final AllowableValue DEFAULTR = new AllowableValue("jolt-transform-default", "Default Transform DSL", " Apply default values to the output JSON.");
- public static final AllowableValue REMOVR = new AllowableValue("jolt-transform-remove", "Remove Transform DSL", " Remove values from input data to create the output JSON.");
- public static final AllowableValue CARDINALITY = new AllowableValue("jolt-transform-card", "Cardinality Transform DSL", "Change the cardinality of input elements to create the output JSON.");
- public static final AllowableValue SORTR = new AllowableValue("jolt-transform-sort", "Sort Transform DSL", "Sort input json key values alphabetically. Any specification set is ignored.");
-
- public static final PropertyDescriptor JOLT_TRANSFORM = new PropertyDescriptor.Builder()
- .name("jolt-transform")
- .displayName("Jolt Transformation")
- .description("Specifies the Jolt Transformation that should be used with the provided specification.")
- .required(true)
- .allowableValues(CARDINALITY, CHAINR, DEFAULTR, REMOVR, SHIFTR, SORTR)
- .defaultValue(CHAINR.getValue())
- .build();
-
- public static final PropertyDescriptor JOLT_SPEC = new PropertyDescriptor.Builder()
- .name("jolt-spec")
- .displayName("Jolt Specification")
- .description("Jolt Specification for transform of JSON data. This value is ignored if the Jolt Sort Transformation is selected.")
- .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
- .required(false)
- .build();
-
- public static final Relationship REL_SUCCESS = new Relationship.Builder()
- .name("success")
- .description("The FlowFile with transformed content will be routed to this relationship")
- .build();
- public static final Relationship REL_FAILURE = new Relationship.Builder()
- .name("failure")
- .description("If a FlowFile fails processing for any reason (for example, the FlowFile is not valid JSON), it will be routed to this relationship")
- .build();
-
- private final static List<PropertyDescriptor> properties;
- private final static Set<Relationship> relationships;
- private volatile Transform transform;
- private final static String DEFAULT_CHARSET = "UTF-8";
-
- static{
-
- final List<PropertyDescriptor> _properties = new ArrayList<>();
- _properties.add(JOLT_TRANSFORM);
- _properties.add(JOLT_SPEC);
- properties = Collections.unmodifiableList(_properties);
-
- final Set<Relationship> _relationships = new HashSet<>();
- _relationships.add(REL_SUCCESS);
- _relationships.add(REL_FAILURE);
- relationships = Collections.unmodifiableSet(_relationships);
-
- }
-
- @Override
- public Set<Relationship> getRelationships() {
- return relationships;
- }
-
- @Override
- protected List<PropertyDescriptor> getSupportedPropertyDescriptors() {
- return properties;
- }
-
-
- @Override
- protected Collection<ValidationResult> customValidate(ValidationContext validationContext) {
- final List<ValidationResult> results = new ArrayList<>(super.customValidate(validationContext));
- String transform = validationContext.getProperty(JOLT_TRANSFORM).getValue();
- String specValue = validationContext.getProperty(JOLT_SPEC).isSet() ? validationContext.getProperty(JOLT_SPEC).getValue() : null;
-
- if(StringUtils.isEmpty(specValue)){
- if(!SORTR.getValue().equals(transform)) {
- String message = "A specification is required for this transformation";
- results.add(new ValidationResult.Builder().valid(false)
- .explanation(message)
- .build());
- }
- } else {
- try {
- Object specJson = JsonUtils.jsonToObject(specValue, DEFAULT_CHARSET);
- TransformationFactory.getTransform(transform, specJson);
- } catch (final Exception e) {
- getLogger().info("Processor is not valid - " + e.toString());
- String message = "Specification not valid for the selected transformation." ;
- results.add(new ValidationResult.Builder().valid(false)
- .explanation(message)
- .build());
- }
- }
- return results;
- }
-
- @Override
- public void onTrigger(final ProcessContext context, ProcessSession session) throws ProcessException {
-
- final FlowFile original = session.get();
- if (original == null) {
- return;
- }
-
- final ComponentLog logger = getLogger();
- final StopWatch stopWatch = new StopWatch(true);
-
- final byte[] originalContent = new byte[(int) original.getSize()];
- session.read(original, new InputStreamCallback() {
- @Override
- public void process(final InputStream in) throws IOException {
- StreamUtils.fillBuffer(in, originalContent, true);
- }
- });
-
- final String jsonString;
-
- try {
- final ByteArrayInputStream bais = new ByteArrayInputStream(originalContent);
- final Object inputJson = JsonUtils.jsonToObject(bais);
- final Object transformedJson = transform.transform(inputJson);
- jsonString = JsonUtils.toJsonString(transformedJson);
-
- } catch (RuntimeException re) {
- logger.error("Unable to transform {} due to {}", new Object[]{original, re});
- session.transfer(original, REL_FAILURE);
- return;
- }
-
- FlowFile transformed = session.write(original, new OutputStreamCallback() {
- @Override
- public void process(OutputStream out) throws IOException {
- out.write(jsonString.getBytes(DEFAULT_CHARSET));
- }
- });
-
- final String transformType = context.getProperty(JOLT_TRANSFORM).getValue();
- transformed = session.putAttribute(transformed, CoreAttributes.MIME_TYPE.key(),"application/json");
- session.transfer(transformed, REL_SUCCESS);
- session.getProvenanceReporter().modifyContent(transformed,"Modified With " + transformType ,stopWatch.getElapsed(TimeUnit.MILLISECONDS));
- logger.info("Transformed {}", new Object[]{original});
-
- }
-
- @OnScheduled
- public void setup(final ProcessContext context) {
- Object specJson = null;
- if(context.getProperty(JOLT_SPEC).isSet()){
- specJson = JsonUtils.jsonToObject(context.getProperty(JOLT_SPEC).getValue(), DEFAULT_CHARSET);
- }
- transform = TransformationFactory.getTransform(context.getProperty(JOLT_TRANSFORM).getValue(), specJson);
- }
-
- private static class TransformationFactory {
-
- static Transform getTransform(String transform, Object specJson) {
- if (transform.equals(DEFAULTR.getValue())) {
- return new Defaultr(specJson);
- } else if (transform.equals(SHIFTR.getValue())) {
- return new Shiftr(specJson);
- } else if (transform.equals(REMOVR.getValue())) {
- return new Removr(specJson);
- } else if (transform.equals(CARDINALITY.getValue())) {
- return new CardinalityTransform(specJson);
- } else if(transform.equals(SORTR.getValue())){
- return new Sortr();
- } else {
- return Chainr.fromSpec(specJson);
- }
- }
-
- }
-
-}
http://git-wip-us.apache.org/repos/asf/nifi/blob/cb3aa8f5/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/resources/META-INF/services/org.apache.nifi.processor.Processor
----------------------------------------------------------------------
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/resources/META-INF/services/org.apache.nifi.processor.Processor b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/resources/META-INF/services/org.apache.nifi.processor.Processor
index bf95078..a4eb235 100644
--- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/resources/META-INF/services/org.apache.nifi.processor.Processor
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/resources/META-INF/services/org.apache.nifi.processor.Processor
@@ -42,6 +42,7 @@ org.apache.nifi.processors.standard.HashAttribute
org.apache.nifi.processors.standard.HashContent
org.apache.nifi.processors.standard.IdentifyMimeType
org.apache.nifi.processors.standard.InvokeHTTP
+org.apache.nifi.processors.standard.JoltTransformJSON
org.apache.nifi.processors.standard.GetJMSQueue
org.apache.nifi.processors.standard.GetJMSTopic
org.apache.nifi.processors.standard.ListFile
@@ -80,7 +81,6 @@ org.apache.nifi.processors.standard.SplitJson
org.apache.nifi.processors.standard.SplitText
org.apache.nifi.processors.standard.SplitXml
org.apache.nifi.processors.standard.TailFile
-org.apache.nifi.processors.standard.TransformJSON
org.apache.nifi.processors.standard.TransformXml
org.apache.nifi.processors.standard.UnpackContent
org.apache.nifi.processors.standard.ValidateXml
http://git-wip-us.apache.org/repos/asf/nifi/blob/cb3aa8f5/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/resources/docs/org.apache.nifi.processors.standard.JoltTransformJSON/additionalDetails.html
----------------------------------------------------------------------
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/resources/docs/org.apache.nifi.processors.standard.JoltTransformJSON/additionalDetails.html b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/resources/docs/org.apache.nifi.processors.standard.JoltTransformJSON/additionalDetails.html
new file mode 100644
index 0000000..f2f1c05
--- /dev/null
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/resources/docs/org.apache.nifi.processors.standard.JoltTransformJSON/additionalDetails.html
@@ -0,0 +1,36 @@
+<!DOCTYPE html>
+<html lang="en">
+<!--
+ 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.
+-->
+<head>
+ <meta charset="utf-8"/>
+ <title>JoltTransformJSON</title>
+ <link rel="stylesheet" href="../../css/component-usage.css" type="text/css"/>
+</head>
+
+<body>
+<!-- Processor Documentation ================================================== -->
+<h2>Usage Information</h2>
+
+<p>
+ The Jolt utilities processing JSON are not not stream based therefore large JSON document
+ transformation may consume large amounts of memory. Currently UTF-8 FlowFile content and Jolt specifications are supported.
+
+ <Strong>Note:</Strong> When configuring a processor if user selects of the Default transformation yet provides a
+ Chain specification the system does not alert that the specification is invalid and and will produce failed flow files.
+ This is a known issue identified within the Jolt library.
+</p>
+</body>
+</html>
http://git-wip-us.apache.org/repos/asf/nifi/blob/cb3aa8f5/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/resources/docs/org.apache.nifi.processors.standard.TransformJSON/additionalDetails.html
----------------------------------------------------------------------
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/resources/docs/org.apache.nifi.processors.standard.TransformJSON/additionalDetails.html b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/resources/docs/org.apache.nifi.processors.standard.TransformJSON/additionalDetails.html
deleted file mode 100644
index 2141d14..0000000
--- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/resources/docs/org.apache.nifi.processors.standard.TransformJSON/additionalDetails.html
+++ /dev/null
@@ -1,36 +0,0 @@
-<!DOCTYPE html>
-<html lang="en">
-<!--
- 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.
--->
-<head>
- <meta charset="utf-8"/>
- <title>TransformJSON</title>
- <link rel="stylesheet" href="../../css/component-usage.css" type="text/css"/>
-</head>
-
-<body>
-<!-- Processor Documentation ================================================== -->
-<h2>Usage Information</h2>
-
-<p>
- The JOLT utilities processing JSON are not not stream based therefore large JSON document
- transformation may consume large amounts of memory. Currently UTF-8 FlowFile content and Jolt specifications are supported.
-
- <Strong>Note:</Strong> When configuring a processor if user selects of the Default transformation yet provides a
- Chain specification the system does not alert that the specification is invalid and and will produce failed flow files.
- This is a known issue identified within the JOLT library.
-</p>
-</body>
-</html>
http://git-wip-us.apache.org/repos/asf/nifi/blob/cb3aa8f5/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestJoltTransformJSON.java
----------------------------------------------------------------------
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestJoltTransformJSON.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestJoltTransformJSON.java
new file mode 100644
index 0000000..79cc95c
--- /dev/null
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestJoltTransformJSON.java
@@ -0,0 +1,232 @@
+/*
+ * 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 java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.Set;
+
+import org.apache.nifi.flowfile.attributes.CoreAttributes;
+import org.apache.nifi.processor.Processor;
+import org.apache.nifi.processor.Relationship;
+import org.apache.nifi.stream.io.ByteArrayInputStream;
+import org.apache.nifi.util.MockFlowFile;
+import org.apache.nifi.util.StringUtils;
+import org.apache.nifi.util.TestRunner;
+import org.apache.nifi.util.TestRunners;
+import org.junit.Test;
+
+import com.bazaarvoice.jolt.Diffy;
+import com.bazaarvoice.jolt.JsonUtils;
+
+import static org.junit.Assert.assertTrue;
+
+public class TestJoltTransformJSON {
+
+ final static Path JSON_INPUT = Paths.get("src/test/resources/TestJoltTransformJson/input.json");
+ final static Diffy DIFFY = new Diffy();
+
+ @Test
+ public void testRelationshipsCreated() throws IOException{
+ Processor processor= new JoltTransformJSON();
+ final TestRunner runner = TestRunners.newTestRunner(processor);
+ final String spec = new String(Files.readAllBytes(Paths.get("src/test/resources/TestJoltTransformJson/chainrSpec.json")));
+ runner.setProperty(JoltTransformJSON.JOLT_SPEC, spec);
+ runner.enqueue(JSON_INPUT);
+ Set<Relationship> relationships = processor.getRelationships();
+ assertTrue(relationships.contains(JoltTransformJSON.REL_FAILURE));
+ assertTrue(relationships.contains(JoltTransformJSON.REL_SUCCESS));
+ assertTrue(relationships.size() == 2);
+ }
+
+ @Test
+ public void testInvalidJOLTSpec() throws IOException {
+ final TestRunner runner = TestRunners.newTestRunner(new JoltTransformJSON());
+ final String spec = "[{}]";
+ runner.setProperty(JoltTransformJSON.JOLT_SPEC, spec);
+ runner.assertNotValid();
+ }
+
+ @Test
+ public void testIncorrectJOLTSpec() throws IOException {
+ final TestRunner runner = TestRunners.newTestRunner(new JoltTransformJSON());
+ final String chainrSpec = new String(Files.readAllBytes(Paths.get("src/test/resources/TestJoltTransformJson/chainrSpec.json")));
+ runner.setProperty(JoltTransformJSON.JOLT_SPEC, chainrSpec);
+ runner.setProperty(JoltTransformJSON.JOLT_TRANSFORM, JoltTransformJSON.SHIFTR);
+ runner.assertNotValid();
+ }
+
+ @Test
+ public void testSpecIsNotSet() throws IOException {
+ final TestRunner runner = TestRunners.newTestRunner(new JoltTransformJSON());
+ runner.setProperty(JoltTransformJSON.JOLT_TRANSFORM, JoltTransformJSON.SHIFTR);
+ runner.assertNotValid();
+ }
+
+ @Test
+ public void testSpecIsEmpty() throws IOException {
+ final TestRunner runner = TestRunners.newTestRunner(new JoltTransformJSON());
+ runner.setProperty(JoltTransformJSON.JOLT_SPEC, StringUtils.EMPTY);
+ runner.setProperty(JoltTransformJSON.JOLT_TRANSFORM, JoltTransformJSON.SHIFTR);
+ runner.assertNotValid();
+ }
+
+ @Test
+ public void testSpecNotRequired() throws IOException {
+ final TestRunner runner = TestRunners.newTestRunner(new JoltTransformJSON());
+ runner.setProperty(JoltTransformJSON.JOLT_TRANSFORM, JoltTransformJSON.SORTR);
+ runner.assertValid();
+ }
+
+ @Test
+ public void testNoFlowFileContent() throws IOException {
+ final TestRunner runner = TestRunners.newTestRunner(new JoltTransformJSON());
+ final String spec = new String(Files.readAllBytes(Paths.get("src/test/resources/TestJoltTransformJson/chainrSpec.json")));
+ runner.setProperty(JoltTransformJSON.JOLT_SPEC, spec);
+ runner.run();
+ runner.assertQueueEmpty();
+ runner.assertTransferCount(JoltTransformJSON.REL_FAILURE,0);
+ runner.assertTransferCount(JoltTransformJSON.REL_SUCCESS,0);
+ }
+
+ @Test
+ public void testInvalidFlowFileContentJson() throws IOException {
+ final TestRunner runner = TestRunners.newTestRunner(new JoltTransformJSON());
+ final String spec = new String(Files.readAllBytes(Paths.get("src/test/resources/TestJoltTransformJson/chainrSpec.json")));
+ runner.setProperty(JoltTransformJSON.JOLT_SPEC, spec);
+ runner.enqueue("invalid json");
+ runner.run();
+ runner.assertAllFlowFilesTransferred(JoltTransformJSON.REL_FAILURE);
+ }
+
+ @Test
+ public void testTransformInputWithChainr() throws IOException {
+ final TestRunner runner = TestRunners.newTestRunner(new JoltTransformJSON());
+ final String spec = new String(Files.readAllBytes(Paths.get("src/test/resources/TestJoltTransformJson/chainrSpec.json")));
+ runner.setProperty(JoltTransformJSON.JOLT_SPEC, spec);
+ runner.enqueue(JSON_INPUT);
+ runner.run();
+ runner.assertAllFlowFilesTransferred(JoltTransformJSON.REL_SUCCESS);
+ final MockFlowFile transformed = runner.getFlowFilesForRelationship(JoltTransformJSON.REL_SUCCESS).get(0);
+ transformed.assertAttributeExists(CoreAttributes.MIME_TYPE.key());
+ transformed.assertAttributeEquals(CoreAttributes.MIME_TYPE.key(),"application/json");
+ Object transformedJson = JsonUtils.jsonToObject(new ByteArrayInputStream(transformed.toByteArray()));
+ Object compareJson = JsonUtils.jsonToObject(Files.newInputStream(Paths.get("src/test/resources/TestJoltTransformJson/chainrOutput.json")));
+ assertTrue(DIFFY.diff(compareJson, transformedJson).isEmpty());
+ }
+
+ @Test
+ public void testTransformInputWithShiftr() throws IOException {
+ final TestRunner runner = TestRunners.newTestRunner(new JoltTransformJSON());
+ final String spec = new String(Files.readAllBytes(Paths.get("src/test/resources/TestJoltTransformJson/shiftrSpec.json")));
+ runner.setProperty(JoltTransformJSON.JOLT_SPEC, spec);
+ runner.setProperty(JoltTransformJSON.JOLT_TRANSFORM, JoltTransformJSON.SHIFTR);
+ runner.enqueue(JSON_INPUT);
+ runner.run();
+ runner.assertAllFlowFilesTransferred(JoltTransformJSON.REL_SUCCESS);
+ final MockFlowFile transformed = runner.getFlowFilesForRelationship(JoltTransformJSON.REL_SUCCESS).get(0);
+ transformed.assertAttributeExists(CoreAttributes.MIME_TYPE.key());
+ transformed.assertAttributeEquals(CoreAttributes.MIME_TYPE.key(),"application/json");
+ Object transformedJson = JsonUtils.jsonToObject(new ByteArrayInputStream(transformed.toByteArray()));
+ Object compareJson = JsonUtils.jsonToObject(Files.newInputStream(Paths.get("src/test/resources/TestJoltTransformJson/shiftrOutput.json")));
+ assertTrue(DIFFY.diff(compareJson, transformedJson).isEmpty());
+ }
+
+ @Test
+ public void testTransformInputWithDefaultr() throws IOException {
+ final TestRunner runner = TestRunners.newTestRunner(new JoltTransformJSON());
+ final String spec = new String(Files.readAllBytes(Paths.get("src/test/resources/TestJoltTransformJson/defaultrSpec.json")));
+ runner.setProperty(JoltTransformJSON.JOLT_SPEC, spec);
+ runner.setProperty(JoltTransformJSON.JOLT_TRANSFORM, JoltTransformJSON.DEFAULTR);
+ runner.enqueue(JSON_INPUT);
+ runner.run();
+ runner.assertAllFlowFilesTransferred(JoltTransformJSON.REL_SUCCESS);
+ final MockFlowFile transformed = runner.getFlowFilesForRelationship(JoltTransformJSON.REL_SUCCESS).get(0);
+ Object transformedJson = JsonUtils.jsonToObject(new ByteArrayInputStream(transformed.toByteArray()));
+ Object compareJson = JsonUtils.jsonToObject(Files.newInputStream(Paths.get("src/test/resources/TestJoltTransformJson/defaultrOutput.json")));
+ assertTrue(DIFFY.diff(compareJson, transformedJson).isEmpty());
+ }
+
+ @Test
+ public void testTransformInputWithRemovr() throws IOException {
+ final TestRunner runner = TestRunners.newTestRunner(new JoltTransformJSON());
+ final String spec = new String(Files.readAllBytes(Paths.get("src/test/resources/TestJoltTransformJson/removrSpec.json")));
+ runner.setProperty(JoltTransformJSON.JOLT_SPEC, spec);
+ runner.setProperty(JoltTransformJSON.JOLT_TRANSFORM, JoltTransformJSON.REMOVR);
+ runner.enqueue(JSON_INPUT);
+ runner.run();
+ runner.assertAllFlowFilesTransferred(JoltTransformJSON.REL_SUCCESS);
+ final MockFlowFile transformed = runner.getFlowFilesForRelationship(JoltTransformJSON.REL_SUCCESS).get(0);
+ Object transformedJson = JsonUtils.jsonToObject(new ByteArrayInputStream(transformed.toByteArray()));
+ Object compareJson = JsonUtils.jsonToObject(Files.newInputStream(Paths.get("src/test/resources/TestJoltTransformJson/removrOutput.json")));
+ assertTrue(DIFFY.diff(compareJson, transformedJson).isEmpty());
+ }
+
+ @Test
+ public void testTransformInputWithCardinality() throws IOException {
+ final TestRunner runner = TestRunners.newTestRunner(new JoltTransformJSON());
+ final String spec = new String(Files.readAllBytes(Paths.get("src/test/resources/TestJoltTransformJson/cardrSpec.json")));
+ runner.setProperty(JoltTransformJSON.JOLT_SPEC, spec);
+ runner.setProperty(JoltTransformJSON.JOLT_TRANSFORM, JoltTransformJSON.CARDINALITY);
+ runner.enqueue(JSON_INPUT);
+ runner.run();
+ runner.assertAllFlowFilesTransferred(JoltTransformJSON.REL_SUCCESS);
+ final MockFlowFile transformed = runner.getFlowFilesForRelationship(JoltTransformJSON.REL_SUCCESS).get(0);
+ Object transformedJson = JsonUtils.jsonToObject(new ByteArrayInputStream(transformed.toByteArray()));
+ Object compareJson = JsonUtils.jsonToObject(Files.newInputStream(Paths.get("src/test/resources/TestJoltTransformJson/cardrOutput.json")));
+ assertTrue(DIFFY.diff(compareJson, transformedJson).isEmpty());
+ }
+
+ @Test
+ public void testTransformInputWithSortr() throws IOException {
+ final TestRunner runner = TestRunners.newTestRunner(new JoltTransformJSON());
+ runner.setProperty(JoltTransformJSON.JOLT_TRANSFORM, JoltTransformJSON.SORTR);
+ runner.enqueue(JSON_INPUT);
+ runner.run();
+ runner.assertAllFlowFilesTransferred(JoltTransformJSON.REL_SUCCESS);
+ final MockFlowFile transformed = runner.getFlowFilesForRelationship(JoltTransformJSON.REL_SUCCESS).get(0);
+ transformed.assertAttributeExists(CoreAttributes.MIME_TYPE.key());
+ transformed.assertAttributeEquals(CoreAttributes.MIME_TYPE.key(),"application/json");
+ Object transformedJson = JsonUtils.jsonToObject(new ByteArrayInputStream(transformed.toByteArray()));
+ Object compareJson = JsonUtils.jsonToObject(Files.newInputStream(Paths.get("src/test/resources/TestJoltTransformJson/sortrOutput.json")));
+ String transformedJsonString = JsonUtils.toJsonString(transformedJson);
+ String compareJsonString = JsonUtils.toJsonString(compareJson);
+ assertTrue(compareJsonString.equals(transformedJsonString));
+ }
+
+ @Test
+ public void testTransformInputWithSortrPopulatedSpec() throws IOException {
+ final TestRunner runner = TestRunners.newTestRunner(new JoltTransformJSON());
+ runner.setProperty(JoltTransformJSON.JOLT_TRANSFORM, JoltTransformJSON.SORTR);
+ runner.setProperty(JoltTransformJSON.JOLT_SPEC, "abcd");
+ runner.enqueue(JSON_INPUT);
+ runner.run();
+ runner.assertAllFlowFilesTransferred(JoltTransformJSON.REL_SUCCESS);
+ final MockFlowFile transformed = runner.getFlowFilesForRelationship(JoltTransformJSON.REL_SUCCESS).get(0);
+ transformed.assertAttributeExists(CoreAttributes.MIME_TYPE.key());
+ transformed.assertAttributeEquals(CoreAttributes.MIME_TYPE.key(),"application/json");
+ Object transformedJson = JsonUtils.jsonToObject(new ByteArrayInputStream(transformed.toByteArray()));
+ Object compareJson = JsonUtils.jsonToObject(Files.newInputStream(Paths.get("src/test/resources/TestJoltTransformJson/sortrOutput.json")));
+ String transformedJsonString = JsonUtils.toJsonString(transformedJson);
+ String compareJsonString = JsonUtils.toJsonString(compareJson);
+ assertTrue(compareJsonString.equals(transformedJsonString));
+ }
+
+
+}