Search in sources :

Example 11 with NumberValue

use of com.google.api.ads.admanager.jaxws.v202105.NumberValue in project googleads-java-lib by googleads.

the class SetLineItemCustomFieldValue method runExample.

/**
 * Runs the example.
 *
 * @param adManagerServices the services factory.
 * @param session the session.
 * @param numberCustomFieldId the ID of the number typed custom field to set on the line item.
 * @param customFieldOptionId the ID of the option for the drop-down custom field.
 * @param lineItemId the ID of the line item to set these custom fields.
 * @throws ApiException if the API request failed with one or more service errors.
 * @throws RemoteException if the API request failed due to other errors.
 */
public static void runExample(AdManagerServices adManagerServices, AdManagerSession session, long numberCustomFieldId, long customFieldOptionId, long lineItemId) throws RemoteException {
    // Get the CustomFieldService.
    CustomFieldServiceInterface customFieldService = adManagerServices.get(session, CustomFieldServiceInterface.class);
    // Get the LineItemService.
    LineItemServiceInterface lineItemService = adManagerServices.get(session, LineItemServiceInterface.class);
    // Get the drop-down custom field ID.
    long dropDownCustomFieldId = customFieldService.getCustomFieldOption(customFieldOptionId).getCustomFieldId();
    // Create a statement to only select a single line item by ID.
    StatementBuilder statementBuilder = new StatementBuilder().where("id = :id").orderBy("id ASC").limit(1).withBindVariableValue("id", lineItemId);
    // Get the line item.
    LineItemPage page = lineItemService.getLineItemsByStatement(statementBuilder.toStatement());
    LineItem lineItem = Iterables.getOnlyElement(Arrays.asList(page.getResults()));
    // Create number custom field value.
    NumberValue numberValue = new NumberValue();
    numberValue.setValue("12345");
    CustomFieldValue numberCustomFieldValue = new CustomFieldValue();
    numberCustomFieldValue.setCustomFieldId(numberCustomFieldId);
    numberCustomFieldValue.setValue(numberValue);
    // Create drop-down custom field value.
    DropDownCustomFieldValue dropDownCustomFieldValue = new DropDownCustomFieldValue();
    dropDownCustomFieldValue.setCustomFieldId(dropDownCustomFieldId);
    dropDownCustomFieldValue.setCustomFieldOptionId(customFieldOptionId);
    // Create a combined custom field value list of existing different custom
    // field values and new ones.
    List<BaseCustomFieldValue> combinedCustomFieldValues = new ArrayList<>();
    if (lineItem.getCustomFieldValues() != null) {
        for (BaseCustomFieldValue existingCustomFieldValue : lineItem.getCustomFieldValues()) {
            if (!existingCustomFieldValue.getCustomFieldId().equals(numberCustomFieldId) && !existingCustomFieldValue.getCustomFieldId().equals(dropDownCustomFieldId)) {
                combinedCustomFieldValues.add(existingCustomFieldValue);
            }
        }
    }
    combinedCustomFieldValues.addAll(Arrays.asList(numberCustomFieldValue, dropDownCustomFieldValue));
    // Set the combined custom field values.
    lineItem.setCustomFieldValues(combinedCustomFieldValues.toArray(new BaseCustomFieldValue[] {}));
    // Update the line item on the server.
    LineItem[] lineItems = lineItemService.updateLineItems(new LineItem[] { lineItem });
    for (LineItem updatedLineItem : lineItems) {
        // Get a string representation of the custom field values.
        List<String> customFieldValueStrings = Lists.transform(Arrays.asList(updatedLineItem.getCustomFieldValues()), new Function<BaseCustomFieldValue, String>() {

            @Override
            public String apply(BaseCustomFieldValue baseCustomFieldValue) {
                if (baseCustomFieldValue instanceof CustomFieldValue && ((CustomFieldValue) baseCustomFieldValue).getValue() instanceof NumberValue) {
                    return String.format("{ID: %d, value: %.0f}", baseCustomFieldValue.getCustomFieldId(), Double.parseDouble(((NumberValue) ((CustomFieldValue) baseCustomFieldValue).getValue()).getValue()));
                } else if (baseCustomFieldValue instanceof DropDownCustomFieldValue) {
                    return String.format("{ID: %d, customFieldOptionId: %d}", baseCustomFieldValue.getCustomFieldId(), ((DropDownCustomFieldValue) baseCustomFieldValue).getCustomFieldOptionId());
                } else {
                    return "{Unrecognized value}";
                }
            }
        });
        System.out.printf("A line item with ID %d was updated with custom field values '%s'%n", updatedLineItem.getId(), Joiner.on(",").join(customFieldValueStrings));
    }
}
Also used : CustomFieldValue(com.google.api.ads.admanager.axis.v202108.CustomFieldValue) BaseCustomFieldValue(com.google.api.ads.admanager.axis.v202108.BaseCustomFieldValue) DropDownCustomFieldValue(com.google.api.ads.admanager.axis.v202108.DropDownCustomFieldValue) DropDownCustomFieldValue(com.google.api.ads.admanager.axis.v202108.DropDownCustomFieldValue) BaseCustomFieldValue(com.google.api.ads.admanager.axis.v202108.BaseCustomFieldValue) LineItemServiceInterface(com.google.api.ads.admanager.axis.v202108.LineItemServiceInterface) CustomFieldServiceInterface(com.google.api.ads.admanager.axis.v202108.CustomFieldServiceInterface) ArrayList(java.util.ArrayList) LineItem(com.google.api.ads.admanager.axis.v202108.LineItem) NumberValue(com.google.api.ads.admanager.axis.v202108.NumberValue) LineItemPage(com.google.api.ads.admanager.axis.v202108.LineItemPage) StatementBuilder(com.google.api.ads.admanager.axis.utils.v202108.StatementBuilder)

