Created
April 29, 2024 11:37
-
-
Save klehmann/070859a7cf5911b04963eb7aae2103a2 to your computer and use it in GitHub Desktop.
View lookup and conversion of column values
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 com.mindoo.domino.jna.test; | |
import java.util.ArrayList; | |
import java.util.EnumSet; | |
import java.util.List; | |
import org.junit.Test; | |
import com.mindoo.domino.jna.NotesCollection; | |
import com.mindoo.domino.jna.NotesCollection.ViewLookupCallback; | |
import com.mindoo.domino.jna.NotesDatabase; | |
import com.mindoo.domino.jna.NotesViewEntryData; | |
import com.mindoo.domino.jna.constants.Find; | |
import com.mindoo.domino.jna.constants.ReadMask; | |
import lotus.domino.Session; | |
public class ViewLookupExample extends BaseJNATestClass { | |
@Test | |
public void testDirLookup() { | |
runWithSession(new IDominoCallable<Object>() { | |
@Override | |
public Object call(Session session) throws Exception { | |
NotesDatabase db = getFakeNamesDb(); | |
NotesCollection view = db.openCollectionByName("($Users)"); | |
String lookupKey = "eas"; | |
ViewLookupCallback<List<Person>> callback = new ViewLookupCallback<List<Person>>() { | |
@Override | |
public List<Person> startingLookup() { | |
return new ArrayList<>(); | |
} | |
@Override | |
public Action entryRead(List<Person> result, NotesViewEntryData entryData) { | |
String unid = entryData.getUNID(); | |
String fullName = entryData.getAsString("fullname", ""); | |
String shortName = entryData.getAsString("shortname", ""); | |
String email = entryData.getAsString("internetaddress", ""); | |
result.add(new Person(unid, fullName, shortName, email)); | |
//continue lookup | |
return Action.Continue; | |
} | |
@Override | |
public List<Person> lookupDone(List<Person> result) { | |
//do some post processing or just keep the result | |
return result; | |
} | |
}; | |
EnumSet<Find> findFlags = EnumSet.of( | |
Find.CASE_INSENSITIVE, // ignore case | |
Find.PARTIAL // prefix search | |
); | |
List<Person> persons = view.getAllEntriesByKey(findFlags, | |
EnumSet.of(ReadMask.NOTEUNID, ReadMask.SUMMARYVALUES), | |
callback, | |
lookupKey); | |
System.out.println("Found " + persons.size() + " persons for key "+lookupKey); | |
persons.forEach(System.out::println); | |
return null; | |
} | |
}); | |
} | |
private static class Person { | |
private String id; | |
private String fullName; | |
private String shortlastName; | |
private String email; | |
public Person(String id, String fullName, String shortName, String email) { | |
this.id = id; | |
this.fullName = fullName; | |
this.shortlastName = shortName; | |
this.email = email; | |
} | |
public String getId() { | |
return id; | |
} | |
public String getFullName() { | |
return fullName; | |
} | |
public String getShortName() { | |
return shortlastName; | |
} | |
public String getEmail() { | |
return email; | |
} | |
@Override | |
public String toString() { | |
return "Person [id=" + id + ", fullName=" + fullName + ", shortName=" + shortlastName + ", email=" + email + "]"; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment