Created
October 19, 2017 08:55
-
-
Save PatrickKwinten/c3580344a48704b3589251c0d5bbb8e5 to your computer and use it in GitHub Desktop.
Now we collect the values from documents in a Notes view
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.wordpress.quintessens.demo.app; | |
import java.io.IOException; | |
import java.util.ArrayList; | |
import java.util.HashSet; | |
import java.util.List; | |
import java.util.Properties; | |
import java.util.Set; | |
import java.util.TreeSet; | |
import java.util.Vector; | |
import java.util.regex.Matcher; | |
import java.util.regex.Pattern; | |
import org.wordpress.quintessens.demo.utils.Utils; | |
import lotus.domino.Database; | |
import lotus.domino.Directory; | |
import lotus.domino.DirectoryNavigator; | |
import lotus.domino.Document; | |
import lotus.domino.DocumentCollection; | |
import lotus.domino.NotesException; | |
import lotus.domino.Session; | |
import lotus.domino.View; | |
import lotus.domino.ViewEntry; | |
import lotus.domino.ViewEntryCollection; | |
import com.ibm.xsp.complex.ValueBindingObjectImpl; | |
import com.ibm.xsp.extlib.component.picker.data.INamePickerData; | |
import com.ibm.xsp.extlib.component.picker.data.IPickerEntry; | |
import com.ibm.xsp.extlib.component.picker.data.IPickerOptions; | |
import com.ibm.xsp.extlib.component.picker.data.IPickerResult; | |
import com.ibm.xsp.extlib.component.picker.data.SimplePickerResult; | |
import com.ibm.xsp.model.domino.DominoUtils; | |
public class NamePickerView extends ValueBindingObjectImpl implements INamePickerData { | |
private Utils utils; | |
Properties props; | |
public NamePickerView(){ | |
//constructor | |
utils = new Utils(); | |
utils.printToConsole(this.getClass().getSimpleName().toString() + " - DirectoryNamePicker() // constructor"); | |
try { | |
props = utils.getDataSourceProperties(); | |
} catch (IOException e) { | |
// TODO Auto-generated catch block | |
e.printStackTrace(); | |
} | |
} | |
public String[] getSourceLabels () { | |
// TODO Auto-generated method stub | |
return null; | |
} | |
public boolean hasCapability (final int arg0) { | |
// TODO Auto-generated method stub | |
return false; | |
} | |
public List<IPickerEntry> loadEntries (final Object[] arg0, final String[] arg1) { | |
// TODO Auto-generated method stub | |
return null; | |
} | |
public IPickerResult readEntries (final IPickerOptions options) { | |
String startKey = options.getStartKey(); | |
int count = options.getCount(); | |
List<IPickerEntry> entries = new ArrayList<IPickerEntry>(); | |
if (startKey != null) { | |
// User is performing a search | |
try { | |
entries = this.viewLookup(startKey, count); | |
} catch (NotesException e) { | |
System.err.println("Exception trying to perform directory lookup: " + e.getMessage()); | |
e.printStackTrace(); | |
} | |
} | |
else{ | |
//default list | |
try{ | |
entries = this.viewDefault(count); | |
}catch (NotesException e) { | |
System.err.println("Exception trying to perform directory lookup: " + e.getMessage()); | |
e.printStackTrace(); | |
} | |
} | |
return new SimplePickerResult(entries, -1); | |
} | |
private final static Pattern nameAbbreviate = Pattern.compile("((O|OU)=|^CN=)"); | |
public ArrayList<IPickerEntry> viewLookup(final String search, final int limit) throws NotesException { | |
String server = props.getProperty("server_notesname"); | |
String filepath = props.getProperty("db_data"); | |
Database db = utils.getSession().getDatabase(server, filepath); | |
ArrayList<IPickerEntry> personList = new ArrayList<IPickerEntry>(); | |
if (null != db){ | |
View vw = db.getView("vw_all_todo_namespicker"); | |
if (null != vw){ | |
vw.setAutoUpdate(false); | |
ViewEntryCollection vc = vw.getAllEntries(); | |
ViewEntry tmpentry; | |
ViewEntry entry = vc.getFirstEntry(); | |
int count = 0; | |
Vector<String> result = new Vector<String>(); | |
while (entry != null && count < limit){ | |
Vector<?> columnValues = entry.getColumnValues(); | |
Object columnValue = columnValues.get(0); | |
if( columnValue instanceof String ){ | |
String person = (String)columnValue; | |
if (person.toLowerCase().contains(search)){ | |
if(!result.contains(person)){ | |
result.add(person); | |
} | |
} | |
} | |
if( columnValue instanceof ArrayList ){ | |
ArrayList people = (ArrayList) columnValue; | |
for( int i=0; i<people.size(); i++ ){ | |
String person = (String)people.get(i); | |
if (person.toLowerCase().contains(search)){ | |
if(!result.contains(person)){ | |
result.add( person ); | |
} | |
} | |
} | |
} | |
if( columnValue instanceof Vector ){ | |
Vector<String> vec = (Vector) columnValue; | |
for( int i=0; i<vec.size(); i++ ){ | |
String person = (String)vec.get(i); | |
if (person.toLowerCase().contains(search)){ | |
if(!result.contains(person)){ | |
result.add( person ); | |
} | |
} | |
} | |
} | |
tmpentry = vc.getNextEntry(); | |
entry.recycle(); | |
entry = tmpentry; | |
count = count +1; | |
} | |
vw.setAutoUpdate(true); | |
Set<String> unique = new HashSet<String>(); | |
unique.addAll(result); | |
for( int i=0; i<result.size(); i++ ){ | |
String name = result.get(i); | |
IPickerEntry pickEntry = new SimplePickerResult.Entry(name, name); | |
personList.add(pickEntry); | |
} | |
} | |
vw.recycle(); | |
} | |
db.recycle(); | |
return personList; | |
} | |
public ArrayList<IPickerEntry> viewLookup2(final String search, final int limit) throws NotesException { | |
String server = props.getProperty("server_notesname"); | |
String filepath = props.getProperty("db_data"); | |
Database db = utils.getSession().getDatabase(server, filepath); | |
ArrayList<IPickerEntry> personList = new ArrayList<IPickerEntry>(); | |
if (null != db){ | |
View vw = db.getView("vw_all_todo_namespicker"); | |
if (null != vw){ | |
vw.setAutoUpdate(false); | |
ViewEntryCollection vc = vw.getAllEntriesByKey(search, false); | |
DocumentCollection nc = vw.getAllDocumentsByKey(search, false); | |
utils.printToConsole("vc size " + vc.getCount()); | |
utils.printToConsole("nc size " + nc.getCount()); | |
ViewEntry tmpentry; | |
ViewEntry entry = vc.getFirstEntry(); | |
int count = 0; | |
Vector<String> result = new Vector<String>(); | |
while (entry != null && count < limit){ | |
Vector<?> columnValues = entry.getColumnValues(); | |
Object columnValue = columnValues.get(0); | |
if( columnValue instanceof String ){ | |
String person = (String)columnValue; | |
if(!result.contains(person)){ | |
result.add(person); | |
} | |
} | |
if( columnValue instanceof ArrayList ){ | |
ArrayList people = (ArrayList) columnValue; | |
for( int i=0; i<people.size(); i++ ){ | |
String person = (String)people.get(i); | |
if(!result.contains(person)){ | |
result.add( person ); | |
} | |
} | |
} | |
if( columnValue instanceof Vector ){ | |
Vector<String> vec = (Vector) columnValue; | |
for( int i=0; i<vec.size(); i++ ){ | |
String person = (String)vec.get(i); | |
if(!result.contains(person)){ | |
result.add( person ); | |
} | |
} | |
} | |
tmpentry = vc.getNextEntry(); | |
entry.recycle(); | |
entry = tmpentry; | |
count = count +1; | |
} | |
vw.setAutoUpdate(true); | |
Set<String> unique = new HashSet<String>(); | |
unique.addAll(result); | |
utils.printToConsole("result " + result.size()); | |
utils.printToConsole("unique " + unique.size()); | |
for( int i=0; i<result.size(); i++ ){ | |
String name = result.get(i); | |
IPickerEntry pickEntry = new SimplePickerResult.Entry(name, name); | |
personList.add(pickEntry); | |
} | |
} | |
vw.recycle(); | |
} | |
db.recycle(); | |
return personList; | |
} | |
public ArrayList<IPickerEntry> viewDefault(final int limit) throws NotesException { | |
ArrayList<IPickerEntry> list = new ArrayList<IPickerEntry>(); | |
String server = props.getProperty("server_notes"); | |
String filepath = props.getProperty("db_data"); | |
Database db = utils.getSession().getDatabase(server, filepath); | |
if (null != db){ | |
View vw = db.getView("vw_all_todo_namespicker"); | |
if (null != vw){ | |
vw.setAutoUpdate(false); | |
ViewEntryCollection vc = vw.getAllEntries(); | |
int count = 0; | |
ViewEntry tmpentry; | |
ViewEntry entry = vc.getFirstEntry(); | |
Vector<String> result = new Vector<String>(); | |
while (entry != null && count < limit){ | |
Vector<?> names = entry.getColumnValues(); | |
Object tmp = names.get(0); | |
if( tmp instanceof String ){ | |
String person = (String)tmp; | |
if(!result.contains(person)){ | |
result.add(person); | |
} | |
} | |
if( tmp instanceof ArrayList ){ | |
ArrayList people = (ArrayList) tmp; | |
for( int i=0; i<people.size(); i++ ){ | |
String person = (String)people.get(i); | |
if(!result.contains(person)){ | |
result.add( person ); | |
} | |
} | |
} | |
if( tmp instanceof Vector ){ | |
Vector<String> vec = (Vector) tmp; | |
for( int i=0; i<vec.size(); i++ ){ | |
String person = (String)vec.get(i); | |
if(!result.contains(person)){ | |
result.add( person ); | |
} | |
} | |
} | |
tmpentry = vc.getNextEntry(); | |
entry.recycle(); | |
entry = tmpentry; | |
count = count +1; | |
} | |
vw.setAutoUpdate(true); | |
for( int i=0; i<result.size(); i++ ){ | |
String name = result.get(i); | |
IPickerEntry pickEntry = new SimplePickerResult.Entry(name, name); | |
list.add(pickEntry); | |
} | |
} | |
vw.recycle(); | |
} | |
db.recycle(); | |
return list; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment