Hi,
I’m experimenting with this Experimental API. I’ve found a couple of problems due to the fact that personService.create()
returns a UserKey
:
- This
UserKey
class (packagecom.atlassian.confluence.api.model.people
) is different from the user key used for searching, so you can not use it like this:personService.find().withUserKey(userKey)
- Why doesn’t it return a Person? That way, it would be natural to do something like
getPerson(userName).orElseGet(() -> createNewPerson(userName));
The current code to use this class is, in my opinion, far from optimal. Here is an example:
public void createPerson(String userName) {
getPerson(userName).orElseGet(() -> createNewPerson(userName));
}
private Person createNewPerson(String userName) {
UserDetailsForCreation userDetailsForCreation = new UserDetailsForCreation();
userDetailsForCreation.setUserName(userName);
UserKey createdUserKey = personService.create(userDetailsForCreation);
com.atlassian.sal.api.user.UserKey userKey = new com.atlassian.sal.api.user.UserKey(createdUserKey.getUserKey());
return personService.find()
.withUserKey(userKey)
.fetch()
.orElseThrow(() -> new IllegalStateException("Could not find created user"));
}