Using native Notes API's - Java example

 

Please refer to the document describing using the OnTime Group Calendar API (here after API) using Notes native API's before reading this document (see Using the OnTime Group Calendar API using Notes native APIs (over NRPC)).

import lotus.domino.Agent;
import lotus.domino.AgentBase;
import lotus.domino.Database;
import lotus.domino.Document;
import lotus.domino.Item;
import lotus.domino.Session;
import java.util.Vector;

public class JavaAgent extends AgentBase {

   public void NotesMain() {
      try {
         // get agent session
         Session session = getSession();

         // compose request
         String request = "{\"Main\": {\"ApplVer\": \"0.0.1\", \"ApplID\": \"Web2011\", \"APIVer\": 2}}";

         // get api database, agent and document
         final Database dbApi = session.getDatabase("Solace/Krynn", "ontime/ontimegcapi.nsf");
         final Agent agentApi = dbApi.getAgent("ApiNotes");
         Document docApi = dbApi.createDocument();

         final Vector v = new Vector();
         v.add("[ReadAll]");
         v.add("[Developer]");
         v.add(dbApi.getServer());
         v.add(session.getEffectiveUserName());
         Item item = docApi.replaceItemValue("_Authors", v);
         item.setReaders(true);
         item.setAuthors(true);
         docApi.replaceItemValue("$Request_0", request);
         docApi.sign();
         docApi.save();

         // get note id 
         final String noteid = docApi.getNoteID();
         docApi.recycle();
         docApi = null;

         // execute agent
         agentApi.runOnServer(noteid);

         // fetch api document
         docApi = dbApi.getDocumentByID(noteid);

         // get response
         StringBuilder b = new StringBuilder();
         for (int i=0; docApi.hasItem("$Response_" + i); i++) {
            b.append(docApi.getItemValueString("$Response_" + i));
         }

         // write response
         System.out.println(b.toString());
      } catch (Exception e) {
         e.printStackTrace();
      }
   }
}

 

Tuesday, 28 October 2014 Posted in Development