You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jackrabbit.apache.org by Torgeir Veimo <to...@netenviron.com> on 2010/11/17 12:57:49 UTC

'reverse path prefix' xpath query

I need to query a workspace to find subscribers nodes to be notified
for a workspace event. Each subscribers have a subscription node with
a property containing the path prefix for what they're subscribing to.
The event listener provides the full path to the node being updated.

Eg. someone subscribes to new blog entries under /blog/wildlife/. A
new blog entry is added with a path of /blog/wildlife/2010/11/17/wolfs

How do I construct an xpath query that finds the nodes with the
correct path prefix property?

-- 
-Tor

Re: 'reverse path prefix' xpath query

Posted by Torgeir Veimo <to...@netenviron.com>.
On 18 November 2010 12:16, Torgeir Veimo <to...@netenviron.com> wrote:
> On 18 November 2010 00:21, Clemens Wyss <cl...@mysign.ch> wrote:
>> I re-read your initial post ;-)
>> How about:
>> //element(*)[@prefix='<path prefix extracted from the nodes path>']
>
> The trick is to get that path prefix extracted
>
> What I was thinking was that if the subscription contained a reference
> to a node instead of it's path, then if it was possible to implicitly
> dereference this reference in the query, and check if it refers to a
> parent node of the given node / path from the event listeners onevent
> call.
>
>> If your subscription nodes have a specific nodetype, e.g. 'myblog:subscription':
>> //element(*, myblog:subscription)[@prefix='<path prefix extracted from the nodes path>']

It looks like this is not possible to do using a query, so an
iteration over parent nodes seems necessary.

Given a node, traverse up its parent nodes, and find subscriber nodes:

1) if subscribers are stored as subnodes of the node, just retrieve a
nodeiterator for the subscriber child nodes, or

2) if subscribers are stored elsewhere, eg as subscriber nodes under a
users 'home' node, with references to the subscribed-to nodes, fetch
all such nodes with node.getReferences() (and check if correct
nodetype).

Anyone got any other ideas worth pursuing for subscriptions?

-- 
-Tor

Re: 'reverse path prefix' xpath query

Posted by Sergiy Shyrkov <my...@gmail.com>.
Hello,

On 23.11.2010 14:52, Torgeir Veimo wrote:
> On 23 November 2010 23:47, Nicolas Betheuil
> <Ni...@europe.adp.com>  wrote:
>> Hi,
>>
>> If I understand well the question, you have some posts under
>> /blog/wildlife/
>>
>> For all nodes added or modified under this node you have an event that is published
>> You have on other hand an EventListener.
>>
>> So you receive an Event from this eventListener on which you can call event.getPath()
>> This call will give you /blog/wildlife/2010/11/17/wolfs
>>
>> On other hand you have a list of subscribers for example like that
>> /subscribers/tom/@prefix=/blog/wildlife
>>         +---/tim/@prefix=/blog/otherOne
>>         +---/titi/@prefix=/blog/wildlife/2010
> Yes that's all correct.
>
>> By the event path, you can have all of those paths by the JCR API or by an regexp
>> /blog/wildlife/2010/11/17/
>> /blog/wildlife/2010/11/
>> /blog/wildlife/2010/
>> /blog/wildlife/
>> /blog/
>>
>> So with an xpath like this it's ok ?
>> //*[@target='/blog/wildlife/2010/11/17/' or ... @target='/blog/wildlife/']
>>
>> Sorry if i don't well understand the problem ...
>> Is it this ?
> Yes. What I wanted to avoid was to traverse the parent relations to
> the event node. I don't want to query for subscribers to the path
> /blog/wildlife/2010/11/17/, then to the path /blog/wildlife/2010/11/,
> then the path /blog/wildlife/2010/ etc, I just wanted a single xpath
> or sql style query.
>
> But it seems this is just not possible to avoid.
>
>
It will be a single xpath or sql style query. It will just use all event 
path possibilities with OR condition (/blog/, /blog/wildlife/, and so on 
up to your event path).
We implemented this kind of handling for our event subscription service: 
subscribers are notified of content updates for nodes, they are 
subscribed to, including subnodes (the whole content tree underneath the 
node in question).
If someone will find a more efficient way, please, share it. Thank you!

Kind regards
Sergiy

Re: 'reverse path prefix' xpath query

Posted by Torgeir Veimo <to...@netenviron.com>.
On 23 November 2010 23:47, Nicolas Betheuil
<Ni...@europe.adp.com> wrote:
> Hi,
>
> If I understand well the question, you have some posts under
> /blog/wildlife/
>
> For all nodes added or modified under this node you have an event that is published
> You have on other hand an EventListener.
>
> So you receive an Event from this eventListener on which you can call event.getPath()
> This call will give you /blog/wildlife/2010/11/17/wolfs
>
> On other hand you have a list of subscribers for example like that
> /subscribers/tom/@prefix=/blog/wildlife
>        +---/tim/@prefix=/blog/otherOne
>        +---/titi/@prefix=/blog/wildlife/2010

