Search in sources :

Example 11 with Address

use of com.google.gerrit.server.mail.Address in project gerrit by GerritCodeReview.

the class ListRevisionReviewers method apply.

@Override
public List<ReviewerInfo> apply(RevisionResource rsrc) throws OrmException, MethodNotAllowedException, PermissionBackendException {
    if (!rsrc.isCurrent()) {
        throw new MethodNotAllowedException("Cannot list reviewers on non-current patch set");
    }
    Map<String, ReviewerResource> reviewers = new LinkedHashMap<>();
    ReviewDb db = dbProvider.get();
    for (Account.Id accountId : approvalsUtil.getReviewers(db, rsrc.getNotes()).all()) {
        if (!reviewers.containsKey(accountId.toString())) {
            reviewers.put(accountId.toString(), resourceFactory.create(rsrc, accountId));
        }
    }
    for (Address address : rsrc.getNotes().getReviewersByEmail().all()) {
        if (!reviewers.containsKey(address.toString())) {
            reviewers.put(address.toString(), new ReviewerResource(rsrc, address));
        }
    }
    return json.format(reviewers.values());
}
Also used : Account(com.google.gerrit.reviewdb.client.Account) MethodNotAllowedException(com.google.gerrit.extensions.restapi.MethodNotAllowedException) Address(com.google.gerrit.server.mail.Address) ReviewDb(com.google.gerrit.reviewdb.server.ReviewDb) LinkedHashMap(java.util.LinkedHashMap)

Example 12 with Address

use of com.google.gerrit.server.mail.Address in project gerrit by GerritCodeReview.

the class ProjectWatchIT method noNotificationForDraftChangesForWatchersInNotifyConfig.

@Test
public void noNotificationForDraftChangesForWatchersInNotifyConfig() throws Exception {
    Address addr = new Address("Watcher", "watcher@example.com");
    NotifyConfig nc = new NotifyConfig();
    nc.addEmail(addr);
    nc.setName("team");
    nc.setHeader(NotifyConfig.Header.TO);
    nc.setTypes(EnumSet.of(NotifyType.NEW_CHANGES, NotifyType.ALL_COMMENTS));
    ProjectConfig cfg = projectCache.checkedGet(project).getConfig();
    cfg.putNotifyConfig("team", nc);
    saveProjectConfig(project, cfg);
    PushOneCommit.Result r = pushFactory.create(db, admin.getIdent(), testRepo, "draft change", "a", "a1").to("refs/for/master%draft");
    r.assertOkStatus();
    assertThat(sender.getMessages()).isEmpty();
    setApiUser(admin);
    ReviewInput in = new ReviewInput();
    in.message = "comment";
    gApi.changes().id(r.getChangeId()).current().review(in);
    assertThat(sender.getMessages()).isEmpty();
}
Also used : ProjectConfig(com.google.gerrit.server.git.ProjectConfig) Address(com.google.gerrit.server.mail.Address) NotifyConfig(com.google.gerrit.server.git.NotifyConfig) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 13 with Address

use of com.google.gerrit.server.mail.Address in project gerrit by GerritCodeReview.

the class MetadataParserTest method parseMetadataFromText.

@Test
public void parseMetadataFromText() {
    // This tests if the metadata parser is able to parse metadata from the
    // the text body of the message.
    MailMessage.Builder b = MailMessage.builder();
    b.id("");
    b.dateReceived(new DateTime());
    b.subject("");
    StringBuilder stringBuilder = new StringBuilder();
    stringBuilder.append(toFooterWithDelimiter(MetadataName.CHANGE_ID) + "cid\r\n");
    stringBuilder.append("> " + toFooterWithDelimiter(MetadataName.PATCH_SET) + "1\n");
    stringBuilder.append(toFooterWithDelimiter(MetadataName.MESSAGE_TYPE) + "comment\n");
    stringBuilder.append(toFooterWithDelimiter(MetadataName.TIMESTAMP) + "Tue, 25 Oct 2016 02:11:35 -0700\r\n");
    b.textContent(stringBuilder.toString());
    Address author = new Address("Diffy", "test@gerritcodereview.com");
    b.from(author);
    MailMetadata meta = MetadataParser.parse(b.build());
    assertThat(meta.author).isEqualTo(author.getEmail());
    assertThat(meta.changeId).isEqualTo("cid");
    assertThat(meta.patchSet).isEqualTo(1);
    assertThat(meta.messageType).isEqualTo("comment");
    assertThat(meta.timestamp.getTime()).isEqualTo(new DateTime(2016, 10, 25, 9, 11, 35, 0, DateTimeZone.UTC).getMillis());
}
Also used : Address(com.google.gerrit.server.mail.Address) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 14 with Address

