Quantcast
Channel: WebSphere Blog by Steve Robinson » Uncategorized
Viewing all articles
Browse latest Browse all 10

Lotus Domino Java agent to remove documents by date

$
0
0

I needed to create an agent in a Lotus Notes Database that would delete documents older than a certain date. My need was to delete some internet stats in my web stats DB. Here is the code for the agent. It is very basic, but it works.

import lotus.domino.*;
public class JavaAgent extends AgentBase {
  public void NotesMain() {
    try {
      Session session = getSession();
      AgentContext agentContext = session.getAgentContext();
      Database db = agentContext.getCurrentDatabase();

      View view = db.getView("SBD");
      Document doc = view.getFirstDocument();
      Document nextDoc;
      int count=0;
      int countRemoved=0;
      DateTime dateConstant = session.createDateTime ( "12/02/2013 00:00:01 AM" );
      DateTime dateCreated;
      while (doc != null) {
    	    nextDoc = view.getNextDocument(doc);
    	    dateCreated = doc.getCreated();
            System.out.println(dateConstant.timeDifference(dateCreated));
            if (dateCreated.timeDifference(dateConstant) < 0) {
            	System.out.println("dateConstant=" + dateConstant.getLocalTime());
            	System.out.println("dateCreated=" + dateCreated.getLocalTime());
                System.out.println("Source=" + doc.getItemValueString("Source"));
                System.out.println("Removing Document");
                doc.remove(true);
                countRemoved++;
            }

      count++;
      doc = nextDoc;
      }

      view.refresh();
      System.out.println("Processed (" + count  + ") documents");
      System.out.println("Removed(" + countRemoved  + ") documents");

    } catch(Exception e) {
      e.printStackTrace();
    }
  }
}


Viewing all articles
Browse latest Browse all 10

Latest Images

Trending Articles



Latest Images