Yes that's all correct.

> By the event path, you can have all of those paths by the JCR API or by an regexp
> /blog/wildlife/2010/11/17/
> /blog/wildlife/2010/11/
> /blog/wildlife/2010/
> /blog/wildlife/
> /blog/
>
> So with an xpath like this it's ok ?
> //*[@target='/blog/wildlife/2010/11/17/' or ... @target='/blog/wildlife/']
>
> Sorry if i don't well understand the problem ...
> Is it this ?

Yes. What I wanted to avoid was to traverse the parent relations to
the event node. I don't want to query for subscribers to the path
/blog/wildlife/2010/11/17/, then to the path /blog/wildlife/2010/11/,
then the path /blog/wildlife/2010/ etc, I just wanted a single xpath
or sql style query.

But it seems this is just not possible to avoid.


-- 
-Tor

RE: 'reverse path prefix' xpath query

Posted by Nicolas Betheuil <Ni...@europe.adp.com>.
Hi,

If I understand well the question, you have some posts under 
/blog/wildlife/

For all nodes added or modified under this node you have an event that is published
You have on other hand an EventListener.

So you receive an Event from this eventListener on which you can call event.getPath()
This call will give you /blog/wildlife/2010/11/17/wolfs

On other hand you have a list of subscribers for example like that
/subscribers/tom/@prefix=/blog/wildlife
        +---/tim/@prefix=/blog/otherOne
        +---/titi/@prefix=/blog/wildlife/2010

By the event path, you can have all of those paths by the JCR API or by an regexp
/blog/wildlife/2010/11/17/
/blog/wildlife/2010/11/
/blog/wildlife/2010/
/blog/wildlife/
/blog/

So with an xpath like this it's ok ?
//*[@target='/blog/wildlife/2010/11/17/' or ... @target='/blog/wildlife/'] 

Sorry if i don't well understand the problem ...
Is it this ?

-----Message d'origine-----
De : Torgeir Veimo [mailto:torgeir@netenviron.com] 
Envoyé : jeudi 18 novembre 2010 03:17
À : users@jackrabbit.apache.org
Objet : Re: 'reverse path prefix' xpath query

On 18 November 2010 00:21, Clemens Wyss <cl...@mysign.ch> wrote:
> I re-read your initial post ;-)
> How about:
> //element(*)[@prefix='<path prefix extracted from the nodes path>']

The trick is to get that path prefix extracted

What I was thinking was that if the subscription contained a reference
to a node instead of it's path, then if it was possible to implicitly
dereference this reference in the query, and check if it refers to a
parent node of the given node / path from the event listeners onevent
call.

> If your subscription nodes have a specific nodetype, e.g. 'myblog:subscription':
> //element(*, myblog:subscription)[@prefix='<path prefix extracted from the nodes path>']



-- 
-Tor

Re: 'reverse path prefix' xpath query

Posted by Torgeir Veimo <to...@netenviron.com>.
On 18 November 2010 00:21, Clemens Wyss <cl...@mysign.ch> wrote:
> I re-read your initial post ;-)
> How about:
> //element(*)[@prefix='<path prefix extracted from the nodes path>']

The trick is to get that path prefix extracted

What I was thinking was that if the subscription contained a reference
to a node instead of it's path, then if it was possible to implicitly
dereference this reference in the query, and check if it refers to a
parent node of the given node / path from the event listeners onevent
call.

> If your subscription nodes have a specific nodetype, e.g. 'myblog:subscription':
> //element(*, myblog:subscription)[@prefix='<path prefix extracted from the nodes path>']



-- 
-Tor

AW: 'reverse path prefix' xpath query

Posted by Clemens Wyss <cl...@mysign.ch>.
I re-read your initial post ;-) 
How about:
//element(*)[@prefix='<path prefix extracted from the nodes path>']

If your subscription nodes have a specific nodetype, e.g. 'myblog:subscription':
//element(*, myblog:subscription)[@prefix='<path prefix extracted from the nodes path>']


-----Ursprüngliche Nachricht-----
Von: Torgeir Veimo [mailto:torgeir@netenviron.com] 
Gesendet: Mittwoch, 17. November 2010 14:49
An: users@jackrabbit.apache.org
Betreff: Re: 'reverse path prefix' xpath query

On 17 November 2010 23:40, Clemens Wyss <cl...@mysign.ch> wrote:
> Where are the subscribers located/persisted?
> Beneath /blog/<category>/subscribers (e.g. /blog/wildlife/subscribers)? If so you could take the node's path, apply the following regexp /(\/.*\/.*\/)/ on it (->/blog/wildlife/) and then get the childnodes of the regexp result concatenated with 'subscribers' (-> /blog/wildlife/subscribers)...