use of com.google.gerrit.server.mail.Address in project gerrit by GerritCodeReview.

the class MetadataParserTest method parseMetadataFromHTML.

@Test
public void parseMetadataFromHTML() {
    // This tests if the metadata parser is able to parse metadata from the
    // the HTML body of the message.
    MailMessage.Builder b = MailMessage.builder();
    b.id("");
    b.dateReceived(new DateTime());
    b.subject("");
    StringBuilder stringBuilder = new StringBuilder();
    stringBuilder.append("<div id\"someid\">" + toFooterWithDelimiter(MetadataName.CHANGE_ID) + "cid</div>");
    stringBuilder.append("<div>" + toFooterWithDelimiter(MetadataName.PATCH_SET) + "1</div>");
    stringBuilder.append("<div>" + toFooterWithDelimiter(MetadataName.MESSAGE_TYPE) + "comment</div>");
    stringBuilder.append("<div>" + toFooterWithDelimiter(MetadataName.TIMESTAMP) + "Tue, 25 Oct 2016 02:11:35 -0700" + "</div>");
    b.htmlContent(stringBuilder.toString());
    Address author = new Address("Diffy", "test@gerritcodereview.com");
    b.from(author);
    MailMetadata meta = MetadataParser.parse(b.build());
    assertThat(meta.author).isEqualTo(author.getEmail());
    assertThat(meta.changeId).isEqualTo("cid");
    assertThat(meta.patchSet).isEqualTo(1);
    assertThat(meta.messageType).isEqualTo("comment");
    assertThat(meta.timestamp.getTime()).isEqualTo(new DateTime(2016, 10, 25, 9, 11, 35, 0, DateTimeZone.UTC).getMillis());
}
Also used : Address(com.google.gerrit.server.mail.Address) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 15 with Address

use of com.google.gerrit.server.mail.Address in project gerrit by GerritCodeReview.

the class HtmlMimeMessage method expectedMailMessage.

@Override
public MailMessage expectedMailMessage() {
    MailMessage.Builder expect = MailMessage.builder();
    expect.id("<001a114cd8be55b4ab053face5cd@google.com>").from(new Address("ekempin (Gerrit)", "noreply-gerritcodereview-qUgXfQecoDLHwp0MldAzig@google.com")).addCc(new Address("ekempin", "ekempin@google.com")).addTo(new Address("Patrick Hiesel", "hiesel@google.com")).textContent(textContent).htmlContent(unencodedHtmlContent).subject("Change in gerrit[master]: Implement receiver class structure and bindings").addAdditionalHeader("MIME-Version: 1.0").dateReceived(new DateTime(2016, 10, 25, 9, 11, 35, 0, DateTimeZone.UTC));
    return expect.build();
}
Also used : MailMessage(com.google.gerrit.server.mail.receive.MailMessage) Address(com.google.gerrit.server.mail.Address) DateTime(org.joda.time.DateTime)

Aggregations

Address (com.google.gerrit.server.mail.Address)23 DateTime (org.joda.time.DateTime)11 MailMessage (com.google.gerrit.server.mail.receive.MailMessage)6 Account (com.google.gerrit.reviewdb.client.Account)5 Test (org.junit.Test)5 ReviewDb (com.google.gerrit.reviewdb.server.ReviewDb)3 LinkedHashMap (java.util.LinkedHashMap)3 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)2 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)2 ReviewInput (com.google.gerrit.extensions.api.changes.ReviewInput)2 MethodNotAllowedException (com.google.gerrit.extensions.restapi.MethodNotAllowedException)2 ResourceNotFoundException (com.google.gerrit.extensions.restapi.ResourceNotFoundException)2 NotifyConfig (com.google.gerrit.server.git.NotifyConfig)2 ProjectConfig (com.google.gerrit.server.git.ProjectConfig)2 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 Strings (com.google.common.base.Strings)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 ImmutableTable (com.google.common.collect.ImmutableTable)1