Adapt warm-cache script for gerrit 3.7

The script is pretty old, looks like it was developed sometime in 2016
based on Gerrit 2.14 (?). As such when running it in Gerrit 3.7 some
classes are missing and therefore the commands will fail.
Change the script in a way that compiles with gerrit 3.7 version
and all exposed commands run successfully. Replace ReviewDB operations
with its successor where possible.

Change-Id: I594a32d7e4eff6dabf1c761b6dcb9342508812f9
diff --git a/admin/warm-cache-1.0.groovy b/admin/warm-cache-1.0.groovy
index eb1df2c..1bad068 100644
--- a/admin/warm-cache-1.0.groovy
+++ b/admin/warm-cache-1.0.groovy
@@ -13,13 +13,12 @@
 // limitations under the License.
 
 import com.google.gerrit.common.data.GlobalCapability
+import com.google.gerrit.entities.AccountGroup
 import com.google.gerrit.sshd.*
 import com.google.gerrit.extensions.annotations.*
 import com.google.gerrit.server.project.*
 import com.google.gerrit.server.account.*
 import com.google.gerrit.server.IdentifiedUser
-import com.google.gerrit.reviewdb.client.AccountGroup
-import com.google.gerrit.reviewdb.server.ReviewDb
 import com.google.inject.*
 import org.kohsuke.args4j.*
 
@@ -75,8 +74,8 @@
   private HashSet<AccountGroup.UUID> allGroupsUUIDs() {
     def allGroupsUuids = new HashSet<AccountGroup.UUID>()
     for (project in cache.all()) {
-      def groupUuids = cache.get(project)?.getConfig()?.getAllGroupUUIDs()
-      if (groupUuids != null) { allGroupsUuids.addAll(groupUuids) }
+      def groupUuids = cache.get(project).stream().flatMap { it.config.allGroupUUIDs.stream() }
+      allGroupsUuids.addAll(groupUuids.collect())
     }
     allGroupsUuids.addAll(groupIncludeCache.allExternalMembers())
     return allGroupsUuids;
@@ -90,12 +89,11 @@
     def groupsLoaded = 0
 
     for (groupUuid in allGroupsUuids) {
-      groupIncludeCache.subgroupsOf(groupUuid)
       groupIncludeCache.parentGroupsOf(groupUuid)
       def group = groupCache.get(groupUuid)
-      if(group != null) {
-        groupCache.get(group.getNameKey())
-        groupCache.get(group.getId())
+      group.ifPresent { internalGroup ->
+        groupCache.get(internalGroup.getNameKey())
+        groupCache.get(internalGroup.getId())
       }
       groupsLoaded++
 
@@ -117,16 +115,16 @@
   AccountCache cache
 
   @Inject
-  Provider<ReviewDb> db
+  Accounts accounts
 
   public void run() {
     println "Loading accounts ..."
     def start = System.currentTimeMillis()
-    def allAccounts = db.get().accounts().all()
+    def allAccounts = accounts.all()
     def loaded = 0
 
     for (account in allAccounts) {
-      cache.get(account.accountId)
+      cache.get(account.account().id())
       loaded++
       if (loaded%1000==0) {
         println "$loaded accounts"
@@ -148,13 +146,13 @@
   public void run() {
     println "Loading groups ..."
     def start = System.currentTimeMillis()
-    def allAccounts = db.get().accounts().all()
+    def allAccounts = accounts.all()
     def loaded = 0
     def allGroupsUUIDs = new HashSet<AccountGroup.UUID>()
     def lastDisplay = 0
 
     for (account in allAccounts) {
-      def user = userFactory.create(account.accountId)
+      def user = userFactory.create(account.account().id())
       def groupsUUIDs = user?.getEffectiveGroups()?.getKnownGroups()
       if (groupsUUIDs != null) { allGroupsUUIDs.addAll(groupsUUIDs) }