embulk-input-kintone 0.1.0 → 0.1.1

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: 50b882dc3ce74fcb86df7ba392da3046c4944e99
4
- data.tar.gz: a85a843021b74f4eda4dc0a9241193413bddcd9b
3
+ metadata.gz: 68954eaff6b8344ffcddf296dfaf47a73882a315
4
+ data.tar.gz: '0587da14d8658b81f0f94ed9a2f26475eb2c5595'
5
5
  SHA512:
6
- metadata.gz: d8f3927799c2d3507e5dc764d798db24813c95e8bb4f563ba93d75a84cc6ec96ac42fd81f2c4b7161ae87dd306a2658a95c95a25b069152aee88a25b6f7320b4
7
- data.tar.gz: 88c09ff176b14da18790495f39e5b5bdadc37d5abbb7f453871ecc54d8f196eed56e1fa6d4b33af7063e5352bcaf4b637aad5d456c67fa3904f912f0cd44fc8e
6
+ metadata.gz: 941e7ed35a81853b42e41da31d78dd0afb3ccf8a27f4f1f6b23e4308caca10f36d705802eaf9d3a21a902f94a4dde3a9548cc519d524b360bfb842a59d2c7337
7
+ data.tar.gz: 48a62cd9aeccf5d307a971a1da9f9e38a350513569be5a3a5218128b3418b6c4414f3a889450f027b9a3272bc90f8a337144571379d41e175c812e7ccf366ca7
data/README.md CHANGED
@@ -27,7 +27,7 @@ embulk 0.9 is only supported due to the dependency of kintone-java-sdk 0.4.0, wh
27
27
  - **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)
28
28
  - **basic_auth_password**: Kintone basic auth password (string, optional)
29
29
  - **guest_space_id**: Kintone app belongs to guest space, guest space id is required. (integer, optional)
30
- - **fields**
30
+ - **fields** (required)
31
31
  - **name** the field code of Kintone app record will be retrieved.
32
32
  - **type** Column values are converted to this embulk type. Available values options are: boolean, long, double, string, json, timestamp)
33
33
 
@@ -64,7 +64,7 @@ in:
64
64
  - {name: $id, type: long}
65
65
  - {name: $revision, type: long}
66
66
  - {name: Time, type: string}
67
- - {name: Created_datatime, type: long}
67
+ - {name: Created_datatime, type: string}
68
68
  - {name: foo, type: string}
69
69
  ```
70
70
 
@@ -73,3 +73,9 @@ in:
73
73
  ```
74
74
  $ ./gradlew gem # -t to watch change of files and rebuild continuously
