Utilities

Class finesse.utilities.Utilities

Collection of utility methods to deal with various text-related activities.

Methods

b64Decode(input)

Decodes a Base64 encoded string.

Note

The output is assumed to be UTF-8, and only the first 8 bits of each output element is significant.

Example

Code Snippet
Copyfinesse.utilities.Utilities.b64Decode(_base64String)

Parameters

Name

Type

Description

Required

input

String

The string to decode to Base64.

Yes

Returns

{String} The decoded string.

b64Encode(input)

Encodes a string to Base64.

Note

The input is assumed to be UTF-8, and only the first 8 bits of each output element is significant.

Example

Code Snippet
Copyfinesse.utilities.Utilities.b64Encode(a + ':' + b)

Parameters

Name

Type

Description

Required

input

String

The string to encode to Base64.

Yes

Returns

{String} The encoded string.

buildTimeString(timeInMs)

Builds a string that specifies the time in minutes and seconds.

Example

Code Snippet
Copyfinesse.utilities.Utilities.buildTimeString(70000)

Parameters

Name

Type

Description

Required

timeInMs

Integer

The time in milliseconds.

Yes

Returns

{String} The time in MINUTES:SECONDS. For example, 11:23.

buildTimeStringWithOptionalHours(timeInMs)

Builds a string that specifies the time in minutes, seconds, and optionally hours.

Example

Code Snippet
Copyfinesse.utilities.Utilities.buildTimeStringWithOptionalHours(11170000)

Parameters

Name

Type

Description

Required

timeInMs

Integer

The time in milliseconds.

Yes

Returns

{String} The time in HOURS:MINUTES:SECONDS or MINUTES:SECONDS. For example, 01:11:23 or 11:23.

buildTotalTimeString(adjustedServerTimeInMs, callStartTimeInMs)

Builds a string that specifies the total call time in minutes and seconds.

Example

Code Snippet
Copyfinesse.utilities.Utilities.buildTotalTimeString(3600000, 900000)

Parameters

Name

Type

Description

Required

adjustedServerTimeInMs

Integer

The expected server time in milliseconds accounting for time difference between the client and server.

Yes

callStartTimeInMs

Integer

The time in milliseconds when the call starts.

Yes

Returns

{String} The elapsed time in MINUTES:SECONDS.

convertDateToISODateString(aDate)

Converts the date object to an ISO date string.

Example

Code Snippet
Copyfinesse.utilities.Utilities.convertDateToISODateString(new Date())

Parameters

Name

Type

Description

Required

aDate

Date

The date to be converted to an ISO date format.

Yes

Returns

{String} The date in ISO format.

Note

Certain browsers do not support the date constructor which considers ISO-8601 date format. For example, Internet Explorer 8.

convertNullToEmptyString(str)

Checks whether the string is null.

Example

Code Snippet
Copyfinesse.utilities.Utilities.convertNullToEmptyString(null)

Parameters

Name

Type

Description

Required

str

String

The string object to be checked.

Yes

Returns

{String} The empty string if it is null or the string itself.

convertToServerTimeMillis(clientTime)

Converts the client time to the server time by adjusting time difference between server and client.

Example
Code Snippet
CopyconvertToServerTimeMillis(new Date().getTime());

Parameters

Name

Type

Description

Required

clientTime

Integer

The client time in milliseconds.

Yes

Returns

{Integer} The server time in milliseconds.

convertTsToDuration(timestamp, now)

Converts the timestamp string of the format YYYY-MM-DDTHH:MM:SSZ into a duration of HH:MM:SS format.

Example

Code Snippet
Copyfinesse.utilities.Utilities.convertTsToDuration(a)

Parameters

Name

Type

Description

Required

timestamp

String

The timestamp of the format YYYY-MM-DDTHH:MM:SSZ.

Yes

now

Date

The defined time from which to calculate the duration instead of using the current time.

Optional

Returns

{String} The duration in the HH:MM:SS format.

convertTsToDurationWithFormat(timestamp, forFormat, now)

Converts the timestamp string of the format YYYY-MM-DDTHH:MM:SSZ into a duration of HH:MM:SS format or -1 for null or negative durations, depending on the forFormat parameter.

Example

Code Snippet
Copyfinesse.utilities.Utilities.convertTsToDurationWithFormat(a, true, new Date())

Parameters

Name

Type

Description

Required

timestamp

String

The timestamp of the format YYYY-MM-DDTHH:MM:SSZ.

Yes

forFormat

Boolean

Determines the timestamp format.

  • True—If the duration is null or a negative value, -1 is returned. Otherwise, the duration is in HH:MM:SS format.

  • False—The duration in HH:MM:SS format.

