Adapt to Gerrit v3.2 for Accounts and ProjectCache

Accounts and ProjectCache have changed their interface
in Gerrit v3.2 and therefore needs adaptation with the
removal of the accounts cache invalidation and the introduction
of Optional<ProjectState> instead of nulls.

Change-Id: I7bc0e65cf3cfa7978a65e44b616d0be41c1172c4
diff --git a/github-plugin/src/main/java/com/googlesource/gerrit/plugins/github/git/PullRequestImportJob.java b/github-plugin/src/main/java/com/googlesource/gerrit/plugins/github/git/PullRequestImportJob.java
index 9b234f5..cb71e78 100644
--- a/github-plugin/src/main/java/com/googlesource/gerrit/plugins/github/git/PullRequestImportJob.java
+++ b/github-plugin/src/main/java/com/googlesource/gerrit/plugins/github/git/PullRequestImportJob.java
@@ -82,7 +82,7 @@
   private final int jobIndex;
   private final ExternalIds externalIds;
   private PullRequestCreateChange createChange;
-  private Project project;
+  private Optional<Project> project;
   private GitJobStatus status;
   private boolean cancelRequested;
   private AccountImporter accountImporter;
@@ -114,11 +114,10 @@
     this.externalIds = externalIds;
   }
 
-  private Project fetchGerritProject(
+  private Optional<Project> fetchGerritProject(
       ProjectCache projectCache, String fetchOrganisation, String fetchRepoName) {
     NameKey projectNameKey = Project.NameKey.parse(fetchOrganisation + "/" + fetchRepoName);
-    ProjectState projectState = projectCache.get(projectNameKey);
-    return projectState.getProject();
+    return projectCache.get(projectNameKey).map(ProjectState::getProject);
   }
 
   @Override
@@ -179,17 +178,19 @@
         GitHubUser gitHubUser = GitHubUser.from(prUser, commitAuthor);
 
         Account.Id pullRequestOwner = getOrRegisterAccount(gitHubUser);
-        Id changeId =
-            createChange.addCommitToChange(
-                project,
-                gitRepo,
-                destinationBranch,
-                pullRequestOwner,
-                revCommit,
-                getChangeMessage(pr),
-                String.format(TOPIC_FORMAT, new Integer(pr.getNumber())));
-        if (changeId != null) {
-          prChanges.add(changeId);
+        if (project.isPresent()) {
+          Id changeId =
+              createChange.addCommitToChange(
+                  project.get(),
+                  gitRepo,
+                  destinationBranch,
+                  pullRequestOwner,
+                  revCommit,
+                  getChangeMessage(pr),
+                  String.format(TOPIC_FORMAT, new Integer(pr.getNumber())));
+          if (changeId != null) {
+            prChanges.add(changeId);
+          }
         }
       }
 
diff --git a/github-plugin/src/main/java/com/googlesource/gerrit/plugins/github/wizard/AccountController.java b/github-plugin/src/main/java/com/googlesource/gerrit/plugins/github/wizard/AccountController.java
index 318dc81..e2b8041 100644
--- a/github-plugin/src/main/java/com/googlesource/gerrit/plugins/github/wizard/AccountController.java
+++ b/github-plugin/src/main/java/com/googlesource/gerrit/plugins/github/wizard/AccountController.java
@@ -160,9 +160,6 @@
           email,
           fullName,
           username);
-
-      accountCache.evict(accountId);
-      log.debug("Account cache evicted for {}", accountId);
     } catch (Exception e) {
       throw new ServletException(
           "Cannot associate email '" + email + "' to current user '" + user + "'", e);