Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

transfer USER_SELECT / CREATOR / MODIFIER / GROUP_SELECT / ORGANIZATION_SELECT / STATUS_ASSIGNEE as JSON #40

Merged
merged 1 commit into from
Jul 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 6 additions & 9 deletions src/main/java/org/embulk/input/kintone/KintoneAccessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@
import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;
import com.kintone.client.model.FileBody;
import com.kintone.client.model.Group;
import com.kintone.client.model.Organization;
import com.kintone.client.model.User;
import com.kintone.client.model.record.CalcFieldValue;
import com.kintone.client.model.record.CheckBoxFieldValue;
import com.kintone.client.model.record.DateFieldValue;
Expand Down Expand Up @@ -71,11 +68,11 @@ private String getAsString(final String fieldCode)
case __REVISION__:
return toString(record.getRevision(), Objects::toString);
case CREATOR:
return toString(record.getCreatorFieldValue(), User::getCode);
return gson.toJson(record.getCreatorFieldValue());
case CREATED_TIME:
return toString(record.getCreatedTimeFieldValue(), (value) -> value.toInstant().toString());
case MODIFIER:
return toString(record.getModifierFieldValue(), User::getCode);
return gson.toJson(record.getModifierFieldValue());
case UPDATED_TIME:
return toString(record.getUpdatedTimeFieldValue(), (value) -> value.toInstant().toString());
case SINGLE_LINE_TEXT:
Expand All @@ -97,11 +94,11 @@ private String getAsString(final String fieldCode)
case DROP_DOWN:
return record.getDropDownFieldValue(fieldCode);
case USER_SELECT:
return toString(record.getUserSelectFieldValue(fieldCode), User::getCode);
return gson.toJson(record.getUserSelectFieldValue(fieldCode));
case ORGANIZATION_SELECT:
return toString(record.getOrganizationSelectFieldValue(fieldCode), Organization::getCode);
return gson.toJson(record.getOrganizationSelectFieldValue(fieldCode));
case GROUP_SELECT:
return toString(record.getGroupSelectFieldValue(fieldCode), Group::getCode);
return gson.toJson(record.getGroupSelectFieldValue(fieldCode));
case DATE:
return toString(record.getDateFieldValue(fieldCode), LocalDate::toString);
case TIME:
Expand All @@ -119,7 +116,7 @@ private String getAsString(final String fieldCode)
case STATUS:
return record.getStatusFieldValue();
case STATUS_ASSIGNEE:
return toString(record.getStatusAssigneeFieldValue(), User::getCode);
return gson.toJson(record.getStatusAssigneeFieldValue());
// 以下は値を取得できないもの
case REFERENCE_TABLE:
case LABEL:
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/org/embulk/input/kintone/KintoneInputPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -212,27 +212,27 @@ private Type buildType(final FieldType fieldType)
case DATETIME:
case UPDATED_TIME:
return Types.TIMESTAMP;
case CREATOR:
case GROUP_SELECT:
case MODIFIER:
case ORGANIZATION_SELECT:
case STATUS_ASSIGNEE:
case SUBTABLE:
case USER_SELECT:
return Types.JSON;
case CATEGORY:
case CHECK_BOX:
case CREATOR:
case DATE:
case DROP_DOWN:
case FILE:
case GROUP_SELECT:
case LINK:
case MODIFIER:
case MULTI_LINE_TEXT:
case MULTI_SELECT:
case ORGANIZATION_SELECT:
case RADIO_BUTTON:
case RICH_TEXT:
case SINGLE_LINE_TEXT:
case STATUS:
case STATUS_ASSIGNEE:
case TIME:
case USER_SELECT:
return Types.STRING;
default:
return null;
Expand Down
52 changes: 27 additions & 25 deletions src/test/java/org/embulk/input/kintone/TestKintoneAccessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,13 @@ public void testAccess()
Record testRecord = createTestRecord();
KintoneAccessor accessor = new KintoneAccessor(testRecord);
String multiValue = "sample1\nsample2";
String userSelect = "code1\ncode2";
String groupSelect = "code3\ncode4";
String orgSelect = "code5\ncode6";
String assigneeSelect = "code7\ncode8";
String userSelectValue = "[{\"name\":\"name1\",\"code\":\"code1\"},{\"name\":\"name2\",\"code\":\"code2\"}]";
String groupSelect = "[{\"name\":\"name3\",\"code\":\"code3\"},{\"name\":\"name4\",\"code\":\"code4\"}]";
String orgSelect = "[{\"name\":\"name5\",\"code\":\"code5\"},{\"name\":\"name5\",\"code\":\"code6\"}]";
String assigneeSelect = "[{\"name\":\"name7\",\"code\":\"code7\"},{\"name\":\"name8\",\"code\":\"code8\"}]";
String subTableValue = "[{\"id\":1,\"value\":{\"sample field1\":{\"type\":\"SINGLE_LINE_TEXT\",\"value\":\"sample_text1\"}}}]";
String creatorValue = "{\"name\":\"name9\",\"code\":\"code9\"}";
String modifierValue = "{\"name\":\"name10\",\"code\":\"code10\"}";
assertEquals(testRecord.getSingleLineTextFieldValue("文字列__1行"), accessor.get("文字列__1行"));
assertEquals("1", accessor.get("数値"));
assertEquals(testRecord.getMultiLineTextFieldValue("文字列__複数行"), accessor.get("文字列__複数行"));
Expand All @@ -146,17 +148,17 @@ public void testAccess()
assertEquals("2018-01-01", accessor.get("日付"));
assertEquals("12:34", accessor.get("時刻"));
assertEquals("2018-01-02T02:30:00Z", accessor.get("日時"));
assertEquals(userSelect, accessor.get("ユーザー選択"));
assertEquals(userSelectValue, accessor.get("ユーザー選択"));
assertEquals(groupSelect, accessor.get("グループ選択"));
assertEquals(orgSelect, accessor.get("組織選択"));
assertEquals(assigneeSelect, accessor.get("作業者"));
assertEquals(subTableValue, accessor.get("サブテーブル"));
assertEquals("sample_record_number", accessor.get("レコード番号"));
assertEquals("123", accessor.get("$id"));
assertEquals("456", accessor.get("$revision"));
assertEquals("code9", accessor.get("作成者"));
assertEquals(creatorValue, accessor.get("作成者"));
assertEquals("2012-01-11T11:30:00Z", accessor.get("作成日時"));
assertEquals("code10", accessor.get("更新者"));
assertEquals(modifierValue, accessor.get("更新者"));
assertEquals("2012-01-11T11:30:00Z", accessor.get("更新日時"));
assertEquals("1.23E-12", accessor.get("計算(Calc)"));
assertEquals("1234", accessor.get("数値(Calc)"));
Expand All @@ -176,9 +178,9 @@ public void testFields()
assertEquals("APPCODE-1", accessor.get("レコード番号"));
assertEquals("1", accessor.get("$id"));
assertEquals("5", accessor.get("$revision"));
assertEquals("sato", accessor.get("作成者"));
assertEquals("{\"name\":\"Noboru Sato\",\"code\":\"sato\"}", accessor.get("作成者"));
assertEquals("2021-01-11T11:11:11Z", accessor.get("作成日時"));
assertEquals("guest/[email protected]", accessor.get("更新者"));
assertEquals("{\"name\":\"Misaki Kato\",\"code\":\"guest/[email protected]\"}", accessor.get("更新者"));
assertEquals("2022-02-22T22:22:22Z", accessor.get("更新日時"));
assertEquals("テストです。", accessor.get("文字列(1行)"));
assertEquals("テスト\nです。", accessor.get("文字列(複数行)"));
Expand All @@ -189,9 +191,9 @@ public void testFields()
assertEquals("選択肢3", accessor.get("ラジオボタン"));
assertEquals("選択肢4\n選択肢5", accessor.get("複数選択"));
assertEquals("選択肢6", accessor.get("ドロップダウン"));
assertEquals("guest/[email protected]\nkato", accessor.get("ユーザー選択"));
assertEquals("kaihatsu\njinji", accessor.get("組織選択"));
assertEquals("project_manager\nteam_leader", accessor.get("グループ選択"));
assertEquals("[{\"name\":\"Noboru Sato\",\"code\":\"guest/[email protected]\"},{\"name\":\"Misaki Kato\",\"code\":\"kato\"}]", accessor.get("ユーザー選択"));
assertEquals("[{\"name\":\"開発部\",\"code\":\"kaihatsu\"},{\"name\":\"人事部\",\"code\":\"jinji\"}]", accessor.get("組織選択"));
assertEquals("[{\"name\":\"プロジェクトマネージャー\",\"code\":\"project_manager\"},{\"name\":\"チームリーダー\",\"code\":\"team_leader\"}]", accessor.get("グループ選択"));
assertEquals("2012-01-11", accessor.get("日付"));
assertEquals("11:30", accessor.get("時刻"));
assertEquals("2012-01-11T11:30:00Z", accessor.get("日時"));
Expand All @@ -200,7 +202,7 @@ public void testFields()
assertEquals("[{\"id\":48290,\"value\":{\"リッチエディター\":{\"type\":\"RICH_TEXT\",\"value\":\"\\u003ca href\\u003d\\\"https://www.cybozu.com\\\"\\u003eサイボウズ\\u003c/a\\u003e\"},\"グループ選択\":{\"type\":\"GROUP_SELECT\",\"value\":[{\"name\":\"プロジェクトマネージャー\",\"code\":\"project_manager\"},{\"name\":\"チームリーダー\",\"code\":\"team_leader\"}]},\"文字列(1行)\":{\"type\":\"SINGLE_LINE_TEXT\",\"value\":\"テストです。\"},\"ラジオボタン\":{\"type\":\"RADIO_BUTTON\",\"value\":\"選択肢3\"},\"ドロップダウン\":{\"type\":\"DROP_DOWN\",\"value\":\"選択肢6\"},\"組織選択\":{\"type\":\"ORGANIZATION_SELECT\",\"value\":[{\"name\":\"開発部\",\"code\":\"kaihatsu\"},{\"name\":\"人事部\",\"code\":\"jinji\"}]},\"ユーザー選択\":{\"type\":\"USER_SELECT\",\"value\":[{\"name\":\"Noboru Sato\",\"code\":\"guest/[email protected]\"},{\"name\":\"Misaki Kato\",\"code\":\"kato\"}]},\"日時\":{\"type\":\"DATETIME\",\"value\":\"2012-01-11T11:30:00Z\"},\"文字列(複数行)\":{\"type\":\"MULTI_LINE_TEXT\",\"value\":\"テスト\\nです。\"},\"時刻\":{\"type\":\"TIME\",\"value\":\"11:30\"},\"チェックボックス\":{\"type\":\"CHECK_BOX\",\"value\":[\"選択肢1\",\"選択肢2\"]},\"複数選択\":{\"type\":\"MULTI_SELECT\",\"value\":[\"選択肢4\",\"選択肢5\"]},\"数値\":{\"type\":\"NUMBER\",\"value\":\"123\"},\"添付ファイル\":{\"type\":\"FILE\",\"value\":[{\"contentType\":\"text/plain\",\"fileKey\":\"201202061155587E339F9067544F1A92C743460E3D12B3297\",\"name\":\"17to20_VerupLog (1).txt\",\"size\":\"23175\"},{\"contentType\":\"application/json\",\"fileKey\":\"201202061155583C763E30196F419E83E91D2E4A03746C273\",\"name\":\"17to20_VerupLog.txt\",\"size\":\"23176\"}]},\"リンク\":{\"type\":\"LINK\",\"value\":\"https://cybozu.co.jp/\"},\"計算\":{\"type\":\"CALC\",\"value\":\"456\"},\"日付\":{\"type\":\"DATE\",\"value\":\"2012-01-11\"}}},{\"id\":48291,\"value\":{\"リッチエディター\":{\"type\":\"RICH_TEXT\",\"value\":\"\\u003ca href\\u003d\\\"https://www.cybozu.com\\\"\\u003eサイボウズ\\u003c/a\\u003e\"},\"グループ選択\":{\"type\":\"GROUP_SELECT\",\"value\":[{\"name\":\"プロジェクトマネージャー\",\"code\":\"project_manager\"},{\"name\":\"チームリーダー\",\"code\":\"team_leader\"}]},\"文字列(1行)\":{\"type\":\"SINGLE_LINE_TEXT\",\"value\":\"テストです。\"},\"ラジオボタン\":{\"type\":\"RADIO_BUTTON\",\"value\":\"選択肢3\"},\"ドロップダウン\":{\"type\":\"DROP_DOWN\",\"value\":\"選択肢6\"},\"組織選択\":{\"type\":\"ORGANIZATION_SELECT\",\"value\":[{\"name\":\"開発部\",\"code\":\"kaihatsu\"},{\"name\":\"人事部\",\"code\":\"jinji\"}]},\"ユーザー選択\":{\"type\":\"USER_SELECT\",\"value\":[{\"name\":\"Noboru Sato\",\"code\":\"guest/[email protected]\"},{\"name\":\"Misaki Kato\",\"code\":\"kato\"}]},\"日時\":{\"type\":\"DATETIME\",\"value\":\"2012-01-11T11:30:00Z\"},\"文字列(複数行)\":{\"type\":\"MULTI_LINE_TEXT\",\"value\":\"テスト\\nです。\"},\"時刻\":{\"type\":\"TIME\",\"value\":\"11:30\"},\"チェックボックス\":{\"type\":\"CHECK_BOX\",\"value\":[\"選択肢1\",\"選択肢2\"]},\"複数選択\":{\"type\":\"MULTI_SELECT\",\"value\":[\"選択肢4\",\"選択肢5\"]},\"数値\":{\"type\":\"NUMBER\",\"value\":\"123\"},\"添付ファイル\":{\"type\":\"FILE\",\"value\":[{\"contentType\":\"text/plain\",\"fileKey\":\"201202061155587E339F9067544F1A92C743460E3D12B3297\",\"name\":\"17to20_VerupLog (1).txt\",\"size\":\"23175\"},{\"contentType\":\"application/json\",\"fileKey\":\"201202061155583C763E30196F419E83E91D2E4A03746C273\",\"name\":\"17to20_VerupLog.txt\",\"size\":\"23176\"}]},\"リンク\":{\"type\":\"LINK\",\"value\":\"https://cybozu.co.jp/\"},\"計算\":{\"type\":\"CALC\",\"value\":\"456\"},\"日付\":{\"type\":\"DATE\",\"value\":\"2012-01-11\"}}}]", accessor.get("テーブル"));
assertEquals("category1\ncategory2", accessor.get("カテゴリー"));
assertEquals("未処理", accessor.get("ステータス"));
assertEquals("sato\nkato", accessor.get("作業者"));
assertEquals("[{\"name\":\"Noboru Sato\",\"code\":\"sato\"},{\"name\":\"Misaki Kato\",\"code\":\"kato\"}]", accessor.get("作業者"));
}