Yes

now

Date

The defined time from which to calculate the duration instead of using the current time.

Optional

Returns

{String} The duration in the HH:MM:SS format or -1 for null or negative values.

currentServerTimeMillis()

Retrieves the current time, which is adjusted by the calculated time difference to the approximate server time. This is used when calculating durations based on a server timestamp, which can produce unexpected results if the clock on the client and server are off.

Example

Code Snippet
Copyfinesse.utilities.Utilities.currentServerTimeMillis()

Returns

{String} The current server time in milliseconds.

encodeNodeName(node)

Encodes the node name.

Example

Code Snippet
Copyfinesse.utilities.Utilities.encodeNodeName('User1@h')

Parameters

Name

Type

Description

Required

node

String

The name of the node. If the string has special characters (?, @, &, ') then, the string is encoded in UTF-8.

Yes

Returns

{String} The encoded name of the node.

escapeSpaces(text)

Escapes the spaces as encoded " " characters so they can be safely rendered by jQuery.text(string) in all browsers. Although Internet Explorer behaves as expected, Firefox collapses spaces if this function is not used.

Example

Code Snippet
Copyfinesse.utilities.Utilities.escapeSpaces('User John')

Parameters

Name

Type

Description

Required

text

String

The string whose spaces must be escaped.

Yes

Returns

{String} The string with spaces escaped.

extractHostname(url)

Extracts the hostname from a given URL string.

Example

Code Snippet
Copyfinesse.utilities.Utilities.extractHostname(a)

Parameters

Name

Type

Description

Required

url

String

The URL from which the hostname of the server is extracted.

Yes

Returns

{String} The hostname of the server. For example, if the given URL is https://finesse25.autobot.cvp:8445/desktop/container/?locale=en_US, then the returned hostname will be "finesse25.autobot.cvp".

extractTime(timeStr)

Extracts the time in milliseconds from the ISO date string.

Example

Code Snippet
Copyfinesse.utilities.Utilities.extractTime('2020-05-25T13:49:42.80Z')

Parameters

Name

Type

Description

Required

timeStr

String

The time in ISO-8601 format (YYYY-MM-DDTHH:mm:ss.sssZ) or empty.

Yes

Returns

{Long} The number of milliseconds since 1 January 1970 (Unix Epoch). If the timeStr is empty, then the time returned is 0.

generateUUID()

Generates an RFC1422v4-compliant UUID using pseudorandom numbers.

Example
Code Snippet
Copyfinesse.utilities.Utilities.generateUUID()

Returns

{String} An RFC1422v4-compliant UUID using pseudorandom numbers. For example, 456efbab-d794-4c7a-a731-762e476eb4d3.

getAuthHeaderString(configObj)

Retrieves the authorization header that is based on SSO or non-SSO deployment. The headers are Bearer or Basic.

Example

Code Snippet
Copyfinesse.utilities.Utilities.getAuthHeaderString(finesse.container.Config)

Parameters

Name

Type

Description

Required

configObj

Object

The configuration data which is either the finesse.container.Config or finesse.gadget.Config.

For more information on gadget configuration, see Gadget Configuration.

Yes

Returns

{String} The authorization header based on SSO or non-SSO deployment. For example,

SSO: Bearer MTAwMTAwMjpjaXNjbw==

NON-SSO: Basic MTAwMTAwMjpjaXNjbw==

getAuthModes()

Retrieves the constant for authentication modes. The modes are SSO, NON_SSO, or HYBRID.

Example

Code Snippet
Copyfinesse.utilities.Utilities.getAuthModes()

Returns

{String} The constant for authentication modes, that is SSO, NON_SSO, or HYBRID.

getAuthTokenObj()

Retrieves the user access token as JSON Object.

Example

Code Snippet
Copyfinesse.utilities.Utilities.getAuthTokenObj()

Returns

{Object} A user access token as the JSON object in SSO mode and null in non-SSO mode.

getCurrentDrift()

Retrieves the current timestamp difference between the client and server.

Example

Code Snippet
Copyfinesse.utilities.Utilities.getCurrentDrift()

Returns

{Integer} The timestamp difference between the client and server. If it cannot be calculated, then it returns 0.

getDisplayTime(time)

Retrieves the timestamp value from milliseconds to the HH:MM:SS format.

Example

Code Snippet
Copyfinesse.utilities.Utilities.getDisplayTime(60000)

Parameters

Name

Type

Description

Required

time

Number

The timestamp in milliseconds.

Yes

Returns

{String} The time string in the HH:MM:SS format.

getEquals(obj1, obj2)

Retrieves the value by comparing the value of each key in the first object with the value of the same key in the second object.

Example

Code Snippet
Copyfinesse.utilities.Utilities.getEquals(x,y)

Parameters

Name

Type

Description

Required

obj1

Object

The first object to compare from. For example, x={'a': 1, 'b': 2}.

Yes

obj2

Object

The second object to compare against. For example, y={'b': 2, 'a': 1}.

Yes

Returns

{Boolean} True if the value of each key in the first object matches the value of the same key in the second object. False, if the value of at least one key in the first object does not match the value of the same key in the second object.

getParameterByName(str, name)

Accepts the value from the corresponding given string.

Example

Code Snippet
Copyfinesse.utilities.Utilities.getParameterByName('http://www.company.com/?param1=value1&param2=value2', 'param1')

Parameters

Name

Type

Description

Required

str

String

The string to search from. The URL from which parameter value is extracted based on the given parameter name.

Yes

name

String

The name to search for. The name of the parameter whose value must be extracted from the given URL string.

Yes

Returns

{String} The value that corresponds to the given name.

getQueryString(field, url)

Retrieves the value of the given field from the query string.

Example

Code Snippet
Copyfinesse.utilities.Utilities.getQueryString('name', 'https://finesse/?name=user');

Parameters

Name

Type

Description

Required

field

String

The name of the field in the query string to retrieve.

Yes

url

String

The URL value from the query string to retrieve.

Optional

Returns

{String} The field value.

getToken()

Retrieves the user access token as a string.

Example

Code Snippet
Copyfinesse.utilities.Utilities.getToken()

Returns

{String} The access token.

getUserAuthString()

Retrieves the Base64 encoded user authorization string.

Example

Code Snippet
Copyfinesse.utilities.Utilities.getUserAuthString()

Returns

{String} The authorization string.

isArray(obj)

Determines whether an object is an array.

Example

Code Snippet
Copyfinesse.utilities.Utilities.isArray(a)

Parameters

Name

Type

Description

Required

obj

Object

The object to be tested.

Yes

Returns

{Boolean} True if the object is an array, else false.

parseDateStringISO8601(s)

Parses the string with ISO-8601 date format: YYYY-MM-DDTHH:mm:ss.sssZ.

Example

Code Snippet
Copyfinesse.utilities.Utilities.parseDateStringISO8601(new Date().toISOString())

Parameters

Name

Type

Description

Required

s

String

ISO-8601 date format: YYYY-MM-DDTHH:mm:ss.sssZ.

Yes

Returns

{Date} The JavaScript date object.

Note

Certain browsers do not support the date constructor which considers ISO-8601 date format. For example, Internet Explorer 8.

removeSpaces(string)

Removes all spaces from the given string.

Example

Code Snippet
Copyfinesse.utilities.Utilities.removeSpaces('user is')

Parameters

Name

Type

Description

Required

string

String

The string to remove spaces from.

Yes

Returns

{String} The string with no leading and trailing whitespace.

trim(str)

Trims the leading and trailing whitespace from the given string.

Example

Code Snippet
Copyfinesse.utilities.Utilities.trim('user ')

Parameters

Name

Type

Description

Required

str

String

The string to trim.

Yes

Returns

{String} The string with removed whitespace from both ends.

validateHandler(handler)

Checks whether the given handler is a function.

Example

Code Snippet
Copyfinesse.utilities.Utilities.validateHandler(a);

Parameters

Name

Type

Description

Required

handler

Function

Any valid JavaScript function.

Yes

Throws

{Error} If the handler provided is invalid, or generic JavaScript error stating handler must be a function.

Returns

{Function} The provided handler if it is valid.

whenAllDone()

Uses jQuery implementation of Promises (Deferred) to run the code when multiple asynchronous processes have completed.

Example

Code Snippet
Copyvar asyncProcess1 = $.Deferred(),
    asyncProcess2 = $.Deferred();

finesse.utilities.Utilities.whenAllDone(asyncProcess1, asyncProcess2) // WHEN both asyncProcess1 and asyncProcess2 are resolved or rejected ...
    .then(
        // First function passed to then() is called when all async processes are complete, regardless of errors
        function() {
            // Perform Logic("all processes completed");
        },
        // Second function passed to then() is called if any async processed threw an exception
        function(failures) { // Array of failure messages
            // Perform Logic("Number of failed async processes: " + failures.length);
        });

Returns

{Object} A jQuery deferred object. For more information, see https://api.jquery.com/jQuery.Deferred/.