From 5474302cb917e117bd68788f20b5f5e281f38e66 Mon Sep 17 00:00:00 2001 From: Dan Hermann Date: Thu, 21 Jan 2021 10:41:04 -0600 Subject: [PATCH 1/2] rename mime_type to media_type --- docs/reference/ingest/processors/set.asciidoc | 2 +- .../ingest/common/SetProcessor.java | 4 +- .../common/SetProcessorFactoryTests.java | 4 +- .../ingest/ConfigurationUtils.java | 12 ++--- .../ingest/ConfigurationUtilsTests.java | 50 ++++++++++--------- 5 files changed, 37 insertions(+), 35 deletions(-) diff --git a/docs/reference/ingest/processors/set.asciidoc b/docs/reference/ingest/processors/set.asciidoc index 9d9c95a17f6ff..1220928057442 100644 --- a/docs/reference/ingest/processors/set.asciidoc +++ b/docs/reference/ingest/processors/set.asciidoc @@ -17,7 +17,7 @@ its value will be replaced with the provided one. | `copy_from` | no | - | The origin field which will be copied to `field`, cannot set `value` simultaneously. Supported data types are `boolean`, `number`, `array`, `object`, `string`, `date`, etc. | `override` | no | `true` | If processor will update fields with pre-existing non-null-valued field. When set to `false`, such fields will not be touched. | `ignore_empty_value` | no | `false` | If `true` and `value` is a <> that evaluates to `null` or the empty string, the processor quietly exits without modifying the document -| `mime_type` | no | `application/json` | The MIME type for encoding `value`. Applies only when `value` is a <>. Must be one of `application/json`, `text/plain`, or `application/x-www-form-urlencoded`. +| `media_type` | no | `application/json` | The media type for encoding `value`. Applies only when `value` is a <>. Must be one of `application/json`, `text/plain`, or `application/x-www-form-urlencoded`. include::common-options.asciidoc[] |====== diff --git a/modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/SetProcessor.java b/modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/SetProcessor.java index a716a0984b4ea..c30868480beab 100644 --- a/modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/SetProcessor.java +++ b/modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/SetProcessor.java @@ -111,11 +111,11 @@ public SetProcessor create(Map registry, String proce String description, Map config) throws Exception { String field = ConfigurationUtils.readStringProperty(TYPE, processorTag, config, "field"); String copyFrom = ConfigurationUtils.readOptionalStringProperty(TYPE, processorTag, config, "copy_from"); - String mimeType = ConfigurationUtils.readMimeTypeProperty(TYPE, processorTag, config, "mime_type", "application/json"); + String mediaType = ConfigurationUtils.readMediaTypeProperty(TYPE, processorTag, config, "media_type", "application/json"); ValueSource valueSource = null; if (copyFrom == null) { Object value = ConfigurationUtils.readObject(TYPE, processorTag, config, "value"); - valueSource = ValueSource.wrap(value, scriptService, Map.of(Script.CONTENT_TYPE_OPTION, mimeType)); + valueSource = ValueSource.wrap(value, scriptService, Map.of(Script.CONTENT_TYPE_OPTION, mediaType)); } else { Object value = config.remove("value"); if (value != null) { diff --git a/modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/SetProcessorFactoryTests.java b/modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/SetProcessorFactoryTests.java index cb8565db1d30f..39502b31da924 100644 --- a/modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/SetProcessorFactoryTests.java +++ b/modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/SetProcessorFactoryTests.java @@ -139,7 +139,7 @@ public void testCreateWithCopyFromAndValue() throws Exception { public void testMimeType() throws Exception { // valid mime type - String expectedMimeType = randomFrom(ConfigurationUtils.VALID_MIME_TYPES); + String expectedMimeType = randomFrom(ConfigurationUtils.VALID_MEDIA_TYPES); Map config = new HashMap<>(); config.put("field", "field1"); config.put("value", "value1"); @@ -149,7 +149,7 @@ public void testMimeType() throws Exception { assertThat(setProcessor.getTag(), equalTo(processorTag)); // invalid mime type - expectedMimeType = randomValueOtherThanMany(m -> Arrays.asList(ConfigurationUtils.VALID_MIME_TYPES).contains(m), + expectedMimeType = randomValueOtherThanMany(m -> Arrays.asList(ConfigurationUtils.VALID_MEDIA_TYPES).contains(m), () -> randomAlphaOfLengthBetween(5, 9)); final Map config2 = new HashMap<>(); config2.put("field", "field1"); diff --git a/server/src/main/java/org/elasticsearch/ingest/ConfigurationUtils.java b/server/src/main/java/org/elasticsearch/ingest/ConfigurationUtils.java index c41bf83c03e1d..0b609a13bbd42 100644 --- a/server/src/main/java/org/elasticsearch/ingest/ConfigurationUtils.java +++ b/server/src/main/java/org/elasticsearch/ingest/ConfigurationUtils.java @@ -49,7 +49,7 @@ public final class ConfigurationUtils { public static final String TAG_KEY = "tag"; public static final String DESCRIPTION_KEY = "description"; - public static final String[] VALID_MIME_TYPES = {"application/json", "text/plain", "application/x-www-form-urlencoded"}; + public static final String[] VALID_MEDIA_TYPES = {"application/json", "text/plain", "application/x-www-form-urlencoded"}; private ConfigurationUtils() { } @@ -306,16 +306,16 @@ public static Object readObject(String processorType, String processorTag, Map configuration, + public static String readMediaTypeProperty(String processorType, String processorTag, Map configuration, String propertyName, String defaultValue) { - String mimeType = readStringProperty(processorType, processorTag, configuration, propertyName, defaultValue); + String mediaType = readStringProperty(processorType, processorTag, configuration, propertyName, defaultValue); - if (Arrays.asList(VALID_MIME_TYPES).contains(mimeType) == false) { + if (Arrays.asList(VALID_MEDIA_TYPES).contains(mediaType) == false) { throw newConfigurationException(processorType, processorTag, propertyName, - "property does not contain a supported MIME type [" + mimeType + "]"); + "property does not contain a supported media type [" + mediaType + "]"); } - return mimeType; + return mediaType; } public static ElasticsearchException newConfigurationException(String processorType, String processorTag, diff --git a/server/src/test/java/org/elasticsearch/ingest/ConfigurationUtilsTests.java b/server/src/test/java/org/elasticsearch/ingest/ConfigurationUtilsTests.java index ace2be9a31d38..3aa2cf7919281 100644 --- a/server/src/test/java/org/elasticsearch/ingest/ConfigurationUtilsTests.java +++ b/server/src/test/java/org/elasticsearch/ingest/ConfigurationUtilsTests.java @@ -116,34 +116,36 @@ public void testReadStringOrIntPropertyInvalidType() { } } - public void testReadMimeProperty() { - // valid mime type - String expectedMimeType = randomFrom(ConfigurationUtils.VALID_MIME_TYPES); - config.put("mime_type", expectedMimeType); - String readMimeType = ConfigurationUtils.readMimeTypeProperty(null, null, config, "mime_type", ""); - assertThat(readMimeType, equalTo(expectedMimeType)); - - // missing mime type with valid default - expectedMimeType = randomFrom(ConfigurationUtils.VALID_MIME_TYPES); - config.remove("mime_type"); - readMimeType = ConfigurationUtils.readMimeTypeProperty(null, null, config, "mime_type", expectedMimeType); - assertThat(readMimeType, equalTo(expectedMimeType)); - - // invalid mime type - expectedMimeType = randomValueOtherThanMany(m -> Arrays.asList(ConfigurationUtils.VALID_MIME_TYPES).contains(m), + public void testReadMediaProperty() { + // valid media type + String expectedMediaType = randomFrom(ConfigurationUtils.VALID_MEDIA_TYPES); + config.put("media_type", expectedMediaType); + String readMediaType = ConfigurationUtils.readMediaTypeProperty(null, null, config, "media_type", ""); + assertThat(readMediaType, equalTo(expectedMediaType)); + + // missing media type with valid default + expectedMediaType = randomFrom(ConfigurationUtils.VALID_MEDIA_TYPES); + config.remove("media_type"); + readMediaType = ConfigurationUtils.readMediaTypeProperty(null, null, config, "media_type", expectedMediaType); + assertThat(readMediaType, equalTo(expectedMediaType)); + + // invalid media type + expectedMediaType = randomValueOtherThanMany(m -> Arrays.asList(ConfigurationUtils.VALID_MEDIA_TYPES).contains(m), () -> randomAlphaOfLengthBetween(5, 9)); - config.put("mime_type", expectedMimeType); + config.put("media_type", expectedMediaType); ElasticsearchException e = expectThrows(ElasticsearchException.class, - () -> ConfigurationUtils.readMimeTypeProperty(null, null, config, "mime_type", "")); - assertThat(e.getMessage(), containsString("property does not contain a supported MIME type [" + expectedMimeType + "]")); + () -> ConfigurationUtils.readMediaTypeProperty(null, null, config, "media_type", "")); + assertThat(e.getMessage(), containsString("property does not contain a supported media type [" + expectedMediaType + "]")); - // missing mime type with invalid default - final String invalidDefaultMimeType = randomValueOtherThanMany(m -> Arrays.asList(ConfigurationUtils.VALID_MIME_TYPES).contains(m), - () -> randomAlphaOfLengthBetween(5, 9)); - config.remove("mime_type"); + // missing media type with invalid default + final String invalidDefaultMediaType = randomValueOtherThanMany( + m -> Arrays.asList(ConfigurationUtils.VALID_MEDIA_TYPES).contains(m), + () -> randomAlphaOfLengthBetween(5, 9) + ); + config.remove("media_type"); e = expectThrows(ElasticsearchException.class, - () -> ConfigurationUtils.readMimeTypeProperty(null, null, config, "mime_type", invalidDefaultMimeType)); - assertThat(e.getMessage(), containsString("property does not contain a supported MIME type [" + invalidDefaultMimeType + "]")); + () -> ConfigurationUtils.readMediaTypeProperty(null, null, config, "media_type", invalidDefaultMediaType)); + assertThat(e.getMessage(), containsString("property does not contain a supported media type [" + invalidDefaultMediaType + "]")); } public void testReadProcessors() throws Exception { From 975f124116b315735895d26e978725c1bf4be900 Mon Sep 17 00:00:00 2001 From: Dan Hermann Date: Fri, 22 Jan 2021 07:40:13 -0600 Subject: [PATCH 2/2] rename mime to media in one more test --- .../ingest/common/SetProcessorFactoryTests.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/SetProcessorFactoryTests.java b/modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/SetProcessorFactoryTests.java index 39502b31da924..90c89552ef8c4 100644 --- a/modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/SetProcessorFactoryTests.java +++ b/modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/SetProcessorFactoryTests.java @@ -137,25 +137,25 @@ public void testCreateWithCopyFromAndValue() throws Exception { assertThat(exception.getMessage(), equalTo("[copy_from] cannot set both `copy_from` and `value` in the same processor")); } - public void testMimeType() throws Exception { - // valid mime type - String expectedMimeType = randomFrom(ConfigurationUtils.VALID_MEDIA_TYPES); + public void testMediaType() throws Exception { + // valid media type + String expectedMediaType = randomFrom(ConfigurationUtils.VALID_MEDIA_TYPES); Map config = new HashMap<>(); config.put("field", "field1"); config.put("value", "value1"); - config.put("mime_type", expectedMimeType); + config.put("media_type", expectedMediaType); String processorTag = randomAlphaOfLength(10); SetProcessor setProcessor = factory.create(null, processorTag, null, config); assertThat(setProcessor.getTag(), equalTo(processorTag)); - // invalid mime type - expectedMimeType = randomValueOtherThanMany(m -> Arrays.asList(ConfigurationUtils.VALID_MEDIA_TYPES).contains(m), + // invalid media type + expectedMediaType = randomValueOtherThanMany(m -> Arrays.asList(ConfigurationUtils.VALID_MEDIA_TYPES).contains(m), () -> randomAlphaOfLengthBetween(5, 9)); final Map config2 = new HashMap<>(); config2.put("field", "field1"); config2.put("value", "value1"); - config2.put("mime_type", expectedMimeType); + config2.put("media_type", expectedMediaType); ElasticsearchException e = expectThrows(ElasticsearchException.class, () -> factory.create(null, processorTag, null, config2)); - assertThat(e.getMessage(), containsString("property does not contain a supported MIME type [" + expectedMimeType + "]")); + assertThat(e.getMessage(), containsString("property does not contain a supported media type [" + expectedMediaType + "]")); } }