Class ValueUtil


  • public class ValueUtil
    extends java.lang.Object
    Utility methods to Construct IValue based on JSON or Connector Property.
    • Constructor Summary

      Constructors 
      Constructor Description
      ValueUtil()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static IValueMap generateValue​(IDataModel dataModel, java.util.Map<java.lang.String,​java.lang.Object> data, boolean autoCoerce)
      Construct the value object according to provided DataModel structured based on result (Java Object) of operation execution.
      static IValueMap generateValue​(IDataModel dataModel, java.util.Map<java.lang.String,​java.lang.Object> data, boolean autoCoerce, boolean generateNullForPropsNotInData)
      Construct the value object according to provided DataModel structured based on result (Java Object) of operation execution.
      static IValueMap generateValue​(IDataModel dataModel, java.util.Map<java.lang.String,​java.lang.Object> data, boolean autoCoerce, boolean generateNullForPropsNotInData, boolean removeComputedAttributes)
      Construct the value object according to provided DataModel structured based on result (Java Object) of operation execution.
      static IValueMap generateValue​(IDataModel dataModel, java.util.Map<java.lang.String,​java.lang.Object> data, java.util.List<? extends IDataModel> datamodels, boolean autoCoerce)
      Construct the value object according to provided DataModel structured based on result (Java Object) of operation execution.
      static IValueMap generateValue​(IDataModel dataModel, java.util.Map<java.lang.String,​java.lang.Object> data, java.util.List<? extends IDataModel> datamodels, boolean autoCoerce, boolean generateNullForPropsNotInData)
      Construct the value object according to provided DataModel structured based on result (Java Object) of operation execution.
      static IValueMap generateValue​(IDataModel dataModel, java.util.Map<java.lang.String,​java.lang.Object> data, java.util.List<? extends IDataModel> datamodels, boolean autoCoerce, boolean generateNullForPropsNotInData, boolean removeComputedAttributes)
      Construct the value object according to provided DataModel structured based on result (Java Object) of operation execution.
      static IValue generateValue​(IProperty property, java.lang.Object data, boolean autoCoerce)
      Construct the value object according to provided Property and based on result (Java Object) of operation execution.
      static IValue generateValue​(IProperty property, java.lang.Object data, boolean autoCoerce, boolean generateNullForPropsNotInData)
      Construct the value object according to provided Property and based on result (Java Object) of operation execution.
      static IValue generateValue​(IProperty property, java.lang.Object data, boolean autoCoerce, boolean generateNullForPropsNotInData, boolean removeComputedAttributes)
      Construct the value object according to provided Property and based on result (Java Object) of operation execution.
      static IValue generateValue​(IProperty property, java.lang.Object data, java.util.List<? extends IDataModel> datamodels, boolean autoCoerce)
      Construct the value object according to provided Property and based on result (Java Object) of operation execution.
      static IValue generateValue​(IProperty property, java.lang.Object data, java.util.List<? extends IDataModel> dataModels, boolean autoCoerce, boolean generateNullForPropsNotInData)
      Construct the value object according to provided Property and based on result (Java Object) of operation execution.
      static IValue generateValue​(IProperty property, java.lang.Object data, java.util.List<? extends IDataModel> dataModels, boolean autoCoerce, boolean generateNullForPropsNotInData, boolean removeComputedAttributes)
      Construct the value object according to provided Property and based on result (Java Object) of operation execution.
      static java.lang.Object getFormattedValue​(java.lang.Object value)
      Return formatted value for provided input.
      static IValue getValue​(IValueMap valueMap, java.lang.String name)
      Get the value object associated with a key.
      static IValueList jsonListToValue​(org.apache.sling.commons.json.JSONArray array)
      Construct the value object based on the provided JSONArray.
      static IValueMap jsonObjectToValue​(org.apache.sling.commons.json.JSONObject data)
      Construct the value object based on the provided JSONObject.
      static IValue jsonToValue​(java.lang.Object data)
      Construct the value object based on the provided json object or array.
      static IValue jsonToValue​(java.lang.String jsonString, IProperty property)
      Construct the value object based on the provided json string.
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • ValueUtil

        public ValueUtil()
    • Method Detail

      • generateValue

        public static IValue generateValue​(IProperty property,
                                           java.lang.Object data,
                                           boolean autoCoerce)
                                    throws DermisException
        Construct the value object according to provided Property and based on result (Java Object) of operation execution. if autoCoerce is false if any type/value is mismatched then DermisExceptionCodes.PROPERTY_TYPE_MISS_MATCH exception is thrown and if its true it will try to convert the value according to property type
        Parameters:
        property - - Property according to which value object is constructed.
        data - - Result of operation execution.
        autoCoerce - - boolean value represent to auto coerce the value according to type
        Returns:
        Returns the IValue representing the output of operation.
        Throws:
        DermisException
      • generateValue

        public static IValue generateValue​(IProperty property,
                                           java.lang.Object data,
                                           java.util.List<? extends IDataModel> datamodels,
                                           boolean autoCoerce)
                                    throws DermisException
        Construct the value object according to provided Property and based on result (Java Object) of operation execution. if autoCoerce is false if any type/value is mismatched then DermisExceptionCodes.PROPERTY_TYPE_MISS_MATCH exception is thrown and if its true it will try to convert the value according to property type if fdmAdditionalData is present in input data and it contains type information, then mentioned type dataModel is used to construct value
        Parameters:
        property - - Property according to which value object is constructed.
        data - - Result of operation execution.
        datamodels - - List of datamodels to be used to resolve _type information present in data and construct value accordingly , if null no resolution will happen
        autoCoerce - - boolean value represent to auto coerce the value according to type
        Returns:
        Returns the IValue representing the output of operation.
        Throws:
        DermisException
      • generateValue

        public static IValue generateValue​(IProperty property,
                                           java.lang.Object data,
                                           boolean autoCoerce,
                                           boolean generateNullForPropsNotInData)
                                    throws DermisException
        Construct the value object according to provided Property and based on result (Java Object) of operation execution. if autoCoerce is false if any type/value is mismatched then DermisExceptionCodes.PROPERTY_TYPE_MISS_MATCH exception is thrown and if its true it will try to convert the value according to property type
        Parameters:
        property - - Property according to which value object is constructed.
        data - - Result of operation execution.
        autoCoerce - - boolean value represent to auto coerce the value according to type
        generateNullForPropsNotInData - - boolean if this is true, properties for which no value is present in data, are included in the output with value null. If value of this parameter is false, null valued properties are omitted entirely from the output
        Returns:
        Returns the IValue representing the output of operation.
        Throws:
        DermisException
      • generateValue

        public static IValue generateValue​(IProperty property,
                                           java.lang.Object data,
                                           java.util.List<? extends IDataModel> dataModels,
                                           boolean autoCoerce,
                                           boolean generateNullForPropsNotInData)
                                    throws DermisException
        Construct the value object according to provided Property and based on result (Java Object) of operation execution. if autoCoerce is false if any type/value is mismatched then DermisExceptionCodes.PROPERTY_TYPE_MISS_MATCH exception is thrown and if its true it will try to convert the value according to property type if fdmAdditionalData is present in input data and it contains type information, then mentioned type dataModel is used to construct value
        Parameters:
        property - - Property according to which value object is constructed.
        data - - Result of operation execution.
        dataModels - - List of datamodels to be used to resolve _type information present in data and construct value accordingly , if null no resolution will happen
        autoCoerce - - boolean value represent to auto coerce the value according to type
        generateNullForPropsNotInData - - boolean if this is true, properties for which no value is present in data, are included in the output with value null. If value of this parameter is false, null valued properties are omitted entirely from the output
        Returns:
        Returns the IValue representing the output of operation.
        Throws:
        DermisException
      • generateValue

        public static IValue generateValue​(IProperty property,
                                           java.lang.Object data,
                                           boolean autoCoerce,
                                           boolean generateNullForPropsNotInData,
                                           boolean removeComputedAttributes)
                                    throws DermisException
        Construct the value object according to provided Property and based on result (Java Object) of operation execution. if autoCoerce is false if any type/value is mismatched then DermisExceptionCodes.PROPERTY_TYPE_MISS_MATCH exception is thrown and if its true it will try to convert the value according to property type
        Parameters:
        property - - Property according to which value object is constructed.
        data - - Result of operation execution.
        autoCoerce - - boolean value represent to auto coerce the value according to type
        generateNullForPropsNotInData - - boolean if this is true, properties for which no value is present in data, are included in the output with value null. If value of this parameter is false, null valued properties are omitted entirely from the output
        removeComputedAttributes - - boolean if this is true, computed attributes will be removed from the output
        Returns:
        Returns the IValue representing the output of operation.
        Throws:
        DermisException
      • generateValue

        public static IValue generateValue​(IProperty property,
                                           java.lang.Object data,
                                           java.util.List<? extends IDataModel> dataModels,
                                           boolean autoCoerce,
                                           boolean generateNullForPropsNotInData,
                                           boolean removeComputedAttributes)
                                    throws DermisException
        Construct the value object according to provided Property and based on result (Java Object) of operation execution. if autoCoerce is false if any type/value is mismatched then DermisExceptionCodes.PROPERTY_TYPE_MISS_MATCH exception is thrown and if its true it will try to convert the value according to property type if fdmAdditionalData is present in input data and it contains type information, then mentioned type dataModel is used to construct value
        Parameters:
        property - - Property according to which value object is constructed.
        data - - Result of operation execution.
        dataModels - - List of datamodels to be used to resolve _type information present in data and construct value accordingly , if null no resolution will happen
        autoCoerce - - boolean value represent to auto coerce the value according to type
        generateNullForPropsNotInData - - boolean if this is true, properties for which no value is present in data, are included in the output with value null. If value of this parameter is false, null valued properties are omitted entirely from the output
        removeComputedAttributes - - boolean if this is true, computed attributes will be removed from the output
        Returns:
        Returns the IValue representing the output of operation.
        Throws:
        DermisException
      • generateValue

        public static IValueMap generateValue​(IDataModel dataModel,
                                              java.util.Map<java.lang.String,​java.lang.Object> data,
                                              boolean autoCoerce)
                                       throws DermisException
        Construct the value object according to provided DataModel structured based on result (Java Object) of operation execution.
        Parameters:
        dataModel - - DataModel according to which value object is constructed.
        data - - Result of operation execution.
        autoCoerce - - boolean value represent to auto coerce the value according to type
        Returns:
        Throws:
        DermisException
      • generateValue

        public static IValueMap generateValue​(IDataModel dataModel,
                                              java.util.Map<java.lang.String,​java.lang.Object> data,
                                              java.util.List<? extends IDataModel> datamodels,
                                              boolean autoCoerce)
                                       throws DermisException
        Construct the value object according to provided DataModel structured based on result (Java Object) of operation execution.
        Parameters:
        dataModel - - DataModel according to which value object is constructed.
        data - - Result of operation execution.
        autoCoerce - - boolean value represent to auto coerce the value according to type
        datamodels - - List of datamodels to be used to resolve _type information present in data and construct value accordingly , if null no resolution will happen
        Returns:
        Returns the IValueMap representing the output of operation.
        Throws:
        DermisException
      • generateValue

        public static IValueMap generateValue​(IDataModel dataModel,
                                              java.util.Map<java.lang.String,​java.lang.Object> data,
                                              boolean autoCoerce,
                                              boolean generateNullForPropsNotInData)
                                       throws DermisException
        Construct the value object according to provided DataModel structured based on result (Java Object) of operation execution.
        Parameters:
        dataModel - - DataModel according to which value object is constructed.
        data - - Result of operation execution.
        autoCoerce - - boolean value represent to auto coerce the value according to type
        generateNullForPropsNotInData - - boolean if this is true, child properties for which no value is present in data, are included in the output with value null. If value of this parameter is false, null valued properties are omitted entirely from the output
        Returns:
        Throws:
        DermisException
      • generateValue

        public static IValueMap generateValue​(IDataModel dataModel,
                                              java.util.Map<java.lang.String,​java.lang.Object> data,
                                              java.util.List<? extends IDataModel> datamodels,
                                              boolean autoCoerce,
                                              boolean generateNullForPropsNotInData)
                                       throws DermisException
        Construct the value object according to provided DataModel structured based on result (Java Object) of operation execution.
        Parameters:
        dataModel - - DataModel according to which value object is constructed.
        data - - Result of operation execution.
        autoCoerce - - boolean value represent to auto coerce the value according to type
        datamodels - -List of datamodels to be used to resolve _type information present in data and construct value accordingly , if null no resolution will happen
        generateNullForPropsNotInData - - boolean if this is true, child properties for which no value is present in data, are included in the output with value null. If value of this parameter is false, null valued properties are omitted entirely from the output
        Returns:
        Returns the IValueMap representing the output of operation.
        Throws:
        DermisException
      • generateValue

        public static IValueMap generateValue​(IDataModel dataModel,
                                              java.util.Map<java.lang.String,​java.lang.Object> data,
                                              boolean autoCoerce,
                                              boolean generateNullForPropsNotInData,
                                              boolean removeComputedAttributes)
                                       throws DermisException
        Construct the value object according to provided DataModel structured based on result (Java Object) of operation execution.
        Parameters:
        dataModel - - DataModel according to which value object is constructed.
        data - - Result of operation execution.
        autoCoerce - - boolean value represent to auto coerce the value according to type
        generateNullForPropsNotInData - - boolean if this is true, child properties for which no value is present in data, are included in the output with value null. If value of this parameter is false, null valued properties are omitted entirely from the output
        Returns:
        Returns the IValueMap representing the output of operation.
        Throws:
        DermisException
      • generateValue

        public static IValueMap generateValue​(IDataModel dataModel,
                                              java.util.Map<java.lang.String,​java.lang.Object> data,
                                              java.util.List<? extends IDataModel> datamodels,
                                              boolean autoCoerce,
                                              boolean generateNullForPropsNotInData,
                                              boolean removeComputedAttributes)
                                       throws DermisException
        Construct the value object according to provided DataModel structured based on result (Java Object) of operation execution.
        Parameters:
        dataModel - - DataModel according to which value object is constructed.
        data - - Result of operation execution.
        datamodels - - List of datamodels to be used to resolve _type information present in data and construct value accordingly , if null no resolution will happen
        autoCoerce - - boolean value represent to auto coerce the value according to type
        generateNullForPropsNotInData - - boolean if this is true, child properties for which no value is present in data, are included in the output with value null. If value of this parameter is false, null valued properties are omitted entirely from the output
        removeComputedAttributes - - boolean if this is true, computed attributes will be removed from the output
        Returns:
        Throws:
        DermisException
      • jsonToValue

        public static IValue jsonToValue​(java.lang.String jsonString,
                                         IProperty property)
                                  throws DermisException,
                                         org.apache.sling.commons.json.JSONException
        Construct the value object based on the provided json string.
        Parameters:
        jsonString - - input json string.
        Returns:
        Returns the IValue representing the output of operation.
        Throws:
        DermisException
        org.apache.sling.commons.json.JSONException
      • jsonToValue

        public static IValue jsonToValue​(java.lang.Object data)
                                  throws DermisException,
                                         org.apache.sling.commons.json.JSONException
        Construct the value object based on the provided json object or array.
        Parameters:
        data - - data representing JSONArray or JSONObject
        Returns:
        Returns the IValue representing the output of operation.
        Throws:
        DermisException
        org.apache.sling.commons.json.JSONException
      • jsonObjectToValue

        public static IValueMap jsonObjectToValue​(org.apache.sling.commons.json.JSONObject data)
                                           throws DermisException,
                                                  org.apache.sling.commons.json.JSONException
        Construct the value object based on the provided JSONObject.
        Parameters:
        data - - data representing JSONObject
        Returns:
        Returns the IValue representing the output of operation.
        Throws:
        DermisException
        org.apache.sling.commons.json.JSONException
      • jsonListToValue

        public static IValueList jsonListToValue​(org.apache.sling.commons.json.JSONArray array)
                                          throws DermisException,
                                                 org.apache.sling.commons.json.JSONException
        Construct the value object based on the provided JSONArray.
        Parameters:
        array - - data representing JSONArray
        Returns:
        Returns the IValue representing the output of operation.
        Throws:
        DermisException
        org.apache.sling.commons.json.JSONException
      • getFormattedValue

        public static java.lang.Object getFormattedValue​(java.lang.Object value)
        Return formatted value for provided input. For date, it will return in ISO8601 format bytes, it will return base64 format of byte array. string and number are return in same format
        Parameters:
        value - - input value to format.
        Returns:
        - Return formatted value for provided input.
      • getValue

        public static IValue getValue​(IValueMap valueMap,
                                      java.lang.String name)
        Get the value object associated with a key.
        Parameters:
        valueMap - A JSONObject Object.
        name - A key string.
        Returns:
        The object associated with the key.