Search in sources :

Example 31 with DateTime

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

the class Pql method createValue.

/**
 * Creates a {@link Value} from the value i.e. a {@link TextValue} for a value of type {@code
 * String}, {@link BooleanValue} for type {@code Boolean}, {@link NumberValue} for type {@code
 * Double}, {@code Long}, or {@code Integer}, and {@link DateTimeValue} for type {@link DateTime}.
 * If the value is a {@code Value}, the value is returned. If the value is {@code null}, an empty
 * {@link TextValue} is returned.
 *
 * @param value the value to convert
 * @return the constructed value of the appropriate type
 * @throws IllegalArgumentException if value cannot be converted
 */
public static Value createValue(Object value) {
    if (value instanceof Value) {
        return (Value) value;
    } else if (value == null) {
        return new TextValue();
    } else {
        if (value instanceof Boolean) {
            BooleanValue booleanValue = new BooleanValue();
            booleanValue.setValue((Boolean) value);
            return booleanValue;
        } else if (value instanceof Double || value instanceof Long || value instanceof Integer) {
            NumberValue numberValue = new NumberValue();
            numberValue.setValue(value.toString());
            return numberValue;
        } else if (value instanceof String) {
            TextValue textValue = new TextValue();
            textValue.setValue((String) value);
            return textValue;
        } else if (value instanceof DateTime) {
            DateTimeValue dateTimeValue = new DateTimeValue();
            dateTimeValue.setValue((DateTime) value);
            return dateTimeValue;
        } else if (value instanceof Date) {
            DateValue dateValue = new DateValue();
            dateValue.setValue((Date) value);
            return dateValue;
        } else if (value instanceof Targeting) {
            TargetingValue targetingValue = new TargetingValue();
            targetingValue.setValue((Targeting) value);
            return targetingValue;
        } else if (value instanceof Set<?>) {
            SetValue setValue = new SetValue();
            Set<Value> values = new LinkedHashSet<Value>();
            for (Object entry : (Set<?>) value) {
                validateSetValueEntryForSet(createValue(entry), values);
                values.add(createValue(entry));
            }
            setValue.getValues().addAll(values);
            return setValue;
        } else {
            throw new IllegalArgumentException("Unsupported Value type [" + value.getClass() + "]");
        }
    }
}
Also used : Set(java.util.Set) ResultSet(com.google.api.ads.admanager.jaxws.v202111.ResultSet) LinkedHashSet(java.util.LinkedHashSet) DateTimeValue(com.google.api.ads.admanager.jaxws.v202111.DateTimeValue) Targeting(com.google.api.ads.admanager.jaxws.v202111.Targeting) DateTime(com.google.api.ads.admanager.jaxws.v202111.DateTime) Date(com.google.api.ads.admanager.jaxws.v202111.Date) NumberValue(com.google.api.ads.admanager.jaxws.v202111.NumberValue) TextValue(com.google.api.ads.admanager.jaxws.v202111.TextValue) DateValue(com.google.api.ads.admanager.jaxws.v202111.DateValue) BooleanValue(com.google.api.ads.admanager.jaxws.v202111.BooleanValue) DateTimeValue(com.google.api.ads.admanager.jaxws.v202111.DateTimeValue) TextValue(com.google.api.ads.admanager.jaxws.v202111.TextValue) SetValue(com.google.api.ads.admanager.jaxws.v202111.SetValue) NumberValue(com.google.api.ads.admanager.jaxws.v202111.NumberValue) TargetingValue(com.google.api.ads.admanager.jaxws.v202111.TargetingValue) Value(com.google.api.ads.admanager.jaxws.v202111.Value) BooleanValue(com.google.api.ads.admanager.jaxws.v202111.BooleanValue) DateValue(com.google.api.ads.admanager.jaxws.v202111.DateValue) TargetingValue(com.google.api.ads.admanager.jaxws.v202111.TargetingValue) SetValue(com.google.api.ads.admanager.jaxws.v202111.SetValue)

Example 32 with DateTime

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

the class Pql method createValue.

