Knowledge Partner
Knowledge Partner
249 views

Using For Each on local variable of a nodeset?


I must be doing something wrong. (obviously)

Anyway, I have a tree structure something like:

Groups
-> APPNAME01
-> Group001
-> Group002
-> APPNAME02
-> Group001

First, I need to find the "container" (APPNAMExx) for the appropriate
"thing".
THAT part seems to be working right.

I then need to get a list of all groups under the aforementioned name.
So I did this in my action set:


Code:
--------------------

<do-set-local-variable name="SecurityGroups" scope="policy">
<arg-node-set>
<token-query class-name="Group" datastore="src" scope="subordinates">
<arg-dn>
<token-global-variable name="idv.dit.data.groups"/>
<token-text xml:space="preserve">\</token-text>
<token-local-variable name="AppName"/>
</arg-dn>
<arg-string>
<token-attr name="CN"/>
</arg-string>
</token-query>
</arg-node-set>
</do-set-local-variable>
--------------------


a) Is this correct? I mean it SHOULD theoretically set the local
variable:
SecurityGroups
to the nodeset that is querying for "cn" attribute of objectclass
Group

so it should set it to like:
Group01,Group02

??

b) If not, then what's the correct way to do this? I saw mention in
the olden days (haha) of having to use XPATH for query expressions but
then Novell let you just use Query natively in the "actions" instead.

c) IF it is correct, then for some strange reason my next rule isn't
seeming to be working correctly. That rule, should then do a: for each
(of the "SecurityGroups" variable) and query for MEMBERS of the two
groups.


Code:
--------------------

<do-for-each>
<arg-node-set>
<token-local-variable name="SecurityGroups"/>
</arg-node-set>
<arg-actions>
<do-set-local-variable name="SecurityGroupMembers" scope="policy">
<arg-node-set>
<token-query class-name="Group" datastore="src" scope="subordinates">
<arg-dn>
<token-global-variable name="idv.dit.data.groups"/>
<token-text xml:space="preserve">\</token-text>
<token-local-variable name="AppName"/>
<token-text xml:space="preserve">\</token-text>
<token-local-variable name="SecurityGroups"/>
</arg-dn>
<arg-string>
<token-attr name="Member"/>
</arg-string>
</token-query>
</arg-node-set>
</do-set-local-variable>
</arg-actions>
</do-for-each>

--------------------


But it doesn't seem to be working properly

--Kevin


--
The opinions expressed are my own.
Check out my OES2 Guides:
Installing OES2 SP2:
http://www.novell.com/communities/node/11600/oes2-sp2-installation-guide
Upgrading to OES2 with ID Transfer:
http://www.novell.com/communities/node/11601/oes2-sp2-migration-guide-transfer-id-scenarios
GroupWise Migration with OES2 ID Transfer:
http://www.novell.com/communities/node/11602/groupwise-migration-netware-oes2-sp2-transfer-id
------------------------------------------------------------------------
kjhurni's Profile: http://forums.novell.com/member.php?userid=734
View this thread: http://forums.novell.com/showthread.php?t=449015

Labels (1)
0 Likes
3 Replies
Knowledge Partner
Knowledge Partner

Re: Using For Each on local variable of a nodeset?

> a) Is this correct? I mean it SHOULD theoretically set the local
> variable:
> SecurityGroups
> to the nodeset that is querying for "cn" attribute of objectclass
> Group
>
> so it should set it to like:
> Group01,Group02


Nope, as a nodeset you will get two
<instance src-dn='\tree\o\ou\whatever'>
<attr attr-name='cn'>
<value>someCN</value>
</attr>
</instance>

So you want to see the values, you for-each over the nodeset and inside,
set local variable LIST-OF-GROUPS to the local variable LIST-OF-GROUPS
then a comma, then local variable current-node





> ??
>
> b) If not, then what's the correct way to do this? I saw mention in
> the olden days (haha) of having to use XPATH for query expressions but
> then Novell let you just use Query natively in the "actions" instead.


Query token and Java query() function are identical. The token is a
VERY nice wrapper on top of all the classes functionality.


> c) IF it is correct, then for some strange reason my next rule isn't
> seeming to be working correctly. That rule, should then do a: for each
> (of the "SecurityGroups" variable) and query for MEMBERS of the two
> groups.


So you probably really need the DN of the group. In which case,
perhaps, loop through your first result, and set local variable
CURR-GROUP to XPATH $current-node/@src-dn to get teh DN of the found object.


>
> Code:
> --------------------
>
> <do-for-each>
> <arg-node-set>
> <token-local-variable name="SecurityGroups"/>
> </arg-node-set>
> <arg-actions>
> <do-set-local-variable name="SecurityGroupMembers" scope="policy">
> <arg-node-set>
> <token-query class-name="Group" datastore="src" scope="subordinates">
> <arg-dn>
> <token-global-variable name="idv.dit.data.groups"/>
> <token-text xml:space="preserve">\</token-text>
> <token-local-variable name="AppName"/>
> <token-text xml:space="preserve">\</token-text>
> <token-local-variable name="SecurityGroups"/>
> </arg-dn>
> <arg-string>
> <token-attr name="Member"/>
> </arg-string>
> </token-query>
> </arg-node-set>
> </do-set-local-variable>
> </arg-actions>
> </do-for-each>
>
> --------------------
>
>
> But it doesn't seem to be working properly
>
> --Kevin
>
>


0 Likes
Knowledge Partner
Knowledge Partner

Re: Using For Each on local variable of a nodeset?


Thanks Geoff.

I see what you mean by the "results". In the trace logging you're
right--it shows like the two src-dn thingies:

<instance src-dn='\tree\o\ou\whatever'>
<attr attr-name='cn'>
<value>someCN</value>
</attr>
</instance>

I'll give it a whirl tomorrow. I didn't know you could set a variable
to itself,variable

I guess in "java" (programming type of "java") a nodeset set to a
variable is like an array/list

So we were expecting:
group01,group02

(since I'm querying for "cn" and thus, I would expect JUST the "cn" to
be in the nodeset, not the "dn")


--
The opinions expressed are my own.
Check out my OES2 Guides:
Installing OES2 SP2:
http://www.novell.com/communities/node/11600/oes2-sp2-installation-guide
Upgrading to OES2 with ID Transfer:
http://www.novell.com/communities/node/11601/oes2-sp2-migration-guide-transfer-id-scenarios
GroupWise Migration with OES2 ID Transfer:
http://www.novell.com/communities/node/11602/groupwise-migration-netware-oes2-sp2-transfer-id
------------------------------------------------------------------------
kjhurni's Profile: http://forums.novell.com/member.php?userid=734
View this thread: http://forums.novell.com/showthread.php?t=449015

0 Likes
Knowledge Partner
Knowledge Partner

Re: Using For Each on local variable of a nodeset?

On Fri, 02 Dec 2011 03:36:01 +0000, kjhurni wrote:

> I see what you mean by the "results". In the trace logging you're
> right--it shows like the two src-dn thingies:


A level 3 trace would help us see what you're looking at...


> I guess in "java" (programming type of "java") a nodeset set to a
> variable is like an array/list


The nearest equivalent is "array", in programming terms, but a nodeset is
more like an array of structures with some other features bolted on as
well. Be careful not to think of it too closely as an array.


> So we were expecting:
> group01,group02
>
> (since I'm querying for "cn" and thus, I would expect JUST the "cn" to
> be in the nodeset, not the "dn")


The query returns a nodeset of objects, arranged so that you can traverse
the nodeset to get to individual object attribute data with XPath.


--
--------------------------------------------------------------------------
David Gersic dgersic_@_niu.edu
Novell Knowledge Partner http://forums.novell.com

Please post questions in the forums. No support provided via email.

0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.