public static void runExample( DfpServices dfpServices, DfpSession session, long advertiserCompanyId) throws Exception { // Get the ActivityGroupService. ActivityGroupServiceInterface activityGroupService = dfpServices.get(session, ActivityGroupServiceInterface.class); // Create a short-term activity group. ActivityGroup shortTermActivityGroup = new ActivityGroup(); shortTermActivityGroup.setName( "Short-term activity group #" + new Random().nextInt(Integer.MAX_VALUE)); shortTermActivityGroup.setCompanyIds(new long[] {advertiserCompanyId}); shortTermActivityGroup.setClicksLookback(1); shortTermActivityGroup.setImpressionsLookback(1); // Create a long-term activity group. ActivityGroup longTermActivityGroup = new ActivityGroup(); longTermActivityGroup.setName( "Long-term activity group #" + new Random().nextInt(Integer.MAX_VALUE)); longTermActivityGroup.setCompanyIds(new long[] {advertiserCompanyId}); longTermActivityGroup.setClicksLookback(30); longTermActivityGroup.setImpressionsLookback(30); // Create the activity groups on the server. ActivityGroup[] activityGroups = activityGroupService.createActivityGroups( new ActivityGroup[] {shortTermActivityGroup, longTermActivityGroup}); for (ActivityGroup createdActivityGroup : activityGroups) { System.out.printf( "An activity group with ID \"%d\" and name \"%s\" was created.\n", createdActivityGroup.getId(), createdActivityGroup.getName()); } }
public static void runExample(DfpServices dfpServices, DfpSession session) throws Exception { // Get the ActivityGroupService. ActivityGroupServiceInterface activityGroupService = dfpServices.get(session, ActivityGroupServiceInterface.class); // Create a statement to only select active activity groups. StatementBuilder statementBuilder = new StatementBuilder() .where("status = :status") .orderBy("id ASC") .limit(StatementBuilder.SUGGESTED_PAGE_LIMIT) .withBindVariableValue("status", ActivityGroupStatus.ACTIVE.toString()); // Default for total result set size. int totalResultSetSize = 0; do { // Get activity groups by statement. ActivityGroupPage page = activityGroupService.getActivityGroupsByStatement(statementBuilder.toStatement()); if (page.getResults() != null) { totalResultSetSize = page.getTotalResultSetSize(); int i = page.getStartIndex(); for (ActivityGroup activityGroup : page.getResults()) { System.out.printf( "%d) Activity group with ID \"%d\" and name \"%s\" was found.\n", i++, activityGroup.getId(), activityGroup.getName()); } } statementBuilder.increaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT); } while (statementBuilder.getOffset() < totalResultSetSize); System.out.printf("Number of results found: %d\n", totalResultSetSize); }