/** * Creates a new search result. * * @param entry ldap entry */ public SearchResult(final LdapEntry... entry) { this(); for (LdapEntry e : entry) { addEntry(e); } }
/** * Creates a new search result. * * @param entry ldap entry */ public SearchResult(final LdapEntry... entry) { this(); for (LdapEntry e : entry) { addEntry(e); } }
/** * Adds entry(s) to this search result. * * @param entries collection of entries to add */ public void addEntries(final Collection<LdapEntry> entries) { for (LdapEntry e : entries) { addEntry(e); } }
/** * Creates a new search result. * * @param entry ldap entry */ public SearchResult(final LdapEntry... entry) { this(); for (LdapEntry e : entry) { addEntry(e); } }
/** * Returns a portion of this result between the specified fromIndex, inclusive, and toIndex, exclusive. If fromIndex * and toIndex are equal, the return result is empty. The result of this method is undefined for unordered results. * * @param fromIndex low endpoint of the search result (inclusive) * @param toIndex high endpoint of the search result (exclusive) * * @return portion of this search result * * @throws IndexOutOfBoundsException for illegal index values */ public SearchResult subResult(final int fromIndex, final int toIndex) { if (fromIndex < 0 || toIndex > resultEntries.size() || fromIndex > toIndex) { throw new IndexOutOfBoundsException("Illegal index value"); } final SearchResult result = new SearchResult(getSortBehavior()); if (resultEntries.isEmpty() || fromIndex == toIndex) { return result; } int i = 0; for (Map.Entry<String, LdapEntry> e : resultEntries.entrySet()) { if (i >= fromIndex && i < toIndex) { result.addEntry(e.getValue()); } i++; } return result; }
/** * Returns a portion of this result between the specified fromIndex, inclusive, and toIndex, exclusive. If fromIndex * and toIndex are equal, the return result is empty. The result of this method is undefined for unordered results. * * @param fromIndex low endpoint of the search result (inclusive) * @param toIndex high endpoint of the search result (exclusive) * * @return portion of this search result * * @throws IndexOutOfBoundsException for illegal index values */ public SearchResult subResult(final int fromIndex, final int toIndex) { if (fromIndex < 0 || toIndex > resultEntries.size() || fromIndex > toIndex) { throw new IndexOutOfBoundsException("Illegal index value"); } final SearchResult result = new SearchResult(getSortBehavior()); if (resultEntries.isEmpty() || fromIndex == toIndex) { return result; } int i = 0; for (Map.Entry<String, LdapEntry> e : resultEntries.entrySet()) { if (i >= fromIndex && i < toIndex) { result.addEntry(e.getValue()); } i++; } return result; }
/** * Returns a portion of this result between the specified fromIndex, inclusive, and toIndex, exclusive. If fromIndex * and toIndex are equal, the return result is empty. The result of this method is undefined for unordered results. * * @param fromIndex low endpoint of the search result (inclusive) * @param toIndex high endpoint of the search result (exclusive) * * @return portion of this search result * * @throws IndexOutOfBoundsException for illegal index values */ public SearchResult subResult(final int fromIndex, final int toIndex) { if (fromIndex < 0 || toIndex > resultEntries.size() || fromIndex > toIndex) { throw new IndexOutOfBoundsException("Illegal index value"); } final SearchResult result = new SearchResult(getSortBehavior()); if (resultEntries.isEmpty() || fromIndex == toIndex) { return result; } int i = 0; for (Map.Entry<String, LdapEntry> e : resultEntries.entrySet()) { if (i >= fromIndex && i < toIndex) { result.addEntry(e.getValue()); } i++; } return result; }
/** * Creates a search result that corresponds to the supplied DSML document. * * @param doc DSML to parse * * @return search result */ protected SearchResult createSearchResult(final Document doc) { final SearchResult result = new SearchResult(sortBehavior); if (doc != null && doc.hasChildNodes()) { final NodeList nodes = doc.getElementsByTagName("dsml:entry"); for (int i = 0; i < nodes.getLength(); i++) { final LdapEntry le = createLdapEntry((Element) nodes.item(i)); result.addEntry(le); } } return result; }
/** * Creates a search result that corresponds to the supplied DSML document. * * @param doc DSML to parse * * @return search result */ protected SearchResult createSearchResult(final Document doc) { final SearchResult result = new SearchResult(sortBehavior); if (doc != null && doc.hasChildNodes()) { final NodeList nodes = doc.getElementsByTagName("dsml:entry"); for (int i = 0; i < nodes.getLength(); i++) { final LdapEntry le = createLdapEntry((Element) nodes.item(i)); result.addEntry(le); } } return result; }
/** * Creates a search result that corresponds to the supplied DSML document. * * @param doc DSML to parse * * @return search result */ protected SearchResult createSearchResult(final Document doc) { final SearchResult result = new SearchResult(sortBehavior); if (doc != null && doc.hasChildNodes()) { final NodeList nodes = doc.getElementsByTagName("dsml:entry"); for (int i = 0; i < nodes.getLength(); i++) { final LdapEntry le = createLdapEntry((Element) nodes.item(i)); result.addEntry(le); } } return result; }
@Override public SearchResult deserialize(final JsonElement json, final Type type, final JsonDeserializationContext context) throws JsonParseException { final SearchResult result = new SearchResult(sortBehavior); final JsonArray jsonResult = json.getAsJsonArray(); for (JsonElement jsonEntry : jsonResult) { final LdapEntry entry = new LdapEntry(sortBehavior); for (Map.Entry<String, JsonElement> jsonAttr : jsonEntry.getAsJsonObject().entrySet()) { if ("dn".equals(jsonAttr.getKey())) { entry.setDn(jsonAttr.getValue().getAsString()); } else { final LdapAttribute attr = new LdapAttribute(sortBehavior); attr.setName(jsonAttr.getKey()); jsonAttr.getValue().getAsJsonArray().forEach(i -> attr.addStringValue(i.getAsString())); entry.addAttribute(attr); } } result.addEntry(entry); } return result; } }
@Override public SearchResult deserialize(final JsonElement json, final Type type, final JsonDeserializationContext context) throws JsonParseException { final SearchResult result = new SearchResult(sortBehavior); final JsonArray jsonResult = json.getAsJsonArray(); for (JsonElement jsonEntry : jsonResult) { final LdapEntry entry = new LdapEntry(sortBehavior); for (Map.Entry<String, JsonElement> jsonAttr : jsonEntry.getAsJsonObject().entrySet()) { if ("dn".equals(jsonAttr.getKey())) { entry.setDn(jsonAttr.getValue().getAsString()); } else { final LdapAttribute attr = new LdapAttribute(sortBehavior); attr.setName(jsonAttr.getKey()); jsonAttr.getValue().getAsJsonArray().forEach(i -> attr.addStringValue(i.getAsString())); entry.addAttribute(attr); } } result.addEntry(entry); } return result; } }
result.addEntry(entry);
for (Response<SearchResult> r : responses) { for (LdapEntry le : r.getResult().getEntries()) { result.addEntry(le); logger.debug("Search found: {}", le.getDn());
for (Response<SearchResult> r : responses) { for (LdapEntry le : r.getResult().getEntries()) { result.addEntry(le); logger.debug("Search found: {}", le.getDn());
for (Response<SearchResult> r : responses) { for (LdapEntry le : r.getResult().getEntries()) { result.addEntry(le); logger.debug("Search found: {}", le.getDn());
/** * Tests ordered sort behavior. * * @param entry1 ldap entry * @param entry2 ldap entry */ @Test(groups = {"bean"}, dataProvider = "entries") public void orderedSortBehavior(final LdapEntry entry1, final LdapEntry entry2) { final SearchResult sr = new SearchResult(SortBehavior.ORDERED); AssertJUnit.assertEquals(SortBehavior.ORDERED, sr.getSortBehavior()); sr.addEntry(entry2, entry1); final LdapEntry[] entries = sr.getEntries().toArray(new LdapEntry[2]); AssertJUnit.assertEquals(entry2, entries[0]); AssertJUnit.assertEquals(entry1, entries[1]); sr.clear(); AssertJUnit.assertEquals(0, sr.size()); }
/** * Tests sorted sort behavior. * * @param entry1 ldap entry * @param entry2 ldap entry */ @Test(groups = {"bean"}, dataProvider = "entries") public void sortedSortBehavior(final LdapEntry entry1, final LdapEntry entry2) { final SearchResult sr = new SearchResult(SortBehavior.SORTED); AssertJUnit.assertEquals(SortBehavior.SORTED, sr.getSortBehavior()); sr.addEntry(entry2, entry1); final LdapEntry[] entries = sr.getEntries().toArray(new LdapEntry[2]); AssertJUnit.assertEquals(entry1, entries[0]); AssertJUnit.assertEquals(entry2, entries[1]); sr.clear(); AssertJUnit.assertEquals(0, sr.size()); }
/** * Tests create with a collection. * * @param entry1 ldap entry * @param entry2 ldap entry */ @Test(groups = {"bean"}, dataProvider = "entries") public void createCollection(final LdapEntry entry1, final LdapEntry entry2) { final Set<LdapEntry> s = new HashSet<>(); s.add(entry1); final SearchResult sr = new SearchResult(s); sr.addEntry(entry2); AssertJUnit.assertEquals(entry1, sr.getEntry("UID=1")); AssertJUnit.assertEquals(entry2, sr.getEntry("uid=2")); AssertJUnit.assertEquals(2, sr.getEntryDns().length); AssertJUnit.assertEquals(2, sr.size()); AssertJUnit.assertEquals(sr, new SearchResult(entry1, entry2)); sr.removeEntry("UID=1"); AssertJUnit.assertEquals(1, sr.size()); sr.clear(); AssertJUnit.assertEquals(0, sr.size()); }
sr.addEntry(entry2, entry1); AssertJUnit.assertEquals(0, sr.subResult(2, 2).size()); AssertJUnit.assertEquals(1, sr.subResult(1, 2).size());