So the only solution is to store the subscriber list local to the data being subscribed to?

--
-Tor

Re: 'reverse path prefix' xpath query

Posted by Torgeir Veimo <to...@netenviron.com>.
On 17 November 2010 23:40, Clemens Wyss <cl...@mysign.ch> wrote:
> Where are the subscribers located/persisted?
> Beneath /blog/<category>/subscribers (e.g. /blog/wildlife/subscribers)? If so you could take the node's path, apply the following regexp /(\/.*\/.*\/)/ on it (->/blog/wildlife/) and then get the childnodes of the regexp result concatenated with 'subscribers' (-> /blog/wildlife/subscribers)...

So the only solution is to store the subscriber list local to the data
being subscribed to?

-- 
-Tor

AW: 'reverse path prefix' xpath query

Posted by Clemens Wyss <cl...@mysign.ch>.
Where are the subscribers located/persisted?
Beneath /blog/<category>/subscribers (e.g. /blog/wildlife/subscribers)? If so you could take the node's path, apply the following regexp /(\/.*\/.*\/)/ on it (->/blog/wildlife/) and then get the childnodes of the regexp result concatenated with 'subscribers' (-> /blog/wildlife/subscribers)...

-----Ursprüngliche Nachricht-----
Von: Torgeir Veimo [mailto:torgeir@netenviron.com] 
Gesendet: Mittwoch, 17. November 2010 14:25
An: users@jackrabbit.apache.org
Betreff: Re: 'reverse path prefix' xpath query

On 17 November 2010 22:10, Ard Schrijvers <a....@onehippo.com> wrote:
> On Wed, Nov 17, 2010 at 12:57 PM, Torgeir Veimo <to...@netenviron.com> wrote:
>> I need to query a workspace to find subscribers nodes to be notified 
>> for a workspace event. Each subscribers have a subscription node with 
>> a property containing the path prefix for what they're subscribing to.
>> The event listener provides the full path to the node being updated.
>>
>> Eg. someone subscribes to new blog entries under /blog/wildlife/. A 
>> new blog entry is added with a path of 
>> /blog/wildlife/2010/11/17/wolfs
>>
>> How do I construct an xpath query that finds the nodes with the 
>> correct path prefix property?
>
> You mean /jcr:root/blog/wildlife//* I guess?

The query will be constructed from the information provided by the onEvent(EventIterator events); call, which is basically the path /blog/wildlife/2010/11/17/wolfs in this case derived from the node.

--
-Tor

Re: 'reverse path prefix' xpath query

Posted by Torgeir Veimo <to...@netenviron.com>.
On 17 November 2010 22:10, Ard Schrijvers <a....@onehippo.com> wrote:
> On Wed, Nov 17, 2010 at 12:57 PM, Torgeir Veimo <to...@netenviron.com> wrote:
>> I need to query a workspace to find subscribers nodes to be notified
>> for a workspace event. Each subscribers have a subscription node with
>> a property containing the path prefix for what they're subscribing to.
>> The event listener provides the full path to the node being updated.
>>
>> Eg. someone subscribes to new blog entries under /blog/wildlife/. A
>> new blog entry is added with a path of /blog/wildlife/2010/11/17/wolfs
>>
>> How do I construct an xpath query that finds the nodes with the
>> correct path prefix property?
>
> You mean /jcr:root/blog/wildlife//* I guess?

The query will be constructed from the information provided by the
onEvent(EventIterator events); call, which is basically the path
/blog/wildlife/2010/11/17/wolfs in this case derived from the node.

-- 
-Tor

Re: 'reverse path prefix' xpath query

Posted by Ard Schrijvers <a....@onehippo.com>.
On Wed, Nov 17, 2010 at 12:57 PM, Torgeir Veimo <to...@netenviron.com> wrote:
> I need to query a workspace to find subscribers nodes to be notified
> for a workspace event. Each subscribers have a subscription node with
> a property containing the path prefix for what they're subscribing to.
> The event listener provides the full path to the node being updated.
>
> Eg. someone subscribes to new blog entries under /blog/wildlife/. A
> new blog entry is added with a path of /blog/wildlife/2010/11/17/wolfs
>
> How do I construct an xpath query that finds the nodes with the
> correct path prefix property?

You mean /jcr:root/blog/wildlife//* I guess?

Ard

>
> --
> -Tor
>



-- 
Hippo
Europe  •  Amsterdam  Oosteinde 11  •  1017 WT Amsterdam  •  +31 (0)20 522 4466
USA  • San Francisco  185 H Street Suite B  •  Petaluma CA 94952-5100
•  +1 (707) 773 4646
Canada    •   Montréal  5369 Boulevard St-Laurent  •  Montréal QC H2T
1S5  •  +1 (514) 316 8966
www.onehippo.com  •  www.onehippo.org  •  info@onehippo.com