Merge changes from topic "return-optional-from-currentuser"

* changes:
  IdentifiedUser#getLoggableName: Use preferred email if available
  Never return null from ReceiveCommits#displayName
  com.google.gerrit.server.account.AuthRequest#getUserName: Return Optional
  com.google.gerrit.server.auth.AuthRequest: Let methods return Optional
  Use identifiedUser.getUserName() instead of identifiedUser.state().getUserName()
  CurrentUser#getUserName: Return Optional<String> instead of nullable String
This commit is contained in:
Edwin Kempin
2018-01-26 14:58:46 +00:00
committed by Gerrit Code Review
34 changed files with 120 additions and 126 deletions

View File

@@ -108,7 +108,7 @@ public class AddSshKey implements RestModifyView<AccountResource, SshKeyInput> {
"Cannot send SSH key added message to " + user.getAccount().getPreferredEmail(), e);
}
sshKeyCache.evict(user.getUserName());
user.getUserName().ifPresent(sshKeyCache::evict);
return Response.<SshKeyInfo>created(GetSshKeys.newSshKeyInfo(sshKey));
} catch (InvalidSshKeyException e) {
throw new BadRequestException(e.getMessage());

View File

@@ -62,7 +62,7 @@ public class DeleteSshKey implements RestModifyView<AccountResource.SshKey, Inpu
}
authorizedKeys.deleteKey(rsrc.getUser().getAccountId(), rsrc.getSshKey().getKey().get());
sshKeyCache.evict(rsrc.getUser().getUserName());
rsrc.getUser().getUserName().ifPresent(sshKeyCache::evict);
return Response.none();
}

View File

@@ -61,7 +61,7 @@ class GetOAuthToken implements RestReadView<AccountResource> {
throw new ResourceNotFoundException();
}
OAuthTokenInfo accessTokenInfo = new OAuthTokenInfo();
accessTokenInfo.username = rsrc.getUser().state().getUserName().orElse(null);
accessTokenInfo.username = rsrc.getUser().getUserName().orElse(null);
accessTokenInfo.resourceHost = getHostName(canonicalWebUrlProvider.get());
accessTokenInfo.accessToken = accessToken.getToken();
accessTokenInfo.providerId = accessToken.getProviderId();

View File

@@ -28,6 +28,6 @@ public class GetUsername implements RestReadView<AccountResource> {
@Override
public String apply(AccountResource rsrc) throws AuthException, ResourceNotFoundException {
return rsrc.getUser().state().getUserName().orElseThrow(ResourceNotFoundException::new);
return rsrc.getUser().getUserName().orElseThrow(ResourceNotFoundException::new);
}
}

View File

@@ -100,11 +100,9 @@ public class PutHttpPassword implements RestModifyView<AccountResource, HttpPass
public Response<String> apply(IdentifiedUser user, String newPassword)
throws ResourceNotFoundException, ResourceConflictException, OrmException, IOException,
ConfigInvalidException {
if (user.getUserName() == null) {
throw new ResourceConflictException("username must be set");
}
ExternalId extId = externalIds.get(ExternalId.Key.create(SCHEME_USERNAME, user.getUserName()));
String userName =
user.getUserName().orElseThrow(() -> new ResourceConflictException("username must be set"));
ExternalId extId = externalIds.get(ExternalId.Key.create(SCHEME_USERNAME, userName));
if (extId == null) {
throw new ResourceNotFoundException();
}