• event.getNoteId() is NULL

    By Heinz Schneider 1 decade ago

    I am working on a tasklet of type AbstractServerTask where i need to get a handle on the note ids of documents that got modified.

    I can catch the event but event.getNoteId() is always NULL

    NSFNoteUpdateExtendedEvent event = (NSFNoteUpdateExtendedEvent)event;

    logMessage("Note ID: " + event.getNoteId());

    Output: Note ID: NULL

    any idea?

    Thanks for any Help

     

    • It looks like you may be overwriting the event object.

      By Paul Fiore 1 decade ago

      Hello,

      It looks like you may be overwriting the event object.  In your code sample you have listed:

      NSFNoteUpdateExtendedEvent event = (NSFNoteUpdateExtendedEvent)event;
      logMessage("Note ID: " + event.getNoteId());

      Try something along the lines of:

      IExtensionManagerEvent event = runWhen.getExtensionManagerEvent();
              
      if (event.getEventId() == IExtensionManagerEvent.EM_NSFNOTEUPDATEXTENDED ||
          event.getEventId() == IExtensionManagerEvent.EM_NSFNOTEUPDATE)
      {
          NSFNoteUpdateExtendedEvent updateEvent = (NSFNoteUpdateExtendedEvent)event;
          logMessage("Note ID: " + updateEvent.getNoteId());
      }

      Let us know if that doesn't resolve your issue.
      Regards,

      Paul
       

      • I only seem to get EM_NSFNOTECREATE events

        By Heinz Schneider 1 decade ago

        Hi Paul, Thanks for you quick response.

        Do i see this right that the events EM_NSFNOTEUPDATEXTENDED and EM_NSFNOTEUPDATE get triggered when documents are edited and saved?

        At the moment i only seem to get EM_NSFNOTECREATE events

        I tried to get NoteID of the create Event and also get NULL, getting the DbPath works.

        IExtensionManagerEvent event = runWhen.getExtensionManagerEvent();
                
        if ( event.getEventId() == IExtensionManagerEvent.EM_NSFNOTECREATE){
                    NSFNoteCreateEvent createEvent = (NSFNoteCreateEvent)event;
                    logMessage("NoteID: " + createEvent.getNoteId());
                    logMessage("Path: " + createevent.getDbPath() );
        }

        • Some thoughts and comments

          By Paul Fiore 1 decade ago

          Hello,

          > Do i see this right that the events EM_NSFNOTEUPDATEXTENDED and EM_NSFNOTEUPDATE get triggered when documents are edited and saved?

          Correct

          > At the moment i only seem to get EM_NSFNOTECREATE events

          You'll need to build in the logic to capture the events you care about.  Along the lines of:

          IExtensionManagerEvent event = runWhen.getExtensionManagerEvent();

          if (event.getEventId() == IExtensionManagerEvent.EM_NSFNOTEUPDATEXTENDED ||
              event.getEventId() == IExtensionManagerEvent.EM_NSFNOTEUPDATE )
          {
              NSFNoteUpdateExtendedEvent updateEvent = (NSFNoteUpdateExtendedEvent)event;
              // Do something...
          }
          else if (event.getEventId() == IExtensionManagerEvent.EM_NSFNOTECREATE)
          {
              NSFNoteCreateEvent createEvent = (NSFNoteCreateEvent)event;
              // Do something else...

          }


          > I tried to get NoteID of the create Event and also get NULL, getting the DbPath works.

          It would be normal to get a NoteId of 0 for a newly created document since it hasn't been saved and does not yet have a NOTEID. The question then would be why does the NSFNoteCreateEvent class have a getNoteId to begin with and the reason is because of the fact that this class inherits from a base class which provides a getNoteId method. In this case it makes sense to ignore this method.

          Regards,

          Paul

          • NSFNoteUpdate*Event not captured

            By Michael B Nielsen 1 decade ago

            I to can't capture the NSFNoteUpdateExtendedEvent. I get at lot of NSFNoteCreateEvent but no NSFNoteUpdate*Event.

            Full code is posted as attachement.

            Do you have some line of code showing have to capture a triggered update?

            // Michael

             

              public void run(RunWhen runWhen, String[] args, IProgressMonitor monitor)
                        throws NotesException {
                    if (runWhen.getUnit() != RunUnit.triggered) {
                        // We only support triggered events
                        return;
                    }

                    IExtensionManagerEvent event = runWhen.getExtensionManagerEvent();

                    AbstractEMEvent ae = (AbstractEMEvent) event;
                    String eventClassName = ae.getClass().getName();
                    String eventName = (eventClassName.lastIndexOf(".") == -1 ? eventClassName
                            : eventClassName.substring(eventClassName.lastIndexOf("."),
                                    eventClassName.length()));
                    String dbPath = ae.getDbPath();

                    /*
                     * This code is run when I open the document I like to update
                     */
                    if (event.getEventId() == IExtensionManagerEvent.HOOK_EVENT_NOTE_OPEN) {
                        try {
                            NSFHookNoteOpenEvent nSFHookEvent = null;
                            nSFHookEvent = (NSFHookNoteOpenEvent) event;
                            if (!ignorList.contains(nSFHookEvent.getDbPath())) {
                                logMessage(MessageFormat
                                        .format(
                                                "Trigger event: "
                                                        + eventName
                                                        + "({0}) with dbPath = {1} and NoteId {2} and username {3}",
                                                event.getEventId(), dbPath, nSFHookEvent
                                                        .getNoteId(), nSFHookEvent
                                                        .getUserName()));
                            }
                        } catch (Exception e) {
                            logMessage("Trigger event: " + eventName + " ... ERROR "
                                    + e.getLocalizedMessage());
                        }
                    }
                    
                    /*
                     * This code is run sometime when I update a document
                     */
                    else if (event.getEventId() == IExtensionManagerEvent.HOOK_EVENT_NOTE_UPDATE) {
                        try {
                            NSFHookNoteUpdateEvent nSFHookEvent = null;
                            nSFHookEvent = (NSFHookNoteUpdateEvent) event;
                            if (!ignorList.contains(nSFHookEvent.getDbPath())) {
                                logMessage(MessageFormat
                                        .format(
                                                "Trigger event: "
                                                        + eventName
                                                        + "({0}) with dbPath = {1} and NoteId {2} and username {3}",
                                                event.getEventId(), dbPath, nSFHookEvent
                                                        .getNoteId(), nSFHookEvent
                                                        .getUserName()));
                            }
                        } catch (Exception e) {
                            logMessage("Trigger event: " + eventName + " ... ERROR "
                                    + e.getLocalizedMessage());
                        }
                    }
                    
                    /*
                     * This code is always run when I update a document - nSFEvent.getNoteId() being null
                     */
                    else if (event.getEventId() == IExtensionManagerEvent.EM_NSFNOTECREATE) {
                        try {
                            NSFNoteCreateEvent nSFEvent = null;
                            nSFEvent = (NSFNoteCreateEvent) event;
                            if (!ignorList.contains(nSFEvent.getDbPath())) {
                                logMessage(MessageFormat.format("Trigger event: "
                                        + eventName
                                        + "({0}) with dbPath = {1} and NoteId {2}}", event
                                        .getEventId(), dbPath, nSFEvent.getNoteId()));
                            }
                        } catch (Exception e) {
                            logMessage("Trigger event: " + eventName + " ... ERROR "
                                    + e.getLocalizedMessage());
                        }
                    }
                    
                    /*
                     * This code is not  run when I update a document !!!
                     */
                    else if (event.getEventId() == IExtensionManagerEvent.EM_NSFNOTEUPDATEXTENDED ||
                            event.getEventId() == IExtensionManagerEvent.EM_NSFNOTEUPDATE) {
                        try {
                            NSFNoteUpdateExtendedEvent  nSFEvent = null;
                            nSFEvent = (NSFNoteUpdateExtendedEvent ) event;
                            if (!ignorList.contains(nSFEvent.getDbPath())) {
                                logMessage(MessageFormat.format("Trigger event: "
                                        + eventName
                                        + "({0}) with dbPath = {1} and NoteId {2}}", event
                                        .getEventId(), dbPath, nSFEvent.getNoteId()));
                            }
                        } catch (Exception e) {
                            logMessage("Trigger event: " + eventName + " ... ERROR "
                                    + e.getLocalizedMessage());
                        }
                    }

                    else {
                        if (dbPath.equals("TaskletDemo.nsf")) {
                            logMessage(MessageFormat.format("Trigger event: " + eventName
                                    + "({0}) with dbPath = {1} and NoteId {2}", event
                                    .getEventId(), dbPath, ae.getNoteId()));
                        }
                    }
                }
             

            • We'll need to investigate further

              By Paul Fiore 1 decade ago

              A couple of posts in regards to triggered events.  We'll need to investigate further.

            • Interim Update

              By Paul Fiore 1 decade ago

              I've taken your sample and have been able to reproduce the events exactly as you state. In summary I see:

              IExtensionManagerEvent.HOOK_EVENT_NOTE_OPEN: This code is run when I open the document I like to update
              This would be the expected behavior

              IExtensionManagerEvent.EM_NSFNOTECREATE: This code is always run when I update a document - nSFEvent.getNoteId() being null
              The Extension Manager will make the call back for any registered events.  This is true even with nested calls.  In the case of updating a document there is a code path that creates a temporary document which is what is triggering the EM_NSFNOTECREATE event you're seeing in this case.  It would be normal to get a NoteId of 0 for a newly created document since it hasn't been saved and does not yet have a NOTEID.

              IExtensionManagerEvent.HOOK_EVENT_NOTE_UPDATE: This code is run sometime when I update a document
              IExtensionManagerEvent.EM_NSFNOTEUPDATEXTENDED ||IExtensionManagerEvent.EM_NSFNOTEUPDATE : This code is not  run when I update a document

              I'm still looking into EM_NSFNOTEUPDATE[XTENDED] notifications in response to your question and another, I will post another update when I have more information.

              • More comments

                By Michael B Nielsen 1 decade ago

                When I delete one document in my test database the NSFHookNoteUpdateEvent is triggered and not the NSFNoteDeleteEvent.

                When I make more then one document to be deleted and I press F9 the NSFHookNoteUpdateEvent is trickered once and give me a handel (nodeId) for only one of the documents - no other event being triggered.

                Looking forward to hearing from you

                // Michael

                 

                • [UPDATED] Some comments on how delete events are handled

                  By Paul Fiore 1 decade ago

                  Hi Michael,

                  On deleted documents, depending on code paths and setup, a delete call may actually be going through the NSFNOTEUPDATEXTENDED callback with a flag set for UPDATE_DELETED.  If you look at the C API reference you will note that it states: "NSFNoteDelete specifies this flag when it calls NSFNoteUpdate in the process of writing the deletion stub to the disk."

                  [UPDATED: The comments below would be the method to get the callback but at this time it appears that those EM events have not been fully implemented within the DOTS framework.]

                  When multiple documents are selected to be deleted they go through NSFDbStampNotes which in turn calls NSFNOTEUPDATEXTENDED.  So you may want to register EM_NSFDBSTAMPNOTES and EM_NSFDBSTAMPNOTESMULTIITEM which would call the dotsDbStampNotes method in dotsNSFHook.cpp.  This should allow you to get access to the ID Table of the deleted notes.

                  Regards,

                  -Paul