You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jackrabbit.apache.org by Nandana Mihindukulasooriya <na...@gmail.com> on 2007/08/12 09:17:41 UTC
Using Observation
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 ? 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 ?
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);
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 ? 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).
Thank you in advance.
Nandana
Re: Using Observation
Posted by Nandana Mihindukulasooriya <na...@gmail.com>.
Hi Marcel,
Thanks a lot for the quick reply.
this depends on the configuration. with the default configuration,
> jackrabbit
> simply allows everyone to login and modify anything.
>
How can we edit the configuration to specify those details ? I don't need
that at the moment in my app but was wondering as those details under
Security Configuration and Access Managers sections couldn't be found in the
configuring Jackrabbit page yet.
In my app, I use
Session session = repository.login(new
SimpleCredentials("username","password".toCharArray()));
to initiate a session. Does this "username" and "password" is used in
Jackrabbit ? If then, for what purpose ?
> I guess the workaround is to manually check the node type of the added
node and
> react accordingly.
So I am doing a check for primary type of the Node as given below. Is there
a more efficient way to do this ?
String path = event.getPath();
// Removing the initial '/' to make a relative path
path = path.substring(1, path.length());
Node eventNode = rootNode.getNode(path);
if ( eventNode.getPrimaryNodeType().getName().equals("blog:comment")) {
}
Thanks once again,
Nandana
Re: Using Observation
Posted by Marcel Reutegger <ma...@gmx.net>.
Anton Gavazuk wrote:
> And how you know - are you superuser or not. Are there exist an predefined
> users in repository?
this depends on the configuration. with the default configuration, jackrabbit
simply allows everyone to login and modify anything.
see: http://jackrabbit.apache.org/faq.html#access-authentication
and: http://jackrabbit.apache.org/faq.html#access-authorization
regards
marcel
Re: Using Observation
Posted by Anton Gavazuk <an...@gmail.com>.
And how you know - are you superuser or not. Are there exist an predefined
users in repository?
2007/8/14, Anton Gavazuk <an...@gmail.com>:
>
> Is it good or not - big life cycle of Session?
>
> 2007/8/14, Marcel Reutegger <ma...@gmx.net>:
> >
> > 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
> >
>
>
Re: Using Observation
Posted by Marcel Reutegger <ma...@gmx.net>.
Anton Gavazuk wrote:
> Is it good or not - big life cycle of Session?
I'm not aware of any disadvantage.
regards
marcel
Re: Using Observation
Posted by Anton Gavazuk <an...@gmail.com>.
Is it good or not - big life cycle of Session?
2007/8/14, Marcel Reutegger <ma...@gmx.net>:
>
> 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
>
Re: Using Observation
Posted by Marcel Reutegger <ma...@gmx.net>.
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