cloud-notifications: fix 2.14 build

Change-Id: Ie04c268a49ad9f4cc82cfb5bc2cd515cad557483
Signed-off-by: Jorge Ruesga <j.ruesga.criado@gmail.com>
diff --git a/BUCK b/BUILD
similarity index 66%
rename from BUCK
rename to BUILD
index 677999b..ab3b9b8 100644
--- a/BUCK
+++ b/BUILD
@@ -14,49 +14,27 @@
 # limitations under the License.
 #
 
-include_defs('//bucklets/gerrit_plugin.bucklet')
-include_defs('//bucklets/java_sources.bucklet')
-include_defs('//bucklets/maven_jar.bucklet')
+load("//tools/bzl:plugin.bzl", "gerrit_plugin")
 
 SOURCES = glob(['src/main/java/**/*.java'])
 RESOURCES = glob(['src/main/resources/**/*'])
 
-PROVIDED_DEPS = [
-  '//lib:gson',
-  ':h2'
-]
-
 DEPS = [
+  '//lib:h2'
 ]
 
 gerrit_plugin(
-  name = 'cloud-notifications',
+  name = "cloud-notifications",
   srcs = SOURCES,
   resources = RESOURCES,
   manifest_entries = [
     'Gerrit-PluginName: cloud-notifications',
-    'Gerrit-ApiType: plugin',
     'Gerrit-ApiVersion: 2.14-SNAPSHOT',
     'Gerrit-Module: com.ruesga.gerrit.plugins.fcm.ApiModule',
     'Implementation-Title: Firebase Cloud Notifications Plugin',
-    'Implementation-Vendor: Jorge Ruesga',
     'Implementation-URL: https://gerrit.googlesource.com/plugins/cloud-notifications',
     'Implementation-Version: 2.14-SNAPSHOT'
   ],
-  deps = DEPS,
-  provided_deps = PROVIDED_DEPS
-)
-
-java_sources(
-  name = 'cloud-notifications-sources',
-  srcs = SOURCES + RESOURCES
-)
-
-maven_jar(
-  name = 'h2',
-  id = 'com.h2database:h2:1.3.176',
-  license = 'Apache2.0',
-  exclude_java_sources = True,
-  visibility = [],
+  deps = DEPS
 )
 
diff --git a/src/main/java/com/ruesga/gerrit/plugins/fcm/handlers/AssigneeChangedEventHandler.java b/src/main/java/com/ruesga/gerrit/plugins/fcm/handlers/AssigneeChangedEventHandler.java
index 6a6b62e..be0e02b 100644
--- a/src/main/java/com/ruesga/gerrit/plugins/fcm/handlers/AssigneeChangedEventHandler.java
+++ b/src/main/java/com/ruesga/gerrit/plugins/fcm/handlers/AssigneeChangedEventHandler.java
@@ -18,10 +18,11 @@
 import com.google.gerrit.extensions.annotations.PluginName;
 import com.google.gerrit.extensions.common.AccountInfo;
 import com.google.gerrit.extensions.events.AssigneeChangedListener;
-import com.google.gerrit.reviewdb.client.AccountProjectWatch.NotifyType;
-import com.google.gerrit.reviewdb.server.ReviewDb;
 import com.google.gerrit.server.IdentifiedUser.GenericFactory;
+import com.google.gerrit.server.account.CapabilityControl;
+import com.google.gerrit.server.account.WatchConfig.NotifyType;
 import com.google.gerrit.server.config.AllProjectsName;
+import com.google.gerrit.server.query.account.InternalAccountQuery;
 import com.google.gerrit.server.query.change.ChangeQueryBuilder;
 import com.google.gerrit.server.query.change.ChangeQueryProcessor;
 import com.google.gson.annotations.SerializedName;
@@ -46,13 +47,15 @@
             AllProjectsName allProjectsName,
             ChangeQueryBuilder cqb,
             ChangeQueryProcessor cqp,
-            Provider<ReviewDb> reviewdb,
+            Provider<InternalAccountQuery> accountQueryProvider,
+            CapabilityControl.Factory capabilityControlFactory,
             GenericFactory identifiedUserFactory) {
         super(pluginName,
                 uploader,
                 allProjectsName,
                 cqb, cqp,
-                reviewdb,
+                accountQueryProvider,
+                capabilityControlFactory,
                 identifiedUserFactory);
     }
 
