All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.microsoft.bingads.v13.bulk.entities.BulkLocationAdExtension Maven / Gradle / Ivy

Go to download

The Bing Ads Java SDK is a library improving developer experience when working with the Bing Ads services by providing high-level access to features such as Bulk API, OAuth Authorization and SOAP API.

There is a newer version: 13.0.22.1
Show newest version
package com.microsoft.bingads.v13.bulk.entities;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import com.microsoft.bingads.internal.functionalinterfaces.BiConsumer;
import com.microsoft.bingads.internal.functionalinterfaces.Consumer;
import com.microsoft.bingads.internal.functionalinterfaces.Function;
import com.microsoft.bingads.v13.bulk.BulkFileReader;
import com.microsoft.bingads.v13.bulk.BulkFileWriter;
import com.microsoft.bingads.v13.bulk.BulkOperation;
import com.microsoft.bingads.v13.bulk.BulkServiceManager;
import com.microsoft.bingads.v13.campaignmanagement.Address;
import com.microsoft.bingads.v13.campaignmanagement.BusinessGeoCodeStatus;
import com.microsoft.bingads.v13.campaignmanagement.GeoPoint;
import com.microsoft.bingads.v13.campaignmanagement.LocationAdExtension;
import com.microsoft.bingads.v13.internal.bulk.BulkMapping;
import com.microsoft.bingads.v13.internal.bulk.MappingHelpers;
import com.microsoft.bingads.v13.internal.bulk.RowValues;
import com.microsoft.bingads.v13.internal.bulk.SimpleBulkMapping;
import com.microsoft.bingads.v13.internal.bulk.StringExtensions;
import com.microsoft.bingads.v13.internal.bulk.StringTable;

