embulk-input-zendesk 0.3.1 → 0.3.2

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: ad43cfba07a05a5677083290abad4876dfaa652a
4
- data.tar.gz: 90dbefa73c45d26e7a499e8c5b1f6618af4512f5
3
+ metadata.gz: d972c5116a66a8dab7e295a806f977bc1cbcf1f5
4
+ data.tar.gz: f51b015c3bfc0e62093b2bb83b78781a5fd22afc
5
5
  SHA512:
6
- metadata.gz: 1bcbdc100b762d7bfa73cddc605d34b64040dcb218e37f31e03b0342dbf4594cbfe5f970d861997dbb85a6b734911fa291db526bbc50a6a933f424ae4924a6ac
7
- data.tar.gz: ceef0158dc916745848727ccc3dd58bd8f63d38647475b3f4a0fee75aa95a690b690ba030d99a08fecdd3d14a0a6fa5fa0e2cf2a34ef109d45aba597dd48cdf5
6
+ metadata.gz: cfee244009630fcff30c4a3ced32729b451e9a88b3f889efc281fbdcf6f671e2f1aa80e094fe1af3cd40b8683f1cc1e0f210b847bc662e43d4737e7619d33af2
7
+ data.tar.gz: d23006d4502f46397ffd406813e55a08532cdf6f6cb6d86ab564240edea303f1b81082c6cd33c11d5870168acf8b5e882ec7168e1c8bdb95f3d58b4e7e535dc9
data/CHANGELOG.md CHANGED
@@ -1,3 +1,6 @@
1
+ ## 0.3.2 - 2019-04-10
2
+ * [fixed] Fix generate config diff based on incremental config #54 [#54](https://github.com/treasure-data/embulk-input-zendesk/pull/54)
3
+
1
4
  ## 0.3.1 - 2019-04-09
2
5
  * [fixed] Fix checking 404 by status code when fetching related objects #52 [#52](https://github.com/treasure-data/embulk-input-zendesk/pull/52)
3
6
 
data/build.gradle CHANGED
@@ -15,7 +15,7 @@ configurations {
15
15
  provided
16
16
  }
17
17
 
18
- version = "0.3.1"
18
+ version = "0.3.2"
19
19
 
20
20
  sourceCompatibility = 1.8
21
21
  targetCompatibility = 1.8
