Skip to content

Commit

Permalink
Add formatter config from OpenSearch
Browse files Browse the repository at this point in the history
Apply same formatting config as OpenSearch.

Signed-off-by: Vijayan Balasubramanian <[email protected]>
  • Loading branch information
VijayanB committed Jan 19, 2022
1 parent 800c1af commit a5bbd1c
Show file tree
Hide file tree
Showing 7 changed files with 392 additions and 18 deletions.
2 changes: 2 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ spotless {
java {
removeUnusedImports()
importOrder 'java', 'javax', 'org', 'com'
eclipse().configFile rootProject.file('formatterConfig.xml')
trimTrailingWhitespace()
endWithNewline()
}
}
373 changes: 373 additions & 0 deletions formatterConfig.xml

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

package org.opensearch.geospatial.geojson;


import java.util.HashMap;
import java.util.Map;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ public FeatureProcessor(String tag, String description, String geoShapeField) {
this.geoShapeField = geoShapeField;
}


@Override
public IngestDocument execute(IngestDocument ingestDocument) {
// 1. Create Feature from ingesting document
Expand All @@ -55,8 +54,12 @@ public String getType() {

public static final class Factory implements org.opensearch.ingest.Processor.Factory {
@Override
public FeatureProcessor create(Map<String, Processor.Factory> registry, String processorTag,
String description, Map<String, Object> config) {
public FeatureProcessor create(
Map<String, Processor.Factory> registry,
String processorTag,
String description,
Map<String, Object> config
) {
String geoShapeField = readStringProperty(TYPE, processorTag, config, FIELD_KEY);
return new FeatureProcessor(processorTag, description, geoShapeField);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ private static String buildPipelinePath(String name) {
return String.join(URL_DELIMITER, "_ingest", "pipeline", name);
}

protected static void createPipeline(String name, Optional<String> description, List<Map<String, Object>> processorConfigs) throws IOException {
protected static void createPipeline(String name, Optional<String> description, List<Map<String, Object>> processorConfigs)
throws IOException {
XContentBuilder builder = XContentFactory.jsonBuilder().startObject();
if (description.isPresent()) {
builder.field(Pipeline.DESCRIPTION_KEY, description.get());
Expand All @@ -61,9 +62,7 @@ protected static void deletePipeline(String name) throws IOException {
protected static void createIndex(String name, Settings settings, Map<String, String> fieldMap) throws IOException {
XContentBuilder xContentBuilder = XContentFactory.jsonBuilder().startObject().startObject(Feature.PROPERTIES_KEY);
for (Map.Entry<String, String> entry : fieldMap.entrySet()) {
xContentBuilder.startObject(entry.getKey())
.field(Feature.TYPE_KEY, entry.getValue())
.endObject();
xContentBuilder.startObject(entry.getKey()).field(Feature.TYPE_KEY, entry.getValue()).endObject();
}
xContentBuilder.endObject().endObject();
String mapping = Strings.toString(xContentBuilder);
Expand All @@ -73,9 +72,7 @@ protected static void createIndex(String name, Settings settings, Map<String, St
public static void indexDocument(String indexName, String docID, String body, Map<String, String> params) throws IOException {

String path = String.join(URL_DELIMITER, indexName, DOC, docID);
String queryParams = params.entrySet().stream()
.map(Object::toString)
.collect(joining("&"));
String queryParams = params.entrySet().stream().map(Object::toString).collect(joining("&"));
StringBuilder endpoint = new StringBuilder();
endpoint.append(path);
endpoint.append("?");
Expand All @@ -94,7 +91,8 @@ protected Map<String, Object> buildGeoJSONProcessorConfig(Map<String, String> pr

public String buildGeoJSONFeatureAsString(String type, Object value, Map<String, Object> properties) throws IOException {

XContentBuilder builder = XContentFactory.jsonBuilder().startObject()
XContentBuilder builder = XContentFactory.jsonBuilder()
.startObject()
.field(Feature.TYPE_KEY, Feature.TYPE)
.startObject(Feature.GEOMETRY_KEY)
.field(GEOMETRY_TYPE_KEY, type)
Expand All @@ -113,8 +111,8 @@ public Map<String, Object> getDocument(String docID, String indexName) throws IO
final Request request = new Request("GET", path);
final Response response = client().performRequest(request);

final Map<String, Object> responseMap =
createParser(XContentType.JSON.xContent(), EntityUtils.toString(response.getEntity())).map();
final Map<String, Object> responseMap = createParser(XContentType.JSON.xContent(), EntityUtils.toString(response.getEntity()))
.map();
if (!responseMap.containsKey(SOURCE)) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ public void testIndexGeoJSONSuccess() throws IOException {
Map<String, String> geoFields = new HashMap<>();
geoFields.put(geoShapeField, "geo_shape");


Map<String, String> processorProperties = new HashMap<>();
processorProperties.put(FeatureProcessor.FIELD_KEY, geoShapeField);
Map<String, Object> geoJSONProcessorConfig = buildGeoJSONProcessorConfig(processorProperties);
Expand All @@ -74,10 +73,11 @@ public void testIndexGeoJSONSuccess() throws IOException {
properties.put(randomString(random()), randomString(random()));
properties.put(randomString(random()), randomString(random()));


String body = buildGeoJSONFeatureAsString(
GeoShapeType.LINESTRING.shapeName(),
randomDoubleArray(LINESTRING_TOTAL_POINTS, LINESTRING_POINT_DIMENSION), properties);
randomDoubleArray(LINESTRING_TOTAL_POINTS, LINESTRING_POINT_DIMENSION),
properties
);
Map<String, String> params = new HashMap<>();
params.put("pipeline", pipelineName);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import com.carrotsearch.randomizedtesting.annotations.Name;
import com.carrotsearch.randomizedtesting.annotations.ParametersFactory;


public class GeospatialClientYamlTestSuiteIT extends OpenSearchClientYamlSuiteTestCase {

public GeospatialClientYamlTestSuiteIT(@Name("yaml") ClientYamlTestCandidate testCandidate) {
Expand Down

0 comments on commit a5bbd1c

Please sign in to comment.