wrusman

Absent Member.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2019-06-05
12:25
444 views
read csv file with ecma script
Hello,
I'm trying to read and parse a csv file for pseudonimising users in a dedicated IDV, and found the forum post where an ecma script was posted that should work for reading files.
https://forums.novell.com/showthread.php/485563-read-text-file-for-information-and-use-it-in-a-driver
It is however unclear to me where to put the csv, or maybe include it in the driver as a "text/+text" Resource ?
can anyone elaborate on this ?
My ecma scripting knowlegde until this morning was zero, so please forgive me if my question may seem somewhat stupid 😉
I'm trying to read and parse a csv file for pseudonimising users in a dedicated IDV, and found the forum post where an ecma script was posted that should work for reading files.
https://forums.novell.com/showthread.php/485563-read-text-file-for-information-and-use-it-in-a-driver
It is however unclear to me where to put the csv, or maybe include it in the driver as a "text/+text" Resource ?
can anyone elaborate on this ?
My ecma scripting knowlegde until this morning was zero, so please forgive me if my question may seem somewhat stupid 😉
6 Replies


Knowledge Partner
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2019-06-05
12:40
wrusman wrote:
> It is however unclear to me where to put the csv, or maybe include it in
> the driver as a "text/+text" Resource ?
If it's a static file why don't you load it into a mapping table and work with
token-map? Or read the mapping table into a nodeset var and xpath your way
around it?
--
http://www.is4it.de/en/solution/identity-access-management/
(If you find this post helpful, please click on the star below.)
> It is however unclear to me where to put the csv, or maybe include it in
> the driver as a "text/+text" Resource ?
If it's a static file why don't you load it into a mapping table and work with
token-map? Or read the mapping table into a nodeset var and xpath your way
around it?
--
http://www.is4it.de/en/solution/identity-access-management/
(If you find this post helpful, please click on the star below.)
______________________________________________
https://www.is4it.de/identity-access-management
https://www.is4it.de/identity-access-management
wrusman

Absent Member.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2019-06-05
12:49
I'm not sure if that will work, because the mapping should not be static. I would like to take a random first and last name from csv's and combine them to a new pseudonym name for that user.


Knowledge Partner
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2019-06-05
13:02
wrusman wrote:
>
> I'm not sure if that will work, because the mapping should not be
> static. I would like to take a random first and last name from csv's and
> combine them to a new pseudonym name for that user.
Add an index column to the table, numbering the rows starting at 0. Say you
have 188 rows, generate a random number between 0 and 187. Then map the index
column to the first name column via the random number. Repeat for last name.
function getRandomInt(max) {
return Math.floor(Math.random() * Math.floor(max));
}
--
http://www.is4it.de/en/solution/identity-access-management/
(If you find this post helpful, please click on the star below.)
>
> I'm not sure if that will work, because the mapping should not be
> static. I would like to take a random first and last name from csv's and
> combine them to a new pseudonym name for that user.
Add an index column to the table, numbering the rows starting at 0. Say you
have 188 rows, generate a random number between 0 and 187. Then map the index
column to the first name column via the random number. Repeat for last name.
function getRandomInt(max) {
return Math.floor(Math.random() * Math.floor(max));
}
--
http://www.is4it.de/en/solution/identity-access-management/
(If you find this post helpful, please click on the star below.)
______________________________________________
https://www.is4it.de/identity-access-management
https://www.is4it.de/identity-access-management
wrusman

Absent Member.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2019-06-05
13:26
ah, that should work indeed.
Thank you for the input !
Thank you for the input !
wrusman

Absent Member.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2019-06-11
10:01
Since this is my first attempt in usinbg ecma script and mapping tables, i'm still a bit fresh on this subject.
I created an ecmascript item with the random code you posted above, thanks for that!
Is this code right for mapping a random number to a mapping table index and returning the value assigned to that index number ?
Thanks in advance
The Given Name attribute is filtered out back to the source IDV so that shouldn't be updated
I created an ecmascript item with the random code you posted above, thanks for that!
Is this code right for mapping a random number to a mapping table index and returning the value assigned to that index number ?
Thanks in advance
<do-set-src-attr-value name="Given Name">
<arg-value type="string">
<token-map dest="name" src="index" table="\[root]\drv\ds\asds-pseudo\firstNames">
<token-op-attr name="es:getRandomInt(4226)"/>
</token-map>
</arg-value>
</do-set-src-attr-value>
The Given Name attribute is filtered out back to the source IDV so that shouldn't be updated
wrusman

