Adding an annotation

You use methods from the ODHit class to add or retrieve an annotation (also known as a note) from a folder.

About this task

An object of the class ODHit represents a Content Manager OnDemand document. The following example uses ODHit methods to display the number of annotations associated with the document and add an annotation with these attributes:
  • The specified annotation text
  • OkToCopy=false
  • Public=false (that is, a private annotation)
  • An empty group name
This example demonstrates the following ODHit methods:
  • getNotes
  • addNote
This example uses ODServer methods to do the following tasks:
  • Prepare for logon
  • Open the specified folder
  • Log off
The example uses the ODFolder methods to search the folder, get the number of hits that matched the query, and close the folder.
This example demonstrates the following ODServer methods:
  • initialize
  • logon
  • openFolder
  • logoff
  • terminate
This example demonstrates the following ODFolder methods:
  • search
  • getDocId
  • getHits
  • close
This example demonstrates the following ODNote methods:
  • getGroupName
  • getText
  • isOkToCopy
  • isPublic
  • setGroupName
  • setOkToCopy
  • setPublic
  • setText
This example uses the following runtime parameters:
  • Server name
  • Port
  • User Id
  • Password
  • Folder name
  • Text of annotation

Example of adding an annotation:

import java.util.*;
import java.io.*;
import com.ibm.edms.od.*;

public class TcAddNote
{
  public static void main ( String argv[] )
  {
    ODServer odServer;
    ODFolder odFolder;
    ODHit odHit;
    ODNote odNote;
    Vector hits;
    Vector notes;
    int j;

    //----------
    // If too few parameters, display syntax and get out
    //----------
    if ( argv.length < 6 )
    {
      System.out.println( "usage: java TcAddNote <server> <port> <userid> <password> <folder> <note text>" );
      return;
    }

    try
    {
      //----------
      // Set the stage
      //----------
      System.out.println( "Testcase TcAddNote started." );
      System.out.println( "This testcase should:" );
      System.out.println( "  Logon to the specified server" );
      System.out.println( "  Open the specified folder" );
      System.out.println( "  Search the folder using the default criteria" );
      System.out.println( "  Display the number of hits" );
      System.out.println( "  Display the number of notes associated with the first hit" );
      System.out.println( "  Add a new note with the these attributes" );
      System.out.println( "    The specified note text" );
      System.out.println( "    OkToCopy=false" );
      System.out.println( "    Public=false (i.e. a private note)" );
      System.out.println( "    An empty group name" );
      System.out.println( "" );
      System.out.println( "---------------------------------------------------" );
      System.out.println( "" );

      //----------
      // Logon to specified server
      //----------

      ODConfig odConfig = new ODConfig();

      if (odConfig != null)
      {
        odServer = new ODServer(odConfig );
        odServer.initialize( "TcAddNote.java" );
        odServer.setPort(Integer.parseInt(argv[1]));
        System.out.println( "Logging on to " + argv[0] + " server with user " + argv[2] + "..." );
        odServer.logon( argv[0], argv[2], argv[3]);
        //----------
        // Open the specified folder and search with the default criteria
        //----------
        System.out.println( "Opening " + argv[4] + " folder..." );
        odFolder = odServer.openFolder( argv[4] );
        System.out.println( "Searching with default criteria..." );
        odFolder.search( );
        hits = odFolder.getHits( );
        System.out.println( "  Number of hits: " + hits.size( ) );

        //----------
        // Add a new note
        //----------
        if ( hits.size( ) > 0 )
        {
          odHit = (ODHit)hits.elementAt( 0 );
          System.out.println("Working with DocID " + odHit.getDocId());
          notes = odHit.getNotes( );
          if(notes.size() > 0)
          System.out.println("  There are " + notes.size( ) + " notes for the first hit" );

          odNote = new ODNote( );
          odNote.setText( argv[5] );
          odNote.setGroupName( "" );
          odNote.setOkToCopy( false );
          odNote.setPublic( false );

          System.out.println("  Adding a new note with:" );
          System.out.println("    Text='" + odNote.getText( ) + "'" );
          System.out.println("      UserId=" + argv[2] );
          System.out.println("      Page=1" );
          System.out.println("      Color=" + 'Y' );
          System.out.println("      Group=" + odNote.getGroupName( ) );
          System.out.println("      Offset=(0,0)" );
          System.out.println("    OkToCopy=" + odNote.isOkToCopy( ) );
          System.out.println("    Public=" + odNote.isPublic( ) );
          System.out.println("    Group=" + odNote.getGroupName( ) );

          odHit.addNote( odNote );
        }
        else
          System.out.println( "No document - cannot list notes" );

        //----------
        // Cleanup
        //----------
        odFolder.close( );
        odServer.logoff( );
        odServer.terminate( );
        System.out.println( "" );
        System.out.println( "---------------------------------------------------" );
        System.out.println( "" );
        System.out.println( "Testcase TcAddNote completed. - Ensure that the new note was correctly" );
        System.out.println( "  added by displaying it with the Windows Client" );
        System.out.println( "" );
      }
      else
      {
         System.out.println( "" );
         System.out.println( "Testcase TcAddNote failed  -" );
         System.out.println( "  ODConfig could not be initialized.  " );
         System.out.println( "" );
      }
    }

    catch ( ODException e )
    {
      System.out.println( "ODException: " + e );
      System.out.println( "   id = " + e.getErrorId( ) );
      System.out.println( "  msg = " + e.getErrorMsg( ) );
      e.printStackTrace( );
    }

    catch ( Exception e2 )
    {
      System.out.println( "exception: " + e2 );
      e2.printStackTrace( );
    }
  }
}