Example 12 with NumberValue

use of com.google.api.ads.admanager.jaxws.v202105.NumberValue in project googleads-java-lib by googleads.

the class PqlTest method setUp.

@Before
public void setUp() throws Exception {
    column1 = new ColumnType();
    column1.setLabelName("column1");
    column2 = new ColumnType();
    column2.setLabelName("column2");
    column3 = new ColumnType();
    column3.setLabelName("column3");
    textValue1 = new TextValue();
    textValue1.setValue("value1");
    textValue2 = new TextValue();
    textValue2.setValue("value2");
    textValue3 = new TextValue();
    textValue3.setValue("value3");
    textValue4 = new TextValue();
    textValue4.setValue("comma,separated");
    booleanValue1 = new BooleanValue();
    booleanValue1.setValue(false);
    booleanValue2 = new BooleanValue();
    booleanValue2.setValue(true);
    booleanValue3 = new BooleanValue();
    booleanValue3.setValue(false);
    numberValue1 = new NumberValue();
    numberValue1.setValue("1");
    numberValue2 = new NumberValue();
    numberValue2.setValue("1.02");
    numberValue3 = new NumberValue();
    numberValue3.setValue("-1");
    dateTime1 = new DateTime();
    date1 = new Date();
    date1.setYear(2012);
    date1.setMonth(12);
    date1.setDay(2);
    dateTime1.setDate(date1);
    dateTime1.setHour(12);
    dateTime1.setMinute(45);
    dateTime1.setSecond(0);
    dateTime1.setTimeZoneId(TIME_ZONE_ID1);
    dateTimeValue1 = new DateTimeValue();
    dateTimeValue1.setValue(dateTime1);
    dateValue1 = new DateValue();
    dateValue1.setValue(date1);
    AdUnitTargeting adUnitTargeting = new AdUnitTargeting();
    adUnitTargeting.setAdUnitId("100");
    InventoryTargeting inventoryTargeting = new InventoryTargeting();
    inventoryTargeting.getTargetedAdUnits().add(adUnitTargeting);
    targeting1 = new Targeting();
    targeting1.setInventoryTargeting(inventoryTargeting);
    targetingValue1 = new TargetingValue();
    targetingValue1.setValue(targeting1);
    numberSetValue = new SetValue();
    numberSetValue.getValues().add(numberValue1);
    numberSetValue.getValues().add(numberValue3);
    textSetValue = new SetValue();
    textSetValue.getValues().add(textValue1);
    textSetValue.getValues().add(textValue2);
    dateSetValue = new SetValue();
    dateSetValue.getValues().add(dateValue1);
    dateTimeSetValue = new SetValue();
    dateTimeSetValue.getValues().add(dateTimeValue1);
    mixedSetValue = new SetValue();
    mixedSetValue.getValues().add(textValue1);
    mixedSetValue.getValues().add(dateTimeValue1);
    commaTextSetValue = new SetValue();
    commaTextSetValue.getValues().add(textValue1);
    commaTextSetValue.getValues().add(textValue4);
}
Also used : ColumnType(com.google.api.ads.admanager.jaxws.v202108.ColumnType) DateTimeValue(com.google.api.ads.admanager.jaxws.v202108.DateTimeValue) AdUnitTargeting(com.google.api.ads.admanager.jaxws.v202108.AdUnitTargeting) InventoryTargeting(com.google.api.ads.admanager.jaxws.v202108.InventoryTargeting) Targeting(com.google.api.ads.admanager.jaxws.v202108.Targeting) InventoryTargeting(com.google.api.ads.admanager.jaxws.v202108.InventoryTargeting) DateTime(com.google.api.ads.admanager.jaxws.v202108.DateTime) Date(com.google.api.ads.admanager.jaxws.v202108.Date) AdUnitTargeting(com.google.api.ads.admanager.jaxws.v202108.AdUnitTargeting) NumberValue(com.google.api.ads.admanager.jaxws.v202108.NumberValue) TextValue(com.google.api.ads.admanager.jaxws.v202108.TextValue) DateValue(com.google.api.ads.admanager.jaxws.v202108.DateValue) BooleanValue(com.google.api.ads.admanager.jaxws.v202108.BooleanValue) TargetingValue(com.google.api.ads.admanager.jaxws.v202108.TargetingValue) SetValue(com.google.api.ads.admanager.jaxws.v202108.SetValue) Before(org.junit.Before)