/**
 * Creates a {@link Value} from the value i.e. a {@link TextValue} for a value of type {@code
 * String}, {@link BooleanValue} for type {@code Boolean}, {@link NumberValue} for type {@code
 * Double}, {@code Long}, or {@code Integer}, and {@link DateTimeValue} for type {@link DateTime}.
 * If the value is a {@code Value}, the value is returned. If the value is {@code null}, an empty
 * {@link TextValue} is returned.
 *
 * @param value the value to convert
 * @return the constructed value of the appropriate type
 * @throws IllegalArgumentException if value cannot be converted
 */
public static Value createValue(Object value) {
    if (value instanceof Value) {
        return (Value) value;
    } else if (value == null) {
        return new TextValue();
    } else {
        if (value instanceof Boolean) {
            BooleanValue booleanValue = new BooleanValue();
            booleanValue.setValue((Boolean) value);
            return booleanValue;
        } else if (value instanceof Double || value instanceof Long || value instanceof Integer) {
            NumberValue numberValue = new NumberValue();
            numberValue.setValue(value.toString());
            return numberValue;
        } else if (value instanceof String) {
            TextValue textValue = new TextValue();
            textValue.setValue((String) value);
            return textValue;
        } else if (value instanceof DateTime) {
            DateTimeValue dateTimeValue = new DateTimeValue();
            dateTimeValue.setValue((DateTime) value);
            return dateTimeValue;
        } else if (value instanceof Date) {
            DateValue dateValue = new DateValue();
            dateValue.setValue((Date) value);
            return dateValue;
        } else if (value instanceof Targeting) {
            TargetingValue targetingValue = new TargetingValue();
            targetingValue.setValue((Targeting) value);
            return targetingValue;
        } else if (value instanceof Set<?>) {
            SetValue setValue = new SetValue();
            Set<Value> values = new LinkedHashSet<Value>();
            for (Object entry : (Set<?>) value) {
                validateSetValueEntryForSet(createValue(entry), values);
                values.add(createValue(entry));
            }
            setValue.getValues().addAll(values);
            return setValue;
        } else {
            throw new IllegalArgumentException("Unsupported Value type [" + value.getClass() + "]");
        }
    }
}
Also used : Set(java.util.Set) ResultSet(com.google.api.ads.admanager.jaxws.v202202.ResultSet) LinkedHashSet(java.util.LinkedHashSet) DateTimeValue(com.google.api.ads.admanager.jaxws.v202202.DateTimeValue) Targeting(com.google.api.ads.admanager.jaxws.v202202.Targeting) DateTime(com.google.api.ads.admanager.jaxws.v202202.DateTime) Date(com.google.api.ads.admanager.jaxws.v202202.Date) 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) SetValue(com.google.api.ads.admanager.jaxws.v202202.SetValue) DateValue(com.google.api.ads.admanager.jaxws.v202202.DateValue) TextValue(com.google.api.ads.admanager.jaxws.v202202.TextValue) BooleanValue(com.google.api.ads.admanager.jaxws.v202202.BooleanValue) DateTimeValue(com.google.api.ads.admanager.jaxws.v202202.DateTimeValue) NumberValue(com.google.api.ads.admanager.jaxws.v202202.NumberValue) Value(com.google.api.ads.admanager.jaxws.v202202.Value) TargetingValue(com.google.api.ads.admanager.jaxws.v202202.TargetingValue) TargetingValue(com.google.api.ads.admanager.jaxws.v202202.TargetingValue) SetValue(com.google.api.ads.admanager.jaxws.v202202.SetValue)

Example 33 with DateTime

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

the class Pql method getApiValue.

/**
 * Gets the underlying value of the {@code Value} object that's comparable to what would be
 * returned in any other API object (i.e. DateTimeValue will return an API DateTime, not a Joda
 * DateTime).
 *
 * @param value the value to convert
 * @return the native value of {@code Value} or {@code null} if the underlying value is null
 * @throws IllegalArgumentException if value cannot be converted
 */
