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

Remove deprecated functions #76

Merged
merged 2 commits into from
Mar 29, 2022
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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## 0.4.1 - 2022-29-03
* [enhancement] Remove deprecated functions [#76](https://github.com/treasure-data/embulk-input-zendesk/pull/76)

## 0.4.0 - 2022-03-03
* [enhancement] Release to Maven Central [#74](https://github.com/treasure-data/embulk-input-zendesk/pull/74)

## 0.3.11 - 2022-14-02
* [enhancement] catch up Embulk 0.10 [#73](https://github.com/treasure-data/embulk-input-zendesk/pull/73)

Expand Down
7 changes: 5 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ repositories {
def embulkVersion = '0.10.31'

group = "com.treasuredata.embulk.plugins"
version = "0.4.0-SNAPSHOT"
version = "0.4.1-SNAPSHOT"
description = "Loads records From Zendesk"

sourceCompatibility = 1.8
Expand Down Expand Up @@ -191,7 +191,10 @@ checkstyleMain {
configFile = file("${project.rootDir}/config/checkstyle/default.xml")
ignoreFailures = false
}

tasks.withType(JavaCompile) {
options.compilerArgs << "-Xlint:deprecation" << "-Xlint:unchecked"
options.encoding = "UTF-8"
}
checkstyleTest {
configFile = file("${project.rootDir}/config/checkstyle/default.xml")
ignoreFailures = false
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/org/embulk/input/zendesk/RecordImporter.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
import org.embulk.spi.ColumnVisitor;
import org.embulk.spi.PageBuilder;
import org.embulk.spi.Schema;
import org.embulk.spi.time.Timestamp;
import org.embulk.util.json.JsonParser;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.time.Instant;
import java.util.function.Function;

public class RecordImporter
Expand Down Expand Up @@ -58,7 +58,7 @@ public void timestampColumn(final Column column)
{
final JsonNode data = record.get(column.getName());
setColumn(column, data, (value) -> {
final Timestamp timestamp = getTimestampValue(value.asText());
final Instant timestamp = getTimestampValue(value.asText());
if (timestamp == null) {
pageBuilder.setNull(column);
}
Expand Down Expand Up @@ -119,12 +119,12 @@ private void setColumn(final Column column, final JsonNode data, final Function<
* For getting the timestamp value of the node
* Sometime if the parser could not parse the value then return null
* */
private Timestamp getTimestampValue(final String value)
private Instant getTimestampValue(final String value)
{
Timestamp result = null;
Instant result = null;
try {
final long timeStamp = ZendeskDateUtils.isoToEpochSecond(value);
result = Timestamp.ofEpochSecond(timeStamp);
result = Instant.ofEpochSecond(timeStamp);
}
catch (final Exception e) {
logger.warn("Error when parse time stamp data " + value);
Expand Down
10 changes: 4 additions & 6 deletions src/main/java/org/embulk/input/zendesk/ZendeskInputPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.ImmutableList;

import org.embulk.config.ConfigDiff;
import org.embulk.config.ConfigException;
import org.embulk.config.ConfigSource;
Expand Down Expand Up @@ -229,7 +227,7 @@ public TaskReport run(final TaskSource taskSource, final Schema schema, final in
if (task.getIncremental()) {
return buildTaskReportKeepOldStartAndEndTime(task);
}
return Exec.newTaskReport();
return CONFIG_MAPPER_FACTORY.newTaskReport();
}

try (final PageBuilder pageBuilder = getPageBuilder(schema, output)) {
Expand All @@ -248,7 +246,7 @@ public ConfigDiff guess(final ConfigSource config)
if (!isValidTimeRange(task)) {
throw new ConfigException("Invalid End time. End time is greater than current time");
}
return Exec.newConfigDiff().set("columns", buildColumns(task));
return CONFIG_MAPPER_FACTORY.newConfigDiff().set("columns", buildColumns(task));
}

@VisibleForTesting
Expand All @@ -259,7 +257,7 @@ protected PageBuilder getPageBuilder(final Schema schema, final PageOutput outpu

private ConfigDiff buildConfigDiff(final PluginTask task, final List<TaskReport> taskReports)
{
final ConfigDiff configDiff = Exec.newConfigDiff();
final ConfigDiff configDiff = CONFIG_MAPPER_FACTORY.newConfigDiff();

if (!taskReports.isEmpty() && task.getIncremental()) {
final TaskReport taskReport = taskReports.get(0);
Expand Down Expand Up @@ -585,7 +583,7 @@ private boolean isValidTimeRange(PluginTask task)

private TaskReport buildTaskReportKeepOldStartAndEndTime(PluginTask task)
{
final TaskReport taskReport = Exec.newTaskReport();
final TaskReport taskReport = CONFIG_MAPPER_FACTORY.newTaskReport();

if (task.getStartTime().isPresent()) {
taskReport.set(ZendeskConstants.Field.START_TIME, ZendeskDateUtils.isoToEpochSecond(task.getStartTime().get()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.embulk.input.zendesk.utils.ZendeskConstants;
import org.embulk.input.zendesk.utils.ZendeskUtils;
import org.embulk.spi.DataException;
import org.embulk.util.retryhelper.RetryExecutor;
import org.embulk.util.retryhelper.RetryGiveupException;
import org.embulk.util.retryhelper.Retryable;
import org.slf4j.Logger;
Expand All @@ -35,7 +36,6 @@

import static org.apache.http.HttpHeaders.AUTHORIZATION;
import static org.apache.http.protocol.HTTP.CONTENT_TYPE;
import static org.embulk.util.retryhelper.RetryExecutor.retryExecutor;

public class ZendeskRestClient
{
Expand All @@ -61,9 +61,11 @@ public String doGet(final String url, final PluginTask task, final boolean isPre
loginURL = task.getLoginUrl();

try {
return retryExecutor().withRetryLimit(task.getRetryLimit())
.withInitialRetryWait(task.getRetryInitialWaitSec() * 1000)
.withMaxRetryWait(task.getMaxRetryWaitSec() * 1000)
return RetryExecutor.builder()
.withRetryLimit(task.getRetryLimit())
.withInitialRetryWaitMillis(task.getRetryInitialWaitSec() * 1000)
.withMaxRetryWaitMillis(task.getMaxRetryWaitSec() * 1000)
.build()
.runInterruptible(new Retryable<String>() {
@Override
public String call()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
import java.util.List;
import java.util.stream.IntStream;

import static org.embulk.input.zendesk.ZendeskInputPlugin.CONFIG_MAPPER_FACTORY;

public class ZendeskChatService implements ZendeskService
{
private static final Logger logger = LoggerFactory.getLogger(ZendeskChatService.class);
Expand Down Expand Up @@ -54,7 +56,7 @@ public boolean isSupportIncremental()
@Override
public TaskReport addRecordToImporter(final int taskIndex, final RecordImporter recordImporter)
{
final TaskReport taskReport = Exec.newTaskReport();
final TaskReport taskReport = CONFIG_MAPPER_FACTORY.newTaskReport();
String startTime = getStartTime();
String endTime = getEndTime();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;

import static org.embulk.input.zendesk.ZendeskInputPlugin.CONFIG_MAPPER_FACTORY;

public class ZendeskCustomObjectService implements ZendeskService
{
protected ZendeskInputPlugin.PluginTask task;
Expand All @@ -47,7 +49,7 @@ public TaskReport addRecordToImporter(final int taskIndex, final RecordImporter
paths.parallelStream().forEach(path -> StreamSupport.stream(new CustomObjectSpliterator(path, getZendeskRestClient(), task, Exec.isPreview()), !Exec.isPreview())
.forEach(recordImporter::addRecord));

return Exec.newTaskReport();
return CONFIG_MAPPER_FACTORY.newTaskReport();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

import static org.embulk.input.zendesk.ZendeskInputPlugin.CONFIG_MAPPER_FACTORY;

public abstract class ZendeskNormalServices implements ZendeskService
{
private static final Logger logger = LoggerFactory.getLogger(ZendeskNormalServices.class);
Expand All @@ -44,7 +46,7 @@ protected ZendeskNormalServices(final ZendeskInputPlugin.PluginTask task)

public TaskReport addRecordToImporter(final int taskIndex, final RecordImporter recordImporter)
{
TaskReport taskReport = Exec.newTaskReport();
TaskReport taskReport = CONFIG_MAPPER_FACTORY.newTaskReport();

if (isSupportIncremental()) {
importDataForIncremental(task, recordImporter, taskReport);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
import java.util.stream.Stream;
import java.util.stream.StreamSupport;

import static org.embulk.input.zendesk.ZendeskInputPlugin.CONFIG_MAPPER_FACTORY;

public class ZendeskUserEventService implements ZendeskService
{
protected ZendeskInputPlugin.PluginTask task;
Expand All @@ -46,7 +48,7 @@ public boolean isSupportIncremental()
@Override
public TaskReport addRecordToImporter(final int taskIndex, final RecordImporter recordImporter)
{
final TaskReport taskReport = Exec.newTaskReport();
final TaskReport taskReport = CONFIG_MAPPER_FACTORY.newTaskReport();

if (Exec.isPreview()) {
JsonNode jsonNode = mockJsonNode();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import org.embulk.spi.Column;
import org.embulk.spi.PageBuilder;
import org.embulk.spi.Schema;
import org.embulk.spi.time.Timestamp;
import org.embulk.util.json.JsonParser;
import org.embulk.util.timestamp.TimestampFormatter;
import org.junit.Before;
Expand Down Expand Up @@ -82,7 +81,7 @@ public void testAddRecordAllRight()
verify(pageBuilder, times(1)).setLong(longColumn, longValue);
verify(pageBuilder, times(1)).setDouble(doubleColumn, doubleValue);
verify(pageBuilder, times(1)).setString(stringColumn, stringValue);
verify(pageBuilder, times(1)).setTimestamp(dateColumn, Timestamp.ofInstant(dateValue));
verify(pageBuilder, times(1)).setTimestamp(dateColumn, dateValue);
verify(pageBuilder, times(1)).setJson(jsonColumn, jsonValue);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.embulk.input.zendesk;

import com.fasterxml.jackson.databind.JsonNode;

import org.embulk.config.ConfigDiff;
import org.embulk.config.ConfigException;
import org.embulk.config.ConfigSource;
Expand All @@ -18,49 +17,44 @@
import org.embulk.input.zendesk.utils.ZendeskDateUtils;
import org.embulk.input.zendesk.utils.ZendeskPluginTestRuntime;
import org.embulk.input.zendesk.utils.ZendeskTestHelper;

import org.embulk.spi.Exec;
import org.embulk.spi.InputPlugin;
import org.embulk.spi.PageBuilder;
import org.embulk.spi.PageOutput;
import org.embulk.spi.Schema;

import org.embulk.spi.TestPageBuilderReader;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;

import java.time.Instant;
import java.time.OffsetDateTime;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

import static org.embulk.input.zendesk.ZendeskInputPlugin.CONFIG_MAPPER;
import static org.embulk.input.zendesk.ZendeskInputPlugin.CONFIG_MAPPER_FACTORY;
import static org.junit.Assert.assertEquals;

import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.ArgumentMatchers.anyString;

import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;

import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import java.time.Instant;
import java.time.OffsetDateTime;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

public class TestZendeskInputPlugin
{
@Rule
Expand Down Expand Up @@ -160,7 +154,7 @@ public void testRunIncrementalStoreStartTimeAndEndTime()
{
final ConfigSource src = ZendeskTestHelper.getConfigSource("incremental.yml")
.set("end_time", "2019-04-12 06:51:50 +0000");
TaskReport taskReport = Exec.newTaskReport();
TaskReport taskReport = CONFIG_MAPPER_FACTORY.newTaskReport();
taskReport.set(ZendeskConstants.Field.START_TIME, 1557026576);
taskReport.set(ZendeskConstants.Field.END_TIME, 1560309776);

Expand All @@ -182,7 +176,7 @@ public void testRunIncrementalStoreStartTimeAndEndTimeForChat()
final ConfigSource src = ZendeskTestHelper.getConfigSource("chat.yml")
.set("incremental", true)
.set("end_time", "2019-04-12 06:51:50 +0000");
TaskReport taskReport = Exec.newTaskReport();
TaskReport taskReport = CONFIG_MAPPER_FACTORY.newTaskReport();
taskReport.set(ZendeskConstants.Field.START_TIME, 1557026576);
taskReport.set(ZendeskConstants.Field.END_TIME, 1560309776);

Expand Down