Search in sources :

Example 11 with ProjectWatchInfo

use of com.google.gerrit.extensions.client.ProjectWatchInfo in project gerrit by GerritCodeReview.

the class WatchedProjectsIT method setAndDeleteWatchedProjects.

@Test
public void setAndDeleteWatchedProjects() throws Exception {
    String projectName1 = createProject(NEW_PROJECT_NAME).get();
    String projectName2 = createProject(NEW_PROJECT_NAME + "2").get();
    List<ProjectWatchInfo> projectsToWatch = new ArrayList<>();
    ProjectWatchInfo pwi = new ProjectWatchInfo();
    pwi.project = projectName1;
    pwi.notifyAbandonedChanges = true;
    pwi.notifyNewChanges = true;
    pwi.notifyAllComments = true;
    projectsToWatch.add(pwi);
    pwi = new ProjectWatchInfo();
    pwi.project = projectName2;
    pwi.filter = "branch:master";
    pwi.notifySubmittedChanges = true;
    pwi.notifyNewPatchSets = true;
    projectsToWatch.add(pwi);
    // Persist watched projects
    gApi.accounts().self().setWatchedProjects(projectsToWatch);
    List<ProjectWatchInfo> d = Lists.newArrayList(pwi);
    gApi.accounts().self().deleteWatchedProjects(d);
    projectsToWatch.remove(pwi);
    List<ProjectWatchInfo> persistedWatchedProjects = gApi.accounts().self().getWatchedProjects();
    assertThat(persistedWatchedProjects).doesNotContain(pwi);
    assertThat(persistedWatchedProjects).containsAllIn(projectsToWatch);
}
Also used : ProjectWatchInfo(com.google.gerrit.extensions.client.ProjectWatchInfo) ArrayList(java.util.ArrayList) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 12 with ProjectWatchInfo

use of com.google.gerrit.extensions.client.ProjectWatchInfo in project gerrit by GerritCodeReview.

the class PostWatchedProjects method asMap.

private Map<ProjectWatchKey, Set<NotifyType>> asMap(List<ProjectWatchInfo> input) throws BadRequestException, UnprocessableEntityException, IOException, PermissionBackendException {
    Map<ProjectWatchKey, Set<NotifyType>> m = new HashMap<>();
    for (ProjectWatchInfo info : input) {
        if (info.project == null) {
            throw new BadRequestException("project name must be specified");
        }
        ProjectWatchKey key = ProjectWatchKey.create(projectsCollection.parse(info.project).getNameKey(), info.filter);
        if (m.containsKey(key)) {
            throw new BadRequestException("duplicate entry for project " + format(info.project, info.filter));
        }
        Set<NotifyType> notifyValues = EnumSet.noneOf(NotifyType.class);
        if (toBoolean(info.notifyAbandonedChanges)) {
            notifyValues.add(NotifyType.ABANDONED_CHANGES);
        }
        if (toBoolean(info.notifyAllComments)) {
            notifyValues.add(NotifyType.ALL_COMMENTS);
        }
        if (toBoolean(info.notifyNewChanges)) {
            notifyValues.add(NotifyType.NEW_CHANGES);
        }
        if (toBoolean(info.notifyNewPatchSets)) {
            notifyValues.add(NotifyType.NEW_PATCHSETS);
        }
        if (toBoolean(info.notifySubmittedChanges)) {
            notifyValues.add(NotifyType.SUBMITTED_CHANGES);
        }
        m.put(key, notifyValues);
    }
    return m;
}
Also used : NotifyType(com.google.gerrit.server.account.WatchConfig.NotifyType) Set(java.util.Set) EnumSet(java.util.EnumSet) ProjectWatchInfo(com.google.gerrit.extensions.client.ProjectWatchInfo) HashMap(java.util.HashMap) ProjectWatchKey(com.google.gerrit.server.account.WatchConfig.ProjectWatchKey) BadRequestException(com.google.gerrit.extensions.restapi.BadRequestException)

Example 13 with ProjectWatchInfo

use of com.google.gerrit.extensions.client.ProjectWatchInfo in project gerrit by GerritCodeReview.

the class AbstractQueryAccountsTest method watch.

protected void watch(AccountInfo account, Project.NameKey project, String filter) throws RestApiException {
    List<ProjectWatchInfo> projectsToWatch = new ArrayList<>();
    ProjectWatchInfo pwi = new ProjectWatchInfo();
    pwi.project = project.get();
    pwi.filter = filter;
    pwi.notifyAbandonedChanges = true;
    pwi.notifyNewChanges = true;
    pwi.notifyAllComments = true;
    projectsToWatch.add(pwi);
    gApi.accounts().id(account._accountId).setWatchedProjects(projectsToWatch);
}
Also used : ProjectWatchInfo(com.google.gerrit.extensions.client.ProjectWatchInfo) ArrayList(java.util.ArrayList)

Aggregations

ProjectWatchInfo (com.google.gerrit.extensions.client.ProjectWatchInfo)13 ArrayList (java.util.ArrayList)12 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)9 Test (org.junit.Test)9 ProjectWatchKey (com.google.gerrit.server.account.WatchConfig.ProjectWatchKey)2 Set (java.util.Set)2 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)1 TestAccount (com.google.gerrit.acceptance.TestAccount)1 BadRequestException (com.google.gerrit.extensions.restapi.BadRequestException)1 Account (com.google.gerrit.reviewdb.client.Account)1 NotifyType (com.google.gerrit.server.account.WatchConfig.NotifyType)1 Message (com.google.gerrit.testutil.FakeEmailSender.Message)1 EnumSet (java.util.EnumSet)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1