Patch from Jasper on August 1.
This commit is contained in:
@@ -91,17 +91,27 @@ public class LdapDaoITest extends AbstractLdapTemplateIntegrationTest
|
||||
}
|
||||
|
||||
|
||||
public void testLoadsReferencedEntities()
|
||||
public void testLoadsReferences()
|
||||
{
|
||||
ITestRole webUser = (ITestRole) ldapDao.findByNamingAttribute("webUser", ITestRole.class);
|
||||
ldapDao.create(testPerson);
|
||||
webUser.setMembers(new ITestPerson[]{testPerson});
|
||||
ldapDao.update(webUser);
|
||||
ITestRole updated = (ITestRole) ldapDao.findByNamingAttribute("webUser", ITestRole.class);
|
||||
LOGGER.debug(updated);
|
||||
LOGGER.debug("Updated:" + updated);
|
||||
Assert.assertTrue(ArrayUtils.contains(updated.getMembers(), testPerson));
|
||||
}
|
||||
|
||||
public void testLoadsReferences_brokenReferenceReturnedAsNull()
|
||||
{
|
||||
ITestRole webUser = (ITestRole) ldapDao.findByNamingAttribute("webUser", ITestRole.class);
|
||||
webUser.setMembers(new ITestPerson[]{testPerson});
|
||||
ldapDao.update(webUser);
|
||||
ITestRole updated = (ITestRole) ldapDao.findByNamingAttribute("webUser", ITestRole.class);
|
||||
Assert.assertNotNull(updated);
|
||||
LOGGER.debug(updated);
|
||||
}
|
||||
|
||||
|
||||
public void testFindByDn()
|
||||
{
|
||||
|
||||
@@ -1,6 +1,13 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
|
||||
<beans>
|
||||
<beans
|
||||
xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:grid="http://schema.majitek.com/spring"
|
||||
xsi:schemaLocation="
|
||||
http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
|
||||
http://schema.majitek.com/spring
|
||||
http://schema.majitek.com/grid-spring-v1.0.xsd">
|
||||
|
||||
<import resource="classpath:/apacheDsContext.xml"/>
|
||||
|
||||
@@ -17,25 +24,25 @@
|
||||
<property name="dirObjectFactory" value="org.springframework.ldap.core.support.DefaultDirObjectFactory" />
|
||||
</bean>
|
||||
|
||||
<bean id="ldapTemplate" singleton="true" class="org.springframework.ldap.core.LdapTemplate">
|
||||
<bean id="ldapTemplate" scope="singleton" class="org.springframework.ldap.core.LdapTemplate">
|
||||
<constructor-arg ref="contextSource"/>
|
||||
</bean>
|
||||
|
||||
<bean id="typeConverter" singleton="true" class="org.springframework.ldap.odm.typeconversion.LdapTypeConverter"/>
|
||||
<bean id="typeConverter" scope="singleton" class="org.springframework.ldap.odm.typeconversion.LdapTypeConverter"/>
|
||||
|
||||
<bean id="referencedEntryEditorFactory" singleton="true"
|
||||
<bean id="referencedEntryEditorFactory" scope="singleton"
|
||||
class="org.springframework.ldap.odm.typeconversion.ReferencedEntryEditorFactory">
|
||||
<constructor-arg value="${base}" />
|
||||
<constructor-arg ref="ldapTemplate"/>
|
||||
</bean>
|
||||
|
||||
<bean id="ctxMapperFactory" singleton="true"
|
||||
<bean id="ctxMapperFactory" scope="singleton"
|
||||
class="org.springframework.ldap.odm.mapping.ObjectDirectoryMapperFactory">
|
||||
<constructor-arg ref="typeConverter"/>
|
||||
<constructor-arg ref="referencedEntryEditorFactory"/>
|
||||
</bean>
|
||||
|
||||
<bean id="ldapDao" singleton="true" class="org.springframework.ldap.odm.dao.LdapDaoImpl">
|
||||
<bean id="ldapDao" scope="singleton" class="org.springframework.ldap.odm.dao.LdapDaoImpl">
|
||||
<constructor-arg ref="ldapTemplate"/>
|
||||
<constructor-arg ref="ctxMapperFactory"/>
|
||||
</bean>
|
||||
|
||||
@@ -68,6 +68,7 @@ public class ObjectDirectoryMapperImpl implements ObjectDirectoryMapper
|
||||
Object beanPropertyValue = typeConverter.convertIfNecessary(
|
||||
new AttributeWrapper(attribute).getAllAsObject(), attributeType);
|
||||
propertySetters.get(beanPropertyName).invoke(instance, beanPropertyValue);
|
||||
|
||||
}
|
||||
catch (TypeMismatchException e)
|
||||
{
|
||||
|
||||
@@ -9,11 +9,13 @@ import org.springframework.ldap.core.LdapTemplate;
|
||||
import org.springframework.ldap.core.DistinguishedName;
|
||||
import org.springframework.ldap.odm.mapping.MappingException;
|
||||
import org.springframework.ldap.odm.mapping.ObjectDirectoryMapper;
|
||||
import org.springframework.ldap.NameNotFoundException;
|
||||
|
||||
import java.beans.PropertyEditorSupport;
|
||||
|
||||
/** ReferencedEntryEditor is responsible for converting references in an object
|
||||
* directory map from distinguished name strings to the target type and vice versa.
|
||||
/**
|
||||
* ReferencedEntryEditor is responsible for converting references in an object
|
||||
* directory map from distinguished name strings to the target type and vice versa.
|
||||
*/
|
||||
public class ReferencedEntryEditor extends PropertyEditorSupport
|
||||
{
|
||||
@@ -30,7 +32,9 @@ public class ReferencedEntryEditor extends PropertyEditorSupport
|
||||
this.objectDirectoryMapper = objectDirectoryMapper;
|
||||
}
|
||||
|
||||
/** Builds a distinguished name from the instance value */
|
||||
/**
|
||||
* Builds a distinguished name from the instance value
|
||||
*/
|
||||
public String getAsText()
|
||||
{
|
||||
try
|
||||
@@ -45,9 +49,11 @@ public class ReferencedEntryEditor extends PropertyEditorSupport
|
||||
}
|
||||
}
|
||||
|
||||
/** Sets the value of the editor by performing a lookup and mapping the result
|
||||
/**
|
||||
* Sets the value of the editor by performing a lookup and mapping the result
|
||||
* to the target type using an object directory mapper.
|
||||
* @param text The distinguished name of an ldap entry.
|
||||
*
|
||||
* @param text The distinguished name of an ldap entry.
|
||||
* @throws IllegalArgumentException
|
||||
*/
|
||||
public void setAsText(String text) throws IllegalArgumentException
|
||||
@@ -60,6 +66,15 @@ public class ReferencedEntryEditor extends PropertyEditorSupport
|
||||
dn.removeFirst();
|
||||
}
|
||||
}
|
||||
setValue(ldapTemplate.lookup(dn, objectDirectoryMapper));
|
||||
try
|
||||
{
|
||||
setValue(ldapTemplate.lookup(dn, objectDirectoryMapper));
|
||||
}
|
||||
catch (NameNotFoundException e)
|
||||
{
|
||||
setValue(null);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user