Changing a document object during a notification

classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|

Changing a document object during a notification

Tiago Rinck Caveden
Hello,

I'm using XWiki notification API (
http://platform.xwiki.org/xwiki/bin/view/DevGuide/Notifications) and now I
need to change a property of the document that is being changed by the user.
I tried simply changing the value but this does not persist it - after
rebooting the server the value is not there anymore.
Using the context.getWiki.saveDocument method was not a very bright idea
either because it started an infinite recursion - it called my notification
code back again.

So, does anybody know what could I do?

Thank you very much,
--
Tiago Rinck Caveden
http://caveden.multiply.com
_______________________________________________
users mailing list
[hidden email]
http://lists.xwiki.org/mailman/listinfo/users
Tiago Rinck Caveden
http://caveden.multiply.com
Reply | Threaded
Open this post in threaded view
|

Re: Changing a document object during a notification

Sergiu Dumitriu-2
Tiago Rinck Caveden wrote:

> Hello,
>
> I'm using XWiki notification API (
> http://platform.xwiki.org/xwiki/bin/view/DevGuide/Notifications) and now I
> need to change a property of the document that is being changed by the user.
> I tried simply changing the value but this does not persist it - after
> rebooting the server the value is not there anymore.
> Using the context.getWiki.saveDocument method was not a very bright idea
> either because it started an infinite recursion - it called my notification
> code back again.
>
> So, does anybody know what could I do?

Yes, use prenotifications. This means that instead of putting the code in verify(), put it in
preverify(), and use the constructor with 3 arguments.
--
Sergiu Dumitriu
http://purl.org/net/sergiu/
_______________________________________________
users mailing list
[hidden email]
http://lists.xwiki.org/mailman/listinfo/users
Reply | Threaded
Open this post in threaded view
|

Re: Changing a document object during a notification

Sergiu Dumitriu-2
Sergiu Dumitriu wrote:

> Tiago Rinck Caveden wrote:
>> Hello,
>>
>> I'm using XWiki notification API (
>> http://platform.xwiki.org/xwiki/bin/view/DevGuide/Notifications) and
>> now I
>> need to change a property of the document that is being changed by the
>> user.
>> I tried simply changing the value but this does not persist it - after
>> rebooting the server the value is not there anymore.
>> Using the context.getWiki.saveDocument method was not a very bright idea
>> either because it started an infinite recursion - it called my
>> notification
>> code back again.
>>
>> So, does anybody know what could I do?
>
> Yes, use prenotifications. This means that instead of putting the code
> in verify(), put it in preverify(), and use the constructor with 3
> arguments.

I hit Send to soon, and my notification knowledge is a bit rusty...

