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;
}
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);
}
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);
}
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);
}
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);
}
Aggregations