jackrabbit-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Marcel Reutegger <marcel.reuteg...@gmx.net>
Subject Re: Using Observation
Date Tue, 14 Aug 2007 10:22:38 GMT
Nandana Mihindukulasooriya wrote:
> Hi,
> 
>     I want to use observation in my blog application and the node structure
> of the application is follows. I want
> to catch the event of adding a new comment to a blog entry. This will be
> used to generate email alerts when a
> comment is added to a blog entry of our interest.
> 
>     - blogRoot[nt:folder]
>        - <username>[blog:user]
>            - <yyyy> [nt:folder]
>                - <mm>[nt:folder]
>                   - <blogEntry>[blog:blogEntry]
>                        - <comment> [blog:Comment]
> 
>     In the application, I initiate a session at the application start up and
> logout that session at the application shutdown
> as I want my listener to be alive throughout the application. Is that the
> correct way to go ?

yes, that's an approach I also recommend.

> It is also said that it is
> good to use the superuser account or a special account to create that
> session to have full read access to the Workspace.
> How can create a session as superuser ?

you just have to login with the credentials of a superuser. which userid you 
have to use depends on your authorization configuration.

>    The specification(JSR-170) says " The set of events can be filtered by
> specifying restrictions based on characteristics
> of the associated parent node of the event. The associated parent node of an
> event is the parent node of the item at (or
> formerly  at) the path returned by Event.getPath.So I tried using the code
> below but it doesn't work. When I remove the
> nodeTypes constraint it works fine and give me all the NODE_ADDED events. Am
> I missing something ?
> 
>     Workspace ws = session.getWorkspace();
>     ObservationManager observationMgr = ws.getObservationManager();
>     AlertManager alertMgr = new AlertManager(repository);
>     observationMgr.addEventListener(alertMgr,Event.NODE_ADDED,"/blogRoot",true,null,new
> String[]{"blog:blogEntry"}, false);

hmm, that's strange. I quickly ran a test and it worked fine.

>     AlertManager implements the javax.jcr.observation.EventListener  .
> 
>   What I really want is to catch the event of adding a new comment. Is there
> a way to constrain the events by the node type
> of the node actually being added and not it's parent ?

no, unfortunately not, the spec says the filters are applied on the parent node.

> Or else do I have to
> use the path returned by the event and do a
> work around if there are many types of nodes are added to the
> parent(blogEntry, in the current context) and I am interested
> in only one type(comment).

I guess the workaround is to manually check the node type of the added node and 
react accordingly.

regards
  marcel

Mime
View raw message