xPages or not xPages

Are xPages a leading technologie ?

Obviously not. Of course Lotus has done a big effort to improve the gap between lotus notes and the today’s technologies, but they fail. The web has grown and they have choose the heavy choice of java and dojo.

What do you think ?

Coming next… dynamic class loading in lotusscript.,. stay tune !

Advertisements

Agent to create a backup of you names.nsf weekly

As an administrator, I often need to put me back in time to check something on the domino infrastructure. My Domino Domain is very small so I can afford to make a backup of my names.nsf every week.

This class, creat a copy of each documents of the names.nsf, zip it and attach it to a document… enjoy !


import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;

import lotus.domino.*;
import java.io.*;
import java.util.zip.*;

/* -----------------------------------------------------------------------------------------------------------------------
* Class : JavaAgent
* Date : 12.01.2011
* Author : Pierre Koerber
* Desc. : Permet de faire un backup du PAB et de le zipper.
*/

public class JavaAgent extends AgentBase {

public void NotesMain() {

try {

Session session = getSession();
AgentContext agentContext = session.getAgentContext();

// get the curr db
Database curDb ;
curDb = agentContext.getCurrentDatabase() ;

// (Your code goes here)
Database db ;
db = session.getDatabase(curDb.getServer(), "names.nsf") ;

DateTime timenow = session.createDateTime("Today");
timenow.setNow();

String sName = new String("") ;
String sZipName = new String("") ;
sName = db.getFilePath() ;

System.out.println("OS current temporary directory is " + System.getProperty("java.io.tmpdir"));

sName = System.getProperty("java.io.tmpdir") ;
sName = sName + "names_backup_" + timenow.getDateOnly().replace('.', '_') + ".nsf";

sZipName = System.getProperty("java.io.tmpdir") ;
sZipName = sZipName + "names_backup_" + timenow.getDateOnly().replace('.', '_') + ".zip";

// copy the database
System.out.println("Create a copy of the names.nsf =" + db.getServer() + "-" + db.getFilePath()) ;

this.deleteIfExist(sName) ;
Database newDb ;
newDb = db.createCopy("", sName) ;

// copy all the documents
DocumentCollection dc ;
Document d ;

dc = db.getAllDocuments() ;
d = dc.getFirstDocument() ;

while(d != null){

// No deletion stubs...
if (d.isDeleted() == false){
d.copyToDatabase(newDb) ;
}
d = dc.getNextDocument() ;
}

// Compress the stuff
System.out.println("Compressing file from " + sName + " to " + sZipName) ;

// delete the files if exist
this.deleteIfExist(sZipName) ;

// compress the database
this.doZipExt(sName,sZipName) ;

// create a document and attach the backup
System.out.println("Attach everything to the archive document") ;
Document doc ;
doc = curDb.createDocument() ;

doc.replaceItemValue("backupName", "Sauvegarde names.nsf of " + db.getServer() + " - " + timenow.getDateOnly()) ;
doc.replaceItemValue("Subject", doc.getItemValueString("backupName")) ;
doc.replaceItemValue("backupDate", timenow) ;
doc.replaceItemValue("agentName", agentContext.getCurrentAgent().getName()) ;
doc.replaceItemValue("Form", "backup") ;

lotus.domino.RichTextItem rt = doc.createRichTextItem("Body") ;
rt.embedObject(EmbeddedObject.EMBED_ATTACHMENT,null, sZipName, "archive") ;

// Save the document
doc.save(true, true);

// delete the database
this.deleteIfExist(sName) ;
this.deleteIfExist(sZipName) ;
System.out.println("Done");

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

public void deleteIfExist(String sName){
File f = new File(sName) ;
if (f.exists()) {
System.out.println("File : " + sName + " deleted");
f.delete() ;
}

}

public void doZipExt(String sFileName, String sZipFileName) throws IOException{
System.out.println("Creating zip file :" + sZipFileName) ;

File sourceFile = new File(sFileName) ;

// Create our zip file
ZipOutputStream zipfile = new ZipOutputStream(new FileOutputStream(sZipFileName));
FileInputStream filetozip = new FileInputStream(sFileName);
zipfile.putNextEntry(new ZipEntry(sourceFile.getName()));

// Loop through the contents writing it to the zip file output stream.
int len;
byte[] buffer = new byte[1024];

while ((len = filetozip.read(buffer)) > 0) {
zipfile.write(buffer,0,len);
}

// Close the entry and the current file.
zipfile.closeEntry();
filetozip.close();
// When done, close the zip file.
zipfile.close();
}

}

show nlcache reset – reset du names lookup domino

Hello, this comand will reset the domino names.nsf cache ! it will allow the user that you’ve just put in a group to have access to an app… be careful, this command has a significant cost on your server !

Greetings

Lotus Notes : simple soft delete form your application

Hi,

In our application it’s a common task to delete document but before granting the deletion, we want to be able to discard the modification…

Here the simpliest soft delete agent in your database, it juste rename the form name which should be enough in every lotus application.

FIELD Form := "DELETED_" + Form;
SELECT @All

Just put all this code in a lotus notes agent and you’re done !

Greetings.

Easy lotusscript picklist class for your apps…

When creating your application it’s always painful to remember how to generate a picklist… here comes in play my class (which is part of my own private framework).

Which 3 lines of code, I’m doing a picklist… let me explain…

Dim pl As New DbPickList(Nothing)
pl.setView("ClasseByName")
Set docRet = pl.getSingleDocument()

The first line allows you to create the picklist object which contain the notesuiworkspace object. The class contains member functions to set every parameter of the original picklist function. Defaults values are set when instantiating the object. There is two basic function to display the picklist 1. getSingleDocument() which return a simple document and getMultipleDocuments() which give you the notesdocumentcollection. Give a look to the class, it’s easy.

Link to the lss file

First download the .lss file and put everything in a script library. Then you should add the use statement.
The class allows you to customize easily the picklist but it is more convenient than the ugly function from the notesUiworkspace… give it a try and enjoy.

One cool thing is to derivate the class and then create all the picklist you need in a new class, then you’ve got centralized your picklists in a central class which allows to simplify the maintenance cycle of your app.

Greetings.

A remain of the past – the dusty console

After sometimes of laziness, (I’m too much playing with facebook and twitter) I’m back on my blog…

Which one of you is an old enough notes freak to remember the dusty old console which was the bread and butter of the dark age of the domino administration ? at this time to administrate a notes server you only need a strong knowledge of the domino directory and a simple console… old good times !

The old console remains in lotus notes today, and you can call it which a simple macro :

@Command([AdminRemoteConsole]) ;

Of course you need the rights to do it, it could be very useful when you are stuck with a “simple” notes client…

The cCounter class.

* When programming a very long an complex agent it’s very fine to display the agent stats at the end of the agent’s execution. These stats could be a lot of numeric data. It’s a pain to declare and manage all these variables.
* For doing this you need to create a lot of different counters and it’s very boring to manage the init part of these counters, the increment and the display. And what a pain if you want to add a new counter…
* With my solution you will find this very easy to manage and you will add a lot of interesting counters in your next complex agent.
* The idea is to put every counter in a class which will manage for us the boring job.
* This class will init the counter, manage the increment and give us the text.

Here the code :

'  Class counter v1.0
'  By Pierre Koerber

Class cCounter
lCounter List As Long

Public Function incrementCount(sCounterName As String)
If Iselement(lCounter(sCounterName)) = False Then
lCounter(sCounterName) = 1
Else
lCounter(sCounterName) = lCounter(sCounterName) + 1
End If
End Function

Public Function toString() As String
Dim sRes As String
Forall x In lCounter

If sRes = "" Then
sRes = Listtag(x) + "=" + Cstr(x)
Else
sRes = sRes + "," + Listtag(x) + "=" + Cstr(x)
End If
End Forall
toString = sRes
End Function

End Class

'-------------------------------

' calling code, this allows you to manage three counter in a easy and cool way.

'-------------------------------

sub initialize
dim counter as new cCounter()

set doc = dc.getFirstDocument
while not(doc is nothing)
if doc.Subject(0) = "" then
Call counter.incrementCount("Err")
else

call counter.incrementCount("Treated")
end if

Call counter.incrementCount("RcdTreated")
set doc = dc.getNextDocument(doc)
wend

log(counter.toString())

end sub