001/*
002 * Copyright (c) 2007-2022 The Cascading Authors. All Rights Reserved.
003 *
004 * Project and contact information: https://cascading.wensel.net/
005 *
006 * This file is part of the Cascading project.
007 *
008 * Licensed under the Apache License, Version 2.0 (the "License");
009 * you may not use this file except in compliance with the License.
010 * You may obtain a copy of the License at
011 *
012 *     http://www.apache.org/licenses/LICENSE-2.0
013 *
014 * Unless required by applicable law or agreed to in writing, software
015 * distributed under the License is distributed on an "AS IS" BASIS,
016 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017 * See the License for the specific language governing permissions and
018 * limitations under the License.
019 */
020
021package cascading.nested.json;
022
023import java.beans.ConstructorProperties;
024import java.util.Collections;
025import java.util.Map;
026
027import cascading.nested.core.NestedSetFunction;
028import cascading.tuple.Fields;
029import com.fasterxml.jackson.databind.JsonNode;
030import com.fasterxml.jackson.databind.node.ArrayNode;
031
032/**
033 * Class JSONSetFunction provides for the ability to simply set multiple tuple values onto an existing JSON object.
034 *
035 * @see <a href=https://tools.ietf.org/html/draft-ietf-appsawg-json-pointer-03">draft-ietf-appsawg-json-pointer-03</a>
036 * @see NestedSetFunction for more details.
037 */
038public class JSONSetFunction extends NestedSetFunction<JsonNode, ArrayNode>
039  {
040  /**
041   * Creates a new JSONSetFunction instance that will pivot all resolved arguments fields into
042   * an existing JSON object, where all the JSON object attributes are the argument field names.
043   *
044   * @param fieldDeclaration of Fields
045   */
046  @ConstructorProperties({"fieldDeclaration"})
047  public JSONSetFunction( Fields fieldDeclaration )
048    {
049    super( JSONCoercibleType.TYPE, fieldDeclaration );
050    }
051
052  /**
053   * Creates a new JSONSetFunction instance that will pivot all resolved arguments fields into
054   * an existing JSON object, where all the JSON object attributes are the argument field names.
055   * <p>
056   * The {@code rootPointer} values specifies the base name of the final pointer path. If {@code rootPointer} is
057   * "/person" and and argument is passed with field name "fullName", the value will be placed in "/person/fullName".
058   *
059   * @param fieldDeclaration of Fields
060   * @param rootPointer      of String
061   */
062  @ConstructorProperties({"fieldDeclaration", "rootPointer"})
063  public JSONSetFunction( Fields fieldDeclaration, String rootPointer )
064    {
065    super( JSONCoercibleType.TYPE, fieldDeclaration, rootPointer );
066    }
067
068  /**
069   * Creates a new JSONSetFunction instance.
070   *
071   * @param fieldDeclaration of Fields
072   * @param fromFields       of Fields
073   * @param stringPointer    of String
074   */
075  public JSONSetFunction( Fields fieldDeclaration, Fields fromFields, String stringPointer )
076    {
077    this( fieldDeclaration, Collections.singletonMap( fromFields, stringPointer ) );
078    }
079
080  /**
081   * Creates a new JSONSetFunction instance.
082   *
083   * @param fieldDeclaration of Fields
084   * @param pointerMap       of Map
085   */
086  @ConstructorProperties({"fieldDeclaration", "pointerMap"})
087  public JSONSetFunction( Fields fieldDeclaration, Map<Fields, String> pointerMap )
088    {
089    super( JSONCoercibleType.TYPE, fieldDeclaration, pointerMap );
090    }
091
092  /**
093   * Creates a new JSONSetFunction instance that will pivot all resolved arguments fields into
094   * an existing JSON object, where all the JSON object attributes are the argument field names.
095   *
096   * @param coercibleType    of JSONCoercibleType
097   * @param fieldDeclaration of Fields
098   */
099  @ConstructorProperties({"coercibleType", "fieldDeclaration"})
100  public JSONSetFunction( JSONCoercibleType coercibleType, Fields fieldDeclaration )
101    {
102    super( coercibleType, fieldDeclaration );
103    }
104
105  /**
106   * Creates a new JSONSetFunction instance that will pivot all resolved arguments fields into
107   * an existing JSON object, where all the JSON object attributes are the argument field names.
108   * <p>
109   * The {@code rootPointer} values specifies the base name of the final pointer path. If {@code rootPointer} is
110   * "/person" and and argument is passed with field name "fullName", the value will be placed in "/person/fullName".
111   *
112   * @param coercibleType    of JSONCoercibleType
113   * @param fieldDeclaration of Fields
114   * @param rootPointer      of String
115   */
116  @ConstructorProperties({"coercibleType", "fieldDeclaration", "rootPointer"})
117  public JSONSetFunction( JSONCoercibleType coercibleType, Fields fieldDeclaration, String rootPointer )
118    {
119    super( coercibleType, fieldDeclaration, rootPointer );
120    }
121
122  /**
123   * Creates a new JSONSetFunction instance.
124   *
125   * @param coercibleType    of JSONCoercibleType
126   * @param fieldDeclaration of Fields
127   * @param fromFields       of Fields
128   * @param stringPointer    of String
129   */
130  @ConstructorProperties({"coercibleType", "fieldDeclaration", "fromFields", "stringPointer"})
131  public JSONSetFunction( JSONCoercibleType coercibleType, Fields fieldDeclaration, Fields fromFields, String stringPointer )
132    {
133    this( coercibleType, fieldDeclaration, Collections.singletonMap( fromFields, stringPointer ) );
134    }
135
136  /**
137   * Creates a new JSONSetFunction instance.
138   *
139   * @param coercibleType    of JSONCoercibleType
140   * @param fieldDeclaration of Fields
141   * @param pointerMap       of Map
142   */
143  @ConstructorProperties({"coercibleType", "fieldDeclaration", "pointerMap"})
144  public JSONSetFunction( JSONCoercibleType coercibleType, Fields fieldDeclaration, Map<Fields, String> pointerMap )
145    {
146    super( coercibleType, fieldDeclaration, pointerMap );
147    }
148  }