Monday, December 21, 2009

Sorting a Notes Document Collection in Java

As I searched in net and could not find a sorted document collection in Java, basically it is available in lotus script. So I rewritten the same in Java.

I written a class by name sortCollection with methods on this like

GetEmptyDocumentCollection,
SortDocumentCollection ( the function takes a document collection as its argument and returns a sorted document collection in assending order).

class SortCollection {
Session session;
AgentContext agentContext;
Database currentDB;
SortCollection() throws NotesException
{
try {
session = NotesFactory.createSession();
agentContext = session.getAgentContext();
currentDB = agentContext.getCurrentDatabase();
} catch( NotesException e) {
throw e;
}
}
// gets an empty notes document collection

public DocumentCollection GetEmptyDocumentCollection() throws NotesException
{
DocumentCollection dc = currentDB.getProfileDocCollection("xxxxxxx");
try
{ if(dc.getCount() > 0 )
dc.removeAll(true);
return dc;
} catch( NotesException e) {
throw e;
}
}
// this method takes a unsorted notes document collection and returns a sorted collection.
public DocumentCollection SortDocumentCollection (DocumentCollection dc ) throws NotesException
{
System.out.println("SortDocumentCollection process Started");
try
{ int count;
count = dc.getCount();
if( count <= 1)
return dc;
Document docs[] = new Document[count];
Document loopDoc;
loopDoc = dc.getFirstDocument();
int i = 0;
while (loopDoc != null)
{
docs[i] = loopDoc;
loopDoc = dc.getNextDocument(loopDoc);
i= i+1;
}
Document outerLoopDoc;
Document innerLoopDoc;
DateTime outerLoopDocLastModDate;
DateTime innerLoopDocLastModDate;
for( int j=0; j <>
{
outerLoopDoc = docs[j];
for(int k=0; k <>
{
innerLoopDoc = docs[k];
innerLoopDocLastModDate = innerLoopDoc.getLastModified();
outerLoopDocLastModDate = outerLoopDoc.getLastAccessed();
if( innerLoopDocLastModDate.timeDifference(outerLoopDocLastModDate) > 0 )
{
Document tempDoc;
tempDoc = docs[j];
docs[j]= docs[k];
docs[k] = tempDoc ;
}
}
}
DocumentCollection returnDocColl;
returnDocColl = GetEmptyDocumentCollection();
for(int j=0; j
returnDocColl.addDocument(docs[j]);
System.out.println("SortDocumentCollection process Finished");
return returnDocColl;
} catch( NotesException e)
{ throw e;
}

}
}
- Narasimha Reddy, Lomadi

2 comments:

  1. Great job, congratulations!
    The lines with "for" cycle are incomplete, could you complete them please!

    Thanks a lot!

    ReplyDelete
  2. please, complete "for" statements...thanks

    ReplyDelete

Generating a CSR with Java keytool , deploying the certificates in keystore and configuring the same in the tomEE server.

  Deploying security certificates is a three-step process in general 1. CSR Generation 2. Importing the certificatates into the keystore 3. ...