bszabo97 commented on code in PR #1682:
URL: https://github.com/apache/solr/pull/1682#discussion_r1224119019


##########
solr/core/src/java/org/apache/solr/handler/admin/api/GetSchemaFieldAPI.java:
##########
@@ -0,0 +1,255 @@
+package org.apache.solr.handler.admin.api;
+
+import static 
org.apache.solr.client.solrj.impl.BinaryResponseParser.BINARY_CONTENT_TYPE_V2;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+import java.util.List;
+import java.util.Map;
+import javax.inject.Inject;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+import org.apache.solr.common.MapWriter;
+import org.apache.solr.common.SolrException;
+import org.apache.solr.common.cloud.SolrClassLoader;
+import org.apache.solr.common.params.SolrParams;
+import org.apache.solr.common.util.NamedList;
+import org.apache.solr.common.util.SimpleOrderedMap;
+import org.apache.solr.core.PluginInfo;
+import org.apache.solr.jersey.PermissionName;
+import org.apache.solr.jersey.SolrJerseyResponse;
+import org.apache.solr.pkg.PackageListeningClassLoader;
+import org.apache.solr.schema.IndexSchema;
+import org.apache.solr.security.PermissionNameProvider;
+
+public class GetSchemaFieldAPI extends GetSchemaAPI {
+
+  private final SolrParams params;
+
+  @Inject
+  public GetSchemaFieldAPI(IndexSchema indexSchema, SolrParams params) {
+    super(indexSchema);
+    this.params = params;
+  }
+
+  @GET
+  @Path("/fields")
+  @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, 
BINARY_CONTENT_TYPE_V2})
+  @PermissionName(PermissionNameProvider.Name.SCHEMA_READ_PERM)
+  public SchemaListFieldsResponse listSchemaFields() {
+    SchemaListFieldsResponse response = 
instantiateJerseyResponse(SchemaListFieldsResponse.class);
+    final String realName = "fields";
+
+    response.fields = listAllFieldsOfType(realName, params);
+
+    return response;
+  }
+
+  public static class SchemaListFieldsResponse extends SolrJerseyResponse {
+    @JsonProperty("fields")
+    public Object fields;
+  }
+
+  @GET
+  @Path("/fields/{fieldName}")
+  @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_ATOM_XML, 
BINARY_CONTENT_TYPE_V2})
+  @PermissionName(PermissionNameProvider.Name.SCHEMA_READ_PERM)
+  public SchemaGetFieldInfoResponse getFieldInfo(@PathParam("fieldName") 
String fieldName) {
+    SchemaGetFieldInfoResponse response =
+        instantiateJerseyResponse(SchemaGetFieldInfoResponse.class);
+    final String realName = "fields";
+
+    SimpleOrderedMap<Object> fieldInfo = retrieveFieldInfoOfType(realName, 
fieldName, params);
+    if (fieldInfo != null) {
+      response.fieldInfo = fieldInfo;
+      return response;
+    }
+    throw new SolrException(
+        SolrException.ErrorCode.NOT_FOUND, "No such path /" + realName + "/" + 
fieldName);
+  }
+
+  public static class SchemaGetFieldInfoResponse extends SolrJerseyResponse {
+    @JsonProperty("field")
+    public SimpleOrderedMap<?> fieldInfo;
+  }
+
+  @GET
+  @Path("/copyfields")
+  @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, 
BINARY_CONTENT_TYPE_V2})
+  @PermissionName(PermissionNameProvider.Name.SCHEMA_READ_PERM)
+  public SchemaListCopyFieldsResponse listCopyFields() {
+    SchemaListCopyFieldsResponse response =
+        instantiateJerseyResponse(SchemaListCopyFieldsResponse.class);
+    final String realName = "copyfields";
+
+    response.copyFields = listAllFieldsOfType(realName, params);
+
+    return response;
+  }
+
+  public static class SchemaListCopyFieldsResponse extends SolrJerseyResponse {
+    @JsonProperty("copyFields")
+    public Object copyFields;
+  }
+
+  @GET
+  @Path("/dynamicfields")
+  @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, 
BINARY_CONTENT_TYPE_V2})
+  @PermissionName(PermissionNameProvider.Name.SCHEMA_READ_PERM)
+  public SchemaListDynamicFieldsResponse listDynamicFields() {
+    SchemaListDynamicFieldsResponse response =
+        instantiateJerseyResponse(SchemaListDynamicFieldsResponse.class);
+    final String realName = "dynamicfields";
+
+    response.dynamicFields = listAllFieldsOfType(realName, params);
+
+    return response;
+  }
+
+  public static class SchemaListDynamicFieldsResponse extends 
SolrJerseyResponse {
+    @JsonProperty("dynamicFields")
+    public Object dynamicFields;
+  }
+
+  @GET
+  @Path("/dynamicfields/{fieldName}")
+  @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_ATOM_XML, 
BINARY_CONTENT_TYPE_V2})
+  @PermissionName(PermissionNameProvider.Name.SCHEMA_READ_PERM)
+  public SchemaGetDynamicFieldInfoResponse getDynamicFieldInfo(
+      @PathParam("fieldName") String fieldName) {
+    SchemaGetDynamicFieldInfoResponse response =
+        instantiateJerseyResponse(SchemaGetDynamicFieldInfoResponse.class);
+    final String realName = "dynamicfields";
+
+    SimpleOrderedMap<Object> dynamicFieldInfo =
+        retrieveFieldInfoOfType(realName, fieldName, params);
+    if (dynamicFieldInfo != null) {
+      response.dynamicFieldInfo = dynamicFieldInfo;
+      return response;
+    }
+    throw new SolrException(
+        SolrException.ErrorCode.NOT_FOUND, "No such path /" + realName + "/" + 
fieldName);
+  }
+
+  public static class SchemaGetDynamicFieldInfoResponse extends 
SolrJerseyResponse {
+    @JsonProperty("dynamicField")
+    public SimpleOrderedMap<?> dynamicFieldInfo;
+  }
+
+  @GET
+  @Path("/fieldtypes")
+  @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, 
BINARY_CONTENT_TYPE_V2})
+  @PermissionName(PermissionNameProvider.Name.SCHEMA_READ_PERM)
+  public SchemaListFieldTypesResponse listSchemaFieldTypes() {
+    SchemaListFieldTypesResponse response =
+        instantiateJerseyResponse(SchemaListFieldTypesResponse.class);
+    final String realName = "fieldtypes";
+
+    response.fieldTypes = listAllFieldsOfType(realName, params);
+
+    return response;
+  }
+
+  public static class SchemaListFieldTypesResponse extends SolrJerseyResponse {
+    @JsonProperty("fieldTypes")
+    public Object fieldTypes;
+  }
+
+  @GET
+  @Path("/fieldtypes/{fieldTypeName}")
+  @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_ATOM_XML, 
BINARY_CONTENT_TYPE_V2})
+  @PermissionName(PermissionNameProvider.Name.SCHEMA_READ_PERM)
+  public SchemaGetFieldTypeInfoResponse getFieldTypeInfo(
+      @PathParam("fieldTypeName") String fieldTypeName) {
+    SchemaGetFieldTypeInfoResponse response =
+        instantiateJerseyResponse(SchemaGetFieldTypeInfoResponse.class);
+
+    final String realName = "fieldtypes";
+
+    SimpleOrderedMap<Object> fieldTypeInfo =
+        retrieveFieldInfoOfType(realName, fieldTypeName, params);
+    if (fieldTypeInfo != null) {
+      response.fieldTypeInfo = fieldTypeInfo;
+      return response;
+    }
+    throw new SolrException(
+        SolrException.ErrorCode.NOT_FOUND, "No such path /" + realName + "/" + 
fieldTypeName);
+  }
+
+  public static class SchemaGetFieldTypeInfoResponse extends 
SolrJerseyResponse {
+    @JsonProperty("fieldType")
+    public SimpleOrderedMap<?> fieldTypeInfo;
+  }
+
+  private Object listAllFieldsOfType(String realName, SolrParams params) {
+    String camelCaseRealName = IndexSchema.nameMapping.get(realName);

Review Comment:
   I was doing an experiment before this approach to try and pass all the 
necessary parameters, but I have found 
[here](https://github.com/apache/solr/blob/8089e6fc6a9d37299df9a63e5372ec5c235e4f9a/solr/core/src/java/org/apache/solr/schema/IndexSchema.java#L1643-L1647)
 that we would need at least 6 parameters. I considered it a bit too much to 
nicely handle so I went ahead and used the parameter injection instead. 
   If you think 6 parameters is a viable option I can easily change it back to 
that approach. Let me know what you think!



-- 
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: issues-unsubscr...@solr.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@solr.apache.org
For additional commands, e-mail: issues-h...@solr.apache.org

Reply via email to