Skip to content
Nuno Aguiar edited this page Apr 24, 2018 · 3 revisions

ow.obj.big.create

ow.obj.big.create(shouldCompressKeys) : Object

Creates a "big" map object that compresses contents in memory. Optionally if shouldCompressKeys = true the key map will also be compressed. See also:

ow.obj.big.set
ow.obj.big.setAll
ow.obj.big.get
ow.obj.big.find


ow.obj.big.find

ow.obj.big.find(aFunction) : Array

Will execute the provided aFunction providing each key available. For the keys where the function returns true the corresponding value will be gathered into the final resulting array.


ow.obj.big.get

ow.obj.big.get(aKeyMap) : Map

Retrieves a value map given the provided aKeyMap.
Example:

var big = ow.obj.big.create();
var data = [
{"name": "Anne", "country": "USA", "company": "Wedo"},
{"name": "Rui", "country": "Portugal", "company": "Wedo"},
{"name": "Paulo", "country": "Portugal", "company": "Sonae"},
{"name": "Peter", "country": "USA", "company": "ACME"},
{"name": "Louis", "country": "USA", "company": "ACME"}
];
big.setAll(["name"], data);
big.get({"name": "Rui"}); // {"name": "Rui", "country": "Portugal", "company": "Wedo"}


ow.obj.big.getSize

ow.obj.big.getSize() : Number

Returns the current number of keys available.


ow.obj.big.remove

ow.obj.big.remove(aKeyMap)

Removes aKeyMap and corresponding value.


ow.obj.big.set

ow.obj.big.set(aKeyMap, aValueMap, aTimestamp)

Sets aValueMap associated with a aKeyMap. Optionally you can set the internal aTimestamp for the record.
Example:

var big = ow.obj.big.create();
big.set({"name": "Anne"}, {"name": "Anne", "country": "USA", "company": "Wedo"});


ow.obj.big.setAll

ow.obj.big.setAll(anArrayKeyNames, anArrayOfValues, aTimestamp)

Given anArrayOfValues will set them internally using the keys on anArrayKeyNames to define the corresponding keys. Optionally you can set the internal aTimestamp for the record.

Example:

var big = ow.obj.big.create();
var data = [
{"name": "Anne", "country": "USA", "company": "Wedo"},
{"name": "Rui", "country": "Portugal", "company": "Wedo"},
{"name": "Paulo", "country": "Portugal", "company": "Sonae"},
{"name": "Peter", "country": "USA", "company": "ACME"},
{"name": "Louis", "country": "USA", "company": "ACME"}
];
big.setAll(["name", "country"], data);


ow.obj.diff

ow.obj.diff(aOriginalJSON, aFinalJSON, optionsMap) : String

Produces a string representation with the difference between aOriginalJSON and aFinalJSON.
If optionsMap.printColor = true it will be immediately print with ANSI colors if available.
If optionsMap.justAnsi it won't print and just produce the ANSI color codes.
If optionsMap.justChanges = true only the changed lines will be represented with the rest.
If optionsMap.justDiff = true only the changed lines will be included.


ow.obj.filterKeys

ow.obj.filterKeys(anArrayKeyNames, aMap) : Map

Given aMap will return an equivalent Map with only the keys contained in the anArrayKeyNames. Note: doesn't traverse existing sub-maps.


ow.obj.flatten

ow.obj.flatten(arrayOfMaps, aSeparator, aNADefault) : Array

Converts any structured arrayOfMaps into a flat array of maps with only one level of keys. The map key path will be converted into a single key using aSeparator (defaults to "_") and the value will be represented as aNADefault (defaults to "") when no  value or key exists in other entries. For each array entry a new array element will be created replicated all other keys. Usefull to convert data to output into CSV for example.


ow.obj.fromArray2DB

ow.obj.fromArray2DB(anArray, aDB, aDBFrom, useParallel) : Number

Given anArray composed of maps where each key is a field name tries to insert into the aDBFrom (table or query between '(', ')') for a provided aDB. Optionally you can specify how many threads should be used with useParallel. This function doesn't perform any database commit. Returns the number of records inserted. (available after ow.loadObj())


ow.obj.fromArray2Obj

ow.obj.fromArray2Obj(anArray, aKey, dontRemove) : Array

