Skip to content

Commit dfb7b4c

Browse files
committed
Retrieve All ODM-Managed Attributes on Update
In this way, if an Entry has an operational attribute, it will be present in both the updated and existing objects so that DirContextAdapter does not compute it as a new attribute. Closes gh-446
1 parent 849255f commit dfb7b4c

File tree

5 files changed

+27
-1
lines changed

5 files changed

+27
-1
lines changed

core/src/main/java/org/springframework/ldap/core/LdapTemplate.java

+7-1
Original file line numberDiff line numberDiff line change
@@ -1674,12 +1674,18 @@ public void update(Object entry) {
16741674

16751675
Assert.notNull(id, String.format("Unable to determine id for entry %s", entry.toString()));
16761676

1677-
DirContextOperations context = lookupContext(id);
1677+
String[] attributes = this.odm.manageClass(entry.getClass());
1678+
DirContextAdapter context = lookup(id, attributes, cast());
1679+
context.setUpdateMode(true);
16781680
this.odm.mapToLdapDataEntry(entry, context);
16791681
modifyAttributes(context);
16801682
}
16811683
}
16821684

1685+
private <T> ContextMapper<T> cast() {
1686+
return (ctx) -> (T) ctx;
1687+
}
1688+
16831689
/**
16841690
* {@inheritDoc}
16851691
*/

test/integration-tests/src/main/java/org/springframework/ldap/itest/odm/Person.java

+8
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ public class Person implements Persistable<Name> {
5757
@Attribute(name = "entryUUID", readonly = true)
5858
private String entryUuid;
5959

60+
// gh-446
61+
@Attribute(name = "creatorsName")
62+
private String creatorsName;
63+
6064
@Override
6165
public Name getId() {
6266
return getDn();
@@ -123,4 +127,8 @@ public String getEntryUuid() {
123127
return this.entryUuid;
124128
}
125129

130+
public String getCreatorsName() {
131+
return this.creatorsName;
132+
}
133+
126134
}

test/integration-tests/src/main/java/org/springframework/ldap/itest/odm/PersonWithDnAnnotations.java

+8
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ public class PersonWithDnAnnotations {
6363
@Attribute(name = "entryUUID", readonly = true)
6464
private String entryUuid;
6565

66+
// gh-446
67+
@Attribute(name = "creatorsName")
68+
private String creatorsName;
69+
6670
public Name getDn() {
6771
return this.dn;
6872
}
@@ -131,4 +135,8 @@ public String getEntryUuid() {
131135
return this.entryUuid;
132136
}
133137

138+
public String getCreatorsName() {
139+
return this.creatorsName;
140+
}
141+
134142
}

test/integration-tests/src/test/java/org/springframework/ldap/itest/odm/LdapTemplateOdmWithDnAnnotationsITests.java

+2
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,8 @@ public void testUpdate() {
157157
person.setDesc(Arrays.asList("New Description"));
158158
String entryUuid = person.getEntryUuid();
159159
assertThat(entryUuid).describedAs("The operational attribute 'entryUUID' was not set").isNotEmpty();
160+
String creatorsName = person.getCreatorsName();
161+
assertThat(creatorsName).describedAs("The operational attribute 'creatorsName' was not set").isNotEmpty();
160162
this.tested.update(person);
161163

162164
person = this.tested.findByDn(LdapUtils.newLdapName("cn=Some Person3, ou=company1, ou=Sweden"),

test/integration-tests/src/test/java/org/springframework/ldap/itest/odm/LdapTemplateOdmWithNoDnAnnotationsITests.java

+2
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,8 @@ public void testUpdate() {
169169
person.setDesc(Arrays.asList("New Description"));
170170
String entryUuid = person.getEntryUuid();
171171
assertThat(entryUuid).describedAs("The operational attribute 'entryUUID' was not set").isNotEmpty();
172+
String creatorsName = person.getCreatorsName();
173+
assertThat(creatorsName).describedAs("The operational attribute 'creatorsName' was not set").isNotEmpty();
172174
this.tested.update(person);
173175

174176
person = this.tested.findOne(LdapQueryBuilder.query().where("cn").is("Some Person3"), Person.class);

0 commit comments

Comments
 (0)