Search in sources :

Example 1 with Statement

use of com.google.api.ads.admanager.axis.v202111.Statement in project open-kilda by telstra.

the class NeoDriver method getPath.

/**
 * {@inheritDoc}
 */
@Override
public ImmutablePair<PathInfoData, PathInfoData> getPath(Flow flow, Strategy strategy) throws UnroutablePathException {
    long latency = 0L;
    List<PathNode> forwardNodes = new LinkedList<>();
    List<PathNode> reverseNodes = new LinkedList<>();
    if (!flow.isOneSwitchFlow()) {
        Statement statement = getPathQuery(flow, strategy);
        logger.debug("QUERY: {}", statement.toString());
        try (Session session = driver.session()) {
            StatementResult result = session.run(statement);
            try {
                Record record = result.next();
                LinkedList<Relationship> isls = new LinkedList<>();
                record.get(0).asPath().relationships().forEach(isls::add);
                int seqId = 0;
                for (Relationship isl : isls) {
                    latency += isl.get("latency").asLong();
                    forwardNodes.add(new PathNode(isl.get("src_switch").asString(), isl.get("src_port").asInt(), seqId, isl.get("latency").asLong()));
                    seqId++;
                    forwardNodes.add(new PathNode(isl.get("dst_switch").asString(), isl.get("dst_port").asInt(), seqId, 0L));
                    seqId++;
                }
                seqId = 0;
                Collections.reverse(isls);
                for (Relationship isl : isls) {
                    reverseNodes.add(new PathNode(isl.get("dst_switch").asString(), isl.get("dst_port").asInt(), seqId, isl.get("latency").asLong()));
                    seqId++;
                    reverseNodes.add(new PathNode(isl.get("src_switch").asString(), isl.get("src_port").asInt(), seqId, 0L));
                    seqId++;
                }
            } catch (NoSuchRecordException e) {
                throw new UnroutablePathException(flow);
            }
        }
    } else {
        logger.info("No path computation for one-switch flow");
    }
    return new ImmutablePair<>(new PathInfoData(latency, forwardNodes), new PathInfoData(latency, reverseNodes));
}
Also used : StatementResult(org.neo4j.driver.v1.StatementResult) Statement(org.neo4j.driver.v1.Statement) PathNode(org.openkilda.messaging.info.event.PathNode) PathInfoData(org.openkilda.messaging.info.event.PathInfoData) ImmutablePair(org.openkilda.messaging.model.ImmutablePair) Relationship(org.neo4j.driver.v1.types.Relationship) Record(org.neo4j.driver.v1.Record) NoSuchRecordException(org.neo4j.driver.v1.exceptions.NoSuchRecordException) Session(org.neo4j.driver.v1.Session)

Example 2 with Statement

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

the class StatementBuilderTest method testLimitOffsetDefaults.

@Test
public void testLimitOffsetDefaults() {
    StatementBuilder statementBuilder = new StatementBuilder();
    Statement initialOffset = statementBuilder.limit(100).toStatement();
    assertEquals("LIMIT 100", initialOffset.getQuery());
    Statement increasedOffset = statementBuilder.increaseOffsetBy(100).toStatement();
    assertEquals("LIMIT 100 OFFSET 100", increasedOffset.getQuery());
}
Also used : Statement(com.google.api.ads.admanager.axis.v202111.Statement) Test(org.junit.Test)

Example 3 with Statement

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

the class StatementBuilderTest method testFrom_stripsFrom.

@Test
public void testFrom_stripsFrom() {
    StatementBuilder statementBuilder = new StatementBuilder();
    Statement statement = statementBuilder.from("FROM line_item").toStatement();
    assertEquals("FROM line_item", statement.getQuery());
}
Also used : Statement(com.google.api.ads.admanager.axis.v202111.Statement) Test(org.junit.Test)

Example 4 with Statement

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

the class GetMarketplaceComments method runExample.