/**
 * Represents an location ad extension. This class exposes
 * properties that can be read
 * and written as fields of the Location Ad Extension record in a bulk file.
 *
 * 

* For more information, see Location Ad Extension at * https://go.microsoft.com/fwlink/?linkid=846127 *

* * @see BulkServiceManager * @see BulkOperation * @see BulkFileReader * @see BulkFileWriter */ public class BulkLocationAdExtension extends BulkAdExtension { /** * Gets the location ad extension. */ public LocationAdExtension getLocationAdExtension() { return this.getAdExtension(); } public void setLocationAdExtension(LocationAdExtension extension) { this.setAdExtension(extension); } private static final List> MAPPINGS; static { List> m = new ArrayList>(); m.add(new SimpleBulkMapping(StringTable.BusinessName, new Function() { @Override public String apply(BulkLocationAdExtension c) { return c.getLocationAdExtension().getCompanyName(); } }, new BiConsumer() { @Override public void accept(String v, BulkLocationAdExtension c) { c.getLocationAdExtension().setCompanyName(v); } } )); m.add(new SimpleBulkMapping(StringTable.PhoneNumber, new Function() { @Override public String apply(BulkLocationAdExtension c) { return StringExtensions.toOptionalBulkString(c.getLocationAdExtension().getPhoneNumber(), c.getLocationAdExtension().getId()); } }, new BiConsumer() { @Override public void accept(String v, BulkLocationAdExtension c) { c.getLocationAdExtension().setPhoneNumber(StringExtensions.getValueOrEmptyString(v)); } }, true )); m.add(new SimpleBulkMapping(StringTable.GeoCodeStatus, new Function() { @Override public String apply(BulkLocationAdExtension c) { return StringExtensions.toGeoCodeStatusBulkString(c.getLocationAdExtension().getGeoCodeStatus()); } }, new BiConsumer() { @Override public void accept(String v, BulkLocationAdExtension c) { c.getLocationAdExtension().setGeoCodeStatus(StringExtensions.parseOptional(v, new Function() { @Override public BusinessGeoCodeStatus apply(String value) { return BusinessGeoCodeStatus.fromValue(value); } })); } } )); m.add(new SimpleBulkMapping(StringTable.AddressLine1, new Function() { @Override public String apply(BulkLocationAdExtension c) { return getAddressPart(c, new Function() { @Override public String apply(Address x) { return x.getStreetAddress(); } }); } }, new BiConsumer() { @Override public void accept(final String v, BulkLocationAdExtension c) { setAddressPart(c, new Consumer
() { @Override public void accept(Address x) { x.setStreetAddress(StringExtensions.getValueOrEmptyString(v)); } }); } } )); m.add(new SimpleBulkMapping(StringTable.AddressLine2, new Function() { @Override public String apply(BulkLocationAdExtension c) { return getAddressPart(c, new Function() { @Override public String apply(Address x) { return StringExtensions.toOptionalBulkString(x.getStreetAddress2(), c.getAdExtension().getId()); } }); } }, new BiConsumer() { @Override public void accept(final String v, BulkLocationAdExtension c) { setAddressPart(c, new Consumer
() { @Override public void accept(Address x) { x.setStreetAddress2(StringExtensions.getValueOrEmptyString(v)); } }); } } )); m.add(new SimpleBulkMapping(StringTable.City, new Function() { @Override public String apply(BulkLocationAdExtension c) { return getAddressPart(c, new Function() { @Override public String apply(Address x) { return x.getCityName(); } }); } }, new BiConsumer() { @Override public void accept(final String v, BulkLocationAdExtension c) { setAddressPart(c, new Consumer
() { @Override public void accept(Address x) { x.setCityName(v); } }); } } )); m.add(new SimpleBulkMapping(StringTable.ProvinceName, new Function() { @Override public String apply(BulkLocationAdExtension c) { return getAddressPart(c, new Function() { @Override public String apply(Address x) { return x.getProvinceName(); } }); } }, new BiConsumer() { @Override public void accept(final String v, BulkLocationAdExtension c) { setAddressPart(c, new Consumer
() { @Override public void accept(Address x) { x.setProvinceName(v); } }); } } )); m.add(new SimpleBulkMapping(StringTable.StateOrProvince, new Function() { @Override public String apply(BulkLocationAdExtension c) { return getAddressPart(c, new Function() { @Override public String apply(Address x) { return x.getProvinceCode(); } }); } }, new BiConsumer() { @Override public void accept(final String v, BulkLocationAdExtension c) { setAddressPart(c, new Consumer
() { @Override public void accept(Address x) { x.setProvinceCode(v); } }); } } )); m.add(new SimpleBulkMapping(StringTable.PostalCode, new Function() { @Override public String apply(BulkLocationAdExtension c) { return getAddressPart(c, new Function() { @Override public String apply(Address x) { return x.getPostalCode(); } }); } }, new BiConsumer() { @Override public void accept(final String v, BulkLocationAdExtension c) { setAddressPart(c, new Consumer
() { @Override public void accept(Address x) { x.setPostalCode(v); } }); } } )); m.add(new SimpleBulkMapping(StringTable.CountryCode, new Function() { @Override public String apply(BulkLocationAdExtension c) { return getAddressPart(c, new Function() { @Override public String apply(Address x) { return x.getCountryCode(); } }); } }, new BiConsumer() { @Override public void accept(final String v, BulkLocationAdExtension c) { setAddressPart(c, new Consumer
() { @Override public void accept(Address x) { x.setCountryCode(v); } }); } } )); m.add(new SimpleBulkMapping(StringTable.Latitude, new Function() { @Override public Double apply(BulkLocationAdExtension c) { return getGeoPointPart(c, new Function() { @Override public Double apply(GeoPoint x) { return (x.getLatitudeInMicroDegrees() / 1000000.0); } }); } }, new BiConsumer() { @Override public void accept(final String v, BulkLocationAdExtension c) { setGeoPointPart(c, new BiConsumer() { @Override public void accept(GeoPoint x, final String longitude) { x.setLatitudeInMicroDegrees(StringExtensions.parseLatLngInMicroDegrees(longitude)); } }, v); } } )); m.add(new SimpleBulkMapping(StringTable.Longitude, new Function() { @Override public Double apply(BulkLocationAdExtension c) { return getGeoPointPart(c, new Function() { @Override public Double apply(GeoPoint x) { return (x.getLongitudeInMicroDegrees() / 1000000.0); } }); } }, new BiConsumer() { @Override public void accept(final String v, BulkLocationAdExtension c) { setGeoPointPart(c, new BiConsumer() { @Override public void accept(GeoPoint x, final String longitude) { x.setLongitudeInMicroDegrees(StringExtensions.parseLatLngInMicroDegrees(longitude)); } }, v); } } )); MAPPINGS = Collections.unmodifiableList(m); } private static String getAddressPart(BulkLocationAdExtension adExtension, Function getFunc) { return adExtension.getLocationAdExtension().getAddress() != null ? getFunc.apply(adExtension.getLocationAdExtension().getAddress()) : null; } private static void setAddressPart(BulkLocationAdExtension adExtension, Consumer
setFunc) { if (adExtension.getLocationAdExtension().getAddress() == null) { adExtension.getLocationAdExtension().setAddress(new Address()); } setFunc.accept(adExtension.getLocationAdExtension().getAddress()); } private static Double getGeoPointPart(BulkLocationAdExtension adExtension, Function getFunc) { return adExtension.getLocationAdExtension().getGeoPoint() != null ? getFunc.apply(adExtension.getLocationAdExtension().getGeoPoint()) : null; } private static void setGeoPointPart(BulkLocationAdExtension adExtension, BiConsumer setFunc, String value) { if (StringExtensions.isNullOrEmpty(value)) { return; } if (adExtension.getLocationAdExtension().getGeoPoint() == null) { adExtension.getLocationAdExtension().setGeoPoint(new GeoPoint()); } setFunc.accept(adExtension.getLocationAdExtension().getGeoPoint(), value); } @Override public void processMappingsFromRowValues(RowValues values) { LocationAdExtension extension = new LocationAdExtension(); extension.setType("LocationAdExtension"); this.setLocationAdExtension(extension); if (!StringExtensions.isNullOrEmpty(values.get(StringTable.Latitude)) || !StringExtensions.isNullOrEmpty(values.get(StringTable.Longitude))) { this.getLocationAdExtension().setGeoPoint(new GeoPoint()); } super.processMappingsFromRowValues(values); MappingHelpers.convertToEntity(values, MAPPINGS, this); } @Override public void processMappingsToRowValues(RowValues values, boolean excludeReadonlyData) { validatePropertyNotNull(this.getLocationAdExtension(), "LocationAdExtension"); super.processMappingsToRowValues(values, excludeReadonlyData); MappingHelpers.convertToValues(this, values, MAPPINGS); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy