Lotus domino user information export to excel
You can export domino users using following steps:
1. Create Agent
2. Run Agent
Create Agent:
Using two way you can create agent:1. On Live server , open domino admin -> go to peoples->click Create->Agent->Put name(All User export) -Select type: Java- OK
-Open java file and paste the below code and Save it
2. If you don't want to do on live server, then copy the names.nsf file to your test server desktop and open it
-open domino admin -> go to peoples->click Create->Agent->Put name(All User export) -Select type: Java-OK
-Open java file and paste the below code and save it
Close the domino designer
--------------------------------------------------------------------------------------------
import lotus.domino.*;
import java.io.*;
import java.util.Iterator;
import java.util.Vector;
import java.lang.Enum;
public class JavaAgent extends AgentBase {
//no enums in the default java version supported by Domino :(
private class SMTPLocalPartTypeEnum {
static final int SHORTNAME = 2;
static final int FULLNAME = 0;
static final int COMMONNAME = 1;
}
private class AddressBuilder {
private Document _gddDoc;
private String _domainSepChar;
private int _smtpLocalPartType;
private boolean _isValidGDD;
AddressBuilder(Document gddDoc) throws Exception{
_gddDoc = gddDoc;
_domainSepChar = gddDoc.getItemValueString("SMTPNotesDomainSepChar");
_smtpLocalPartType = gddDoc.getItemValueInteger("SMTPLocalPart");
_isValidGDD = true;
if (gddDoc.getItemValueInteger("SMTPNotesDomainIncluded") != 0) {
System.out.println("domain(s) included is not set to none");
_isValidGDD = false;
}
if (gddDoc.getItemValueInteger("SMTPNotesDomainPos") == 1) {
System.out.println("Domains pos is not at left of the @ char");
_isValidGDD = false;
}
}
String buildInternetAddress(String mailDomain, Name name, String shortName) throws Exception {
if (!_isValidGDD)
return "";
String leftPart = "";
switch (_smtpLocalPartType)
{
case SMTPLocalPartTypeEnum.SHORTNAME:
leftPart = shortName;
break;
case SMTPLocalPartTypeEnum.COMMONNAME:
leftPart = name.getCommon().replace(' ', '_');
break;
case SMTPLocalPartTypeEnum.FULLNAME:
leftPart = name.getAbbreviated().replace(' ', '_');
break;
}
String ret = leftPart +_domainSepChar + mailDomain + "@" +
_gddDoc.getItemValueString("LocalPrimaryInternetDomain").toString();
return ret;
}
}
private class AddressBuilderProvider {
AddressBuilder _addressBuilder = null;
boolean _noGDD = false;
JavaAgent _agent;
AddressBuilderProvider(JavaAgent agent) {
_agent = agent;
}
AddressBuilder GetBuilder(String mailDomain) throws Exception
{
//for now ignore mailDomain and return default GDD or the single GDD found
if (_noGDD)
return null;
//based on further testing we may need to load different GDDs into a dictionary based on maildomain
//for now just use default gdd in case there are more than one or gdd found.
if (_addressBuilder != null)
return _addressBuilder;
View domains = _agent.getSession().getCurrentDatabase().getView("$Domains");
Document doc = domains.getFirstDocument();
if (doc == null)
System.out.println("first doc in dominas is null");
Document gdd = null;
while (doc != null)
{
System.out.println(doc.getItemValueString("DomainType").toString());
if (doc.getItemValueString("DomainType").toString().trim().compareTo("GlobalDomain") == 0)
{
gdd = doc;
if (doc.getItemValueInteger("DefaultGlobalDomain") == 1)
break;
}
doc = domains.getNextDocument(doc);
}
if (gdd == null)
{
System.out.println("gdd not found");
_noGDD = true;
return null;
}
_addressBuilder = new AddressBuilder(gdd);
return _addressBuilder;
}
}
private AddressBuilderProvider _addressBuilderProvider;
public void NotesMain() {
FileWriter fw = null;
try {
System.out.println("Starting...");
Session session = getSession();
AgentContext agentContext = session.getAgentContext();
Database db = session.getCurrentDatabase();
_addressBuilderProvider = new AddressBuilderProvider(this);
View view = db.getView("$VIMPeople");
view.setAutoUpdate(false);
Document doc = view.getFirstDocument();
File file = new File("AllUserexport.txt");
if (file.exists())
file.delete();
file.createNewFile();
fw = new FileWriter(file);
String lineSeparator = (String) java.security.AccessController.doPrivileged(
new sun.security.action.GetPropertyAction("line.separator"));
fw.append(lineSeparator);
fw.append(lineSeparator);
fw.append(lineSeparator);
while (doc != null)
{
Item fullName = doc.getFirstItem("FullName");
String dn = fullName.getValues().get(0).toString();
System.out.println(dn);
String shortName = doc.getItemValueString("ShortName").toLowerCase();
Name name = session.createName(dn);
fw.append("dn: ");
fw.append(dn);
fw.append(lineSeparator);
Item givenName = doc.getFirstItem("FirstName");
//if (givenName.getText().length() > 0)
//{
fw.append("FirstName: ");
fw.append(givenName.getText());
fw.append(lineSeparator);
//}
// 'MiddleInitial
Item MiddleInitial = doc.getFirstItem("MiddleInitial");
fw.append("MiddleInitial: ");
fw.append(MiddleInitial.getText());
fw.append(lineSeparator);
Item lastName = doc.getFirstItem("LastName");
fw.append("LastName: ");
fw.append(lastName.getText());
fw.append(lineSeparator);
Item mailFile = doc.getFirstItem("MailFile");
fw.append("MailFile: ");
fw.append(mailFile.getText());
fw.append(lineSeparator);
Item mail = doc.getFirstItem("InternetAddress");
System.out.println("mail:" + mail.getText() + " length:" + mail.getText().length());
String internetAddress = mail.getText().trim() == null || mail.getText().length() == 0 ? buildAutoGenInternetAddress(doc, name, shortName) : mail.getText();
fw.append("mail: ");
fw.append(internetAddress);
fw.append(lineSeparator);
Item mailDomain = doc.getFirstItem("MailDomain");
String mailDomainStr = mailDomain.getText() == null ? "" : mailDomain.getText();
fw.append("maildomain: ");
fw.append(mailDomainStr);
fw.append(lineSeparator);
String userNames = getUserNamesLeftPartOnly(fullName) ;
// userNames = internetAddress == null || internetAddress.isEmpty() ? userNames :
//userNames + ";" + getEmailAddrLeftPart(internetAddress);
fw.append("usernames: ");
fw.append(userNames);
fw.append(lineSeparator);
fw.append(lineSeparator);
doc = view.getNextDocument(doc);
}
fw.append(lineSeparator);
// (Your code goes here)
} catch(Exception e) {
e.printStackTrace();
System.out.println(e.getMessage());
}
finally {
if (fw != null)
try {
fw.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
String getUserNamesLeftPartOnly(Item fullName) throws Exception {
Vector userNames = fullName.getValues();
StringBuilder sb = new StringBuilder();
Iterator it = userNames.iterator();
while (it.hasNext()) {
String userName = (String)it.next();
if (userName.indexOf("@")>0)
sb.append(getEmailAddrLeftPart(userName));
else
sb.append(userName.toLowerCase());
sb.append(";");
}
return sb.toString();
}
String getEmailAddrLeftPart(String emailAddress) throws Exception {
//int atPos = 0;
//atPos = emailAddress.indexOf("@");
//return emailAddress.substring(0,atPos).toLowerCase();
Name name = getSession().createName(emailAddress);
return name.getAddr822LocalPart().toLowerCase();
}
String buildAutoGenInternetAddress(Document personDoc, Name name, String shortName) throws Exception
{
System.out.println(" in buildAutoGenInternetAddress");
String mailDomain = personDoc.getItemValueString("MailDomain").toString();
if (mailDomain == "")
return "";
AddressBuilder addressBuilder = _addressBuilderProvider.GetBuilder(mailDomain);
if (addressBuilder == null)
return "";
return addressBuilder.buildInternetAddress(mailDomain, name, shortName);
}
}
Close the domino designer
------------------------------------------------------------------------------------------------
Export User information
- Open Admin->Click Action->Click on All User export
- You will fine the AllUserexport.txt file in Lotus folder at admin client path
Reference: https://archive.atlassian.net/wiki/display/adminhelp/Domino+User+Export+Instructions


