Search in sources :

Example 56 with NumberValue

use of com.google.api.ads.admanager.jaxws.v202205.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 : BaseCustomFieldValue(com.google.api.ads.admanager.axis.v202205.BaseCustomFieldValue) DropDownCustomFieldValue(com.google.api.ads.admanager.axis.v202205.DropDownCustomFieldValue) CustomFieldValue(com.google.api.ads.admanager.axis.v202205.CustomFieldValue) DropDownCustomFieldValue(com.google.api.ads.admanager.axis.v202205.DropDownCustomFieldValue) BaseCustomFieldValue(com.google.api.ads.admanager.axis.v202205.BaseCustomFieldValue) LineItemServiceInterface(com.google.api.ads.admanager.axis.v202205.LineItemServiceInterface) CustomFieldServiceInterface(com.google.api.ads.admanager.axis.v202205.CustomFieldServiceInterface) ArrayList(java.util.ArrayList) LineItem(com.google.api.ads.admanager.axis.v202205.LineItem) NumberValue(com.google.api.ads.admanager.axis.v202205.NumberValue) LineItemPage(com.google.api.ads.admanager.axis.v202205.LineItemPage) StatementBuilder(com.google.api.ads.admanager.axis.utils.v202205.StatementBuilder)

Example 57 with NumberValue

use of com.google.api.ads.admanager.jaxws.v202205.NumberValue in project osate2 by osate.

the class InterpreterUtil method max.

public static NumberValue max(Collection<NumberValue> nvals) {
    Iterator<NumberValue> it = nvals.iterator();
    NumberValue result = it.next();
    while (it.hasNext()) {
        NumberValue nv = it.next();
        if (compareTo(nv, result) > 0) {
            result = nv;
        }
    }
    return result;
}
Also used : NumberValue(org.osate.aadl2.NumberValue)

Example 58 with NumberValue

use of com.google.api.ads.admanager.jaxws.v202205.NumberValue in project osate2 by osate.

the class InterpreterUtil method min.

public static NumberValue min(Collection<NumberValue> nvals) {
    Iterator<NumberValue> it = nvals.iterator();
    NumberValue result = it.next();
    while (it.hasNext()) {
        NumberValue nv = it.next();
        if (compareTo(nv, result) < 0) {
            result = nv;
        }
    }
    return result;
}
Also used : NumberValue(org.osate.aadl2.NumberValue)

Example 59 with NumberValue

use of com.google.api.ads.admanager.jaxws.v202205.NumberValue in project osate2 by osate.

the class PropertyUtils method getMinRangeValue.

/**
 * Extract minimum range value from a specified property. May return null.
 *
 * @param i
 *            component instance.
 * @param propertyName
 *            property name.
 * @return property value.
 */
public static NumberValue getMinRangeValue(NamedElement i, String propertyName) {
    PropertyAssociation pa = findPropertyAssociation(propertyName, i);
    if (pa != null) {
        Property p = pa.getProperty();
        if (p.getName().equalsIgnoreCase(propertyName)) {
            List<ModalPropertyValue> values = pa.getOwnedValues();
            if (values.size() == 1) {
                ModalPropertyValue v = values.get(0);
                PropertyExpression expr = v.getOwnedValue();
                if (expr instanceof RangeValue) {
                    NumberValue n = ((RangeValue) expr).getMinimumValue();
                    return n;
                } else if (expr instanceof NumberValue) {
                    return (NumberValue) expr;
                }
            }
        }
    }
    return null;
}
Also used : ModalPropertyValue(org.osate.aadl2.ModalPropertyValue) NumberValue(org.osate.aadl2.NumberValue) PropertyAssociation(org.osate.aadl2.PropertyAssociation) BasicPropertyAssociation(org.osate.aadl2.BasicPropertyAssociation) PropertyExpression(org.osate.aadl2.PropertyExpression) BasicProperty(org.osate.aadl2.BasicProperty) Property(org.osate.aadl2.Property) RangeValue(org.osate.aadl2.RangeValue)

Example 60 with NumberValue

use of com.google.api.ads.admanager.jaxws.v202205.NumberValue in project osate2 by osate.

the class AadlBaTypeChecker method integerValueConstantToArrayDimension.

private ArrayDimension integerValueConstantToArrayDimension(IntegerValueConstant ivc) {
    ArrayDimension result = Aadl2Factory.eINSTANCE.createArrayDimension();
    ArraySize size = result.createSize();
    result.setSize(size);
    result.setLocationReference(ivc.getLocationReference());
    size.setLocationReference(ivc.getLocationReference());
    if (ivc instanceof BehaviorIntegerLiteral) {
        size.setSize(((BehaviorIntegerLiteral) ivc).getValue());
    } else if (ivc instanceof BehaviorPropertyConstant) {
        PropertyExpression pe = null;
        PropertyConstant pc = ((BehaviorPropertyConstant) ivc).getProperty();
        pe = pc.getConstantValue();
        if (pe instanceof NumberValue) {
            double value = ((NumberValue) pe).getScaledValue();
            size.setSize((long) value);
        } else {
            String msg = "cannot evaluate the property constant";
            _errManager.warning(ivc, msg);
        }
    } else if (ivc instanceof PropertyReference) {
        PropertyReference pr = (PropertyReference) ivc;
        PropertyNameHolder last = pr.getProperties().get(pr.getProperties().size() - 1);
        Element el = last.getProperty().getElement();
        if (el instanceof NumberValue) {
            double value = ((NumberValue) el).getScaledValue();
            size.setSize((long) value);
        } else {
            String msg = "cannot evaluate the property value";
            _errManager.warning(ivc, msg);
        }
    } else {
        String errorMsg = "integerValueConstantToArrayDimension : " + ivc.getClass().getSimpleName() + " is not supported yet.";
        System.err.println(errorMsg);
        throw new UnsupportedOperationException(errorMsg);
    }
    return result;
}
Also used : Element(org.osate.aadl2.Element) QualifiedNamedElement(org.osate.ba.declarative.QualifiedNamedElement) DeclarativeBehaviorElement(org.osate.ba.declarative.DeclarativeBehaviorElement) NamedElement(org.osate.aadl2.NamedElement) PropertyConstant(org.osate.aadl2.PropertyConstant) DeclarativePropertyReference(org.osate.ba.declarative.DeclarativePropertyReference) NumberValue(org.osate.aadl2.NumberValue) ArraySize(org.osate.aadl2.ArraySize) PropertyExpression(org.osate.aadl2.PropertyExpression) ArrayDimension(org.osate.aadl2.ArrayDimension) DeclarativeArrayDimension(org.osate.ba.declarative.DeclarativeArrayDimension)

Aggregations

LinkedHashSet (java.util.LinkedHashSet)30 NumberValue (org.osate.aadl2.NumberValue)24 RangeValue (org.osate.aadl2.RangeValue)13 PropertyExpression (org.osate.aadl2.PropertyExpression)12 ParseException (java.text.ParseException)10 Set (java.util.Set)10 Before (org.junit.Before)10 Test (org.junit.Test)10 RecordValue (org.osate.aadl2.RecordValue)6 NumberValue (com.google.api.ads.admanager.axis.v202108.NumberValue)5 NumberValue (com.google.api.ads.admanager.axis.v202111.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 BooleanValue (com.google.api.ads.admanager.jaxws.v202205.BooleanValue)4