Skip to content
QiTASC.com / intaQt Built-ins /
Common Built-ins
/ .. /
Common Built-ins





Common Built-ins

Common Built-ins provide general functionality for:

Sorting List of Maps

The map sorting function provides the ability to sort lists of maps by a common key key so that they are ordered as required. Additionally, the list's sorting can be specified as ascending or descending.

Syntax

1
Common.sortListOfMaps(<listOfMaps List<Map<Any, Any>>>, <sortByKeyInOrder Map<Any, Boolean>>)

Parameters

  • listOfMaps - The list of maps to be sorted
  • Values in the maps must be comparable (for example string, date, number or boolean), otherwise an exception will be thrown

  • sortByKeyInOrder - Sorts the list of maps passed to the function and does not return any other value

  • The keys must match the keys in the list's maps
  • The values of the key/value pair must be boolean, with true sorting in ascending order and false sorting in descending order

Example

1
2
3
4
5
6
7
stepdef "sort test"
    list := [{"key1" : 10, "key2" : 20},
             {"key1" : 20, "key2" : 0},
             {"key1" : 0, "key2" : 50},
             {"key1" : 0, "key2" : 25}]
    Common.sortListOfMaps(list, {"key1" : false})
end

Results in:

1
2
3
4
5
list == [{"key1" : 20, "key2" : 0},
         {"key1" : 10, "key2" : 20},
         {"key1" : 0, "key2" : 50},
         {"key1" : 0, "key2" : 25}]
end

Group Lists of Maps

The map grouping function provides an SQL-like group-by functionality with the ability to aggregate all other key-value entries. The groupListOfMaps function creates a temporary object on which an aggregate logic must be applied to retrieve results.

Syntax

1
2
<result List<Map<Any, Any>> := Common.groupListOfMaps(<listOfMaps List<Map<Any, Any>>>, <groupingKeys List<Any>>)
        .aggregate(<aggregateFunctionMap Map<any, String>>)

Parameters

  • listOfMaps - The list of maps to be grouped
  • Their values do not need to be comparable if proper aggregate functions are applied

  • groupingKeys - The list of keys on which maps must be grouped

  • If the list of grouping keys has more than one entry, the maps will be grouped together if the corresponding keys' values between these maps are equal

  • aggregateFunctionMap - The map of aggregate functions

  • For this function, the object is the key on which the aggregation must be performed
  • The string is the name of the aggregate function

    • It must be one of the following:
  • LIST - Makes a list out of grouped values * If only one map was grouped, a list for one value will be created

  • COUNT - Maps the key to the amount of found grouped maps

  • SUM - Maps the key to the sum of grouped integers

  • MAX - Maps the key to the maximum value of the grouped values (values must be comparable)

  • MIN - maps the key to the minimum value out of grouped values (values must be comparable)

Note: The aggregate function should map remaining keys (although not necessarily all) after the grouping function has been called.

Example

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
stepdef "group test"
    list := [{"key1" : 10, "key2" : 20},
             {"key1" : 20, "key2" : 0},
             {"key1" : 0, "key2" : 50},
             {"key1" : 0, "key2" : 25}]
    resultingList := Common.groupListOfMaps(list, ["key1"])
        .aggregate({"key2" : "SUM"})
    println("resultingList(0)[key2] = " + resultingList[0]["key2"]) // 20
    println("resultingList(1)[key2] = " + resultingList[1]["key2"]) // 0
    println("resultingList(2)[key2] = " + resultingList[2]["key2"]) // 75
end

PDF Form Filling

The PDF form filling methods provide a functionality to fill editable AcroForms or write text using specified coordinates. The getPdfDocument function is used to get an instance of the PDF document. Additional functions for text fields, choice fields and checkboxes can then be applied before saving and closing the modified document.

Syntax

1
2
3
4
5
6
<pdfDocument PdfDocumentObject> := Common.getPdfDocument(<pdfFilePath String>)

...

pdfDocument.save(<saveFilePath String>)
pdfDocument.close()

Parameters

  • pdfDocument - The name assigned to the PDF document objet

  • pdfFilePath - The path to the PDF document that will be filled

  • saveFilePath - The file path to where the PDF document will be saved

Example

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
stepdef "PDF check"
    pdfDocument := Common.getPdfDocument("/Users/user/Documents/simple.pdf")
    println(pdfDocument.getText())
    for fieldIndex, field in pdfDocument.getTextFieldNames()
        println(field)
    end
    pdfDocument.setTextFieldValues(["Firstname", "Lastname", "Address"])
    pdfDocument.check("checkbox1")
    pdfDocument.uncheck("checkbox2")
    pdfDocument.setChoiceFieldValue("listbox", "Item 1")
    pdfDocument.save("/Users/user/Documents/filled_simple.pdf")
    pdfDocument.close()
