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
This commit is contained in:
Josh Cummings
2024-10-10 12:11:00 -06:00
parent 849255ffa2
commit dfb7b4ceeb
5 changed files with 27 additions and 1 deletions

View File

@@ -1674,12 +1674,18 @@ public class LdapTemplate implements LdapOperations, InitializingBean {
Assert.notNull(id, String.format("Unable to determine id for entry %s", entry.toString()));
DirContextOperations context = lookupContext(id);
String[] attributes = this.odm.manageClass(entry.getClass());
DirContextAdapter context = lookup(id, attributes, cast());
context.setUpdateMode(true);
this.odm.mapToLdapDataEntry(entry, context);
modifyAttributes(context);
}
}
private <T> ContextMapper<T> cast() {
return (ctx) -> (T) ctx;
}
/**
* {@inheritDoc}
*/

View File

@@ -57,6 +57,10 @@ public class Person implements Persistable<Name> {
@Attribute(name = "entryUUID", readonly = true)
private String entryUuid;
// gh-446
@Attribute(name = "creatorsName")
private String creatorsName;
@Override
public Name getId() {
return getDn();
@@ -123,4 +127,8 @@ public class Person implements Persistable<Name> {
return this.entryUuid;
}
public String getCreatorsName() {
return this.creatorsName;
}
}

View File

@@ -63,6 +63,10 @@ public class PersonWithDnAnnotations {
@Attribute(name = "entryUUID", readonly = true)
private String entryUuid;
// gh-446
@Attribute(name = "creatorsName")
private String creatorsName;
public Name getDn() {
return this.dn;
}
@@ -131,4 +135,8 @@ public class PersonWithDnAnnotations {
return this.entryUuid;
}
public String getCreatorsName() {
return this.creatorsName;
}
}

View File

@@ -157,6 +157,8 @@ public class LdapTemplateOdmWithDnAnnotationsITests extends AbstractLdapTemplate
person.setDesc(Arrays.asList("New Description"));
String entryUuid = person.getEntryUuid();
assertThat(entryUuid).describedAs("The operational attribute 'entryUUID' was not set").isNotEmpty();
String creatorsName = person.getCreatorsName();
assertThat(creatorsName).describedAs("The operational attribute 'creatorsName' was not set").isNotEmpty();
this.tested.update(person);
person = this.tested.findByDn(LdapUtils.newLdapName("cn=Some Person3, ou=company1, ou=Sweden"),

View File

@@ -169,6 +169,8 @@ public class LdapTemplateOdmWithNoDnAnnotationsITests extends AbstractLdapTempla
person.setDesc(Arrays.asList("New Description"));
String entryUuid = person.getEntryUuid();
assertThat(entryUuid).describedAs("The operational attribute 'entryUUID' was not set").isNotEmpty();
String creatorsName = person.getCreatorsName();
assertThat(creatorsName).describedAs("The operational attribute 'creatorsName' was not set").isNotEmpty();
this.tested.update(person);
person = this.tested.findOne(LdapQueryBuilder.query().where("cn").is("Some Person3"), Person.class);