embulk-output-kintone 0.3.3 → 0.3.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +11 -4
- data/build.gradle +11 -0
- data/classpath/{embulk-output-kintone-0.3.3.jar → embulk-output-kintone-0.3.6.jar} +0 -0
- data/src/main/java/org/embulk/output/kintone/KintoneColumnOption.java +12 -15
- data/src/main/java/org/embulk/output/kintone/KintoneColumnVisitor.java +186 -211
- data/src/main/java/org/embulk/output/kintone/KintoneMode.java +19 -21
- data/src/main/java/org/embulk/output/kintone/KintoneOutputPlugin.java +41 -54
- data/src/main/java/org/embulk/output/kintone/KintonePageOutput.java +277 -284
- data/src/main/java/org/embulk/output/kintone/PluginTask.java +34 -37
- data/src/test/java/org/embulk/output/kintone/TestKintoneOutputPlugin.java +1 -3
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4db580dd68dc408de335d4c115a01394b794e0b1
|
4
|
+
data.tar.gz: 420c0efc922b96404adce1f13e68611e12c7d6fa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 03b503cff07e5b80f4fd0c1d57f81e74df997d5a07d710081e6058fcb3811492f1ba9e1e9b9ba1a3396727591445a6a1bc4f3684283c4d7bfaca099ad709f4a8
|
7
|
+
data.tar.gz: 6b0e6f9d6d0753b559fdffa57b53a24884fb68d1b6e8daa0e6cd5c1a0e62f3124a2e2e1008a873f2768216bd1b99f2e5f0af9f60bc0a38c168fe70ffbaca01ec
|
data/.github/workflows/ci.yml
CHANGED
@@ -3,14 +3,18 @@ name: main
|
|
3
3
|
on:
|
4
4
|
push:
|
5
5
|
branches:
|
6
|
-
-
|
6
|
+
- "master"
|
7
7
|
tags:
|
8
|
-
-
|
8
|
+
- "*"
|
9
9
|
pull_request:
|
10
10
|
branches:
|
11
|
-
-
|
11
|
+
- "master"
|
12
12
|
types: [opened, synchronize]
|
13
13
|
|
14
|
+
permissions:
|
15
|
+
contents: read
|
16
|
+
packages: write
|
17
|
+
|
14
18
|
jobs:
|
15
19
|
main:
|
16
20
|
runs-on: ubuntu-latest
|
@@ -21,6 +25,9 @@ jobs:
|
|
21
25
|
with:
|
22
26
|
java-version: 1.8
|
23
27
|
|
28
|
+
- name: Code format check by Spotless
|
29
|
+
run: ./gradlew spotlessCheck
|
30
|
+
|
24
31
|
- name: Test
|
25
32
|
run: ./gradlew test
|
26
33
|
|
@@ -57,4 +64,4 @@ jobs:
|
|
57
64
|
gem push --otp="${OTP_TOKEN}" ./pkg/*.gem
|
58
65
|
env:
|
59
66
|
GEM_HOST_API_KEY: "${{secrets.RUBYGEMS_API_KEY}}"
|
60
|
-
OTP_SECRET: "${{secrets.RUBYGEMS_OTP_SECRET}}"
|
67
|
+
OTP_SECRET: "${{secrets.RUBYGEMS_OTP_SECRET}}"
|
data/build.gradle
CHANGED
@@ -5,6 +5,7 @@ plugins {
|
|
5
5
|
id "java"
|
6
6
|
id "checkstyle"
|
7
7
|
id "com.palantir.git-version" version "0.12.3"
|
8
|
+
id "com.diffplug.spotless" version "6.13.0"
|
8
9
|
}
|
9
10
|
import com.github.jrubygradle.JRubyExec
|
10
11
|
repositories {
|
@@ -116,3 +117,13 @@ end
|
|
116
117
|
}
|
117
118
|
}
|
118
119
|
clean { delete "${project.name}.gemspec" }
|
120
|
+
|
121
|
+
spotless {
|
122
|
+
java {
|
123
|
+
importOrder()
|
124
|
+
removeUnusedImports()
|
125
|
+
googleJavaFormat()
|
126
|
+
formatAnnotations()
|
127
|
+
toggleOffOn()
|
128
|
+
}
|
129
|
+
}
|
Binary file
|
@@ -1,25 +1,22 @@
|
|
1
1
|
package org.embulk.output.kintone;
|
2
2
|
|
3
|
+
import java.util.Optional;
|
3
4
|
import org.embulk.config.Config;
|
4
5
|
import org.embulk.config.ConfigDefault;
|
5
6
|
import org.embulk.config.Task;
|
6
7
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
extends Task
|
11
|
-
{
|
12
|
-
@Config("type")
|
13
|
-
String getType();
|
8
|
+
public interface KintoneColumnOption extends Task {
|
9
|
+
@Config("type")
|
10
|
+
String getType();
|
14
11
|
|
15
|
-
|
16
|
-
|
12
|
+
@Config("field_code")
|
13
|
+
String getFieldCode();
|
17
14
|
|
18
|
-
|
19
|
-
|
20
|
-
|
15
|
+
@Config("timezone")
|
16
|
+
@ConfigDefault("\"UTC\"")
|
17
|
+
Optional<String> getTimezone();
|
21
18
|
|
22
|
-
|
23
|
-
|
24
|
-
|
19
|
+
@Config("val_sep")
|
20
|
+
@ConfigDefault("\",\"")
|
21
|
+
String getValueSeparator();
|
25
22
|
}
|
@@ -12,222 +12,197 @@ import com.kintone.client.model.record.NumberFieldValue;
|
|
12
12
|
import com.kintone.client.model.record.Record;
|
13
13
|
import com.kintone.client.model.record.SingleLineTextFieldValue;
|
14
14
|
import com.kintone.client.model.record.UpdateKey;
|
15
|
-
import org.embulk.spi.Column;
|
16
|
-
import org.embulk.spi.ColumnVisitor;
|
17
|
-
import org.embulk.spi.PageReader;
|
18
|
-
import org.embulk.spi.time.Timestamp;
|
19
|
-
|
20
15
|
import java.math.BigDecimal;
|
21
16
|
import java.time.Instant;
|
22
17
|
import java.time.ZoneId;
|
23
18
|
import java.time.ZonedDateTime;
|
19
|
+
import java.util.Arrays;
|
20
|
+
import java.util.List;
|
24
21
|
import java.util.Map;
|
25
22
|
import java.util.Objects;
|
23
|
+
import org.embulk.spi.Column;
|
24
|
+
import org.embulk.spi.ColumnVisitor;
|
25
|
+
import org.embulk.spi.PageReader;
|
26
|
+
import org.embulk.spi.time.Timestamp;
|
26
27
|
|
27
|
-
public class KintoneColumnVisitor
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
}
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
}
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
}
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
}
|
208
|
-
|
209
|
-
@Override
|
210
|
-
public void timestampColumn(Column column)
|
211
|
-
{
|
212
|
-
Timestamp value = pageReader.getTimestamp(column);
|
213
|
-
if (value == null) {
|
214
|
-
return;
|
215
|
-
}
|
216
|
-
|
217
|
-
String fieldCode = getFieldCode(column);
|
218
|
-
FieldType type = getType(column, FieldType.DATETIME);
|
219
|
-
ZoneId zoneId = getZoneId(column);
|
220
|
-
if (type == FieldType.DATETIME) {
|
221
|
-
zoneId = ZoneId.of("UTC");
|
222
|
-
}
|
223
|
-
setTimestampValue(fieldCode, value.getInstant(), zoneId, type);
|
224
|
-
}
|
225
|
-
|
226
|
-
@Override
|
227
|
-
public void jsonColumn(Column column)
|
228
|
-
{
|
229
|
-
String fieldCode = getFieldCode(column);
|
230
|
-
FieldType type = getType(column, FieldType.MULTI_LINE_TEXT);
|
231
|
-
setValue(fieldCode, pageReader.getJson(column), type, isUpdateKey(column));
|
232
|
-
}
|
28
|
+
public class KintoneColumnVisitor implements ColumnVisitor {
|
29
|
+
private final PageReader pageReader;
|
30
|
+
private Record record;
|
31
|
+
private UpdateKey updateKey;
|
32
|
+
private final Map<String, KintoneColumnOption> columnOptions;
|
33
|
+
private String updateKeyName;
|
34
|
+
|
35
|
+
public KintoneColumnVisitor(
|
36
|
+
PageReader pageReader, Map<String, KintoneColumnOption> columnOptions) {
|
37
|
+
this.pageReader = pageReader;
|
38
|
+
this.columnOptions = columnOptions;
|
39
|
+
}
|
40
|
+
|
41
|
+
public KintoneColumnVisitor(
|
42
|
+
PageReader pageReader, Map<String, KintoneColumnOption> columnOptions, String updateKeyName) {
|
43
|
+
this.pageReader = pageReader;
|
44
|
+
this.columnOptions = columnOptions;
|
45
|
+
this.updateKeyName = updateKeyName;
|
46
|
+
}
|
47
|
+
|
48
|
+
public void setRecord(Record record) {
|
49
|
+
this.record = record;
|
50
|
+
}
|
51
|
+
|
52
|
+
public void setUpdateKey(UpdateKey updateKey) {
|
53
|
+
this.updateKey = updateKey;
|
54
|
+
}
|
55
|
+
|
56
|
+
private void setValue(String fieldCode, Object value, FieldType type, boolean isUpdateKey) {
|
57
|
+
if (isUpdateKey && updateKey != null) {
|
58
|
+
updateKey.setField(fieldCode).setValue(Objects.toString(value, ""));
|
59
|
+
}
|
60
|
+
String stringValue = Objects.toString(value, "");
|
61
|
+
FieldValue fieldValue;
|
62
|
+
switch (type) {
|
63
|
+
case NUMBER:
|
64
|
+
BigDecimal setValue = stringValue.equals("") ? null : new BigDecimal(stringValue);
|
65
|
+
fieldValue = new NumberFieldValue(setValue);
|
66
|
+
break;
|
67
|
+
case MULTI_LINE_TEXT:
|
68
|
+
fieldValue = new MultiLineTextFieldValue(stringValue);
|
69
|
+
break;
|
70
|
+
case DROP_DOWN:
|
71
|
+
fieldValue = new DropDownFieldValue(stringValue);
|
72
|
+
break;
|
73
|
+
case LINK:
|
74
|
+
fieldValue = new LinkFieldValue(stringValue);
|
75
|
+
break;
|
76
|
+
default:
|
77
|
+
fieldValue = new SingleLineTextFieldValue(stringValue);
|
78
|
+
}
|
79
|
+
record.putField(fieldCode, fieldValue);
|
80
|
+
}
|
81
|
+
|
82
|
+
private void setTimestampValue(String fieldCode, Instant instant, ZoneId zoneId, FieldType type) {
|
83
|
+
FieldValue fieldValue = null;
|
84
|
+
ZonedDateTime datetime = instant.atZone(zoneId);
|
85
|
+
switch (type) {
|
86
|
+
case DATE:
|
87
|
+
fieldValue = new DateFieldValue(datetime.toLocalDate());
|
88
|
+
break;
|
89
|
+
case DATETIME:
|
90
|
+
fieldValue = new DateTimeFieldValue(datetime);
|
91
|
+
}
|
92
|
+
record.putField(fieldCode, fieldValue);
|
93
|
+
}
|
94
|
+
|
95
|
+
private void setCheckBoxValue(String fieldCode, Object value, String valueSeparator) {
|
96
|
+
String str = String.valueOf(value);
|
97
|
+
CheckBoxFieldValue checkBoxFieldValue = new CheckBoxFieldValue();
|
98
|
+
|
99
|
+
if (str != null && !str.equals("")) {
|
100
|
+
List<String> values = Arrays.asList(str.split(valueSeparator, 0));
|
101
|
+
checkBoxFieldValue = new CheckBoxFieldValue(values);
|
102
|
+
}
|
103
|
+
record.putField(fieldCode, checkBoxFieldValue);
|
104
|
+
}
|
105
|
+
|
106
|
+
private FieldType getType(Column column, FieldType defaultType) {
|
107
|
+
KintoneColumnOption option = columnOptions.get(column.getName());
|
108
|
+
if (option == null) {
|
109
|
+
return defaultType;
|
110
|
+
} else {
|
111
|
+
return FieldType.valueOf(option.getType());
|
112
|
+
}
|
113
|
+
}
|
114
|
+
|
115
|
+
private String getFieldCode(Column column) {
|
116
|
+
KintoneColumnOption option = columnOptions.get(column.getName());
|
117
|
+
if (option == null) {
|
118
|
+
return column.getName();
|
119
|
+
} else {
|
120
|
+
return option.getFieldCode();
|
121
|
+
}
|
122
|
+
}
|
123
|
+
|
124
|
+
private ZoneId getZoneId(Column column) {
|
125
|
+
KintoneColumnOption option = columnOptions.get(column.getName());
|
126
|
+
if (option == null) {
|
127
|
+
return ZoneId.of("UTC");
|
128
|
+
}
|
129
|
+
return ZoneId.of(option.getTimezone().orElse("UTC"));
|
130
|
+
}
|
131
|
+
|
132
|
+
private boolean isUpdateKey(Column column) {
|
133
|
+
if (this.updateKeyName == null) {
|
134
|
+
return false;
|
135
|
+
}
|
136
|
+
|
137
|
+
return this.updateKeyName.equals(column.getName());
|
138
|
+
}
|
139
|
+
|
140
|
+
private String getValueSeparator(Column column) {
|
141
|
+
KintoneColumnOption option = columnOptions.get(column.getName());
|
142
|
+
if (option == null) {
|
143
|
+
return ",";
|
144
|
+
}
|
145
|
+
return option.getValueSeparator();
|
146
|
+
}
|
147
|
+
|
148
|
+
@Override
|
149
|
+
public void booleanColumn(Column column) {
|
150
|
+
String fieldCode = getFieldCode(column);
|
151
|
+
FieldType type = getType(column, FieldType.NUMBER);
|
152
|
+
setValue(fieldCode, pageReader.getBoolean(column), type, isUpdateKey(column));
|
153
|
+
}
|
154
|
+
|
155
|
+
@Override
|
156
|
+
public void longColumn(Column column) {
|
157
|
+
String fieldCode = getFieldCode(column);
|
158
|
+
FieldType type = getType(column, FieldType.NUMBER);
|
159
|
+
if (pageReader.isNull(column)) {
|
160
|
+
setValue(fieldCode, null, type, isUpdateKey(column));
|
161
|
+
} else {
|
162
|
+
setValue(fieldCode, pageReader.getLong(column), type, isUpdateKey(column));
|
163
|
+
}
|
164
|
+
}
|
165
|
+
|
166
|
+
@Override
|
167
|
+
public void doubleColumn(Column column) {
|
168
|
+
String fieldCode = getFieldCode(column);
|
169
|
+
FieldType type = getType(column, FieldType.NUMBER);
|
170
|
+
setValue(fieldCode, pageReader.getDouble(column), type, isUpdateKey(column));
|
171
|
+
}
|
172
|
+
|
173
|
+
@Override
|
174
|
+
public void stringColumn(Column column) {
|
175
|
+
String fieldCode = getFieldCode(column);
|
176
|
+
FieldType type = getType(column, FieldType.MULTI_LINE_TEXT);
|
177
|
+
Object value = pageReader.getString(column);
|
178
|
+
if (type == FieldType.CHECK_BOX) {
|
179
|
+
String stringValue = Objects.toString(value, "");
|
180
|
+
setCheckBoxValue(fieldCode, value, getValueSeparator(column));
|
181
|
+
return;
|
182
|
+
}
|
183
|
+
setValue(fieldCode, value, type, isUpdateKey(column));
|
184
|
+
}
|
185
|
+
|
186
|
+
@Override
|
187
|
+
public void timestampColumn(Column column) {
|
188
|
+
Timestamp value = pageReader.getTimestamp(column);
|
189
|
+
if (value == null) {
|
190
|
+
return;
|
191
|
+
}
|
192
|
+
|
193
|
+
String fieldCode = getFieldCode(column);
|
194
|
+
FieldType type = getType(column, FieldType.DATETIME);
|
195
|
+
ZoneId zoneId = getZoneId(column);
|
196
|
+
if (type == FieldType.DATETIME) {
|
197
|
+
zoneId = ZoneId.of("UTC");
|
198
|
+
}
|
199
|
+
setTimestampValue(fieldCode, value.getInstant(), zoneId, type);
|
200
|
+
}
|
201
|
+
|
202
|
+
@Override
|
203
|
+
public void jsonColumn(Column column) {
|
204
|
+
String fieldCode = getFieldCode(column);
|
205
|
+
FieldType type = getType(column, FieldType.MULTI_LINE_TEXT);
|
206
|
+
setValue(fieldCode, pageReader.getJson(column), type, isUpdateKey(column));
|
207
|
+
}
|
233
208
|
}
|
@@ -2,30 +2,28 @@ package org.embulk.output.kintone;
|
|
2
2
|
|
3
3
|
import org.embulk.config.ConfigException;
|
4
4
|
|
5
|
-
public enum KintoneMode
|
6
|
-
|
7
|
-
|
5
|
+
public enum KintoneMode {
|
6
|
+
INSERT("insert"),
|
7
|
+
UPDATE("update"),
|
8
|
+
UPSERT("upsert");
|
8
9
|
|
9
|
-
|
10
|
+
private final String value;
|
10
11
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
}
|
12
|
+
KintoneMode(String value) {
|
13
|
+
this.value = value;
|
14
|
+
}
|
15
15
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
}
|
16
|
+
@Override
|
17
|
+
public String toString() {
|
18
|
+
return value;
|
19
|
+
}
|
21
20
|
|
22
|
-
|
23
|
-
{
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
}
|
28
|
-
}
|
29
|
-
throw new ConfigException(String.format("Unknown mode '%s'", value));
|
21
|
+
public static KintoneMode getKintoneModeByValue(String value) {
|
22
|
+
for (KintoneMode mode : values()) {
|
23
|
+
if (mode.toString().equals(value)) {
|
24
|
+
return mode;
|
25
|
+
}
|
30
26
|
}
|
27
|
+
throw new ConfigException(String.format("Unknown mode '%s'", value));
|
28
|
+
}
|
31
29
|
}
|