private static final String USER_ID = "INSERT_USER_ID_HERE";
public static void runExample(DfpServices dfpServices, DfpSession session, long userId)
throws Exception {
// Get the UserTeamAssociationService.
UserTeamAssociationServiceInterface userTeamAssociationService =
dfpServices.get(session, UserTeamAssociationServiceInterface.class);
// Create a statement to get all user team associations for a user.
StatementBuilder statementBuilder = new StatementBuilder()
.where("WHERE userId = :userId ")
.orderBy("userId ASC, teamid ASC")
.limit(StatementBuilder.SUGGESTED_PAGE_LIMIT)
.withBindVariableValue("userId", userId);
// Default for total result set size.
int totalResultSetSize = 0;
do {
// Get user team associations by statement.
UserTeamAssociationPage page = userTeamAssociationService.getUserTeamAssociationsByStatement(
statementBuilder.toStatement());
if (page.getResults() != null) {
totalResultSetSize = page.getTotalResultSetSize();
int i = page.getStartIndex();
for (UserTeamAssociation userTeamAssociation : page.getResults()) {
System.out.printf("%d) User team association with user ID \"%d\" and "
+ "team ID \"%d\" will be deleted.\n", i++, userTeamAssociation.getUserId(),
userTeamAssociation.getTeamId());
}
}
statementBuilder.increaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
} while (statementBuilder.getOffset() < totalResultSetSize);
System.out.printf("Number of user team associations to be deleted: %d\n", totalResultSetSize);
if (totalResultSetSize > 0) {
// Remove limit and offset from statement.
statementBuilder.removeLimitAndOffset();
// Create action.
com.google.api.ads.dfp.axis.v201308.DeleteUserTeamAssociations action =
new com.google.api.ads.dfp.axis.v201308.DeleteUserTeamAssociations();
// Perform action.
UpdateResult result = userTeamAssociationService.performUserTeamAssociationAction(
action, statementBuilder.toStatement());
if (result != null && result.getNumChanges() > 0) {
System.out.printf("Number of user team associations deleted: %d\n",
result.getNumChanges());