Example 13 with NumberValue

use of com.google.api.ads.admanager.jaxws.v202105.NumberValue in project googleads-java-lib by googleads.

the class PqlTest method testCreateValue_numberSet.

@Test
public void testCreateValue_numberSet() {
    Set<Long> numberSet = new LinkedHashSet<Long>();
    numberSet.add(1L);
    Value value1 = ((SetValue) Pql.createValue(numberSet)).getValues(0);
    assertEquals("1", ((NumberValue) value1).getValue());
}
Also used : LinkedHashSet(java.util.LinkedHashSet) DateValue(com.google.api.ads.admanager.axis.v202108.DateValue) TargetingValue(com.google.api.ads.admanager.axis.v202108.TargetingValue) DateTimeValue(com.google.api.ads.admanager.axis.v202108.DateTimeValue) BooleanValue(com.google.api.ads.admanager.axis.v202108.BooleanValue) TextValue(com.google.api.ads.admanager.axis.v202108.TextValue) Value(com.google.api.ads.admanager.axis.v202108.Value) SetValue(com.google.api.ads.admanager.axis.v202108.SetValue) NumberValue(com.google.api.ads.admanager.axis.v202108.NumberValue) SetValue(com.google.api.ads.admanager.axis.v202108.SetValue) Test(org.junit.Test)

Example 14 with NumberValue

use of com.google.api.ads.admanager.jaxws.v202105.NumberValue in project googleads-java-lib by googleads.

the class PqlTest method testCreateValue_numberSet.

@Test
public void testCreateValue_numberSet() {
    Set<Long> numberSet = new LinkedHashSet<Long>();
    numberSet.add(1L);
    Value value1 = ((SetValue) Pql.createValue(numberSet)).getValues().get(0);
    assertEquals("1", ((NumberValue) value1).getValue());
}
Also used : LinkedHashSet(java.util.LinkedHashSet) DateTimeValue(com.google.api.ads.admanager.jaxws.v202111.DateTimeValue) SetValue(com.google.api.ads.admanager.jaxws.v202111.SetValue) NumberValue(com.google.api.ads.admanager.jaxws.v202111.NumberValue) Value(com.google.api.ads.admanager.jaxws.v202111.Value) BooleanValue(com.google.api.ads.admanager.jaxws.v202111.BooleanValue) TextValue(com.google.api.ads.admanager.jaxws.v202111.TextValue) TargetingValue(com.google.api.ads.admanager.jaxws.v202111.TargetingValue) DateValue(com.google.api.ads.admanager.jaxws.v202111.DateValue) Test(org.junit.Test)

Example 15 with NumberValue

use of com.google.api.ads.admanager.jaxws.v202105.NumberValue in project googleads-java-lib by googleads.

the class PqlTest method setUp.