Tries to create a map of maps from the provided anArrays. Optionally if aKey is provided it will be used to create the map keys (otherwise will fallback to "row[number]"). And can also optionally indicate by dontRemove = true that aKey shouldn't be removed from each map.
var a = {
  "A1": { "abc": "123", "xpt": "000" },
  "A2": { "abc": "456", "xpt": "001" },
  "A3": { "abc": "789", "xpt": "002" }
}

fromObj2Array(a, "key");
// [
//  { "abc": "123", "xpt": "000", "key": "A1" },
//  { "abc": "456", "xpt": "001", "key": "A2" },
//  { "abc": "789", "xpt": "002", "key": "A3" }
// ]


ow.obj.fromArray2OrderedObj

ow.obj.fromArray2OrderedObj(anArray) : Map

Converts the provided anArray into a Map where each array entry is converted to a map entry  which ordered will provide the same ordering found on the array. (available after ow.loadObj())


ow.obj.fromDBRS2Obj

ow.obj.fromDBRS2Obj(aDBRS, doDates) : Map

Converts a Java database result set object (retrieved with DB.qsRS) into a map where the key is the name of the field in upper case. Optionally doDates will convert any SQL dates into javascript Date objects.


ow.obj.fromJson

ow.obj.fromJson(aJson) : Object

Creates an object or objects, using the aJson and the indication of the object prototypes to use. This is based on JMix from https://github.com/khayll/jsmix.
Example:

var Point = function() {};
Point.prototype.getX = function() { return this.x; }
Point.prototype.getY = function() { return this.y; }

ow.obj.fromJson({ x: 1, y: 2 }).withObject(Point.prototype).build().getX(); // 1

var mylines = { "lines": [
  { "name": "line 1", "points": [ { x: 0, y: 0}, { x: 5, y: 6} ] },
  { "name": "line 2", "points": [ { x: -5, y: -5}, { x: 1, y: 3} ] },
]};

var res = ow.obj.fromJson(mylines).withObject(Point.prototype, "lines..points.").build();
res.lines[1].points[1].getY(); // 3


ow.obj.fromObj2Array

ow.obj.fromObj2Array(anObj, aKey) : Array

Tries to create an array of maps from the provided anObj map of maps. Optionally if aKey is provided it will be added to each array map with the map key. Example:

var a = {
  "A1": { "abc": "123", "xpt": "000" },
  "A2": { "abc": "456", "xpt": "001" },
  "A3": { "abc": "789", "xpt": "002" }
}

fromObj2Array(a, "key");
// [
//  { "abc": "123", "xpt": "000", "key": "A1" },
//  { "abc": "456", "xpt": "001", "key": "A2" },
//  { "abc": "789", "xpt": "002", "key": "A3" }
// ]


ow.obj.fromOrderedObj2Array

ow.obj.fromOrderedObj2Array(aMap, aKeySortFunction) : Array

Converts a provided aMap into an array where each element will be composed from the maps entries ordered by the corresponding key. Optionally you can provide aKeySortFunction that will accept two arguments and work similarly to javascript's array sorting functions. (available after ow.loadObj())


ow.obj.fuzzySearch

ow.obj.fuzzySearch(anArrayOfKeys, anArrayOfObjects, searchString, fuseOptions) : Array

