Search in sources :

Example 1 with ProjectWatchInfo

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

the class GetWatchedProjects method apply.

@Override
public List<ProjectWatchInfo> apply(AccountResource rsrc) throws OrmException, AuthException, IOException, ConfigInvalidException, PermissionBackendException {
    if (self.get() != rsrc.getUser()) {
        permissionBackend.user(self).check(GlobalPermission.ADMINISTRATE_SERVER);
    }
    Account.Id accountId = rsrc.getUser().getAccountId();
    List<ProjectWatchInfo> projectWatchInfos = new ArrayList<>();
    for (Map.Entry<ProjectWatchKey, Set<NotifyType>> e : watchConfig.getProjectWatches(accountId).entrySet()) {
        ProjectWatchInfo pwi = new ProjectWatchInfo();
        pwi.filter = e.getKey().filter();
        pwi.project = e.getKey().project().get();
        pwi.notifyAbandonedChanges = toBoolean(e.getValue().contains(NotifyType.ABANDONED_CHANGES));
        pwi.notifyNewChanges = toBoolean(e.getValue().contains(NotifyType.NEW_CHANGES));
        pwi.notifyNewPatchSets = toBoolean(e.getValue().contains(NotifyType.NEW_PATCHSETS));
        pwi.notifySubmittedChanges = toBoolean(e.getValue().contains(NotifyType.SUBMITTED_CHANGES));
        pwi.notifyAllComments = toBoolean(e.getValue().contains(NotifyType.ALL_COMMENTS));
        projectWatchInfos.add(pwi);
    }
    Collections.sort(projectWatchInfos, new Comparator<ProjectWatchInfo>() {

        @Override
        public int compare(ProjectWatchInfo pwi1, ProjectWatchInfo pwi2) {
            return ComparisonChain.start().compare(pwi1.project, pwi2.project).compare(Strings.nullToEmpty(pwi1.filter), Strings.nullToEmpty(pwi2.filter)).result();
        }
    });
    return projectWatchInfos;
}
Also used : Account(com.google.gerrit.reviewdb.client.Account) ProjectWatchInfo(com.google.gerrit.extensions.client.ProjectWatchInfo) Set(java.util.Set) ProjectWatchKey(com.google.gerrit.server.account.WatchConfig.ProjectWatchKey) ArrayList(java.util.ArrayList) Map(java.util.Map)

Example 2 with ProjectWatchInfo

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

the class WatchedProjectsIT method setAndDeleteWatchedProjectsWithDifferentFilter.

@Test
public void setAndDeleteWatchedProjectsWithDifferentFilter() throws Exception {
    String projectName = project.get();
    List<ProjectWatchInfo> projectsToWatch = new ArrayList<>();
    ProjectWatchInfo pwi = new ProjectWatchInfo();
    pwi.project = projectName;
    pwi.filter = "branch:stable";
    pwi.notifyAbandonedChanges = true;
    pwi.notifyNewChanges = true;
    pwi.notifyAllComments = true;
    projectsToWatch.add(pwi);
    pwi = new ProjectWatchInfo();
    pwi.project = projectName;
    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 3 with ProjectWatchInfo

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

the class WatchedProjectsIT method modifyProjectWatchUsingOmittedValues.

@Test
public void modifyProjectWatchUsingOmittedValues() throws Exception {
    String projectName = project.get();
    // Let another user watch a project
    setApiUser(admin);
    List<ProjectWatchInfo> projectsToWatch = new ArrayList<>();
    ProjectWatchInfo pwi = new ProjectWatchInfo();
    pwi.project = projectName;
    pwi.notifyAbandonedChanges = true;
    pwi.notifyNewChanges = true;
    pwi.notifyAllComments = true;
    projectsToWatch.add(pwi);
    // Persist a defined state
    gApi.accounts().self().setWatchedProjects(projectsToWatch);
    // Omit previously set value - will set it to false on the server
    // The response will not carry this field then as we omit sending
    // false values in JSON
    pwi.notifyNewChanges = null;
    // Perform update
    gApi.accounts().self().setWatchedProjects(projectsToWatch);
    List<ProjectWatchInfo> watchedProjects = gApi.accounts().self().getWatchedProjects();
    assertThat(watchedProjects).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 4 with ProjectWatchInfo

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

the class WatchedProjectsIT method setConflictingWatches.

@Test
public void setConflictingWatches() throws Exception {
    String projectName = createProject(NEW_PROJECT_NAME).get();
    List<ProjectWatchInfo> projectsToWatch = new ArrayList<>();
    ProjectWatchInfo pwi = new ProjectWatchInfo();
    pwi.project = projectName;
    pwi.notifyAbandonedChanges = true;
    pwi.notifyNewChanges = true;
    pwi.notifyAllComments = true;
    projectsToWatch.add(pwi);
    pwi = new ProjectWatchInfo();
    pwi.project = projectName;
    pwi.notifySubmittedChanges = true;
    pwi.notifyNewPatchSets = true;
    projectsToWatch.add(pwi);
    exception.expect(BadRequestException.class);
    exception.expectMessage("duplicate entry for project " + projectName);
    gApi.accounts().self().setWatchedProjects(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 5 with ProjectWatchInfo

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

the class WatchedProjectsIT method setAndGetEmptyWatch.

@Test
public void setAndGetEmptyWatch() throws Exception {
    String projectName = createProject(NEW_PROJECT_NAME).get();
    List<ProjectWatchInfo> projectsToWatch = new ArrayList<>();
    ProjectWatchInfo pwi = new ProjectWatchInfo();
    pwi.project = projectName;
    projectsToWatch.add(pwi);
    gApi.accounts().self().setWatchedProjects(projectsToWatch);
    List<ProjectWatchInfo> persistedWatchedProjects = gApi.accounts().self().getWatchedProjects();
    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)

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