@Before
public void setUp() throws Exception {
    column1 = new ColumnType();
    column1.setLabelName("column1");
    column2 = new ColumnType();
    column2.setLabelName("column2");
    column3 = new ColumnType();
    column3.setLabelName("column3");
    textValue1 = new TextValue();
    textValue1.setValue("value1");
    textValue2 = new TextValue();
    textValue2.setValue("value2");
    textValue3 = new TextValue();
    textValue3.setValue("value3");
    textValue4 = new TextValue();
    textValue4.setValue("comma,separated");
    booleanValue1 = new BooleanValue();
    booleanValue1.setValue(false);
    booleanValue2 = new BooleanValue();
    booleanValue2.setValue(true);
    booleanValue3 = new BooleanValue();
    booleanValue3.setValue(false);
    numberValue1 = new NumberValue();
    numberValue1.setValue("1");
    numberValue2 = new NumberValue();
    numberValue2.setValue("1.02");
    numberValue3 = new NumberValue();
    numberValue3.setValue("-1");
    dateTime1 = new DateTime();
    date1 = new Date();
    date1.setYear(2012);
    date1.setMonth(12);
    date1.setDay(2);
    dateTime1.setDate(date1);
    dateTime1.setHour(12);
    dateTime1.setMinute(45);
    dateTime1.setSecond(0);
    dateTime1.setTimeZoneId(TIME_ZONE_ID1);
    dateTimeValue1 = new DateTimeValue();
    dateTimeValue1.setValue(dateTime1);
    dateValue1 = new DateValue();
    dateValue1.setValue(date1);
    AdUnitTargeting adUnitTargeting = new AdUnitTargeting();
    adUnitTargeting.setAdUnitId("100");
    InventoryTargeting inventoryTargeting = new InventoryTargeting();
    inventoryTargeting.getTargetedAdUnits().add(adUnitTargeting);
    targeting1 = new Targeting();
    targeting1.setInventoryTargeting(inventoryTargeting);
    targetingValue1 = new TargetingValue();
    targetingValue1.setValue(targeting1);
    numberSetValue = new SetValue();
    numberSetValue.getValues().add(numberValue1);
    numberSetValue.getValues().add(numberValue3);
    textSetValue = new SetValue();
    textSetValue.getValues().add(textValue1);
    textSetValue.getValues().add(textValue2);
    dateSetValue = new SetValue();
    dateSetValue.getValues().add(dateValue1);
    dateTimeSetValue = new SetValue();
    dateTimeSetValue.getValues().add(dateTimeValue1);
    mixedSetValue = new SetValue();
    mixedSetValue.getValues().add(textValue1);
    mixedSetValue.getValues().add(dateTimeValue1);
    commaTextSetValue = new SetValue();
    commaTextSetValue.getValues().add(textValue1);
    commaTextSetValue.getValues().add(textValue4);
}
Also used : ColumnType(com.google.api.ads.admanager.jaxws.v202202.ColumnType) DateTimeValue(com.google.api.ads.admanager.jaxws.v202202.DateTimeValue) AdUnitTargeting(com.google.api.ads.admanager.jaxws.v202202.AdUnitTargeting) Targeting(com.google.api.ads.admanager.jaxws.v202202.Targeting) InventoryTargeting(com.google.api.ads.admanager.jaxws.v202202.InventoryTargeting) InventoryTargeting(com.google.api.ads.admanager.jaxws.v202202.InventoryTargeting) DateTime(com.google.api.ads.admanager.jaxws.v202202.DateTime) Date(com.google.api.ads.admanager.jaxws.v202202.Date) AdUnitTargeting(com.google.api.ads.admanager.jaxws.v202202.AdUnitTargeting) NumberValue(com.google.api.ads.admanager.jaxws.v202202.NumberValue) TextValue(com.google.api.ads.admanager.jaxws.v202202.TextValue) DateValue(com.google.api.ads.admanager.jaxws.v202202.DateValue) BooleanValue(com.google.api.ads.admanager.jaxws.v202202.BooleanValue) TargetingValue(com.google.api.ads.admanager.jaxws.v202202.TargetingValue) SetValue(com.google.api.ads.admanager.jaxws.v202202.SetValue) Before(org.junit.Before)

Aggregations

LinkedHashSet (java.util.LinkedHashSet)24 ParseException (java.text.ParseException)8 Set (java.util.Set)8 Before (org.junit.Before)8 Test (org.junit.Test)8 NumberValue (com.google.api.ads.admanager.axis.v202108.NumberValue)5 NumberValue (com.google.api.ads.admanager.axis.v202111.NumberValue)5 NumberValue (com.google.api.ads.admanager.axis.v202202.NumberValue)5 BooleanValue (com.google.api.ads.admanager.axis.v202105.BooleanValue)4 DateTimeValue (com.google.api.ads.admanager.axis.v202105.DateTimeValue)4 DateValue (com.google.api.ads.admanager.axis.v202105.DateValue)4 NumberValue (com.google.api.ads.admanager.axis.v202105.NumberValue)4 SetValue (com.google.api.ads.admanager.axis.v202105.SetValue)4 TargetingValue (com.google.api.ads.admanager.axis.v202105.TargetingValue)4 TextValue (com.google.api.ads.admanager.axis.v202105.TextValue)4 BooleanValue (com.google.api.ads.admanager.axis.v202202.BooleanValue)4 DateTimeValue (com.google.api.ads.admanager.axis.v202202.DateTimeValue)4 DateValue (com.google.api.ads.admanager.axis.v202202.DateValue)4 SetValue (com.google.api.ads.admanager.axis.v202202.SetValue)4 TargetingValue (com.google.api.ads.admanager.axis.v202202.TargetingValue)4