diff options
Diffstat (limited to 'gerrit-server/src/main/java/com/google/gerrit/server/api/accounts/AccountApiImpl.java')
-rw-r--r-- | gerrit-server/src/main/java/com/google/gerrit/server/api/accounts/AccountApiImpl.java | 150 |
1 files changed, 90 insertions, 60 deletions
diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/api/accounts/AccountApiImpl.java b/gerrit-server/src/main/java/com/google/gerrit/server/api/accounts/AccountApiImpl.java index 430b6b733c..d7952f84de 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/server/api/accounts/AccountApiImpl.java +++ b/gerrit-server/src/main/java/com/google/gerrit/server/api/accounts/AccountApiImpl.java @@ -14,10 +14,10 @@ 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.common.errors.EmailException; import com.google.gerrit.extensions.api.accounts.AccountApi; import com.google.gerrit.extensions.api.accounts.EmailInput; import com.google.gerrit.extensions.api.accounts.GpgKeyApi; @@ -33,12 +33,12 @@ 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.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.GpgException; import com.google.gerrit.server.account.AccountLoader; import com.google.gerrit.server.account.AccountResource; import com.google.gerrit.server.account.AddSshKey; @@ -55,6 +55,7 @@ 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; @@ -62,6 +63,7 @@ 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.PutName; import com.google.gerrit.server.account.PutStatus; import com.google.gerrit.server.account.SetDiffPreferences; import com.google.gerrit.server.account.SetEditPreferences; @@ -74,11 +76,9 @@ 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.io.IOException; import java.util.List; import java.util.Map; import java.util.SortedSet; -import org.eclipse.jgit.errors.ConfigInvalidException; public class AccountApiImpl implements AccountApi { interface Factory { @@ -120,6 +120,8 @@ public class AccountApiImpl implements AccountApi { private final GetExternalIds getExternalIds; private final DeleteExternalIds deleteExternalIds; private final PutStatus putStatus; + private final GetGroups getGroups; + private final PutName putName; @Inject AccountApiImpl( @@ -157,6 +159,8 @@ public class AccountApiImpl implements AccountApi { GetExternalIds getExternalIds, DeleteExternalIds deleteExternalIds, PutStatus putStatus, + GetGroups getGroups, + PutName putName, @Assisted AccountResource account) { this.account = account; this.accountLoaderFactory = ailf; @@ -193,6 +197,8 @@ public class AccountApiImpl implements AccountApi { this.getExternalIds = getExternalIds; this.deleteExternalIds = deleteExternalIds; this.putStatus = putStatus; + this.getGroups = getGroups; + this.putName = putName; } @Override @@ -202,8 +208,8 @@ public class AccountApiImpl implements AccountApi { AccountInfo ai = accountLoader.get(account.getUser().getAccountId()); accountLoader.fill(); return ai; - } catch (OrmException e) { - throw new RestApiException("Cannot parse change", e); + } catch (Exception e) { + throw asRestApiException("Cannot parse account", e); } } @@ -221,8 +227,8 @@ public class AccountApiImpl implements AccountApi { } else { deleteActive.apply(account, new DeleteActive.Input()); } - } catch (OrmException | IOException e) { - throw new RestApiException("Cannot set active", e); + } catch (Exception e) { + throw asRestApiException("Cannot set active", e); } } @@ -234,15 +240,19 @@ public class AccountApiImpl implements AccountApi { @Override public GeneralPreferencesInfo getPreferences() throws RestApiException { - return getPreferences.apply(account); + 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 (IOException | ConfigInvalidException e) { - throw new RestApiException("Cannot set preferences", e); + } catch (Exception e) { + throw asRestApiException("Cannot set preferences", e); } } @@ -250,8 +260,8 @@ public class AccountApiImpl implements AccountApi { public DiffPreferencesInfo getDiffPreferences() throws RestApiException { try { return getDiffPreferences.apply(account); - } catch (IOException | ConfigInvalidException e) { - throw new RestApiException("Cannot query diff preferences", e); + } catch (Exception e) { + throw asRestApiException("Cannot query diff preferences", e); } } @@ -259,8 +269,8 @@ public class AccountApiImpl implements AccountApi { public DiffPreferencesInfo setDiffPreferences(DiffPreferencesInfo in) throws RestApiException { try { return setDiffPreferences.apply(account, in); - } catch (IOException | ConfigInvalidException e) { - throw new RestApiException("Cannot set diff preferences", e); + } catch (Exception e) { + throw asRestApiException("Cannot set diff preferences", e); } } @@ -268,8 +278,8 @@ public class AccountApiImpl implements AccountApi { public EditPreferencesInfo getEditPreferences() throws RestApiException { try { return getEditPreferences.apply(account); - } catch (IOException | ConfigInvalidException e) { - throw new RestApiException("Cannot query edit preferences", e); + } catch (Exception e) { + throw asRestApiException("Cannot query edit preferences", e); } } @@ -277,8 +287,8 @@ public class AccountApiImpl implements AccountApi { public EditPreferencesInfo setEditPreferences(EditPreferencesInfo in) throws RestApiException { try { return setEditPreferences.apply(account, in); - } catch (IOException | ConfigInvalidException e) { - throw new RestApiException("Cannot set edit preferences", e); + } catch (Exception e) { + throw asRestApiException("Cannot set edit preferences", e); } } @@ -286,8 +296,8 @@ public class AccountApiImpl implements AccountApi { public List<ProjectWatchInfo> getWatchedProjects() throws RestApiException { try { return getWatchedProjects.apply(account); - } catch (OrmException | IOException | ConfigInvalidException e) { - throw new RestApiException("Cannot get watched projects", e); + } catch (Exception e) { + throw asRestApiException("Cannot get watched projects", e); } } @@ -296,8 +306,8 @@ public class AccountApiImpl implements AccountApi { throws RestApiException { try { return postWatchedProjects.apply(account, in); - } catch (OrmException | IOException | ConfigInvalidException e) { - throw new RestApiException("Cannot update watched projects", e); + } catch (Exception e) { + throw asRestApiException("Cannot update watched projects", e); } } @@ -305,8 +315,8 @@ public class AccountApiImpl implements AccountApi { public void deleteWatchedProjects(List<ProjectWatchInfo> in) throws RestApiException { try { deleteWatchedProjects.apply(account, in); - } catch (OrmException | IOException | ConfigInvalidException e) { - throw new RestApiException("Cannot delete watched projects", e); + } catch (Exception e) { + throw asRestApiException("Cannot delete watched projects", e); } } @@ -316,8 +326,8 @@ public class AccountApiImpl implements AccountApi { ChangeResource rsrc = changes.parse(TopLevelResource.INSTANCE, IdString.fromUrl(changeId)); starredChangesCreate.setChange(rsrc); starredChangesCreate.apply(account, new StarredChanges.EmptyInput()); - } catch (OrmException | IOException e) { - throw new RestApiException("Cannot star change", e); + } catch (Exception e) { + throw asRestApiException("Cannot star change", e); } } @@ -328,8 +338,8 @@ public class AccountApiImpl implements AccountApi { AccountResource.StarredChange starredChange = new AccountResource.StarredChange(account.getUser(), rsrc); starredChangesDelete.apply(starredChange, new StarredChanges.EmptyInput()); - } catch (OrmException | IOException e) { - throw new RestApiException("Cannot unstar change", e); + } catch (Exception e) { + throw asRestApiException("Cannot unstar change", e); } } @@ -338,8 +348,8 @@ public class AccountApiImpl implements AccountApi { try { AccountResource.Star rsrc = stars.parse(account, IdString.fromUrl(changeId)); starsPost.apply(rsrc, input); - } catch (OrmException e) { - throw new RestApiException("Cannot post stars", e); + } catch (Exception e) { + throw asRestApiException("Cannot post stars", e); } } @@ -348,8 +358,8 @@ public class AccountApiImpl implements AccountApi { try { AccountResource.Star rsrc = stars.parse(account, IdString.fromUrl(changeId)); return starsGet.apply(rsrc); - } catch (OrmException e) { - throw new RestApiException("Cannot get stars", e); + } catch (Exception e) { + throw asRestApiException("Cannot get stars", e); } } @@ -357,8 +367,17 @@ public class AccountApiImpl implements AccountApi { 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 new RestApiException("Cannot get starred changes", e); + throw asRestApiException("Cannot get groups", e); } } @@ -372,8 +391,8 @@ public class AccountApiImpl implements AccountApi { AccountResource.Email rsrc = new AccountResource.Email(account.getUser(), input.email); try { createEmailFactory.create(input.email).apply(rsrc, input); - } catch (EmailException | OrmException | IOException | ConfigInvalidException e) { - throw new RestApiException("Cannot add email", e); + } catch (Exception e) { + throw asRestApiException("Cannot add email", e); } } @@ -382,8 +401,8 @@ public class AccountApiImpl implements AccountApi { AccountResource.Email rsrc = new AccountResource.Email(account.getUser(), email); try { deleteEmail.apply(rsrc, null); - } catch (OrmException | IOException | ConfigInvalidException e) { - throw new RestApiException("Cannot delete email", e); + } catch (Exception e) { + throw asRestApiException("Cannot delete email", e); } } @@ -392,8 +411,8 @@ public class AccountApiImpl implements AccountApi { PutStatus.Input in = new PutStatus.Input(status); try { putStatus.apply(account, in); - } catch (OrmException | IOException e) { - throw new RestApiException("Cannot set status", e); + } catch (Exception e) { + throw asRestApiException("Cannot set status", e); } } @@ -401,8 +420,8 @@ public class AccountApiImpl implements AccountApi { public List<SshKeyInfo> listSshKeys() throws RestApiException { try { return getSshKeys.apply(account); - } catch (OrmException | IOException | ConfigInvalidException e) { - throw new RestApiException("Cannot list SSH keys", e); + } catch (Exception e) { + throw asRestApiException("Cannot list SSH keys", e); } } @@ -412,8 +431,8 @@ public class AccountApiImpl implements AccountApi { in.raw = RawInputUtil.create(key); try { return addSshKey.apply(account, in).value(); - } catch (OrmException | IOException | ConfigInvalidException e) { - throw new RestApiException("Cannot add SSH key", e); + } catch (Exception e) { + throw asRestApiException("Cannot add SSH key", e); } } @@ -423,8 +442,8 @@ public class AccountApiImpl implements AccountApi { AccountResource.SshKey sshKeyRes = sshKeys.parse(account, IdString.fromDecoded(Integer.toString(seq))); deleteSshKey.apply(sshKeyRes, null); - } catch (OrmException | IOException | ConfigInvalidException e) { - throw new RestApiException("Cannot delete SSH key", e); + } catch (Exception e) { + throw asRestApiException("Cannot delete SSH key", e); } } @@ -432,8 +451,8 @@ public class AccountApiImpl implements AccountApi { public Map<String, GpgKeyInfo> listGpgKeys() throws RestApiException { try { return gpgApiAdapter.listGpgKeys(account); - } catch (GpgException e) { - throw new RestApiException("Cannot list GPG keys", e); + } catch (Exception e) { + throw asRestApiException("Cannot list GPG keys", e); } } @@ -442,8 +461,8 @@ public class AccountApiImpl implements AccountApi { throws RestApiException { try { return gpgApiAdapter.putGpgKeys(account, add, delete); - } catch (GpgException e) { - throw new RestApiException("Cannot add GPG key", e); + } catch (Exception e) { + throw asRestApiException("Cannot add GPG key", e); } } @@ -451,8 +470,8 @@ public class AccountApiImpl implements AccountApi { public GpgKeyApi gpgKey(String id) throws RestApiException { try { return gpgApiAdapter.gpgKey(account, IdString.fromDecoded(id)); - } catch (GpgException e) { - throw new RestApiException("Cannot get PGP key", e); + } catch (Exception e) { + throw asRestApiException("Cannot get PGP key", e); } } @@ -467,8 +486,8 @@ public class AccountApiImpl implements AccountApi { AgreementInput input = new AgreementInput(); input.name = agreementName; putAgreement.apply(account, input); - } catch (IOException | OrmException e) { - throw new RestApiException("Cannot sign agreement", e); + } catch (Exception e) { + throw asRestApiException("Cannot sign agreement", e); } } @@ -476,8 +495,8 @@ public class AccountApiImpl implements AccountApi { public void index() throws RestApiException { try { index.apply(account, new Index.Input()); - } catch (IOException e) { - throw new RestApiException("Cannot index account", e); + } catch (Exception e) { + throw asRestApiException("Cannot index account", e); } } @@ -485,8 +504,8 @@ public class AccountApiImpl implements AccountApi { public List<AccountExternalIdInfo> getExternalIds() throws RestApiException { try { return getExternalIds.apply(account); - } catch (OrmException e) { - throw new RestApiException("Cannot get external IDs", e); + } catch (Exception e) { + throw asRestApiException("Cannot get external IDs", e); } } @@ -494,8 +513,19 @@ public class AccountApiImpl implements AccountApi { public void deleteExternalIds(List<String> externalIds) throws RestApiException { try { deleteExternalIds.apply(account, externalIds); - } catch (IOException | OrmException | ConfigInvalidException e) { - throw new RestApiException("Cannot delete external IDs", e); + } catch (Exception e) { + throw asRestApiException("Cannot delete external IDs", e); + } + } + + @Override + public void setName(String name) throws RestApiException { + PutName.Input input = new PutName.Input(); + input.name = name; + try { + putName.apply(account, input); + } catch (Exception e) { + throw asRestApiException("Cannot set account name", e); } } } |