Given anArrayOfObjects (similar objects) will fuzzy search the searchString on the values for the keys in anArrayOfKeys. Returns an array of the most probable objects to match the searchString (you can use fuseOptions = { shouldSort: true } to  ensure that the array is ordered by score). It uses the FuseJS library internally so fuseOptions can be used to add more options (check more in http://fusejs.io/).

For example:
  ow.obj.fuzzySearch(["n"], [{n: "World War I"}, {n: "World War II"}, {n: "Name a war"}, {n: "Name some war"}], "world");


ow.obj.getPath

ow.obj.getPath(aObject, aPath) : Object

Given aObject it will try to parse the aPath a retrive the corresponding object under that path. Example:

var a = { a : 1, b : { c: 2, d: [0, 1] } };

print(ow.obj.getPath(a, "b.c")); // 2
sprint(ow.obj.getPath(a, "b.d")); // [0, 1]
print(ow.obj.getPath(a, "b.d[0]")); // 0


ow.obj.pmSchema.applySchema

ow.obj.pmSchema.applySchema(aJavaPM, aSchema) : JavaParameterMap

Given aSchema (produced by ow.obj.pmSchema.fromJavaParameterMap) and aJavaPM (a Java Parameter Map) it  corrects the types where needed (for example: enforce that a integer should really be a long). The corrected Java Parameter Map is returned. If aJavaPM is not a Java Parameter Map it will try to convert to Map and return an output Map instead of JavaParameterMap.


ow.obj.pmSchema.getSchema

ow.obj.pmSchema.getSchema(aJavaPM) : Map

Builds a type schema from the provided aJavaPM (a Java Parameter Map) to be used with  ow.obj.pmSchema.toJavaParameterMap to enforce a schema of types. If aJavaPM is not a Java Parameter Map it will try to convert to one from a Map.


ow.obj.pmSchema.makeKey

ow.obj.pmSchema.makeKey(aJavaPM) : String

Produces a key for the aJavaPM (a Java parameter map or Map) to identify the provided map in a pmSchema when using ow.obj.applySchema.


ow.obj.pool.AF

ow.obj.pool.AF(anURL, aTimeout)

Creates a pool setting with ow.obj.pool.setFactoryAF.


ow.obj.pool.DB

ow.obj.pool.DB(aDriver, aURL, aLogin, aPassword)

Creates a pool setting with ow.obj.pool.setFactoryDB.


ow.obj.pool.RAIDDB

ow.obj.pool.RAIDDB(anAF, aConn, aKeepAlive, aURL, aPassword, useCIR, aDriver)

Creates a pool setting with ow.obj.pool.setFactoryRAIDDB.


ow.obj.pool.SSH

ow.obj.pool.SSH(aHost, aPort, aLogin, aPass, anIdentificationKey, withCompression)

Creates a pool setting with ow.obj.pool.setFactorySSH.


ow.obj.pool.add

ow.obj.pool.add(aObject, inUse)

Adds aObject to the current pool. Optionally you can indicate if it should be add has checkout (inUse = true).


ow.obj.pool.checkIn

ow.obj.pool.checkIn(aObject, shouldKeep)

Returns the aObject instance back to the pool removing the mark that is in use. If shouldKeep = false the object instance will be removed from the pool (trying to call the closeFunction and ignoring any exception).


ow.obj.pool.checkOut

ow.obj.pool.checkOut() : Object

Tries to obtain an object instance from the pool and returns it marking it as in use. Throws an exception if no object is available even after retrying.


ow.obj.pool.create

ow.obj.pool.create() : Object

Creates an object pool with the ability to provide objects produce by a factory method and to close the objects when needed (if defined to have minimum and maximum number of objects in the pool). It's possible also to define a keep alive function.


ow.obj.pool.setFactory

ow.obj.pool.setFactory(aFactoryFunction, aCloseFunction, aKeepaliveFunction)

Sets the functions to use to create new object instances with a aFactoryFunction (this function should return a new object instance each time is called). aCloseFunction to be called whenever an object instances needs to be terminated. And an optionally aKeepaliveFunction, that receives a object instances as an argument, and should perform the necessary procedures to keep the object instance "alive" (think connections that timeout after not being used for a long time).


ow.obj.pool.setFactoryAF

ow.obj.pool.setFactoryAF(anURL, aTimeout)

Setups: a factory function to create an AF object using anURL and tries to send a Ping operation; a close function to close the AF object connection; a keep alive function that sends a Ping operation.


ow.obj.pool.setFactoryDB

ow.obj.pool.setFactoryDB(aDriver, aURL, aLogin, aPassword)

Setups: a factory function to create an DB object using aDriver, aURL, aLogin and aPassword; a close function to close the DB object connection; a keep alive function that tries to execute a select from dual.


ow.obj.pool.setFactoryRAIDDB

ow.obj.pool.setFactoryRAIDDB(anAF, aConn, aKeepAlive, aURL, aPassword, useCIR, aDriver)

Setups: a factory function to create an DB object using anAF and aConn connection name from the RAID/WAF server; a close function to close the DB object connection; a keep alive function that tries to execute a select from dual (you can override this function providing aKeepAlive function that receives a database object as argument).


ow.obj.pool.setFactorySSH

ow.obj.pool.setFactorySSH(aHost, aPort, aLogin, aPass, anIdentificationKey, withCompression)

Setups: a factory function to create an SSH object using aHost, aPort, aLogin, aPass, anIdentificationKey, withCompression; a close function to close the SSH object connection; a keep alive function that tries to execute a command "true".


ow.obj.pool.setIncrementsOf

ow.obj.pool.setIncrementsOf(aNumberOfInstances)

Sets the number of increments in object instances on the pool in case that a new object instances is needed


ow.obj.pool.setKeepalive

ow.obj.pool.setKeepalive(aTimeInSeconds)

Sets the aTimeInSeconds for the keep alive function to be called for all object instances in the pool. After setting to aTimeInSeconds > 0 the keep alive cycle will be started. Otherwise any existing keep alive cycle will be stopped. Note: don't forget to use ow.obj.pool.stop to keep the keep alive thread from running after you no longer need it.


ow.obj.pool.setMax

ow.obj.pool.setMax(aMaxNumberOfInstances)

Sets the maximum number of object instances the pool can have.


ow.obj.pool.setMin

ow.obj.pool.setMin(aNumberOfInstances)

Sets the minimum number of object instances the pool should have. These will be created upon ow.obj.pool.start.


ow.obj.pool.setRetry

ow.obj.pool.setRetry(numberOfRetries)

Sets the number of retries to obtain a free object from the pool.


ow.obj.pool.setTimeout

ow.obj.pool.setTimeout(aTimeoutInMs)

Sets a timeout in ms between each retry to obtain a free object from the pool.


ow.obj.pool.start

ow.obj.pool.start()

Starts the object pool by creating the minimal number of object instances.


ow.obj.pool.stop

ow.obj.pool.stop()

Stops the object pool closing all object instances and any keep alive cycle.


ow.obj.pool.use

ow.obj.pool.use(aFunction)

Executes aFunction providing, as an argument, an object instance from the pool (equivalent to ow.obj.pool.checkOut). After the execution the object instance will be returned to the pool (equivalent to ow.obj.pool.checkIn). If the aFunction returns false the provided object instance will be removed from the pool (interpreting as something is wrong  with it).


ow.obj.rest.create

ow.obj.rest.create(aBaseURI, aIndexMap, aDataRowMap, aLoginOrFunction, aPassword, aTimeout, aRequestMap, urlEncode) : String

Tries to create a new aDataRowMap entry, identified by aIndexMap, on the REST aBaseURI service returning the reply as a string (uses the HTTP POST method). Optionally you can provide aLogin, aPassword and/or aTimeout for the REST request or use a function (aLoginOrFunction) that receives the HTTP object. If urlEncode=true the aDataRowMap will be converted into x-www-form-urlencoded instead of JSON.


ow.obj.rest.exceptionParse

ow.obj.rest.exceptionParse(anException) : Map

Tries to parse the response of a rest call exception and the response also if it's json.


ow.obj.rest.get

ow.obj.rest.get(aBaseURI, aIndexMap, aLoginOrFunction, aPassword, aTimeout, aRequestMap) : String

Tries to obtain aIndexMap from the REST aBaseURI service returning as a string (uses the HTTP GET method). Optionally you can provide aLogin, aPassword and/or aTimeout for the REST request or use a function (aLoginOrFunction) that receives the HTTP object.


ow.obj.rest.jsonCreate

ow.obj.rest.jsonCreate(aBaseURI, aIndexMap, aDataRowMap, aLoginOrFunction, aPassword, aTimeout, aRequestMap, urlEncode) : Map

Tries to create a new aDataRowMap entry, identified by aIndexMap, on the REST aBaseURI service returning the reply as a map (uses the HTTP POST method). Optionally you can provide aLogin, aPassword and/or aTimeout for the REST request or use a function (aLoginOrFunction) that receives the HTTP object.  If urlEncode=true the aDataRowMap will be converted into x-www-form-urlencoded instead of JSON.


ow.obj.rest.jsonGet

ow.obj.rest.jsonGet(aBaseURI, aIndexMap, aLoginOrFunction, aPassword, aTimeout, aRequestMap) : Map

Tries to obtain aIndexMap from the REST aBaseURI service returning as a map (uses the HTTP GET method). Optionally you can provide aLogin, aPassword and/or aTimeout for the REST request or use a function (aLoginOrFunction) that receives the HTTP object.


ow.obj.rest.jsonRemove

ow.obj.rest.jsonRemove(aBaseURI, aIndexMap, aLoginOrFunction, aPassword, aTimeout, aRequestMap) : Map

Tries to remove aIndexMap entry from the REST aBaseURI service returning the reply as a map (uses the HTTP DELETE method). Optionally you can provide aLogin, aPassword and/or aTimeout for the REST request or use a function (aLoginOrFunction) that receives the HTTP object.


ow.obj.rest.jsonSet

ow.obj.rest.jsonSet(aBaseURI, aIndexMap, aDataRowMap, aLoginOrFunction, aPassword, aTimeout, urlEncode) : Map

Tries to set aDataRowMap entry, identified by aIndexMap, on the REST aBaseURI service returning the reply as a map (uses the HTTP PUT method). Optionally you can provide aLogin, aPassword and/or aTimeout for the REST request or use a function (aLoginOrFunction) that receives the HTTP object. If urlEncode=true the aDataRowMap will be converted into x-www-form-urlencoded instead of JSON.


ow.obj.rest.remove

ow.obj.rest.remove(aBaseURI, aIndexMap, aLoginOrFunction, aPassword, aTimeout, aRequestMap) : String

Tries to remove aIndexMap entry from the REST aBaseURI service returning the reply as a string (uses the HTTP DELETE method). Optionally you can provide aLogin, aPassword and/or aTimeout for the REST request or use a function (aLoginOrFunction) that receives the HTTP object.


ow.obj.rest.set

ow.obj.rest.set(aBaseURI, aIndexMap, aDataRowMap, aLoginOrFunction, aPassword, aTimeout, urlEncode) : String

Tries to set aDataRowMap entry, identified by aIndexMap, on the REST aBaseURI service returning the reply as a string (uses the HTTP PUT method). Optionally you can provide aLogin, aPassword and/or aTimeout for the REST request or use a function (aLoginOrFunction) that receives the HTTP object. If urlEncode=true the aDataRowMap will be converted into x-www-form-urlencoded instead of JSON.


ow.obj.rest.writeIndexes

ow.obj.rest.writeIndexes(aPropsMap) : String

Given a map of REST API indexes (aPropsMap) will return a corresponding URI.


ow.obj.rest.writeQuery

ow.obj.rest.writeQuery(aMap) : String

Given aMap will return a URL query string. Example:
"http://some.thing/other/stuff?" + ow.obj.rest.writeQuery({ a: 1, b: 2}));