@@ -213,17 +213,14 @@ public class ZendeskInputPlugin implements InputPlugin
213
213
  {
214
214
  final ConfigDiff configDiff = Exec.newConfigDiff();
215
215
 
216
- if (!taskReports.isEmpty()) {
217
- if (ZendeskUtils.isSupportAPIIncremental(task.getTarget())) {
218
- final TaskReport taskReport = taskReports.get(0);
219
- if (taskReport.has(ZendeskConstants.Field.START_TIME)) {
220
- final OffsetDateTime offsetDateTime = OffsetDateTime.ofInstant(Instant.ofEpochSecond(
221
- taskReport.get(JsonNode.class, ZendeskConstants.Field.START_TIME).asLong()),
222
- ZoneOffset.UTC);
223
-
224
- configDiff.set(ZendeskConstants.Field.START_TIME,
216
+ if (!taskReports.isEmpty() && task.getIncremental()) {
217
+ final TaskReport taskReport = taskReports.get(0);
218
+ if (taskReport.has(ZendeskConstants.Field.START_TIME)) {
219
+ final OffsetDateTime offsetDateTime = OffsetDateTime.ofInstant(Instant.ofEpochSecond(
220
+ taskReport.get(JsonNode.class, ZendeskConstants.Field.START_TIME).asLong()), ZoneOffset.UTC);
221
+
222
+ configDiff.set(ZendeskConstants.Field.START_TIME,
225
223
  offsetDateTime.format(DateTimeFormatter.ofPattern(ZendeskConstants.Misc.RUBY_TIMESTAMP_FORMAT_INPUT)));
226
- }
227
224
  }
228
225
  }
229
226
  return configDiff;
@@ -296,16 +293,19 @@ public class ZendeskInputPlugin implements InputPlugin
296
293
  }
297
294
  }
298
295
  logger.info("Fetched '{}' records from start_time '{}'", recordCount, startTime);
299
- if (result.has(ZendeskConstants.Field.END_TIME) && !result.get(ZendeskConstants.Field.END_TIME).isNull()
300
- && result.has(task.getTarget().getJsonName())) {
301
- // NOTE: start_time compared as "=>", not ">".
302
- // If we will use end_time for next start_time, we got the same record that is last fetched
303
- // end_time + 1 is workaround for that
304
- taskReport.set("start_time", result.get(ZendeskConstants.Field.END_TIME).asLong() + 1);
305
- }
306
- else {
307
- // Sometimes no record and no end_time fetched on the job, but we should generate start_time on config_diff.
308
- taskReport.set("start_time", Instant.now().getEpochSecond());
296
+
297
+ if (task.getIncremental()) {
298
+ if (result.has(ZendeskConstants.Field.END_TIME) && !result.get(ZendeskConstants.Field.END_TIME).isNull()
299
+ && result.has(task.getTarget().getJsonName())) {
300
+ // NOTE: start_time compared as "=>", not ">".
301
+ // If we will use end_time for next start_time, we got the same record that is last fetched
302
+ // end_time + 1 is workaround for that
303
+ taskReport.set(ZendeskConstants.Field.START_TIME, result.get(ZendeskConstants.Field.END_TIME).asLong() + 1);
304
+ }
305
+ else {
306
+ // Sometimes no record and no end_time fetched on the job, but we should generate start_time on config_diff.
307
+ taskReport.set(ZendeskConstants.Field.START_TIME, Instant.now().getEpochSecond());
308
+ }
309
309
  }
310
310
 
311
311
  if (numberOfRecords < ZendeskConstants.Misc.MAXIMUM_RECORDS_INCREMENTAL) {
@@ -8,6 +8,7 @@ import org.embulk.config.ConfigSource;
8
8
  import org.embulk.config.TaskReport;
9
9
  import org.embulk.config.TaskSource;
10
10
  import org.embulk.input.zendesk.services.ZendeskSupportAPIService;
11
+ import org.embulk.input.zendesk.utils.ZendeskConstants;
11
12
  import org.embulk.input.zendesk.utils.ZendeskPluginTestRuntime;
12
13
  import org.embulk.input.zendesk.utils.ZendeskTestHelper;
13
14
 
@@ -117,7 +118,7 @@ public class TestZendeskInputPlugin
117
118
  when(zendeskSupportAPIService.getData(anyString(), anyInt(), anyBoolean(), anyLong())).thenReturn(dataJson);
118
119
 
119
120
  ConfigDiff configDiff = zendeskInputPlugin.transaction(src, new Control());
120
- String nextStartTime = configDiff.get(String.class, "start_time");
121
+ String nextStartTime = configDiff.get(String.class, ZendeskConstants.Field.START_TIME);
121
122
  verify(pageBuilder, times(4)).addRecord();
122
123
  verify(pageBuilder, times(1)).finish();
123
124
  assertEquals("2019-02-20 07:17:34 +0000", nextStartTime);
@@ -134,7 +135,7 @@ public class TestZendeskInputPlugin
134
135
  .thenReturn(dataJsonNext);
135
136
 
136
137
  ConfigDiff configDiff = zendeskInputPlugin.transaction(src, new Control());
137
- String nextStartTime = configDiff.get(String.class, "start_time");
138
+ String nextStartTime = configDiff.get(String.class, ZendeskConstants.Field.START_TIME);
138
139
  verify(pageBuilder, times(1)).addRecord();
139
140
  verify(pageBuilder, times(1)).finish();
140
141
  assertEquals("2019-02-20 07:17:34 +0000", nextStartTime);
@@ -150,7 +151,7 @@ public class TestZendeskInputPlugin
150
151
  when(zendeskSupportAPIService.getData(anyString(), anyInt(), anyBoolean(), anyLong())).thenReturn(dataJsonNext);
151
152
 
152
153
  ConfigDiff configDiff = zendeskInputPlugin.transaction(src, new Control());
153
- String nextStartTime = configDiff.get(String.class, "start_time");
154
+ String nextStartTime = configDiff.get(String.class, ZendeskConstants.Field.START_TIME);
154
155
  verify(pageBuilder, times(5)).addRecord();
155
156
  verify(pageBuilder, times(1)).finish();
156
157
  assertEquals("2019-02-20 07:17:34 +0000", nextStartTime);
@@ -166,7 +167,7 @@ public class TestZendeskInputPlugin
166
167
  when(zendeskSupportAPIService.getData(anyString(), anyInt(), anyBoolean(), anyLong())).thenReturn(dataJson);
167
168
 
168
169
  ConfigDiff configDiff = zendeskInputPlugin.transaction(src, new Control());
169
- String nextStartTime = configDiff.get(String.class, "start_time");
170
+ String nextStartTime = configDiff.get(String.class, ZendeskConstants.Field.START_TIME);
170
171
  verify(pageBuilder, times(3)).addRecord();
171
172
  verify(pageBuilder, times(1)).finish();
172
173
  assertEquals("2019-02-20 07:17:34 +0000", nextStartTime);
@@ -187,7 +188,7 @@ public class TestZendeskInputPlugin
187
188
  ConfigDiff configDiff = zendeskInputPlugin.transaction(src, new Control());
188
189
 
189
190
  verify(pageBuilder, times(1)).finish();
190
- String nextStartTime = configDiff.get(String.class, "start_time");
191
+ String nextStartTime = configDiff.get(String.class, ZendeskConstants.Field.START_TIME);
191
192
  assertEquals("2019-02-20 07:17:34 +0000", nextStartTime);
192
193
  }
193
194
 
@@ -204,6 +205,42 @@ public class TestZendeskInputPlugin
204
205
  Assert.assertTrue(configDiff.isEmpty());
205
206
  }
206
207
 
208
+ @Test
209
+ public void testRunNotGenerateStartTimeWhenRunningInNonIncrementalModeAndTargetSupportIncremental()
210
+ {
211
+ final ConfigSource src = ZendeskTestHelper.getConfigSource("incremental.yml");
212
+ src.set("incremental", false);
213
+ loadData("data/tickets.json");
214
+
215
+ ConfigDiff configDiff = zendeskInputPlugin.transaction(src, new Control());
216
+
217
+ Assert.assertTrue(configDiff.isEmpty());
218
+ }
219
+
220
+ @Test
221
+ public void testRunNotGenerateStartTimeWhenRunningInIncrementalModeAndTargetDoesNotSupportIncremental()
222
+ {
223
+ final ConfigSource src = ZendeskTestHelper.getConfigSource("non-incremental.yml");
224
+ src.set("incremental", true);
225
+ loadData("data/ticket_fields.json");
226
+
227
+ ConfigDiff configDiff = zendeskInputPlugin.transaction(src, new Control());
228
+
229
+ Assert.assertTrue(configDiff.isEmpty());
230
+ }
231
+
232
+ @Test
233
+ public void testRunIncrementalGenerateStartTimeWhenRunningInIncrementalModeAndTargetSupportIncremental()
234
+ {
235
+ String expectedStartTime = "2019-02-20 07:17:34 +0000";
236
+ final ConfigSource src = ZendeskTestHelper.getConfigSource("incremental.yml");
237
+ loadData("data/tickets.json");
238
+
239
+ ConfigDiff configDiff = zendeskInputPlugin.transaction(src, new Control());
240
+ Assert.assertFalse(configDiff.isEmpty());
241
+ Assert.assertEquals(expectedStartTime, configDiff.get(String.class, ZendeskConstants.Field.START_TIME));
242
+ }
243
+
207
244
  private class Control implements InputPlugin.Control
208
245
  {
209
246
  @Override
@@ -114,7 +114,7 @@ public class TestZendeskValidatorUtils
114
114
  configSource.set("target", "ticket_fields");
115
115
  configSource.set("incremental", true);
116
116
  configSource.set("dedup", false);
117
- configSource.set("start_time", "");
117
+ configSource.set(ZendeskConstants.Field.START_TIME, "");
118
118
 
119
119
  final ZendeskInputPlugin.PluginTask task = configSource.loadConfig(ZendeskInputPlugin.PluginTask.class);
120
120
  ZendeskValidatorUtils.validateInputTask(task, zendeskSupportAPIService);
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: embulk-input-zendesk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - hieu.duong
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-04-09 00:00:00.000000000 Z
11
+ date: 2019-04-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement
@@ -95,8 +95,8 @@ files:
95
95
  - src/test/resources/data/tickets_continue.json
96
96
  - src/test/resources/data/util.json
97
97
  - src/test/resources/data/util_page.json
98
+ - classpath/embulk-input-zendesk-0.3.2.jar
98
99
  - classpath/commons-logging-1.2.jar
99
- - classpath/embulk-input-zendesk-0.3.1.jar
100
100
  - classpath/httpcore-4.4.10.jar
101
101
  - classpath/httpclient-4.5.6.jar
102
102
  - classpath/commons-codec-1.10.jar