embulk-output-mailchimp 0.3.23 → 0.3.24

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f18ee80430139a3e22677d7e18e3fd80eed89665
4
- data.tar.gz: 1c3ebcd7abeaae441d926103f0920ca7d5d6ac6d
3
+ metadata.gz: 7bd2a4db83fe03e54434449187716447a8c7ce7b
4
+ data.tar.gz: 3b3385ab55f592b937b38a4cfac2f2c5d62ad548
5
5
  SHA512:
6
- metadata.gz: ae75be9b1e060a13d6f0bcb4dfa71cea026f653832944bbcfd023df5987b819407decfac00fbdb84c8f31431c7c30dfe1dd8f2b16dcfa47f813ada7a93ba8a64
7
- data.tar.gz: 960ede6f290226c7f35d3d2554175669e14db0a2ecc8ec89f87a8e2548b63f4438b54651f1e04a5a4122853709473a8a15acbae35e5f9e654cda87a62b062200
6
+ metadata.gz: 727ddd4c581d69b5b34962d73a3d8a54e2e4365ee98b7ddd13df84b04b6c8222adcc101673056c74c113ba061d654034dd7fea4b4dfe1e48e148ddbeaa2b1c2b
7
+ data.tar.gz: ecd1e9229bb8015e28eea7a5dbedb70e7997b28fb74d78ab3cdafbf4e2790ff6f7f22a0523ace0e710cf873f4bdf2166db9d59a79ae1b77cd50cd933459c6bcf
data/build.gradle CHANGED
@@ -18,7 +18,7 @@ configurations {
18
18
  provided
19
19
  }
20
20
 
21
- version = "0.3.23"
21
+ version = "0.3.24"
22
22
 
23
23
  sourceCompatibility = 1.7
24
24
  targetCompatibility = 1.7
@@ -33,9 +33,11 @@ import java.util.HashSet;
33
33
  import java.util.List;
34
34
  import java.util.Map;
35
35
  import java.util.Set;
36
+ import java.util.TreeMap;
36
37
 
38
+ import static java.lang.String.CASE_INSENSITIVE_ORDER;
39
+ import static java.lang.String.format;
37
40
  import static org.embulk.output.mailchimp.MailChimpOutputPluginDelegate.PluginTask;
38
- import static org.embulk.output.mailchimp.helper.MailChimpHelper.containsCaseInsensitive;
39
41
  import static org.embulk.output.mailchimp.helper.MailChimpHelper.fromCommaSeparatedString;
40
42
  import static org.embulk.output.mailchimp.helper.MailChimpHelper.orderJsonNode;
41
43
  import static org.embulk.output.mailchimp.helper.MailChimpHelper.toJsonNode;
@@ -206,26 +208,38 @@ public class MailChimpRecordBuffer
206
208
 
207
209
  // Update additional merge fields if exist