/**
 * Runs the example.
 *
 * @param adManagerServices the services factory.
 * @param session the session.
 * @param proposalId the proposal ID.
 * @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 proposalId) throws RemoteException {
    ProposalServiceInterface proposalService = adManagerServices.get(session, ProposalServiceInterface.class);
    // Create a statement to select marketplace comments.
    StatementBuilder statementBuilder = new StatementBuilder().where("proposalId = :proposalId").withBindVariableValue("proposalId", proposalId);
    MarketplaceCommentPage page = proposalService.getMarketplaceCommentsByStatement(statementBuilder.toStatement());
    if (page.getResults() != null) {
        // Print out some information for each marketplace comment.
        int i = page.getStartIndex();
        for (MarketplaceComment marketplaceComment : page.getResults()) {
            System.out.printf("%d) Marketplace comment with creation time '%s' and comment '%s' was found.%n", i++, DateTimes.toString(marketplaceComment.getCreationTime()), marketplaceComment.getComment());
        }
    } else {
        System.out.println("No marketplace comments found.");
    }
}
Also used : MarketplaceCommentPage(com.google.api.ads.admanager.axis.v202111.MarketplaceCommentPage) ProposalServiceInterface(com.google.api.ads.admanager.axis.v202111.ProposalServiceInterface) StatementBuilder(com.google.api.ads.admanager.axis.utils.v202111.StatementBuilder) MarketplaceComment(com.google.api.ads.admanager.axis.v202111.MarketplaceComment)

Example 5 with Statement

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

the class RequestBuyerAcceptance method runExample.

/**
 * Runs the example.
 *
 * @param adManagerServices the services factory.
 * @param session the session.
 * @param proposalId the proposal ID to send.
 * @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 proposalId) throws RemoteException {
    // Get the ProposalService.
    ProposalServiceInterface proposalService = adManagerServices.get(session, ProposalServiceInterface.class);
    // Create a statement to only select a single proposal by ID.
    StatementBuilder statementBuilder = new StatementBuilder().where("WHERE id = :id").orderBy("id ASC").limit(StatementBuilder.SUGGESTED_PAGE_LIMIT).withBindVariableValue("id", proposalId);
    // Retrieve a small amount of proposals at a time, paging through until all
    // proposals have been retrieved.
    int totalResultSetSize = 0;
    do {
        ProposalPage page = proposalService.getProposalsByStatement(statementBuilder.toStatement());
        if (page.getResults() != null) {
            // Print out some information for each proposal.
            totalResultSetSize = page.getTotalResultSetSize();
            int i = page.getStartIndex();
            for (Proposal proposal : page.getResults()) {
                System.out.printf("%d) Proposal with ID %d and name '%s' will be sent to Marketplace for buyer " + "acceptance.%n", i++, proposal.getId(), proposal.getName());
            }
        }
        statementBuilder.increaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
    } while (statementBuilder.getOffset() < totalResultSetSize);
    System.out.printf("Number of proposals to be sent to Marketplace for buyer acceptance: %d%n", totalResultSetSize);
    if (totalResultSetSize > 0) {
        // Remove limit and offset from statement.
        statementBuilder.removeLimitAndOffset();
        // Create action.
        com.google.api.ads.admanager.axis.v202111.RequestBuyerAcceptance action = new com.google.api.ads.admanager.axis.v202111.RequestBuyerAcceptance();
        // Perform action.
        UpdateResult result = proposalService.performProposalAction(action, statementBuilder.toStatement());
        if (result != null && result.getNumChanges() > 0) {
            System.out.printf("Number of proposals that were sent to Marketplace for buyer acceptance: %d%n", result.getNumChanges());
        } else {
            System.out.println("No proposals were sent to Marketplace for buyer acceptance.");
        }
    }
}
Also used : ProposalServiceInterface(com.google.api.ads.admanager.axis.v202111.ProposalServiceInterface) ProposalPage(com.google.api.ads.admanager.axis.v202111.ProposalPage) StatementBuilder(com.google.api.ads.admanager.axis.utils.v202111.StatementBuilder) Proposal(com.google.api.ads.admanager.axis.v202111.Proposal) UpdateResult(com.google.api.ads.admanager.axis.v202111.UpdateResult)

Aggregations

StatementBuilder (com.google.api.ads.admanager.axis.utils.v202111.StatementBuilder)119 Test (org.junit.Test)61 UpdateResult (com.google.api.ads.admanager.axis.v202111.UpdateResult)18 Statement (com.google.api.ads.admanager.axis.v202105.Statement)16 Statement (com.google.api.ads.admanager.axis.v202108.Statement)16 Statement (com.google.api.ads.admanager.axis.v202111.Statement)16 Statement (com.google.api.ads.admanager.axis.v202202.Statement)16 CustomTargetingServiceInterface (com.google.api.ads.admanager.axis.v202111.CustomTargetingServiceInterface)8 InventoryServiceInterface (com.google.api.ads.admanager.axis.v202111.InventoryServiceInterface)8 AdUnit (com.google.api.ads.admanager.axis.v202111.AdUnit)7 AdUnitPage (com.google.api.ads.admanager.axis.v202111.AdUnitPage)7 PublisherQueryLanguageServiceInterface (com.google.api.ads.admanager.axis.v202111.PublisherQueryLanguageServiceInterface)7 ResultSet (com.google.api.ads.admanager.axis.v202111.ResultSet)7 ArrayList (java.util.ArrayList)6 ProposalServiceInterface (com.google.api.ads.admanager.axis.v202111.ProposalServiceInterface)5 String_ValueMapEntry (com.google.api.ads.admanager.axis.v202105.String_ValueMapEntry)4 String_ValueMapEntry (com.google.api.ads.admanager.axis.v202108.String_ValueMapEntry)4 AdjustmentServiceInterface (com.google.api.ads.admanager.axis.v202111.AdjustmentServiceInterface)4 LineItem (com.google.api.ads.admanager.axis.v202111.LineItem)4 LineItemPage (com.google.api.ads.admanager.axis.v202111.LineItemPage)4