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:
@@ -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}
|
||||
*/
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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"),
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user