Search in sources :

Example 41 with LineItem

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

the class UpdateLineItems method runExample.

/**
 * Runs the example.
 *
 * @param adManagerServices the services factory.
 * @param session the session.
 * @param lineItemId the ID of the line item to update.
 * @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 lineItemId) throws RemoteException {
    // Get the LineItemService.
    LineItemServiceInterface lineItemService = adManagerServices.get(session, LineItemServiceInterface.class);
    // 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()));
    // Update the line item's priority to High if possible.
    if (lineItem.getLineItemType().equals(LineItemType.STANDARD)) {
        lineItem.setPriority(6);
        // Update the line item on the server.
        LineItem[] lineItems = lineItemService.updateLineItems(new LineItem[] { lineItem });
        for (LineItem updatedLineItem : lineItems) {
            System.out.printf("Line item with ID %d and name '%s' was updated.%n", updatedLineItem.getId(), updatedLineItem.getName());
        }
    } else {
        System.out.println("No line items were updated.");
    }
}
Also used : LineItemServiceInterface(com.google.api.ads.admanager.axis.v202205.LineItemServiceInterface) LineItemPage(com.google.api.ads.admanager.axis.v202205.LineItemPage) StatementBuilder(com.google.api.ads.admanager.axis.utils.v202205.StatementBuilder) LineItem(com.google.api.ads.admanager.axis.v202205.LineItem)

Example 42 with LineItem

use of com.google.api.ads.admanager.axis.v202205.LineItem in project xmlbeans by apache.

the class POReadOneJaxb2 method run.

private int run(CharArrayReader reader) throws Exception {
    // create the xml source from the reader
    StreamSource source = new StreamSource(reader);
    // unmarshall the xml instance
    JAXBContext context = JAXBContext.newInstance("org.openuri.easypo.jaxb2");
    Unmarshaller unmarshaller = context.createUnmarshaller();
    // depricated - unmarshaller.setValidating(false);
    PurchaseOrder po = (PurchaseOrder) unmarshaller.unmarshal(source);
    // retreive the first line item
    LineItem lineitem = (LineItem) po.getLineItem().get(0);
    // return the char length of the description
    return lineitem.getDescription().length();
}
Also used : StreamSource(javax.xml.transform.stream.StreamSource) PurchaseOrder(org.openuri.easypo.jaxb2.PurchaseOrder) LineItem(org.openuri.easypo.jaxb2.LineItem) JAXBContext(javax.xml.bind.JAXBContext) Unmarshaller(javax.xml.bind.Unmarshaller)

Example 43 with LineItem

use of com.google.api.ads.admanager.axis.v202205.LineItem in project xmlbeans by apache.

the class POTopDownSaveJaxb2 method run.

private int run() throws Exception {
    // create the purchase order
    PurchaseOrder po = new PurchaseOrder();
    // create and initialize the customer
    Customer customer = new Customer();
    customer.setName(Constants.PO_CUSTOMER_NAME);
    customer.setAddress(Constants.PO_CUSTOMER_ADDR);
    po.setCustomer(customer);
    // set the date
    // Date required in javax.xml.datatype.XMLGregorianCalendar format
    GregorianCalendar gdate = new GregorianCalendar();
    po.setDate(javax.xml.datatype.DatatypeFactory.newInstance().newXMLGregorianCalendar(Long.toString(gdate.getTimeInMillis())));
    // create and initialize the line item array
    for (int i = 0; i < Constants.PO_NUM_LINEITEMS; i++) {
        LineItem li = new LineItem();
        li.setDescription(Constants.PO_LI_DESC);
        li.setPerUnitOunces(Constants.PO_LI_PUO);
        li.setPrice(Constants.PO_LI_PRICE);
        li.setQuantity(Constants.PO_LI_QUANTITY);
        po.getLineItem().add(li);
    }
    // create and initialize the shipper
    Shipper shipper = new Shipper();
    shipper.setName(Constants.PO_SHIPPER_NAME);
    shipper.setPerOunceRate(Constants.PO_SHIPPER_POR);
    po.setShipper(shipper);
    // grab the instance that was constructed
    JAXBContext context = JAXBContext.newInstance("org.openuri.easypo.jaxb2");
    Marshaller marshaller = context.createMarshaller();
    StringWriter writer = new StringWriter();
    marshaller.marshal(po, writer);
    // calculate a hash to return
    int hash = (po.getLineItem().size()) * 17;
    return hash;
}
Also used : Marshaller(javax.xml.bind.Marshaller) StringWriter(java.io.StringWriter) Customer(org.openuri.easypo.jaxb2.Customer) GregorianCalendar(java.util.GregorianCalendar) Shipper(org.openuri.easypo.jaxb2.Shipper) PurchaseOrder(org.openuri.easypo.jaxb2.PurchaseOrder) LineItem(org.openuri.easypo.jaxb2.LineItem) JAXBContext(javax.xml.bind.JAXBContext)

Example 44 with LineItem

use of com.google.api.ads.admanager.axis.v202205.LineItem in project xmlbeans by apache.

the class POTopDownJaxb2 method run.

private int run() throws Exception {
    // create the purchase order
    PurchaseOrder po = new PurchaseOrder();
    // create and initialize the customer
    Customer customer = new Customer();
    customer.setName(Constants.PO_CUSTOMER_NAME);
    customer.setAddress(Constants.PO_CUSTOMER_ADDR);
    po.setCustomer(customer);
    // set the date
    // Date required in javax.xml.datatype.XMLGregorianCalendar format
    GregorianCalendar gdate = new GregorianCalendar();
    po.setDate(javax.xml.datatype.DatatypeFactory.newInstance().newXMLGregorianCalendar(Long.toString(gdate.getTimeInMillis())));
    // create and initialize the line item array
    for (int i = 0; i < Constants.PO_NUM_LINEITEMS; i++) {
        LineItem li = new LineItem();
        li.setDescription(Constants.PO_LI_DESC);
        li.setPerUnitOunces(Constants.PO_LI_PUO);
        li.setPrice(Constants.PO_LI_PRICE);
        li.setQuantity(Constants.PO_LI_QUANTITY);
        po.getLineItem().add(li);
    }
    // create and initialize the shipper
    Shipper shipper = new Shipper();
    shipper.setName(Constants.PO_SHIPPER_NAME);
    shipper.setPerOunceRate(Constants.PO_SHIPPER_POR);
    po.setShipper(shipper);
    // calculate a hash to return
    int hash = (po.getLineItem().size()) * 17;
    return hash;
}
Also used : Customer(org.openuri.easypo.jaxb2.Customer) GregorianCalendar(java.util.GregorianCalendar) Shipper(org.openuri.easypo.jaxb2.Shipper) PurchaseOrder(org.openuri.easypo.jaxb2.PurchaseOrder) LineItem(org.openuri.easypo.jaxb2.LineItem)

Aggregations

Random (java.util.Random)12 LineItem (com.google.api.ads.admanager.axis.v202108.LineItem)10 LineItem (com.google.api.ads.admanager.axis.v202111.LineItem)10 LineItem (com.google.api.ads.admanager.axis.v202202.LineItem)10 LineItem (com.google.api.ads.admanager.axis.v202205.LineItem)10 LineItemServiceInterface (com.google.api.ads.admanager.axis.v202108.LineItemServiceInterface)9 LineItemServiceInterface (com.google.api.ads.admanager.axis.v202111.LineItemServiceInterface)9 LineItemServiceInterface (com.google.api.ads.admanager.axis.v202202.LineItemServiceInterface)9 LineItemServiceInterface (com.google.api.ads.admanager.axis.v202205.LineItemServiceInterface)9 StatementBuilder (com.google.api.ads.admanager.axis.utils.v202108.StatementBuilder)6 StatementBuilder (com.google.api.ads.admanager.axis.utils.v202111.StatementBuilder)6 StatementBuilder (com.google.api.ads.admanager.axis.utils.v202202.StatementBuilder)6 StatementBuilder (com.google.api.ads.admanager.axis.utils.v202205.StatementBuilder)6 LineItemPage (com.google.api.ads.admanager.axis.v202108.LineItemPage)6 LineItemPage (com.google.api.ads.admanager.axis.v202111.LineItemPage)6 LineItemPage (com.google.api.ads.admanager.axis.v202202.LineItemPage)6 AdUnitTargeting (com.google.api.ads.admanager.axis.v202108.AdUnitTargeting)4 CreativePlaceholder (com.google.api.ads.admanager.axis.v202108.CreativePlaceholder)4 Goal (com.google.api.ads.admanager.axis.v202108.Goal)4 InventoryTargeting (com.google.api.ads.admanager.axis.v202108.InventoryTargeting)4