embulk-output-kintone 0.4.1 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (35) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +8 -6
  3. data/classpath/embulk-output-kintone-1.0.0.jar +0 -0
  4. data/classpath/{shadow-kintone-java-client-0.4.1-all.jar → shadow-kintone-java-client-1.0.0-all.jar} +0 -0
  5. data/src/main/java/org/embulk/output/kintone/KintoneColumnOption.java +1 -2
  6. data/src/main/java/org/embulk/output/kintone/KintoneColumnType.java +368 -0
  7. data/src/main/java/org/embulk/output/kintone/KintoneColumnVisitor.java +195 -135
  8. data/src/main/java/org/embulk/output/kintone/KintoneMode.java +0 -1
  9. data/src/main/java/org/embulk/output/kintone/KintoneOutputPlugin.java +0 -2
  10. data/src/main/java/org/embulk/output/kintone/KintonePageOutput.java +169 -157
  11. data/src/main/java/org/embulk/output/kintone/PluginTask.java +8 -0
  12. data/src/test/java/org/embulk/output/kintone/KintoneColumnOptionBuilder.java +2 -3
  13. data/src/test/java/org/embulk/output/kintone/KintoneColumnVisitorTest.java +563 -40
  14. data/src/test/java/org/embulk/output/kintone/KintoneColumnVisitorVerifier.java +35 -14
  15. data/src/test/java/org/embulk/output/kintone/KintonePageOutputVerifier.java +2 -7
  16. data/src/test/java/org/embulk/output/kintone/TestKintoneOutputPlugin.java +22 -9
  17. data/src/test/java/org/embulk/output/kintone/TestTaskMode.java +12 -0
  18. data/src/test/resources/org/embulk/output/kintone/task/mode/config.yml +104 -0
  19. data/src/test/resources/org/embulk/output/kintone/task/mode/input.csv +7 -7
  20. data/src/test/resources/org/embulk/output/kintone/task/mode/insert_add_ignore_nulls_records.jsonl +6 -0
  21. data/src/test/resources/org/embulk/output/kintone/task/mode/insert_add_prefer_nulls_records.jsonl +6 -0
  22. data/src/test/resources/org/embulk/output/kintone/task/mode/insert_add_records.jsonl +6 -6
  23. data/src/test/resources/org/embulk/output/kintone/task/mode/update_update_ignore_nulls_records.jsonl +3 -0
  24. data/src/test/resources/org/embulk/output/kintone/task/mode/update_update_prefer_nulls_records.jsonl +3 -0
  25. data/src/test/resources/org/embulk/output/kintone/task/mode/update_update_records.jsonl +6 -3
  26. data/src/test/resources/org/embulk/output/kintone/task/mode/upsert_add_ignore_nulls_records.jsonl +3 -0
  27. data/src/test/resources/org/embulk/output/kintone/task/mode/upsert_add_prefer_nulls_records.jsonl +3 -0
  28. data/src/test/resources/org/embulk/output/kintone/task/mode/upsert_add_records.jsonl +2 -2
  29. data/src/test/resources/org/embulk/output/kintone/task/mode/upsert_update_ignore_nulls_records.jsonl +3 -0
  30. data/src/test/resources/org/embulk/output/kintone/task/mode/upsert_update_prefer_nulls_records.jsonl +3 -0
  31. data/src/test/resources/org/embulk/output/kintone/task/mode/upsert_update_records.jsonl +4 -4
  32. data/src/test/resources/org/embulk/output/kintone/task/mode/values_ignore_nulls.json +1 -0
  33. data/src/test/resources/org/embulk/output/kintone/task/mode/values_prefer_nulls.json +1 -0
  34. metadata +15 -4
  35. data/classpath/embulk-output-kintone-0.4.1.jar +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c677006a4f3dfdbec29c97e039045874614b3e99
