Sha256: 44ee9bd020a5a0b72241c7683c410eddbc6697c0378f841106bfa84396aee394

Contents?: true

Size: 1.84 KB

Versions: 1

Compression:

Stored size: 1.84 KB

Contents

package org.embulk.output.kintone;

import java.util.List;
import org.embulk.config.ConfigDiff;
import org.embulk.config.ConfigException;
import org.embulk.config.ConfigSource;
import org.embulk.config.TaskReport;
import org.embulk.config.TaskSource;
import org.embulk.spi.Exec;
import org.embulk.spi.OutputPlugin;
import org.embulk.spi.Schema;
import org.embulk.spi.TransactionalPageOutput;

public class KintoneOutputPlugin implements OutputPlugin {
  @Override
  public ConfigDiff transaction(
      ConfigSource config, Schema schema, int taskCount, OutputPlugin.Control control) {
    PluginTask task = config.loadConfig(PluginTask.class);
    control.run(task.dump());
    return Exec.newConfigDiff();
  }

  @Override
  public ConfigDiff resume(
      TaskSource taskSource, Schema schema, int taskCount, OutputPlugin.Control control) {
    throw new UnsupportedOperationException("kintone output plugin does not support resuming");
  }

  @Override
  public void cleanup(
      TaskSource taskSource, Schema schema, int taskCount, List<TaskReport> successTaskReports) {}

  @Override
  public TransactionalPageOutput open(TaskSource taskSource, Schema schema, int taskIndex) {
    PluginTask task = taskSource.loadTask(PluginTask.class);
    KintoneMode mode = KintoneMode.getKintoneModeByValue(task.getMode());
    switch (mode) {
      case INSERT:
        if (task.getUpdateKeyName().isPresent()) {
          throw new ConfigException("when mode is insert, require no update_key.");
        }
        break;
      case UPDATE:
      case UPSERT:
        if (!task.getUpdateKeyName().isPresent()) {
          throw new ConfigException("when mode is update or upsert, require update_key.");
        }
        break;
      default:
        throw new ConfigException(String.format("Unknown mode '%s'", task.getMode()));
    }
    return new KintonePageOutput(task, schema);
  }
}

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
embulk-output-kintone-1.0.0 src/main/java/org/embulk/output/kintone/KintoneOutputPlugin.java