Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

The valueFormatter can also be used outside the JSON-generation.

3.1 - Data model

3.2 - JSONTagDef

A record in the JSON_TAG_DEF defines a single tag (key/value pair) of the resulting JSON file, and it has the following attributes:

3.

...

2.1 - Columns

TAG_NAMEName of the tag. For example currency, amount, Name, Voucher, Id, brand etc
MAP_KEY

Key to retrieve the correct component from the map. Example: HEADER or FILEDEF or RECORD_DEF or tag name of the parent record from which a child tag value can be obtained.

HEADER holds the file source record.

FILEDEF holds the current instance of JSONDocumenrFiller.

RECORD_DEF holds the CDR_RECORD_DEF (with CODE = DETAIL) instance set up for this JSON Document export

VALUE_TYPECan be FIELD (if the value to print is a field of the map object) or METHOD (if the content is retrieved calling a specific method in the map object obtained via the key set in MAP_KEY).
FIELD_NAMEIf the value type is FIELD then this specify the field to print in the JSON tag content.
METHOD_NAMEif the value type is METHOD, then this specify the method to invoke on the map object to retrieve the data to fill the content for the current tag.
JSON_DATA_TYPE

The data type with which the JSON field value should be represented while writing value to file. Possible value are OBJECT, ARRAY, STRING, NUMBER andBOOLEAN.

  • OBJECT, ARRAY types can be used only for the parent tag types (i.e JSON_TAG_DEF  entries that have children). 
  • STRING, NUMBER, BOOLEAN types can be used only for the JSON_TAG_DEF entries that do not have any children.

Please see: Value Formatter and How to use VALUE_FORMATTER and JSON_DATA_TYPE for more details

Note: JSON Key names will always be surrounded by double quotes. This JSON_DATA_TYPE configuration settings are applicable only for values, not the keys.

JSON_DATA_TYPE

value

Description of behaviorExample
OBJECT (Default setting for the JSON_TAG_DEF  entries that have children)

Can be used only for the parent tag types.

If this type is chosen, the children of this parent tag will be surrounded by curly braces { }

JSON Tag Voucher is set up as OBJECT type

  • JSON_TAG_DEF.TAG_NAME = voucher, JSON_DATA_TYPE = OBJECT / empty
  • Resulting line in JSON file: 
    "voucher" : { "id" : "12345","serial_number" : "12345","secret_code" : "12345" }
ARRAY

Can be used only for the parent tag types.

If this type is chosen, the children of this parent tag will be surrounded by square brackets [ ]

JSON Tag Voucher is set up as OBJECT type

  • JSON_TAG_DEF.TAG_NAME = voucher, JSON_DATA_TYPE = ARRAY
  • Resulting line in JSON file: 
    "voucher" : [ "id" : "12345","serial_number" : "12345","secret_code" : "12345" ]
STRING (Default setting for JSON_TAG_DEF  entries that do not have any children)

Can be used only for the JSON_TAG_DEF entries that do not have any children.

Resulting value will be surrounded by double quotes.

JSON_TAG_DEF.TAG_NAME = brand

Actual Field Value

Result After Choosing

JSON_DATA_TYPE = STRING

Resulting key value pair in JSON file

XYZ

"XYZ""brand" : "XYZ"
NUMBER

Can be used only for the JSON_TAG_DEF entries that do not have any children.

Resulting value will not have double quotes around. Should be used for presenting numeric type values in JSON file.

JSON_TAG_DEF.TAG_NAME = count

Actual Field Value

Result After Choosing

JSON_DATA_TYPE = NUMBER

Resulting key value pair in JSON file

43

43"count" : 43
BOOLEAN

Can be used only for the JSON_TAG_DEF entries that do not have any children.

Boolean equivalent of the actual field value gets written to the json file. Resulting value will not be surrounded by double quotes

JSON_TAG_DEF.TAG_NAME = exported

Actual Field Value

Result After Choosing

JSON_DATA_TYPE = BOOLEAN

Resulting key value pair in JSON file
1true"exported" : true
0false"exported" : false
abcdefgfalse"exported" : false
Ytrue"exported" : true
Truetrue"exported" : true
PARENT_IDDefines the ID of the parent tag and therefore it is used to define the structure of the JSON-file. The parent ID for the root tag will be null.
FLUSH_CONTENTif ‘Y’ the content generated in the outputStream will be flushed in the JSON-file when the end tag of the current tag is printed.
FORMATTER_ID

ID of appropriate VALUE_FORMATTER table entry that is suitable to format this field value. The value formatter used to format the JSON field value, before applying the JSON_DATA_TYPE. So, first the Value formatter is applied to the field value, and then the JSON_DATA_TYPE setting is applied.

Please see: Value Formatter and  How to use VALUE_FORMATTER and JSON_DATA_TYPE for more details

METHOD_INPUTIn some cases when the METHOD_NAME is invoked we also need some extra information that must be passed in the method. For instance in the cdr generation if we have a list of invoice detail lines inside the record tag we need to retrieve only the invoice detail lines related to that billing record and this can be done by defining in this field the tag name related to the object to pass: in this case it will be “Record”.
METHOD_INPUT_CLASS_NAMEThis is the class name of the method_input field (“com.CDRator.billing.rating.BillingRecords” in this example).
SEQ_ORDERIf a tag has more than one child, here we can specify the preferred order to print them.
RELOAD_METHODIf the tag to print is related to a list (i.e. a list of records) then it is possible to load them in multiple batches. In the JSON file generation when the content of the current batch has been printed then we try to retrieve further elements using the reload method if set.

