Merge changes I56e2e597,I6a91e6bf,I5e654b38,I22ea50c7
* changes: Delete ChangeListService.forAccount Delete ChangeListService.allQueryNext Delete ChangeListService.myStarredChangeIds Delete ProjectAdminService visibleProjects, suggestParentCandidates
This commit is contained in:
@@ -15,33 +15,14 @@
|
||||
package com.google.gerrit.common.data;
|
||||
|
||||
import com.google.gerrit.common.auth.SignInRequired;
|
||||
import com.google.gerrit.reviewdb.client.Account;
|
||||
import com.google.gerrit.reviewdb.client.Change;
|
||||
import com.google.gwtjsonrpc.common.AsyncCallback;
|
||||
import com.google.gwtjsonrpc.common.RemoteJsonService;
|
||||
import com.google.gwtjsonrpc.common.RpcImpl;
|
||||
import com.google.gwtjsonrpc.common.VoidResult;
|
||||
import com.google.gwtjsonrpc.common.RpcImpl.Version;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
@RpcImpl(version = Version.V2_0)
|
||||
public interface ChangeListService extends RemoteJsonService {
|
||||
/** Get all changes which match an arbitrary query string. */
|
||||
void allQueryPrev(String query, String pos, int limit,
|
||||
AsyncCallback<SingleListChangeInfo> callback);
|
||||
|
||||
/** Get all changes which match an arbitrary query string. */
|
||||
void allQueryNext(String query, String pos, int limit,
|
||||
AsyncCallback<SingleListChangeInfo> callback);
|
||||
|
||||
/** Get the data to show AccountDashboardScreen for an account. */
|
||||
void forAccount(Account.Id id, AsyncCallback<AccountDashboardInfo> callback);
|
||||
|
||||
/** Get the ids of all changes starred by the caller. */
|
||||
@SignInRequired
|
||||
void myStarredChangeIds(AsyncCallback<Set<Change.Id>> callback);
|
||||
|
||||
/**
|
||||
* Add and/or remove changes from the set of starred changes of the caller.
|
||||
*
|
||||
|
||||
@@ -28,10 +28,7 @@ import java.util.Set;
|
||||
|
||||
@RpcImpl(version = Version.V2_0)
|
||||
public interface ProjectAdminService extends RemoteJsonService {
|
||||
void visibleProjects(AsyncCallback<ProjectList> callback);
|
||||
|
||||
void visibleProjectDetails(AsyncCallback<List<ProjectDetail>> callback);
|
||||
void suggestParentCandidates(AsyncCallback<List<Project>> callback);
|
||||
|
||||
void projectDetail(Project.NameKey projectName,
|
||||
AsyncCallback<ProjectDetail> callback);
|
||||
|
||||
@@ -1,43 +0,0 @@
|
||||
// Copyright (C) 2011 The Android Open Source Project
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License
|
||||
|
||||
package com.google.gerrit.common.data;
|
||||
|
||||
import com.google.gerrit.reviewdb.client.Project;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class ProjectList {
|
||||
protected List<Project> projects;
|
||||
protected boolean canCreateProject;
|
||||
|
||||
public ProjectList() {
|
||||
}
|
||||
|
||||
public List<Project> getProjects() {
|
||||
return projects;
|
||||
}
|
||||
|
||||
public void setProjects(List<Project> projects) {
|
||||
this.projects = projects;
|
||||
}
|
||||
|
||||
public boolean canCreateProject() {
|
||||
return canCreateProject;
|
||||
}
|
||||
|
||||
public void setCanCreateProject(boolean canCreateProject) {
|
||||
this.canCreateProject = canCreateProject;
|
||||
}
|
||||
}
|
||||
@@ -14,258 +14,32 @@
|
||||
|
||||
package com.google.gerrit.httpd.rpc;
|
||||
|
||||
import com.google.gerrit.common.data.AccountDashboardInfo;
|
||||
import com.google.gerrit.common.data.ChangeInfo;
|
||||
import com.google.gerrit.common.data.ChangeListService;
|
||||
import com.google.gerrit.common.data.GlobalCapability;
|
||||
import com.google.gerrit.common.data.SingleListChangeInfo;
|
||||
import com.google.gerrit.common.data.ToggleStarRequest;
|
||||
import com.google.gerrit.common.errors.InvalidQueryException;
|
||||
import com.google.gerrit.common.errors.NoSuchEntityException;
|
||||
import com.google.gerrit.reviewdb.client.Account;
|
||||
import com.google.gerrit.reviewdb.client.Change;
|
||||
import com.google.gerrit.reviewdb.client.PatchSetApproval;
|
||||
import com.google.gerrit.reviewdb.client.StarredChange;
|
||||
import com.google.gerrit.reviewdb.server.ChangeAccess;
|
||||
import com.google.gerrit.reviewdb.server.ReviewDb;
|
||||
import com.google.gerrit.server.CurrentUser;
|
||||
import com.google.gerrit.server.account.AccountInfoCacheFactory;
|
||||
import com.google.gerrit.server.project.ChangeControl;
|
||||
import com.google.gerrit.server.project.NoSuchChangeException;
|
||||
import com.google.gerrit.server.query.Predicate;
|
||||
import com.google.gerrit.server.query.QueryParseException;
|
||||
import com.google.gerrit.server.query.change.ChangeData;
|
||||
import com.google.gerrit.server.query.change.ChangeDataSource;
|
||||
import com.google.gerrit.server.query.change.ChangeQueryBuilder;
|
||||
import com.google.gerrit.server.query.change.ChangeQueryRewriter;
|
||||
import com.google.gwtjsonrpc.common.AsyncCallback;
|
||||
import com.google.gwtjsonrpc.common.VoidResult;
|
||||
import com.google.gwtorm.server.ListResultSet;
|
||||
import com.google.gwtorm.server.OrmException;
|
||||
import com.google.gwtorm.server.ResultSet;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Provider;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class ChangeListServiceImpl extends BaseServiceImplementation implements
|
||||
ChangeListService {
|
||||
private static final Comparator<ChangeInfo> ID_COMP =
|
||||
new Comparator<ChangeInfo>() {
|
||||
public int compare(final ChangeInfo o1, final ChangeInfo o2) {
|
||||
return o1.getId().get() - o2.getId().get();
|
||||
}
|
||||
};
|
||||
private static final Comparator<ChangeInfo> SORT_KEY_COMP =
|
||||
new Comparator<ChangeInfo>() {
|
||||
public int compare(final ChangeInfo o1, final ChangeInfo o2) {
|
||||
return o2.getSortKey().compareTo(o1.getSortKey());
|
||||
}
|
||||
};
|
||||
private static final Comparator<Change> QUERY_PREV =
|
||||
new Comparator<Change>() {
|
||||
public int compare(final Change a, final Change b) {
|
||||
return a.getSortKey().compareTo(b.getSortKey());
|
||||
}
|
||||
};
|
||||
private static final Comparator<Change> QUERY_NEXT =
|
||||
new Comparator<Change>() {
|
||||
public int compare(final Change a, final Change b) {
|
||||
return b.getSortKey().compareTo(a.getSortKey());
|
||||
}
|
||||
};
|
||||
|
||||
private final Provider<CurrentUser> currentUser;
|
||||
private final ChangeControl.Factory changeControlFactory;
|
||||
private final AccountInfoCacheFactory.Factory accountInfoCacheFactory;
|
||||
|
||||
private final ChangeQueryBuilder.Factory queryBuilder;
|
||||
private final Provider<ChangeQueryRewriter> queryRewriter;
|
||||
|
||||
@Inject
|
||||
ChangeListServiceImpl(final Provider<ReviewDb> schema,
|
||||
final Provider<CurrentUser> currentUser,
|
||||
final ChangeControl.Factory changeControlFactory,
|
||||
final AccountInfoCacheFactory.Factory accountInfoCacheFactory,
|
||||
final ChangeQueryBuilder.Factory queryBuilder,
|
||||
final Provider<ChangeQueryRewriter> queryRewriter) {
|
||||
final Provider<CurrentUser> currentUser) {
|
||||
super(schema, currentUser);
|
||||
this.currentUser = currentUser;
|
||||
this.changeControlFactory = changeControlFactory;
|
||||
this.accountInfoCacheFactory = accountInfoCacheFactory;
|
||||
this.queryBuilder = queryBuilder;
|
||||
this.queryRewriter = queryRewriter;
|
||||
}
|
||||
|
||||
private boolean canRead(final Change c, final ReviewDb db) throws OrmException {
|
||||
try {
|
||||
return changeControlFactory.controlFor(c).isVisible(db);
|
||||
} catch (NoSuchChangeException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void allQueryPrev(final String query, final String pos,
|
||||
final int pageSize, final AsyncCallback<SingleListChangeInfo> callback) {
|
||||
try {
|
||||
run(callback, new QueryPrev(pageSize, pos) {
|
||||
@Override
|
||||
ResultSet<Change> query(ReviewDb db, int lim, String key)
|
||||
throws OrmException, InvalidQueryException {
|
||||
return searchQuery(db, query, lim, key, QUERY_PREV);
|
||||
}
|
||||
});
|
||||
} catch (InvalidQueryException e) {
|
||||
callback.onFailure(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void allQueryNext(final String query, final String pos,
|
||||
final int pageSize, final AsyncCallback<SingleListChangeInfo> callback) {
|
||||
try {
|
||||
run(callback, new QueryNext(pageSize, pos) {
|
||||
@Override
|
||||
ResultSet<Change> query(ReviewDb db, int lim, String key)
|
||||
throws OrmException, InvalidQueryException {
|
||||
return searchQuery(db, query, lim, key, QUERY_NEXT);
|
||||
}
|
||||
});
|
||||
} catch (InvalidQueryException e) {
|
||||
callback.onFailure(e);
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private ResultSet<Change> searchQuery(final ReviewDb db, String query,
|
||||
final int limit, final String key, final Comparator<Change> cmp)
|
||||
throws OrmException, InvalidQueryException {
|
||||
try {
|
||||
final ChangeQueryBuilder builder = queryBuilder.create(currentUser.get());
|
||||
final Predicate<ChangeData> visibleToMe = builder.is_visible();
|
||||
Predicate<ChangeData> q = builder.parse(query);
|
||||
q = Predicate.and(q, //
|
||||
cmp == QUERY_PREV //
|
||||
? builder.sortkey_after(key) //
|
||||
: builder.sortkey_before(key), //
|
||||
builder.limit(limit), //
|
||||
visibleToMe //
|
||||
);
|
||||
|
||||
ChangeQueryRewriter rewriter = queryRewriter.get();
|
||||
Predicate<ChangeData> s = rewriter.rewrite(q);
|
||||
if (!(s instanceof ChangeDataSource)) {
|
||||
s = rewriter.rewrite(Predicate.and(builder.status_open(), q));
|
||||
}
|
||||
|
||||
if (s instanceof ChangeDataSource) {
|
||||
ArrayList<Change> r = new ArrayList<Change>();
|
||||
HashSet<Change.Id> want = new HashSet<Change.Id>();
|
||||
for (ChangeData d : ((ChangeDataSource) s).read()) {
|
||||
if (d.hasChange()) {
|
||||
// Checking visibleToMe here should be unnecessary, the
|
||||
// query should have already performed it. But we don't
|
||||
// want to trust the query rewriter that much yet.
|
||||
//
|
||||
if (visibleToMe.match(d)) {
|
||||
r.add(d.getChange());
|
||||
}
|
||||
} else {
|
||||
want.add(d.getId());
|
||||
}
|
||||
}
|
||||
|
||||
// Here we have to check canRead. Its impossible to
|
||||
// do that test without the change object, and it being
|
||||
// missing above means we have to compute it ourselves.
|
||||
//
|
||||
if (!want.isEmpty()) {
|
||||
for (Change c : db.changes().get(want)) {
|
||||
if (canRead(c, db)) {
|
||||
r.add(c);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Collections.sort(r, cmp);
|
||||
return new ListResultSet<Change>(r);
|
||||
} else {
|
||||
throw new InvalidQueryException("Not Supported", s.toString());
|
||||
}
|
||||
} catch (QueryParseException e) {
|
||||
throw new InvalidQueryException(e.getMessage(), query);
|
||||
}
|
||||
}
|
||||
|
||||
public void forAccount(final Account.Id id,
|
||||
final AsyncCallback<AccountDashboardInfo> callback) {
|
||||
final Account.Id me = getAccountId();
|
||||
final Account.Id target = id != null ? id : me;
|
||||
if (target == null) {
|
||||
callback.onFailure(new NoSuchEntityException());
|
||||
return;
|
||||
}
|
||||
|
||||
run(callback, new Action<AccountDashboardInfo>() {
|
||||
public AccountDashboardInfo run(final ReviewDb db) throws OrmException,
|
||||
Failure {
|
||||
final AccountInfoCacheFactory ac = accountInfoCacheFactory.create();
|
||||
final Account user = ac.get(target);
|
||||
if (user == null) {
|
||||
throw new Failure(new NoSuchEntityException());
|
||||
}
|
||||
|
||||
final Set<Change.Id> stars = currentUser.get().getStarredChanges();
|
||||
final ChangeAccess changes = db.changes();
|
||||
final AccountDashboardInfo d;
|
||||
|
||||
final Set<Change.Id> openReviews = new HashSet<Change.Id>();
|
||||
final Set<Change.Id> closedReviews = new HashSet<Change.Id>();
|
||||
for (final PatchSetApproval ca : db.patchSetApprovals().openByUser(id)) {
|
||||
openReviews.add(ca.getPatchSetId().getParentKey());
|
||||
}
|
||||
for (final PatchSetApproval ca : db.patchSetApprovals()
|
||||
.closedByUser(id)) {
|
||||
closedReviews.add(ca.getPatchSetId().getParentKey());
|
||||
}
|
||||
|
||||
d = new AccountDashboardInfo(target);
|
||||
d.setByOwner(filter(changes.byOwnerOpen(target), stars, ac, db));
|
||||
d.setClosed(filter(changes.byOwnerClosed(target), stars, ac, db));
|
||||
|
||||
for (final ChangeInfo c : d.getByOwner()) {
|
||||
openReviews.remove(c.getId());
|
||||
}
|
||||
d.setForReview(filter(changes.get(openReviews), stars, ac, db));
|
||||
Collections.sort(d.getForReview(), ID_COMP);
|
||||
|
||||
for (final ChangeInfo c : d.getClosed()) {
|
||||
closedReviews.remove(c.getId());
|
||||
}
|
||||
if (!closedReviews.isEmpty()) {
|
||||
d.getClosed().addAll(filter(changes.get(closedReviews), stars, ac, db));
|
||||
Collections.sort(d.getClosed(), SORT_KEY_COMP);
|
||||
}
|
||||
|
||||
// User dashboards are visible to other users, if the current user
|
||||
// can see any of the changes in the dashboard.
|
||||
if (!target.equals(me)
|
||||
&& d.getByOwner().isEmpty()
|
||||
&& d.getClosed().isEmpty()
|
||||
&& d.getForReview().isEmpty()) {
|
||||
throw new Failure(new NoSuchEntityException());
|
||||
}
|
||||
|
||||
d.setAccounts(ac.create());
|
||||
return d;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void toggleStars(final ToggleStarRequest req,
|
||||
@@ -297,97 +71,4 @@ public class ChangeListServiceImpl extends BaseServiceImplementation implements
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void myStarredChangeIds(final AsyncCallback<Set<Change.Id>> callback) {
|
||||
callback.onSuccess(currentUser.get().getStarredChanges());
|
||||
}
|
||||
|
||||
private int safePageSize(final int pageSize) throws InvalidQueryException {
|
||||
int maxLimit = currentUser.get().getCapabilities()
|
||||
.getRange(GlobalCapability.QUERY_LIMIT)
|
||||
.getMax();
|
||||
if (maxLimit <= 0) {
|
||||
throw new InvalidQueryException("Search Disabled");
|
||||
}
|
||||
return 0 < pageSize && pageSize <= maxLimit ? pageSize : maxLimit;
|
||||
}
|
||||
|
||||
private List<ChangeInfo> filter(final ResultSet<Change> rs,
|
||||
final Set<Change.Id> starred, final AccountInfoCacheFactory accts,
|
||||
final ReviewDb db) throws OrmException {
|
||||
final ArrayList<ChangeInfo> r = new ArrayList<ChangeInfo>();
|
||||
for (final Change c : rs) {
|
||||
if (canRead(c, db)) {
|
||||
final ChangeInfo ci = new ChangeInfo(c);
|
||||
accts.want(ci.getOwner());
|
||||
ci.setStarred(starred.contains(ci.getId()));
|
||||
r.add(ci);
|
||||
}
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
private abstract class QueryNext implements Action<SingleListChangeInfo> {
|
||||
protected final String pos;
|
||||
protected final int limit;
|
||||
protected final int slim;
|
||||
|
||||
QueryNext(final int pageSize, final String pos) throws InvalidQueryException {
|
||||
this.pos = pos;
|
||||
this.limit = safePageSize(pageSize);
|
||||
this.slim = limit + 1;
|
||||
}
|
||||
|
||||
public SingleListChangeInfo run(final ReviewDb db) throws OrmException,
|
||||
InvalidQueryException {
|
||||
final AccountInfoCacheFactory ac = accountInfoCacheFactory.create();
|
||||
final SingleListChangeInfo d = new SingleListChangeInfo();
|
||||
final Set<Change.Id> starred = currentUser.get().getStarredChanges();
|
||||
|
||||
final ArrayList<ChangeInfo> list = new ArrayList<ChangeInfo>();
|
||||
final ResultSet<Change> rs = query(db, slim, pos);
|
||||
for (final Change c : rs) {
|
||||
if (!canRead(c, db)) {
|
||||
continue;
|
||||
}
|
||||
final ChangeInfo ci = new ChangeInfo(c);
|
||||
ac.want(ci.getOwner());
|
||||
ci.setStarred(starred.contains(ci.getId()));
|
||||
list.add(ci);
|
||||
if (list.size() == slim) {
|
||||
rs.close();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
final boolean atEnd = finish(list);
|
||||
d.setChanges(list, atEnd);
|
||||
d.setAccounts(ac.create());
|
||||
return d;
|
||||
}
|
||||
|
||||
boolean finish(final ArrayList<ChangeInfo> list) {
|
||||
final boolean atEnd = list.size() <= limit;
|
||||
if (list.size() == slim) {
|
||||
list.remove(limit);
|
||||
}
|
||||
return atEnd;
|
||||
}
|
||||
|
||||
abstract ResultSet<Change> query(final ReviewDb db, final int slim,
|
||||
String sortKey) throws OrmException, InvalidQueryException;
|
||||
}
|
||||
|
||||
private abstract class QueryPrev extends QueryNext {
|
||||
QueryPrev(int pageSize, String pos) throws InvalidQueryException {
|
||||
super(pageSize, pos);
|
||||
}
|
||||
|
||||
@Override
|
||||
boolean finish(final ArrayList<ChangeInfo> list) {
|
||||
final boolean atEnd = super.finish(list);
|
||||
Collections.reverse(list);
|
||||
return atEnd;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,6 @@ import com.google.gerrit.common.data.ListBranchesResult;
|
||||
import com.google.gerrit.common.data.ProjectAccess;
|
||||
import com.google.gerrit.common.data.ProjectAdminService;
|
||||
import com.google.gerrit.common.data.ProjectDetail;
|
||||
import com.google.gerrit.common.data.ProjectList;
|
||||
import com.google.gerrit.reviewdb.client.Branch;
|
||||
import com.google.gerrit.reviewdb.client.Project;
|
||||
import com.google.gwtjsonrpc.common.AsyncCallback;
|
||||
@@ -37,12 +36,10 @@ class ProjectAdminServiceImpl implements ProjectAdminService {
|
||||
private final ChangeProjectSettings.Factory changeProjectSettingsFactory;
|
||||
private final DeleteBranches.Factory deleteBranchesFactory;
|
||||
private final ListBranches.Factory listBranchesFactory;
|
||||
private final VisibleProjects.Factory visibleProjectsFactory;
|
||||
private final VisibleProjectDetails.Factory visibleProjectDetailsFactory;
|
||||
private final ProjectAccessFactory.Factory projectAccessFactory;
|
||||
private final CreateProjectHandler.Factory createProjectHandlerFactory;
|
||||
private final ProjectDetailFactory.Factory projectDetailFactory;
|
||||
private final SuggestParentCandidatesHandler.Factory suggestParentCandidatesHandlerFactory;
|
||||
|
||||
@Inject
|
||||
ProjectAdminServiceImpl(final AddBranch.Factory addBranchFactory,
|
||||
@@ -50,28 +47,19 @@ class ProjectAdminServiceImpl implements ProjectAdminService {
|
||||
final ChangeProjectSettings.Factory changeProjectSettingsFactory,
|
||||
final DeleteBranches.Factory deleteBranchesFactory,
|
||||
final ListBranches.Factory listBranchesFactory,
|
||||
final VisibleProjects.Factory visibleProjectsFactory,
|
||||
final VisibleProjectDetails.Factory visibleProjectDetailsFactory,
|
||||
final ProjectAccessFactory.Factory projectAccessFactory,
|
||||
final ProjectDetailFactory.Factory projectDetailFactory,
|
||||
final SuggestParentCandidatesHandler.Factory parentCandidatesFactory,
|
||||
final CreateProjectHandler.Factory createNewProjectFactory) {
|
||||
this.addBranchFactory = addBranchFactory;
|
||||
this.changeProjectAccessFactory = changeProjectAccessFactory;
|
||||
this.changeProjectSettingsFactory = changeProjectSettingsFactory;
|
||||
this.deleteBranchesFactory = deleteBranchesFactory;
|
||||
this.listBranchesFactory = listBranchesFactory;
|
||||
this.visibleProjectsFactory = visibleProjectsFactory;
|
||||
this.visibleProjectDetailsFactory = visibleProjectDetailsFactory;
|
||||
this.projectAccessFactory = projectAccessFactory;
|
||||
this.projectDetailFactory = projectDetailFactory;
|
||||
this.createProjectHandlerFactory = createNewProjectFactory;
|
||||
this.suggestParentCandidatesHandlerFactory = parentCandidatesFactory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visibleProjects(final AsyncCallback<ProjectList> callback) {
|
||||
visibleProjectsFactory.create().to(callback);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -79,11 +67,6 @@ class ProjectAdminServiceImpl implements ProjectAdminService {
|
||||
visibleProjectDetailsFactory.create().to(callback);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void suggestParentCandidates(AsyncCallback<List<Project>> callback) {
|
||||
suggestParentCandidatesHandlerFactory.create().to(callback);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void projectDetail(final Project.NameKey projectName,
|
||||
final AsyncCallback<ProjectDetail> callback) {
|
||||
|
||||
@@ -34,11 +34,9 @@ public class ProjectModule extends RpcServletModule {
|
||||
factory(ChangeProjectSettings.Factory.class);
|
||||
factory(DeleteBranches.Factory.class);
|
||||
factory(ListBranches.Factory.class);
|
||||
factory(VisibleProjects.Factory.class);
|
||||
factory(VisibleProjectDetails.Factory.class);
|
||||
factory(ProjectAccessFactory.Factory.class);
|
||||
factory(ProjectDetailFactory.Factory.class);
|
||||
factory(SuggestParentCandidatesHandler.Factory.class);
|
||||
}
|
||||
});
|
||||
rpc(ProjectAdminServiceImpl.class);
|
||||
|
||||
@@ -1,40 +0,0 @@
|
||||
// Copyright (C) 2011 The Android Open Source Project
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License
|
||||
|
||||
package com.google.gerrit.httpd.rpc.project;
|
||||
|
||||
import com.google.gerrit.httpd.rpc.Handler;
|
||||
import com.google.gerrit.reviewdb.client.Project;
|
||||
import com.google.gerrit.server.project.SuggestParentCandidates;
|
||||
import com.google.inject.Inject;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class SuggestParentCandidatesHandler extends Handler<List<Project>> {
|
||||
interface Factory {
|
||||
SuggestParentCandidatesHandler create();
|
||||
}
|
||||
|
||||
private final SuggestParentCandidates suggestParentCandidates;
|
||||
|
||||
@Inject
|
||||
SuggestParentCandidatesHandler(final SuggestParentCandidates suggestParentCandidates) {
|
||||
this.suggestParentCandidates = suggestParentCandidates;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Project> call() throws Exception {
|
||||
return suggestParentCandidates.getProjects();
|
||||
}
|
||||
}
|
||||
@@ -1,75 +0,0 @@
|
||||
// Copyright (C) 2009 The Android Open Source Project
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package com.google.gerrit.httpd.rpc.project;
|
||||
|
||||
import com.google.gerrit.common.data.ProjectList;
|
||||
import com.google.gerrit.httpd.rpc.Handler;
|
||||
import com.google.gerrit.reviewdb.client.Project;
|
||||
import com.google.gerrit.server.CurrentUser;
|
||||
import com.google.gerrit.server.project.NoSuchProjectException;
|
||||
import com.google.gerrit.server.project.ProjectCache;
|
||||
import com.google.gerrit.server.project.ProjectControl;
|
||||
import com.google.inject.Inject;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
class VisibleProjects extends Handler<ProjectList> {
|
||||
interface Factory {
|
||||
VisibleProjects create();
|
||||
}
|
||||
|
||||
private final ProjectControl.Factory projectControlFactory;
|
||||
private final ProjectCache projectCache;
|
||||
private final CurrentUser user;
|
||||
|
||||
@Inject
|
||||
VisibleProjects(final ProjectControl.Factory projectControlFactory,
|
||||
final ProjectCache projectCache, final CurrentUser user) {
|
||||
this.projectControlFactory = projectControlFactory;
|
||||
this.projectCache = projectCache;
|
||||
this.user = user;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProjectList call() {
|
||||
ProjectList result = new ProjectList();
|
||||
result.setProjects(getProjects());
|
||||
result.setCanCreateProject(user.getCapabilities().canCreateProject());
|
||||
return result;
|
||||
}
|
||||
|
||||
private List<Project> getProjects() {
|
||||
List<Project> result = new ArrayList<Project>();
|
||||
for (Project.NameKey p : projectCache.all()) {
|
||||
try {
|
||||
ProjectControl c = projectControlFactory.controlFor(p);
|
||||
if (c.isVisible() || c.isOwner()) {
|
||||
result.add(c.getProject());
|
||||
}
|
||||
} catch (NoSuchProjectException e) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
Collections.sort(result, new Comparator<Project>() {
|
||||
public int compare(final Project a, final Project b) {
|
||||
return a.getName().compareTo(b.getName());
|
||||
}
|
||||
});
|
||||
return result;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user