ow.obj.searchArray

ow.obj.searchArray(anArray, aPartialMap, useRegEx, ignoreCase, useParallel) : Array

Searches anArray of maps for entries where aPartialMap matches. If useRegEx is true all string entries on aPartialMap will be interpreted as regular expressions. For number entries on the original map you can  have the prefixes >, <, >= and <= to limit the numeric values. Optionally you can provide also ignoreCase = true to ignore case (will only affect if useRegEx is true). And optionally also useParallel to provide the number of threads to use. Example:

ow.obj.searchArray(io.listFiles("/usr/bin").files, { "isFile": true, "filename": "^cal.*", "size": ">=32000" }, true, true);

// you can use it, for example, in conjunction with jLinq
$from(ow.obj.searchArray(listFilesRecursive("/usr/lib"), { "filepath": "/usr/lib/ruby", "size": ">100000" }, true)).sort("size").select();

// to refer to a sub map value
ow.obj.searchArray(students, { "details.age": "<=25", "details.isMale": true }, true);

(available after ow.loadObj())


ow.obj.setPath

ow.obj.setPath(aObject, aPath, aNewValue) : Object

Given aObject it will try to parse the aPath a set the corresponding object under that path to aNewValue. Example:

var a = { a : 1, b : { c: 2, d: [0, 1] } };

sprint(ow.obj.setPath(a, "b.c", 123); // { a : 1, b : { c: 123, d: [0, 1] } }

Clone this wiki locally