use of com.google.gerrit.server.account.AccountLoader in project gerrit by GerritCodeReview.
the class ListMembers method toAccountInfos.
private List<AccountInfo> toAccountInfos(Set<Account.Id> members) throws PermissionBackendException {
AccountLoader accountLoader = accountLoaderFactory.create(true);
List<AccountInfo> memberInfos = new ArrayList<>(members.size());
for (Account.Id member : members) {
memberInfos.add(accountLoader.get(member));
}
accountLoader.fill();
memberInfos.sort(AccountInfoComparator.ORDER_NULLS_FIRST);
return memberInfos;
}
use of com.google.gerrit.server.account.AccountLoader in project gerrit by GerritCodeReview.
the class CreateAccount method apply.
public Response<AccountInfo> apply(IdString id, AccountInput input) throws BadRequestException, ResourceConflictException, UnprocessableEntityException, IOException, ConfigInvalidException, PermissionBackendException {
String username = applyCaseOfUsername(id.get());
if (input.username != null && !username.equals(applyCaseOfUsername(input.username))) {
throw new BadRequestException("username must match URL");
}
if (!ExternalId.isValidUsername(username)) {
throw new BadRequestException("Invalid username '" + username + "'");
}
if (input.name == null) {
input.name = input.username;
}
Set<AccountGroup.UUID> groups = parseGroups(input.groups);
Account.Id accountId = Account.id(seq.nextAccountId());
List<ExternalId> extIds = new ArrayList<>();
if (input.email != null) {
if (!validator.isValid(input.email)) {
throw new BadRequestException("invalid email address");
}
extIds.add(externalIdFactory.createEmail(accountId, input.email));
}
extIds.add(externalIdFactory.createUsername(username, accountId, input.httpPassword));
externalIdCreators.runEach(c -> extIds.addAll(c.create(accountId, username, input.email)));
try {
accountsUpdateProvider.get().insert("Create Account via API", accountId, u -> u.setFullName(input.name).setPreferredEmail(input.email).addExternalIds(extIds));
} catch (DuplicateExternalIdKeyException e) {
if (e.getDuplicateKey().isScheme(SCHEME_USERNAME)) {
throw new ResourceConflictException("username '" + e.getDuplicateKey().id() + "' already exists");
} else if (e.getDuplicateKey().isScheme(SCHEME_MAILTO)) {
throw new UnprocessableEntityException("email '" + e.getDuplicateKey().id() + "' already exists");
} else {
// AccountExternalIdCreator returned an external ID that already exists
throw e;
}
}
for (AccountGroup.UUID groupUuid : groups) {
try {
addGroupMember(groupUuid, accountId);
} catch (NoSuchGroupException e) {
throw new UnprocessableEntityException(String.format("Group %s not found", groupUuid), e);
}
}
if (input.sshKey != null) {
try {
authorizedKeys.addKey(accountId, input.sshKey);
sshKeyCache.evict(username);
} catch (InvalidSshKeyException e) {
throw new BadRequestException(e.getMessage());
}
}
AccountLoader loader = infoLoader.create(true);
AccountInfo info = loader.get(accountId);
loader.fill();
return Response.created(info);
}
use of com.google.gerrit.server.account.AccountLoader in project gerrit by GerritCodeReview.
the class GetPastAssignees method apply.
@Override
public Response<List<AccountInfo>> apply(ChangeResource rsrc) throws PermissionBackendException {
Set<Account.Id> pastAssignees = rsrc.getNotes().load().getPastAssignees();
if (pastAssignees == null) {
return Response.ok(Collections.emptyList());
}
AccountLoader accountLoader = accountLoaderFactory.create(true);
List<AccountInfo> infos = pastAssignees.stream().map(accountLoader::get).collect(toList());
accountLoader.fill();
return Response.ok(infos);
}
use of com.google.gerrit.server.account.AccountLoader in project gerrit by GerritCodeReview.
the class ListChangeMessages method apply.
@Override
public Response<List<ChangeMessageInfo>> apply(ChangeResource resource) throws PermissionBackendException {
AccountLoader accountLoader = accountLoaderFactory.create(true);
List<ChangeMessage> messages = changeMessagesUtil.byChange(resource.getNotes());
List<ChangeMessageInfo> messageInfos = messages.stream().map(m -> changeMessagesUtil.createChangeMessageInfoWithReplacedTemplates(m, accountLoader)).collect(Collectors.toList());
accountLoader.fill();
return Response.ok(messageInfos);
}
Aggregations