75
75
  ```
76
+
77
+ ## Development
78
+ ```
79
+ $ ./gradew build
80
+ $ ./gradew test
81
+ ```
@@ -13,7 +13,7 @@ configurations {
13
13
  provided
14
14
  }
15
15
 
16
- version = "0.1.0"
16
+ version = "0.1.1"
17
17
 
18
18
  sourceCompatibility = 1.8
19
19
  targetCompatibility = 1.8
@@ -22,8 +22,10 @@ dependencies {
22
22
  compile "org.embulk:embulk-core:0.9.12"
23
23
  provided "org.embulk:embulk-core:0.9.12"
24
24
  compile group: 'com.cybozu.kintone', name: 'kintone-sdk', version: '0.4.0'
25
- // compile "YOUR_JAR_DEPENDENCY_GROUP:YOUR_JAR_DEPENDENCY_MODULE:YOUR_JAR_DEPENDENCY_VERSION"
25
+
26
26
  testCompile "junit:junit:4.+"
27
+ testCompile 'org.embulk:embulk-standards:0.9.12'
28
+ testCompile 'org.embulk:embulk-test:0.9.12'
27
29
  }
28
30
 
29
31
  task classpath(type: Copy, dependsOn: ["jar"]) {
@@ -83,7 +85,7 @@ Gem::Specification.new do |spec|
83
85
  spec.description = %[Loads records from Kintone.]
84
86
  spec.email = ["ugw.gi.world@gmail.com"]
85
87
  spec.licenses = ["MIT"]
86
- # TODO set this: spec.homepage = "https://github.com/ugw.gi.world/embulk-input-kintone"
88
+ spec.homepage = "https://github.com/trocco-io/embulk-input-kintone"
87
89
 
88
90
  spec.files = `git ls-files`.split("\n") + Dir["classpath/*.jar"]
89
91
  spec.test_files = spec.files.grep(%r"^(test|spec)/")
@@ -1,5 +1,6 @@
1
+ #Fri Oct 11 16:04:33 JST 2019
1
2
  distributionBase=GRADLE_USER_HOME
2
3
  distributionPath=wrapper/dists
3
4
  zipStoreBase=GRADLE_USER_HOME
4
5
  zipStorePath=wrapper/dists
5
- distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-bin.zip
6
+ distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
@@ -26,7 +26,7 @@ public class KintoneAccessor {
26
26
  case GROUP_SELECT:
27
27
  case STATUS_ASSIGNEE:
28
28
  ArrayList<Member> members = (ArrayList<Member>) this.record.get(name).getValue();
29
- return members.stream().map(m -> m.getCode())
29
+ return members.stream().map(Member::getCode)
30
30
  .reduce((accum, value) -> accum + this.delimiter + value)
31
31
  .orElse("");
32
32
  case SUBTABLE:
@@ -45,9 +45,11 @@ public class KintoneAccessor {
45
45
  .orElse("");
46
46
  case FILE:
47
47
  ArrayList<FileModel> cbFileList = (ArrayList<FileModel>) this.record.get(name).getValue();
48
- return cbFileList.stream().map(f -> f.getFileKey())
48
+ return cbFileList.stream().map(FileModel::getFileKey)
49
49
  .reduce((accum, value) -> accum + this.delimiter + value)
50
50
  .orElse("");
51
+ case NUMBER:
52
+ return String.valueOf(this.record.get(name).getValue());
51
53
  default:
52
54
  return (String) this.record.get(name).getValue();
53
55
  }
@@ -14,49 +14,49 @@ import java.util.ArrayList;
14
14
 
15
15
  public class KintoneClient {
16
16
  private final Logger logger = LoggerFactory.getLogger(KintoneClient.class);
17
- private final PluginTask pluginTask;
17
+ private final PluginTask task;
18
18
  private ArrayList<String> fields;
19
19
  private Auth kintoneAuth;
20
20
  private Record kintoneRecordManager;
21
21
  private Connection con;
22
22
 
23
- public KintoneClient(final PluginTask pluginTask) {
24
- this.pluginTask = pluginTask;
23
+ public KintoneClient(final PluginTask task) {
24
+ this.task = task;
25
25
  this.kintoneAuth = new Auth();
26
26
 
27
- this.fields = new ArrayList<String>();
28
- for (ColumnConfig c : pluginTask.getFields().getColumns()
27
+ this.fields = new ArrayList<>();
28
+ for (ColumnConfig c : task.getFields().getColumns()
29
29
  ) {
30
30
  fields.add(c.getName());
31
31
  }
32
32
  this.setAuth();
33
- if (pluginTask.getGuestSpaceId().isPresent()) {
34
- this.con = new Connection(pluginTask.getDomain(), this.kintoneAuth, pluginTask.getGuestSpaceId().or(-1));
33
+ if (task.getGuestSpaceId().isPresent()) {
34
+ this.con = new Connection(task.getDomain(), this.kintoneAuth, task.getGuestSpaceId().or(-1));
35
35
  } else {
36
- this.con = new Connection(pluginTask.getDomain(), this.kintoneAuth);
36
+ this.con = new Connection(task.getDomain(), this.kintoneAuth);
37
37
  }
38
38
  this.kintoneRecordManager = new Record(con);
39
39
  }
40
40
 
41
41
  private void setAuth() {
42
- if (pluginTask.getUsername().isPresent() && pluginTask.getPassword().isPresent()) {
43
- this.kintoneAuth.setPasswordAuth(pluginTask.getUsername().get(), pluginTask.getPassword().get());
44
- } else if (pluginTask.getToken().isPresent()) {
45
- this.kintoneAuth.setApiToken(pluginTask.getToken().get());
42
+ if (task.getUsername().isPresent() && task.getPassword().isPresent()) {
43
+ this.kintoneAuth.setPasswordAuth(task.getUsername().get(), task.getPassword().get());
44
+ } else if (task.getToken().isPresent()) {
45
+ this.kintoneAuth.setApiToken(task.getToken().get());
46
46
  } else {
47
47
  throw new ConfigException("Username and password or token must be provided");
48
48
  }
49
49
 
50
- if (pluginTask.getBasicAuthUsername().isPresent() && pluginTask.getBasicAuthPassword().isPresent()) {
51
- this.kintoneAuth.setBasicAuth(pluginTask.getBasicAuthUsername().get(),
52
- pluginTask.getBasicAuthPassword().get());
50
+ if (task.getBasicAuthUsername().isPresent() && task.getBasicAuthPassword().isPresent()) {
51
+ this.kintoneAuth.setBasicAuth(task.getBasicAuthUsername().get(),
52
+ task.getBasicAuthPassword().get());
53
53
  }
54
54
  }
55
55
 
56
56
  public GetRecordsResponse getResponse() {
57
57
  try {
58
58
  return kintoneRecordManager.getAllRecordsByQuery(
59
- this.pluginTask.getAppId(), this.pluginTask.getQuery().or(""), this.fields);
59
+ this.task.getAppId(), this.task.getQuery().or(""), this.fields);
60
60
  } catch (Exception e) {
61
61
  throw new RuntimeException(e);
62
62
  }
@@ -3,10 +3,7 @@ package org.embulk.input.kintone;
3
3
  import java.util.HashMap;
4
4
  import java.util.List;
5
5
 
6
- import org.embulk.config.ConfigDiff;
7
- import org.embulk.config.ConfigSource;
8
- import org.embulk.config.TaskReport;
9
- import org.embulk.config.TaskSource;
6
+ import org.embulk.config.*;
10
7
  import org.embulk.spi.Exec;
11
8
  import org.embulk.spi.PageBuilder;
12
9
  import org.embulk.spi.InputPlugin;
@@ -56,7 +53,6 @@ public class KintoneInputPlugin
56
53
  try {
57
54
  try (PageBuilder pageBuilder = new PageBuilder(Exec.getBufferAllocator(), schema, output)) {
58
55
  KintoneClient client = new KintoneClient(task);
59
- // TODO: interface should accept query?
60
56
  GetRecordsResponse response = client.getResponse();
61
57
  for (HashMap<String, FieldValue> record : response.getRecords()) {
62
58
  schema.visitColumns(new KintoneInputColumnVisitor(new KintoneAccessor(record), pageBuilder, task));
@@ -65,8 +61,8 @@ public class KintoneInputPlugin
65
61
  pageBuilder.finish();
66
62
  }
67
63
  } catch (Exception e) {
68
- System.out.println(e.getMessage());
69
- System.out.println(e.fillInStackTrace());
64
+ logger.error(e.getMessage());
65
+ throw e;
70
66
  }
71
67
  return Exec.newTaskReport();
72
68
  }
@@ -0,0 +1,94 @@
1
+ package org.embulk.input.kintone;
2
+
3
+
4
+ import com.cybozu.kintone.client.model.app.form.FieldType;
5
+ import com.cybozu.kintone.client.model.record.field.FieldValue;
6
+ import com.cybozu.kintone.client.model.member.Member;
7
+ import org.junit.Test;
8
+
9
+ import java.util.ArrayList;
10
+ import java.util.HashMap;
11
+
12
+ import static org.junit.Assert.*;
13
+
14
+
15
+ public class TestKintoneAccessor {
16
+ private static Member testman1 = new Member("code1", "name1");
17
+ private static Member testman2 = new Member("code2", "name2");
18
+ private static Member testgroup1 = new Member("code3", "name3");
19
+ private static Member testgroup2 = new Member("code4", "name4");
20
+ private static Member testorg1 = new Member("code5", "name5");
21
+ private static Member testorg2 = new Member("code6", "name6");
22
+ private Integer uniqueKey = 1;
23
+
24
+ public HashMap<String, FieldValue> createTestRecord() {
25
+ HashMap<String, FieldValue> testRecord = new HashMap<>();
26
+
27
+ testRecord = addField(testRecord, "文字列__1行", FieldType.SINGLE_LINE_TEXT, "test single text");
28
+ testRecord = addField(testRecord, "数値", FieldType.NUMBER, this.uniqueKey);
29
+ this.uniqueKey += 1;
30
+ testRecord = addField(testRecord, "文字列__複数行", FieldType.MULTI_LINE_TEXT, "test multi text");
31
+ testRecord = addField(testRecord, "リッチエディター", FieldType.RICH_TEXT, "<div>test rich text<br /></div>");
32
+
33
+ ArrayList<String> selectedItemList = new ArrayList<>();
34
+ selectedItemList.add("sample1");
35
+ selectedItemList.add("sample2");
36
+ testRecord = addField(testRecord, "チェックボックス", FieldType.CHECK_BOX, selectedItemList);
37
+ testRecord = addField(testRecord, "ラジオボタン", FieldType.RADIO_BUTTON, "sample2");
38
+ testRecord = addField(testRecord, "ドロップダウン", FieldType.DROP_DOWN, "sample3");
39
+ testRecord = addField(testRecord, "複数選択", FieldType.MULTI_SELECT, selectedItemList);
40
+ testRecord = addField(testRecord, "リンク", FieldType.LINK, "http://cybozu.co.jp/");
41
+ testRecord = addField(testRecord, "日付", FieldType.DATE, "2018-01-01");
42
+ testRecord = addField(testRecord, "時刻", FieldType.TIME, "12:34");
43
+ testRecord = addField(testRecord, "日時", FieldType.DATETIME, "2018-01-02T02:30:00Z");
44
+
45
+ ArrayList<Member> userList = new ArrayList<>();
46
+ userList.add(testman1);
47
+ userList.add(testman2);
48
+ addField(testRecord, "ユーザー選択", FieldType.USER_SELECT, userList);
49
+ ArrayList<Member> groupList = new ArrayList<>();
50
+ groupList.add(testgroup1);
51
+ groupList.add(testgroup2);
52
+ addField(testRecord, "グループ選択", FieldType.GROUP_SELECT, groupList);
53
+ ArrayList<Member> orgList = new ArrayList<>();
54
+ orgList.add(testorg1);
55
+ orgList.add(testorg2);
56
+ addField(testRecord, "組織選択", FieldType.ORGANIZATION_SELECT, orgList);
57
+ return testRecord;
58
+ }
59
+
60
+ private HashMap<String, FieldValue> addField(HashMap<String, FieldValue> record, String code, FieldType type,
61
+ Object value) {
62
+ FieldValue newField = new FieldValue();
63
+ newField.setType(type);
64
+ newField.setValue(value);
65
+ record.put(code, newField);
66
+ return record;
67
+ }
68
+
69
+ @Test
70
+ public void testAccess() {
71
+ HashMap<String, FieldValue> testRecord = createTestRecord();
72
+ KintoneAccessor accessor = new KintoneAccessor(testRecord);
73
+ String multiValue = "sample1\nsample2";
74
+ String userSelect = "code1\ncode2";
75
+ String groupSelect = "code3\ncode4";
76
+ String orgSelect = "code5\ncode6";
77
+
78
+ assertEquals(testRecord.get("文字列__1行").getValue(), accessor.get("文字列__1行"));
79
+ assertEquals("1", accessor.get("数値"));
80
+ assertEquals(testRecord.get("文字列__複数行").getValue(), accessor.get("文字列__複数行"));
81
+ assertEquals(testRecord.get("リッチエディター").getValue(), accessor.get("リッチエディター"));
82
+ assertEquals(multiValue, accessor.get("チェックボックス"));
83
+ assertEquals(testRecord.get("ラジオボタン").getValue(), accessor.get("ラジオボタン"));
84
+ assertEquals(testRecord.get("ドロップダウン").getValue(), accessor.get("ドロップダウン"));
85
+ assertEquals(multiValue, accessor.get("複数選択"));
86
+ assertEquals(testRecord.get("リンク").getValue(), accessor.get("リンク"));
87
+ assertEquals(testRecord.get("日付").getValue(), accessor.get("日付"));
88
+ assertEquals(testRecord.get("時刻").getValue(), accessor.get("時刻"));
89
+ assertEquals(testRecord.get("日時").getValue(), accessor.get("日時"));
90
+ assertEquals(userSelect, accessor.get("ユーザー選択"));
91
+ assertEquals(groupSelect, accessor.get("グループ選択"));
92
+ assertEquals(orgSelect, accessor.get("組織選択"));
93
+ }
94
+ }
@@ -0,0 +1,75 @@
1
+ package org.embulk.input.kintone;
2
+
3
+ import org.embulk.config.ConfigException;
4
+ import org.embulk.config.ConfigSource;
5
+ import org.embulk.spi.InputPlugin;
6
+
7
+ import org.embulk.test.TestingEmbulk;
8
+ import org.junit.Rule;
9
+ import org.junit.Test;
10
+ import org.junit.rules.ExpectedException;
11
+
12
+ import static org.junit.Assert.*;
13
+
14
+ public class TestKintoneClient {
15
+ private ConfigSource config;
16
+ private static final String BASIC_RESOURCE_PATH = "org/embulk/input/kintone/";
17
+
18
+ private static ConfigSource loadYamlResource(TestingEmbulk embulk, String fileName) {
19
+ return embulk.loadYamlResource(BASIC_RESOURCE_PATH + fileName);
20
+ }
21
+
22
+ @Rule
23
+ public TestingEmbulk embulk = TestingEmbulk.builder()
24
+ .registerPlugin(InputPlugin.class, "kintone", KintoneInputPlugin.class)
25
+ .build();
26
+
27
+ @Test
28
+ public void checkClientWithUsernameAndPassword() {
29
+ config = loadYamlResource(embulk, "base.yml");
30
+ PluginTask task = config.loadConfig(PluginTask.class);
31
+ KintoneClient client = new KintoneClient(task);
32
+ assertNotNull(client);
33
+ }
34
+
35
+ @Test
36
+ public void checkThrowErrorWithoutAuthInfo() {
37
+ config = loadYamlResource(embulk, "base.yml");
38
+ config.remove("username")
39
+ .remove("password");
40
+ PluginTask task = config.loadConfig(PluginTask.class);
41
+ ConfigException e = assertThrows(ConfigException.class, () -> new KintoneClient(task));
42
+ assertEquals("Username and password or token must be provided", e.getMessage());
43
+ }
44
+
45
+ @Test
46
+ public void checkClientErrorLackingPassword() {
47
+ config = loadYamlResource(embulk, "base.yml");
48
+ config.remove("password");
49
+ PluginTask task = config.loadConfig(PluginTask.class);
50
+ ConfigException e = assertThrows(ConfigException.class, () -> new KintoneClient(task));
51
+ assertEquals("Username and password or token must be provided", e.getMessage());
52
+ }
53
+
54
+ @Test
55
+ public void checkClientErrorLackingUsername() {
56
+ config = loadYamlResource(embulk, "base.yml");
57
+ config.remove("username");
58
+ PluginTask task = config.loadConfig(PluginTask.class);
59
+ ConfigException e = assertThrows(ConfigException.class, () -> {
60
+ new KintoneClient(task);
61
+ });
62
+ assertEquals("Username and password or token must be provided", e.getMessage());
63
+ }
64
+
65
+ @Test
66
+ public void checkClientWithToken() {
67
+ config = loadYamlResource(embulk, "base.yml");
68
+ config.remove("username")
69
+ .remove("password")
70
+ .set("token", "token");
71
+ PluginTask task = config.loadConfig(PluginTask.class);
72
+ KintoneClient client = new KintoneClient(task);
73
+ assertNotNull(client);
74
+ }
75
+ }
@@ -1,5 +1,40 @@
1
1
  package org.embulk.input.kintone;
2
2
 
3
- public class TestKintoneInputPlugin
4
- {
3
+ import org.embulk.config.ConfigSource;
4
+ import org.embulk.spi.InputPlugin;
5
+
6
+ import org.embulk.test.TestingEmbulk;
7
+ import org.junit.Rule;
8
+ import org.junit.Test;
9
+
10
+ import static org.junit.Assert.*;
11
+
12
+ public class TestKintoneInputPlugin {
13
+ private ConfigSource config;
14
+ private static final String BASIC_RESOURCE_PATH = "org/embulk/input/kintone/";
15
+
16
+ private static ConfigSource loadYamlResource(TestingEmbulk embulk, String fileName) {
17
+ return embulk.loadYamlResource(BASIC_RESOURCE_PATH + fileName);
18
+ }
19
+
20
+ @Rule
21
+ public TestingEmbulk embulk = TestingEmbulk.builder()
22
+ .registerPlugin(InputPlugin.class, "kintone", KintoneInputPlugin.class)
23
+ .build();
24
+
25
+ @Test
26
+ public void checkDefaultConfigValues() {
27
+ config = loadYamlResource(embulk, "base.yml");
28
+ PluginTask task = config.loadConfig(PluginTask.class);
29
+ assertEquals("dev.cybozu.com", task.getDomain());
30
+ assertEquals(1, task.getAppId());
31
+ assertEquals("username", task.getUsername().get());
32
+ assertEquals("password", task.getPassword().get());
33
+ assertFalse(task.getToken().isPresent());
34
+ assertFalse(task.getGuestSpaceId().isPresent());
35
+ assertFalse(task.getBasicAuthUsername().isPresent());
36
+ assertFalse(task.getBasicAuthPassword().isPresent());
37
+ assertFalse(task.getQuery().isPresent());
38
+ assertNotNull(task.getFields());
39
+ }
5
40
  }
@@ -0,0 +1,9 @@
1
+ type: kintone
2
+ domain: dev.cybozu.com
3
+ app_id: 1
4
+ username: username
5
+ password: password
6
+ fields:
7
+ - {name: foo, type: string}
8
+ - {name: bar, type: long}
9
+ - {name: baz, type: double}
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: embulk-input-kintone
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - giwa
@@ -49,7 +49,7 @@ files:
49
49
  - LICENSE.txt
50
50
  - README.md
51
51
  - build.gradle
52
- - classpath/embulk-input-kintone-0.1.0.jar
52
+ - classpath/embulk-input-kintone-0.1.1.jar
53
53
  - classpath/gson-2.8.2.jar
54
54
  - classpath/kintone-sdk-0.4.0.jar
55
55
  - config/checkstyle/checkstyle.xml
@@ -64,8 +64,11 @@ files:
64
64
  - src/main/java/org/embulk/input/kintone/KintoneInputColumnVisitor.java
65
65
  - src/main/java/org/embulk/input/kintone/KintoneInputPlugin.java
66
66
  - src/main/java/org/embulk/input/kintone/PluginTask.java
67
+ - src/test/java/org/embulk/input/kintone/TestKintoneAccessor.java
68
+ - src/test/java/org/embulk/input/kintone/TestKintoneClient.java
67
69
  - src/test/java/org/embulk/input/kintone/TestKintoneInputPlugin.java
68
- homepage:
70
+ - src/test/resources/org/embulk/input/kintone/base.yml
71
+ homepage: https://github.com/trocco-io/embulk-input-kintone
69
72
  licenses:
70
73
  - MIT
71
74
  metadata: {}