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

com.microsoft.bingads.v13.bulk.entities.BulkPromotionAdExtension 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.text.ParseException;
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.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.ArrayOfstring;
import com.microsoft.bingads.v13.campaignmanagement.PromotionAdExtension;
import com.microsoft.bingads.v13.campaignmanagement.PromotionDiscountModifier;
import com.microsoft.bingads.v13.campaignmanagement.PromotionOccasion;
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 promotion ad extension that can be read or written in a bulk file.
 * This class exposes the properties
 * that can be read and written as fields of the Promotion Ad Extension record in a
 * bulk file.
 *
 * For more information, see Promotion Ad Extension at
 * https://go.microsoft.com/fwlink/?linkid=846127
 *
 * @see BulkServiceManager
 * @see BulkOperation
 * @see BulkFileReader
 * @see BulkFileWriter
 */
public class BulkPromotionAdExtension extends BulkAdExtension {

    /**
     * Gets the promotion ad extension.
     */
    public PromotionAdExtension getPromotionAdExtension() {
        return getAdExtension();
    }

    /**
     * Sets the promotion ad extension.
     */
    public void setPromotionAdExtension(PromotionAdExtension PromotionAdExtension) {
        setAdExtension(PromotionAdExtension);
    }

    private static final List> MAPPINGS;
    
    private String actionText;

