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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7107e79ed02bf30d233e34a3606bc84851e65b04
4
- data.tar.gz: 4c8c90cd5f2e3c72a3b1cb10f4b0f3373c626a06
3
+ metadata.gz: 4db580dd68dc408de335d4c115a01394b794e0b1
4
+ data.tar.gz: 420c0efc922b96404adce1f13e68611e12c7d6fa
5
5
  SHA512:
6
- metadata.gz: ec15b3471eb9cca3b7804a62f3beed3242e6ef8c4b547d5995f826fb9840f0505e5705ae26856a27dea5653caf0500d9bde3e58de39e0f385ec51a428d024379
7
- data.tar.gz: ab6ea4f392578a902bd778136e5b2b9972f93b0836aa515db48110001e6b984c867a11c7fb2cb08192afb3d8eda334b8e72ff007b7704984f98ea84cc4d91e08
6
+ metadata.gz: 03b503cff07e5b80f4fd0c1d57f81e74df997d5a07d710081e6058fcb3811492f1ba9e1e9b9ba1a3396727591445a6a1bc4f3684283c4d7bfaca099ad709f4a8
7
+ data.tar.gz: 6b0e6f9d6d0753b559fdffa57b53a24884fb68d1b6e8daa0e6cd5c1a0e62f3124a2e2e1008a873f2768216bd1b99f2e5f0af9f60bc0a38c168fe70ffbaca01ec
@@ -3,14 +3,18 @@ name: main
3
3
  on:
4
4
  push:
5
5
  branches:
6
- - 'master'
6
+ - "master"
7
7
  tags:
8
- - '*'
8
+ - "*"
9
9
  pull_request:
10
10
  branches:
11
- - 'master'
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
+ }
@@ -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
- import java.util.Optional;
8
-
9
- public interface KintoneColumnOption
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
- @Config("field_code")
16
- String getFieldCode();
12
+ @Config("field_code")
13
+ String getFieldCode();
17
14
 
18
- @Config("timezone")
19
- @ConfigDefault("\"UTC\"")
20
- Optional<String> getTimezone();
15
+ @Config("timezone")
16
+ @ConfigDefault("\"UTC\"")
17
+ Optional<String> getTimezone();
21
18
 
22
- @Config("val_sep")
23
- @ConfigDefault("\",\"")
24
- String getValueSeparator();
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
- implements ColumnVisitor
29
- {
30
- private final PageReader pageReader;
31
- private Record record;
32
- private UpdateKey updateKey;
33
- private final Map<String, KintoneColumnOption> columnOptions;
34
- private String updateKeyName;
35
-
36
- public KintoneColumnVisitor(PageReader pageReader,
37
- Map<String, KintoneColumnOption> columnOptions)
38
- {
39
- this.pageReader = pageReader;
40
- this.columnOptions = columnOptions;
41
- }
42
-
43
- public KintoneColumnVisitor(PageReader pageReader,
44
- Map<String, KintoneColumnOption> columnOptions,
45
- String updateKeyName)
46
- {
47
- this.pageReader = pageReader;
48
- this.columnOptions = columnOptions;
49
- this.updateKeyName = updateKeyName;
50
- }
51
-
52
- public void setRecord(Record record)
53
- {
54
- this.record = record;
55
- }
56
-
57
- public void setUpdateKey(UpdateKey updateKey)
58
- {
59
- this.updateKey = updateKey;
60
- }
61
-
62
- private void setValue(String fieldCode, Object value, FieldType type, boolean isUpdateKey)
63
- {
64
- if (isUpdateKey && updateKey != null) {
65
- updateKey
66
- .setField(fieldCode)
67
- .setValue(Objects.toString(value, ""));
68
- }
69
- String stringValue = Objects.toString(value, "");
70
- FieldValue fieldValue;
71
- switch (type) {
72
- case NUMBER:
73
- BigDecimal setValue = stringValue.equals("") ? null : new BigDecimal(stringValue);
74
- fieldValue = new NumberFieldValue(setValue);
75
- break;
76
- case MULTI_LINE_TEXT:
77
- fieldValue = new MultiLineTextFieldValue(stringValue);
78
- break;
79
- case DROP_DOWN:
80
- fieldValue = new DropDownFieldValue(stringValue);
81
- break;
82
- case LINK:
83
- fieldValue = new LinkFieldValue(stringValue);
84
- break;
85
- default:
86
- fieldValue = new SingleLineTextFieldValue(stringValue);
87
- }
88
- record.putField(fieldCode, fieldValue);
89
- }
90
-
91
- private void setTimestampValue(String fieldCode, Instant instant, ZoneId zoneId, FieldType type)
92
- {
93
- FieldValue fieldValue = null;
94
- ZonedDateTime datetime = instant.atZone(zoneId);
95
- switch (type) {
96
- case DATE:
97
- fieldValue = new DateFieldValue(datetime.toLocalDate());
98
- break;
99
- case DATETIME:
100
- fieldValue = new DateTimeFieldValue(datetime);
101
- }
102
- record.putField(fieldCode, fieldValue);
103
- }
104
-
105
- private void setCheckBoxValue(String fieldCode, Object value, String valueSeparator)
106
- {
107
- String str = String.valueOf(value);
108
- record.putField(
109
- fieldCode,
110
- new CheckBoxFieldValue(str.split(valueSeparator, 0))
111
- );
112
- }
113
-
114
- private FieldType getType(Column column, FieldType defaultType)
115
- {
116
- KintoneColumnOption option = columnOptions.get(column.getName());
117
- if (option == null) {
118
- return defaultType;
119
- }
120
- else {
121
- return FieldType.valueOf(option.getType());
122
- }
123
- }
124
-
125
- private String getFieldCode(Column column)
126
- {
127
- KintoneColumnOption option = columnOptions.get(column.getName());
128
- if (option == null) {
129
- return column.getName();
130
- }
131
- else {
132
- return option.getFieldCode();
133
- }
134
- }
135
-
136
- private ZoneId getZoneId(Column column)
137
- {
138
- KintoneColumnOption option = columnOptions.get(column.getName());
139
- if (option == null) {
140
- return ZoneId.of("UTC");
141
- }
142
- return ZoneId.of(option.getTimezone().orElse("UTC"));
143
- }
144
-
145
- private boolean isUpdateKey(Column column)
146
- {
147
- if (this.updateKeyName == null) {
148
- return false;
149
- }
150
-
151
- return this.updateKeyName.equals(column.getName());
152
- }
153
-
154
- private String getValueSeparator(Column column)
155
- {
156
- KintoneColumnOption option = columnOptions.get(column.getName());
157
- if (option == null) {
158
- return ",";
159
- }
160
- return option.getValueSeparator();
161
- }
162
-
163
- @Override
164
- public void booleanColumn(Column column)
165
- {
166
- String fieldCode = getFieldCode(column);
167
- FieldType type = getType(column, FieldType.NUMBER);
168
- setValue(fieldCode, pageReader.getBoolean(column), type, isUpdateKey(column));
169
- }
170
-
171
- @Override
172
- public void longColumn(Column column)
173
- {
174
- String fieldCode = getFieldCode(column);
175
- FieldType type = getType(column, FieldType.NUMBER);
176
- if (pageReader.isNull(column)) {
177
- setValue(fieldCode, null, type, isUpdateKey(column));
178
- } else {
179
- setValue(fieldCode, pageReader.getLong(column), type, isUpdateKey(column));
180
- }
181
- }
182
-
183
- @Override
184
- public void doubleColumn(Column column)
185
- {
186
- String fieldCode = getFieldCode(column);
187
- FieldType type = getType(column, FieldType.NUMBER);
188
- setValue(fieldCode, pageReader.getDouble(column), type, isUpdateKey(column));
189
- }
190
-
191
- @Override
192
- public void stringColumn(Column column)
193
- {
194
- String fieldCode = getFieldCode(column);
195
- FieldType type = getType(column, FieldType.MULTI_LINE_TEXT);
196
- Object value = pageReader.getString(column);
197
- if (type == FieldType.CHECK_BOX) {
198
- String stringValue = Objects.toString(value, "");
199
- if (stringValue == "") {
200
- return;
201
- } else {
202
- setCheckBoxValue(fieldCode, value, getValueSeparator(column));
203
- }
204
- return;
205
- }
206
- setValue(fieldCode, value, type, isUpdateKey(column));
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
- INSERT("insert"), UPDATE("update"), UPSERT("upsert");
5
+ public enum KintoneMode {
6
+ INSERT("insert"),
7
+ UPDATE("update"),
8
+ UPSERT("upsert");
8
9
 
9
- private final String value;
10
+ private final String value;
10
11
 
11
- KintoneMode(String value)
12
- {
13
- this.value = value;
14
- }
12
+ KintoneMode(String value) {
13
+ this.value = value;
14
+ }
15
15
 
16
- @Override
17
- public String toString()
18
- {
19
- return value;
20
- }
16
+ @Override
17
+ public String toString() {
18
+ return value;
19
+ }
21
20
 
22
- public static KintoneMode getKintoneModeByValue(String value)
23
- {
24
- for (KintoneMode mode : values()) {
25
- if (mode.toString().equals(value)) {
26
- return mode;
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
  }