diff --git a/src/main/java/com/ruesga/gerrit/plugins/fcm/handlers/ChangeAbandonedEventHandler.java b/src/main/java/com/ruesga/gerrit/plugins/fcm/handlers/ChangeAbandonedEventHandler.java
index 551980c..6a7a859 100644
--- a/src/main/java/com/ruesga/gerrit/plugins/fcm/handlers/ChangeAbandonedEventHandler.java
+++ b/src/main/java/com/ruesga/gerrit/plugins/fcm/handlers/ChangeAbandonedEventHandler.java
@@ -17,10 +17,11 @@
 
 import com.google.gerrit.extensions.annotations.PluginName;
 import com.google.gerrit.extensions.events.ChangeAbandonedListener;
-import com.google.gerrit.reviewdb.client.AccountProjectWatch.NotifyType;
-import com.google.gerrit.reviewdb.server.ReviewDb;
 import com.google.gerrit.server.IdentifiedUser.GenericFactory;
+import com.google.gerrit.server.account.CapabilityControl;
+import com.google.gerrit.server.account.WatchConfig.NotifyType;
 import com.google.gerrit.server.config.AllProjectsName;
+import com.google.gerrit.server.query.account.InternalAccountQuery;
 import com.google.gerrit.server.query.change.ChangeQueryBuilder;
 import com.google.gerrit.server.query.change.ChangeQueryProcessor;
 import com.google.inject.Inject;
@@ -39,13 +40,15 @@
             AllProjectsName allProjectsName,
             ChangeQueryBuilder cqb,
             ChangeQueryProcessor cqp,
-            Provider<ReviewDb> reviewdb,
+            Provider<InternalAccountQuery> accountQueryProvider,
+            CapabilityControl.Factory capabilityControlFactory,
             GenericFactory identifiedUserFactory) {
         super(pluginName,
                 uploader,
                 allProjectsName,
                 cqb, cqp,
-                reviewdb,
+                accountQueryProvider,
+                capabilityControlFactory,
                 identifiedUserFactory);
     }
 
diff --git a/src/main/java/com/ruesga/gerrit/plugins/fcm/handlers/ChangeMergedEventHandler.java b/src/main/java/com/ruesga/gerrit/plugins/fcm/handlers/ChangeMergedEventHandler.java
index 06e6036..bf8bc5a 100644
--- a/src/main/java/com/ruesga/gerrit/plugins/fcm/handlers/ChangeMergedEventHandler.java
+++ b/src/main/java/com/ruesga/gerrit/plugins/fcm/handlers/ChangeMergedEventHandler.java
@@ -17,10 +17,11 @@
 
 import com.google.gerrit.extensions.annotations.PluginName;
 import com.google.gerrit.extensions.events.ChangeMergedListener;
-import com.google.gerrit.reviewdb.client.AccountProjectWatch.NotifyType;
-import com.google.gerrit.reviewdb.server.ReviewDb;
 import com.google.gerrit.server.IdentifiedUser.GenericFactory;
+import com.google.gerrit.server.account.CapabilityControl;
+import com.google.gerrit.server.account.WatchConfig.NotifyType;
 import com.google.gerrit.server.config.AllProjectsName;
+import com.google.gerrit.server.query.account.InternalAccountQuery;
 import com.google.gerrit.server.query.change.ChangeQueryBuilder;
 import com.google.gerrit.server.query.change.ChangeQueryProcessor;
 import com.google.inject.Inject;
@@ -39,13 +40,15 @@
             AllProjectsName allProjectsName,
             ChangeQueryBuilder cqb,
             ChangeQueryProcessor cqp,
-            Provider<ReviewDb> reviewdb,
+            Provider<InternalAccountQuery> accountQueryProvider,
+            CapabilityControl.Factory capabilityControlFactory,
             GenericFactory identifiedUserFactory) {
         super(pluginName,
                 uploader,
                 allProjectsName,
                 cqb, cqp,
-                reviewdb,
+                accountQueryProvider,
+                capabilityControlFactory,
                 identifiedUserFactory);
     }
 
diff --git a/src/main/java/com/ruesga/gerrit/plugins/fcm/handlers/ChangeRestoredEventHandler.java b/src/main/java/com/ruesga/gerrit/plugins/fcm/handlers/ChangeRestoredEventHandler.java
index 8c77c1a..a0976d9 100644
--- a/src/main/java/com/ruesga/gerrit/plugins/fcm/handlers/ChangeRestoredEventHandler.java
+++ b/src/main/java/com/ruesga/gerrit/plugins/fcm/handlers/ChangeRestoredEventHandler.java
@@ -17,10 +17,11 @@
 
 import com.google.gerrit.extensions.annotations.PluginName;
 import com.google.gerrit.extensions.events.ChangeRestoredListener;
-import com.google.gerrit.reviewdb.client.AccountProjectWatch.NotifyType;
-import com.google.gerrit.reviewdb.server.ReviewDb;
 import com.google.gerrit.server.IdentifiedUser.GenericFactory;
+import com.google.gerrit.server.account.CapabilityControl;
+import com.google.gerrit.server.account.WatchConfig.NotifyType;
 import com.google.gerrit.server.config.AllProjectsName;
+import com.google.gerrit.server.query.account.InternalAccountQuery;
 import com.google.gerrit.server.query.change.ChangeQueryBuilder;
 import com.google.gerrit.server.query.change.ChangeQueryProcessor;
 import com.google.inject.Inject;
@@ -39,13 +40,15 @@
             AllProjectsName allProjectsName,
             ChangeQueryBuilder cqb,
             ChangeQueryProcessor cqp,
-            Provider<ReviewDb> reviewdb,
+            Provider<InternalAccountQuery> accountQueryProvider,
+            CapabilityControl.Factory capabilityControlFactory,
             GenericFactory identifiedUserFactory) {
         super(pluginName,
                 uploader,
                 allProjectsName,
                 cqb, cqp,
-                reviewdb,
+                accountQueryProvider,
+                capabilityControlFactory,
                 identifiedUserFactory);
     }
 
diff --git a/src/main/java/com/ruesga/gerrit/plugins/fcm/handlers/ChangeRevertedEventHandler.java b/src/main/java/com/ruesga/gerrit/plugins/fcm/handlers/ChangeRevertedEventHandler.java
index 1db50e2..e859a17 100644
--- a/src/main/java/com/ruesga/gerrit/plugins/fcm/handlers/ChangeRevertedEventHandler.java
+++ b/src/main/java/com/ruesga/gerrit/plugins/fcm/handlers/ChangeRevertedEventHandler.java
@@ -17,10 +17,11 @@
 
 import com.google.gerrit.extensions.annotations.PluginName;
 import com.google.gerrit.extensions.events.ChangeRevertedListener;
-import com.google.gerrit.reviewdb.client.AccountProjectWatch.NotifyType;
-import com.google.gerrit.reviewdb.server.ReviewDb;
 import com.google.gerrit.server.IdentifiedUser.GenericFactory;
+import com.google.gerrit.server.account.CapabilityControl;
+import com.google.gerrit.server.account.WatchConfig.NotifyType;
 import com.google.gerrit.server.config.AllProjectsName;
+import com.google.gerrit.server.query.account.InternalAccountQuery;
 import com.google.gerrit.server.query.change.ChangeQueryBuilder;
 import com.google.gerrit.server.query.change.ChangeQueryProcessor;
 import com.google.inject.Inject;
@@ -39,13 +40,15 @@
             AllProjectsName allProjectsName,
             ChangeQueryBuilder cqb,
             ChangeQueryProcessor cqp,
-            Provider<ReviewDb> reviewdb,
+            Provider<InternalAccountQuery> accountQueryProvider,
+            CapabilityControl.Factory capabilityControlFactory,
             GenericFactory identifiedUserFactory) {
         super(pluginName,
                 uploader,
                 allProjectsName,
                 cqb, cqp,
-                reviewdb,
+                accountQueryProvider,
+                capabilityControlFactory,
                 identifiedUserFactory);
     }
 
