com.microsoft.bingads.v10.bulk.entities.BulkAccount Maven / Gradle / Ivy
Show all versions of microsoft.bingads Show documentation
package com.microsoft.bingads.v10.bulk.entities;
import com.microsoft.bingads.v10.bulk.BulkServiceManager;
import com.microsoft.bingads.v10.bulk.BulkFileReader;
import com.microsoft.bingads.v10.bulk.BulkFileWriter;
import com.microsoft.bingads.v10.bulk.BulkOperation;
import com.microsoft.bingads.internal.UncheckedParseException;
import com.microsoft.bingads.v10.internal.bulk.StringExtensions;
import com.microsoft.bingads.v10.internal.bulk.StringTable;
import com.microsoft.bingads.v10.internal.bulk.BulkMapping;
import com.microsoft.bingads.v10.internal.bulk.MappingHelpers;
import com.microsoft.bingads.v10.internal.bulk.RowValues;
import com.microsoft.bingads.v10.internal.bulk.SimpleBulkMapping;
import com.microsoft.bingads.v10.internal.bulk.entities.SingleRecordBulkEntity;
import com.microsoft.bingads.internal.functionalinterfaces.BiConsumer;
import com.microsoft.bingads.internal.functionalinterfaces.Function;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collections;
import java.util.GregorianCalendar;
import java.util.List;
import java.util.TimeZone;
/**
* Represents an account that can be read or written in a bulk file.
*
*
* Properties of this class and of classes that it is derived from, correspond to fields of the Account record in a bulk file.
* For more information, see Account at
* http://go.microsoft.com/fwlink/?LinkID=620233.
*
*
* @see BulkServiceManager
* @see BulkOperation
* @see BulkFileReader
* @see BulkFileWriter
*/
public class BulkAccount extends SingleRecordBulkEntity {
private long id;
private long customerId;
private Calendar syncTime;
private static final List> MAPPINGS;
static {
List> m = new ArrayList>();
m.add(new SimpleBulkMapping(StringTable.Id,
new Function() {
@Override
public Long apply(BulkAccount t) {
return t.getId();
}
},
new BiConsumer() {
@Override
public void accept(String v, BulkAccount c) {
c.setId(Long.parseLong(v));
}
}
));
m.add(new SimpleBulkMapping(StringTable.ParentId,
new Function() {
@Override
public Long apply(BulkAccount t) {
return t.getCustomerId();
}
},
new BiConsumer() {
@Override
public void accept(String v, BulkAccount c) {
c.setCustomerId(Long.parseLong(v));
}
}
));
m.add(new SimpleBulkMapping(StringTable.SyncTime,
new Function() {
@Override
public String apply(BulkAccount t) {
if (t.getSyncTime() == null) {
return null;
}
SimpleDateFormat format = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
format.setTimeZone(TimeZone.getTimeZone("UTC"));
return format.format(t.getSyncTime().getTime());
}
},
new BiConsumer() {
@Override
public void accept(String v, BulkAccount c) {
c.setSyncTime(StringExtensions.parseOptional(v, new Function() {
@Override
public Calendar apply(String t) {
Calendar c = new GregorianCalendar();
try {
SimpleDateFormat format = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
format.setTimeZone(TimeZone.getTimeZone("UTC"));
c.setTime(format.parse(t));
} catch (ParseException ex) {
throw new UncheckedParseException(ex);
}
return c;
}
}));
}
}
));
MAPPINGS = Collections.unmodifiableList(m);
}
/**
* Gets the identifier of the account.
*
*
* Corresponds to the 'Id' field in the bulk file.
*
*/
public long getId() {
return id;
}
/**
* Sets the identifier of the account.
*
*
* Corresponds to the 'Id' field in the bulk file.
*
*/
public void setId(long id) {
this.id = id;
}
/**
* Gets the identifier of the customer that contains the account.
*
*
* Corresponds to the 'Parent Id' field in the bulk file.
*
*/
public long getCustomerId() {
return customerId;
}
/**
* Sets the identifier of the customer that contains the account.
*
*
* Corresponds to the 'Parent Id' field in the bulk file.
*
*/
public void setCustomerId(long customerId) {
this.customerId = customerId;
}
/**
* Gets the date and time that you last synced your account using the bulk service.
*
*
* You should keep track of this value in UTC time.
* Corresponds to the 'Sync Time' field in the bulk file.
*
*/
public Calendar getSyncTime() {
return syncTime;
}
/**
* Sets the date and time that you last synced your account using the bulk service.
*
*
* You should keep track of this value in UTC time.
* Corresponds to the 'Sync Time' field in the bulk file.
*
*/
public void setSyncTime(Calendar syncTime) {
this.syncTime = syncTime;
}
@Override
public void processMappingsFromRowValues(RowValues values) {
MappingHelpers.convertToEntity(values, MAPPINGS, this);
}
@Override
public void processMappingsToRowValues(RowValues values, boolean excludeReadonlyData) {
MappingHelpers.convertToValues(this, values, MAPPINGS);
}
}