end

Available Builder Methods

The PDF form filling function has methods for text fields, choice fields and checkbox fields. Additionally, general methods are available for getting text from the document as well as saving and closing it.

Text Fields

Text field methods are used for retrieving and setting text within text fields.

  • getTextFieldNames() - Retrieves the text field names from the AcroForm as a list of strings

  • setTextFieldValues() - Sets the text fields' values in the depth-first-search (DFS) order of fields, as structured in the AcroForm

  • setTextFieldValue(, ) - Changes the value's field, as specified by its name

  • getTextFieldValue() - Retrieves the text field's current value, as specified by the given name

Choice Fields

Choice field methods are used for retrieving choice field names, options and values, as well as setting values.

  • getChoiceFieldNames() - Retrieves the choice field names from the AcroForm as strings

  • setChoiceFieldValues(>) - Changes the choice field's values in the DFS order of fields, as structured in the AcroForm

  • setChoiceFieldValue(>, >) - Changes the fields value, as specified by its name

  • getChoiceFieldOptions() - Retrieves the choice field's list of possible options, as specified by field name

  • getChoiceFieldValue() - Retrieves the current value as a list of the selected values, as specified by the choice field name

Checkboxes

The checkbox methods retrieve checkbox names, set their values, and can check, uncheck or confirm the state of the checkbox.

  • getCheckboxNames() - Retrieves the checkbox names form the AcroForm as strings

  • setCheckboxValues(>) - Changes the checkbox's values in the DFS order of checkboxes, as structured in the AcroForm

  • check() - Checks the specified checkbox

  • uncheck() - Unchecks the specified checkbox

  • isChecked() - Retrieves the specified checkbox's boolean value, based on the checkbox's current state

General Methods

  • getText() - Retrieves the text from the PDF document

  • save() - Saves the PDF document to the specified path

  • close() - Closes the PDF document instance and releases the resources taken

PDF Text Writer

The PDF text writer function enters text into a PDF. Characteristics about the text such as font, font size and color can be specified.

Syntax

1
2
3
4
5
6
7
8
9
<pdfDocument PdfDocumentObject> := Common.getPdfDocument(<pdfFilePath String>)
textWriter := pdfDocument.getTextWriter(<pageNumber Number>)
textWriter.setFont(<font String>, <fontSize Number>)
textWriter.setColor(<red Number>, <green Number>, <blue Number>)
textWriter.setColor(<red Number>, <green Number>, <blue Number>, <alpha Number>)
textWriter.setPosition(<xCoordinate Number>, <yCoordinate Number>)
textWriter.newLineAtOffset(<xDeltaCoordinate Number>, <yDeltaCoordinate Number>)
textWriter.addText(<text String>)
textWriter.close()

Parameters

  • pdfDocument - The variable that holds the PDF document

  • pdfFilePath - The file path to the PDF document

  • getTextWriter - Retrieves the specified page for adding text to the PDF's specified page

  • Counting starts from 0

  • font - The font being set

  • May be one of:
  • Courier, Courier-Bold Courier-Oblique, Courier-BoldOblique, Helvetica, Helvetica-Bold, Helvetica-Oblique, Helvetica-BoldOblique, Symbol, Times-Roman, Times-Bold, Times-Italic, Times-BoldItalic or ZapfDingbats

  • fontSize - The font's size

  • color - When setting the color, the red, green and blue channel numbers (ranging from 0 to 255) must each be set

  • alpha - When added after the color settings, this adjusts the font color's opacity

  • Can range from 0 to 255

  • xCoordinate and yCoordinate - Moves coordinates for the next text to the specified coordinates

  • xDeltaCoordinate and yDeltaCoordinate - Moves coordinate of the next text by the specified shifted amount

  • text - The text to be added

Example

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
stepdef "PDF text"
    pdfDocument := Common.getPdfDocument("/Users/user/Documents/simple.pdf")
    pdfDocument.getTextWriter(0)
        .setFont("Helvetica", 16)
        .setColor(0, 0, 0) // black
        .moveTextPositionByAmount(50, 600)
        .addText("John")
        .moveTextPositionByAmount(0, -20)
        .addText("Doe")
        .close()
    pdfDocument.save("/Users/user/Documents/filled.pdf")
    pdfDocument.close()
end