/** * Lookup all values for the specified attribute, looping through the results incrementally if necessary. * * @param ldapOperations The instance to use for performing the actual lookup. * @param dn The distinguished name of the object to find. * @param attribute name of the attribute to request. * @return a list with all attribute values found for the requested attribute. * Never <code>null</code>, an empty list indicates that the attribute was not set or empty. */ public static List<Object> lookupAttributeValues(LdapOperations ldapOperations, Name dn, String attribute) { List<Object> values = loopForAllAttributeValues(ldapOperations, dn, new String[]{attribute}).getValues(attribute); if(values == null) { values = Collections.emptyList(); } return values; }
/** * Lookup all values for the specified attribute, looping through the results incrementally if necessary. * * @param ldapOperations The instance to use for performing the actual lookup. * @param dn The distinguished name of the object to find. * @param attribute name of the attribute to request. * @return a list with all attribute values found for the requested attribute. * Never <code>null</code>, an empty list indicates that the attribute was not set or empty. */ public static List<Object> lookupAttributeValues(LdapOperations ldapOperations, Name dn, String attribute) { List<Object> values = loopForAllAttributeValues(ldapOperations, dn, new String[]{attribute}).getValues(attribute); if(values == null) { values = Collections.emptyList(); } return values; }
/** * Lookup all values for the specified attribute, looping through the results incrementally if necessary. * * @param ldapOperations The instance to use for performing the actual lookup. * @param dn The distinguished name of the object to find. * @param attribute name of the attribute to request. * @return a list with all attribute values found for the requested attribute. * Never <code>null</code>, an empty list indicates that the attribute was not set or empty. */ public static List<Object> lookupAttributeValues(LdapOperations ldapOperations, Name dn, String attribute) { List<Object> values = loopForAllAttributeValues(ldapOperations, dn, new String[]{attribute}).getValues(attribute); if(values == null) { values = Collections.emptyList(); } return values; }
/** * Lookup all values for the specified attribute, looping through the results incrementally if necessary. * * @param ldapOperations The instance to use for performing the actual lookup. * @param dn The distinguished name of the object to find. * @param attribute name of the attribute to request. * @return a list with all attribute values found for the requested attribute. * Never <code>null</code>, an empty list indicates that the attribute was not set or empty. */ public static List<Object> lookupAttributeValues(LdapOperations ldapOperations, Name dn, String attribute) { List<Object> values = loopForAllAttributeValues(ldapOperations, dn, new String[]{attribute}).getValues(attribute); if(values == null) { values = Collections.emptyList(); } return values; }
@Override public final Attributes getCollectedAttributes() { BasicAttributes attributes = new BasicAttributes(); Set<String> attributeNames = stateMap.keySet(); for (String attributeName : attributeNames) { BasicAttribute oneAttribute = new BasicAttribute(attributeName); List<Object> values = getValues(attributeName); if (values != null) { for (Object oneValue : values) { oneAttribute.add(oneValue); } } attributes.put(oneAttribute); } return attributes; }
@Override public final Attributes getCollectedAttributes() { BasicAttributes attributes = new BasicAttributes(); Set<String> attributeNames = stateMap.keySet(); for (String attributeName : attributeNames) { BasicAttribute oneAttribute = new BasicAttribute(attributeName); List<Object> values = getValues(attributeName); if (values != null) { for (Object oneValue : values) { oneAttribute.add(oneValue); } } attributes.put(oneAttribute); } return attributes; }
@Override public final Attributes getCollectedAttributes() { BasicAttributes attributes = new BasicAttributes(); Set<String> attributeNames = stateMap.keySet(); for (String attributeName : attributeNames) { BasicAttribute oneAttribute = new BasicAttribute(attributeName); List<Object> values = getValues(attributeName); if (values != null) { for (Object oneValue : values) { oneAttribute.add(oneValue); } } attributes.put(oneAttribute); } return attributes; }
@Override public final Attributes getCollectedAttributes() { BasicAttributes attributes = new BasicAttributes(); Set<String> attributeNames = stateMap.keySet(); for (String attributeName : attributeNames) { BasicAttribute oneAttribute = new BasicAttribute(attributeName); List<Object> values = getValues(attributeName); if (values != null) { for (Object oneValue : values) { oneAttribute.add(oneValue); } } attributes.put(oneAttribute); } return attributes; }
@Test public void testLoopEmpty() throws Exception { assertThat(tested.hasMore()).isTrue(); Attributes attributes = new BasicAttributes(); tested.mapFromAttributes(attributes); assertThat(tested.hasMore()).isFalse(); assertThat(tested.getValues("member")).isNull(); }
@Test public void testLoop() throws Exception { Attributes attributes = createAttributes("member", new RangeOption(0, 10)); tested.mapFromAttributes(attributes); assertThat(tested.hasMore()).isTrue(); assertThat(tested.getValues("member")).hasSize(11); attributes = createAttributes("member", new RangeOption(11), 5); tested.mapFromAttributes(attributes); assertThat(tested.hasMore()).isFalse(); assertThat(tested.getValues("member")).hasSize(16); }
@Test public void test2LoopsWithPageSizeExact() throws Exception { tested = new DefaultIncrementalAttributesMapper(20, "member"); Attributes attributes = createAttributes("member", new RangeOption(0, 10)); tested.mapFromAttributes(attributes); assertThat(tested.hasMore()).isTrue(); assertThat(tested.getValues("member")).hasSize(11); attributes = createAttributes("member", new RangeOption(11, 30)); tested.mapFromAttributes(attributes); assertThat(tested.hasMore()).isFalse(); assertThat(tested.getValues("member")).hasSize(31); }
@Test public void test2LoopsWithPageSize() throws Exception { tested = new DefaultIncrementalAttributesMapper(20, "member"); Attributes attributes = createAttributes("member", new RangeOption(0, 10)); tested.mapFromAttributes(attributes); assertThat(tested.hasMore()).isTrue(); assertThat(tested.getValues("member")).hasSize(11); attributes = createAttributes("member", new RangeOption(11), 5); tested.mapFromAttributes(attributes); assertThat(tested.hasMore()).isFalse(); assertThat(tested.getValues("member")).hasSize(16); }
@Test public void testLoopWithTwoRangedAttributesLoopOnOneAttribute() throws Exception { tested = new DefaultIncrementalAttributesMapper(10, new String[]{"member", "cn"}); Attributes attributes = createAttributes("member", new RangeOption(0, 5)); attributes.put(createRangeAttribute("cn", new RangeOption(0, 10), 10)); tested.mapFromAttributes(attributes); assertThat(tested.hasMore()).isTrue(); assertThat(tested.getValues("member")).hasSize(6); assertThat(tested.getValues("cn")).hasSize(10); assertThat(tested.getAttributesForLookup().length).isEqualTo(1); attributes = createAttributes("member", new RangeOption(6), 5); tested.mapFromAttributes(attributes); assertThat(tested.hasMore()).isFalse(); assertThat(tested.getValues("member")).hasSize(11); }
@Test public void test1LoopWithPageSizeExact() throws Exception { tested = new DefaultIncrementalAttributesMapper(10, "member"); Attributes attributes = createAttributes("member", new RangeOption(0, 10)); tested.mapFromAttributes(attributes); assertThat(tested.hasMore()).isFalse(); assertThat(tested.getValues("member")).hasSize(11); }
@Test public void verifyRetrievalOfLotsOfAttributeValues() { DistinguishedName testgroupDn = new DistinguishedName(OU_DN).append("cn", "testgroup"); // The 'member' attribute consists of > 1500 entries and will not be returned without range specifier. DirContextOperations ctx = ldapTemplate.lookupContext(testgroupDn); assertThat(ctx.getStringAttribute("member")).isNull(); DefaultIncrementalAttributesMapper attributeMapper = new DefaultIncrementalAttributesMapper(new String[]{"member", "cn"}); assertThat(attributeMapper.hasMore()).as("There should be more results to get").isTrue(); String[] attributesArray = attributeMapper.getAttributesForLookup(); assertThat(attributesArray.length).isEqualTo(2); assertThat(attributesArray[0]).isEqualTo("member"); assertThat(attributesArray[1]).isEqualTo("cn"); // First iteration - there should now be more members left, but all cn values should have been collected. ldapTemplate.lookup(testgroupDn, attributesArray, attributeMapper); assertThat(attributeMapper.hasMore()).as("There should be more results to get").isTrue(); // Only member attribute should be requested in this query. attributesArray = attributeMapper.getAttributesForLookup(); assertThat(attributesArray.length).isEqualTo(1); assertThat(attributesArray[0]).isEqualTo("member;Range=1500-*"); // Second iteration - all data should now have been collected. ldapTemplate.lookup(testgroupDn, attributeMapper.getAttributesForLookup(), attributeMapper); assertThat(attributeMapper.hasMore()).as("There should be no more results to get").isFalse(); List memberValues = attributeMapper.getValues("member"); assertThat(memberValues).isNotNull(); assertThat(memberValues).hasSize(1501); List cnValues = attributeMapper.getValues("cn"); assertThat(cnValues).isNotNull(); assertThat(cnValues).hasSize(1); }