public static Object getApiValue(Value value) {
    if (value instanceof BooleanValue) {
        return ((BooleanValue) value).isValue();
    } else if (value instanceof NumberValue) {
        if (((NumberValue) value).getValue() == null) {
            return null;
        } else {
            try {
                return NumberFormat.getInstance().parse(((NumberValue) value).getValue());
            } catch (ParseException e) {
                throw new IllegalStateException("Received invalid number format from API: " + ((NumberValue) value).getValue());
            }
        }
    } else if (value instanceof TextValue) {
        return ((TextValue) value).getValue();
    } else if (value instanceof DateTimeValue) {
        return ((DateTimeValue) value).getValue();
    } else if (value instanceof DateValue) {
        return ((DateValue) value).getValue();
    } else if (value instanceof TargetingValue) {
        return ((TargetingValue) value).getValue();
    } else if (value instanceof SetValue) {
        List<Value> setValues = ((SetValue) value).getValues();
        Set<Object> apiValue = new LinkedHashSet<Object>();
        if (setValues != null) {
            for (Value setValue : setValues) {
                validateSetValueEntryForSet(getApiValue(setValue), apiValue);
                apiValue.add(getApiValue(setValue));
            }
        }
        return apiValue;
    } else {
        throw new IllegalArgumentException("Unsupported Value type [" + value.getClass() + "]");
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) DateTimeValue(com.google.api.ads.admanager.jaxws.v202205.DateTimeValue) NumberValue(com.google.api.ads.admanager.jaxws.v202205.NumberValue) TextValue(com.google.api.ads.admanager.jaxws.v202205.TextValue) DateValue(com.google.api.ads.admanager.jaxws.v202205.DateValue) BooleanValue(com.google.api.ads.admanager.jaxws.v202205.BooleanValue) SetValue(com.google.api.ads.admanager.jaxws.v202205.SetValue) TextValue(com.google.api.ads.admanager.jaxws.v202205.TextValue) NumberValue(com.google.api.ads.admanager.jaxws.v202205.NumberValue) Value(com.google.api.ads.admanager.jaxws.v202205.Value) TargetingValue(com.google.api.ads.admanager.jaxws.v202205.TargetingValue) BooleanValue(com.google.api.ads.admanager.jaxws.v202205.BooleanValue) DateValue(com.google.api.ads.admanager.jaxws.v202205.DateValue) DateTimeValue(com.google.api.ads.admanager.jaxws.v202205.DateTimeValue) ParseException(java.text.ParseException) TargetingValue(com.google.api.ads.admanager.jaxws.v202205.TargetingValue) SetValue(com.google.api.ads.admanager.jaxws.v202205.SetValue)

Example 34 with DateTime

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

the class Pql method createValue.

/**
 * Creates a {@link Value} from the value i.e. a {@link TextValue} for a value of type {@code
 * String}, {@link BooleanValue} for type {@code Boolean}, {@link NumberValue} for type {@code
 * Double}, {@code Long}, or {@code Integer}, and {@link DateTimeValue} for type {@link DateTime}.
 * If the value is a {@code Value}, the value is returned. If the value is {@code null}, an empty
 * {@link TextValue} is returned.
 *
 * @param value the value to convert
 * @return the constructed value of the appropriate type
 * @throws IllegalArgumentException if value cannot be converted
 */
public static Value createValue(Object value) {
    if (value instanceof Value) {
        return (Value) value;
    } else if (value == null) {
        return new TextValue();
    } else {
        if (value instanceof Boolean) {
            BooleanValue booleanValue = new BooleanValue();
            booleanValue.setValue((Boolean) value);
            return booleanValue;
        } else if (value instanceof Double || value instanceof Long || value instanceof Integer) {
            NumberValue numberValue = new NumberValue();
            numberValue.setValue(value.toString());
            return numberValue;
        } else if (value instanceof String) {
            TextValue textValue = new TextValue();
            textValue.setValue((String) value);
            return textValue;
        } else if (value instanceof DateTime) {
            DateTimeValue dateTimeValue = new DateTimeValue();
            dateTimeValue.setValue((DateTime) value);
            return dateTimeValue;
        } else if (value instanceof Date) {
            DateValue dateValue = new DateValue();
            dateValue.setValue((Date) value);
            return dateValue;
        } else if (value instanceof Targeting) {
            TargetingValue targetingValue = new TargetingValue();
            targetingValue.setValue((Targeting) value);
            return targetingValue;
        } else if (value instanceof Set<?>) {
            SetValue setValue = new SetValue();
            Set<Value> values = new LinkedHashSet<Value>();
            for (Object entry : (Set<?>) value) {
                validateSetValueEntryForSet(createValue(entry), values);
                values.add(createValue(entry));
            }
            setValue.getValues().addAll(values);
            return setValue;
        } else {
            throw new IllegalArgumentException("Unsupported Value type [" + value.getClass() + "]");
        }
    }
}
Also used : Set(java.util.Set) ResultSet(com.google.api.ads.admanager.jaxws.v202205.ResultSet) LinkedHashSet(java.util.LinkedHashSet) DateTimeValue(com.google.api.ads.admanager.jaxws.v202205.DateTimeValue) Targeting(com.google.api.ads.admanager.jaxws.v202205.Targeting) DateTime(com.google.api.ads.admanager.jaxws.v202205.DateTime) Date(com.google.api.ads.admanager.jaxws.v202205.Date) NumberValue(com.google.api.ads.admanager.jaxws.v202205.NumberValue) TextValue(com.google.api.ads.admanager.jaxws.v202205.TextValue) DateValue(com.google.api.ads.admanager.jaxws.v202205.DateValue) BooleanValue(com.google.api.ads.admanager.jaxws.v202205.BooleanValue) SetValue(com.google.api.ads.admanager.jaxws.v202205.SetValue) TextValue(com.google.api.ads.admanager.jaxws.v202205.TextValue) NumberValue(com.google.api.ads.admanager.jaxws.v202205.NumberValue) Value(com.google.api.ads.admanager.jaxws.v202205.Value) TargetingValue(com.google.api.ads.admanager.jaxws.v202205.TargetingValue) BooleanValue(com.google.api.ads.admanager.jaxws.v202205.BooleanValue) DateValue(com.google.api.ads.admanager.jaxws.v202205.DateValue) DateTimeValue(com.google.api.ads.admanager.jaxws.v202205.DateTimeValue) TargetingValue(com.google.api.ads.admanager.jaxws.v202205.TargetingValue) SetValue(com.google.api.ads.admanager.jaxws.v202205.SetValue)

Example 35 with DateTime

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

the class PqlTest method testCreateValue_dateTimeSet.

@Test
public void testCreateValue_dateTimeSet() {
    Set<DateTime> dateTimeSet = new LinkedHashSet<DateTime>();
    dateTimeSet.add(dateTime1);
    Value value1 = ((SetValue) Pql.createValue(dateTimeSet)).getValues(0);
    assertEquals("2012-12-02T12:45:00+08:00", DateTimes.toStringWithTimeZone(((DateTimeValue) value1).getValue()));
}
Also used : LinkedHashSet(java.util.LinkedHashSet) DateTimeValue(com.google.api.ads.admanager.axis.v202111.DateTimeValue) DateTimeValue(com.google.api.ads.admanager.axis.v202111.DateTimeValue) TextValue(com.google.api.ads.admanager.axis.v202111.TextValue) Value(com.google.api.ads.admanager.axis.v202111.Value) NumberValue(com.google.api.ads.admanager.axis.v202111.NumberValue) TargetingValue(com.google.api.ads.admanager.axis.v202111.TargetingValue) BooleanValue(com.google.api.ads.admanager.axis.v202111.BooleanValue) DateValue(com.google.api.ads.admanager.axis.v202111.DateValue) SetValue(com.google.api.ads.admanager.axis.v202111.SetValue) SetValue(com.google.api.ads.admanager.axis.v202111.SetValue) DateTime(com.google.api.ads.admanager.axis.v202111.DateTime) Test(org.junit.Test)

Aggregations

LinkedHashSet (java.util.LinkedHashSet)21 Set (java.util.Set)10 Before (org.junit.Before)10 Test (org.junit.Test)10 BooleanValue (com.google.api.ads.admanager.jaxws.v202205.BooleanValue)4 DateTimeValue (com.google.api.ads.admanager.jaxws.v202205.DateTimeValue)4 DateValue (com.google.api.ads.admanager.jaxws.v202205.DateValue)4 NumberValue (com.google.api.ads.admanager.jaxws.v202205.NumberValue)4 SetValue (com.google.api.ads.admanager.jaxws.v202205.SetValue)4 TargetingValue (com.google.api.ads.admanager.jaxws.v202205.TargetingValue)4 TextValue (com.google.api.ads.admanager.jaxws.v202205.TextValue)4 org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Bigint (org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Bigint)4 org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Binary (org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Binary)4 org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Blob (org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Blob)4 org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Boolean (org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Boolean)4 org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Char (org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Char)4 org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Clob (org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Clob)4 org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Date (org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Date)4 org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Datetime (org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Datetime)4 org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Decimal (org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Decimal)4