@Test public void canMapFromBooleanFalse2() throws LdapException { final LdapMapper<SocialPerson> mapper = new LdapMapper<>(); final Entry existing = new DefaultEntry("uid=hendy,ou=users,dc=aksimata,dc=com"); existing.put("objectClass", "organizationalPerson", "extensibleObject", "inetOrgPerson", "uidObject"); existing.put("uid", "hendy"); existing.put("cn", "Hendy Irawan"); existing.put("newsletterSubscriptionEnabled", "false"); log.info("Input Entry: {}", existing); final SocialPerson person = mapper.fromEntry(existing, SocialPerson.class); assertEquals(false, person.getNewsletterSubscriptionEnabled()); }
public T fromEntry(Entry entry, Class<? extends T> entityClass) { if (entry.getDn() == null) throw new LdapMappingException("LDAP Entry DN cannot be null"); try { final T bean = entityClass.newInstance(); Class<?> currentClass = entityClass; while (currentClass != null) { mapToProperties(entry, currentClass, bean); currentClass = currentClass.getSuperclass(); if (currentClass == Object.class) break; } return bean; } catch (InstantiationException e) { log.error("Error mapping Entry " + entry.getDn() + " to " + entityClass.getName(), e); throw new LdapMappingException("Error mapping Entry " + entry.getDn() + " to " + entityClass.getName(), e); } catch (IllegalAccessException e) { log.error("Error mapping Entry " + entry.getDn() + " to " + entityClass.getName(), e); throw new LdapMappingException("Error mapping Entry " + entry.getDn() + " to " + entityClass.getName(), e); } catch (InvocationTargetException e) { log.error("Error mapping Entry " + entry.getDn() + " to " + entityClass.getName(), e); throw new LdapMappingException("Error mapping Entry " + entry.getDn() + " to " + entityClass.getName(), e); } catch (LdapInvalidAttributeValueException e) { log.error("Error mapping Entry " + entry.getDn() + " to " + entityClass.getName(), e); throw new LdapMappingException("Error mapping Entry " + entry.getDn() + " to " + entityClass.getName(), e); } catch (NoSuchMethodException e) { log.error("Error mapping Entry " + entry.getDn() + " to " + entityClass.getName(), e); throw new LdapMappingException("Error mapping Entry " + entry.getDn() + " to " + entityClass.getName(), e); } }
LdapMapper { public T fromEntry(Entry entry, Class<? extends T> entityClass) { if (entry.getDn() == null) throw new LdapMappingException("LDAP Entry DN cannot be null"); try { final T bean = entityClass.newInstance(); Class<?> currentClass = entityClass; while (currentClass != null) { mapToProperties(entry, currentClass, bean); currentClass = currentClass.getSuperclass(); if (currentClass == Object.class) break; } return bean; } catch (InstantiationException e) { log.error("Error mapping Entry " + entry.getDn() + " to " + entityClass.getName(), e); throw new LdapMappingException("Error mapping Entry " + entry.getDn() + " to " + entityClass.getName(), e); } catch (IllegalAccessException e) { log.error("Error mapping Entry " + entry.getDn() + " to " + entityClass.getName(), e); throw new LdapMappingException("Error mapping Entry " + entry.getDn() + " to " + entityClass.getName(), e); } catch (InvocationTargetException e) { log.error("Error mapping Entry " + entry.getDn() + " to " + entityClass.getName(), e); throw new LdapMappingException("Error mapping Entry " + entry.getDn() + " to " + entityClass.getName(), e); } catch (LdapInvalidAttributeValueException e) { log.error("Error mapping Entry " + entry.getDn() + " to " + entityClass.getName(), e); throw new LdapMappingException("Error mapping Entry " + entry.getDn() + " to " + entityClass.getName(), e); } catch (NoSuchMethodException e) { log.error("Error mapping Entry " + entry.getDn() + " to " + entityClass.getName(), e); throw new LdapMappingException("Error mapping Entry " + entry.getDn() + " to " + entityClass.getName(), e); } } }
LdapMapper { public T fromEntry(Entry entry, Class<? extends T> entityClass) { if (entry.getDn() == null) throw new LdapMappingException("LDAP Entry DN cannot be null"); try { final T bean = entityClass.newInstance(); Class<?> currentClass = entityClass; while (currentClass != null) { mapToProperties(entry, currentClass, bean); currentClass = currentClass.getSuperclass(); if (currentClass == Object.class) break; } return bean; } catch (InstantiationException e) { log.error("Error mapping Entry " + entry.getDn() + " to " + entityClass.getName(), e); throw new LdapMappingException("Error mapping Entry " + entry.getDn() + " to " + entityClass.getName(), e); } catch (IllegalAccessException e) { log.error("Error mapping Entry " + entry.getDn() + " to " + entityClass.getName(), e); throw new LdapMappingException("Error mapping Entry " + entry.getDn() + " to " + entityClass.getName(), e); } catch (InvocationTargetException e) { log.error("Error mapping Entry " + entry.getDn() + " to " + entityClass.getName(), e); throw new LdapMappingException("Error mapping Entry " + entry.getDn() + " to " + entityClass.getName(), e); } catch (LdapInvalidAttributeValueException e) { log.error("Error mapping Entry " + entry.getDn() + " to " + entityClass.getName(), e); throw new LdapMappingException("Error mapping Entry " + entry.getDn() + " to " + entityClass.getName(), e); } catch (NoSuchMethodException e) { log.error("Error mapping Entry " + entry.getDn() + " to " + entityClass.getName(), e); throw new LdapMappingException("Error mapping Entry " + entry.getDn() + " to " + entityClass.getName(), e); } } LdapMapper(); }
LdapMapper { public T fromEntry(Entry entry, Class<? extends T> entityClass) { if (entry.getDn() == null) throw new LdapMappingException("LDAP Entry DN cannot be null"); try { final T bean = entityClass.newInstance(); Class<?> currentClass = entityClass; while (currentClass != null) { mapToProperties(entry, currentClass, bean); currentClass = currentClass.getSuperclass(); if (currentClass == Object.class) break; } return bean; } catch (InstantiationException e) { log.error("Error mapping Entry " + entry.getDn() + " to " + entityClass.getName(), e); throw new LdapMappingException("Error mapping Entry " + entry.getDn() + " to " + entityClass.getName(), e); } catch (IllegalAccessException e) { log.error("Error mapping Entry " + entry.getDn() + " to " + entityClass.getName(), e); throw new LdapMappingException("Error mapping Entry " + entry.getDn() + " to " + entityClass.getName(), e); } catch (InvocationTargetException e) { log.error("Error mapping Entry " + entry.getDn() + " to " + entityClass.getName(), e); throw new LdapMappingException("Error mapping Entry " + entry.getDn() + " to " + entityClass.getName(), e); } catch (LdapInvalidAttributeValueException e) { log.error("Error mapping Entry " + entry.getDn() + " to " + entityClass.getName(), e); throw new LdapMappingException("Error mapping Entry " + entry.getDn() + " to " + entityClass.getName(), e); } catch (NoSuchMethodException e) { log.error("Error mapping Entry " + entry.getDn() + " to " + entityClass.getName(), e); throw new LdapMappingException("Error mapping Entry " + entry.getDn() + " to " + entityClass.getName(), e); } } LdapMapper(); LdapMapping getMapping(final Class<?> clazz); Entry toEntry(Object obj, String baseDn); Set<String> getAttributeIds(Class<?> clazz); T fromEntry(Entry entry, Class<? extends T> entityClass); String getDn(final String rdnValue, final Class<?> clazz, final String baseDn); @Nonnull String getDn(final Object obj, final String baseDn); @Nullable String getRdnValue(final Object obj); ModifyRequest createModifyRequest(final Entry existingEntry, final T existing, final T up); }
LdapMapper { public T fromEntry(Entry entry, Class<? extends T> entityClass) { if (entry.getDn() == null) throw new LdapMappingException("LDAP Entry DN cannot be null"); try { final T bean = entityClass.newInstance(); Class<?> currentClass = entityClass; while (currentClass != null) { mapToProperties(entry, currentClass, bean); currentClass = currentClass.getSuperclass(); if (currentClass == Object.class) break; } return bean; } catch (InstantiationException e) { log.error("Error mapping Entry " + entry.getDn() + " to " + entityClass.getName(), e); throw new LdapMappingException("Error mapping Entry " + entry.getDn() + " to " + entityClass.getName(), e); } catch (IllegalAccessException e) { log.error("Error mapping Entry " + entry.getDn() + " to " + entityClass.getName(), e); throw new LdapMappingException("Error mapping Entry " + entry.getDn() + " to " + entityClass.getName(), e); } catch (InvocationTargetException e) { log.error("Error mapping Entry " + entry.getDn() + " to " + entityClass.getName(), e); throw new LdapMappingException("Error mapping Entry " + entry.getDn() + " to " + entityClass.getName(), e); } catch (LdapInvalidAttributeValueException e) { log.error("Error mapping Entry " + entry.getDn() + " to " + entityClass.getName(), e); throw new LdapMappingException("Error mapping Entry " + entry.getDn() + " to " + entityClass.getName(), e); } catch (NoSuchMethodException e) { log.error("Error mapping Entry " + entry.getDn() + " to " + entityClass.getName(), e); throw new LdapMappingException("Error mapping Entry " + entry.getDn() + " to " + entityClass.getName(), e); } } LdapMapper(); LdapMapping getMapping(final Class<?> clazz); Entry toEntry(Object obj, String baseDn); Set<String> getAttributeIds(Class<?> clazz); T fromEntry(Entry entry, Class<? extends T> entityClass); String getDn(final String rdnValue, final Class<?> clazz, final String baseDn); @Nonnull String getDn(final Object obj, final String baseDn); @Nullable String getRdnValue(final Object obj); ModifyRequest createModifyRequest(final Entry existingEntry, final T existing, final T up);  }