Absent Member.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2019-06-12
12:48
for future reference and other people trying to achieve the same, here is what i found out so far:
* Use designer 4.6.1 or higher, otherwise ecmascript in the simulation will NOT work and you will stare yourself blind on the error.
* In your driver (or store) create a ecmascript with the randomInt function from lhaeger :
In your driver (or store) create mapping tables with first names and surnames like so :
In your driver (or library) create a new DirXML script and in this create a function like this :
This will yield this result in the Simulation:
* Use designer 4.6.1 or higher, otherwise ecmascript in the simulation will NOT work and you will stare yourself blind on the error.
* In your driver (or store) create a ecmascript with the randomInt function from lhaeger :
function getRandomInt(max) {*
return Math.floor(Math.random() * Math.floor(max));
}
In your driver (or store) create mapping tables with first names and surnames like so :
<?xml version="1.0" encoding="UTF-8"?>
<mapping-table>
<col-def name="index" type="numeric"/>
<row>
<col>1</col>
<col>Aachal</col>
</row>
<row>
<col>2</col>
<col>Aad</col>
</row>
...................
<row>
<col>4226</col>
<col>Żywisław</col>
</row>
<col-def name="name" type="nocase"/>
</mapping-table>
In your driver (or library) create a new DirXML script and in this create a function like this :
<actions>
<do-reformat-op-attr name="Given Name">
<arg-value type="string">
<token-map dest="name" src="index" table="\[root]\drv\ds\asds-pseudo\firstNames">
<token-xpath expression="es:getRandomInt(4226)"/>
</token-map>
</arg-value>
</do-reformat-op-attr>
</actions>
This will yield this result in the Simulation:
Anon-Driver :Applying policy: %+C%14Cpub-cp-transform-userdata%-C.
Anon-Driver : Applying to add #1.
Anon-Driver : Evaluating selection criteria for rule 'Random-firstname-lastname'.
Anon-Driver : (if-class-name equal "User") = TRUE.
Anon-Driver : Rule selected.
Anon-Driver : Applying rule 'Random-firstname-lastname'.
Anon-Driver : Action: do-reformat-op-attr("Given Name",token-map("\[root]\drv\ds\Anon-Driver\firstNames","index","name",token-xpath("es:getRandomInt(4226)"))).
Anon-Driver : arg-string(token-map("\[root]\drv\ds\Anon-Driver\firstNames","index","name",token-xpath("es:getRandomInt(4226)")))
Anon-Driver : token-map("\[root]\drv\ds\Anon-Driver\firstNames","index","name",token-xpath("es:getRandomInt(4226)"))
Anon-Driver : token-map("\[root]\drv\ds\Anon-Driver\firstNames","index","name",token-xpath("es:getRandomInt(4226)"))
Anon-Driver : token-xpath("es:getRandomInt(4226)")
Anon-Driver : Token Value: "1956".
Anon-Driver : Arg Value: "1956".
Anon-Driver : Token Value: "Jeremy".
Anon-Driver : Arg Value: "Jeremy".
Anon-Driver : Action: do-reformat-op-attr("Surname",token-map("\[root]\drv\ds\Anon-Driver\lastNames","index","name",token-xpath("es:getRandomInt(3630)"))).
Anon-Driver : arg-string(token-map("\[root]\drv\ds\Anon-Driver\lastNames","index","name",token-xpath("es:getRandomInt(3630)")))
Anon-Driver : token-map("\[root]\drv\ds\Anon-Driver\lastNames","index","name",token-xpath("es:getRandomInt(3630)"))
Anon-Driver : token-map("\[root]\drv\ds\Anon-Driver\lastNames","index","name",token-xpath("es:getRandomInt(3630)"))
Anon-Driver : token-xpath("es:getRandomInt(3630)")
Anon-Driver : Token Value: "3370".
Anon-Driver : Arg Value: "3370".
Anon-Driver : Token Value: "Urs".
Anon-Driver : Arg Value: "Urs".
Anon-Driver :Policy returned:
Anon-Driver :
<nds dtdversion="4.0" ndsversion="8.x">
<source>
<product version="4.6.1.0">DirXML</product>
<contact>NetIQ Corporation</contact>
</source>
<input>
<add class-name="User" src-dn="cn=ID2435,ou=users,o=id">
<add-attr attr-name="Given Name">
<value type="string">Jeremy</value>
</add-attr>
<add-attr attr-name="Surname">
<value type="string">Urs</value>
</add-attr>
</add>
</input>
</nds>