epugh commented on code in PR #4203:
URL: https://github.com/apache/solr/pull/4203#discussion_r3448609648


##########
solr/core/src/java/org/apache/solr/handler/designer/SchemaDesigner.java:
##########
@@ -772,57 +767,80 @@ public void query(SolrQueryRequest req, SolrQueryResponse 
rsp)
           version,
           currentVersion);
       List<SolrInputDocument> docs = 
configSetHelper.retrieveSampleDocs(configSet);
-      ManagedIndexSchema schema = loadLatestSchema(mutableId);
-      errorsDuringIndexing =
-          indexSampleDocsWithRebuildOnAnalysisError(
-              schema.getUniqueKeyField().getName(), docs, mutableId, true, 
null);
-      // the version changes when you index (due to field guessing URP)
-      currentVersion = configSetHelper.getCurrentSchemaVersion(mutableId);
+      if (!docs.isEmpty()) {
+        ManagedIndexSchema schema = loadLatestSchema(mutableId);
+        errorsDuringIndexing =
+            indexSampleDocsWithRebuildOnAnalysisError(
+                schema.getUniqueKeyField().getName(), docs, mutableId, true, 
null);
+        // the version changes when you index (due to field guessing URP)
+        currentVersion = configSetHelper.getCurrentSchemaVersion(mutableId);
+      }
       indexedVersion.put(mutableId, currentVersion);
     }
 
     if (errorsDuringIndexing != null) {
-      Map<String, Object> response = new HashMap<>();
-      rsp.setException(
+      Map<String, Object> errorResponse = new HashMap<>();
+      addErrorToResponse(
+          mutableId,
           new SolrException(
               SolrException.ErrorCode.BAD_REQUEST,
-              "Failed to re-index sample documents after schema updated."));
-      response.put(ERROR_DETAILS, errorsDuringIndexing);
-      rsp.getValues().addAll(response);
-      return;
+              "Failed to re-index sample documents after schema updated."),
+          errorsDuringIndexing,
+          errorResponse,
+          "Failed to re-index sample documents after schema updated.");
+      return buildFlexibleResponse(errorResponse);
     }
 
     // execute the user's query against the temp collection
-    QueryResponse qr = cloudClient().query(mutableId, req.getParams());
-    rsp.getValues().addAll(qr.getResponse());
+    QueryResponse qr = cloudClient().query(mutableId, 
solrQueryRequest.getParams());
+    Map<String, Object> responseMap = new HashMap<>();
+    qr.getResponse()
+        .forEach(
+            (name, val) -> {
+              if ("response".equals(name) && val instanceof SolrDocumentList) {
+                // SolrDocumentList extends ArrayList, so Jackson would 
serialize it as a plain
+                // array, losing numFound/start metadata that the UI expects 
at data.response.docs
+                SolrDocumentList docList = (SolrDocumentList) val;
+                Map<String, Object> responseObj = new HashMap<>();
+                responseObj.put("numFound", docList.getNumFound());
+                responseObj.put("start", docList.getStart());
+                responseObj.put("docs", new ArrayList<>(docList));
+                responseMap.put(name, responseObj);
+              } else {
+                responseMap.put(name, val);
+              }
+            });
+    return buildFlexibleResponse(responseMap);
   }
 
   /**
    * Return the diff of designer schema with the source schema (either 
previously published or the
    * copyFrom).
    */
-  @EndPoint(method = GET, path = "/schema-designer/diff", permission = 
CONFIG_READ_PERM)
-  public void getSchemaDiff(SolrQueryRequest req, SolrQueryResponse rsp) 
throws IOException {
-    final String configSet = getRequiredParam(CONFIG_SET_PARAM, req);
+  @Override
+  @PermissionName(CONFIG_READ_PERM)
+  public SchemaDesignerSchemaDiffResponse getSchemaDiff(String configSet) 
throws Exception {
+    requireNotEmpty(CONFIG_SET_PARAM, configSet);
 
     SchemaDesignerSettings settings = getMutableSchemaForConfigSet(configSet, 
-1, null);
     // diff the published if found, else use the original source schema
     String sourceSchema = configExists(configSet) ? configSet : 
settings.getCopyFrom();
-    Map<String, Object> response = new HashMap<>();
-    response.put(
-        "diff", ManagedSchemaDiff.diff(loadLatestSchema(sourceSchema), 
settings.getSchema()));
-    response.put("diff-source", sourceSchema);
+    SchemaDesignerSchemaDiffResponse response =

Review Comment:
   done!   Made this change in various palces.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to