private Record record()
Expand Down Expand Up @@ -266,10 +268,10 @@ public void testNullFields()
assertNull(accessor.get("$id"));
assertNull(accessor.get("$revision"));
assertNull(accessor.get("作成者"));
assertNull(accessor.get("作成者(null項目)"));
assertEquals("{}", accessor.get("作成者(null項目)"));
assertNull(accessor.get("作成日時"));
assertNull(accessor.get("更新者"));
assertNull(accessor.get("更新者(null項目)"));
assertEquals("{}", accessor.get("更新者(null項目)"));
assertNull(accessor.get("更新日時"));
assertNull(accessor.get("文字列(1行)"));
assertNull(accessor.get("文字列(複数行)"));
Expand All @@ -282,15 +284,15 @@ public void testNullFields()
assertEquals("", accessor.get("複数選択(空)"));
assertEquals("", accessor.get("複数選択(null要素)"));
assertNull(accessor.get("ドロップダウン"));
assertEquals("", accessor.get("ユーザー選択(空)"));
assertEquals("", accessor.get("ユーザー選択(null要素)"));
assertEquals("", accessor.get("ユーザー選択(null項目)"));
assertEquals("", accessor.get("組織選択(空)"));
assertEquals("", accessor.get("組織選択(null要素)"));
assertEquals("", accessor.get("組織選択(null項目)"));
assertEquals("", accessor.get("グループ選択(空)"));
assertEquals("", accessor.get("グループ選択(null要素)"));
assertEquals("", accessor.get("グループ選択(null項目)"));
assertEquals("[]", accessor.get("ユーザー選択(空)"));
assertEquals("[null,null]", accessor.get("ユーザー選択(null要素)"));
assertEquals("[{},{}]", accessor.get("ユーザー選択(null項目)"));
assertEquals("[]", accessor.get("組織選択(空)"));
assertEquals("[null,null]", accessor.get("組織選択(null要素)"));
assertEquals("[{},{}]", accessor.get("組織選択(null項目)"));
assertEquals("[]", accessor.get("グループ選択(空)"));
assertEquals("[null,null]", accessor.get("グループ選択(null要素)"));
assertEquals("[{},{}]", accessor.get("グループ選択(null項目)"));
assertNull(accessor.get("日付"));
assertNull(accessor.get("時刻"));
assertNull(accessor.get("日時"));
Expand All @@ -306,7 +308,7 @@ public void testNullFields()
assertEquals("", accessor.get("カテゴリー(null要素)"));
*/
assertNull(accessor.get("ステータス"));
assertEquals("", accessor.get("作業者(空)"));
assertEquals("[]", accessor.get("作業者(空)"));
/* ビルトインフィールドは 1 つしか追加できない
assertEquals("", accessor.get("作業者(null要素)"));
assertEquals("", accessor.get("作業者(null項目)"));
Expand Down
Loading