Dissolve gerrit-server top-level directory
Change-Id: I538512dfe0f1bea774c01fdd45fa410a45634011
This commit is contained in:
committed by
Dave Borowitz
parent
472396c797
commit
376a7bbb64
39
java/com/google/gerrit/server/api/ApiUtil.java
Normal file
39
java/com/google/gerrit/server/api/ApiUtil.java
Normal file
@@ -0,0 +1,39 @@
|
||||
// Copyright (C) 2017 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.server.api;
|
||||
|
||||
import com.google.common.base.Throwables;
|
||||
import com.google.gerrit.extensions.restapi.RestApiException;
|
||||
|
||||
/** Static utilities for API implementations. */
|
||||
public class ApiUtil {
|
||||
/**
|
||||
* Convert an exception encountered during API execution to a {@link RestApiException}.
|
||||
*
|
||||
* @param msg message to be used in the case where a new {@code RestApiException} is wrapped
|
||||
* around {@code e}.
|
||||
* @param e exception being handled.
|
||||
* @return {@code e} if it is already a {@code RestApiException}, otherwise a new {@code
|
||||
* RestApiException} wrapped around {@code e}.
|
||||
* @throws RuntimeException if {@code e} is a runtime exception, it is rethrown as-is.
|
||||
*/
|
||||
public static RestApiException asRestApiException(String msg, Exception e)
|
||||
throws RuntimeException {
|
||||
Throwables.throwIfUnchecked(e);
|
||||
return e instanceof RestApiException ? (RestApiException) e : new RestApiException(msg, e);
|
||||
}
|
||||
|
||||
private ApiUtil() {}
|
||||
}
|
||||
81
java/com/google/gerrit/server/api/GerritApiImpl.java
Normal file
81
java/com/google/gerrit/server/api/GerritApiImpl.java
Normal file
@@ -0,0 +1,81 @@
|
||||
// Copyright (C) 2013 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.server.api;
|
||||
|
||||
import com.google.gerrit.extensions.api.GerritApi;
|
||||
import com.google.gerrit.extensions.api.accounts.Accounts;
|
||||
import com.google.gerrit.extensions.api.changes.Changes;
|
||||
import com.google.gerrit.extensions.api.config.Config;
|
||||
import com.google.gerrit.extensions.api.groups.Groups;
|
||||
import com.google.gerrit.extensions.api.plugins.Plugins;
|
||||
import com.google.gerrit.extensions.api.projects.Projects;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Singleton;
|
||||
|
||||
@Singleton
|
||||
class GerritApiImpl implements GerritApi {
|
||||
private final Accounts accounts;
|
||||
private final Changes changes;
|
||||
private final Config config;
|
||||
private final Groups groups;
|
||||
private final Projects projects;
|
||||
private final Plugins plugins;
|
||||
|
||||
@Inject
|
||||
GerritApiImpl(
|
||||
Accounts accounts,
|
||||
Changes changes,
|
||||
Config config,
|
||||
Groups groups,
|
||||
Projects projects,
|
||||
Plugins plugins) {
|
||||
this.accounts = accounts;
|
||||
this.changes = changes;
|
||||
this.config = config;
|
||||
this.groups = groups;
|
||||
this.projects = projects;
|
||||
this.plugins = plugins;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Accounts accounts() {
|
||||
return accounts;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Changes changes() {
|
||||
return changes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Config config() {
|
||||
return config;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Groups groups() {
|
||||
return groups;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Projects projects() {
|
||||
return projects;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Plugins plugins() {
|
||||
return plugins;
|
||||
}
|
||||
}
|
||||
31
java/com/google/gerrit/server/api/Module.java
Normal file
31
java/com/google/gerrit/server/api/Module.java
Normal file
@@ -0,0 +1,31 @@
|
||||
// Copyright (C) 2013 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.server.api;
|
||||
|
||||
import com.google.gerrit.extensions.api.GerritApi;
|
||||
import com.google.inject.AbstractModule;
|
||||
|
||||
public class Module extends AbstractModule {
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(GerritApi.class).to(GerritApiImpl.class);
|
||||
|
||||
install(new com.google.gerrit.server.api.accounts.Module());
|
||||
install(new com.google.gerrit.server.api.changes.Module());
|
||||
install(new com.google.gerrit.server.api.config.Module());
|
||||
install(new com.google.gerrit.server.api.groups.Module());
|
||||
install(new com.google.gerrit.server.api.projects.Module());
|
||||
}
|
||||
}
|
||||
519
java/com/google/gerrit/server/api/accounts/AccountApiImpl.java
Normal file
519
java/com/google/gerrit/server/api/accounts/AccountApiImpl.java
Normal file
@@ -0,0 +1,519 @@
|
||||
// Copyright (C) 2014 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.server.api.accounts;
|
||||
|
||||
import static com.google.gerrit.server.api.ApiUtil.asRestApiException;
|
||||
import static javax.servlet.http.HttpServletResponse.SC_OK;
|
||||
|
||||
import com.google.gerrit.common.RawInputUtil;
|
||||
import com.google.gerrit.extensions.api.accounts.AccountApi;
|
||||
import com.google.gerrit.extensions.api.accounts.EmailInput;
|
||||
import com.google.gerrit.extensions.api.accounts.GpgKeyApi;
|
||||
import com.google.gerrit.extensions.api.accounts.SshKeyInput;
|
||||
import com.google.gerrit.extensions.api.accounts.StatusInput;
|
||||
import com.google.gerrit.extensions.api.changes.StarsInput;
|
||||
import com.google.gerrit.extensions.client.DiffPreferencesInfo;
|
||||
import com.google.gerrit.extensions.client.EditPreferencesInfo;
|
||||
import com.google.gerrit.extensions.client.GeneralPreferencesInfo;
|
||||
import com.google.gerrit.extensions.client.ProjectWatchInfo;
|
||||
import com.google.gerrit.extensions.common.AccountExternalIdInfo;
|
||||
import com.google.gerrit.extensions.common.AccountInfo;
|
||||
import com.google.gerrit.extensions.common.AgreementInfo;
|
||||
import com.google.gerrit.extensions.common.AgreementInput;
|
||||
import com.google.gerrit.extensions.common.ChangeInfo;
|
||||
import com.google.gerrit.extensions.common.EmailInfo;
|
||||
import com.google.gerrit.extensions.common.GpgKeyInfo;
|
||||
import com.google.gerrit.extensions.common.GroupInfo;
|
||||
import com.google.gerrit.extensions.common.Input;
|
||||
import com.google.gerrit.extensions.common.SshKeyInfo;
|
||||
import com.google.gerrit.extensions.restapi.IdString;
|
||||
import com.google.gerrit.extensions.restapi.Response;
|
||||
import com.google.gerrit.extensions.restapi.RestApiException;
|
||||
import com.google.gerrit.extensions.restapi.TopLevelResource;
|
||||
import com.google.gerrit.server.account.AccountLoader;
|
||||
import com.google.gerrit.server.account.AccountResource;
|
||||
import com.google.gerrit.server.account.AddSshKey;
|
||||
import com.google.gerrit.server.account.CreateEmail;
|
||||
import com.google.gerrit.server.account.DeleteActive;
|
||||
import com.google.gerrit.server.account.DeleteEmail;
|
||||
import com.google.gerrit.server.account.DeleteExternalIds;
|
||||
import com.google.gerrit.server.account.DeleteSshKey;
|
||||
import com.google.gerrit.server.account.DeleteWatchedProjects;
|
||||
import com.google.gerrit.server.account.GetActive;
|
||||
import com.google.gerrit.server.account.GetAgreements;
|
||||
import com.google.gerrit.server.account.GetAvatar;
|
||||
import com.google.gerrit.server.account.GetDiffPreferences;
|
||||
import com.google.gerrit.server.account.GetEditPreferences;
|
||||
import com.google.gerrit.server.account.GetEmails;
|
||||
import com.google.gerrit.server.account.GetExternalIds;
|
||||
import com.google.gerrit.server.account.GetGroups;
|
||||
import com.google.gerrit.server.account.GetPreferences;
|
||||
import com.google.gerrit.server.account.GetSshKeys;
|
||||
import com.google.gerrit.server.account.GetWatchedProjects;
|
||||
import com.google.gerrit.server.account.Index;
|
||||
import com.google.gerrit.server.account.PostWatchedProjects;
|
||||
import com.google.gerrit.server.account.PutActive;
|
||||
import com.google.gerrit.server.account.PutAgreement;
|
||||
import com.google.gerrit.server.account.PutStatus;
|
||||
import com.google.gerrit.server.account.SetDiffPreferences;
|
||||
import com.google.gerrit.server.account.SetEditPreferences;
|
||||
import com.google.gerrit.server.account.SetPreferences;
|
||||
import com.google.gerrit.server.account.SshKeys;
|
||||
import com.google.gerrit.server.account.StarredChanges;
|
||||
import com.google.gerrit.server.account.Stars;
|
||||
import com.google.gerrit.server.change.ChangeResource;
|
||||
import com.google.gerrit.server.change.ChangesCollection;
|
||||
import com.google.gwtorm.server.OrmException;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.assistedinject.Assisted;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.SortedSet;
|
||||
|
||||
public class AccountApiImpl implements AccountApi {
|
||||
interface Factory {
|
||||
AccountApiImpl create(AccountResource account);
|
||||
}
|
||||
|
||||
private final AccountResource account;
|
||||
private final ChangesCollection changes;
|
||||
private final AccountLoader.Factory accountLoaderFactory;
|
||||
private final GetAvatar getAvatar;
|
||||
private final GetPreferences getPreferences;
|
||||
private final SetPreferences setPreferences;
|
||||
private final GetDiffPreferences getDiffPreferences;
|
||||
private final SetDiffPreferences setDiffPreferences;
|
||||
private final GetEditPreferences getEditPreferences;
|
||||
private final SetEditPreferences setEditPreferences;
|
||||
private final GetWatchedProjects getWatchedProjects;
|
||||
private final PostWatchedProjects postWatchedProjects;
|
||||
private final DeleteWatchedProjects deleteWatchedProjects;
|
||||
private final StarredChanges.Create starredChangesCreate;
|
||||
private final StarredChanges.Delete starredChangesDelete;
|
||||
private final Stars stars;
|
||||
private final Stars.Get starsGet;
|
||||
private final Stars.Post starsPost;
|
||||
private final GetEmails getEmails;
|
||||
private final CreateEmail.Factory createEmailFactory;
|
||||
private final DeleteEmail deleteEmail;
|
||||
private final GpgApiAdapter gpgApiAdapter;
|
||||
private final GetSshKeys getSshKeys;
|
||||
private final AddSshKey addSshKey;
|
||||
private final DeleteSshKey deleteSshKey;
|
||||
private final SshKeys sshKeys;
|
||||
private final GetAgreements getAgreements;
|
||||
private final PutAgreement putAgreement;
|
||||
private final GetActive getActive;
|
||||
private final PutActive putActive;
|
||||
private final DeleteActive deleteActive;
|
||||
private final Index index;
|
||||
private final GetExternalIds getExternalIds;
|
||||
private final DeleteExternalIds deleteExternalIds;
|
||||
private final PutStatus putStatus;
|
||||
private final GetGroups getGroups;
|
||||
|
||||
@Inject
|
||||
AccountApiImpl(
|
||||
AccountLoader.Factory ailf,
|
||||
ChangesCollection changes,
|
||||
GetAvatar getAvatar,
|
||||
GetPreferences getPreferences,
|
||||
SetPreferences setPreferences,
|
||||
GetDiffPreferences getDiffPreferences,
|
||||
SetDiffPreferences setDiffPreferences,
|
||||
GetEditPreferences getEditPreferences,
|
||||
SetEditPreferences setEditPreferences,
|
||||
GetWatchedProjects getWatchedProjects,
|
||||
PostWatchedProjects postWatchedProjects,
|
||||
DeleteWatchedProjects deleteWatchedProjects,
|
||||
StarredChanges.Create starredChangesCreate,
|
||||
StarredChanges.Delete starredChangesDelete,
|
||||
Stars stars,
|
||||
Stars.Get starsGet,
|
||||
Stars.Post starsPost,
|
||||
GetEmails getEmails,
|
||||
CreateEmail.Factory createEmailFactory,
|
||||
DeleteEmail deleteEmail,
|
||||
GpgApiAdapter gpgApiAdapter,
|
||||
GetSshKeys getSshKeys,
|
||||
AddSshKey addSshKey,
|
||||
DeleteSshKey deleteSshKey,
|
||||
SshKeys sshKeys,
|
||||
GetAgreements getAgreements,
|
||||
PutAgreement putAgreement,
|
||||
GetActive getActive,
|
||||
PutActive putActive,
|
||||
DeleteActive deleteActive,
|
||||
Index index,
|
||||
GetExternalIds getExternalIds,
|
||||
DeleteExternalIds deleteExternalIds,
|
||||
PutStatus putStatus,
|
||||
GetGroups getGroups,
|
||||
@Assisted AccountResource account) {
|
||||
this.account = account;
|
||||
this.accountLoaderFactory = ailf;
|
||||
this.changes = changes;
|
||||
this.getAvatar = getAvatar;
|
||||
this.getPreferences = getPreferences;
|
||||
this.setPreferences = setPreferences;
|
||||
this.getDiffPreferences = getDiffPreferences;
|
||||
this.setDiffPreferences = setDiffPreferences;
|
||||
this.getEditPreferences = getEditPreferences;
|
||||
this.setEditPreferences = setEditPreferences;
|
||||
this.getWatchedProjects = getWatchedProjects;
|
||||
this.postWatchedProjects = postWatchedProjects;
|
||||
this.deleteWatchedProjects = deleteWatchedProjects;
|
||||
this.starredChangesCreate = starredChangesCreate;
|
||||
this.starredChangesDelete = starredChangesDelete;
|
||||
this.stars = stars;
|
||||
this.starsGet = starsGet;
|
||||
this.starsPost = starsPost;
|
||||
this.getEmails = getEmails;
|
||||
this.createEmailFactory = createEmailFactory;
|
||||
this.deleteEmail = deleteEmail;
|
||||
this.getSshKeys = getSshKeys;
|
||||
this.addSshKey = addSshKey;
|
||||
this.deleteSshKey = deleteSshKey;
|
||||
this.sshKeys = sshKeys;
|
||||
this.gpgApiAdapter = gpgApiAdapter;
|
||||
this.getAgreements = getAgreements;
|
||||
this.putAgreement = putAgreement;
|
||||
this.getActive = getActive;
|
||||
this.putActive = putActive;
|
||||
this.deleteActive = deleteActive;
|
||||
this.index = index;
|
||||
this.getExternalIds = getExternalIds;
|
||||
this.deleteExternalIds = deleteExternalIds;
|
||||
this.putStatus = putStatus;
|
||||
this.getGroups = getGroups;
|
||||
}
|
||||
|
||||
@Override
|
||||
public com.google.gerrit.extensions.common.AccountInfo get() throws RestApiException {
|
||||
AccountLoader accountLoader = accountLoaderFactory.create(true);
|
||||
try {
|
||||
AccountInfo ai = accountLoader.get(account.getUser().getAccountId());
|
||||
accountLoader.fill();
|
||||
return ai;
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot parse change", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getActive() throws RestApiException {
|
||||
Response<String> result = getActive.apply(account);
|
||||
return result.statusCode() == SC_OK && result.value().equals("ok");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setActive(boolean active) throws RestApiException {
|
||||
try {
|
||||
if (active) {
|
||||
putActive.apply(account, new Input());
|
||||
} else {
|
||||
deleteActive.apply(account, new Input());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot set active", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAvatarUrl(int size) throws RestApiException {
|
||||
getAvatar.setSize(size);
|
||||
return getAvatar.apply(account).location();
|
||||
}
|
||||
|
||||
@Override
|
||||
public GeneralPreferencesInfo getPreferences() throws RestApiException {
|
||||
try {
|
||||
return getPreferences.apply(account);
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot get preferences", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public GeneralPreferencesInfo setPreferences(GeneralPreferencesInfo in) throws RestApiException {
|
||||
try {
|
||||
return setPreferences.apply(account, in);
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot set preferences", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public DiffPreferencesInfo getDiffPreferences() throws RestApiException {
|
||||
try {
|
||||
return getDiffPreferences.apply(account);
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot query diff preferences", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public DiffPreferencesInfo setDiffPreferences(DiffPreferencesInfo in) throws RestApiException {
|
||||
try {
|
||||
return setDiffPreferences.apply(account, in);
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot set diff preferences", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public EditPreferencesInfo getEditPreferences() throws RestApiException {
|
||||
try {
|
||||
return getEditPreferences.apply(account);
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot query edit preferences", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public EditPreferencesInfo setEditPreferences(EditPreferencesInfo in) throws RestApiException {
|
||||
try {
|
||||
return setEditPreferences.apply(account, in);
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot set edit preferences", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ProjectWatchInfo> getWatchedProjects() throws RestApiException {
|
||||
try {
|
||||
return getWatchedProjects.apply(account);
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot get watched projects", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ProjectWatchInfo> setWatchedProjects(List<ProjectWatchInfo> in)
|
||||
throws RestApiException {
|
||||
try {
|
||||
return postWatchedProjects.apply(account, in);
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot update watched projects", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteWatchedProjects(List<ProjectWatchInfo> in) throws RestApiException {
|
||||
try {
|
||||
deleteWatchedProjects.apply(account, in);
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot delete watched projects", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void starChange(String changeId) throws RestApiException {
|
||||
try {
|
||||
ChangeResource rsrc = changes.parse(TopLevelResource.INSTANCE, IdString.fromUrl(changeId));
|
||||
starredChangesCreate.setChange(rsrc);
|
||||
starredChangesCreate.apply(account, new StarredChanges.EmptyInput());
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot star change", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unstarChange(String changeId) throws RestApiException {
|
||||
try {
|
||||
ChangeResource rsrc = changes.parse(TopLevelResource.INSTANCE, IdString.fromUrl(changeId));
|
||||
AccountResource.StarredChange starredChange =
|
||||
new AccountResource.StarredChange(account.getUser(), rsrc);
|
||||
starredChangesDelete.apply(starredChange, new StarredChanges.EmptyInput());
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot unstar change", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setStars(String changeId, StarsInput input) throws RestApiException {
|
||||
try {
|
||||
AccountResource.Star rsrc = stars.parse(account, IdString.fromUrl(changeId));
|
||||
starsPost.apply(rsrc, input);
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot post stars", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public SortedSet<String> getStars(String changeId) throws RestApiException {
|
||||
try {
|
||||
AccountResource.Star rsrc = stars.parse(account, IdString.fromUrl(changeId));
|
||||
return starsGet.apply(rsrc);
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot get stars", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ChangeInfo> getStarredChanges() throws RestApiException {
|
||||
try {
|
||||
return stars.list().apply(account);
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot get starred changes", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<GroupInfo> getGroups() throws RestApiException {
|
||||
try {
|
||||
return getGroups.apply(account);
|
||||
} catch (OrmException e) {
|
||||
throw asRestApiException("Cannot get groups", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<EmailInfo> getEmails() {
|
||||
return getEmails.apply(account);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addEmail(EmailInput input) throws RestApiException {
|
||||
AccountResource.Email rsrc = new AccountResource.Email(account.getUser(), input.email);
|
||||
try {
|
||||
createEmailFactory.create(input.email).apply(rsrc, input);
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot add email", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteEmail(String email) throws RestApiException {
|
||||
AccountResource.Email rsrc = new AccountResource.Email(account.getUser(), email);
|
||||
try {
|
||||
deleteEmail.apply(rsrc, null);
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot delete email", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setStatus(String status) throws RestApiException {
|
||||
StatusInput in = new StatusInput(status);
|
||||
try {
|
||||
putStatus.apply(account, in);
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot set status", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SshKeyInfo> listSshKeys() throws RestApiException {
|
||||
try {
|
||||
return getSshKeys.apply(account);
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot list SSH keys", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public SshKeyInfo addSshKey(String key) throws RestApiException {
|
||||
SshKeyInput in = new SshKeyInput();
|
||||
in.raw = RawInputUtil.create(key);
|
||||
try {
|
||||
return addSshKey.apply(account, in).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot add SSH key", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteSshKey(int seq) throws RestApiException {
|
||||
try {
|
||||
AccountResource.SshKey sshKeyRes =
|
||||
sshKeys.parse(account, IdString.fromDecoded(Integer.toString(seq)));
|
||||
deleteSshKey.apply(sshKeyRes, null);
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot delete SSH key", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, GpgKeyInfo> listGpgKeys() throws RestApiException {
|
||||
try {
|
||||
return gpgApiAdapter.listGpgKeys(account);
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot list GPG keys", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, GpgKeyInfo> putGpgKeys(List<String> add, List<String> delete)
|
||||
throws RestApiException {
|
||||
try {
|
||||
return gpgApiAdapter.putGpgKeys(account, add, delete);
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot add GPG key", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public GpgKeyApi gpgKey(String id) throws RestApiException {
|
||||
try {
|
||||
return gpgApiAdapter.gpgKey(account, IdString.fromDecoded(id));
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot get PGP key", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<AgreementInfo> listAgreements() throws RestApiException {
|
||||
return getAgreements.apply(account);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void signAgreement(String agreementName) throws RestApiException {
|
||||
try {
|
||||
AgreementInput input = new AgreementInput();
|
||||
input.name = agreementName;
|
||||
putAgreement.apply(account, input);
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot sign agreement", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void index() throws RestApiException {
|
||||
try {
|
||||
index.apply(account, new Input());
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot index account", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<AccountExternalIdInfo> getExternalIds() throws RestApiException {
|
||||
try {
|
||||
return getExternalIds.apply(account);
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot get external IDs", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteExternalIds(List<String> externalIds) throws RestApiException {
|
||||
try {
|
||||
deleteExternalIds.apply(account, externalIds);
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot delete external IDs", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
// Copyright (C) 2016 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.server.api.accounts;
|
||||
|
||||
import com.google.gerrit.reviewdb.client.Account;
|
||||
import com.google.gerrit.server.account.externalids.ExternalId;
|
||||
import java.util.List;
|
||||
|
||||
public interface AccountExternalIdCreator {
|
||||
|
||||
/**
|
||||
* Returns additional external identifiers to assign to a given user when creating an account.
|
||||
*
|
||||
* @param id the identifier of the account.
|
||||
* @param username the name of the user.
|
||||
* @param email an optional email address to assign to the external identifiers, or {@code null}.
|
||||
* @return a list of external identifiers, or an empty list.
|
||||
*/
|
||||
List<ExternalId> create(Account.Id id, String username, String email);
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
// Copyright (C) 2015 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.server.api.accounts;
|
||||
|
||||
import com.google.common.collect.ComparisonChain;
|
||||
import com.google.common.collect.Ordering;
|
||||
import com.google.gerrit.extensions.common.AccountInfo;
|
||||
import java.util.Comparator;
|
||||
|
||||
public class AccountInfoComparator extends Ordering<AccountInfo>
|
||||
implements Comparator<AccountInfo> {
|
||||
public static final AccountInfoComparator ORDER_NULLS_FIRST = new AccountInfoComparator();
|
||||
public static final AccountInfoComparator ORDER_NULLS_LAST =
|
||||
new AccountInfoComparator().setNullsLast();
|
||||
|
||||
private boolean nullsLast;
|
||||
|
||||
private AccountInfoComparator() {}
|
||||
|
||||
private AccountInfoComparator setNullsLast() {
|
||||
this.nullsLast = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compare(AccountInfo a, AccountInfo b) {
|
||||
return ComparisonChain.start()
|
||||
.compare(a.name, b.name, createOrdering())
|
||||
.compare(a.email, b.email, createOrdering())
|
||||
.compare(a._accountId, b._accountId, createOrdering())
|
||||
.result();
|
||||
}
|
||||
|
||||
private <S extends Comparable<?>> Ordering<S> createOrdering() {
|
||||
if (nullsLast) {
|
||||
return Ordering.natural().nullsLast();
|
||||
}
|
||||
return Ordering.natural().nullsFirst();
|
||||
}
|
||||
}
|
||||
167
java/com/google/gerrit/server/api/accounts/AccountsImpl.java
Normal file
167
java/com/google/gerrit/server/api/accounts/AccountsImpl.java
Normal file
@@ -0,0 +1,167 @@
|
||||
// Copyright (C) 2014 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.server.api.accounts;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static com.google.gerrit.server.api.ApiUtil.asRestApiException;
|
||||
|
||||
import com.google.gerrit.extensions.api.accounts.AccountApi;
|
||||
import com.google.gerrit.extensions.api.accounts.AccountInput;
|
||||
import com.google.gerrit.extensions.api.accounts.Accounts;
|
||||
import com.google.gerrit.extensions.client.ListAccountsOption;
|
||||
import com.google.gerrit.extensions.common.AccountInfo;
|
||||
import com.google.gerrit.extensions.restapi.AuthException;
|
||||
import com.google.gerrit.extensions.restapi.BadRequestException;
|
||||
import com.google.gerrit.extensions.restapi.IdString;
|
||||
import com.google.gerrit.extensions.restapi.RestApiException;
|
||||
import com.google.gerrit.extensions.restapi.TopLevelResource;
|
||||
import com.google.gerrit.server.CurrentUser;
|
||||
import com.google.gerrit.server.account.AccountResource;
|
||||
import com.google.gerrit.server.account.AccountsCollection;
|
||||
import com.google.gerrit.server.account.CreateAccount;
|
||||
import com.google.gerrit.server.account.QueryAccounts;
|
||||
import com.google.gerrit.server.permissions.GlobalPermission;
|
||||
import com.google.gerrit.server.permissions.PermissionBackend;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Provider;
|
||||
import com.google.inject.Singleton;
|
||||
import java.util.List;
|
||||
|
||||
@Singleton
|
||||
public class AccountsImpl implements Accounts {
|
||||
private final AccountsCollection accounts;
|
||||
private final AccountApiImpl.Factory api;
|
||||
private final PermissionBackend permissionBackend;
|
||||
private final Provider<CurrentUser> self;
|
||||
private final CreateAccount.Factory createAccount;
|
||||
private final Provider<QueryAccounts> queryAccountsProvider;
|
||||
|
||||
@Inject
|
||||
AccountsImpl(
|
||||
AccountsCollection accounts,
|
||||
AccountApiImpl.Factory api,
|
||||
PermissionBackend permissionBackend,
|
||||
Provider<CurrentUser> self,
|
||||
CreateAccount.Factory createAccount,
|
||||
Provider<QueryAccounts> queryAccountsProvider) {
|
||||
this.accounts = accounts;
|
||||
this.api = api;
|
||||
this.permissionBackend = permissionBackend;
|
||||
this.self = self;
|
||||
this.createAccount = createAccount;
|
||||
this.queryAccountsProvider = queryAccountsProvider;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AccountApi id(String id) throws RestApiException {
|
||||
try {
|
||||
return api.create(accounts.parse(TopLevelResource.INSTANCE, IdString.fromDecoded(id)));
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot parse change", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public AccountApi id(int id) throws RestApiException {
|
||||
return id(String.valueOf(id));
|
||||
}
|
||||
|
||||
@Override
|
||||
public AccountApi self() throws RestApiException {
|
||||
if (!self.get().isIdentifiedUser()) {
|
||||
throw new AuthException("Authentication required");
|
||||
}
|
||||
return api.create(new AccountResource(self.get().asIdentifiedUser()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public AccountApi create(String username) throws RestApiException {
|
||||
AccountInput in = new AccountInput();
|
||||
in.username = username;
|
||||
return create(in);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AccountApi create(AccountInput in) throws RestApiException {
|
||||
if (checkNotNull(in, "AccountInput").username == null) {
|
||||
throw new BadRequestException("AccountInput must specify username");
|
||||
}
|
||||
try {
|
||||
CreateAccount impl = createAccount.create(in.username);
|
||||
permissionBackend.user(self).checkAny(GlobalPermission.fromAnnotation(impl.getClass()));
|
||||
AccountInfo info = impl.apply(TopLevelResource.INSTANCE, in).value();
|
||||
return id(info._accountId);
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot create account " + in.username, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public SuggestAccountsRequest suggestAccounts() throws RestApiException {
|
||||
return new SuggestAccountsRequest() {
|
||||
@Override
|
||||
public List<AccountInfo> get() throws RestApiException {
|
||||
return AccountsImpl.this.suggestAccounts(this);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public SuggestAccountsRequest suggestAccounts(String query) throws RestApiException {
|
||||
return suggestAccounts().withQuery(query);
|
||||
}
|
||||
|
||||
private List<AccountInfo> suggestAccounts(SuggestAccountsRequest r) throws RestApiException {
|
||||
try {
|
||||
QueryAccounts myQueryAccounts = queryAccountsProvider.get();
|
||||
myQueryAccounts.setSuggest(true);
|
||||
myQueryAccounts.setQuery(r.getQuery());
|
||||
myQueryAccounts.setLimit(r.getLimit());
|
||||
return myQueryAccounts.apply(TopLevelResource.INSTANCE);
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot retrieve suggested accounts", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public QueryRequest query() throws RestApiException {
|
||||
return new QueryRequest() {
|
||||
@Override
|
||||
public List<AccountInfo> get() throws RestApiException {
|
||||
return AccountsImpl.this.query(this);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public QueryRequest query(String query) throws RestApiException {
|
||||
return query().withQuery(query);
|
||||
}
|
||||
|
||||
private List<AccountInfo> query(QueryRequest r) throws RestApiException {
|
||||
try {
|
||||
QueryAccounts myQueryAccounts = queryAccountsProvider.get();
|
||||
myQueryAccounts.setQuery(r.getQuery());
|
||||
myQueryAccounts.setLimit(r.getLimit());
|
||||
myQueryAccounts.setStart(r.getStart());
|
||||
for (ListAccountsOption option : r.getOptions()) {
|
||||
myQueryAccounts.addOption(option);
|
||||
}
|
||||
return myQueryAccounts.apply(TopLevelResource.INSTANCE);
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot retrieve suggested accounts", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
// Copyright (C) 2015 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.server.api.accounts;
|
||||
|
||||
import com.google.gerrit.extensions.api.accounts.GpgKeyApi;
|
||||
import com.google.gerrit.extensions.common.GpgKeyInfo;
|
||||
import com.google.gerrit.extensions.common.PushCertificateInfo;
|
||||
import com.google.gerrit.extensions.restapi.IdString;
|
||||
import com.google.gerrit.extensions.restapi.RestApiException;
|
||||
import com.google.gerrit.server.GpgException;
|
||||
import com.google.gerrit.server.IdentifiedUser;
|
||||
import com.google.gerrit.server.account.AccountResource;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public interface GpgApiAdapter {
|
||||
boolean isEnabled();
|
||||
|
||||
Map<String, GpgKeyInfo> listGpgKeys(AccountResource account)
|
||||
throws RestApiException, GpgException;
|
||||
|
||||
Map<String, GpgKeyInfo> putGpgKeys(AccountResource account, List<String> add, List<String> delete)
|
||||
throws RestApiException, GpgException;
|
||||
|
||||
GpgKeyApi gpgKey(AccountResource account, IdString idStr) throws RestApiException, GpgException;
|
||||
|
||||
PushCertificateInfo checkPushCertificate(String certStr, IdentifiedUser expectedUser)
|
||||
throws GpgException;
|
||||
}
|
||||
27
java/com/google/gerrit/server/api/accounts/Module.java
Normal file
27
java/com/google/gerrit/server/api/accounts/Module.java
Normal file
@@ -0,0 +1,27 @@
|
||||
// Copyright (C) 2014 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.server.api.accounts;
|
||||
|
||||
import com.google.gerrit.extensions.api.accounts.Accounts;
|
||||
import com.google.gerrit.extensions.config.FactoryModule;
|
||||
|
||||
public class Module extends FactoryModule {
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(Accounts.class).to(AccountsImpl.class);
|
||||
|
||||
factory(AccountApiImpl.Factory.class);
|
||||
}
|
||||
}
|
||||
710
java/com/google/gerrit/server/api/changes/ChangeApiImpl.java
Normal file
710
java/com/google/gerrit/server/api/changes/ChangeApiImpl.java
Normal file
@@ -0,0 +1,710 @@
|
||||
// Copyright (C) 2013 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.server.api.changes;
|
||||
|
||||
import static com.google.gerrit.server.api.ApiUtil.asRestApiException;
|
||||
|
||||
import com.google.gerrit.common.Nullable;
|
||||
import com.google.gerrit.extensions.api.changes.AbandonInput;
|
||||
import com.google.gerrit.extensions.api.changes.AddReviewerInput;
|
||||
import com.google.gerrit.extensions.api.changes.AddReviewerResult;
|
||||
import com.google.gerrit.extensions.api.changes.AssigneeInput;
|
||||
import com.google.gerrit.extensions.api.changes.ChangeApi;
|
||||
import com.google.gerrit.extensions.api.changes.ChangeEditApi;
|
||||
import com.google.gerrit.extensions.api.changes.Changes;
|
||||
import com.google.gerrit.extensions.api.changes.FixInput;
|
||||
import com.google.gerrit.extensions.api.changes.HashtagsInput;
|
||||
import com.google.gerrit.extensions.api.changes.IncludedInInfo;
|
||||
import com.google.gerrit.extensions.api.changes.MoveInput;
|
||||
import com.google.gerrit.extensions.api.changes.RebaseInput;
|
||||
import com.google.gerrit.extensions.api.changes.RestoreInput;
|
||||
import com.google.gerrit.extensions.api.changes.RevertInput;
|
||||
import com.google.gerrit.extensions.api.changes.ReviewerApi;
|
||||
import com.google.gerrit.extensions.api.changes.RevisionApi;
|
||||
import com.google.gerrit.extensions.api.changes.SubmittedTogetherInfo;
|
||||
import com.google.gerrit.extensions.api.changes.SubmittedTogetherOption;
|
||||
import com.google.gerrit.extensions.api.changes.TopicInput;
|
||||
import com.google.gerrit.extensions.client.ListChangesOption;
|
||||
import com.google.gerrit.extensions.common.AccountInfo;
|
||||
import com.google.gerrit.extensions.common.ChangeInfo;
|
||||
import com.google.gerrit.extensions.common.CommentInfo;
|
||||
import com.google.gerrit.extensions.common.CommitMessageInput;
|
||||
import com.google.gerrit.extensions.common.EditInfo;
|
||||
import com.google.gerrit.extensions.common.Input;
|
||||
import com.google.gerrit.extensions.common.MergePatchSetInput;
|
||||
import com.google.gerrit.extensions.common.PureRevertInfo;
|
||||
import com.google.gerrit.extensions.common.RobotCommentInfo;
|
||||
import com.google.gerrit.extensions.common.SuggestedReviewerInfo;
|
||||
import com.google.gerrit.extensions.restapi.IdString;
|
||||
import com.google.gerrit.extensions.restapi.Response;
|
||||
import com.google.gerrit.extensions.restapi.RestApiException;
|
||||
import com.google.gerrit.server.StarredChangesUtil;
|
||||
import com.google.gerrit.server.StarredChangesUtil.IllegalLabelException;
|
||||
import com.google.gerrit.server.change.Abandon;
|
||||
import com.google.gerrit.server.change.ChangeIncludedIn;
|
||||
import com.google.gerrit.server.change.ChangeJson;
|
||||
import com.google.gerrit.server.change.ChangeResource;
|
||||
import com.google.gerrit.server.change.Check;
|
||||
import com.google.gerrit.server.change.CreateMergePatchSet;
|
||||
import com.google.gerrit.server.change.DeleteAssignee;
|
||||
import com.google.gerrit.server.change.DeleteChange;
|
||||
import com.google.gerrit.server.change.DeletePrivate;
|
||||
import com.google.gerrit.server.change.GetAssignee;
|
||||
import com.google.gerrit.server.change.GetHashtags;
|
||||
import com.google.gerrit.server.change.GetPastAssignees;
|
||||
import com.google.gerrit.server.change.GetPureRevert;
|
||||
import com.google.gerrit.server.change.GetTopic;
|
||||
import com.google.gerrit.server.change.Ignore;
|
||||
import com.google.gerrit.server.change.Index;
|
||||
import com.google.gerrit.server.change.ListChangeComments;
|
||||
import com.google.gerrit.server.change.ListChangeDrafts;
|
||||
import com.google.gerrit.server.change.ListChangeRobotComments;
|
||||
import com.google.gerrit.server.change.MarkAsReviewed;
|
||||
import com.google.gerrit.server.change.MarkAsUnreviewed;
|
||||
import com.google.gerrit.server.change.Move;
|
||||
import com.google.gerrit.server.change.PostHashtags;
|
||||
import com.google.gerrit.server.change.PostPrivate;
|
||||
import com.google.gerrit.server.change.PostReviewers;
|
||||
import com.google.gerrit.server.change.PutAssignee;
|
||||
import com.google.gerrit.server.change.PutMessage;
|
||||
import com.google.gerrit.server.change.PutTopic;
|
||||
import com.google.gerrit.server.change.Rebase;
|
||||
import com.google.gerrit.server.change.Restore;
|
||||
import com.google.gerrit.server.change.Revert;
|
||||
import com.google.gerrit.server.change.Reviewers;
|
||||
import com.google.gerrit.server.change.Revisions;
|
||||
import com.google.gerrit.server.change.SetPrivateOp;
|
||||
import com.google.gerrit.server.change.SetReadyForReview;
|
||||
import com.google.gerrit.server.change.SetWorkInProgress;
|
||||
import com.google.gerrit.server.change.SubmittedTogether;
|
||||
import com.google.gerrit.server.change.SuggestChangeReviewers;
|
||||
import com.google.gerrit.server.change.Unignore;
|
||||
import com.google.gerrit.server.change.WorkInProgressOp;
|
||||
import com.google.gwtorm.server.OrmException;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Provider;
|
||||
import com.google.inject.assistedinject.Assisted;
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
class ChangeApiImpl implements ChangeApi {
|
||||
interface Factory {
|
||||
ChangeApiImpl create(ChangeResource change);
|
||||
}
|
||||
|
||||
private final Changes changeApi;
|
||||
private final Reviewers reviewers;
|
||||
private final Revisions revisions;
|
||||
private final ReviewerApiImpl.Factory reviewerApi;
|
||||
private final RevisionApiImpl.Factory revisionApi;
|
||||
private final SuggestChangeReviewers suggestReviewers;
|
||||
private final ChangeResource change;
|
||||
private final Abandon abandon;
|
||||
private final Revert revert;
|
||||
private final Restore restore;
|
||||
private final CreateMergePatchSet updateByMerge;
|
||||
private final Provider<SubmittedTogether> submittedTogether;
|
||||
private final Rebase.CurrentRevision rebase;
|
||||
private final DeleteChange deleteChange;
|
||||
private final GetTopic getTopic;
|
||||
private final PutTopic putTopic;
|
||||
private final ChangeIncludedIn includedIn;
|
||||
private final PostReviewers postReviewers;
|
||||
private final ChangeJson.Factory changeJson;
|
||||
private final PostHashtags postHashtags;
|
||||
private final GetHashtags getHashtags;
|
||||
private final PutAssignee putAssignee;
|
||||
private final GetAssignee getAssignee;
|
||||
private final GetPastAssignees getPastAssignees;
|
||||
private final DeleteAssignee deleteAssignee;
|
||||
private final ListChangeComments listComments;
|
||||
private final ListChangeRobotComments listChangeRobotComments;
|
||||
private final ListChangeDrafts listDrafts;
|
||||
private final ChangeEditApiImpl.Factory changeEditApi;
|
||||
private final Check check;
|
||||
private final Index index;
|
||||
private final Move move;
|
||||
private final PostPrivate postPrivate;
|
||||
private final DeletePrivate deletePrivate;
|
||||
private final Ignore ignore;
|
||||
private final Unignore unignore;
|
||||
private final MarkAsReviewed markAsReviewed;
|
||||
private final MarkAsUnreviewed markAsUnreviewed;
|
||||
private final SetWorkInProgress setWip;
|
||||
private final SetReadyForReview setReady;
|
||||
private final PutMessage putMessage;
|
||||
private final GetPureRevert getPureRevert;
|
||||
private final StarredChangesUtil stars;
|
||||
|
||||
@Inject
|
||||
ChangeApiImpl(
|
||||
Changes changeApi,
|
||||
Reviewers reviewers,
|
||||
Revisions revisions,
|
||||
ReviewerApiImpl.Factory reviewerApi,
|
||||
RevisionApiImpl.Factory revisionApi,
|
||||
SuggestChangeReviewers suggestReviewers,
|
||||
Abandon abandon,
|
||||
Revert revert,
|
||||
Restore restore,
|
||||
CreateMergePatchSet updateByMerge,
|
||||
Provider<SubmittedTogether> submittedTogether,
|
||||
Rebase.CurrentRevision rebase,
|
||||
DeleteChange deleteChange,
|
||||
GetTopic getTopic,
|
||||
PutTopic putTopic,
|
||||
ChangeIncludedIn includedIn,
|
||||
PostReviewers postReviewers,
|
||||
ChangeJson.Factory changeJson,
|
||||
PostHashtags postHashtags,
|
||||
GetHashtags getHashtags,
|
||||
PutAssignee putAssignee,
|
||||
GetAssignee getAssignee,
|
||||
GetPastAssignees getPastAssignees,
|
||||
DeleteAssignee deleteAssignee,
|
||||
ListChangeComments listComments,
|
||||
ListChangeRobotComments listChangeRobotComments,
|
||||
ListChangeDrafts listDrafts,
|
||||
ChangeEditApiImpl.Factory changeEditApi,
|
||||
Check check,
|
||||
Index index,
|
||||
Move move,
|
||||
PostPrivate postPrivate,
|
||||
DeletePrivate deletePrivate,
|
||||
Ignore ignore,
|
||||
Unignore unignore,
|
||||
MarkAsReviewed markAsReviewed,
|
||||
MarkAsUnreviewed markAsUnreviewed,
|
||||
SetWorkInProgress setWip,
|
||||
SetReadyForReview setReady,
|
||||
PutMessage putMessage,
|
||||
GetPureRevert getPureRevert,
|
||||
StarredChangesUtil stars,
|
||||
@Assisted ChangeResource change) {
|
||||
this.changeApi = changeApi;
|
||||
this.revert = revert;
|
||||
this.reviewers = reviewers;
|
||||
this.revisions = revisions;
|
||||
this.reviewerApi = reviewerApi;
|
||||
this.revisionApi = revisionApi;
|
||||
this.suggestReviewers = suggestReviewers;
|
||||
this.abandon = abandon;
|
||||
this.restore = restore;
|
||||
this.updateByMerge = updateByMerge;
|
||||
this.submittedTogether = submittedTogether;
|
||||
this.rebase = rebase;
|
||||
this.deleteChange = deleteChange;
|
||||
this.getTopic = getTopic;
|
||||
this.putTopic = putTopic;
|
||||
this.includedIn = includedIn;
|
||||
this.postReviewers = postReviewers;
|
||||
this.changeJson = changeJson;
|
||||
this.postHashtags = postHashtags;
|
||||
this.getHashtags = getHashtags;
|
||||
this.putAssignee = putAssignee;
|
||||
this.getAssignee = getAssignee;
|
||||
this.getPastAssignees = getPastAssignees;
|
||||
this.deleteAssignee = deleteAssignee;
|
||||
this.listComments = listComments;
|
||||
this.listChangeRobotComments = listChangeRobotComments;
|
||||
this.listDrafts = listDrafts;
|
||||
this.changeEditApi = changeEditApi;
|
||||
this.check = check;
|
||||
this.index = index;
|
||||
this.move = move;
|
||||
this.postPrivate = postPrivate;
|
||||
this.deletePrivate = deletePrivate;
|
||||
this.ignore = ignore;
|
||||
this.unignore = unignore;
|
||||
this.markAsReviewed = markAsReviewed;
|
||||
this.markAsUnreviewed = markAsUnreviewed;
|
||||
this.setWip = setWip;
|
||||
this.setReady = setReady;
|
||||
this.putMessage = putMessage;
|
||||
this.getPureRevert = getPureRevert;
|
||||
this.stars = stars;
|
||||
this.change = change;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String id() {
|
||||
return Integer.toString(change.getId().get());
|
||||
}
|
||||
|
||||
@Override
|
||||
public RevisionApi current() throws RestApiException {
|
||||
return revision("current");
|
||||
}
|
||||
|
||||
@Override
|
||||
public RevisionApi revision(int id) throws RestApiException {
|
||||
return revision(String.valueOf(id));
|
||||
}
|
||||
|
||||
@Override
|
||||
public RevisionApi revision(String id) throws RestApiException {
|
||||
try {
|
||||
return revisionApi.create(revisions.parse(change, IdString.fromDecoded(id)));
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot parse revision", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ReviewerApi reviewer(String id) throws RestApiException {
|
||||
try {
|
||||
return reviewerApi.create(reviewers.parse(change, IdString.fromDecoded(id)));
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot parse reviewer", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void abandon() throws RestApiException {
|
||||
abandon(new AbandonInput());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void abandon(AbandonInput in) throws RestApiException {
|
||||
try {
|
||||
abandon.apply(change, in);
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot abandon change", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void restore() throws RestApiException {
|
||||
restore(new RestoreInput());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void restore(RestoreInput in) throws RestApiException {
|
||||
try {
|
||||
restore.apply(change, in);
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot restore change", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void move(String destination) throws RestApiException {
|
||||
MoveInput in = new MoveInput();
|
||||
in.destinationBranch = destination;
|
||||
move(in);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void move(MoveInput in) throws RestApiException {
|
||||
try {
|
||||
move.apply(change, in);
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot move change", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPrivate(boolean value, @Nullable String message) throws RestApiException {
|
||||
try {
|
||||
SetPrivateOp.Input input = new SetPrivateOp.Input(message);
|
||||
if (value) {
|
||||
postPrivate.apply(change, input);
|
||||
} else {
|
||||
deletePrivate.apply(change, input);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot change private status", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setWorkInProgress(String message) throws RestApiException {
|
||||
try {
|
||||
setWip.apply(change, new WorkInProgressOp.Input(message));
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot set work in progress state", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setReadyForReview(String message) throws RestApiException {
|
||||
try {
|
||||
setReady.apply(change, new WorkInProgressOp.Input(message));
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot set ready for review state", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChangeApi revert() throws RestApiException {
|
||||
return revert(new RevertInput());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChangeApi revert(RevertInput in) throws RestApiException {
|
||||
try {
|
||||
return changeApi.id(revert.apply(change, in)._number);
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot revert change", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChangeInfo createMergePatchSet(MergePatchSetInput in) throws RestApiException {
|
||||
try {
|
||||
return updateByMerge.apply(change, in).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot update change by merge", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ChangeInfo> submittedTogether() throws RestApiException {
|
||||
SubmittedTogetherInfo info =
|
||||
submittedTogether(
|
||||
EnumSet.noneOf(ListChangesOption.class), EnumSet.noneOf(SubmittedTogetherOption.class));
|
||||
return info.changes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SubmittedTogetherInfo submittedTogether(EnumSet<SubmittedTogetherOption> options)
|
||||
throws RestApiException {
|
||||
return submittedTogether(EnumSet.noneOf(ListChangesOption.class), options);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SubmittedTogetherInfo submittedTogether(
|
||||
EnumSet<ListChangesOption> listOptions, EnumSet<SubmittedTogetherOption> submitOptions)
|
||||
throws RestApiException {
|
||||
try {
|
||||
return submittedTogether
|
||||
.get()
|
||||
.addListChangesOption(listOptions)
|
||||
.addSubmittedTogetherOption(submitOptions)
|
||||
.applyInfo(change);
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot query submittedTogether", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
@Override
|
||||
public void publish() throws RestApiException {
|
||||
throw new UnsupportedOperationException("draft workflow is discontinued");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void rebase() throws RestApiException {
|
||||
rebase(new RebaseInput());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void rebase(RebaseInput in) throws RestApiException {
|
||||
try {
|
||||
rebase.apply(change, in);
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot rebase change", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete() throws RestApiException {
|
||||
try {
|
||||
deleteChange.apply(change, null);
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot delete change", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String topic() throws RestApiException {
|
||||
return getTopic.apply(change);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void topic(String topic) throws RestApiException {
|
||||
TopicInput in = new TopicInput();
|
||||
in.topic = topic;
|
||||
try {
|
||||
putTopic.apply(change, in);
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot set topic", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public IncludedInInfo includedIn() throws RestApiException {
|
||||
try {
|
||||
return includedIn.apply(change);
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Could not extract IncludedIn data", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public AddReviewerResult addReviewer(String reviewer) throws RestApiException {
|
||||
AddReviewerInput in = new AddReviewerInput();
|
||||
in.reviewer = reviewer;
|
||||
return addReviewer(in);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AddReviewerResult addReviewer(AddReviewerInput in) throws RestApiException {
|
||||
try {
|
||||
return postReviewers.apply(change, in);
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot add change reviewer", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public SuggestedReviewersRequest suggestReviewers() throws RestApiException {
|
||||
return new SuggestedReviewersRequest() {
|
||||
@Override
|
||||
public List<SuggestedReviewerInfo> get() throws RestApiException {
|
||||
return ChangeApiImpl.this.suggestReviewers(this);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public SuggestedReviewersRequest suggestReviewers(String query) throws RestApiException {
|
||||
return suggestReviewers().withQuery(query);
|
||||
}
|
||||
|
||||
private List<SuggestedReviewerInfo> suggestReviewers(SuggestedReviewersRequest r)
|
||||
throws RestApiException {
|
||||
try {
|
||||
suggestReviewers.setQuery(r.getQuery());
|
||||
suggestReviewers.setLimit(r.getLimit());
|
||||
return suggestReviewers.apply(change);
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot retrieve suggested reviewers", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChangeInfo get(EnumSet<ListChangesOption> s) throws RestApiException {
|
||||
try {
|
||||
return changeJson.create(s).format(change);
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot retrieve change", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChangeInfo get() throws RestApiException {
|
||||
return get(EnumSet.complementOf(EnumSet.of(ListChangesOption.CHECK)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public EditInfo getEdit() throws RestApiException {
|
||||
return edit().get().orElse(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChangeEditApi edit() throws RestApiException {
|
||||
return changeEditApi.create(change);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMessage(String msg) throws RestApiException {
|
||||
CommitMessageInput in = new CommitMessageInput();
|
||||
in.message = msg;
|
||||
setMessage(in);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMessage(CommitMessageInput in) throws RestApiException {
|
||||
try {
|
||||
putMessage.apply(change, in);
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot edit commit message", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChangeInfo info() throws RestApiException {
|
||||
return get(EnumSet.noneOf(ListChangesOption.class));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setHashtags(HashtagsInput input) throws RestApiException {
|
||||
try {
|
||||
postHashtags.apply(change, input);
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot post hashtags", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getHashtags() throws RestApiException {
|
||||
try {
|
||||
return getHashtags.apply(change).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot get hashtags", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public AccountInfo setAssignee(AssigneeInput input) throws RestApiException {
|
||||
try {
|
||||
return putAssignee.apply(change, input);
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot set assignee", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public AccountInfo getAssignee() throws RestApiException {
|
||||
try {
|
||||
Response<AccountInfo> r = getAssignee.apply(change);
|
||||
return r.isNone() ? null : r.value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot get assignee", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<AccountInfo> getPastAssignees() throws RestApiException {
|
||||
try {
|
||||
return getPastAssignees.apply(change).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot get past assignees", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public AccountInfo deleteAssignee() throws RestApiException {
|
||||
try {
|
||||
Response<AccountInfo> r = deleteAssignee.apply(change, null);
|
||||
return r.isNone() ? null : r.value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot delete assignee", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, List<CommentInfo>> comments() throws RestApiException {
|
||||
try {
|
||||
return listComments.apply(change);
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot get comments", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, List<RobotCommentInfo>> robotComments() throws RestApiException {
|
||||
try {
|
||||
return listChangeRobotComments.apply(change);
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot get robot comments", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, List<CommentInfo>> drafts() throws RestApiException {
|
||||
try {
|
||||
return listDrafts.apply(change);
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot get drafts", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChangeInfo check() throws RestApiException {
|
||||
try {
|
||||
return check.apply(change).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot check change", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChangeInfo check(FixInput fix) throws RestApiException {
|
||||
try {
|
||||
// TODO(dborowitz): Convert to RetryingRestModifyView. Needs to plumb BatchUpdate.Factory into
|
||||
// ConsistencyChecker.
|
||||
return check.apply(change, fix).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot check change", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void index() throws RestApiException {
|
||||
try {
|
||||
index.apply(change, new Input());
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot index change", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void ignore(boolean ignore) throws RestApiException {
|
||||
// TODO(dborowitz): Convert to RetryingRestModifyView. Needs to plumb BatchUpdate.Factory into
|
||||
// StarredChangesUtil.
|
||||
try {
|
||||
if (ignore) {
|
||||
this.ignore.apply(change, new Input());
|
||||
} else {
|
||||
unignore.apply(change, new Input());
|
||||
}
|
||||
} catch (OrmException | IllegalLabelException e) {
|
||||
throw asRestApiException("Cannot ignore change", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean ignored() throws RestApiException {
|
||||
try {
|
||||
return stars.isIgnored(change);
|
||||
} catch (OrmException e) {
|
||||
throw asRestApiException("Cannot check if ignored", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void markAsReviewed(boolean reviewed) throws RestApiException {
|
||||
// TODO(dborowitz): Convert to RetryingRestModifyView. Needs to plumb BatchUpdate.Factory into
|
||||
// StarredChangesUtil.
|
||||
try {
|
||||
if (reviewed) {
|
||||
markAsReviewed.apply(change, new Input());
|
||||
} else {
|
||||
markAsUnreviewed.apply(change, new Input());
|
||||
}
|
||||
} catch (OrmException | IllegalLabelException e) {
|
||||
throw asRestApiException(
|
||||
"Cannot mark change as " + (reviewed ? "reviewed" : "unreviewed"), e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public PureRevertInfo pureRevert() throws RestApiException {
|
||||
return pureRevert(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PureRevertInfo pureRevert(@Nullable String claimedOriginal) throws RestApiException {
|
||||
try {
|
||||
return getPureRevert.setClaimedOriginal(claimedOriginal).apply(change);
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot compute pure revert", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
217
java/com/google/gerrit/server/api/changes/ChangeEditApiImpl.java
Normal file
217
java/com/google/gerrit/server/api/changes/ChangeEditApiImpl.java
Normal file
@@ -0,0 +1,217 @@
|
||||
// Copyright (C) 2017 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.server.api.changes;
|
||||
|
||||
import static com.google.gerrit.server.api.ApiUtil.asRestApiException;
|
||||
|
||||
import com.google.gerrit.extensions.api.changes.ChangeEditApi;
|
||||
import com.google.gerrit.extensions.api.changes.PublishChangeEditInput;
|
||||
import com.google.gerrit.extensions.common.EditInfo;
|
||||
import com.google.gerrit.extensions.common.Input;
|
||||
import com.google.gerrit.extensions.restapi.AuthException;
|
||||
import com.google.gerrit.extensions.restapi.BinaryResult;
|
||||
import com.google.gerrit.extensions.restapi.IdString;
|
||||
import com.google.gerrit.extensions.restapi.RawInput;
|
||||
import com.google.gerrit.extensions.restapi.ResourceNotFoundException;
|
||||
import com.google.gerrit.extensions.restapi.Response;
|
||||
import com.google.gerrit.extensions.restapi.RestApiException;
|
||||
import com.google.gerrit.server.change.ChangeEditResource;
|
||||
import com.google.gerrit.server.change.ChangeEdits;
|
||||
import com.google.gerrit.server.change.ChangeResource;
|
||||
import com.google.gerrit.server.change.DeleteChangeEdit;
|
||||
import com.google.gerrit.server.change.PublishChangeEdit;
|
||||
import com.google.gerrit.server.change.RebaseChangeEdit;
|
||||
import com.google.gwtorm.server.OrmException;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.assistedinject.Assisted;
|
||||
import java.io.IOException;
|
||||
import java.util.Optional;
|
||||
|
||||
public class ChangeEditApiImpl implements ChangeEditApi {
|
||||
interface Factory {
|
||||
ChangeEditApiImpl create(ChangeResource changeResource);
|
||||
}
|
||||
|
||||
private final ChangeEdits.Detail editDetail;
|
||||
private final ChangeEdits.Post changeEditsPost;
|
||||
private final DeleteChangeEdit deleteChangeEdit;
|
||||
private final RebaseChangeEdit.Rebase rebaseChangeEdit;
|
||||
private final PublishChangeEdit.Publish publishChangeEdit;
|
||||
private final ChangeEdits.Get changeEditsGet;
|
||||
private final ChangeEdits.Put changeEditsPut;
|
||||
private final ChangeEdits.DeleteContent changeEditDeleteContent;
|
||||
private final ChangeEdits.GetMessage getChangeEditCommitMessage;
|
||||
private final ChangeEdits.EditMessage modifyChangeEditCommitMessage;
|
||||
private final ChangeEdits changeEdits;
|
||||
private final ChangeResource changeResource;
|
||||
|
||||
@Inject
|
||||
public ChangeEditApiImpl(
|
||||
ChangeEdits.Detail editDetail,
|
||||
ChangeEdits.Post changeEditsPost,
|
||||
DeleteChangeEdit deleteChangeEdit,
|
||||
RebaseChangeEdit.Rebase rebaseChangeEdit,
|
||||
PublishChangeEdit.Publish publishChangeEdit,
|
||||
ChangeEdits.Get changeEditsGet,
|
||||
ChangeEdits.Put changeEditsPut,
|
||||
ChangeEdits.DeleteContent changeEditDeleteContent,
|
||||
ChangeEdits.GetMessage getChangeEditCommitMessage,
|
||||
ChangeEdits.EditMessage modifyChangeEditCommitMessage,
|
||||
ChangeEdits changeEdits,
|
||||
@Assisted ChangeResource changeResource) {
|
||||
this.editDetail = editDetail;
|
||||
this.changeEditsPost = changeEditsPost;
|
||||
this.deleteChangeEdit = deleteChangeEdit;
|
||||
this.rebaseChangeEdit = rebaseChangeEdit;
|
||||
this.publishChangeEdit = publishChangeEdit;
|
||||
this.changeEditsGet = changeEditsGet;
|
||||
this.changeEditsPut = changeEditsPut;
|
||||
this.changeEditDeleteContent = changeEditDeleteContent;
|
||||
this.getChangeEditCommitMessage = getChangeEditCommitMessage;
|
||||
this.modifyChangeEditCommitMessage = modifyChangeEditCommitMessage;
|
||||
this.changeEdits = changeEdits;
|
||||
this.changeResource = changeResource;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<EditInfo> get() throws RestApiException {
|
||||
try {
|
||||
Response<EditInfo> edit = editDetail.apply(changeResource);
|
||||
return edit.isNone() ? Optional.empty() : Optional.of(edit.value());
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot retrieve change edit", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void create() throws RestApiException {
|
||||
try {
|
||||
changeEditsPost.apply(changeResource, null);
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot create change edit", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete() throws RestApiException {
|
||||
try {
|
||||
deleteChangeEdit.apply(changeResource, new Input());
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot delete change edit", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void rebase() throws RestApiException {
|
||||
try {
|
||||
rebaseChangeEdit.apply(changeResource, null);
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot rebase change edit", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void publish() throws RestApiException {
|
||||
publish(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void publish(PublishChangeEditInput publishChangeEditInput) throws RestApiException {
|
||||
try {
|
||||
publishChangeEdit.apply(changeResource, publishChangeEditInput);
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot publish change edit", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<BinaryResult> getFile(String filePath) throws RestApiException {
|
||||
try {
|
||||
ChangeEditResource changeEditResource = getChangeEditResource(filePath);
|
||||
Response<BinaryResult> fileResponse = changeEditsGet.apply(changeEditResource);
|
||||
return fileResponse.isNone() ? Optional.empty() : Optional.of(fileResponse.value());
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot retrieve file of change edit", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renameFile(String oldFilePath, String newFilePath) throws RestApiException {
|
||||
try {
|
||||
ChangeEdits.Post.Input renameInput = new ChangeEdits.Post.Input();
|
||||
renameInput.oldPath = oldFilePath;
|
||||
renameInput.newPath = newFilePath;
|
||||
changeEditsPost.apply(changeResource, renameInput);
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot rename file of change edit", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void restoreFile(String filePath) throws RestApiException {
|
||||
try {
|
||||
ChangeEdits.Post.Input restoreInput = new ChangeEdits.Post.Input();
|
||||
restoreInput.restorePath = filePath;
|
||||
changeEditsPost.apply(changeResource, restoreInput);
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot restore file of change edit", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void modifyFile(String filePath, RawInput newContent) throws RestApiException {
|
||||
try {
|
||||
changeEditsPut.apply(changeResource, filePath, newContent);
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot modify file of change edit", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteFile(String filePath) throws RestApiException {
|
||||
try {
|
||||
changeEditDeleteContent.apply(changeResource, filePath);
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot delete file of change edit", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCommitMessage() throws RestApiException {
|
||||
try {
|
||||
try (BinaryResult binaryResult = getChangeEditCommitMessage.apply(changeResource)) {
|
||||
return binaryResult.asString();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot get commit message of change edit", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void modifyCommitMessage(String newCommitMessage) throws RestApiException {
|
||||
ChangeEdits.EditMessage.Input input = new ChangeEdits.EditMessage.Input();
|
||||
input.message = newCommitMessage;
|
||||
try {
|
||||
modifyChangeEditCommitMessage.apply(changeResource, input);
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot modify commit message of change edit", e);
|
||||
}
|
||||
}
|
||||
|
||||
private ChangeEditResource getChangeEditResource(String filePath)
|
||||
throws ResourceNotFoundException, AuthException, IOException, OrmException {
|
||||
return changeEdits.parse(changeResource, IdString.fromDecoded(filePath));
|
||||
}
|
||||
}
|
||||
141
java/com/google/gerrit/server/api/changes/ChangesImpl.java
Normal file
141
java/com/google/gerrit/server/api/changes/ChangesImpl.java
Normal file
@@ -0,0 +1,141 @@
|
||||
// Copyright (C) 2013 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.server.api.changes;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static com.google.common.base.Preconditions.checkState;
|
||||
import static com.google.gerrit.server.api.ApiUtil.asRestApiException;
|
||||
|
||||
import com.google.common.base.Joiner;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.gerrit.extensions.api.changes.ChangeApi;
|
||||
import com.google.gerrit.extensions.api.changes.Changes;
|
||||
import com.google.gerrit.extensions.client.ListChangesOption;
|
||||
import com.google.gerrit.extensions.common.ChangeInfo;
|
||||
import com.google.gerrit.extensions.common.ChangeInput;
|
||||
import com.google.gerrit.extensions.restapi.IdString;
|
||||
import com.google.gerrit.extensions.restapi.RestApiException;
|
||||
import com.google.gerrit.extensions.restapi.TopLevelResource;
|
||||
import com.google.gerrit.extensions.restapi.Url;
|
||||
import com.google.gerrit.reviewdb.client.Change;
|
||||
import com.google.gerrit.server.change.ChangesCollection;
|
||||
import com.google.gerrit.server.change.CreateChange;
|
||||
import com.google.gerrit.server.query.change.QueryChanges;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Provider;
|
||||
import com.google.inject.Singleton;
|
||||
import java.util.List;
|
||||
|
||||
@Singleton
|
||||
class ChangesImpl implements Changes {
|
||||
private final ChangesCollection changes;
|
||||
private final ChangeApiImpl.Factory api;
|
||||
private final CreateChange createChange;
|
||||
private final Provider<QueryChanges> queryProvider;
|
||||
|
||||
@Inject
|
||||
ChangesImpl(
|
||||
ChangesCollection changes,
|
||||
ChangeApiImpl.Factory api,
|
||||
CreateChange createChange,
|
||||
Provider<QueryChanges> queryProvider) {
|
||||
this.changes = changes;
|
||||
this.api = api;
|
||||
this.createChange = createChange;
|
||||
this.queryProvider = queryProvider;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChangeApi id(int id) throws RestApiException {
|
||||
return id(String.valueOf(id));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChangeApi id(String project, String branch, String id) throws RestApiException {
|
||||
return id(
|
||||
Joiner.on('~')
|
||||
.join(ImmutableList.of(Url.encode(project), Url.encode(branch), Url.encode(id))));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChangeApi id(String id) throws RestApiException {
|
||||
try {
|
||||
return api.create(changes.parse(TopLevelResource.INSTANCE, IdString.fromUrl(id)));
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot parse change", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChangeApi id(String project, int id) throws RestApiException {
|
||||
return id(
|
||||
Joiner.on('~').join(ImmutableList.of(Url.encode(project), Url.encode(String.valueOf(id)))));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChangeApi create(ChangeInput in) throws RestApiException {
|
||||
try {
|
||||
ChangeInfo out = createChange.apply(TopLevelResource.INSTANCE, in).value();
|
||||
return api.create(changes.parse(new Change.Id(out._number)));
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot create change", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public QueryRequest query() {
|
||||
return new QueryRequest() {
|
||||
@Override
|
||||
public List<ChangeInfo> get() throws RestApiException {
|
||||
return ChangesImpl.this.get(this);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public QueryRequest query(String query) {
|
||||
return query().withQuery(query);
|
||||
}
|
||||
|
||||
private List<ChangeInfo> get(QueryRequest q) throws RestApiException {
|
||||
QueryChanges qc = queryProvider.get();
|
||||
if (q.getQuery() != null) {
|
||||
qc.addQuery(q.getQuery());
|
||||
}
|
||||
qc.setLimit(q.getLimit());
|
||||
qc.setStart(q.getStart());
|
||||
for (ListChangesOption option : q.getOptions()) {
|
||||
qc.addOption(option);
|
||||
}
|
||||
|
||||
try {
|
||||
List<?> result = qc.apply(TopLevelResource.INSTANCE);
|
||||
if (result.isEmpty()) {
|
||||
return ImmutableList.of();
|
||||
}
|
||||
|
||||
// Check type safety of result; the extension API should be safer than the
|
||||
// REST API in this case, since it's intended to be used in Java.
|
||||
Object first = checkNotNull(result.iterator().next());
|
||||
checkState(first instanceof ChangeInfo);
|
||||
@SuppressWarnings("unchecked")
|
||||
List<ChangeInfo> infos = (List<ChangeInfo>) result;
|
||||
|
||||
return ImmutableList.copyOf(infos);
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot query changes", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
// Copyright (C) 2014 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.server.api.changes;
|
||||
|
||||
import static com.google.gerrit.server.api.ApiUtil.asRestApiException;
|
||||
|
||||
import com.google.gerrit.extensions.api.changes.CommentApi;
|
||||
import com.google.gerrit.extensions.api.changes.DeleteCommentInput;
|
||||
import com.google.gerrit.extensions.common.CommentInfo;
|
||||
import com.google.gerrit.extensions.restapi.RestApiException;
|
||||
import com.google.gerrit.server.change.CommentResource;
|
||||
import com.google.gerrit.server.change.DeleteComment;
|
||||
import com.google.gerrit.server.change.GetComment;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.assistedinject.Assisted;
|
||||
|
||||
class CommentApiImpl implements CommentApi {
|
||||
interface Factory {
|
||||
CommentApiImpl create(CommentResource c);
|
||||
}
|
||||
|
||||
private final GetComment getComment;
|
||||
private final DeleteComment deleteComment;
|
||||
private final CommentResource comment;
|
||||
|
||||
@Inject
|
||||
CommentApiImpl(
|
||||
GetComment getComment, DeleteComment deleteComment, @Assisted CommentResource comment) {
|
||||
this.getComment = getComment;
|
||||
this.deleteComment = deleteComment;
|
||||
this.comment = comment;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommentInfo get() throws RestApiException {
|
||||
try {
|
||||
return getComment.apply(comment);
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot retrieve comment", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommentInfo delete(DeleteCommentInput input) throws RestApiException {
|
||||
try {
|
||||
return deleteComment.apply(comment, input);
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot delete comment", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
85
java/com/google/gerrit/server/api/changes/DraftApiImpl.java
Normal file
85
java/com/google/gerrit/server/api/changes/DraftApiImpl.java
Normal file
@@ -0,0 +1,85 @@
|
||||
// Copyright (C) 2014 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.server.api.changes;
|
||||
|
||||
import static com.google.gerrit.server.api.ApiUtil.asRestApiException;
|
||||
|
||||
import com.google.gerrit.extensions.api.changes.DeleteCommentInput;
|
||||
import com.google.gerrit.extensions.api.changes.DraftApi;
|
||||
import com.google.gerrit.extensions.api.changes.DraftInput;
|
||||
import com.google.gerrit.extensions.common.CommentInfo;
|
||||
import com.google.gerrit.extensions.restapi.NotImplementedException;
|
||||
import com.google.gerrit.extensions.restapi.RestApiException;
|
||||
import com.google.gerrit.server.change.DeleteDraftComment;
|
||||
import com.google.gerrit.server.change.DraftCommentResource;
|
||||
import com.google.gerrit.server.change.GetDraftComment;
|
||||
import com.google.gerrit.server.change.PutDraftComment;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.assistedinject.Assisted;
|
||||
|
||||
class DraftApiImpl implements DraftApi {
|
||||
interface Factory {
|
||||
DraftApiImpl create(DraftCommentResource d);
|
||||
}
|
||||
|
||||
private final DeleteDraftComment deleteDraft;
|
||||
private final GetDraftComment getDraft;
|
||||
private final PutDraftComment putDraft;
|
||||
private final DraftCommentResource draft;
|
||||
|
||||
@Inject
|
||||
DraftApiImpl(
|
||||
DeleteDraftComment deleteDraft,
|
||||
GetDraftComment getDraft,
|
||||
PutDraftComment putDraft,
|
||||
@Assisted DraftCommentResource draft) {
|
||||
this.deleteDraft = deleteDraft;
|
||||
this.getDraft = getDraft;
|
||||
this.putDraft = putDraft;
|
||||
this.draft = draft;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommentInfo get() throws RestApiException {
|
||||
try {
|
||||
return getDraft.apply(draft);
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot retrieve draft", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommentInfo update(DraftInput in) throws RestApiException {
|
||||
try {
|
||||
return putDraft.apply(draft, in).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot update draft", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete() throws RestApiException {
|
||||
try {
|
||||
deleteDraft.apply(draft, null);
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot delete draft", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommentInfo delete(DeleteCommentInput input) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
111
java/com/google/gerrit/server/api/changes/FileApiImpl.java
Normal file
111
java/com/google/gerrit/server/api/changes/FileApiImpl.java
Normal file
@@ -0,0 +1,111 @@
|
||||
// Copyright (C) 2014 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.server.api.changes;
|
||||
|
||||
import static com.google.gerrit.server.api.ApiUtil.asRestApiException;
|
||||
|
||||
import com.google.gerrit.extensions.api.changes.FileApi;
|
||||
import com.google.gerrit.extensions.common.DiffInfo;
|
||||
import com.google.gerrit.extensions.restapi.BinaryResult;
|
||||
import com.google.gerrit.extensions.restapi.RestApiException;
|
||||
import com.google.gerrit.server.change.FileResource;
|
||||
import com.google.gerrit.server.change.GetContent;
|
||||
import com.google.gerrit.server.change.GetDiff;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.assistedinject.Assisted;
|
||||
|
||||
class FileApiImpl implements FileApi {
|
||||
interface Factory {
|
||||
FileApiImpl create(FileResource r);
|
||||
}
|
||||
|
||||
private final GetContent getContent;
|
||||
private final GetDiff getDiff;
|
||||
private final FileResource file;
|
||||
|
||||
@Inject
|
||||
FileApiImpl(GetContent getContent, GetDiff getDiff, @Assisted FileResource file) {
|
||||
this.getContent = getContent;
|
||||
this.getDiff = getDiff;
|
||||
this.file = file;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BinaryResult content() throws RestApiException {
|
||||
try {
|
||||
return getContent.apply(file);
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot retrieve file content", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public DiffInfo diff() throws RestApiException {
|
||||
try {
|
||||
return getDiff.apply(file).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot retrieve diff", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public DiffInfo diff(String base) throws RestApiException {
|
||||
try {
|
||||
return getDiff.setBase(base).apply(file).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot retrieve diff", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public DiffInfo diff(int parent) throws RestApiException {
|
||||
try {
|
||||
return getDiff.setParent(parent).apply(file).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot retrieve diff", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public DiffRequest diffRequest() {
|
||||
return new DiffRequest() {
|
||||
@Override
|
||||
public DiffInfo get() throws RestApiException {
|
||||
return FileApiImpl.this.get(this);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private DiffInfo get(DiffRequest r) throws RestApiException {
|
||||
if (r.getBase() != null) {
|
||||
getDiff.setBase(r.getBase());
|
||||
}
|
||||
if (r.getContext() != null) {
|
||||
getDiff.setContext(r.getContext());
|
||||
}
|
||||
if (r.getIntraline() != null) {
|
||||
getDiff.setIntraline(r.getIntraline());
|
||||
}
|
||||
if (r.getWhitespace() != null) {
|
||||
getDiff.setWhitespace(r.getWhitespace());
|
||||
}
|
||||
r.getParent().ifPresent(getDiff::setParent);
|
||||
try {
|
||||
return getDiff.apply(file).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot retrieve diff", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
35
java/com/google/gerrit/server/api/changes/Module.java
Normal file
35
java/com/google/gerrit/server/api/changes/Module.java
Normal file
@@ -0,0 +1,35 @@
|
||||
// Copyright (C) 2013 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.server.api.changes;
|
||||
|
||||
import com.google.gerrit.extensions.api.changes.Changes;
|
||||
import com.google.gerrit.extensions.config.FactoryModule;
|
||||
|
||||
public class Module extends FactoryModule {
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(Changes.class).to(ChangesImpl.class);
|
||||
|
||||
factory(ChangeApiImpl.Factory.class);
|
||||
factory(CommentApiImpl.Factory.class);
|
||||
factory(RobotCommentApiImpl.Factory.class);
|
||||
factory(DraftApiImpl.Factory.class);
|
||||
factory(RevisionApiImpl.Factory.class);
|
||||
factory(FileApiImpl.Factory.class);
|
||||
factory(ReviewerApiImpl.Factory.class);
|
||||
factory(RevisionReviewerApiImpl.Factory.class);
|
||||
factory(ChangeEditApiImpl.Factory.class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
// Copyright (C) 2014 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.server.api.changes;
|
||||
|
||||
import static com.google.gerrit.server.api.ApiUtil.asRestApiException;
|
||||
|
||||
import com.google.gerrit.extensions.api.changes.DeleteReviewerInput;
|
||||
import com.google.gerrit.extensions.api.changes.DeleteVoteInput;
|
||||
import com.google.gerrit.extensions.api.changes.ReviewerApi;
|
||||
import com.google.gerrit.extensions.restapi.RestApiException;
|
||||
import com.google.gerrit.server.change.DeleteReviewer;
|
||||
import com.google.gerrit.server.change.DeleteVote;
|
||||
import com.google.gerrit.server.change.ReviewerResource;
|
||||
import com.google.gerrit.server.change.VoteResource;
|
||||
import com.google.gerrit.server.change.Votes;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.assistedinject.Assisted;
|
||||
import java.util.Map;
|
||||
|
||||
public class ReviewerApiImpl implements ReviewerApi {
|
||||
interface Factory {
|
||||
ReviewerApiImpl create(ReviewerResource r);
|
||||
}
|
||||
|
||||
private final ReviewerResource reviewer;
|
||||
private final Votes.List listVotes;
|
||||
private final DeleteVote deleteVote;
|
||||
private final DeleteReviewer deleteReviewer;
|
||||
|
||||
@Inject
|
||||
ReviewerApiImpl(
|
||||
Votes.List listVotes,
|
||||
DeleteVote deleteVote,
|
||||
DeleteReviewer deleteReviewer,
|
||||
@Assisted ReviewerResource reviewer) {
|
||||
this.listVotes = listVotes;
|
||||
this.deleteVote = deleteVote;
|
||||
this.deleteReviewer = deleteReviewer;
|
||||
this.reviewer = reviewer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Short> votes() throws RestApiException {
|
||||
try {
|
||||
return listVotes.apply(reviewer);
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot list votes", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteVote(String label) throws RestApiException {
|
||||
try {
|
||||
deleteVote.apply(new VoteResource(reviewer, label), null);
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot delete vote", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteVote(DeleteVoteInput input) throws RestApiException {
|
||||
try {
|
||||
deleteVote.apply(new VoteResource(reviewer, input.label), input);
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot delete vote", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove() throws RestApiException {
|
||||
remove(new DeleteReviewerInput());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove(DeleteReviewerInput input) throws RestApiException {
|
||||
try {
|
||||
deleteReviewer.apply(reviewer, input);
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot remove reviewer", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
588
java/com/google/gerrit/server/api/changes/RevisionApiImpl.java
Normal file
588
java/com/google/gerrit/server/api/changes/RevisionApiImpl.java
Normal file
@@ -0,0 +1,588 @@
|
||||
// Copyright (C) 2013 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.server.api.changes;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
import static com.google.gerrit.server.api.ApiUtil.asRestApiException;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.gerrit.extensions.api.changes.ChangeApi;
|
||||
import com.google.gerrit.extensions.api.changes.Changes;
|
||||
import com.google.gerrit.extensions.api.changes.CherryPickInput;
|
||||
import com.google.gerrit.extensions.api.changes.CommentApi;
|
||||
import com.google.gerrit.extensions.api.changes.DraftApi;
|
||||
import com.google.gerrit.extensions.api.changes.DraftInput;
|
||||
import com.google.gerrit.extensions.api.changes.FileApi;
|
||||
import com.google.gerrit.extensions.api.changes.RebaseInput;
|
||||
import com.google.gerrit.extensions.api.changes.ReviewInput;
|
||||
import com.google.gerrit.extensions.api.changes.ReviewResult;
|
||||
import com.google.gerrit.extensions.api.changes.RevisionApi;
|
||||
import com.google.gerrit.extensions.api.changes.RevisionReviewerApi;
|
||||
import com.google.gerrit.extensions.api.changes.RobotCommentApi;
|
||||
import com.google.gerrit.extensions.api.changes.SubmitInput;
|
||||
import com.google.gerrit.extensions.client.SubmitType;
|
||||
import com.google.gerrit.extensions.common.ActionInfo;
|
||||
import com.google.gerrit.extensions.common.CommentInfo;
|
||||
import com.google.gerrit.extensions.common.CommitInfo;
|
||||
import com.google.gerrit.extensions.common.DescriptionInput;
|
||||
import com.google.gerrit.extensions.common.EditInfo;
|
||||
import com.google.gerrit.extensions.common.FileInfo;
|
||||
import com.google.gerrit.extensions.common.Input;
|
||||
import com.google.gerrit.extensions.common.MergeableInfo;
|
||||
import com.google.gerrit.extensions.common.RobotCommentInfo;
|
||||
import com.google.gerrit.extensions.common.TestSubmitRuleInput;
|
||||
import com.google.gerrit.extensions.restapi.BinaryResult;
|
||||
import com.google.gerrit.extensions.restapi.IdString;
|
||||
import com.google.gerrit.extensions.restapi.RestApiException;
|
||||
import com.google.gerrit.extensions.restapi.RestModifyView;
|
||||
import com.google.gerrit.server.change.ApplyFix;
|
||||
import com.google.gerrit.server.change.CherryPick;
|
||||
import com.google.gerrit.server.change.Comments;
|
||||
import com.google.gerrit.server.change.CreateDraftComment;
|
||||
import com.google.gerrit.server.change.DraftComments;
|
||||
import com.google.gerrit.server.change.FileResource;
|
||||
import com.google.gerrit.server.change.Files;
|
||||
import com.google.gerrit.server.change.Fixes;
|
||||
import com.google.gerrit.server.change.GetCommit;
|
||||
import com.google.gerrit.server.change.GetDescription;
|
||||
import com.google.gerrit.server.change.GetMergeList;
|
||||
import com.google.gerrit.server.change.GetPatch;
|
||||
import com.google.gerrit.server.change.GetRevisionActions;
|
||||
import com.google.gerrit.server.change.ListRevisionComments;
|
||||
import com.google.gerrit.server.change.ListRevisionDrafts;
|
||||
import com.google.gerrit.server.change.ListRobotComments;
|
||||
import com.google.gerrit.server.change.Mergeable;
|
||||
import com.google.gerrit.server.change.PostReview;
|
||||
import com.google.gerrit.server.change.PreviewSubmit;
|
||||
import com.google.gerrit.server.change.PutDescription;
|
||||
import com.google.gerrit.server.change.Rebase;
|
||||
import com.google.gerrit.server.change.RebaseUtil;
|
||||
import com.google.gerrit.server.change.Reviewed;
|
||||
import com.google.gerrit.server.change.RevisionResource;
|
||||
import com.google.gerrit.server.change.RevisionReviewers;
|
||||
import com.google.gerrit.server.change.RobotComments;
|
||||
import com.google.gerrit.server.change.Submit;
|
||||
import com.google.gerrit.server.change.TestSubmitType;
|
||||
import com.google.gerrit.server.git.GitRepositoryManager;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Provider;
|
||||
import com.google.inject.assistedinject.Assisted;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import org.eclipse.jgit.lib.Repository;
|
||||
import org.eclipse.jgit.revwalk.RevWalk;
|
||||
|
||||
class RevisionApiImpl implements RevisionApi {
|
||||
interface Factory {
|
||||
RevisionApiImpl create(RevisionResource r);
|
||||
}
|
||||
|
||||
private final GitRepositoryManager repoManager;
|
||||
private final Changes changes;
|
||||
private final RevisionReviewers revisionReviewers;
|
||||
private final RevisionReviewerApiImpl.Factory revisionReviewerApi;
|
||||
private final CherryPick cherryPick;
|
||||
private final Rebase rebase;
|
||||
private final RebaseUtil rebaseUtil;
|
||||
private final Submit submit;
|
||||
private final PreviewSubmit submitPreview;
|
||||
private final Reviewed.PutReviewed putReviewed;
|
||||
private final Reviewed.DeleteReviewed deleteReviewed;
|
||||
private final RevisionResource revision;
|
||||
private final Files files;
|
||||
private final Files.ListFiles listFiles;
|
||||
private final GetCommit getCommit;
|
||||
private final GetPatch getPatch;
|
||||
private final PostReview review;
|
||||
private final Mergeable mergeable;
|
||||
private final FileApiImpl.Factory fileApi;
|
||||
private final ListRevisionComments listComments;
|
||||
private final ListRobotComments listRobotComments;
|
||||
private final ApplyFix applyFix;
|
||||
private final Fixes fixes;
|
||||
private final ListRevisionDrafts listDrafts;
|
||||
private final CreateDraftComment createDraft;
|
||||
private final DraftComments drafts;
|
||||
private final DraftApiImpl.Factory draftFactory;
|
||||
private final Comments comments;
|
||||
private final CommentApiImpl.Factory commentFactory;
|
||||
private final RobotComments robotComments;
|
||||
private final RobotCommentApiImpl.Factory robotCommentFactory;
|
||||
private final GetRevisionActions revisionActions;
|
||||
private final TestSubmitType testSubmitType;
|
||||
private final TestSubmitType.Get getSubmitType;
|
||||
private final Provider<GetMergeList> getMergeList;
|
||||
private final PutDescription putDescription;
|
||||
private final GetDescription getDescription;
|
||||
|
||||
@Inject
|
||||
RevisionApiImpl(
|
||||
GitRepositoryManager repoManager,
|
||||
Changes changes,
|
||||
RevisionReviewers revisionReviewers,
|
||||
RevisionReviewerApiImpl.Factory revisionReviewerApi,
|
||||
CherryPick cherryPick,
|
||||
Rebase rebase,
|
||||
RebaseUtil rebaseUtil,
|
||||
Submit submit,
|
||||
PreviewSubmit submitPreview,
|
||||
Reviewed.PutReviewed putReviewed,
|
||||
Reviewed.DeleteReviewed deleteReviewed,
|
||||
Files files,
|
||||
Files.ListFiles listFiles,
|
||||
GetCommit getCommit,
|
||||
GetPatch getPatch,
|
||||
PostReview review,
|
||||
Mergeable mergeable,
|
||||
FileApiImpl.Factory fileApi,
|
||||
ListRevisionComments listComments,
|
||||
ListRobotComments listRobotComments,
|
||||
ApplyFix applyFix,
|
||||
Fixes fixes,
|
||||
ListRevisionDrafts listDrafts,
|
||||
CreateDraftComment createDraft,
|
||||
DraftComments drafts,
|
||||
DraftApiImpl.Factory draftFactory,
|
||||
Comments comments,
|
||||
CommentApiImpl.Factory commentFactory,
|
||||
RobotComments robotComments,
|
||||
RobotCommentApiImpl.Factory robotCommentFactory,
|
||||
GetRevisionActions revisionActions,
|
||||
TestSubmitType testSubmitType,
|
||||
TestSubmitType.Get getSubmitType,
|
||||
Provider<GetMergeList> getMergeList,
|
||||
PutDescription putDescription,
|
||||
GetDescription getDescription,
|
||||
@Assisted RevisionResource r) {
|
||||
this.repoManager = repoManager;
|
||||
this.changes = changes;
|
||||
this.revisionReviewers = revisionReviewers;
|
||||
this.revisionReviewerApi = revisionReviewerApi;
|
||||
this.cherryPick = cherryPick;
|
||||
this.rebase = rebase;
|
||||
this.rebaseUtil = rebaseUtil;
|
||||
this.review = review;
|
||||
this.submit = submit;
|
||||
this.submitPreview = submitPreview;
|
||||
this.files = files;
|
||||
this.putReviewed = putReviewed;
|
||||
this.deleteReviewed = deleteReviewed;
|
||||
this.listFiles = listFiles;
|
||||
this.getCommit = getCommit;
|
||||
this.getPatch = getPatch;
|
||||
this.mergeable = mergeable;
|
||||
this.fileApi = fileApi;
|
||||
this.listComments = listComments;
|
||||
this.robotComments = robotComments;
|
||||
this.listRobotComments = listRobotComments;
|
||||
this.applyFix = applyFix;
|
||||
this.fixes = fixes;
|
||||
this.listDrafts = listDrafts;
|
||||
this.createDraft = createDraft;
|
||||
this.drafts = drafts;
|
||||
this.draftFactory = draftFactory;
|
||||
this.comments = comments;
|
||||
this.commentFactory = commentFactory;
|
||||
this.robotCommentFactory = robotCommentFactory;
|
||||
this.revisionActions = revisionActions;
|
||||
this.testSubmitType = testSubmitType;
|
||||
this.getSubmitType = getSubmitType;
|
||||
this.getMergeList = getMergeList;
|
||||
this.putDescription = putDescription;
|
||||
this.getDescription = getDescription;
|
||||
this.revision = r;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ReviewResult review(ReviewInput in) throws RestApiException {
|
||||
try {
|
||||
return review.apply(revision, in).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot post review", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void submit() throws RestApiException {
|
||||
SubmitInput in = new SubmitInput();
|
||||
submit(in);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void submit(SubmitInput in) throws RestApiException {
|
||||
try {
|
||||
submit.apply(revision, in);
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot submit change", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public BinaryResult submitPreview() throws RestApiException {
|
||||
return submitPreview("zip");
|
||||
}
|
||||
|
||||
@Override
|
||||
public BinaryResult submitPreview(String format) throws RestApiException {
|
||||
try {
|
||||
submitPreview.setFormat(format);
|
||||
return submitPreview.apply(revision);
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot get submit preview", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void publish() throws RestApiException {
|
||||
throw new UnsupportedOperationException("draft workflow is discontinued");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete() throws RestApiException {
|
||||
throw new UnsupportedOperationException("draft workflow is discontinued");
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChangeApi rebase() throws RestApiException {
|
||||
RebaseInput in = new RebaseInput();
|
||||
return rebase(in);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChangeApi rebase(RebaseInput in) throws RestApiException {
|
||||
try {
|
||||
return changes.id(rebase.apply(revision, in)._number);
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot rebase ps", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canRebase() throws RestApiException {
|
||||
try (Repository repo = repoManager.openRepository(revision.getProject());
|
||||
RevWalk rw = new RevWalk(repo)) {
|
||||
return rebaseUtil.canRebase(revision.getPatchSet(), revision.getChange().getDest(), repo, rw);
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot check if rebase is possible", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChangeApi cherryPick(CherryPickInput in) throws RestApiException {
|
||||
try {
|
||||
return changes.id(cherryPick.apply(revision, in)._number);
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot cherry pick", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public RevisionReviewerApi reviewer(String id) throws RestApiException {
|
||||
try {
|
||||
return revisionReviewerApi.create(
|
||||
revisionReviewers.parse(revision, IdString.fromDecoded(id)));
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot parse reviewer", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setReviewed(String path, boolean reviewed) throws RestApiException {
|
||||
try {
|
||||
RestModifyView<FileResource, Input> view;
|
||||
if (reviewed) {
|
||||
view = putReviewed;
|
||||
} else {
|
||||
view = deleteReviewed;
|
||||
}
|
||||
view.apply(files.parse(revision, IdString.fromDecoded(path)), new Input());
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot update reviewed flag", e);
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public Set<String> reviewed() throws RestApiException {
|
||||
try {
|
||||
return ImmutableSet.copyOf(
|
||||
(Iterable<String>) listFiles.setReviewed(true).apply(revision).value());
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot list reviewed files", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public MergeableInfo mergeable() throws RestApiException {
|
||||
try {
|
||||
return mergeable.apply(revision);
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot check mergeability", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public MergeableInfo mergeableOtherBranches() throws RestApiException {
|
||||
try {
|
||||
mergeable.setOtherBranches(true);
|
||||
return mergeable.apply(revision);
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot check mergeability", e);
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public Map<String, FileInfo> files() throws RestApiException {
|
||||
try {
|
||||
return (Map<String, FileInfo>) listFiles.apply(revision).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot retrieve files", e);
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public Map<String, FileInfo> files(String base) throws RestApiException {
|
||||
try {
|
||||
return (Map<String, FileInfo>) listFiles.setBase(base).apply(revision).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot retrieve files", e);
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public Map<String, FileInfo> files(int parentNum) throws RestApiException {
|
||||
try {
|
||||
return (Map<String, FileInfo>) listFiles.setParent(parentNum).apply(revision).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot retrieve files", e);
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public List<String> queryFiles(String query) throws RestApiException {
|
||||
try {
|
||||
checkArgument(query != null, "no query provided");
|
||||
return (List<String>) listFiles.setQuery(query).apply(revision).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot retrieve files", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public FileApi file(String path) {
|
||||
return fileApi.create(files.parse(revision, IdString.fromDecoded(path)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommitInfo commit(boolean addLinks) throws RestApiException {
|
||||
try {
|
||||
return getCommit.setAddLinks(addLinks).apply(revision).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot retrieve commit", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, List<CommentInfo>> comments() throws RestApiException {
|
||||
try {
|
||||
return listComments.apply(revision);
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot retrieve comments", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, List<RobotCommentInfo>> robotComments() throws RestApiException {
|
||||
try {
|
||||
return listRobotComments.apply(revision);
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot retrieve robot comments", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<CommentInfo> commentsAsList() throws RestApiException {
|
||||
try {
|
||||
return listComments.getComments(revision);
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot retrieve comments", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, List<CommentInfo>> drafts() throws RestApiException {
|
||||
try {
|
||||
return listDrafts.apply(revision);
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot retrieve drafts", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<RobotCommentInfo> robotCommentsAsList() throws RestApiException {
|
||||
try {
|
||||
return listRobotComments.getComments(revision);
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot retrieve robot comments", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public EditInfo applyFix(String fixId) throws RestApiException {
|
||||
try {
|
||||
return applyFix.apply(fixes.parse(revision, IdString.fromDecoded(fixId)), null).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot apply fix", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<CommentInfo> draftsAsList() throws RestApiException {
|
||||
try {
|
||||
return listDrafts.getComments(revision);
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot retrieve drafts", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public DraftApi draft(String id) throws RestApiException {
|
||||
try {
|
||||
return draftFactory.create(drafts.parse(revision, IdString.fromDecoded(id)));
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot retrieve draft", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public DraftApi createDraft(DraftInput in) throws RestApiException {
|
||||
try {
|
||||
String id = createDraft.apply(revision, in).value().id;
|
||||
// Reread change to pick up new notes refs.
|
||||
return changes
|
||||
.id(revision.getChange().getId().get())
|
||||
.revision(revision.getPatchSet().getId().get())
|
||||
.draft(id);
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot create draft", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommentApi comment(String id) throws RestApiException {
|
||||
try {
|
||||
return commentFactory.create(comments.parse(revision, IdString.fromDecoded(id)));
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot retrieve comment", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public RobotCommentApi robotComment(String id) throws RestApiException {
|
||||
try {
|
||||
return robotCommentFactory.create(robotComments.parse(revision, IdString.fromDecoded(id)));
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot retrieve robot comment", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public BinaryResult patch() throws RestApiException {
|
||||
try {
|
||||
return getPatch.apply(revision);
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot get patch", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public BinaryResult patch(String path) throws RestApiException {
|
||||
try {
|
||||
return getPatch.setPath(path).apply(revision);
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot get patch", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, ActionInfo> actions() throws RestApiException {
|
||||
try {
|
||||
return revisionActions.apply(revision).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot get actions", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public SubmitType submitType() throws RestApiException {
|
||||
try {
|
||||
return getSubmitType.apply(revision);
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot get submit type", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public SubmitType testSubmitType(TestSubmitRuleInput in) throws RestApiException {
|
||||
try {
|
||||
return testSubmitType.apply(revision, in);
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot test submit type", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public MergeListRequest getMergeList() throws RestApiException {
|
||||
return new MergeListRequest() {
|
||||
@Override
|
||||
public List<CommitInfo> get() throws RestApiException {
|
||||
try {
|
||||
GetMergeList gml = getMergeList.get();
|
||||
gml.setUninterestingParent(getUninterestingParent());
|
||||
gml.setAddLinks(getAddLinks());
|
||||
return gml.apply(revision).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot get merge list", e);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public void description(String description) throws RestApiException {
|
||||
DescriptionInput in = new DescriptionInput();
|
||||
in.description = description;
|
||||
try {
|
||||
putDescription.apply(revision, in);
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot set description", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String description() throws RestApiException {
|
||||
return getDescription.apply(revision);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String etag() throws RestApiException {
|
||||
return revisionActions.getETag(revision);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
// Copyright (C) 2017 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.server.api.changes;
|
||||
|
||||
import static com.google.gerrit.server.api.ApiUtil.asRestApiException;
|
||||
|
||||
import com.google.gerrit.extensions.api.changes.DeleteVoteInput;
|
||||
import com.google.gerrit.extensions.api.changes.RevisionReviewerApi;
|
||||
import com.google.gerrit.extensions.restapi.RestApiException;
|
||||
import com.google.gerrit.server.change.DeleteVote;
|
||||
import com.google.gerrit.server.change.ReviewerResource;
|
||||
import com.google.gerrit.server.change.VoteResource;
|
||||
import com.google.gerrit.server.change.Votes;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.assistedinject.Assisted;
|
||||
import java.util.Map;
|
||||
|
||||
public class RevisionReviewerApiImpl implements RevisionReviewerApi {
|
||||
interface Factory {
|
||||
RevisionReviewerApiImpl create(ReviewerResource r);
|
||||
}
|
||||
|
||||
private final ReviewerResource reviewer;
|
||||
private final Votes.List listVotes;
|
||||
private final DeleteVote deleteVote;
|
||||
|
||||
@Inject
|
||||
RevisionReviewerApiImpl(
|
||||
Votes.List listVotes, DeleteVote deleteVote, @Assisted ReviewerResource reviewer) {
|
||||
this.listVotes = listVotes;
|
||||
this.deleteVote = deleteVote;
|
||||
this.reviewer = reviewer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Short> votes() throws RestApiException {
|
||||
try {
|
||||
return listVotes.apply(reviewer);
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot list votes", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteVote(String label) throws RestApiException {
|
||||
try {
|
||||
deleteVote.apply(new VoteResource(reviewer, label), null);
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot delete vote", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteVote(DeleteVoteInput input) throws RestApiException {
|
||||
try {
|
||||
deleteVote.apply(new VoteResource(reviewer, input.label), input);
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot delete vote", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
// Copyright (C) 2016 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.server.api.changes;
|
||||
|
||||
import static com.google.gerrit.server.api.ApiUtil.asRestApiException;
|
||||
|
||||
import com.google.gerrit.extensions.api.changes.RobotCommentApi;
|
||||
import com.google.gerrit.extensions.common.RobotCommentInfo;
|
||||
import com.google.gerrit.extensions.restapi.RestApiException;
|
||||
import com.google.gerrit.server.change.GetRobotComment;
|
||||
import com.google.gerrit.server.change.RobotCommentResource;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.assistedinject.Assisted;
|
||||
|
||||
public class RobotCommentApiImpl implements RobotCommentApi {
|
||||
interface Factory {
|
||||
RobotCommentApiImpl create(RobotCommentResource c);
|
||||
}
|
||||
|
||||
private final GetRobotComment getComment;
|
||||
private final RobotCommentResource comment;
|
||||
|
||||
@Inject
|
||||
RobotCommentApiImpl(GetRobotComment getComment, @Assisted RobotCommentResource comment) {
|
||||
this.getComment = getComment;
|
||||
this.comment = comment;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RobotCommentInfo get() throws RestApiException {
|
||||
try {
|
||||
return getComment.apply(comment);
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot retrieve robot comment", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
35
java/com/google/gerrit/server/api/config/ConfigImpl.java
Normal file
35
java/com/google/gerrit/server/api/config/ConfigImpl.java
Normal file
@@ -0,0 +1,35 @@
|
||||
// Copyright (C) 2015 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.server.api.config;
|
||||
|
||||
import com.google.gerrit.extensions.api.config.Config;
|
||||
import com.google.gerrit.extensions.api.config.Server;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Singleton;
|
||||
|
||||
@Singleton
|
||||
public class ConfigImpl implements Config {
|
||||
private final ServerImpl serverApi;
|
||||
|
||||
@Inject
|
||||
ConfigImpl(ServerImpl serverApi) {
|
||||
this.serverApi = serverApi;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Server server() {
|
||||
return serverApi;
|
||||
}
|
||||
}
|
||||
27
java/com/google/gerrit/server/api/config/Module.java
Normal file
27
java/com/google/gerrit/server/api/config/Module.java
Normal file
@@ -0,0 +1,27 @@
|
||||
// Copyright (C) 2015 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.server.api.config;
|
||||
|
||||
import com.google.gerrit.extensions.api.config.Config;
|
||||
import com.google.gerrit.extensions.api.config.Server;
|
||||
import com.google.gerrit.extensions.config.FactoryModule;
|
||||
|
||||
public class Module extends FactoryModule {
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(Config.class).to(ConfigImpl.class);
|
||||
bind(Server.class).to(ServerImpl.class);
|
||||
}
|
||||
}
|
||||
123
java/com/google/gerrit/server/api/config/ServerImpl.java
Normal file
123
java/com/google/gerrit/server/api/config/ServerImpl.java
Normal file
@@ -0,0 +1,123 @@
|
||||
// Copyright (C) 2015 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.server.api.config;
|
||||
|
||||
import static com.google.gerrit.server.api.ApiUtil.asRestApiException;
|
||||
|
||||
import com.google.gerrit.common.Version;
|
||||
import com.google.gerrit.extensions.api.config.ConsistencyCheckInfo;
|
||||
import com.google.gerrit.extensions.api.config.ConsistencyCheckInput;
|
||||
import com.google.gerrit.extensions.api.config.Server;
|
||||
import com.google.gerrit.extensions.client.DiffPreferencesInfo;
|
||||
import com.google.gerrit.extensions.client.GeneralPreferencesInfo;
|
||||
import com.google.gerrit.extensions.common.ServerInfo;
|
||||
import com.google.gerrit.extensions.restapi.RestApiException;
|
||||
import com.google.gerrit.server.config.CheckConsistency;
|
||||
import com.google.gerrit.server.config.ConfigResource;
|
||||
import com.google.gerrit.server.config.GetDiffPreferences;
|
||||
import com.google.gerrit.server.config.GetPreferences;
|
||||
import com.google.gerrit.server.config.GetServerInfo;
|
||||
import com.google.gerrit.server.config.SetDiffPreferences;
|
||||
import com.google.gerrit.server.config.SetPreferences;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Provider;
|
||||
import com.google.inject.Singleton;
|
||||
|
||||
@Singleton
|
||||
public class ServerImpl implements Server {
|
||||
private final GetPreferences getPreferences;
|
||||
private final SetPreferences setPreferences;
|
||||
private final GetDiffPreferences getDiffPreferences;
|
||||
private final SetDiffPreferences setDiffPreferences;
|
||||
private final GetServerInfo getServerInfo;
|
||||
private final Provider<CheckConsistency> checkConsistency;
|
||||
|
||||
@Inject
|
||||
ServerImpl(
|
||||
GetPreferences getPreferences,
|
||||
SetPreferences setPreferences,
|
||||
GetDiffPreferences getDiffPreferences,
|
||||
SetDiffPreferences setDiffPreferences,
|
||||
GetServerInfo getServerInfo,
|
||||
Provider<CheckConsistency> checkConsistency) {
|
||||
this.getPreferences = getPreferences;
|
||||
this.setPreferences = setPreferences;
|
||||
this.getDiffPreferences = getDiffPreferences;
|
||||
this.setDiffPreferences = setDiffPreferences;
|
||||
this.getServerInfo = getServerInfo;
|
||||
this.checkConsistency = checkConsistency;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getVersion() throws RestApiException {
|
||||
return Version.getVersion();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ServerInfo getInfo() throws RestApiException {
|
||||
try {
|
||||
return getServerInfo.apply(new ConfigResource());
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot get server info", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public GeneralPreferencesInfo getDefaultPreferences() throws RestApiException {
|
||||
try {
|
||||
return getPreferences.apply(new ConfigResource());
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot get default general preferences", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public GeneralPreferencesInfo setDefaultPreferences(GeneralPreferencesInfo in)
|
||||
throws RestApiException {
|
||||
try {
|
||||
return setPreferences.apply(new ConfigResource(), in);
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot set default general preferences", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public DiffPreferencesInfo getDefaultDiffPreferences() throws RestApiException {
|
||||
try {
|
||||
return getDiffPreferences.apply(new ConfigResource());
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot get default diff preferences", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public DiffPreferencesInfo setDefaultDiffPreferences(DiffPreferencesInfo in)
|
||||
throws RestApiException {
|
||||
try {
|
||||
return setDiffPreferences.apply(new ConfigResource(), in);
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot set default diff preferences", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConsistencyCheckInfo checkConsistency(ConsistencyCheckInput in) throws RestApiException {
|
||||
try {
|
||||
return checkConsistency.get().apply(new ConfigResource(), in);
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot check consistency", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
281
java/com/google/gerrit/server/api/groups/GroupApiImpl.java
Normal file
281
java/com/google/gerrit/server/api/groups/GroupApiImpl.java
Normal file
@@ -0,0 +1,281 @@
|
||||
// Copyright (C) 2015 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.server.api.groups;
|
||||
|
||||
import static com.google.gerrit.server.api.ApiUtil.asRestApiException;
|
||||
|
||||
import com.google.gerrit.extensions.api.groups.GroupApi;
|
||||
import com.google.gerrit.extensions.api.groups.OwnerInput;
|
||||
import com.google.gerrit.extensions.common.AccountInfo;
|
||||
import com.google.gerrit.extensions.common.DescriptionInput;
|
||||
import com.google.gerrit.extensions.common.GroupAuditEventInfo;
|
||||
import com.google.gerrit.extensions.common.GroupInfo;
|
||||
import com.google.gerrit.extensions.common.GroupOptionsInfo;
|
||||
import com.google.gerrit.extensions.common.Input;
|
||||
import com.google.gerrit.extensions.common.NameInput;
|
||||
import com.google.gerrit.extensions.restapi.RestApiException;
|
||||
import com.google.gerrit.server.group.AddMembers;
|
||||
import com.google.gerrit.server.group.AddSubgroups;
|
||||
import com.google.gerrit.server.group.DeleteMembers;
|
||||
import com.google.gerrit.server.group.DeleteSubgroups;
|
||||
import com.google.gerrit.server.group.GetAuditLog;
|
||||
import com.google.gerrit.server.group.GetDescription;
|
||||
import com.google.gerrit.server.group.GetDetail;
|
||||
import com.google.gerrit.server.group.GetGroup;
|
||||
import com.google.gerrit.server.group.GetName;
|
||||
import com.google.gerrit.server.group.GetOptions;
|
||||
import com.google.gerrit.server.group.GetOwner;
|
||||
import com.google.gerrit.server.group.GroupResource;
|
||||
import com.google.gerrit.server.group.Index;
|
||||
import com.google.gerrit.server.group.ListMembers;
|
||||
import com.google.gerrit.server.group.ListSubgroups;
|
||||
import com.google.gerrit.server.group.PutDescription;
|
||||
import com.google.gerrit.server.group.PutName;
|
||||
import com.google.gerrit.server.group.PutOptions;
|
||||
import com.google.gerrit.server.group.PutOwner;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.assistedinject.Assisted;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
class GroupApiImpl implements GroupApi {
|
||||
interface Factory {
|
||||
GroupApiImpl create(GroupResource rsrc);
|
||||
}
|
||||
|
||||
private final GetGroup getGroup;
|
||||
private final GetDetail getDetail;
|
||||
private final GetName getName;
|
||||
private final PutName putName;
|
||||
private final GetOwner getOwner;
|
||||
private final PutOwner putOwner;
|
||||
private final GetDescription getDescription;
|
||||
private final PutDescription putDescription;
|
||||
private final GetOptions getOptions;
|
||||
private final PutOptions putOptions;
|
||||
private final ListMembers listMembers;
|
||||
private final AddMembers addMembers;
|
||||
private final DeleteMembers deleteMembers;
|
||||
private final ListSubgroups listSubgroups;
|
||||
private final AddSubgroups addSubgroups;
|
||||
private final DeleteSubgroups deleteSubgroups;
|
||||
private final GetAuditLog getAuditLog;
|
||||
private final GroupResource rsrc;
|
||||
private final Index index;
|
||||
|
||||
@Inject
|
||||
GroupApiImpl(
|
||||
GetGroup getGroup,
|
||||
GetDetail getDetail,
|
||||
GetName getName,
|
||||
PutName putName,
|
||||
GetOwner getOwner,
|
||||
PutOwner putOwner,
|
||||
GetDescription getDescription,
|
||||
PutDescription putDescription,
|
||||
GetOptions getOptions,
|
||||
PutOptions putOptions,
|
||||
ListMembers listMembers,
|
||||
AddMembers addMembers,
|
||||
DeleteMembers deleteMembers,
|
||||
ListSubgroups listSubgroups,
|
||||
AddSubgroups addSubgroups,
|
||||
DeleteSubgroups deleteSubgroups,
|
||||
GetAuditLog getAuditLog,
|
||||
Index index,
|
||||
@Assisted GroupResource rsrc) {
|
||||
this.getGroup = getGroup;
|
||||
this.getDetail = getDetail;
|
||||
this.getName = getName;
|
||||
this.putName = putName;
|
||||
this.getOwner = getOwner;
|
||||
this.putOwner = putOwner;
|
||||
this.getDescription = getDescription;
|
||||
this.putDescription = putDescription;
|
||||
this.getOptions = getOptions;
|
||||
this.putOptions = putOptions;
|
||||
this.listMembers = listMembers;
|
||||
this.addMembers = addMembers;
|
||||
this.deleteMembers = deleteMembers;
|
||||
this.listSubgroups = listSubgroups;
|
||||
this.addSubgroups = addSubgroups;
|
||||
this.deleteSubgroups = deleteSubgroups;
|
||||
this.getAuditLog = getAuditLog;
|
||||
this.index = index;
|
||||
this.rsrc = rsrc;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GroupInfo get() throws RestApiException {
|
||||
try {
|
||||
return getGroup.apply(rsrc);
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot retrieve group", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public GroupInfo detail() throws RestApiException {
|
||||
try {
|
||||
return getDetail.apply(rsrc);
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot retrieve group", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String name() throws RestApiException {
|
||||
return getName.apply(rsrc);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void name(String name) throws RestApiException {
|
||||
NameInput in = new NameInput();
|
||||
in.name = name;
|
||||
try {
|
||||
putName.apply(rsrc, in);
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot put group name", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public GroupInfo owner() throws RestApiException {
|
||||
try {
|
||||
return getOwner.apply(rsrc);
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot get group owner", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void owner(String owner) throws RestApiException {
|
||||
OwnerInput in = new OwnerInput();
|
||||
in.owner = owner;
|
||||
try {
|
||||
putOwner.apply(rsrc, in);
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot put group owner", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String description() throws RestApiException {
|
||||
return getDescription.apply(rsrc);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void description(String description) throws RestApiException {
|
||||
DescriptionInput in = new DescriptionInput();
|
||||
in.description = description;
|
||||
try {
|
||||
putDescription.apply(rsrc, in);
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot put group description", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public GroupOptionsInfo options() throws RestApiException {
|
||||
return getOptions.apply(rsrc);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void options(GroupOptionsInfo options) throws RestApiException {
|
||||
try {
|
||||
putOptions.apply(rsrc, options);
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot put group options", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<AccountInfo> members() throws RestApiException {
|
||||
return members(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<AccountInfo> members(boolean recursive) throws RestApiException {
|
||||
listMembers.setRecursive(recursive);
|
||||
try {
|
||||
return listMembers.apply(rsrc);
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot list group members", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addMembers(String... members) throws RestApiException {
|
||||
try {
|
||||
addMembers.apply(rsrc, AddMembers.Input.fromMembers(Arrays.asList(members)));
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot add group members", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeMembers(String... members) throws RestApiException {
|
||||
try {
|
||||
deleteMembers.apply(rsrc, AddMembers.Input.fromMembers(Arrays.asList(members)));
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot remove group members", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<GroupInfo> includedGroups() throws RestApiException {
|
||||
try {
|
||||
return listSubgroups.apply(rsrc);
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot list subgroups", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addGroups(String... groups) throws RestApiException {
|
||||
try {
|
||||
addSubgroups.apply(rsrc, AddSubgroups.Input.fromGroups(Arrays.asList(groups)));
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot add subgroups", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeGroups(String... groups) throws RestApiException {
|
||||
try {
|
||||
deleteSubgroups.apply(rsrc, AddSubgroups.Input.fromGroups(Arrays.asList(groups)));
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot remove subgroups", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<? extends GroupAuditEventInfo> auditLog() throws RestApiException {
|
||||
try {
|
||||
return getAuditLog.apply(rsrc);
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot get audit log", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void index() throws RestApiException {
|
||||
try {
|
||||
index.apply(rsrc, new Input());
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot index group", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
190
java/com/google/gerrit/server/api/groups/GroupsImpl.java
Normal file
190
java/com/google/gerrit/server/api/groups/GroupsImpl.java
Normal file
@@ -0,0 +1,190 @@
|
||||
// Copyright (C) 2015 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.server.api.groups;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static com.google.gerrit.server.api.ApiUtil.asRestApiException;
|
||||
|
||||
import com.google.gerrit.extensions.api.groups.GroupApi;
|
||||
import com.google.gerrit.extensions.api.groups.GroupInput;
|
||||
import com.google.gerrit.extensions.api.groups.Groups;
|
||||
import com.google.gerrit.extensions.client.ListGroupsOption;
|
||||
import com.google.gerrit.extensions.common.GroupInfo;
|
||||
import com.google.gerrit.extensions.restapi.BadRequestException;
|
||||
import com.google.gerrit.extensions.restapi.IdString;
|
||||
import com.google.gerrit.extensions.restapi.RestApiException;
|
||||
import com.google.gerrit.extensions.restapi.TopLevelResource;
|
||||
import com.google.gerrit.server.CurrentUser;
|
||||
import com.google.gerrit.server.account.AccountsCollection;
|
||||
import com.google.gerrit.server.group.CreateGroup;
|
||||
import com.google.gerrit.server.group.GroupsCollection;
|
||||
import com.google.gerrit.server.group.ListGroups;
|
||||
import com.google.gerrit.server.group.QueryGroups;
|
||||
import com.google.gerrit.server.permissions.GlobalPermission;
|
||||
import com.google.gerrit.server.permissions.PermissionBackend;
|
||||
import com.google.gerrit.server.project.ProjectResource;
|
||||
import com.google.gerrit.server.project.ProjectsCollection;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Provider;
|
||||
import com.google.inject.Singleton;
|
||||
import java.util.List;
|
||||
import java.util.SortedMap;
|
||||
|
||||
@Singleton
|
||||
class GroupsImpl implements Groups {
|
||||
private final AccountsCollection accounts;
|
||||
private final GroupsCollection groups;
|
||||
private final ProjectsCollection projects;
|
||||
private final Provider<ListGroups> listGroups;
|
||||
private final Provider<QueryGroups> queryGroups;
|
||||
private final Provider<CurrentUser> user;
|
||||
private final PermissionBackend permissionBackend;
|
||||
private final CreateGroup.Factory createGroup;
|
||||
private final GroupApiImpl.Factory api;
|
||||
|
||||
@Inject
|
||||
GroupsImpl(
|
||||
AccountsCollection accounts,
|
||||
GroupsCollection groups,
|
||||
ProjectsCollection projects,
|
||||
Provider<ListGroups> listGroups,
|
||||
Provider<QueryGroups> queryGroups,
|
||||
Provider<CurrentUser> user,
|
||||
PermissionBackend permissionBackend,
|
||||
CreateGroup.Factory createGroup,
|
||||
GroupApiImpl.Factory api) {
|
||||
this.accounts = accounts;
|
||||
this.groups = groups;
|
||||
this.projects = projects;
|
||||
this.listGroups = listGroups;
|
||||
this.queryGroups = queryGroups;
|
||||
this.user = user;
|
||||
this.permissionBackend = permissionBackend;
|
||||
this.createGroup = createGroup;
|
||||
this.api = api;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GroupApi id(String id) throws RestApiException {
|
||||
return api.create(groups.parse(TopLevelResource.INSTANCE, IdString.fromDecoded(id)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public GroupApi create(String name) throws RestApiException {
|
||||
GroupInput in = new GroupInput();
|
||||
in.name = name;
|
||||
return create(in);
|
||||
}
|
||||
|
||||
@Override
|
||||
public GroupApi create(GroupInput in) throws RestApiException {
|
||||
if (checkNotNull(in, "GroupInput").name == null) {
|
||||
throw new BadRequestException("GroupInput must specify name");
|
||||
}
|
||||
try {
|
||||
CreateGroup impl = createGroup.create(in.name);
|
||||
permissionBackend.user(user).checkAny(GlobalPermission.fromAnnotation(impl.getClass()));
|
||||
GroupInfo info = impl.apply(TopLevelResource.INSTANCE, in);
|
||||
return id(info.id);
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot create group " + in.name, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ListRequest list() {
|
||||
return new ListRequest() {
|
||||
@Override
|
||||
public SortedMap<String, GroupInfo> getAsMap() throws RestApiException {
|
||||
return list(this);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private SortedMap<String, GroupInfo> list(ListRequest req) throws RestApiException {
|
||||
TopLevelResource tlr = TopLevelResource.INSTANCE;
|
||||
ListGroups list = listGroups.get();
|
||||
list.setOptions(req.getOptions());
|
||||
|
||||
for (String project : req.getProjects()) {
|
||||
try {
|
||||
ProjectResource rsrc = projects.parse(tlr, IdString.fromDecoded(project));
|
||||
list.addProject(rsrc.getProjectState());
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Error looking up project " + project, e);
|
||||
}
|
||||
}
|
||||
|
||||
for (String group : req.getGroups()) {
|
||||
list.addGroup(groups.parse(group).getGroupUUID());
|
||||
}
|
||||
|
||||
list.setVisibleToAll(req.getVisibleToAll());
|
||||
|
||||
if (req.getOwnedBy() != null) {
|
||||
list.setOwnedBy(req.getOwnedBy());
|
||||
}
|
||||
|
||||
if (req.getUser() != null) {
|
||||
try {
|
||||
list.setUser(accounts.parse(req.getUser()).getAccountId());
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Error looking up user " + req.getUser(), e);
|
||||
}
|
||||
}
|
||||
|
||||
list.setOwned(req.getOwned());
|
||||
list.setLimit(req.getLimit());
|
||||
list.setStart(req.getStart());
|
||||
list.setMatchSubstring(req.getSubstring());
|
||||
list.setMatchRegex(req.getRegex());
|
||||
list.setSuggest(req.getSuggest());
|
||||
try {
|
||||
return list.apply(tlr);
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot list groups", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public QueryRequest query() {
|
||||
return new QueryRequest() {
|
||||
@Override
|
||||
public List<GroupInfo> get() throws RestApiException {
|
||||
return GroupsImpl.this.query(this);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public QueryRequest query(String query) {
|
||||
return query().withQuery(query);
|
||||
}
|
||||
|
||||
private List<GroupInfo> query(QueryRequest r) throws RestApiException {
|
||||
try {
|
||||
QueryGroups myQueryGroups = queryGroups.get();
|
||||
myQueryGroups.setQuery(r.getQuery());
|
||||
myQueryGroups.setLimit(r.getLimit());
|
||||
myQueryGroups.setStart(r.getStart());
|
||||
for (ListGroupsOption option : r.getOptions()) {
|
||||
myQueryGroups.addOption(option);
|
||||
}
|
||||
return myQueryGroups.apply(TopLevelResource.INSTANCE);
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot query groups", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
27
java/com/google/gerrit/server/api/groups/Module.java
Normal file
27
java/com/google/gerrit/server/api/groups/Module.java
Normal file
@@ -0,0 +1,27 @@
|
||||
// Copyright (C) 2015 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.server.api.groups;
|
||||
|
||||
import com.google.gerrit.extensions.api.groups.Groups;
|
||||
import com.google.gerrit.extensions.config.FactoryModule;
|
||||
|
||||
public class Module extends FactoryModule {
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(Groups.class).to(GroupsImpl.class);
|
||||
|
||||
factory(GroupApiImpl.Factory.class);
|
||||
}
|
||||
}
|
||||
73
java/com/google/gerrit/server/api/plugins/PluginApiImpl.java
Normal file
73
java/com/google/gerrit/server/api/plugins/PluginApiImpl.java
Normal file
@@ -0,0 +1,73 @@
|
||||
// Copyright (C) 2017 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.server.api.plugins;
|
||||
|
||||
import com.google.gerrit.extensions.api.plugins.PluginApi;
|
||||
import com.google.gerrit.extensions.common.Input;
|
||||
import com.google.gerrit.extensions.common.PluginInfo;
|
||||
import com.google.gerrit.extensions.restapi.RestApiException;
|
||||
import com.google.gerrit.server.plugins.DisablePlugin;
|
||||
import com.google.gerrit.server.plugins.EnablePlugin;
|
||||
import com.google.gerrit.server.plugins.GetStatus;
|
||||
import com.google.gerrit.server.plugins.PluginResource;
|
||||
import com.google.gerrit.server.plugins.ReloadPlugin;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.assistedinject.Assisted;
|
||||
|
||||
public class PluginApiImpl implements PluginApi {
|
||||
public interface Factory {
|
||||
PluginApiImpl create(PluginResource resource);
|
||||
}
|
||||
|
||||
private final GetStatus getStatus;
|
||||
private final EnablePlugin enable;
|
||||
private final DisablePlugin disable;
|
||||
private final ReloadPlugin reload;
|
||||
private final PluginResource resource;
|
||||
|
||||
@Inject
|
||||
PluginApiImpl(
|
||||
GetStatus getStatus,
|
||||
EnablePlugin enable,
|
||||
DisablePlugin disable,
|
||||
ReloadPlugin reload,
|
||||
@Assisted PluginResource resource) {
|
||||
this.getStatus = getStatus;
|
||||
this.enable = enable;
|
||||
this.disable = disable;
|
||||
this.reload = reload;
|
||||
this.resource = resource;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PluginInfo get() throws RestApiException {
|
||||
return getStatus.apply(resource);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enable() throws RestApiException {
|
||||
enable.apply(resource, new Input());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disable() throws RestApiException {
|
||||
disable.apply(resource, new Input());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reload() throws RestApiException {
|
||||
reload.apply(resource, new Input());
|
||||
}
|
||||
}
|
||||
77
java/com/google/gerrit/server/api/plugins/PluginsImpl.java
Normal file
77
java/com/google/gerrit/server/api/plugins/PluginsImpl.java
Normal file
@@ -0,0 +1,77 @@
|
||||
// Copyright (C) 2017 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.server.api.plugins;
|
||||
|
||||
import com.google.gerrit.extensions.api.plugins.PluginApi;
|
||||
import com.google.gerrit.extensions.api.plugins.Plugins;
|
||||
import com.google.gerrit.extensions.common.InstallPluginInput;
|
||||
import com.google.gerrit.extensions.common.PluginInfo;
|
||||
import com.google.gerrit.extensions.restapi.Response;
|
||||
import com.google.gerrit.extensions.restapi.RestApiException;
|
||||
import com.google.gerrit.extensions.restapi.TopLevelResource;
|
||||
import com.google.gerrit.server.plugins.InstallPlugin;
|
||||
import com.google.gerrit.server.plugins.ListPlugins;
|
||||
import com.google.gerrit.server.plugins.PluginsCollection;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Provider;
|
||||
import com.google.inject.Singleton;
|
||||
import java.io.IOException;
|
||||
import java.util.SortedMap;
|
||||
|
||||
@Singleton
|
||||
public class PluginsImpl implements Plugins {
|
||||
private final PluginsCollection plugins;
|
||||
private final Provider<ListPlugins> listProvider;
|
||||
private final Provider<InstallPlugin> installProvider;
|
||||
private final PluginApiImpl.Factory pluginApi;
|
||||
|
||||
@Inject
|
||||
PluginsImpl(
|
||||
PluginsCollection plugins,
|
||||
Provider<ListPlugins> listProvider,
|
||||
Provider<InstallPlugin> installProvider,
|
||||
PluginApiImpl.Factory pluginApi) {
|
||||
this.plugins = plugins;
|
||||
this.listProvider = listProvider;
|
||||
this.installProvider = installProvider;
|
||||
this.pluginApi = pluginApi;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PluginApi name(String name) throws RestApiException {
|
||||
return pluginApi.create(plugins.parse(name));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ListRequest list() {
|
||||
return new ListRequest() {
|
||||
@Override
|
||||
public SortedMap<String, PluginInfo> getAsMap() throws RestApiException {
|
||||
return listProvider.get().request(this).apply(TopLevelResource.INSTANCE);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public PluginApi install(String name, InstallPluginInput input) throws RestApiException {
|
||||
try {
|
||||
Response<PluginInfo> created =
|
||||
installProvider.get().setName(name).apply(TopLevelResource.INSTANCE, input);
|
||||
return pluginApi.create(plugins.parse(created.value().id));
|
||||
} catch (IOException e) {
|
||||
throw new RestApiException("could not install plugin", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
131
java/com/google/gerrit/server/api/projects/BranchApiImpl.java
Normal file
131
java/com/google/gerrit/server/api/projects/BranchApiImpl.java
Normal file
@@ -0,0 +1,131 @@
|
||||
// Copyright (C) 2013 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.server.api.projects;
|
||||
|
||||
import static com.google.gerrit.server.api.ApiUtil.asRestApiException;
|
||||
|
||||
import com.google.gerrit.extensions.api.projects.BranchApi;
|
||||
import com.google.gerrit.extensions.api.projects.BranchInfo;
|
||||
import com.google.gerrit.extensions.api.projects.BranchInput;
|
||||
import com.google.gerrit.extensions.api.projects.ReflogEntryInfo;
|
||||
import com.google.gerrit.extensions.common.Input;
|
||||
import com.google.gerrit.extensions.restapi.BinaryResult;
|
||||
import com.google.gerrit.extensions.restapi.IdString;
|
||||
import com.google.gerrit.extensions.restapi.RestApiException;
|
||||
import com.google.gerrit.server.permissions.PermissionBackendException;
|
||||
import com.google.gerrit.server.project.BranchResource;
|
||||
import com.google.gerrit.server.project.BranchesCollection;
|
||||
import com.google.gerrit.server.project.CreateBranch;
|
||||
import com.google.gerrit.server.project.DeleteBranch;
|
||||
import com.google.gerrit.server.project.FileResource;
|
||||
import com.google.gerrit.server.project.FilesCollection;
|
||||
import com.google.gerrit.server.project.GetBranch;
|
||||
import com.google.gerrit.server.project.GetContent;
|
||||
import com.google.gerrit.server.project.GetReflog;
|
||||
import com.google.gerrit.server.project.ProjectResource;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.assistedinject.Assisted;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
public class BranchApiImpl implements BranchApi {
|
||||
interface Factory {
|
||||
BranchApiImpl create(ProjectResource project, String ref);
|
||||
}
|
||||
|
||||
private final BranchesCollection branches;
|
||||
private final CreateBranch.Factory createBranchFactory;
|
||||
private final DeleteBranch deleteBranch;
|
||||
private final FilesCollection filesCollection;
|
||||
private final GetBranch getBranch;
|
||||
private final GetContent getContent;
|
||||
private final GetReflog getReflog;
|
||||
private final String ref;
|
||||
private final ProjectResource project;
|
||||
|
||||
@Inject
|
||||
BranchApiImpl(
|
||||
BranchesCollection branches,
|
||||
CreateBranch.Factory createBranchFactory,
|
||||
DeleteBranch deleteBranch,
|
||||
FilesCollection filesCollection,
|
||||
GetBranch getBranch,
|
||||
GetContent getContent,
|
||||
GetReflog getReflog,
|
||||
@Assisted ProjectResource project,
|
||||
@Assisted String ref) {
|
||||
this.branches = branches;
|
||||
this.createBranchFactory = createBranchFactory;
|
||||
this.deleteBranch = deleteBranch;
|
||||
this.filesCollection = filesCollection;
|
||||
this.getBranch = getBranch;
|
||||
this.getContent = getContent;
|
||||
this.getReflog = getReflog;
|
||||
this.project = project;
|
||||
this.ref = ref;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BranchApi create(BranchInput input) throws RestApiException {
|
||||
try {
|
||||
createBranchFactory.create(ref).apply(project, input);
|
||||
return this;
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot create branch", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public BranchInfo get() throws RestApiException {
|
||||
try {
|
||||
return getBranch.apply(resource());
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot read branch", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete() throws RestApiException {
|
||||
try {
|
||||
deleteBranch.apply(resource(), new Input());
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot delete branch", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public BinaryResult file(String path) throws RestApiException {
|
||||
try {
|
||||
FileResource resource = filesCollection.parse(resource(), IdString.fromDecoded(path));
|
||||
return getContent.apply(resource);
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot retrieve file", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ReflogEntryInfo> reflog() throws RestApiException {
|
||||
try {
|
||||
return getReflog.apply(resource());
|
||||
} catch (IOException | PermissionBackendException e) {
|
||||
throw new RestApiException("Cannot retrieve reflog", e);
|
||||
}
|
||||
}
|
||||
|
||||
private BranchResource resource()
|
||||
throws RestApiException, IOException, PermissionBackendException {
|
||||
return branches.parse(project, IdString.fromDecoded(ref));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
// Copyright (C) 2015 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.server.api.projects;
|
||||
|
||||
import com.google.gerrit.extensions.api.projects.ChildProjectApi;
|
||||
import com.google.gerrit.extensions.common.ProjectInfo;
|
||||
import com.google.gerrit.extensions.restapi.RestApiException;
|
||||
import com.google.gerrit.server.project.ChildProjectResource;
|
||||
import com.google.gerrit.server.project.GetChildProject;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.assistedinject.Assisted;
|
||||
|
||||
public class ChildProjectApiImpl implements ChildProjectApi {
|
||||
interface Factory {
|
||||
ChildProjectApiImpl create(ChildProjectResource rsrc);
|
||||
}
|
||||
|
||||
private final GetChildProject getChildProject;
|
||||
private final ChildProjectResource rsrc;
|
||||
|
||||
@Inject
|
||||
ChildProjectApiImpl(GetChildProject getChildProject, @Assisted ChildProjectResource rsrc) {
|
||||
this.getChildProject = getChildProject;
|
||||
this.rsrc = rsrc;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProjectInfo get() throws RestApiException {
|
||||
return get(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProjectInfo get(boolean recursive) throws RestApiException {
|
||||
getChildProject.setRecursive(recursive);
|
||||
return getChildProject.apply(rsrc);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
// Copyright (C) 2017 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.server.api.projects;
|
||||
|
||||
import static com.google.gerrit.server.api.ApiUtil.asRestApiException;
|
||||
|
||||
import com.google.gerrit.extensions.api.changes.ChangeApi;
|
||||
import com.google.gerrit.extensions.api.changes.Changes;
|
||||
import com.google.gerrit.extensions.api.changes.CherryPickInput;
|
||||
import com.google.gerrit.extensions.api.projects.CommitApi;
|
||||
import com.google.gerrit.extensions.restapi.RestApiException;
|
||||
import com.google.gerrit.server.change.CherryPickCommit;
|
||||
import com.google.gerrit.server.project.CommitResource;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.assistedinject.Assisted;
|
||||
|
||||
public class CommitApiImpl implements CommitApi {
|
||||
public interface Factory {
|
||||
CommitApiImpl create(CommitResource r);
|
||||
}
|
||||
|
||||
private final Changes changes;
|
||||
private final CherryPickCommit cherryPickCommit;
|
||||
private final CommitResource commitResource;
|
||||
|
||||
@Inject
|
||||
CommitApiImpl(
|
||||
Changes changes, CherryPickCommit cherryPickCommit, @Assisted CommitResource commitResource) {
|
||||
this.changes = changes;
|
||||
this.cherryPickCommit = cherryPickCommit;
|
||||
this.commitResource = commitResource;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChangeApi cherryPick(CherryPickInput input) throws RestApiException {
|
||||
try {
|
||||
return changes.id(cherryPickCommit.apply(commitResource, input)._number);
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot cherry pick", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
// Copyright (C) 2017 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.server.api.projects;
|
||||
|
||||
import static com.google.gerrit.server.api.ApiUtil.asRestApiException;
|
||||
|
||||
import com.google.gerrit.common.Nullable;
|
||||
import com.google.gerrit.extensions.api.projects.DashboardApi;
|
||||
import com.google.gerrit.extensions.api.projects.DashboardInfo;
|
||||
import com.google.gerrit.extensions.common.SetDashboardInput;
|
||||
import com.google.gerrit.extensions.restapi.IdString;
|
||||
import com.google.gerrit.extensions.restapi.ResourceNotFoundException;
|
||||
import com.google.gerrit.extensions.restapi.RestApiException;
|
||||
import com.google.gerrit.server.permissions.PermissionBackendException;
|
||||
import com.google.gerrit.server.project.DashboardResource;
|
||||
import com.google.gerrit.server.project.DashboardsCollection;
|
||||
import com.google.gerrit.server.project.GetDashboard;
|
||||
import com.google.gerrit.server.project.ProjectResource;
|
||||
import com.google.gerrit.server.project.SetDashboard;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Provider;
|
||||
import com.google.inject.assistedinject.Assisted;
|
||||
import java.io.IOException;
|
||||
import org.eclipse.jgit.errors.ConfigInvalidException;
|
||||
|
||||
public class DashboardApiImpl implements DashboardApi {
|
||||
interface Factory {
|
||||
DashboardApiImpl create(ProjectResource project, String id);
|
||||
}
|
||||
|
||||
private final DashboardsCollection dashboards;
|
||||
private final Provider<GetDashboard> get;
|
||||
private final SetDashboard set;
|
||||
private final ProjectResource project;
|
||||
private final String id;
|
||||
|
||||
@Inject
|
||||
DashboardApiImpl(
|
||||
DashboardsCollection dashboards,
|
||||
Provider<GetDashboard> get,
|
||||
SetDashboard set,
|
||||
@Assisted ProjectResource project,
|
||||
@Assisted @Nullable String id) {
|
||||
this.dashboards = dashboards;
|
||||
this.get = get;
|
||||
this.set = set;
|
||||
this.project = project;
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DashboardInfo get() throws RestApiException {
|
||||
return get(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DashboardInfo get(boolean inherited) throws RestApiException {
|
||||
try {
|
||||
return get.get().setInherited(inherited).apply(resource());
|
||||
} catch (IOException | PermissionBackendException | ConfigInvalidException e) {
|
||||
throw asRestApiException("Cannot read dashboard", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDefault() throws RestApiException {
|
||||
SetDashboardInput input = new SetDashboardInput();
|
||||
input.id = id;
|
||||
try {
|
||||
set.apply(
|
||||
DashboardResource.projectDefault(project.getProjectState(), project.getUser()), input);
|
||||
} catch (Exception e) {
|
||||
String msg = String.format("Cannot %s default dashboard", id != null ? "set" : "remove");
|
||||
throw asRestApiException(msg, e);
|
||||
}
|
||||
}
|
||||
|
||||
private DashboardResource resource()
|
||||
throws ResourceNotFoundException, IOException, ConfigInvalidException,
|
||||
PermissionBackendException {
|
||||
return dashboards.parse(project, IdString.fromDecoded(id));
|
||||
}
|
||||
}
|
||||
32
java/com/google/gerrit/server/api/projects/Module.java
Normal file
32
java/com/google/gerrit/server/api/projects/Module.java
Normal file
@@ -0,0 +1,32 @@
|
||||
// Copyright (C) 2013 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.server.api.projects;
|
||||
|
||||
import com.google.gerrit.extensions.api.projects.Projects;
|
||||
import com.google.gerrit.extensions.config.FactoryModule;
|
||||
|
||||
public class Module extends FactoryModule {
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(Projects.class).to(ProjectsImpl.class);
|
||||
|
||||
factory(BranchApiImpl.Factory.class);
|
||||
factory(TagApiImpl.Factory.class);
|
||||
factory(ProjectApiImpl.Factory.class);
|
||||
factory(ChildProjectApiImpl.Factory.class);
|
||||
factory(CommitApiImpl.Factory.class);
|
||||
factory(DashboardApiImpl.Factory.class);
|
||||
}
|
||||
}
|
||||
611
java/com/google/gerrit/server/api/projects/ProjectApiImpl.java
Normal file
611
java/com/google/gerrit/server/api/projects/ProjectApiImpl.java
Normal file
@@ -0,0 +1,611 @@
|
||||
// Copyright (C) 2013 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.server.api.projects;
|
||||
|
||||
import static com.google.gerrit.server.api.ApiUtil.asRestApiException;
|
||||
import static com.google.gerrit.server.project.DashboardsCollection.DEFAULT_DASHBOARD_NAME;
|
||||
import static java.util.stream.Collectors.toList;
|
||||
|
||||
import com.google.gerrit.extensions.api.access.ProjectAccessInfo;
|
||||
import com.google.gerrit.extensions.api.access.ProjectAccessInput;
|
||||
import com.google.gerrit.extensions.api.config.AccessCheckInfo;
|
||||
import com.google.gerrit.extensions.api.config.AccessCheckInput;
|
||||
import com.google.gerrit.extensions.api.projects.BranchApi;
|
||||
import com.google.gerrit.extensions.api.projects.BranchInfo;
|
||||
import com.google.gerrit.extensions.api.projects.ChildProjectApi;
|
||||
import com.google.gerrit.extensions.api.projects.CommitApi;
|
||||
import com.google.gerrit.extensions.api.projects.ConfigInfo;
|
||||
import com.google.gerrit.extensions.api.projects.ConfigInput;
|
||||
import com.google.gerrit.extensions.api.projects.DashboardApi;
|
||||
import com.google.gerrit.extensions.api.projects.DashboardInfo;
|
||||
import com.google.gerrit.extensions.api.projects.DeleteBranchesInput;
|
||||
import com.google.gerrit.extensions.api.projects.DeleteTagsInput;
|
||||
import com.google.gerrit.extensions.api.projects.DescriptionInput;
|
||||
import com.google.gerrit.extensions.api.projects.HeadInput;
|
||||
import com.google.gerrit.extensions.api.projects.ParentInput;
|
||||
import com.google.gerrit.extensions.api.projects.ProjectApi;
|
||||
import com.google.gerrit.extensions.api.projects.ProjectInput;
|
||||
import com.google.gerrit.extensions.api.projects.TagApi;
|
||||
import com.google.gerrit.extensions.api.projects.TagInfo;
|
||||
import com.google.gerrit.extensions.common.ChangeInfo;
|
||||
import com.google.gerrit.extensions.common.ProjectInfo;
|
||||
import com.google.gerrit.extensions.restapi.BadRequestException;
|
||||
import com.google.gerrit.extensions.restapi.IdString;
|
||||
import com.google.gerrit.extensions.restapi.NotImplementedException;
|
||||
import com.google.gerrit.extensions.restapi.ResourceConflictException;
|
||||
import com.google.gerrit.extensions.restapi.ResourceNotFoundException;
|
||||
import com.google.gerrit.extensions.restapi.RestApiException;
|
||||
import com.google.gerrit.extensions.restapi.TopLevelResource;
|
||||
import com.google.gerrit.server.CurrentUser;
|
||||
import com.google.gerrit.server.permissions.GlobalPermission;
|
||||
import com.google.gerrit.server.permissions.PermissionBackend;
|
||||
import com.google.gerrit.server.project.CheckAccess;
|
||||
import com.google.gerrit.server.project.ChildProjectsCollection;
|
||||
import com.google.gerrit.server.project.CommitsCollection;
|
||||
import com.google.gerrit.server.project.CreateAccessChange;
|
||||
import com.google.gerrit.server.project.CreateProject;
|
||||
import com.google.gerrit.server.project.DeleteBranches;
|
||||
import com.google.gerrit.server.project.DeleteTags;
|
||||
import com.google.gerrit.server.project.GetAccess;
|
||||
import com.google.gerrit.server.project.GetConfig;
|
||||
import com.google.gerrit.server.project.GetDescription;
|
||||
import com.google.gerrit.server.project.GetHead;
|
||||
import com.google.gerrit.server.project.GetParent;
|
||||
import com.google.gerrit.server.project.ListBranches;
|
||||
import com.google.gerrit.server.project.ListChildProjects;
|
||||
import com.google.gerrit.server.project.ListDashboards;
|
||||
import com.google.gerrit.server.project.ListTags;
|
||||
import com.google.gerrit.server.project.ProjectJson;
|
||||
import com.google.gerrit.server.project.ProjectResource;
|
||||
import com.google.gerrit.server.project.ProjectsCollection;
|
||||
import com.google.gerrit.server.project.PutConfig;
|
||||
import com.google.gerrit.server.project.PutDescription;
|
||||
import com.google.gerrit.server.project.SetAccess;
|
||||
import com.google.gerrit.server.project.SetHead;
|
||||
import com.google.gerrit.server.project.SetParent;
|
||||
import com.google.inject.Provider;
|
||||
import com.google.inject.assistedinject.Assisted;
|
||||
import com.google.inject.assistedinject.AssistedInject;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class ProjectApiImpl implements ProjectApi {
|
||||
interface Factory {
|
||||
ProjectApiImpl create(ProjectResource project);
|
||||
|
||||
ProjectApiImpl create(String name);
|
||||
}
|
||||
|
||||
private final CurrentUser user;
|
||||
private final PermissionBackend permissionBackend;
|
||||
private final CreateProject.Factory createProjectFactory;
|
||||
private final ProjectApiImpl.Factory projectApi;
|
||||
private final ProjectsCollection projects;
|
||||
private final GetDescription getDescription;
|
||||
private final PutDescription putDescription;
|
||||
private final ChildProjectApiImpl.Factory childApi;
|
||||
private final ChildProjectsCollection children;
|
||||
private final ProjectResource project;
|
||||
private final ProjectJson projectJson;
|
||||
private final String name;
|
||||
private final BranchApiImpl.Factory branchApi;
|
||||
private final TagApiImpl.Factory tagApi;
|
||||
private final GetAccess getAccess;
|
||||
private final SetAccess setAccess;
|
||||
private final CreateAccessChange createAccessChange;
|
||||
private final GetConfig getConfig;
|
||||
private final PutConfig putConfig;
|
||||
private final Provider<ListBranches> listBranches;
|
||||
private final Provider<ListTags> listTags;
|
||||
private final DeleteBranches deleteBranches;
|
||||
private final DeleteTags deleteTags;
|
||||
private final CommitsCollection commitsCollection;
|
||||
private final CommitApiImpl.Factory commitApi;
|
||||
private final DashboardApiImpl.Factory dashboardApi;
|
||||
private final CheckAccess checkAccess;
|
||||
private final Provider<ListDashboards> listDashboards;
|
||||
private final GetHead getHead;
|
||||
private final SetHead setHead;
|
||||
private final GetParent getParent;
|
||||
private final SetParent setParent;
|
||||
|
||||
@AssistedInject
|
||||
ProjectApiImpl(
|
||||
CurrentUser user,
|
||||
PermissionBackend permissionBackend,
|
||||
CreateProject.Factory createProjectFactory,
|
||||
ProjectApiImpl.Factory projectApi,
|
||||
ProjectsCollection projects,
|
||||
GetDescription getDescription,
|
||||
PutDescription putDescription,
|
||||
ChildProjectApiImpl.Factory childApi,
|
||||
ChildProjectsCollection children,
|
||||
ProjectJson projectJson,
|
||||
BranchApiImpl.Factory branchApiFactory,
|
||||
TagApiImpl.Factory tagApiFactory,
|
||||
GetAccess getAccess,
|
||||
SetAccess setAccess,
|
||||
CreateAccessChange createAccessChange,
|
||||
GetConfig getConfig,
|
||||
PutConfig putConfig,
|
||||
Provider<ListBranches> listBranches,
|
||||
Provider<ListTags> listTags,
|
||||
DeleteBranches deleteBranches,
|
||||
DeleteTags deleteTags,
|
||||
CommitsCollection commitsCollection,
|
||||
CommitApiImpl.Factory commitApi,
|
||||
DashboardApiImpl.Factory dashboardApi,
|
||||
CheckAccess checkAccess,
|
||||
Provider<ListDashboards> listDashboards,
|
||||
GetHead getHead,
|
||||
SetHead setHead,
|
||||
GetParent getParent,
|
||||
SetParent setParent,
|
||||
@Assisted ProjectResource project) {
|
||||
this(
|
||||
user,
|
||||
permissionBackend,
|
||||
createProjectFactory,
|
||||
projectApi,
|
||||
projects,
|
||||
getDescription,
|
||||
putDescription,
|
||||
childApi,
|
||||
children,
|
||||
projectJson,
|
||||
branchApiFactory,
|
||||
tagApiFactory,
|
||||
getAccess,
|
||||
setAccess,
|
||||
createAccessChange,
|
||||
getConfig,
|
||||
putConfig,
|
||||
listBranches,
|
||||
listTags,
|
||||
deleteBranches,
|
||||
deleteTags,
|
||||
project,
|
||||
commitsCollection,
|
||||
commitApi,
|
||||
dashboardApi,
|
||||
checkAccess,
|
||||
listDashboards,
|
||||
getHead,
|
||||
setHead,
|
||||
getParent,
|
||||
setParent,
|
||||
null);
|
||||
}
|
||||
|
||||
@AssistedInject
|
||||
ProjectApiImpl(
|
||||
CurrentUser user,
|
||||
PermissionBackend permissionBackend,
|
||||
CreateProject.Factory createProjectFactory,
|
||||
ProjectApiImpl.Factory projectApi,
|
||||
ProjectsCollection projects,
|
||||
GetDescription getDescription,
|
||||
PutDescription putDescription,
|
||||
ChildProjectApiImpl.Factory childApi,
|
||||
ChildProjectsCollection children,
|
||||
ProjectJson projectJson,
|
||||
BranchApiImpl.Factory branchApiFactory,
|
||||
TagApiImpl.Factory tagApiFactory,
|
||||
GetAccess getAccess,
|
||||
SetAccess setAccess,
|
||||
CreateAccessChange createAccessChange,
|
||||
GetConfig getConfig,
|
||||
PutConfig putConfig,
|
||||
Provider<ListBranches> listBranches,
|
||||
Provider<ListTags> listTags,
|
||||
DeleteBranches deleteBranches,
|
||||
DeleteTags deleteTags,
|
||||
CommitsCollection commitsCollection,
|
||||
CommitApiImpl.Factory commitApi,
|
||||
DashboardApiImpl.Factory dashboardApi,
|
||||
CheckAccess checkAccess,
|
||||
Provider<ListDashboards> listDashboards,
|
||||
GetHead getHead,
|
||||
SetHead setHead,
|
||||
GetParent getParent,
|
||||
SetParent setParent,
|
||||
@Assisted String name) {
|
||||
this(
|
||||
user,
|
||||
permissionBackend,
|
||||
createProjectFactory,
|
||||
projectApi,
|
||||
projects,
|
||||
getDescription,
|
||||
putDescription,
|
||||
childApi,
|
||||
children,
|
||||
projectJson,
|
||||
branchApiFactory,
|
||||
tagApiFactory,
|
||||
getAccess,
|
||||
setAccess,
|
||||
createAccessChange,
|
||||
getConfig,
|
||||
putConfig,
|
||||
listBranches,
|
||||
listTags,
|
||||
deleteBranches,
|
||||
deleteTags,
|
||||
null,
|
||||
commitsCollection,
|
||||
commitApi,
|
||||
dashboardApi,
|
||||
checkAccess,
|
||||
listDashboards,
|
||||
getHead,
|
||||
setHead,
|
||||
getParent,
|
||||
setParent,
|
||||
name);
|
||||
}
|
||||
|
||||
private ProjectApiImpl(
|
||||
CurrentUser user,
|
||||
PermissionBackend permissionBackend,
|
||||
CreateProject.Factory createProjectFactory,
|
||||
ProjectApiImpl.Factory projectApi,
|
||||
ProjectsCollection projects,
|
||||
GetDescription getDescription,
|
||||
PutDescription putDescription,
|
||||
ChildProjectApiImpl.Factory childApi,
|
||||
ChildProjectsCollection children,
|
||||
ProjectJson projectJson,
|
||||
BranchApiImpl.Factory branchApiFactory,
|
||||
TagApiImpl.Factory tagApiFactory,
|
||||
GetAccess getAccess,
|
||||
SetAccess setAccess,
|
||||
CreateAccessChange createAccessChange,
|
||||
GetConfig getConfig,
|
||||
PutConfig putConfig,
|
||||
Provider<ListBranches> listBranches,
|
||||
Provider<ListTags> listTags,
|
||||
DeleteBranches deleteBranches,
|
||||
DeleteTags deleteTags,
|
||||
ProjectResource project,
|
||||
CommitsCollection commitsCollection,
|
||||
CommitApiImpl.Factory commitApi,
|
||||
DashboardApiImpl.Factory dashboardApi,
|
||||
CheckAccess checkAccess,
|
||||
Provider<ListDashboards> listDashboards,
|
||||
GetHead getHead,
|
||||
SetHead setHead,
|
||||
GetParent getParent,
|
||||
SetParent setParent,
|
||||
String name) {
|
||||
this.user = user;
|
||||
this.permissionBackend = permissionBackend;
|
||||
this.createProjectFactory = createProjectFactory;
|
||||
this.projectApi = projectApi;
|
||||
this.projects = projects;
|
||||
this.getDescription = getDescription;
|
||||
this.putDescription = putDescription;
|
||||
this.childApi = childApi;
|
||||
this.children = children;
|
||||
this.projectJson = projectJson;
|
||||
this.project = project;
|
||||
this.branchApi = branchApiFactory;
|
||||
this.tagApi = tagApiFactory;
|
||||
this.getAccess = getAccess;
|
||||
this.setAccess = setAccess;
|
||||
this.getConfig = getConfig;
|
||||
this.putConfig = putConfig;
|
||||
this.listBranches = listBranches;
|
||||
this.listTags = listTags;
|
||||
this.deleteBranches = deleteBranches;
|
||||
this.deleteTags = deleteTags;
|
||||
this.commitsCollection = commitsCollection;
|
||||
this.commitApi = commitApi;
|
||||
this.createAccessChange = createAccessChange;
|
||||
this.dashboardApi = dashboardApi;
|
||||
this.checkAccess = checkAccess;
|
||||
this.listDashboards = listDashboards;
|
||||
this.getHead = getHead;
|
||||
this.setHead = setHead;
|
||||
this.getParent = getParent;
|
||||
this.setParent = setParent;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProjectApi create() throws RestApiException {
|
||||
return create(new ProjectInput());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProjectApi create(ProjectInput in) throws RestApiException {
|
||||
try {
|
||||
if (name == null) {
|
||||
throw new ResourceConflictException("Project already exists");
|
||||
}
|
||||
if (in.name != null && !name.equals(in.name)) {
|
||||
throw new BadRequestException("name must match input.name");
|
||||
}
|
||||
CreateProject impl = createProjectFactory.create(name);
|
||||
permissionBackend.user(user).checkAny(GlobalPermission.fromAnnotation(impl.getClass()));
|
||||
impl.apply(TopLevelResource.INSTANCE, in);
|
||||
return projectApi.create(projects.parse(name));
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot create project: " + e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProjectInfo get() throws RestApiException {
|
||||
if (project == null) {
|
||||
throw new ResourceNotFoundException(name);
|
||||
}
|
||||
return projectJson.format(project.getProjectState());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String description() throws RestApiException {
|
||||
return getDescription.apply(checkExists());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProjectAccessInfo access() throws RestApiException {
|
||||
try {
|
||||
return getAccess.apply(checkExists());
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot get access rights", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public AccessCheckInfo checkAccess(AccessCheckInput in) throws RestApiException {
|
||||
try {
|
||||
return checkAccess.apply(checkExists(), in);
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot check access rights", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProjectAccessInfo access(ProjectAccessInput p) throws RestApiException {
|
||||
try {
|
||||
return setAccess.apply(checkExists(), p);
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot put access rights", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChangeInfo accessChange(ProjectAccessInput p) throws RestApiException {
|
||||
try {
|
||||
return createAccessChange.apply(checkExists(), p).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot put access right change", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void description(DescriptionInput in) throws RestApiException {
|
||||
try {
|
||||
putDescription.apply(checkExists(), in);
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot put project description", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConfigInfo config() throws RestApiException {
|
||||
return getConfig.apply(checkExists());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConfigInfo config(ConfigInput in) throws RestApiException {
|
||||
try {
|
||||
return putConfig.apply(checkExists(), in);
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot list tags", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ListRefsRequest<BranchInfo> branches() {
|
||||
return new ListRefsRequest<BranchInfo>() {
|
||||
@Override
|
||||
public List<BranchInfo> get() throws RestApiException {
|
||||
try {
|
||||
return listBranches.get().request(this).apply(checkExists());
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot list branches", e);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public ListRefsRequest<TagInfo> tags() {
|
||||
return new ListRefsRequest<TagInfo>() {
|
||||
@Override
|
||||
public List<TagInfo> get() throws RestApiException {
|
||||
try {
|
||||
return listTags.get().request(this).apply(checkExists());
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot list tags", e);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ProjectInfo> children() throws RestApiException {
|
||||
return children(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ProjectInfo> children(boolean recursive) throws RestApiException {
|
||||
ListChildProjects list = children.list();
|
||||
list.setRecursive(recursive);
|
||||
try {
|
||||
return list.apply(checkExists());
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot list children", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChildProjectApi child(String name) throws RestApiException {
|
||||
try {
|
||||
return childApi.create(children.parse(checkExists(), IdString.fromDecoded(name)));
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot parse child project", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public BranchApi branch(String ref) throws ResourceNotFoundException {
|
||||
return branchApi.create(checkExists(), ref);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TagApi tag(String ref) throws ResourceNotFoundException {
|
||||
return tagApi.create(checkExists(), ref);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteBranches(DeleteBranchesInput in) throws RestApiException {
|
||||
try {
|
||||
deleteBranches.apply(checkExists(), in);
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot delete branches", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteTags(DeleteTagsInput in) throws RestApiException {
|
||||
try {
|
||||
deleteTags.apply(checkExists(), in);
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot delete tags", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommitApi commit(String commit) throws RestApiException {
|
||||
try {
|
||||
return commitApi.create(commitsCollection.parse(checkExists(), IdString.fromDecoded(commit)));
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot parse commit", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public DashboardApi dashboard(String name) throws RestApiException {
|
||||
try {
|
||||
return dashboardApi.create(checkExists(), name);
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot parse dashboard", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public DashboardApi defaultDashboard() throws RestApiException {
|
||||
return dashboard(DEFAULT_DASHBOARD_NAME);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void defaultDashboard(String name) throws RestApiException {
|
||||
try {
|
||||
dashboardApi.create(checkExists(), name).setDefault();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot set default dashboard", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeDefaultDashboard() throws RestApiException {
|
||||
try {
|
||||
dashboardApi.create(checkExists(), null).setDefault();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot remove default dashboard", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ListDashboardsRequest dashboards() throws RestApiException {
|
||||
return new ListDashboardsRequest() {
|
||||
@Override
|
||||
public List<DashboardInfo> get() throws RestApiException {
|
||||
try {
|
||||
List<?> r = listDashboards.get().apply(checkExists());
|
||||
if (r.isEmpty()) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
if (r.get(0) instanceof DashboardInfo) {
|
||||
return r.stream().map(i -> (DashboardInfo) i).collect(toList());
|
||||
}
|
||||
throw new NotImplementedException("list with inheritance");
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot list dashboards", e);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public String head() throws RestApiException {
|
||||
try {
|
||||
return getHead.apply(checkExists());
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot get HEAD", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void head(String head) throws RestApiException {
|
||||
HeadInput input = new HeadInput();
|
||||
input.ref = head;
|
||||
try {
|
||||
setHead.apply(checkExists(), input);
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot set HEAD", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String parent() throws RestApiException {
|
||||
try {
|
||||
return getParent.apply(checkExists());
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot get parent", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void parent(String parent) throws RestApiException {
|
||||
try {
|
||||
ParentInput input = new ParentInput();
|
||||
input.parent = parent;
|
||||
setParent.apply(checkExists(), input);
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot set parent", e);
|
||||
}
|
||||
}
|
||||
|
||||
private ProjectResource checkExists() throws ResourceNotFoundException {
|
||||
if (project == null) {
|
||||
throw new ResourceNotFoundException(name);
|
||||
}
|
||||
return project;
|
||||
}
|
||||
}
|
||||
162
java/com/google/gerrit/server/api/projects/ProjectsImpl.java
Normal file
162
java/com/google/gerrit/server/api/projects/ProjectsImpl.java
Normal file
@@ -0,0 +1,162 @@
|
||||
// Copyright (C) 2013 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.server.api.projects;
|
||||
|
||||
import static com.google.gerrit.server.api.ApiUtil.asRestApiException;
|
||||
|
||||
import com.google.gerrit.extensions.api.projects.ProjectApi;
|
||||
import com.google.gerrit.extensions.api.projects.ProjectInput;
|
||||
import com.google.gerrit.extensions.api.projects.Projects;
|
||||
import com.google.gerrit.extensions.common.ProjectInfo;
|
||||
import com.google.gerrit.extensions.restapi.BadRequestException;
|
||||
import com.google.gerrit.extensions.restapi.RestApiException;
|
||||
import com.google.gerrit.extensions.restapi.TopLevelResource;
|
||||
import com.google.gerrit.extensions.restapi.UnprocessableEntityException;
|
||||
import com.google.gerrit.server.permissions.PermissionBackendException;
|
||||
import com.google.gerrit.server.project.ListProjects;
|
||||
import com.google.gerrit.server.project.ListProjects.FilterType;
|
||||
import com.google.gerrit.server.project.ProjectsCollection;
|
||||
import com.google.gerrit.server.project.QueryProjects;
|
||||
import com.google.gwtorm.server.OrmException;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Provider;
|
||||
import com.google.inject.Singleton;
|
||||
import java.util.List;
|
||||
import java.util.SortedMap;
|
||||
|
||||
@Singleton
|
||||
class ProjectsImpl implements Projects {
|
||||
private final ProjectsCollection projects;
|
||||
private final ProjectApiImpl.Factory api;
|
||||
private final Provider<ListProjects> listProvider;
|
||||
private final Provider<QueryProjects> queryProvider;
|
||||
|
||||
@Inject
|
||||
ProjectsImpl(
|
||||
ProjectsCollection projects,
|
||||
ProjectApiImpl.Factory api,
|
||||
Provider<ListProjects> listProvider,
|
||||
Provider<QueryProjects> queryProvider) {
|
||||
this.projects = projects;
|
||||
this.api = api;
|
||||
this.listProvider = listProvider;
|
||||
this.queryProvider = queryProvider;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProjectApi name(String name) throws RestApiException {
|
||||
try {
|
||||
return api.create(projects.parse(name));
|
||||
} catch (UnprocessableEntityException e) {
|
||||
return api.create(name);
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot retrieve project", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProjectApi create(String name) throws RestApiException {
|
||||
ProjectInput in = new ProjectInput();
|
||||
in.name = name;
|
||||
return create(in);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProjectApi create(ProjectInput in) throws RestApiException {
|
||||
if (in.name == null) {
|
||||
throw new BadRequestException("input.name is required");
|
||||
}
|
||||
return name(in.name).create(in);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ListRequest list() {
|
||||
return new ListRequest() {
|
||||
@Override
|
||||
public SortedMap<String, ProjectInfo> getAsMap() throws RestApiException {
|
||||
try {
|
||||
return list(this);
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("project list unavailable", e);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private SortedMap<String, ProjectInfo> list(ListRequest request)
|
||||
throws RestApiException, PermissionBackendException {
|
||||
ListProjects lp = listProvider.get();
|
||||
lp.setShowDescription(request.getDescription());
|
||||
lp.setLimit(request.getLimit());
|
||||
lp.setStart(request.getStart());
|
||||
lp.setMatchPrefix(request.getPrefix());
|
||||
|
||||
lp.setMatchSubstring(request.getSubstring());
|
||||
lp.setMatchRegex(request.getRegex());
|
||||
lp.setShowTree(request.getShowTree());
|
||||
for (String branch : request.getBranches()) {
|
||||
lp.addShowBranch(branch);
|
||||
}
|
||||
|
||||
FilterType type;
|
||||
switch (request.getFilterType()) {
|
||||
case ALL:
|
||||
type = FilterType.ALL;
|
||||
break;
|
||||
case CODE:
|
||||
type = FilterType.CODE;
|
||||
break;
|
||||
case PARENT_CANDIDATES:
|
||||
type = FilterType.PARENT_CANDIDATES;
|
||||
break;
|
||||
case PERMISSIONS:
|
||||
type = FilterType.PERMISSIONS;
|
||||
break;
|
||||
default:
|
||||
throw new BadRequestException("Unknown filter type: " + request.getFilterType());
|
||||
}
|
||||
lp.setFilterType(type);
|
||||
|
||||
return lp.apply();
|
||||
}
|
||||
|
||||
@Override
|
||||
public QueryRequest query() {
|
||||
return new QueryRequest() {
|
||||
@Override
|
||||
public List<ProjectInfo> get() throws RestApiException {
|
||||
return ProjectsImpl.this.query(this);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public QueryRequest query(String query) {
|
||||
return query().withQuery(query);
|
||||
}
|
||||
|
||||
private List<ProjectInfo> query(QueryRequest r) throws RestApiException {
|
||||
try {
|
||||
QueryProjects myQueryProjects = queryProvider.get();
|
||||
myQueryProjects.setQuery(r.getQuery());
|
||||
myQueryProjects.setLimit(r.getLimit());
|
||||
myQueryProjects.setStart(r.getStart());
|
||||
|
||||
return myQueryProjects.apply(TopLevelResource.INSTANCE);
|
||||
} catch (OrmException e) {
|
||||
throw new RestApiException("Cannot query projects", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
94
java/com/google/gerrit/server/api/projects/TagApiImpl.java
Normal file
94
java/com/google/gerrit/server/api/projects/TagApiImpl.java
Normal file
@@ -0,0 +1,94 @@
|
||||
// Copyright (C) 2015 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.server.api.projects;
|
||||
|
||||
import static com.google.gerrit.server.api.ApiUtil.asRestApiException;
|
||||
|
||||
import com.google.gerrit.extensions.api.projects.TagApi;
|
||||
import com.google.gerrit.extensions.api.projects.TagInfo;
|
||||
import com.google.gerrit.extensions.api.projects.TagInput;
|
||||
import com.google.gerrit.extensions.common.Input;
|
||||
import com.google.gerrit.extensions.restapi.IdString;
|
||||
import com.google.gerrit.extensions.restapi.RestApiException;
|
||||
import com.google.gerrit.server.project.CreateTag;
|
||||
import com.google.gerrit.server.project.DeleteTag;
|
||||
import com.google.gerrit.server.project.ListTags;
|
||||
import com.google.gerrit.server.project.ProjectResource;
|
||||
import com.google.gerrit.server.project.TagResource;
|
||||
import com.google.gerrit.server.project.TagsCollection;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.assistedinject.Assisted;
|
||||
import java.io.IOException;
|
||||
|
||||
public class TagApiImpl implements TagApi {
|
||||
interface Factory {
|
||||
TagApiImpl create(ProjectResource project, String ref);
|
||||
}
|
||||
|
||||
private final ListTags listTags;
|
||||
private final CreateTag.Factory createTagFactory;
|
||||
private final DeleteTag deleteTag;
|
||||
private final TagsCollection tags;
|
||||
private final String ref;
|
||||
private final ProjectResource project;
|
||||
|
||||
@Inject
|
||||
TagApiImpl(
|
||||
ListTags listTags,
|
||||
CreateTag.Factory createTagFactory,
|
||||
DeleteTag deleteTag,
|
||||
TagsCollection tags,
|
||||
@Assisted ProjectResource project,
|
||||
@Assisted String ref) {
|
||||
this.listTags = listTags;
|
||||
this.createTagFactory = createTagFactory;
|
||||
this.deleteTag = deleteTag;
|
||||
this.tags = tags;
|
||||
this.project = project;
|
||||
this.ref = ref;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TagApi create(TagInput input) throws RestApiException {
|
||||
try {
|
||||
createTagFactory.create(ref).apply(project, input);
|
||||
return this;
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot create tag", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public TagInfo get() throws RestApiException {
|
||||
try {
|
||||
return listTags.get(project, IdString.fromDecoded(ref));
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot get tag", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete() throws RestApiException {
|
||||
try {
|
||||
deleteTag.apply(resource(), new Input());
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot delete tag", e);
|
||||
}
|
||||
}
|
||||
|
||||
private TagResource resource() throws RestApiException, IOException {
|
||||
return tags.parse(project, IdString.fromDecoded(ref));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user