PooledLdapRepository extends CrudRepositoryBase<T, String> implements LdapRepository<T> { @Override public <S extends T> S add(S entity) { Preconditions.checkNotNull(entity, "Cannot add null object to %s, expected %s", baseDn, getEntityClass().getName()); final Entry entry = mapper.toEntry(entity, baseDn); log.info("Add LDAP Entry {}: {}", entry.getDn(), entry); final Entry newEntry = withConnection(new Function<LdapConnection, Entry>() { @Override @Nullable public Entry apply(@Nullable LdapConnection conn) { try { conn.add(entry); log.debug("Lookup added LDAP Entry {}", entry.getDn()); return conn.lookup(entry.getDn()); } catch (LdapException e) { throw new LdapRepositoryException(e, "Error adding LDAP Entry %s", entry.getDn()); } } }); return (S) mapper.fromEntry(newEntry, entityClass); } PooledLdapRepository(final Class<? extends T> entityClass, final ObjectPool<LdapConnection> pool, final String baseDn); @Override @Deprecated void init(); @Override S add(S entity); @Override @Nonnull T modify(final T entity); @Override S modify(String id, final S entity); @Override boolean delete(String id); @SuppressWarnings("unchecked") @Override U findOne(String id); @Override String toDn(String id); @Override T findOneByAttribute(String attribute, String value); @Override List<String> findIdsByAttribute(String attribute, String value); @Override List<T> findAll(); @Override String getBaseDn(); @Override Class<? extends T> getEntityClass(); @Override LdapMapper<T> getMapper(); ObjectPool<LdapConnection> getPool(); @Override boolean exists(@Nullable String id); @Override List<T> search(@Nullable String searchText); @Override boolean existsByAttribute(String attribute, String value); @Override List<T> findAllByFilter(String filter); @Override long count(); @Override long countByAttribute(String attribute, String value); @Override Page<T> findAll(final Pageable pageable); @Override List<String> findIdsByFilter(String filter);  }
@Test public void add() { SocialPerson liz = new SocialPerson("liz", "liz.lemon", "Liz", "Lemon", Gender.FEMALE); liz.setEmails(ImmutableSet.of("liz.lemon@example.com", "liz@example.com")); liz.setPhotoId("liz_lemon"); liz.setFacebookId(123456L); liz.setFacebookUsername("liz.lemon"); liz.setTwitterId(123456L); liz.setTwitterScreenName("liz.lemon"); liz.setBirthDate(new DateTime(new Date())); liz.setNewsletterSubscriptionEnabled(true); liz.setNewsletterSubscriptionTime(new DateTime()); liz.setSignupSourceType(SignupSourceType.ALIA_MAGAZINE); liz.setAccountStatus(AccountStatus.ACTIVE); log.info("Input Person: {}", liz); SocialPerson newLiz = personRepo.add(liz); Assert.assertNotNull(newLiz); SocialPerson foundLiz = personRepo.findOne("liz"); Assert.assertNotNull(foundLiz); Assert.assertEquals("liz", foundLiz.getId()); Assert.assertEquals("Liz Lemon", foundLiz.getName()); }