throw new UnauthorizedException("Authorization required");
}
String displayName = profileForm.getDisplayName();
TeeShirtSize teeShirtSize = profileForm.getTeeShirtSize();
Profile profile = ofy().load().key(Key.create(Profile.class, getUserId(user))).now();
if (profile == null) {
// Populate displayName and teeShirtSize with the default values if null.
if (displayName == null) {
displayName = extractDefaultDisplayNameFromEmail(user.getEmail());
}
if (teeShirtSize == null) {
teeShirtSize = TeeShirtSize.NOT_SPECIFIED;
}
profile = new Profile(getUserId(user), displayName, user.getEmail(), teeShirtSize);
} else {
profile.update(displayName, teeShirtSize);
}
ofy().save().entity(profile).now();
return profile;
}