diff --git a/src/main/java/com/ruesga/gerrit/plugins/fcm/handlers/CommentAddedEventHandler.java b/src/main/java/com/ruesga/gerrit/plugins/fcm/handlers/CommentAddedEventHandler.java
index 32fbe51..0ebe7dc 100644
--- a/src/main/java/com/ruesga/gerrit/plugins/fcm/handlers/CommentAddedEventHandler.java
+++ b/src/main/java/com/ruesga/gerrit/plugins/fcm/handlers/CommentAddedEventHandler.java
@@ -19,10 +19,11 @@
 
 import com.google.gerrit.extensions.annotations.PluginName;
 import com.google.gerrit.extensions.events.CommentAddedListener;
-import com.google.gerrit.reviewdb.client.AccountProjectWatch.NotifyType;
-import com.google.gerrit.reviewdb.server.ReviewDb;
 import com.google.gerrit.server.IdentifiedUser.GenericFactory;
+import com.google.gerrit.server.account.CapabilityControl;
+import com.google.gerrit.server.account.WatchConfig.NotifyType;
 import com.google.gerrit.server.config.AllProjectsName;
+import com.google.gerrit.server.query.account.InternalAccountQuery;
 import com.google.gerrit.server.query.change.ChangeQueryBuilder;
 import com.google.gerrit.server.query.change.ChangeQueryProcessor;
 import com.google.inject.Inject;
@@ -41,13 +42,15 @@
             AllProjectsName allProjectsName,
             ChangeQueryBuilder cqb,
             ChangeQueryProcessor cqp,
-            Provider<ReviewDb> reviewdb,
+            Provider<InternalAccountQuery> accountQueryProvider,
+            CapabilityControl.Factory capabilityControlFactory,
             GenericFactory identifiedUserFactory) {
         super(pluginName,
                 uploader,
                 allProjectsName,
                 cqb, cqp,
-                reviewdb,
+                accountQueryProvider,
+                capabilityControlFactory,
                 identifiedUserFactory);
     }
 
diff --git a/src/main/java/com/ruesga/gerrit/plugins/fcm/handlers/DraftPublishedEventHandler.java b/src/main/java/com/ruesga/gerrit/plugins/fcm/handlers/DraftPublishedEventHandler.java
index 1bab4a9..eaffee9 100644
--- a/src/main/java/com/ruesga/gerrit/plugins/fcm/handlers/DraftPublishedEventHandler.java
+++ b/src/main/java/com/ruesga/gerrit/plugins/fcm/handlers/DraftPublishedEventHandler.java
@@ -17,10 +17,11 @@
 
 import com.google.gerrit.extensions.annotations.PluginName;
 import com.google.gerrit.extensions.events.DraftPublishedListener;
-import com.google.gerrit.reviewdb.client.AccountProjectWatch.NotifyType;
-import com.google.gerrit.reviewdb.server.ReviewDb;
 import com.google.gerrit.server.IdentifiedUser.GenericFactory;
 import com.google.gerrit.server.config.AllProjectsName;
+import com.google.gerrit.server.account.CapabilityControl;
+import com.google.gerrit.server.account.WatchConfig.NotifyType;
+import com.google.gerrit.server.query.account.InternalAccountQuery;
 import com.google.gerrit.server.query.change.ChangeQueryBuilder;
 import com.google.gerrit.server.query.change.ChangeQueryProcessor;
 import com.google.inject.Inject;
@@ -39,13 +40,15 @@
             AllProjectsName allProjectsName,
             ChangeQueryBuilder cqb,
             ChangeQueryProcessor cqp,
-            Provider<ReviewDb> reviewdb,
+            Provider<InternalAccountQuery> accountQueryProvider,
+            CapabilityControl.Factory capabilityControlFactory,
             GenericFactory identifiedUserFactory) {
         super(pluginName,
                 uploader,
                 allProjectsName,
                 cqb, cqp,
-                reviewdb,
+                accountQueryProvider,
+                capabilityControlFactory,
                 identifiedUserFactory);
     }
 
diff --git a/src/main/java/com/ruesga/gerrit/plugins/fcm/handlers/EventHandler.java b/src/main/java/com/ruesga/gerrit/plugins/fcm/handlers/EventHandler.java
index 53451d6..db56c43 100644
--- a/src/main/java/com/ruesga/gerrit/plugins/fcm/handlers/EventHandler.java
+++ b/src/main/java/com/ruesga/gerrit/plugins/fcm/handlers/EventHandler.java
@@ -19,6 +19,7 @@
 import java.util.Collection;
 import java.util.HashSet;
 import java.util.List;
