@Test public void canMapToBooleanFalse() throws LdapException { final LdapMapper<SocialPerson> mapper = new LdapMapper<>(); final SocialPerson hendy = new SocialPerson("hendy", "hendy", "Hendy", "Irawan"); hendy.setNewsletterSubscriptionEnabled(false); log.info("Input Person: {}", hendy); final Entry personEntry = mapper.toEntry(hendy, "ou=users"); assertEquals("FALSE", personEntry.get("newsletterSubscriptionEnabled").getString()); }
public Entry toEntry(Object obj, String baseDn) { Preconditions.checkNotNull(obj, "Cannot map null object in %s", baseDn); final Class<?> clazz = obj.getClass(); log.trace("Mapping {} {} as Entry in {}", clazz.getName(), obj, baseDn); final DefaultEntry entry = new DefaultEntry(); LdapEntry entryAnn = clazz.getAnnotation(LdapEntry.class); if (entryAnn == null) { throw new LdapMappingException(clazz.getName() + " must be annotated with @LdapEntry"); } final String[] objectClasses = entryAnn.objectClasses(); log.trace("{} maps to objectClasses: {}", clazz.getName(), objectClasses); try { entry.add("objectClass", objectClasses); Class<?> currentClass = clazz; while (currentClass != null) { mapFromProperties(obj, baseDn, currentClass, entry); currentClass = currentClass.getSuperclass(); if (currentClass == Object.class || currentClass == EObjectImpl.class) break; } return entry; } catch (LdapException | IllegalAccessException | InvocationTargetException | NoSuchMethodException e) { throw new LdapMappingException(e, "Error mapping " + clazz.getName()); } }
LdapMapper { public Entry toEntry(Object obj, String baseDn) { Preconditions.checkNotNull(obj, "Cannot map null object in %s", baseDn); final Class<?> clazz = obj.getClass(); log.trace("Mapping {} {} as Entry in {}", clazz.getName(), obj, baseDn); final DefaultEntry entry = new DefaultEntry(); LdapEntry entryAnn = clazz.getAnnotation(LdapEntry.class); if (entryAnn == null) { throw new LdapMappingException(clazz.getName() + " must be annotated with @LdapEntry"); } final String[] objectClasses = entryAnn.objectClasses(); log.trace("{} maps to objectClasses: {}", clazz.getName(), objectClasses); try { entry.add("objectClass", objectClasses); Class<?> currentClass = clazz; while (currentClass != null) { mapFromProperties(obj, baseDn, currentClass, entry); currentClass = currentClass.getSuperclass(); if (currentClass == Object.class || currentClass == EObjectImpl.class) break; } return entry; } catch (LdapException | IllegalAccessException | InvocationTargetException | NoSuchMethodException e) { throw new LdapMappingException(e, "Error mapping " + clazz.getName()); } } }
LdapMapper { public Entry toEntry(Object obj, String baseDn) { Preconditions.checkNotNull(obj, "Cannot map null object in %s", baseDn); final Class<?> clazz = obj.getClass(); log.trace("Mapping {} {} as Entry in {}", clazz.getName(), obj, baseDn); final DefaultEntry entry = new DefaultEntry(); LdapEntry entryAnn = clazz.getAnnotation(LdapEntry.class); if (entryAnn == null) { throw new LdapMappingException(clazz.getName() + " must be annotated with @LdapEntry"); } final String[] objectClasses = entryAnn.objectClasses(); log.trace("{} maps to objectClasses: {}", clazz.getName(), objectClasses); try { entry.add("objectClass", objectClasses); Class<?> currentClass = clazz; while (currentClass != null) { mapFromProperties(obj, baseDn, currentClass, entry); currentClass = currentClass.getSuperclass(); if (currentClass == Object.class || currentClass == EObjectImpl.class) break; } return entry; } catch (LdapException | IllegalAccessException | InvocationTargetException | NoSuchMethodException e) { throw new LdapMappingException(e, "Error mapping " + clazz.getName()); } } LdapMapper(); }
LdapMapper { public Entry toEntry(Object obj, String baseDn) { Preconditions.checkNotNull(obj, "Cannot map null object in %s", baseDn); final Class<?> clazz = obj.getClass(); log.trace("Mapping {} {} as Entry in {}", clazz.getName(), obj, baseDn); final DefaultEntry entry = new DefaultEntry(); LdapEntry entryAnn = clazz.getAnnotation(LdapEntry.class); if (entryAnn == null) { throw new LdapMappingException(clazz.getName() + " must be annotated with @LdapEntry"); } final String[] objectClasses = entryAnn.objectClasses(); log.trace("{} maps to objectClasses: {}", clazz.getName(), objectClasses); try { entry.add("objectClass", objectClasses); Class<?> currentClass = clazz; while (currentClass != null) { mapFromProperties(obj, baseDn, currentClass, entry); currentClass = currentClass.getSuperclass(); if (currentClass == Object.class || currentClass == EObjectImpl.class) break; } return entry; } catch (LdapException | IllegalAccessException | InvocationTargetException | NoSuchMethodException e) { throw new LdapMappingException(e, "Error mapping " + clazz.getName()); } } 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 Entry toEntry(Object obj, String baseDn) { Preconditions.checkNotNull(obj, "Cannot map null object in %s", baseDn); final Class<?> clazz = obj.getClass(); log.trace("Mapping {} {} as Entry in {}", clazz.getName(), obj, baseDn); final DefaultEntry entry = new DefaultEntry(); LdapEntry entryAnn = clazz.getAnnotation(LdapEntry.class); if (entryAnn == null) { throw new LdapMappingException(clazz.getName() + " must be annotated with @LdapEntry"); } final String[] objectClasses = entryAnn.objectClasses(); log.trace("{} maps to objectClasses: {}", clazz.getName(), objectClasses); try { entry.add("objectClass", objectClasses); Class<?> currentClass = clazz; while (currentClass != null) { mapFromProperties(obj, baseDn, currentClass, entry); currentClass = currentClass.getSuperclass(); if (currentClass == Object.class || currentClass == EObjectImpl.class) break; } return entry; } catch (LdapException | IllegalAccessException | InvocationTargetException | NoSuchMethodException e) { throw new LdapMappingException(e, "Error mapping " + clazz.getName()); } } 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);  }