use of com.google.gerrit.server.account.Emails in project gerrit by GerritCodeReview.
the class EmailIT method getEmails.
private Set<String> getEmails() throws Exception {
RestResponse r = adminRestSession.get("/accounts/self/emails");
r.assertOK();
List<EmailInfo> emails = newGson().fromJson(r.getReader(), new TypeToken<List<EmailInfo>>() {
}.getType());
return emails.stream().map(e -> e.email).collect(toSet());
}
use of com.google.gerrit.server.account.Emails in project gerrit by GerritCodeReview.
the class AccountIT method createAtomically.
@Test
@UseClockStep
public void createAtomically() throws Exception {
Account.Id accountId = Account.id(seq.nextAccountId());
String fullName = "Foo";
ExternalId extId = externalIdFactory.createEmail(accountId, "foo@example.com");
AccountState accountState = accountsUpdateProvider.get().insert("Create Account Atomically", accountId, u -> u.setFullName(fullName).addExternalId(extId));
assertThat(accountState.account().fullName()).isEqualTo(fullName);
AccountInfo info = gApi.accounts().id(accountId.get()).get();
assertThat(info.name).isEqualTo(fullName);
List<EmailInfo> emails = gApi.accounts().id(accountId.get()).getEmails();
assertThat(emails.stream().map(e -> e.email).collect(toSet())).containsExactly(extId.email());
RevCommit commitUserBranch = projectOperations.project(allUsers).getHead(RefNames.refsUsers(accountId));
RevCommit commitRefsMetaExternalIds = projectOperations.project(allUsers).getHead(RefNames.REFS_EXTERNAL_IDS);
assertThat(commitUserBranch.getCommitTime()).isEqualTo(commitRefsMetaExternalIds.getCommitTime());
}
use of com.google.gerrit.server.account.Emails in project gerrit by GerritCodeReview.
the class AbstractCommitUserIdentityPredicate method exec.
protected Operation exec(Prolog engine, PersonIdent userId) throws PrologException {
engine.setB0();
Term a1 = arg1.dereference();
Term a2 = arg2.dereference();
Term a3 = arg3.dereference();
Term idTerm;
Term nameTerm = Prolog.Nil;
Term emailTerm = Prolog.Nil;
PrologEnvironment env = (PrologEnvironment) engine.control;
Emails emails = env.getArgs().getEmails();
Account.Id id = null;
try {
ImmutableSet<Account.Id> ids = emails.getAccountForExternal(userId.getEmailAddress());
if (ids.size() == 1) {
id = ids.iterator().next();
}
} catch (IOException e) {
throw new SystemException(e.getMessage());
}
if (id == null) {
idTerm = anonymous;
} else {
idTerm = new IntegerTerm(id.get());
}
String name = userId.getName();
if (name != null && !name.equals("")) {
nameTerm = SymbolTerm.create(name);
}
String email = userId.getEmailAddress();
if (email != null && !email.equals("")) {
emailTerm = SymbolTerm.create(email);
}
if (!a1.unify(new StructureTerm(user, idTerm), engine.trail)) {
return engine.fail();
}
if (!a2.unify(nameTerm, engine.trail)) {
return engine.fail();
}
if (!a3.unify(emailTerm, engine.trail)) {
return engine.fail();
}
return cont;
}
Aggregations