Migrate from project.info to project.search conduit API method

Change-Id: I95367d0ca0b2c609d4e3939fede0b47ac430d7f0
diff --git a/src/main/java/com/googlesource/gerrit/plugins/its/phabricator/PhabricatorItsFacade.java b/src/main/java/com/googlesource/gerrit/plugins/its/phabricator/PhabricatorItsFacade.java
index 82264bc..f2bd4ff 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/its/phabricator/PhabricatorItsFacade.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/its/phabricator/PhabricatorItsFacade.java
@@ -27,7 +27,7 @@
 import com.googlesource.gerrit.plugins.its.phabricator.conduit.ConduitException;
 import com.googlesource.gerrit.plugins.its.phabricator.conduit.results.ManiphestSearch;
 import com.googlesource.gerrit.plugins.its.phabricator.conduit.results.ManiphestResults;
-import com.googlesource.gerrit.plugins.its.phabricator.conduit.results.ProjectInfo;
+import com.googlesource.gerrit.plugins.its.phabricator.conduit.results.ProjectSearch;
 import java.io.IOException;
 import java.net.URL;
 import java.util.Set;
@@ -131,8 +131,8 @@
 
   private void maniphestEdit(String projectName, int taskId, String actions) throws IOException {
     try {
-      ProjectInfo projectInfo = conduit.projectQuery(projectName);
-      String projectPhid = projectInfo.getPhid();
+      ProjectSearch projectSearch = conduit.projectSearch(projectName);
+      String projectPhid = projectSearch.getPhid();
 
       Set<String> projectPhids = Sets.newHashSet(projectPhid);
 
diff --git a/src/main/java/com/googlesource/gerrit/plugins/its/phabricator/conduit/Conduit.java b/src/main/java/com/googlesource/gerrit/plugins/its/phabricator/conduit/Conduit.java
index 15e227d..0ff669a 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/its/phabricator/conduit/Conduit.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/its/phabricator/conduit/Conduit.java
@@ -15,14 +15,15 @@
 package com.googlesource.gerrit.plugins.its.phabricator.conduit;
 
 import com.google.gson.Gson;
+import com.google.gson.JsonArray;
 import com.google.gson.JsonElement;
 import com.google.gson.JsonObject;
 import com.googlesource.gerrit.plugins.its.phabricator.conduit.results.ConduitPing;
 import com.googlesource.gerrit.plugins.its.phabricator.conduit.results.ManiphestEdit;
-import com.googlesource.gerrit.plugins.its.phabricator.conduit.results.ManiphestSearch;
 import com.googlesource.gerrit.plugins.its.phabricator.conduit.results.ManiphestResults;
-import com.googlesource.gerrit.plugins.its.phabricator.conduit.results.ProjectInfo;
-import com.googlesource.gerrit.plugins.its.phabricator.conduit.results.QueryResult;
+import com.googlesource.gerrit.plugins.its.phabricator.conduit.results.ManiphestSearch;
+import com.googlesource.gerrit.plugins.its.phabricator.conduit.results.ProjectResults;
+import com.googlesource.gerrit.plugins.its.phabricator.conduit.results.ProjectSearch;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.HashMap;
@@ -148,21 +149,24 @@
     return result;
   }
 
-  /** Runs the API's 'projectQuery' method to match exactly one project name */
-  public ProjectInfo projectQuery(String name) throws ConduitException {
-    Map<String, Object> params = new HashMap<>();
-    params.put("names", Arrays.asList(name));
+  /** Runs the API's 'projectSearch' method to match exactly one project name */
+  public ProjectSearch projectSearch(String name) throws ConduitException {
+    HashMap<String, Object> params = new HashMap<>();
+    HashMap<String, Object> params2 = new HashMap<>();
 
-    JsonElement callResult = conduitConnection.call("project.query", params, token);
-    QueryResult queryResult = gson.fromJson(callResult, QueryResult.class);
-    JsonObject queryResultData = queryResult.getData().getAsJsonObject();
+    params2.put("query", name);
 
-    ProjectInfo result = null;
-    for (Entry<String, JsonElement> queryResultEntry : queryResultData.entrySet()) {
-      JsonElement queryResultEntryValue = queryResultEntry.getValue();
-      ProjectInfo queryResultProjectInfo = gson.fromJson(queryResultEntryValue, ProjectInfo.class);
-      if (queryResultProjectInfo.getName().equals(name)) {
-        result = queryResultProjectInfo;
+    params.put("constraints", params2);
+
+    JsonElement callResult = conduitConnection.call("project.search", params, token);
+    ProjectResults projectResult = gson.fromJson(callResult, ProjectResults.class);
+    JsonArray projectResultData = projectResult.getData().getAsJsonArray();
+
+    ProjectSearch result = null;
+    for (JsonElement jsonElement : projectResultData) {
+      ProjectSearch projectResultSearch = gson.fromJson(jsonElement, ProjectSearch.class);
+      if (projectResultSearch.getFields().getName().equals(name)) {
+        result = projectResultSearch;
       }
     }
     return result;
diff --git a/src/main/java/com/googlesource/gerrit/plugins/its/phabricator/conduit/results/ProjectInfo.java b/src/main/java/com/googlesource/gerrit/plugins/its/phabricator/conduit/results/ProjectInfo.java
deleted file mode 100644
index c0d2706..0000000
--- a/src/main/java/com/googlesource/gerrit/plugins/its/phabricator/conduit/results/ProjectInfo.java
+++ /dev/null
@@ -1,89 +0,0 @@
-// Copyright (C) 2015 The Android Open Source Project
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-package com.googlesource.gerrit.plugins.its.phabricator.conduit.results;
-
-import com.google.gson.JsonElement;
-
-/**
- * Models the result for API methods returning Project information
- *
- * <p>JSON looks like:
- *
- * <pre>
- * {
- *   "id":"23",
- *   "phid":"PHID-PROJ-lxmsio4ggx63mhakxhnn",
- *   "name":"QChris-Test-Project",
- *   "profileImagePHID":null,
- *   "icon":"briefcase",
- *   "color":"blue",
- *   "members":["PHID-USER-kem5g5ua7s75ffvlzwgk","PHID-USER-h4n62fq2kt2v3a2qjyqh"],
- *   "slugs":["qchris-test-project"],
- *   "dateCreated":"1413551900",
- *   "dateModified":"1424557030"
- * }
- * </pre>
- */
-public class ProjectInfo {
-  private int id;
-  private String phid;
-  private String name;
-  private String profileImagePHID;
-  private String icon;
-  private String color;
-  private JsonElement members;
-  private JsonElement slugs;
-  private String dateCreated;
-  private String dateModified;
-
-  public int getId() {
-    return id;
-  }
-
-  public String getPhid() {
-    return phid;
-  }
-
-  public String getName() {
-    return name;
-  }
-
-  public String getProfileImagePHID() {
-    return profileImagePHID;
-  }
-
-  public String getIcon() {
-    return icon;
-  }
-
-  public String getColor() {
-    return color;
-  }
-
-  public JsonElement getMembers() {
-    return members;
-  }
-
-  public JsonElement getSlugs() {
-    return slugs;
-  }
-
-  public String getDateCreated() {
-    return dateCreated;
-  }
-
-  public String getDateModified() {
-    return dateModified;
-  }
-}
diff --git a/src/main/java/com/googlesource/gerrit/plugins/its/phabricator/conduit/results/QueryResult.java b/src/main/java/com/googlesource/gerrit/plugins/its/phabricator/conduit/results/ProjectResults.java
similarity index 68%
rename from src/main/java/com/googlesource/gerrit/plugins/its/phabricator/conduit/results/QueryResult.java
rename to src/main/java/com/googlesource/gerrit/plugins/its/phabricator/conduit/results/ProjectResults.java
index 5f45f15..fcd9b44 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/its/phabricator/conduit/results/QueryResult.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/its/phabricator/conduit/results/ProjectResults.java
@@ -1,4 +1,4 @@
-// Copyright (C) 2015 The Android Open Source Project
+// Copyright (C) 2018 The Android Open Source Project
 //
 // Licensed under the Apache License, Version 2.0 (the "License");
 // you may not use this file except in compliance with the License.
@@ -11,41 +11,38 @@
 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 // See the License for the specific language governing permissions and
 // limitations under the License.
+
 package com.googlesource.gerrit.plugins.its.phabricator.conduit.results;
 
 import com.google.gson.JsonElement;
 
 /**
- * Models the result for API methods returning a (possible paged) QueryResult
+ * Models the result for API methods
  *
  * <p>JSON looks like:
  *
  * <pre>
  * {
- *   "data": { ... },
- *   "slugMap": [],
+ *   "data": [
+ *     { ... }
+ *   ],
+ *   "maps": {},
+ *   "query": {
+ *     "queryKey": null
+ *   },
  *   "cursor": {
  *     "limit": 100,
  *     "after": null,
- *     "before": null
+ *     "before": null,
+ *     "order": null
  *   }
  * }
  * </pre>
  */
-public class QueryResult {
+public class ProjectResults {
   private JsonElement data;
-  private JsonElement slugMap;
-  private JsonElement cursor;
 
   public JsonElement getData() {
     return data;
   }
-
-  public JsonElement getSlugMap() {
-    return slugMap;
-  }
-
-  public JsonElement getCursor() {
-    return cursor;
-  }
 }
diff --git a/src/main/java/com/googlesource/gerrit/plugins/its/phabricator/conduit/results/ProjectSearch.java b/src/main/java/com/googlesource/gerrit/plugins/its/phabricator/conduit/results/ProjectSearch.java
new file mode 100644
index 0000000..7410c68
--- /dev/null
+++ b/src/main/java/com/googlesource/gerrit/plugins/its/phabricator/conduit/results/ProjectSearch.java
@@ -0,0 +1,90 @@
+// Copyright (C) 2018 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package com.googlesource.gerrit.plugins.its.phabricator.conduit.results;
+
+import com.google.gson.JsonElement;
+
+/**
+ * Models the result for API methods returning Project searches.
+ *
+ * <p>JSON looks like:</p>
+ *
+ * <pre>
+ * {
+ * "id": 8,
+ * "type": "PROJ",
+ * "phid": "PHID-PROJ-ro6wrekgi7u3fwzz5p6a",
+ * "fields": {
+ *   "name": "Patch-For-Review",
+ *   "slug": "patch-for-review",
+ *   "milestone": null,
+ *   "depth": 0,
+ *   "parent": null,
+ *   "icon": {
+ *     "key": "project",
+ *     "name": "Project",
+ *     "icon": "fa-briefcase"
+ *   },
+ *   "color": {
+ *     "key": "pink",
+ *     "name": "Pink"
+ *   },
+ *   "spacePHID": null,
+ *   "dateCreated": 1538054863,
+ *   "dateModified": 1538090166,
+ *   "policy": {
+ *     "view": "public",
+ *     "edit": "users",
+ *     "join": "users"
+ *   },
+ *   "description": null,
+ *   "startdate": null,
+ *   "enddate": null,
+ *   "issprint": false
+ * },
+ * "attachments": {}
+ * }
+ * </pre>
+ */
+public class ProjectSearch {
+  private int id;
+  private String type;
+  private String phid;
+  private Fields fields;
+
+  public int getId() {
+    return id;
+  }
+
+  public String getType() {
+    return type;
+  }
+
+  public String getPhid() {
+    return phid;
+  }
+
+  public Fields getFields() {
+    return fields;
+  }
+
+  public class Fields {
+    private String name;
+
+    public String getName() {
+      return name;
+    }
+  }
+}