Skip to content

Commit

Permalink
Retrieve All ODM-Managed Attributes on Update
Browse files Browse the repository at this point in the history
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
  • Loading branch information
jzheaux committed Oct 10, 2024
1 parent 0c169ec commit 0b90840
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -1674,12 +1674,18 @@ public void update(Object entry) {

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}
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -123,4 +127,8 @@ public String getEntryUuid() {
return this.entryUuid;
}

public String getCreatorsName() {
return this.creatorsName;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -131,4 +135,8 @@ public String getEntryUuid() {
return this.entryUuid;
}

public String getCreatorsName() {
return this.creatorsName;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@ public void testUpdate() {
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"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,8 @@ public void testUpdate() {
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);
Expand Down

0 comments on commit 0b90840

Please sign in to comment.