+import java.util.Map;
 import java.util.Set;
 
 import org.apache.commons.lang.StringUtils;
@@ -32,16 +33,19 @@
 import com.google.gerrit.extensions.common.ChangeInfo;
 import com.google.gerrit.extensions.events.ChangeEvent;
 import com.google.gerrit.extensions.events.RevisionEvent;
-import com.google.gerrit.reviewdb.client.AccountProjectWatch;
-import com.google.gerrit.reviewdb.client.AccountProjectWatch.NotifyType;
-import com.google.gerrit.reviewdb.server.ReviewDb;
+import com.google.gerrit.reviewdb.client.Account;
 import com.google.gerrit.server.CurrentUser;
 import com.google.gerrit.server.IdentifiedUser;
 import com.google.gerrit.server.IdentifiedUser.GenericFactory;
+import com.google.gerrit.server.account.AccountState;
+import com.google.gerrit.server.account.CapabilityControl;
+import com.google.gerrit.server.account.WatchConfig.NotifyType;
+import com.google.gerrit.server.account.WatchConfig.ProjectWatchKey;
 import com.google.gerrit.server.config.AllProjectsName;
 import com.google.gerrit.server.query.Predicate;
 import com.google.gerrit.server.query.QueryParseException;
 import com.google.gerrit.server.query.QueryResult;
+import com.google.gerrit.server.query.account.InternalAccountQuery;
 import com.google.gerrit.server.query.change.ChangeData;
 import com.google.gerrit.server.query.change.ChangeQueryBuilder;
 import com.google.gerrit.server.query.change.ChangeQueryProcessor;
@@ -62,7 +66,7 @@
     private final AllProjectsName allProjectsName;
     private final ChangeQueryBuilder cqb;
     private final ChangeQueryProcessor cqp;
-    private final Provider<ReviewDb> reviewdb;
+    private final Provider<InternalAccountQuery> accountQueryProvider;
     private final GenericFactory identifiedUserFactory;
     private final Gson gson;
 
@@ -72,7 +76,8 @@
             AllProjectsName allProjectsName,
             ChangeQueryBuilder cqb,
             ChangeQueryProcessor cqp,
-            Provider<ReviewDb> reviewdb,
+            Provider<InternalAccountQuery> accountQueryProvider,
+            CapabilityControl.Factory capabilityControlFactory,
             GenericFactory identifiedUserFactory) {
         super();
         this.pluginName = pluginName;
@@ -80,7 +85,7 @@
         this.allProjectsName = allProjectsName;
         this.cqb = cqb;
         this.cqp = cqp;
-        this.reviewdb = reviewdb;
+        this.accountQueryProvider = accountQueryProvider;
         this.identifiedUserFactory = identifiedUserFactory;
         this.gson = new GsonBuilder().create();
     }
@@ -173,17 +178,34 @@
         return new ArrayList<>(notifiedUsers);
     }
 