    static {
        List> m = new ArrayList>();

        m.add(new SimpleBulkMapping(StringTable.CurrencyCode,
                new Function() {
                    @Override
                    public String apply(BulkPromotionAdExtension t) {
                        return t.getPromotionAdExtension().getCurrencyCode();
                    }
                },
                new BiConsumer() {
                    @Override
                    public void accept(String v, BulkPromotionAdExtension c) {
                        c.getPromotionAdExtension().setCurrencyCode(StringExtensions.getValueOrEmptyString(v));
                    }
                }
        ));
        
        m.add(new SimpleBulkMapping(StringTable.Language,
                new Function() {
                    @Override
                    public String apply(BulkPromotionAdExtension t) {
                        return t.getPromotionAdExtension().getLanguage();
                    }
                },
                new BiConsumer() {
                    @Override
                    public void accept(String v, BulkPromotionAdExtension c) {
                        c.getPromotionAdExtension().setLanguage(StringExtensions.getValueOrEmptyString(v));
                    }
                }
        ));
        

        m.add(new SimpleBulkMapping(StringTable.PromotionCode,
                new Function() {
                    @Override
                    public String apply(BulkPromotionAdExtension t) {
                        return StringExtensions.toOptionalBulkString(t.getPromotionAdExtension().getPromotionCode(), t.getPromotionAdExtension().getId());
                    }
                },
                new BiConsumer() {
                    @Override
                    public void accept(String v, BulkPromotionAdExtension c) {
                        c.getPromotionAdExtension().setPromotionCode(StringExtensions.getValueOrEmptyString(v));
                    }
                }
        ));
        
        m.add(new SimpleBulkMapping(StringTable.PromotionTarget,
                new Function() {
                    @Override
                    public String apply(BulkPromotionAdExtension t) {
                        return t.getPromotionAdExtension().getPromotionItem();
                    }
                },
                new BiConsumer() {
                    @Override
                    public void accept(String v, BulkPromotionAdExtension c) {
                        c.getPromotionAdExtension().setPromotionItem(StringExtensions.getValueOrEmptyString(v));
                    }
                }
        ));
        
        m.add(new SimpleBulkMapping(StringTable.PromotionStart,
                new Function() {
                    @Override
                    public String apply(BulkPromotionAdExtension t) {
                        return StringExtensions.toScheduleDateBulkString(t.getPromotionAdExtension().getPromotionStartDate(), t.getPromotionAdExtension().getId());
                    }
                },
                new BiConsumer() {
                    @Override
                    public void accept(String v, BulkPromotionAdExtension c) {
                        try {
                            c.getPromotionAdExtension().setPromotionStartDate(StringExtensions.parseDate(v));
                        } catch (ParseException e) {
                            e.printStackTrace();
                        }
                    }
                }
        ));
        
        m.add(new SimpleBulkMapping(StringTable.PromotionEnd,
                new Function() {
                    @Override
                    public String apply(BulkPromotionAdExtension t) {
                        return StringExtensions.toScheduleDateBulkString(t.getPromotionAdExtension().getPromotionEndDate(), t.getPromotionAdExtension().getId());
                    }
                },
                new BiConsumer() {
                    @Override
                    public void accept(String v, BulkPromotionAdExtension c) {
                        try {
                            c.getPromotionAdExtension().setPromotionEndDate(StringExtensions.parseDate(v));
                        } catch (ParseException e) {
                            e.printStackTrace();
                        }
                    }
                }
        ));
        
        m.add(new SimpleBulkMapping(StringTable.MoneyAmountOff,
                new Function() {
                    @Override
                    public String apply(BulkPromotionAdExtension t) {
                        return StringExtensions.toBulkString(t.getPromotionAdExtension().getMoneyAmountOff());
                    }
                },
                new BiConsumer() {
                    @Override
                    public void accept(String v, BulkPromotionAdExtension c) {
                        c.getPromotionAdExtension().setMoneyAmountOff(StringExtensions.parseOptional(v,  new Function() {
                            @Override
                            public Double apply(String value) {
                                return Double.parseDouble(value);
                            }
                        }));
                    }
                }
        ));

        m.add(new SimpleBulkMapping(StringTable.OrdersOverAmount,
                new Function() {
                    @Override
                    public String apply(BulkPromotionAdExtension t) {
                        return StringExtensions.toBulkString(t.getPromotionAdExtension().getOrdersOverAmount());
                    }
                },
                new BiConsumer() {
                    @Override
                    public void accept(String v, BulkPromotionAdExtension c) {
                        c.getPromotionAdExtension().setOrdersOverAmount(StringExtensions.parseOptional(v,  new Function() {
                            @Override
                            public Double apply(String value) {
                                return Double.parseDouble(value);
                            }
                        }));
                    }
                }
        ));

        m.add(new SimpleBulkMapping(StringTable.PercentOff,
                new Function() {
                    @Override
                    public String apply(BulkPromotionAdExtension t) {
                        return StringExtensions.toBulkString(t.getPromotionAdExtension().getPercentOff());
                    }
                },
                new BiConsumer() {
                    @Override
                    public void accept(String v, BulkPromotionAdExtension c) {
                        c.getPromotionAdExtension().setPercentOff(StringExtensions.parseOptional(v,  new Function() {
                            @Override
                            public Double apply(String value) {
                                return Double.parseDouble(value);
                            }
                        }));
                    }
                }
        ));

        m.add(new SimpleBulkMapping(StringTable.DiscountModifier,
                new Function() {
                    @Override
                    public String apply(BulkPromotionAdExtension t) {
                        if (t.getPromotionAdExtension().getDiscountModifier() == null) return null;
                        return StringExtensions.toBulkString(t.getPromotionAdExtension().getDiscountModifier().value());
                    }
                },
                new BiConsumer() {
                    @Override
                    public void accept(String v, BulkPromotionAdExtension c) {
                        c.getPromotionAdExtension().setDiscountModifier(StringExtensions.parseOptional(v,  new Function() {
                            @Override
                            public PromotionDiscountModifier apply(String value) {
                                return PromotionDiscountModifier.fromValue(value);
                            }
                        }));
                    }
                }
        ));

        m.add(new SimpleBulkMapping(StringTable.Occasion,
                new Function() {
                    @Override
                    public String apply(BulkPromotionAdExtension t) {
                        if (t.getPromotionAdExtension().getPromotionOccasion() == null) return null;
                        return StringExtensions.toBulkString(t.getPromotionAdExtension().getPromotionOccasion().value());
                    }
                },
                new BiConsumer() {
                    @Override
                    public void accept(String v, BulkPromotionAdExtension c) {
                        c.getPromotionAdExtension().setPromotionOccasion(StringExtensions.parseOptional(v,  new Function() {
                            @Override
                            public PromotionOccasion apply(String value) {
                                return PromotionOccasion.fromValue(value);
                            }
                        }));
                    }
                }
        ));

        m.add(new SimpleBulkMapping(StringTable.FinalUrl,
                new Function() {
                    @Override
                    public String apply(BulkPromotionAdExtension c) {
                        return StringExtensions.writeUrls("; ", c.getPromotionAdExtension().getFinalUrls(), c.getPromotionAdExtension().getId());
                    }
                },
                new BiConsumer() {
                    @Override
                    public void accept(String v, BulkPromotionAdExtension c) {
                        ArrayOfstring urls = new ArrayOfstring();
                        List urlArray = StringExtensions.parseUrls(v);
                        if(urlArray == null) {
                            urls = null;
                        } else {
                            urls.getStrings().addAll(urlArray);
                        }
                        c.getPromotionAdExtension().setFinalUrls(urls);
                    }
                }
        ));
        
        m.add(new SimpleBulkMapping(StringTable.FinalMobileUrl,
                new Function() {
                    @Override
                    public String apply(BulkPromotionAdExtension c) {
                        return StringExtensions.writeUrls("; ", c.getPromotionAdExtension().getFinalMobileUrls(), c.getPromotionAdExtension().getId());
                    }
                },
                new BiConsumer() {
                    @Override
                    public void accept(String v, BulkPromotionAdExtension c) {
                        ArrayOfstring urls = new ArrayOfstring();
                        List urlArray = StringExtensions.parseUrls(v);
                        if(urlArray == null) {
                            urls = null;
                        } else {
                            urls.getStrings().addAll(urlArray);
                        }
                        c.getPromotionAdExtension().setFinalMobileUrls(urls);
                    }
                }
        ));

        m.add(new SimpleBulkMapping(StringTable.TrackingTemplate,
                new Function() {
                    @Override
                    public String apply(BulkPromotionAdExtension t) {
                        return StringExtensions.toOptionalBulkString(t.getPromotionAdExtension().getTrackingUrlTemplate(), t.getPromotionAdExtension().getId());
                    }
                },
                new BiConsumer() {
                    @Override
                    public void accept(String v, BulkPromotionAdExtension c) {
                        c.getPromotionAdExtension().setTrackingUrlTemplate(StringExtensions.getValueOrEmptyString(v));
                    }
                }
        ));


        m.add(new SimpleBulkMapping(StringTable.CustomParameter,
                new Function() {
                    @Override
                    public String apply(BulkPromotionAdExtension c) {
                        return StringExtensions.toCustomParaBulkString(c.getPromotionAdExtension().getUrlCustomParameters(), c.getPromotionAdExtension().getId());
                    }
                },
                new BiConsumer() {
                    @Override
                    public void accept(String v, BulkPromotionAdExtension c) {
                        try {
                                c.getPromotionAdExtension().setUrlCustomParameters(StringExtensions.parseCustomParameters(v));
                        } catch (Exception e) {
                                e.printStackTrace();
                        }
                    }
                }
        ));

        m.add(new SimpleBulkMapping(StringTable.FinalUrlSuffix,
                new Function() {
                    @Override
                    public String apply(BulkPromotionAdExtension c) {
                        return StringExtensions.toOptionalBulkString(c.getAdExtension().getFinalUrlSuffix(), c.getAdExtension().getId());
                    }
                },
                new BiConsumer() {
                    @Override
                    public void accept(String v, BulkPromotionAdExtension c) {
                        c.getAdExtension().setFinalUrlSuffix(StringExtensions.getValueOrEmptyString(v));
                    }
                }
        ));

        MAPPINGS = Collections.unmodifiableList(m);
    }

    @Override
    public void processMappingsFromRowValues(RowValues values) {
        PromotionAdExtension extension = new PromotionAdExtension();

        extension.setType("PromotionAdExtension");

        setAdExtension(extension);

        super.processMappingsFromRowValues(values);

        MappingHelpers.convertToEntity(values, MAPPINGS, this);
    }

    @Override
    public void processMappingsToRowValues(RowValues values, boolean excludeReadonlyData) {
        validatePropertyNotNull(this.getPromotionAdExtension(), "PromotionAdExtension");

        super.processMappingsToRowValues(values, excludeReadonlyData);
        MappingHelpers.convertToValues(this, values, MAPPINGS);
    }

    public String getActionText() {
        return actionText;
    }

    public void setActionText(String actionText) {
        this.actionText = actionText;
    }
    
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy