package org.embulk.input.adebis.operation; import com.google.common.base.Optional; import jp.ne.ebis.extreme.ws.entity.xsd.HoteiAuthHeader; import jp.ne.ebis.extreme.ws.entity.xsd.HoteiAuthHeaderE; import jp.ne.ebis.extreme.ws.service.AdGroup1ManagementService; import jp.ne.ebis.extreme.ws.service.AdGroup1ManagementServiceStub; import jp.ne.ebis.extreme.ws.service.GetAdGroup1SResponse; import org.apache.axis2.AxisFault; import org.embulk.config.Config; import org.embulk.config.ConfigDefault; import org.embulk.config.Task; import org.embulk.input.adebis.AdebisInputPlugin; import org.embulk.spi.Column; import org.embulk.spi.PageBuilder; import org.embulk.spi.Schema; import org.embulk.spi.type.Types; import java.rmi.RemoteException; import java.time.LocalDate; import java.time.LocalDateTime; import java.util.Date; public class AdGroup1 extends AbstractOperation { public int lastRecordId = 0; public interface Condition extends Task { //リクエストパラメータ無し } public void run(PageBuilder pageBuilder) { Schema schema = pageBuilder.getSchema(); AdGroup1ManagementService adGroup1ManagementService; try { adGroup1ManagementService = new AdGroup1ManagementServiceStub(); } catch (AxisFault axisFault) { axisFault.printStackTrace(); return; } //LocalDate startDate = LocalDate.parse(condition.getStartDate().get(), adebisDateFormat); //LocalDate endDate = LocalDate.parse(condition.getEndDate().get(), adebisDateFormat); LocalDateTime lastRecordTime, newestRecordTime; //System.out.println(startDate); //System.out.println(endDate); if(getLastRecordTime().isPresent()) { lastRecordTime = LocalDateTime.parse(getLastRecordTime().get(), embulkDateTimeFormat); } else { //lastRecordTime = startDate.atStartOfDay(); lastRecordTime = LocalDateTime.now(); //lastRecordTime = Optional.of(lastRecordTime.format(embulkDateTimeFormat)); } if(getLastRecordId().isPresent()) { lastRecordId = Integer.parseInt(getLastRecordId().get()); } //if(lastRecordTime.isAfter(startDate.atStartOfDay())) { // startDate = lastRecordTime.toLocalDate(); //} // Build Header HoteiAuthHeader header = new HoteiAuthHeader(); HoteiAuthHeaderE headerE = new HoteiAuthHeaderE(); header.setLogId(getLogId()); header.setLogArgument(getLogArgument()); header.setApiKey(getApiKey()); headerE.setHoteiAuthHeader(header); GetAdGroup1SResponse response; newestRecordTime = lastRecordTime; try { response = adGroup1ManagementService.getAdGroup1S(headerE); } catch (RemoteException e) { e.printStackTrace(); return; } catch (NullPointerException e) { return; } jp.ne.ebis.extreme.ws.entity.xsd.AdGroup1[] results = response.get_return(); for (jp.ne.ebis.extreme.ws.entity.xsd.AdGroup1 record : results) { Boolean isExcluded = false; int currentRecordId= record.getAdGroup1Id(); if ( ! record.isAdGroup1IdSpecified()) { break; } if (lastRecordId < currentRecordId) { lastRecordId = currentRecordId; } else { continue; } for (Column c : schema.getColumns()) { switch (c.getName()) { case "createdAt": long unixtime = System.currentTimeMillis() / 1000L; org.embulk.spi.time.Timestamp timestamp = org.embulk.spi.time.Timestamp.ofEpochSecond(unixtime); pageBuilder.setTimestamp(c, timestamp); break; case "adGroup1Id": if (record.isAdGroup1IdSpecified()) pageBuilder.setLong(c, record.getAdGroup1Id()); else pageBuilder.setNull(c); break; case "adGroup1Name": if (record.isAdGroup1NameSpecified()) pageBuilder.setString(c, record.getAdGroup1Name()); else pageBuilder.setNull(c); break; default: break; } if (isExcluded) break; } if (isExcluded) pageBuilder.flush(); else pageBuilder.addRecord(); } setLastRecordTime(Optional.of(newestRecordTime.format(embulkDateTimeFormat))); setLastRecordId(Optional.of(String.valueOf(lastRecordId))); } public Schema buildSchema() { return Schema.builder() .add("createdAt" , Types.TIMESTAMP) .add("adGroup1Id" , Types.LONG) .add("adGroup1Name", Types.STRING) .build(); } }