diff options
Diffstat (limited to 'gerrit-httpd/src/main/java/com/google/gerrit/httpd/rpc/account/AccountServiceImpl.java')
-rw-r--r-- | gerrit-httpd/src/main/java/com/google/gerrit/httpd/rpc/account/AccountServiceImpl.java | 65 |
1 files changed, 57 insertions, 8 deletions
diff --git a/gerrit-httpd/src/main/java/com/google/gerrit/httpd/rpc/account/AccountServiceImpl.java b/gerrit-httpd/src/main/java/com/google/gerrit/httpd/rpc/account/AccountServiceImpl.java index 9c1f530a64..4fd8e28f35 100644 --- a/gerrit-httpd/src/main/java/com/google/gerrit/httpd/rpc/account/AccountServiceImpl.java +++ b/gerrit-httpd/src/main/java/com/google/gerrit/httpd/rpc/account/AccountServiceImpl.java @@ -17,9 +17,11 @@ package com.google.gerrit.httpd.rpc.account; import com.google.gerrit.common.data.AccountProjectWatchInfo; import com.google.gerrit.common.data.AccountService; import com.google.gerrit.common.data.AgreementInfo; +import com.google.gerrit.common.errors.InvalidQueryException; import com.google.gerrit.common.errors.NoSuchEntityException; import com.google.gerrit.httpd.rpc.BaseServiceImplementation; import com.google.gerrit.reviewdb.Account; +import com.google.gerrit.reviewdb.AccountDiffPreference; import com.google.gerrit.reviewdb.AccountGeneralPreferences; import com.google.gerrit.reviewdb.AccountProjectWatch; import com.google.gerrit.reviewdb.Project; @@ -28,8 +30,11 @@ import com.google.gerrit.server.IdentifiedUser; import com.google.gerrit.server.account.AccountCache; import com.google.gerrit.server.project.NoSuchProjectException; import com.google.gerrit.server.project.ProjectControl; +import com.google.gerrit.server.query.QueryParseException; +import com.google.gerrit.server.query.change.ChangeQueryBuilder; import com.google.gwt.user.client.rpc.AsyncCallback; import com.google.gwtjsonrpc.client.VoidResult; +import com.google.gwtorm.client.OrmDuplicateKeyException; import com.google.gwtorm.client.OrmException; import com.google.inject.Inject; import com.google.inject.Provider; @@ -46,24 +51,37 @@ class AccountServiceImpl extends BaseServiceImplementation implements private final AccountCache accountCache; private final ProjectControl.Factory projectControlFactory; private final AgreementInfoFactory.Factory agreementInfoFactory; + private final ChangeQueryBuilder.Factory queryBuilder; @Inject AccountServiceImpl(final Provider<ReviewDb> schema, final Provider<IdentifiedUser> identifiedUser, final AccountCache accountCache, final ProjectControl.Factory projectControlFactory, - final AgreementInfoFactory.Factory agreementInfoFactory) { + final AgreementInfoFactory.Factory agreementInfoFactory, + final ChangeQueryBuilder.Factory queryBuilder) { super(schema, identifiedUser); this.currentUser = identifiedUser; this.accountCache = accountCache; this.projectControlFactory = projectControlFactory; this.agreementInfoFactory = agreementInfoFactory; + this.queryBuilder = queryBuilder; } public void myAccount(final AsyncCallback<Account> callback) { callback.onSuccess(currentUser.get().getAccount()); } + @Override + public void myDiffPreferences(AsyncCallback<AccountDiffPreference> callback) { + run(callback, new Action<AccountDiffPreference>() { + @Override + public AccountDiffPreference run(ReviewDb db) throws OrmException { + return currentUser.get().getAccountDiffPreference(); + } + }); + } + public void changePreferences(final AccountGeneralPreferences pref, final AsyncCallback<VoidResult> callback) { run(callback, new Action<VoidResult>() { @@ -80,6 +98,23 @@ class AccountServiceImpl extends BaseServiceImplementation implements }); } + @Override + public void changeDiffPreferences(final AccountDiffPreference diffPref, + AsyncCallback<VoidResult> callback) { + run(callback, new Action<VoidResult>(){ + public VoidResult run(ReviewDb db) throws OrmException { + Account.Id accountId = getAccountId(); + if (!diffPref.getAccountId().equals(getAccountId())) { + throw new IllegalArgumentException("diffPref.getAccountId() " + + diffPref.getAccountId() + " doesn't match" + + " the accountId of the signed in user " + getAccountId()); + } + db.accountDiffPreferences().upsert(Collections.singleton(diffPref)); + return VoidResult.INSTANCE; + } + }); + } + public void myProjectWatch( final AsyncCallback<List<AccountProjectWatchInfo>> callback) { run(callback, new Action<List<AccountProjectWatchInfo>>() { @@ -109,19 +144,33 @@ class AccountServiceImpl extends BaseServiceImplementation implements }); } - public void addProjectWatch(final String projectName, + public void addProjectWatch(final String projectName, final String filter, final AsyncCallback<AccountProjectWatchInfo> callback) { run(callback, new Action<AccountProjectWatchInfo>() { public AccountProjectWatchInfo run(ReviewDb db) throws OrmException, - NoSuchProjectException { + NoSuchProjectException, InvalidQueryException { final Project.NameKey nameKey = new Project.NameKey(projectName); final ProjectControl ctl = projectControlFactory.validateFor(nameKey); - final AccountProjectWatch watch = - new AccountProjectWatch( - new AccountProjectWatch.Key(((IdentifiedUser) ctl - .getCurrentUser()).getAccountId(), nameKey)); - db.accountProjectWatches().insert(Collections.singleton(watch)); + if (filter != null) { + try { + ChangeQueryBuilder builder = queryBuilder.create(currentUser.get()); + builder.setAllowFile(true); + builder.parse(filter); + } catch (QueryParseException badFilter) { + throw new InvalidQueryException(badFilter.getMessage(), filter); + } + } + + AccountProjectWatch watch = + new AccountProjectWatch(new AccountProjectWatch.Key( + ((IdentifiedUser) ctl.getCurrentUser()).getAccountId(), + nameKey, filter)); + try { + db.accountProjectWatches().insert(Collections.singleton(watch)); + } catch (OrmDuplicateKeyException alreadyHave) { + watch = db.accountProjectWatches().get(watch.getKey()); + } return new AccountProjectWatchInfo(watch, ctl.getProject()); } }); |