208
210
  if (task.getMergeFields().isPresent() && !task.getMergeFields().get().isEmpty()) {
209
- for (final Column column : schema.getColumns()) {
210
- if (!"".equals(containsCaseInsensitive(column.getName(), task.getMergeFields().get()))) {
211
- String value = input.hasNonNull(column.getName()) ? input.findValue(column.getName()).asText() : "";
212
-
213
- // Try to convert to Json from string with the merge field's type is address
214
- if (availableMergeFields.get(column.getName().toLowerCase()).getType()
215
- .equals(MergeField.MergeFieldType.ADDRESS.getType())) {
216
- JsonNode addressNode = toJsonNode(value);
217
- if (addressNode instanceof NullNode) {
218
- mergeFields.put(column.getName().toUpperCase(), value);
219
- }
220
- else {
221
- mergeFields.set(column.getName().toUpperCase(),
222
- orderJsonNode(addressNode, AddressMergeFieldAttribute.values()));
223
- }
211
+ Map<String, String> columnNameLookup = new TreeMap<>(CASE_INSENSITIVE_ORDER);
212
+ for (Column col : schema.getColumns()) {
213
+ columnNameLookup.put(col.getName(), col.getName());
214
+ }
215
+ for (String field : task.getMergeFields().get()) {
216
+ if (!columnNameLookup.containsKey(field)) {
217
+ LOG.warn(format("Field '%s' is configured on data transfer but cannot be found on any columns.", field));
218
+ continue;
219
+ }
220
+ String columnName = columnNameLookup.get(field);
221
+ if (!availableMergeFields.containsKey(columnName.toLowerCase())) {
222
+ LOG.warn(format("Field '%s' is configured on data transfer but is not predefined on Mailchimp.", field));
223
+ continue;
224
+ }
225
+
226
+ String value = input.hasNonNull(columnName) ? input.findValue(columnName).asText() : "";
227
+
228
+ // Try to convert to Json from string with the merge field's type is address
229
+ if (availableMergeFields.get(columnName).getType()
230
+ .equals(MergeField.MergeFieldType.ADDRESS.getType())) {
231
+ JsonNode addressNode = toJsonNode(value);
232
+ if (addressNode instanceof NullNode) {
233
+ mergeFields.put(columnName.toUpperCase(), value);
224
234
  }
225
235
  else {
226
- mergeFields.put(column.getName().toUpperCase(), value);
236
+ mergeFields.set(columnName.toUpperCase(),
237
+ orderJsonNode(addressNode, AddressMergeFieldAttribute.values()));
227
238
  }
228
239
  }
240
+ else {
241
+ mergeFields.put(columnName.toUpperCase(), value);
242
+ }
229
243
  }
230
244
  }
231
245
 
@@ -45,15 +45,14 @@ public final class MailChimpHelper
45
45
  * @param list the list
46
46
  * @return the boolean
47
47
  */
48
- public static String containsCaseInsensitive(final String s, final List<String> list)
48
+ public static boolean containsCaseInsensitive(final String s, final List<String> list)
49
49
  {
50
50
  for (String string : list) {
51
51
  if (string.equalsIgnoreCase(s)) {
52
- return string;
52
+ return true;
53
53
  }
54
54
  }
55
-
56
- return "";
55
+ return false;
57
56
  }
58
57
 
59
58
  /**
@@ -20,6 +20,7 @@ import static org.embulk.output.mailchimp.helper.MailChimpHelper.orderJsonNode;
20
20
  import static org.embulk.output.mailchimp.helper.MailChimpHelper.toJsonNode;
21
21
  import static org.junit.Assert.assertArrayEquals;
22
22
  import static org.junit.Assert.assertEquals;
23
+ import static org.junit.Assert.assertTrue;
23
24
 
24
25
  /**
25
26
  * Created by thangnc on 4/26/17.
@@ -37,8 +38,7 @@ public class TestMailChimpHelper
37
38
  @Test
38
39
  public void test_containsCaseInsensitive_validMergeFields()
39
40
  {
40
- String expect = "United State";
41
- assertEquals("Interest category should match", expect, containsCaseInsensitive("united state",
41
+ assertTrue("Interest category should match", containsCaseInsensitive("united state",
42
42
  Arrays.asList("Donating", "United State")));
43
43
  }
44
44
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: embulk-output-mailchimp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.23
4
+ version: 0.3.24
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thang Nguyen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-09-11 00:00:00.000000000 Z
11
+ date: 2018-10-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement
@@ -88,13 +88,13 @@ files:
88
88
  - test/embulk/output/test_mailchimp.rb
89
89
  - test/override_assert_raise.rb
90
90
  - test/run-test.rb
91
- - classpath/embulk-base-restclient-0.5.3.jar
92
- - classpath/embulk-output-mailchimp-0.3.23.jar
93
- - classpath/embulk-util-retryhelper-jetty92-0.5.3.jar
94
- - classpath/jetty-client-9.2.14.v20151106.jar
95
- - classpath/jetty-http-9.2.14.v20151106.jar
96
91
  - classpath/jetty-io-9.2.14.v20151106.jar
92
+ - classpath/embulk-output-mailchimp-0.3.24.jar
97
93
  - classpath/jetty-util-9.2.14.v20151106.jar
94
+ - classpath/jetty-http-9.2.14.v20151106.jar
95
+ - classpath/jetty-client-9.2.14.v20151106.jar
96
+ - classpath/embulk-base-restclient-0.5.3.jar
97
+ - classpath/embulk-util-retryhelper-jetty92-0.5.3.jar
98
98
  homepage: https://github.com/treasure-data/embulk-output-mailchimp
99
99
  licenses:
100
100
  - MIT