Merge changes from topic 'replace-rpc-services'
* changes: Remove unused RPC suggest service PermissionEditor: Use REST API instead of RPC service AccountGroupSuggestOracle: Use REST API rather than RPC service ListGroups: Allow -s as an alias of --suggest
This commit is contained in:
@@ -174,13 +174,12 @@ Query 25 groups starting from index 50.
|
|||||||
|
|
||||||
[[suggest-group]]
|
[[suggest-group]]
|
||||||
==== Suggest Group
|
==== Suggest Group
|
||||||
The `suggest` option indicates a user-entered string that
|
The `suggest` or `s` option indicates a user-entered string that
|
||||||
should be auto-completed to group names.
|
should be auto-completed to group names.
|
||||||
If this option is set and `n` is not set, then `n` defaults to 10.
|
If this option is set and `n` is not set, then `n` defaults to 10.
|
||||||
|
|
||||||
When using this option,
|
When using this option, the `project` or `p` option can be used to
|
||||||
the `project` or `p` option can be used to name the current project,
|
name the current project, to allow context-dependent suggestions.
|
||||||
to allow context-dependent suggestions.
|
|
||||||
|
|
||||||
Not compatible with `visible-to-all`, `owned`, `user`, `match`, `q`,
|
Not compatible with `visible-to-all`, `owned`, `user`, `match`, `q`,
|
||||||
or `S`.
|
or `S`.
|
||||||
|
|||||||
@@ -1,29 +0,0 @@
|
|||||||
// Copyright (C) 2008 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 com.google.gwtjsonrpc.common.AsyncCallback;
|
|
||||||
import com.google.gwtjsonrpc.common.RemoteJsonService;
|
|
||||||
import com.google.gwtjsonrpc.common.RpcImpl;
|
|
||||||
import com.google.gwtjsonrpc.common.RpcImpl.Version;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@RpcImpl(version = Version.V2_0)
|
|
||||||
public interface SuggestService extends RemoteJsonService {
|
|
||||||
void suggestAccountGroupForProject(Project.NameKey project, String query,
|
|
||||||
int limit, AsyncCallback<List<GroupReference>> callback);
|
|
||||||
}
|
|
||||||
@@ -14,8 +14,8 @@
|
|||||||
|
|
||||||
package com.google.gerrit.client.admin;
|
package com.google.gerrit.client.admin;
|
||||||
|
|
||||||
|
import com.google.gerrit.client.groups.GroupMap;
|
||||||
import com.google.gerrit.client.rpc.GerritCallback;
|
import com.google.gerrit.client.rpc.GerritCallback;
|
||||||
import com.google.gerrit.client.ui.SuggestUtil;
|
|
||||||
import com.google.gerrit.common.data.AccessSection;
|
import com.google.gerrit.common.data.AccessSection;
|
||||||
import com.google.gerrit.common.data.GlobalCapability;
|
import com.google.gerrit.common.data.GlobalCapability;
|
||||||
import com.google.gerrit.common.data.GroupInfo;
|
import com.google.gerrit.common.data.GroupInfo;
|
||||||
@@ -241,14 +241,16 @@ public class PermissionEditor extends Composite implements Editor<Permission>,
|
|||||||
// If the oracle didn't get to complete a UUID, resolve it now.
|
// If the oracle didn't get to complete a UUID, resolve it now.
|
||||||
//
|
//
|
||||||
addRule.setEnabled(false);
|
addRule.setEnabled(false);
|
||||||
SuggestUtil.SVC.suggestAccountGroupForProject(
|
GroupMap.suggestAccountGroupForProject(
|
||||||
projectName, ref.getName(), 1,
|
projectName.get(), ref.getName(), 1,
|
||||||
new GerritCallback<List<GroupReference>>() {
|
new GerritCallback<GroupMap>() {
|
||||||
@Override
|
@Override
|
||||||
public void onSuccess(List<GroupReference> result) {
|
public void onSuccess(GroupMap result) {
|
||||||
addRule.setEnabled(true);
|
addRule.setEnabled(true);
|
||||||
if (result.size() == 1) {
|
if (result.values().length() == 1) {
|
||||||
addGroup(result.get(0));
|
addGroup(new GroupReference(
|
||||||
|
result.values().get(0).getGroupUUID(),
|
||||||
|
result.values().get(0).name()));
|
||||||
} else {
|
} else {
|
||||||
groupToAdd.setFocus(true);
|
groupToAdd.setFocus(true);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,6 +38,21 @@ public class GroupMap extends NativeMap<GroupInfo> {
|
|||||||
call.get(NativeMap.copyKeysIntoChildren(cb));
|
call.get(NativeMap.copyKeysIntoChildren(cb));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void suggestAccountGroupForProject(String project, String query,
|
||||||
|
int limit, AsyncCallback<GroupMap> cb) {
|
||||||
|
RestApi call = groups();
|
||||||
|
if (project != null) {
|
||||||
|
call.addParameter("p", project);
|
||||||
|
}
|
||||||
|
if (query != null) {
|
||||||
|
call.addParameter("s", query);
|
||||||
|
}
|
||||||
|
if (limit > 0) {
|
||||||
|
call.addParameter("n", limit);
|
||||||
|
}
|
||||||
|
call.get(NativeMap.copyKeysIntoChildren(cb));
|
||||||
|
}
|
||||||
|
|
||||||
public static void myOwned(AsyncCallback<GroupMap> cb) {
|
public static void myOwned(AsyncCallback<GroupMap> cb) {
|
||||||
myOwnedGroups().get(NativeMap.copyKeysIntoChildren(cb));
|
myOwnedGroups().get(NativeMap.copyKeysIntoChildren(cb));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,16 +14,16 @@
|
|||||||
|
|
||||||
package com.google.gerrit.client.ui;
|
package com.google.gerrit.client.ui;
|
||||||
|
|
||||||
import com.google.gerrit.client.RpcStatus;
|
import com.google.gerrit.client.groups.GroupInfo;
|
||||||
|
import com.google.gerrit.client.groups.GroupMap;
|
||||||
import com.google.gerrit.client.rpc.GerritCallback;
|
import com.google.gerrit.client.rpc.GerritCallback;
|
||||||
import com.google.gerrit.common.data.GroupReference;
|
import com.google.gerrit.client.rpc.Natives;
|
||||||
import com.google.gerrit.reviewdb.client.AccountGroup;
|
import com.google.gerrit.reviewdb.client.AccountGroup;
|
||||||
import com.google.gerrit.reviewdb.client.Project;
|
import com.google.gerrit.reviewdb.client.Project;
|
||||||
import com.google.gwt.user.client.ui.SuggestOracle;
|
import com.google.gwt.user.client.ui.SuggestOracle;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
/** Suggestion Oracle for AccountGroup entities. */
|
/** Suggestion Oracle for AccountGroup entities. */
|
||||||
@@ -34,26 +34,20 @@ public class AccountGroupSuggestOracle extends SuggestAfterTypingNCharsOracle {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void _onRequestSuggestions(final Request req, final Callback callback) {
|
public void _onRequestSuggestions(final Request req, final Callback callback) {
|
||||||
RpcStatus.hide(new Runnable() {
|
GroupMap.suggestAccountGroupForProject(
|
||||||
@Override
|
projectName.get(), req.getQuery(), req.getLimit(),
|
||||||
public void run() {
|
new GerritCallback<GroupMap>() {
|
||||||
SuggestUtil.SVC.suggestAccountGroupForProject(
|
@Override
|
||||||
projectName, req.getQuery(), req.getLimit(),
|
public void onSuccess(GroupMap result) {
|
||||||
new GerritCallback<List<GroupReference>>() {
|
priorResults.clear();
|
||||||
@Override
|
ArrayList<AccountGroupSuggestion> r = new ArrayList<>(result.size());
|
||||||
public void onSuccess(final List<GroupReference> result) {
|
for (GroupInfo group : Natives.asList(result.values())) {
|
||||||
priorResults.clear();
|
r.add(new AccountGroupSuggestion(group));
|
||||||
final ArrayList<AccountGroupSuggestion> r =
|
priorResults.put(group.name(), group.getGroupUUID());
|
||||||
new ArrayList<>(result.size());
|
}
|
||||||
for (final GroupReference p : result) {
|
callback.onSuggestionsReady(req, new Response(r));
|
||||||
r.add(new AccountGroupSuggestion(p));
|
}
|
||||||
priorResults.put(p.getName(), p.getUUID());
|
});
|
||||||
}
|
|
||||||
callback.onSuggestionsReady(req, new Response(r));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setProject(Project.NameKey projectName) {
|
public void setProject(Project.NameKey projectName) {
|
||||||
@@ -62,20 +56,20 @@ public class AccountGroupSuggestOracle extends SuggestAfterTypingNCharsOracle {
|
|||||||
|
|
||||||
private static class AccountGroupSuggestion implements
|
private static class AccountGroupSuggestion implements
|
||||||
SuggestOracle.Suggestion {
|
SuggestOracle.Suggestion {
|
||||||
private final GroupReference info;
|
private final GroupInfo info;
|
||||||
|
|
||||||
AccountGroupSuggestion(final GroupReference k) {
|
AccountGroupSuggestion(final GroupInfo k) {
|
||||||
info = k;
|
info = k;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getDisplayString() {
|
public String getDisplayString() {
|
||||||
return info.getName();
|
return info.name();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getReplacementString() {
|
public String getReplacementString() {
|
||||||
return info.getName();
|
return info.name();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,31 +0,0 @@
|
|||||||
// Copyright (C) 2008 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.client.ui;
|
|
||||||
|
|
||||||
import com.google.gerrit.common.data.SuggestService;
|
|
||||||
import com.google.gwt.core.client.GWT;
|
|
||||||
import com.google.gwtjsonrpc.client.JsonUtil;
|
|
||||||
|
|
||||||
public class SuggestUtil {
|
|
||||||
public static final SuggestService SVC;
|
|
||||||
|
|
||||||
static {
|
|
||||||
SVC = GWT.create(SuggestService.class);
|
|
||||||
JsonUtil.bind(SVC, "rpc/SuggestService");
|
|
||||||
}
|
|
||||||
|
|
||||||
private SuggestUtil() {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,76 +0,0 @@
|
|||||||
// Copyright (C) 2008 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;
|
|
||||||
|
|
||||||
import com.google.common.collect.Iterables;
|
|
||||||
import com.google.common.collect.Lists;
|
|
||||||
import com.google.gerrit.common.Nullable;
|
|
||||||
import com.google.gerrit.common.data.GroupReference;
|
|
||||||
import com.google.gerrit.common.data.SuggestService;
|
|
||||||
import com.google.gerrit.reviewdb.client.Project;
|
|
||||||
import com.google.gerrit.reviewdb.server.ReviewDb;
|
|
||||||
import com.google.gerrit.server.CurrentUser;
|
|
||||||
import com.google.gerrit.server.account.GroupBackend;
|
|
||||||
import com.google.gerrit.server.project.NoSuchProjectException;
|
|
||||||
import com.google.gerrit.server.project.ProjectControl;
|
|
||||||
import com.google.gwtjsonrpc.common.AsyncCallback;
|
|
||||||
import com.google.inject.Inject;
|
|
||||||
import com.google.inject.Provider;
|
|
||||||
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
class SuggestServiceImpl extends BaseServiceImplementation implements
|
|
||||||
SuggestService {
|
|
||||||
private final ProjectControl.Factory projectControlFactory;
|
|
||||||
private final GroupBackend groupBackend;
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
SuggestServiceImpl(final Provider<ReviewDb> schema,
|
|
||||||
final Provider<CurrentUser> currentUser,
|
|
||||||
final ProjectControl.Factory projectControlFactory,
|
|
||||||
final GroupBackend groupBackend) {
|
|
||||||
super(schema, currentUser);
|
|
||||||
this.projectControlFactory = projectControlFactory;
|
|
||||||
this.groupBackend = groupBackend;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void suggestAccountGroupForProject(final Project.NameKey project,
|
|
||||||
final String query, final int limit,
|
|
||||||
final AsyncCallback<List<GroupReference>> callback) {
|
|
||||||
run(callback, new Action<List<GroupReference>>() {
|
|
||||||
@Override
|
|
||||||
public List<GroupReference> run(final ReviewDb db) {
|
|
||||||
ProjectControl projectControl = null;
|
|
||||||
if (project != null) {
|
|
||||||
try {
|
|
||||||
projectControl = projectControlFactory.controlFor(project);
|
|
||||||
} catch (NoSuchProjectException e) {
|
|
||||||
return Collections.emptyList();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return suggestAccountGroup(projectControl, query, limit);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private List<GroupReference> suggestAccountGroup(
|
|
||||||
@Nullable final ProjectControl projectControl, final String query, final int limit) {
|
|
||||||
return Lists.newArrayList(Iterables.limit(
|
|
||||||
groupBackend.suggest(query, projectControl),
|
|
||||||
limit <= 0 ? 10 : Math.min(limit, 10)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -27,7 +27,6 @@ public class UiRpcModule extends RpcServletModule {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void configureServlets() {
|
protected void configureServlets() {
|
||||||
rpc(SuggestServiceImpl.class);
|
|
||||||
rpc(SystemInfoServiceImpl.class);
|
rpc(SystemInfoServiceImpl.class);
|
||||||
|
|
||||||
install(new AccountModule());
|
install(new AccountModule());
|
||||||
|
|||||||
@@ -127,7 +127,8 @@ public class ListGroups implements RestReadView<TopLevelResource> {
|
|||||||
this.matchSubstring = matchSubstring;
|
this.matchSubstring = matchSubstring;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Option(name = "--suggest", usage = "to get a suggestion of groups")
|
@Option(name = "--suggest", aliases = {"-s"},
|
||||||
|
usage = "to get a suggestion of groups")
|
||||||
public void setSuggest(String suggest) {
|
public void setSuggest(String suggest) {
|
||||||
this.suggest = suggest;
|
this.suggest = suggest;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user