Also I tried downloading the HashMap Connector, but I get 'java is
undefined' error.
You have to edit the script and point it at a Connector
already configured in your Library (under the Connectors
folder in the Navigator). This Library Connector must
support Iterator mode and be configured to return the
data you want to search in; For example, a FileSystem
Connector with Parser reading from some file.
-Eddie
Do you have an example? I think I'm inputing into my cache
05:52:38 * 5 of 5 entries cached.
05:52:38 * Initializing Cache Connector using Connectors/
ReadScopeFile
05:52:38 CTGDJW002I Parser will use provide column names: '[name,
start, end]'.
05:52:38 * 5 of 5 entries cached.
05:52:38 * Initializing Cache Connector using Connectors/
ReadScopeFile
05:52:38 CTGDJW002I Parser will use provide column names: '[name,
start, end]'.
05:52:38 * 5 of 5 entries cached.
But not finding on lookup when I do I simple Link on "start equals"
[5:56:16 AM EST] java.lang.Exception: [CacheConnector_1] CTGDIS047W
Entry not found.
And get the following when I use a custom script
ret.filter = "start <= " + work.getString("ipAddress.dotNotation") +
" && end >= " + work.getString("ipAddress.dotNotation");
[6:01:01 AM EST] java.lang.ArrayIndexOutOfBoundsException: Array index
out of range: 0
It would be helpful if I could see an example. Thanks
Can I only search on the key attribute? I want to search between
start and end, and get the name.
var keyAttribute = "name"; // Unique Attribute to use
I plan to roll out a TDI 7 version of this, with a config
parameters onscreen (like I did with the FileScan Connector:
http://www.tdi-users.org/twiki/bin/view/Integrator/FileList),
if my day-job permits :)
-Eddie
Ok,
Ok, I can get both connectors working when I use the simple Link
Criteria. But I get the following error when I build my criteria. It
would be great if you can give me the syntax. "start" is the field in
the hash. I tried "start[0]". How should it be referenced? Thanks
ret.filter = "start == " + work.getString("ipAddress.dotNotation");
Error
[4:13:58 PM EST] java.lang.ArrayIndexOutOfBoundsException: Array index
out of range: 0
This simple Connector really just looks at the value you
pass in a Link Criteria (e.g. $work.AttName or literal value)
and applies this against the single index to this data (defined
by the keyAttribute variable. Have you tried a simple Link Crit
and just looked for a value that you know exists?
-Eddie
Yes that works, but I need to search for the range an ip falls into.
There for it can't be a simple match.
First off, if you look at the start of the HashMap
Connector script you'll see the HashMap variable
I use to provide the simple lookup:
---
...
var hsh = new java.util.HashMap();
...
---
This gets populated with the entries read by the
library Connector you assigned to "connectorName".
So if you want to search for a range of ip addresses
(which you are using as the key for searches) then
you can ask the HashMap to return the keys as
a set:
---
keySet = hsh.keySet();
---
Then you can return the keySet as an Array of
Strings, sort the array and then use your favorite
search approach to determine the match:
---
keyArray = keySet.toArray();
java.util.Arrays.sort(keyArray);
function getInRange(startIP, endIP) {
// I'll return all entries found as values to an
// Attribute - it's a handy collection :)
retAtt = system.newAttribute("EntriesFound");
// Brute force search
for (var i = 0; i < keyArray.length; i++)
if (keyArray[i] > endIP)
break
else if (keyArray[i] >= startIP)
retAtt.addValue(hsh.get(keyArray[i]));
return retAtt;
}
---
Then you can check retAtt.size() to see how many
are returned, and then cycle through the values
any way you see fit (e.g. with an Attribute Value
Loop - that is, once you've put retAtt into the
Work Entry.
Your challenge here (should you choose to accept
it :) is that a scripted component lives "outside"
the scope of the AL Script engine - it has its own.
So you will need to modify the script in order to
put the HashMap (hsh) someplace that you can
reach outside. For example:
--- In the HashMap Connector script
...
var hsh = new java.util.HashMap();
java.lang.System.getProperties().put("HashM", hsh);
...
--- And then in your AL someplace
...
var hsh = java.lang.System.getProperties().get("HashM");
...
---
Hope this helps!
-Eddie