Merging Two Domino Databases With Folders

I’ve had a few cases recently where some users ended up with multiple archives because they moved from having a local archive to a server based archive for their email. When this happens the user eventually asks if there is any way to merge the two archives so that just have a single place to look for their archived email.

The BOFH Admins will gladly help the user out by telling them that they can copy/paste the emails from one archive to the other. This takes forever and the user normally gives up or ends up with duplicate emails. Sometimes it’s fun being a BOFH Admin Laughing

But there is a way to easily merge two archives ( or any two Lotus Domino databases for that fact ) using LotusScript. You can even take into account all the folders in both databases and copy over the folders ( including their design ) for folders in the source database that don’t already exist in the destination database. All you need is the following agent. It’s not 100% perfect, it relies on the fact that every document is in a folder so it won;t work for databases that use 100% views but it could easily be modified for that if you need it.

I hope it helps somebody out there. It just saved me a load of time…

%REM
 Agent Merge Archives
 Created Dec 14, 2010 by Declan Lynch/CZARNOWSKI
 Description: Copies all documents from a source database to a destination database including folders and folder designs
 %END REM
 Option Public
 Option Declare
Sub Initialize
Dim s As New NotesSession
 Dim w As New NotesUIWorkspace
 Dim sourceDB As NotesDatabase
 Dim sourceView As NotesView
Dim sourceViewColl As NotesViewEntryCollection
 Dim sourceViewEntry As NotesViewEntry
 Dim sourceFolders() As String
Dim destDB As NotesDatabase
 Dim destView As NotesView
 Dim destViewColumn As NotesViewColumn
 Dim destDoc As NotesDocument
Dim colCount As Integer
' Ask for the Source DB and See If It Exists
 Dim selectedSourceDB
 MessageBox "Please Select the Source Database",64,"Lotus Notes Database Merger"
 selectedSourceDB = w.Prompt( 13, "Choose the source database to copy the folders from","Lotus Notes Database Merger" )
 If IsEmpty( selectedSourceDB ) Then
 MessageBox "Source database not selected", , "Lotus Notes Database Merger"
 Exit Sub
 End If
 Set sourceDB = s.GetDatabase( selectedSourceDB(0), selectedSourceDB(1), False )
 If sourceDB is Nothing Then
 MessageBox "Error Opening The Source Database", , "Lotus Notes Database Merger"
 Exit Sub
 End If
' Ask for the Destination DB and See If It Exists
 MessageBox "Please Select the Destination Database",64,"Lotus Notes Database Merger"
 Dim selectedDestDB
 selectedDestDB = w.Prompt( 13, "Choose the destination database to copy the folder to","Lotus Notes Database Merger" )
 If IsEmpty( selectedDestDB ) Then
 MessageBox "Destination database selected.", , "Lotus Notes Database Merger"
 Exit Sub
 End If
 Set destDB = s.GetDatabase( selectedDestDB(0), selectedDestDB(1), False )
 If destDB is Nothing Then
 MessageBox "Error Opening The Destination Database", , "Lotus Notes Database Merger"
 Exit Sub
 End If
' Get All The Folders In The Source DB
 ForAll v In sourceDB.Views
 If v.IsFolder Then
 Print "Processing Folder : " + v.Name
 Set sourceView = sourceDB.getView(v.Name)
 Set sourceViewColl = sourceView.Allentries
Set destView = destDB.getView(v.Name)
 If destView is Nothing Then
 ' No existing Destination folder. Create A New Folder
 Call destDB.EnableFolder(v.Name)
 Set destView = destDB.getView(v.Name)
 ' Copy the Source Folder Design
 ' Remove all The view columns From the folder
 While destView.ColumnCount > 0
 Call destView.RemoveColumn(destView.ColumnCount)
 Wend
 ' Copy All the ViewColumns from the source Folder
 For colCount = 0 To sourceView.ColumnCount-1
 Set destViewColumn = destView.CopyColumn(sourceView.Columns(colCount), colCount+1)
 Next
 End If
' Copy All The Documents In The Folder To The Destination Database
 Set sourceViewEntry = sourceViewColl.GetFirstEntry
 Do Until sourceViewEntry Is Nothing
 Set destDoc = sourceViewEntry.Document.CopyToDatabase(destDB)
 Call destDoc.PutInFolder(v.Name)
 Set sourceViewEntry = sourceViewColl.GetNextEntry(sourceViewEntry)
 Loop
End If
 End ForAll
MessageBox "Processing Complete",64,"Lotus Notes Database Merger"
End Sub
Tagged with: , ,
Posted in Uncategorized

Dynamic PDF creation using XPages and the iTextPDF Java Libary

Recently I was tasked with adding an ‘Export To PDF’ function to one of our internal applications so I had a quick look around at possible solutions and I found that some others in the Lotus community had been successful in using the iTextPDF library with their applications but only with client based apps and classic Domino web apps. I couldn’t find any information of using iTextPDF with XPages so I set about seeing if I could get it to work.

The first thing you will need to do is download the iTextPDF JAR file and add it into your NSF. I won’t explain how to do that here as a quick google search shows that a number of people have blogged about how to do that already.

Once you have the JAR file in your NSF you can now generate your PDF files using SSJS. For my purposes I added a ‘link’ control to a page and then in the server side onClick even I used the following code…

———————————————————————

// Load the java packages
importPackage(com.itextpdf);

//Initialization
var con = facesContext.getExternalContext();
var response:com.ibm.xsp.webapp.XspHttpServletResponse = con.getResponse();

//setting response headers for browser to recognize data
response.setContentType(“application/pdf”);
response.setHeader(“Cache-Control”, “no-cache”);
response.setDateHeader(“Expires”, -1);
response.setHeader( “Content-Disposition”, “attachment; filename=”export.pdf”” );

// Setup the PDF Output Stream
var newPDF:com.itextpdf.text.Document = new com.itextpdf.text.Document();
var writer = com.itextpdf.text.pdf.PdfWriter.getInstance(newPDF,response.getOutputStream());

// Open the PDF and write the PDF header info
newPDF.open();
newPDF.addAuthor(“Declan Lynch”);
newPDF.addCreationDate();
newPDF.addCreator(“IBM Lotus Domino V8.5.2 : XPages iText Library”);
newPDF.addTitle(“PDF Export Demo”);

Tagged with: , ,
Posted in None

Steeler Monkey

Tagged with: , ,
Posted in Uncategorized

Things I Hope Not To See At Lotusphere 2011

It’s that time of year again, Lotusphere registration is open, abstracts are being written and submitted ( I’m not submitting any abstracts myself ), and in a few weeks we’ll see loads of blog posts from people saying that they will be speaking at Lotusphere and probably one or two comments complaining that they aren’t speaking at Lotusphere and how life is unfair.

With all that in mind I’d like to present for your comments my list of things that I HOPE I don’t see at Lotusphere 2011…

The fold-out sessions schedule. Please bring back the booklet, it was easier to manage.

That’s my list. Comment below if you have anything to add, maybe the Lotusphere gods and goddesses will take a look in and take a look at the list.

Tagged with:
Posted in Uncategorized
Archives