I mean, when creating the notification rule (DocChangeRule or whichever you're using), use the
constructor with 3 arguments, and use true for the second argument, false for the third one. If the
Rule doesn't have such a constructor, call setPostverify(false) and setPreverify(true). That's all
you need to do.

--
Sergiu Dumitriu
http://purl.org/net/sergiu/
_______________________________________________
users mailing list
[hidden email]
http://lists.xwiki.org/mailman/listinfo/users
Reply | Threaded
Open this post in threaded view
|

Re: Changing a document object during a notification

Tiago Rinck Caveden
On Wed, Jun 25, 2008 at 7:31 PM, Sergiu Dumitriu <[hidden email]> wrote:

> Sergiu Dumitriu wrote:
> > Yes, use prenotifications. This means that instead of putting the code
> > in verify(), put it in preverify(), and use the constructor with 3
> > arguments.
>
> I hit Send to soon, and my notification knowledge is a bit rusty...
>
> I mean, when creating the notification rule (DocChangeRule or whichever
> you're using), use the
> constructor with 3 arguments, and use true for the second argument, false
> for the third one. If the
> Rule doesn't have such a constructor, call setPostverify(false) and
> setPreverify(true). That's all
> you need to do.



Thanks, that helped me!

I have one more question... isn't the EVENT_UPDATE_OBJECT event code ever
used?
I only need to execute my code when the object in the page is changed, so I
made an if with this event but then the code stopped being called. I made an
Eclipse search over the variable and it didn't find any use all over XWiki's
source code...

[]'s
--
Tiago Rinck Caveden
http://caveden.multiply.com
_______________________________________________
users mailing list
[hidden email]
http://lists.xwiki.org/mailman/listinfo/users
Tiago Rinck Caveden
http://caveden.multiply.com
Reply | Threaded
Open this post in threaded view
|

Re: Changing a document object during a notification

Tiago Rinck Caveden
On Thu, Jun 26, 2008 at 11:39 AM, Tiago Rinck Caveden <[hidden email]>
wrote:

> I have one more question... isn't the EVENT_UPDATE_OBJECT event code ever
> used?
> I only need to execute my code when the object in the page is changed, so I
> made an if with this event but then the code stopped being called. I made an
> Eclipse search over the variable and it didn't find any use all over XWiki's
> source code...
>


And now I'm trying to distinguish the behavior of an update from the one of
a delete and I can't manage to... apparently the event == EVENT_DELETE is
not being sent...

Or may I be doing something wrong?

Thanks,
--
Tiago Rinck Caveden
http://caveden.multiply.com
_______________________________________________
users mailing list
[hidden email]
http://lists.xwiki.org/mailman/listinfo/users
Tiago Rinck Caveden
http://caveden.multiply.com
Reply | Threaded
Open this post in threaded view
|

Re: Changing a document object during a notification

Marius Dumitru Florea
Maybe this http://tinyurl.com/3hzmjd can help. It's the ActivityStream
implementation for Curriki. It uses the Notification System. Take a look.

> On Thu, Jun 26, 2008 at 11:39 AM, Tiago Rinck Caveden <[hidden email]>
> wrote:
>
>> I have one more question... isn't the EVENT_UPDATE_OBJECT event code
>> ever
>> used?
>> I only need to execute my code when the object in the page is changed,
>> so I
>> made an if with this event but then the code stopped being called. I
>> made an
>> Eclipse search over the variable and it didn't find any use all over
>> XWiki's
>> source code...
>>
>
>
> And now I'm trying to distinguish the behavior of an update from the one
> of
> a delete and I can't manage to... apparently the event == EVENT_DELETE is
> not being sent...
>
> Or may I be doing something wrong?
>
> Thanks,
> --
> Tiago Rinck Caveden
> http://caveden.multiply.com
> _______________________________________________
> users mailing list
> [hidden email]
> http://lists.xwiki.org/mailman/listinfo/users
>


_______________________________________________
users mailing list
[hidden email]
http://lists.xwiki.org/mailman/listinfo/users
Reply | Threaded
Open this post in threaded view
|

Re: Changing a document object during a notification

Tiago Rinck Caveden
Hello!

On Thu, Jun 26, 2008 at 2:29 PM, Marius Dumitru Florea <
[hidden email]> wrote:

> Maybe this http://tinyurl.com/3hzmjd can help. It's the ActivityStream
> implementation for Curriki. It uses the Notification System. Take a look.



Thanks. I took a quick look, and I saw that the code there seems to be
trying to guess which is the event by inspecting the objects and properties
of the documents, is that right?

If it is like that, why is the "event" int parameter there anyway? I thought
it was his "job" to inform this.... if he always come with the same value it
looks a bit weird.

Anyway, I'm guessing the interface was thought this way to allow this
implementation in the future, but currently is not implemented... is it so?
In this case, I might use the same "guessing techniques" shown there in my
code too.

Thank you!
--
Tiago Rinck Caveden
http://caveden.multiply.com
_______________________________________________
users mailing list
[hidden email]
http://lists.xwiki.org/mailman/listinfo/users
Tiago Rinck Caveden
http://caveden.multiply.com
Reply | Threaded
Open this post in threaded view
|

Re: Changing a document object during a notification

Marius Dumitru Florea
See below,

> Hello!
>
> On Thu, Jun 26, 2008 at 2:29 PM, Marius Dumitru Florea <
> [hidden email]> wrote:
>
>> Maybe this http://tinyurl.com/3hzmjd can help. It's the ActivityStream
>> implementation for Curriki. It uses the Notification System. Take a
>> look.
>
>
>
> Thanks. I took a quick look, and I saw that the code there seems to be
> trying to guess which is the event by inspecting the objects and
> properties
> of the documents, is that right?

Unfortunately, yes.

>
> If it is like that, why is the "event" int parameter there anyway? I
> thought
> it was his "job" to inform this.... if he always come with the same value
> it
> looks a bit weird.

I've asked my self the same question: http://tinyurl.com/66o5yz

>
> Anyway, I'm guessing the interface was thought this way to allow this
> implementation in the future, but currently is not implemented... is it
> so?

I'd say it's rather a bug.

> In this case, I might use the same "guessing techniques" shown there in my
> code too.

You should first take a look at Vincent's observation component. If it
doesn't help then I can't see other option than to use a "guessing
technique" :(

>
> Thank you!

You're welcome!
Marius

> --
> Tiago Rinck Caveden
> http://caveden.multiply.com
> _______________________________________________
> users mailing list
> [hidden email]
> http://lists.xwiki.org/mailman/listinfo/users
>


_______________________________________________
users mailing list
[hidden email]
http://lists.xwiki.org/mailman/listinfo/users
Reply | Threaded
Open this post in threaded view
|

Re: Changing a document object during a notification

Sergiu Dumitriu-2
In reply to this post by Tiago Rinck Caveden
Tiago Rinck Caveden wrote:

> On Wed, Jun 25, 2008 at 7:31 PM, Sergiu Dumitriu <[hidden email]> wrote:
>
>> Sergiu Dumitriu wrote:
>>> Yes, use prenotifications. This means that instead of putting the code
>>> in verify(), put it in preverify(), and use the constructor with 3
>>> arguments.
>> I hit Send to soon, and my notification knowledge is a bit rusty...
>>
>> I mean, when creating the notification rule (DocChangeRule or whichever
>> you're using), use the
>> constructor with 3 arguments, and use true for the second argument, false
>> for the third one. If the
>> Rule doesn't have such a constructor, call setPostverify(false) and
>> setPreverify(true). That's all
>> you need to do.
>
>
>
> Thanks, that helped me!
>
> I have one more question... isn't the EVENT_UPDATE_OBJECT event code ever
> used?
> I only need to execute my code when the object in the page is changed, so I
> made an if with this event but then the code stopped being called. I made an
> Eclipse search over the variable and it didn't find any use all over XWiki's
> source code...
>

Sorry, that's a bug. See http://jira.xwiki.org/jira/browse/XWIKI-2105
--
Sergiu Dumitriu
http://purl.org/net/sergiu/
_______________________________________________
users mailing list
[hidden email]
http://lists.xwiki.org/mailman/listinfo/users
Reply | Threaded
Open this post in threaded view
|

Re: Changing a document object during a notification

Sergiu Dumitriu-2
In reply to this post by Marius Dumitru Florea
Marius Dumitru Florea wrote:
>> In this case, I might use the same "guessing techniques" shown there in my
>> code too.
>
> You should first take a look at Vincent's observation component. If it
> doesn't help then I can't see other option than to use a "guessing
> technique" :(

Unfortunately that's more a stub for future use, because there aren't many events generated. Still,
it is able to distinguish between create, update and delete events, which is already better.

--
Sergiu Dumitriu
http://purl.org/net/sergiu/
_______________________________________________
users mailing list
[hidden email]
http://lists.xwiki.org/mailman/listinfo/users