4
- data.tar.gz: 9c1fff33d958a4ee8be940da64cc7e10af04eb92
3
+ metadata.gz: 11c7f1cbe588863b206b1581bf2ec89adeafeea4
4
+ data.tar.gz: c17ae7651f3409a6e51999e65233a96da2d87bf4
5
5
  SHA512:
6
- metadata.gz: d6e53840dad2b56c75e7422a769f0ae2eb8b24ce6034cc269255952e22442c77164c3bdac78a08f28086e5318df2318f99ad924d1bd85af8966ae83e5d57d627
7
- data.tar.gz: 641e40a2986787204ef8e0feec1b916a2d4d0b5c0cc1d5e9d0137f38eaf8ed43b3b5b0b2f19f3304ee8736668b049d0a115836a62d8d3cd6efa20fe61ecc3be5
6
+ metadata.gz: 4e1bc2fe10bc224c643d88c06a37a19bfe4849fb46318fede913ef3a3923e1315ce48b78aea8bbdcc5ea9a5b4760058776c569e8acedf8f02691b80b330c5657
7
+ data.tar.gz: 9261603e49b45d2c8b72bf013d2995057293dd7f98ae0588f4dfa2f7e962b0ba2eac70990cdd7658eedf72a5caabd9cbb8f3135bc80cb91a7d250706c06081b4
data/README.md CHANGED
@@ -8,19 +8,22 @@ kintone output plugin for Embulk stores app records from kintone.
8
8
 
9
9
  ## Configuration
10
10
 
11
- - **domain**: kintone domain(FQDN) e.g. devfoo.cybozu.com (string, required)
11
+ - **domain**: kintone domain (FQDN) e.g. devfoo.cybozu.com (string, required)
12
12
  - **username**: kintone username (string, optional)
13
13
  - **password**: kintone password (string, optional)
14
14
  - **token**: kintone app token. Username and password or token must be configured. If all of them are provided, this plugin uses username and password (string, optional)
15
15
  - **app_id**: kintone app id (integer, required)