-    private Set<Integer> getWatchers(NotifyType type, ChangeData change) {
+    public final Set<Integer> getWatchers(NotifyType type, ChangeData change) {
         Set<Integer> watchers = new HashSet<>();
         try {
-            for (AccountProjectWatch w : reviewdb.get().accountProjectWatches()
-                    .byProject(change.project())) {
-                add(watchers, w, type, change);
+            Set<Account.Id> projectWatchers = new HashSet<>();
+            for (AccountState a : accountQueryProvider.get().byWatchedProject(
+                    change.project())) {
+                Account.Id accountId = a.getAccount().getId();
+                for (Map.Entry<ProjectWatchKey, Set<NotifyType>> e : a.getProjectWatches().entrySet()) {
+                    if (change.project().equals(e.getKey().project())
+                            && add(watchers, accountId, e.getKey(), e.getValue(), type, change)) {
+                        // We only want to prevent matching All-Projects if this filter hits
+                        projectWatchers.add(accountId);
+                    }
+                }
             }
-            for (AccountProjectWatch w : reviewdb.get().accountProjectWatches()
-                    .byProject(this.allProjectsName)) {
-                add(watchers, w, type, change);
+
+            for (AccountState a : accountQueryProvider.get().byWatchedProject(
+                    allProjectsName)) {
+              for (Map.Entry<ProjectWatchKey, Set<NotifyType>> e : a.getProjectWatches().entrySet()) {
+                if (allProjectsName.equals(e.getKey().project())) {
+                  Account.Id accountId = a.getAccount().getId();
+                  if (!projectWatchers.contains(accountId)) {
+                    add(watchers, accountId, e.getKey(), e.getValue(), type, change);
+                  }
+                }
+              }
             }
+
         } catch (OrmException ex) {
             log.error(String.format(
                     "[%s] Failed to obtain watchers", pluginName), ex);
@@ -191,16 +213,17 @@
         return watchers;
     }
 
-    private boolean add(Set<Integer> watchers, AccountProjectWatch w,
-            NotifyType type, ChangeData change) throws OrmException {
-        IdentifiedUser user = identifiedUserFactory.create(w.getAccountId());
+    private boolean add(Set<Integer> watchers, Account.Id accountId,
+            ProjectWatchKey key, Set<NotifyType> watchedTypes, NotifyType type,
+            ChangeData change) throws OrmException {
+        IdentifiedUser user = identifiedUserFactory.create(accountId);
 
         try {
-            if (filterMatch(user, w.getFilter(), change)) {
+            if (filterMatch(user, key.filter(), change)) {
                 // If we are set to notify on this type, add the user.
                 // Otherwise, still return true to stop notifications for this user.
-                if (w.isNotify(type)) {
-                    watchers.add(w.getAccountId().get());
+                if (watchedTypes.contains(type)) {
+                    watchers.add(accountId.get());
                 }
                 return true;
             }
@@ -255,4 +278,4 @@
         }
         return account.email;
     }
-}
+}
\ No newline at end of file
diff --git a/src/main/java/com/ruesga/gerrit/plugins/fcm/handlers/HashtagsEditedEventHandler.java b/src/main/java/com/ruesga/gerrit/plugins/fcm/handlers/HashtagsEditedEventHandler.java
index 8c5fcc1..992fd5d 100644
--- a/src/main/java/com/ruesga/gerrit/plugins/fcm/handlers/HashtagsEditedEventHandler.java
+++ b/src/main/java/com/ruesga/gerrit/plugins/fcm/handlers/HashtagsEditedEventHandler.java
@@ -17,10 +17,11 @@
 
 import com.google.gerrit.extensions.annotations.PluginName;
 import com.google.gerrit.extensions.events.HashtagsEditedListener;
-import com.google.gerrit.reviewdb.client.AccountProjectWatch.NotifyType;
-import com.google.gerrit.reviewdb.server.ReviewDb;
 import com.google.gerrit.server.IdentifiedUser.GenericFactory;
+import com.google.gerrit.server.account.CapabilityControl;
+import com.google.gerrit.server.account.WatchConfig.NotifyType;
 import com.google.gerrit.server.config.AllProjectsName;
+import com.google.gerrit.server.query.account.InternalAccountQuery;
 import com.google.gerrit.server.query.change.ChangeQueryBuilder;
 import com.google.gerrit.server.query.change.ChangeQueryProcessor;
 import com.google.gson.annotations.SerializedName;
@@ -45,13 +46,15 @@
             AllProjectsName allProjectsName,
             ChangeQueryBuilder cqb,
             ChangeQueryProcessor cqp,
-            Provider<ReviewDb> reviewdb,
+            Provider<InternalAccountQuery> accountQueryProvider,
+            CapabilityControl.Factory capabilityControlFactory,
             GenericFactory identifiedUserFactory) {
         super(pluginName,
                 uploader,
                 allProjectsName,
                 cqb, cqp,
-                reviewdb,
+                accountQueryProvider,
+                capabilityControlFactory,
                 identifiedUserFactory);
     }
 
diff --git a/src/main/java/com/ruesga/gerrit/plugins/fcm/handlers/ReviewerAddedEventHandler.java b/src/main/java/com/ruesga/gerrit/plugins/fcm/handlers/ReviewerAddedEventHandler.java
index 4f4a16d..bb4b561 100644
--- a/src/main/java/com/ruesga/gerrit/plugins/fcm/handlers/ReviewerAddedEventHandler.java
+++ b/src/main/java/com/ruesga/gerrit/plugins/fcm/handlers/ReviewerAddedEventHandler.java
@@ -20,10 +20,11 @@
 import com.google.gerrit.extensions.annotations.PluginName;
 import com.google.gerrit.extensions.common.AccountInfo;
 import com.google.gerrit.extensions.events.ReviewerAddedListener;
-import com.google.gerrit.reviewdb.client.AccountProjectWatch.NotifyType;
-import com.google.gerrit.reviewdb.server.ReviewDb;
 import com.google.gerrit.server.IdentifiedUser.GenericFactory;
+import com.google.gerrit.server.account.CapabilityControl;
+import com.google.gerrit.server.account.WatchConfig.NotifyType;
 import com.google.gerrit.server.config.AllProjectsName;
+import com.google.gerrit.server.query.account.InternalAccountQuery;
 import com.google.gerrit.server.query.change.ChangeQueryBuilder;
 import com.google.gerrit.server.query.change.ChangeQueryProcessor;
 import com.google.inject.Inject;
@@ -42,13 +43,15 @@
             AllProjectsName allProjectsName,
             ChangeQueryBuilder cqb,
             ChangeQueryProcessor cqp,
-            Provider<ReviewDb> reviewdb,
+            Provider<InternalAccountQuery> accountQueryProvider,
+            CapabilityControl.Factory capabilityControlFactory,
             GenericFactory identifiedUserFactory) {
         super(pluginName,
                 uploader,
                 allProjectsName,
                 cqb, cqp,
-                reviewdb,
+                accountQueryProvider,
+                capabilityControlFactory,
                 identifiedUserFactory);
     }
 
diff --git a/src/main/java/com/ruesga/gerrit/plugins/fcm/handlers/ReviewerDeletedEventHandler.java b/src/main/java/com/ruesga/gerrit/plugins/fcm/handlers/ReviewerDeletedEventHandler.java
index de5b6e0..ffbabcf 100644
--- a/src/main/java/com/ruesga/gerrit/plugins/fcm/handlers/ReviewerDeletedEventHandler.java
+++ b/src/main/java/com/ruesga/gerrit/plugins/fcm/handlers/ReviewerDeletedEventHandler.java
@@ -17,10 +17,11 @@
 
 import com.google.gerrit.extensions.annotations.PluginName;
 import com.google.gerrit.extensions.events.ReviewerDeletedListener;
-import com.google.gerrit.reviewdb.client.AccountProjectWatch.NotifyType;
-import com.google.gerrit.reviewdb.server.ReviewDb;
 import com.google.gerrit.server.IdentifiedUser.GenericFactory;
+import com.google.gerrit.server.account.CapabilityControl;
+import com.google.gerrit.server.account.WatchConfig.NotifyType;
 import com.google.gerrit.server.config.AllProjectsName;
+import com.google.gerrit.server.query.account.InternalAccountQuery;
 import com.google.gerrit.server.query.change.ChangeQueryBuilder;
 import com.google.gerrit.server.query.change.ChangeQueryProcessor;
 import com.google.inject.Inject;
@@ -39,13 +40,15 @@
             AllProjectsName allProjectsName,
             ChangeQueryBuilder cqb,
             ChangeQueryProcessor cqp,
-            Provider<ReviewDb> reviewdb,
+            Provider<InternalAccountQuery> accountQueryProvider,
+            CapabilityControl.Factory capabilityControlFactory,
             GenericFactory identifiedUserFactory) {
         super(pluginName,
                 uploader,
                 allProjectsName,
                 cqb, cqp,
-                reviewdb,
+                accountQueryProvider,
+                capabilityControlFactory,
                 identifiedUserFactory);
     }
 
diff --git a/src/main/java/com/ruesga/gerrit/plugins/fcm/handlers/RevisionCreatedEventHandler.java b/src/main/java/com/ruesga/gerrit/plugins/fcm/handlers/RevisionCreatedEventHandler.java
index 9761542..946d113 100644
--- a/src/main/java/com/ruesga/gerrit/plugins/fcm/handlers/RevisionCreatedEventHandler.java
+++ b/src/main/java/com/ruesga/gerrit/plugins/fcm/handlers/RevisionCreatedEventHandler.java
@@ -17,10 +17,11 @@
 
 import com.google.gerrit.extensions.annotations.PluginName;
 import com.google.gerrit.extensions.events.RevisionCreatedListener;
-import com.google.gerrit.reviewdb.client.AccountProjectWatch.NotifyType;
-import com.google.gerrit.reviewdb.server.ReviewDb;
 import com.google.gerrit.server.IdentifiedUser.GenericFactory;
+import com.google.gerrit.server.account.CapabilityControl;
+import com.google.gerrit.server.account.WatchConfig.NotifyType;
 import com.google.gerrit.server.config.AllProjectsName;
+import com.google.gerrit.server.query.account.InternalAccountQuery;
 import com.google.gerrit.server.query.change.ChangeQueryBuilder;
 import com.google.gerrit.server.query.change.ChangeQueryProcessor;
 import com.google.inject.Inject;
@@ -39,13 +40,15 @@
             AllProjectsName allProjectsName,
             ChangeQueryBuilder cqb,
             ChangeQueryProcessor cqp,
-            Provider<ReviewDb> reviewdb,
+            Provider<InternalAccountQuery> accountQueryProvider,
+            CapabilityControl.Factory capabilityControlFactory,
             GenericFactory identifiedUserFactory) {
         super(pluginName,
                 uploader,
                 allProjectsName,
                 cqb, cqp,
-                reviewdb,
+                accountQueryProvider,
+                capabilityControlFactory,
                 identifiedUserFactory);
     }
 
diff --git a/src/main/java/com/ruesga/gerrit/plugins/fcm/handlers/TopicEditedEventHandler.java b/src/main/java/com/ruesga/gerrit/plugins/fcm/handlers/TopicEditedEventHandler.java
index dfb1270..e255b6b 100644
--- a/src/main/java/com/ruesga/gerrit/plugins/fcm/handlers/TopicEditedEventHandler.java
+++ b/src/main/java/com/ruesga/gerrit/plugins/fcm/handlers/TopicEditedEventHandler.java
@@ -17,10 +17,11 @@
 
 import com.google.gerrit.extensions.annotations.PluginName;
 import com.google.gerrit.extensions.events.TopicEditedListener;
-import com.google.gerrit.reviewdb.client.AccountProjectWatch.NotifyType;
-import com.google.gerrit.reviewdb.server.ReviewDb;
 import com.google.gerrit.server.IdentifiedUser.GenericFactory;
+import com.google.gerrit.server.account.CapabilityControl;
+import com.google.gerrit.server.account.WatchConfig.NotifyType;
 import com.google.gerrit.server.config.AllProjectsName;
+import com.google.gerrit.server.query.account.InternalAccountQuery;
 import com.google.gerrit.server.query.change.ChangeQueryBuilder;
 import com.google.gerrit.server.query.change.ChangeQueryProcessor;
 import com.google.gson.annotations.SerializedName;
@@ -44,13 +45,15 @@
             AllProjectsName allProjectsName,
             ChangeQueryBuilder cqb,
             ChangeQueryProcessor cqp,
-            Provider<ReviewDb> reviewdb,
+            Provider<InternalAccountQuery> accountQueryProvider,
+            CapabilityControl.Factory capabilityControlFactory,
             GenericFactory identifiedUserFactory) {
         super(pluginName,
                 uploader,
                 allProjectsName,
                 cqb, cqp,
-                reviewdb,
+                accountQueryProvider,
+                capabilityControlFactory,
                 identifiedUserFactory);
     }
 
diff --git a/src/main/resources/Documentation/build.md b/src/main/resources/Documentation/build.md
index 04029fb..2a1d3d6 100644
--- a/src/main/resources/Documentation/build.md
+++ b/src/main/resources/Documentation/build.md
@@ -14,13 +14,13 @@
   git submodule init
   git submodule update
   git clone https://gerrit.googlesource.com/plugins/cloud-notifications plugins/cloud-notifications
-  buck build plugins/cloud-notifications
+  bazel build plugins/cloud-notifications
 ```
 
 The output is created in
 
 ```
-  buck-out/gen/plugins/cloud-notifications/cloud-notifications.jar
+  bazel-genfiles/plugins/cloud-notifications/cloud-notifications.jar
 ```
 
 Check out the Gerrit Plugin API [documentation](https://gerrit-review.googlesource.com/Documentation/dev-buck.html#_extension_and_plugin_api_jar_files)