The following piece of code can be used to test the connectivity with the lotus notes and also can be used to perform various operations:
Session _session=null;
Session session=null;
Database userDb;
System.out.println("inside main");
try {
HashMap<String,String> credentialsMap=getHashMapFromProperties("./properties/LotusNotes.properties");
String hostName=credentialsMap.get("HostName");
System.out.println(hostName);
String port=credentialsMap.get("PortNumber");
System.out.println(port);
String AdminID=credentialsMap.get("AdminID");
System.out.println(AdminID);
String AdminPwd=credentialsMap.get("AdminPassword");
System.out.println(AdminPwd);
String server=credentialsMap.get("Server");
String database=credentialsMap.get("Database");
System.out.println("Creating Notes Session");
session=NotesFactory.createSession(hostName+":"+port,AdminID,AdminPwd);
System.out.println("Session created successfully");
userDb=session.getDatabase(server, database);
System.out.println("Database loaded successfully");
DocumentCollection collection=userDb.search("((form='Person')&(ShortName='"+arg[0]+"'))");
int countDoc=collection.getCount();
Document doc = collection.getFirstDocument();
.
.
.
-----
Reading the credentials from the properties file:
private static HashMap<String, String> getHashMapFromProperties(String filelocation){
HashMap<String, String> hashMap = new HashMap<String, String>();
String thisLine = null;
String DELIMITER="=";
try {
BufferedReader bufferedReader =
new BufferedReader(new InputStreamReader(new FileInputStream(filelocation)));
while ((thisLine = bufferedReader.readLine()) != null) {
if(thisLine.trim().startsWith("#")) continue;
int indexOfDelimiter = thisLine.indexOf(DELIMITER);
hashMap.put(thisLine.substring(0, indexOfDelimiter), thisLine.substring(indexOfDelimiter + 1));
}
} catch (FileNotFoundException e) {
System.out.println("Exception Occurred while parsing " + filelocation+":"+e);
System.exit(1);
} catch (IOException e) {
System.out.println("Exception Occurred while parsing " + filelocation+":"+e);
System.exit(1);
}
return hashMap;
}
Session _session=null;
Session session=null;
Database userDb;
System.out.println("inside main");
try {
HashMap<String,String> credentialsMap=getHashMapFromProperties("./properties/LotusNotes.properties");
String hostName=credentialsMap.get("HostName");
System.out.println(hostName);
String port=credentialsMap.get("PortNumber");
System.out.println(port);
String AdminID=credentialsMap.get("AdminID");
System.out.println(AdminID);
String AdminPwd=credentialsMap.get("AdminPassword");
System.out.println(AdminPwd);
String server=credentialsMap.get("Server");
String database=credentialsMap.get("Database");
System.out.println("Creating Notes Session");
session=NotesFactory.createSession(hostName+":"+port,AdminID,AdminPwd);
System.out.println("Session created successfully");
userDb=session.getDatabase(server, database);
System.out.println("Database loaded successfully");
DocumentCollection collection=userDb.search("((form='Person')&(ShortName='"+arg[0]+"'))");
int countDoc=collection.getCount();
Document doc = collection.getFirstDocument();
.
.
.
-----
Reading the credentials from the properties file:
private static HashMap<String, String> getHashMapFromProperties(String filelocation){
HashMap<String, String> hashMap = new HashMap<String, String>();
String thisLine = null;
String DELIMITER="=";
try {
BufferedReader bufferedReader =
new BufferedReader(new InputStreamReader(new FileInputStream(filelocation)));
while ((thisLine = bufferedReader.readLine()) != null) {
if(thisLine.trim().startsWith("#")) continue;
int indexOfDelimiter = thisLine.indexOf(DELIMITER);
hashMap.put(thisLine.substring(0, indexOfDelimiter), thisLine.substring(indexOfDelimiter + 1));
}
} catch (FileNotFoundException e) {
System.out.println("Exception Occurred while parsing " + filelocation+":"+e);
System.exit(1);
} catch (IOException e) {
System.out.println("Exception Occurred while parsing " + filelocation+":"+e);
System.exit(1);
}
return hashMap;
}
No comments:
Post a Comment