16
- - **basic_auth_username**: kintone basic auth username Please see kintone basic auth [here](https://jp.cybozu.help/general/en/admin/list_security/list_ip_basic/basic_auth.html) (string, optional)
17
- - **basic_auth_password**: kintone basic auth password (string, optional)
16
+ - **basic_auth_username**: kintone basic auth username Please see kintone basic auth [here](https://jp.cybozu.help/general/en/admin/list_security/list_ip_basic/basic_auth.html) (string, optional)
17
+ - **basic_auth_password**: kintone basic auth password (string, optional)
18
18
  - **guest_space_id**: kintone app belongs to guest space, guest space id is required. (integer, optional)
19
19
  - **mode**: kintone mode (string, required)
20
- - **update_key**: column name to set update key (string, required if mode is update or upsert)
20
+ - **update_key**: Column name to set update key (string, required if mode is update or upsert)
21
+ - **prefer_nulls**: Whether to set fields to null instead of default value of type when column is null (boolean, default is `false`)
22
+ - **ignore_nulls**: Whether to completely ignore fields when column is null (boolean, default is `false`)
21
23
  - **column_options** advanced: a key-value pairs where key is a column name and value is options for the column.
22
24
  - **field_code**: field code (string, required)
23
- - **type**: field type (string, required)
25
+ - **type**: field type (string, required). See [this page](https://cybozu.dev/ja/kintone/docs/overview/field-types/#field-type-update) for list of available types. However, following types are not yet supported
26
+ - `USER_SELECT`, `ORGANIZATION_SELECT`, `GROUP_SELECT`, `FILE`, `SUBTABLE`
24
27
  - **timezone**: timezone to convert into `date` (string, default is `UTC`)
25
28
  - **val_sep**: Used to specify multiple checkbox values (string, default is `,`)
26
29
 
@@ -43,7 +46,6 @@ out:
43
46
  date_time: {field_code: "datetime", type: "DATETIME"}
44
47
  ```
45
48
 
46
-
47
49
  ## Build
48
50
 
49
51
  ```
@@ -1,6 +1,5 @@
1
1
  package org.embulk.output.kintone;
2
2
 
3
- import java.util.Optional;
4
3
  import org.embulk.config.Config;
5
4
  import org.embulk.config.ConfigDefault;
6
5
  import org.embulk.config.Task;
@@ -14,7 +13,7 @@ public interface KintoneColumnOption extends Task {
14
13
 
15
14
  @Config("timezone")
16
15
  @ConfigDefault("\"UTC\"")
17
- Optional<String> getTimezone();
16
+ String getTimezone();
18
17
 
19
18
  @Config("val_sep")
20
19
  @ConfigDefault("\",\"")
@@ -0,0 +1,368 @@
1
+ package org.embulk.output.kintone;
2
+
3
+ import com.kintone.client.model.record.CheckBoxFieldValue;
4
+ import com.kintone.client.model.record.DateFieldValue;
5
+ import com.kintone.client.model.record.DateTimeFieldValue;
6
+ import com.kintone.client.model.record.DropDownFieldValue;
7
+ import com.kintone.client.model.record.FieldValue;
8
+ import com.kintone.client.model.record.FileFieldValue;
9
+ import com.kintone.client.model.record.GroupSelectFieldValue;
10
+ import com.kintone.client.model.record.LinkFieldValue;
11
+ import com.kintone.client.model.record.MultiLineTextFieldValue;
12
+ import com.kintone.client.model.record.MultiSelectFieldValue;
13
+ import com.kintone.client.model.record.NumberFieldValue;
14
+ import com.kintone.client.model.record.OrganizationSelectFieldValue;
15
+ import com.kintone.client.model.record.RadioButtonFieldValue;
16
+ import com.kintone.client.model.record.RichTextFieldValue;
17
+ import com.kintone.client.model.record.SingleLineTextFieldValue;
18
+ import com.kintone.client.model.record.SubtableFieldValue;
19
+ import com.kintone.client.model.record.TimeFieldValue;
20
+ import com.kintone.client.model.record.UpdateKey;
21
+ import com.kintone.client.model.record.UserSelectFieldValue;
22
+ import java.math.BigDecimal;
23
+ import java.time.Instant;
24
+ import java.time.LocalDate;
25
+ import java.time.LocalTime;
26
+ import java.time.ZoneId;
27
+ import java.time.ZoneOffset;
28
+ import java.time.ZonedDateTime;
29
+ import java.util.Arrays;
30
+ import java.util.Collections;
31
+ import java.util.List;
32
+ import org.embulk.spi.time.Timestamp;
33
+ import org.msgpack.value.Value;
34
+
35
+ public enum KintoneColumnType {
36
+ SINGLE_LINE_TEXT {
37
+ @Override
38
+ public SingleLineTextFieldValue getFieldValue() {
39
+ return new SingleLineTextFieldValue(null);
40
+ }
41
+
42
+ @Override
43
+ public SingleLineTextFieldValue getFieldValue(String value, KintoneColumnOption option) {
44
+ return new SingleLineTextFieldValue(value);
45
+ }
46
+
47
+ @Override
48
+ public void setUpdateKey(UpdateKey updateKey, String field) {
49
+ updateKey.setField(field);
50
+ }
51
+
52
+ @Override
53
+ public void setUpdateKey(UpdateKey updateKey, String field, FieldValue value) {
54
+ updateKey.setField(field).setValue(((SingleLineTextFieldValue) value).getValue());
55
+ }
56
+ },
57
+ MULTI_LINE_TEXT {
58
+ @Override
59
+ public MultiLineTextFieldValue getFieldValue() {
60
+ return new MultiLineTextFieldValue(null);
61
+ }
62
+
63
+ @Override
64
+ public MultiLineTextFieldValue getFieldValue(String value, KintoneColumnOption option) {
65
+ return new MultiLineTextFieldValue(value);
66
+ }
67
+ },
68
+ RICH_TEXT {
69
+ @Override
70
+ public RichTextFieldValue getFieldValue() {
71
+ return new RichTextFieldValue(null);
72
+ }
73
+
74
+ @Override
75
+ public RichTextFieldValue getFieldValue(String value, KintoneColumnOption option) {
76
+ return new RichTextFieldValue(value);
77
+ }
78
+ },
79
+ NUMBER {
80
+ @Override
81
+ public NumberFieldValue getFieldValue() {
82
+ return new NumberFieldValue(null);
83
+ }
84
+
85
+ @Override
86
+ public NumberFieldValue getFieldValue(boolean value, KintoneColumnOption option) {
87
+ return getFieldValue(value ? "1" : "0", option);
88
+ }
89
+
90
+ @Override
91
+ public NumberFieldValue getFieldValue(String value, KintoneColumnOption option) {
92
+ return new NumberFieldValue(new BigDecimal(value.isEmpty() ? "0" : value));
93
+ }
94
+
95
+ @Override
96
+ public NumberFieldValue getFieldValue(Timestamp value, KintoneColumnOption option) {
97
+ return (NumberFieldValue) getFieldValue(value.getEpochSecond(), option);
98
+ }
99
+
100
+ @Override
101
+ public void setUpdateKey(UpdateKey updateKey, String field) {
102
+ updateKey.setField(field);
103
+ }
104
+
105
+ @Override
106
+ public void setUpdateKey(UpdateKey updateKey, String field, FieldValue value) {
107
+ updateKey.setField(field).setValue(((NumberFieldValue) value).getValue());
108
+ }
109
+ },
110
+ CHECK_BOX {
111
+ @Override
112
+ public CheckBoxFieldValue getFieldValue() {
113
+ return new CheckBoxFieldValue();
114
+ }
115
+
116
+ @Override
117
+ public CheckBoxFieldValue getFieldValue(String value, KintoneColumnOption option) {
118
+ return new CheckBoxFieldValue(asList(value, option));
119
+ }
120
+ },
121
+ RADIO_BUTTON {
122
+ @Override
123
+ public RadioButtonFieldValue getFieldValue() {
124
+ return new RadioButtonFieldValue(null);
125
+ }
126
+
127
+ @Override
128
+ public RadioButtonFieldValue getFieldValue(String value, KintoneColumnOption option) {
129
+ return new RadioButtonFieldValue(value);
130
+ }
131
+ },
132
+ MULTI_SELECT {
133
+ @Override
134
+ public MultiSelectFieldValue getFieldValue() {
135
+ return new MultiSelectFieldValue();
136
+ }
137
+
138
+ @Override
139
+ public MultiSelectFieldValue getFieldValue(String value, KintoneColumnOption option) {
140
+ return new MultiSelectFieldValue(asList(value, option));
141
+ }
142
+ },
143
+ DROP_DOWN {
144
+ @Override
145
+ public DropDownFieldValue getFieldValue() {
146
+ return new DropDownFieldValue(null);
147
+ }
148
+
149
+ @Override
150
+ public DropDownFieldValue getFieldValue(String value, KintoneColumnOption option) {
151
+ return new DropDownFieldValue(value);
152
+ }
153
+ },
154
+ USER_SELECT {
155
+ @Override
156
+ public UserSelectFieldValue getFieldValue() {
157
+ return new UserSelectFieldValue();
158
+ }
159
+
160
+ @Override
161
+ public UserSelectFieldValue getFieldValue(String value, KintoneColumnOption option) {
162
+ throw new UnsupportedOperationException();
163
+ }
164
+ },
165
+ ORGANIZATION_SELECT {
166
+ @Override
167
+ public OrganizationSelectFieldValue getFieldValue() {
168
+ return new OrganizationSelectFieldValue();
169
+ }
170
+
171
+ @Override
172
+ public OrganizationSelectFieldValue getFieldValue(String value, KintoneColumnOption option) {
173
+ throw new UnsupportedOperationException();
174
+ }
175
+ },
176
+ GROUP_SELECT {
177
+ @Override
178
+ public GroupSelectFieldValue getFieldValue() {
179
+ return new GroupSelectFieldValue();
180
+ }
181
+
182
+ @Override
183
+ public GroupSelectFieldValue getFieldValue(String value, KintoneColumnOption option) {
184
+ throw new UnsupportedOperationException();
185
+ }
186
+ },
187
+ DATE {
188
+ @Override
189
+ public DateFieldValue getFieldValue() {
190
+ return new DateFieldValue(null);
191
+ }
192
+
193
+ @Override
194
+ public DateFieldValue getFieldValue(long value, KintoneColumnOption option) {
195
+ return getFieldValue(Timestamp.ofEpochSecond(value), option);
196
+ }
197
+
198
+ @Override
199
+ public DateFieldValue getFieldValue(double value, KintoneColumnOption option) {
200
+ return getFieldValue(Double.valueOf(value).longValue(), option);
201
+ }
202
+
203
+ @Override
204
+ public DateFieldValue getFieldValue(String value, KintoneColumnOption option) {
205
+ return value.isEmpty()
206
+ ? getFieldValue(EPOCH, option)
207
+ : new DateFieldValue(
208
+ LocalDate.parse(value)
209
+ .atStartOfDay(ZoneOffset.UTC)
210
+ .withZoneSameInstant(getZoneId(option))
211
+ .toLocalDate());
212
+ }
213
+
214
+ @Override
215
+ public DateFieldValue getFieldValue(Timestamp value, KintoneColumnOption option) {
216
+ return new DateFieldValue(value.getInstant().atZone(getZoneId(option)).toLocalDate());
217
+ }
218
+ },
219
+ TIME {
220
+ @Override
221
+ public TimeFieldValue getFieldValue() {
222
+ return new TimeFieldValue(null);
223
+ }
224
+
225
+ @Override
226
+ public TimeFieldValue getFieldValue(long value, KintoneColumnOption option) {
227
+ return getFieldValue(Timestamp.ofEpochSecond(value), option);
228
+ }
229
+
230
+ @Override
231
+ public TimeFieldValue getFieldValue(double value, KintoneColumnOption option) {
232
+ return getFieldValue(Double.valueOf(value).longValue(), option);
233
+ }
234
+
235
+ @Override
236
+ public TimeFieldValue getFieldValue(String value, KintoneColumnOption option) {
237
+ return value.isEmpty()
238
+ ? getFieldValue(EPOCH, option)
239
+ : new TimeFieldValue(
240
+ LocalTime.parse(value)
241
+ .atOffset(ZoneOffset.UTC)
242
+ .withOffsetSameInstant(getZoneOffset(option))
243
+ .toLocalTime());
244
+ }
245
+
246
+ @Override
247
+ public TimeFieldValue getFieldValue(Timestamp value, KintoneColumnOption option) {
248
+ return new TimeFieldValue(value.getInstant().atZone(getZoneId(option)).toLocalTime());
249
+ }
250
+ },
251
+ DATETIME {
252
+ @Override
253
+ public DateTimeFieldValue getFieldValue() {
254
+ return new DateTimeFieldValue(null);
255
+ }
256
+
257
+ @Override
258
+ public DateTimeFieldValue getFieldValue(long value, KintoneColumnOption option) {
259
+ return getFieldValue(Timestamp.ofEpochSecond(value), option);
260
+ }
261
+
262
+ @Override
263
+ public DateTimeFieldValue getFieldValue(double value, KintoneColumnOption option) {
264
+ return getFieldValue(Double.valueOf(value).longValue(), option);
265
+ }
266
+
267
+ @Override
268
+ public DateTimeFieldValue getFieldValue(String value, KintoneColumnOption option) {
269
+ return value.isEmpty()
270
+ ? getFieldValue(EPOCH, option)
271
+ : new DateTimeFieldValue(ZonedDateTime.parse(value));
272
+ }
273
+
274
+ @Override
275
+ public DateTimeFieldValue getFieldValue(Timestamp value, KintoneColumnOption option) {
276
+ return new DateTimeFieldValue(value.getInstant().atZone(ZoneOffset.UTC));
277
+ }
278
+ },
279
+ LINK {
280
+ @Override
281
+ public LinkFieldValue getFieldValue() {
282
+ return new LinkFieldValue(null);
283
+ }
284
+
285
+ @Override
286
+ public LinkFieldValue getFieldValue(String value, KintoneColumnOption option) {
287
+ return new LinkFieldValue(value);
288
+ }
289
+ },
290
+ FILE {
291
+ @Override
292
+ public FileFieldValue getFieldValue() {
293
+ return new FileFieldValue();
294
+ }
295
+
296
+ @Override
297
+ public FileFieldValue getFieldValue(String value, KintoneColumnOption option) {
298
+ throw new UnsupportedOperationException();
299
+ }
300
+ },
301
+ SUBTABLE {
302
+ @Override
303
+ public SubtableFieldValue getFieldValue() {
304
+ return new SubtableFieldValue();
305
+ }
306
+
307
+ @Override
308
+ public SubtableFieldValue getFieldValue(String value, KintoneColumnOption option) {
309
+ throw new UnsupportedOperationException();
310
+ }
311
+ };
312
+ private static final Timestamp EPOCH = Timestamp.ofInstant(Instant.EPOCH);
313
+
314
+ public static KintoneColumnType getType(
315
+ KintoneColumnOption option, KintoneColumnType defaultType) {
316
+ return option != null ? valueOf(option.getType()) : defaultType;
317
+ }
318
+
319
+ public abstract FieldValue getFieldValue();
320
+
321
+ public FieldValue getFieldValue(boolean value, KintoneColumnOption option) {
322
+ return getFieldValue(String.valueOf(value), option);
323
+ }
324
+
325
+ public FieldValue getFieldValue(long value, KintoneColumnOption option) {
326
+ return getFieldValue(String.valueOf(value), option);
327
+ }
328
+
329
+ public FieldValue getFieldValue(double value, KintoneColumnOption option) {
330
+ return getFieldValue(String.valueOf(value), option);
331
+ }
332
+
333
+ public abstract FieldValue getFieldValue(String value, KintoneColumnOption option);
334
+
335
+ public FieldValue getFieldValue(Timestamp value, KintoneColumnOption option) {
336
+ return getFieldValue(value.getInstant().toString(), option);
337
+ }
338
+
339
+ public FieldValue getFieldValue(Value value, KintoneColumnOption option) {
340
+ return getFieldValue(value.toJson(), option);
341
+ }
342
+
343
+ public void setUpdateKey(UpdateKey updateKey, String field) {
344
+ throw new UnsupportedOperationException();
345
+ }
346
+
347
+ public void setUpdateKey(UpdateKey updateKey, String field, FieldValue value) {
348
+ throw new UnsupportedOperationException();
349
+ }
350
+
351
+ private static List<String> asList(String value, KintoneColumnOption option) {
352
+ return value.isEmpty()
353
+ ? Collections.emptyList()
354
+ : Arrays.asList(value.split(getValueSeparator(option), 0));
355
+ }
356
+
357
+ private static ZoneOffset getZoneOffset(KintoneColumnOption option) {
358
+ return getZoneId(option).getRules().getOffset(Instant.EPOCH);
359
+ }
360
+
361
+ private static ZoneId getZoneId(KintoneColumnOption option) {
362
+ return ZoneId.of(option != null ? option.getTimezone() : "UTC");
363
+ }
364
+
365
+ private static String getValueSeparator(KintoneColumnOption option) {
366
+ return option != null ? option.getValueSeparator() : ",";
367
+ }
368
+ }