3.

...

3 - DocumentDef

An DocumentDef models the definition for a document type for example JSON. Here a filler class can be defined that will contain the logic to fill the map with the data, the methods to be called and also the reload method.

3.

...

3.1 - Columns

DESCRIPTIONShort description of the document definition
KEYUnique key to retrieve the document definition
FILLER_CLASSClass name used to generate the map for this specific type of document. This class will also be part of the map (with key "FILEDEF") if it is needed to call methods inside the filler to retrieve data.
ROOT_TAG_IDReference of the Root tag of the document.
SQL_LOAD_RECORDSContains the SQL-query to obtain the records that should be exported to the file. This SQL-query string can contain the label <BILLING_SOURCE_ID> which will be replaced with appropriate value at run-time.
SQL_RELOAD_RECORDSContains the SQL-query to load the next batch of records with ID greater than the last loaded maximum ID, which are to be exported into the JSON-file.  This is used only if the reload_method is setup on at least one of the JSON_TAG_DEF entries. This SQL-query can contain the tags <BILLING_SOURCE_ID> and <MAX_LOADED_ID> labels which will be replaced with appropriate values at run-time

3.

...

4 - DocumentFiller

An abstract class DocumentFiller has been defined with an abstract method populate that will generate the dataBeans map according to a context map.

...

Following Concrete sub-classes of DocumentFiller can be found in the FileProcessor Integration project. See JSONDocumentFiller for more details

3.

...

4.1 - JSONDocumentFiller 

The JSONDocumentFiller class contains the logic for generating the JSON-files from data obtained by joining some database tables by executing the SQL-script configured via the corresponding DOCUMENT_DEF record.  If the desired JSON-file format cannot be achieved with JSONDocumentFiller sub class, A new subclass of  DocumentFiller must be created as per the requirements.

...

  • The query from SQL_LOAD_RECORDS column is used to load the first batch of records (10000).
  • If there are more records to be added to the same JSON file and the reload_method on one of the JSON_TAG_DEF entries is set to 'reloadRecords', the SQL from SQL_RELOAD_RECORDS column is used to load the next batches, with 10000 max rows selected in each subsequent batch, until all pending records have been added to the file.

3.

...

5 - ValueFormatter

The value formatter is used in order to be able to configure the formatting of field values. Here a formatter class and a pattern can be specified that will be used to generate a string.

...

Value Formatter

implementation

DescriptionExample
com.CDRator.billing.utils.formatter.DateFormatterUsed to format a Date object to a String according the pattern set on this Value_Formatter entry.

Input value Type: Date

Pattern: dd.MM.yyyy

Input value: 26-11-2015 10:00:00

Result: 26.11.2015

com.CDRator.billing.utils.formatter.NumberFormatter

Used to format a Number to a String according the pattern set on this Value_Formatter entry.

Input value Type: any number type

Pattern: #,##0.00

Input value: 200

Result: 200.00

com.CDRator.billing.utils.formatter.XmlStringFormatter

Used to escape a String to be compatible with XML format

Input value Type: String

Input value: x>y

Result: x&gt;y

com.CDRator.billing.utils.formatter.JsonStringFormatter

Used to escape a String to be compatible with JSON format

Input value Type: String

Input value: 'test'

Result: \'test\'

3.

...

5.1 - Columns

NAMEA unique name to distinguish different Formatters
CODEFormatter code
DESCRIPTIONDescribes the purpose of the formatter
VALUE_CLASS

Defines the input for the formatter (i.e. java.util.Date or java.lang.Number or java.lang.String)

Important Note: The formatter should be chosen based on the actual value type. If the value type is not compatible with the java type defined in VALUE_FORMATTER.VALUE_CLASS, the formatting fails and hence file generation fails.

  • If the value to be formatted is a String, then use a Value_Formatter that has the VALUE_CLASS = 'java.lang.String'
  • If the value to be formatted is a Number type (int or long or Amount or float or Integer etc..), then use a Value_Formatter that has the VALUE_CLASS = 'java.lang.Number'
  • If the value to be formatter is a Date, then use a Value_Formatter that has the VALUE_CLASS = 'java.util.Date'
FORMATTER_CLASSClass used to format ( For example: com.CDRator.billing.utils.formatter.DateFormatter)
FORMATTER_METHODMethod name from the class defined in FORMATTER_CLASS, that should be executed to format the input value. Usually it is 'format'.
FORMATTER_EXPRESSION

Pattern used to convert the object to formatted string. This is optional for the formatters that do not require a pattern to be defined.

Examples:

  • “dd.MM.yyyy” to format a Date object to a string in this format
  • “#,##0.00” to format a Number to decimal format String
NULL_VALUE

Value returned if the input object is null. This is optional and defaults to null.

3.

...

5.2 - How to use VALUE_FORMATTER and JSON_DATA_TYPE to get desired result

It is possible to represent the field values in a JSON Document in different ways. If the value should be represented as a string, it will be surrounded by double quotes. If it has to be written to the JSON file as a Number, no double quotes will be placed around the value. If the value should be represented as a boolean, the boolean equivalent of the actual field value (i.e. true/false) will be written to the JSON file. Consider the following scenarios:

...