private static final String AD_UNIT_ID = "INSERT_AD_UNIT_ID_HERE";
public static void runExample(
DfpServices dfpServices, DfpSession session, long teamId, String adUnitId) throws Exception {
// Get the TeamService.
TeamServiceInterface teamService =
dfpServices.get(session, TeamServiceInterface.class);
// Get the team.
Team team = teamService.getTeam(teamId);
// Don't add ad unit if the team has all inventory already.
if (!team.getHasAllInventory()) {
List<String> adUnitIds = Lists.newArrayList();
if (team.getAdUnitIds() != null) {
Collections.addAll(adUnitIds, team.getAdUnitIds());
}
adUnitIds.add(adUnitId);
team.setAdUnitIds(adUnitIds.toArray(new String[] {}));
// Update the team on the server.
Team[] teams = teamService.updateTeams(new Team[] {team});
for (Team updatedTeam : teams) {
System.out.printf("Team with ID \"%d\" and name \"%s\" was updated.\n", updatedTeam.getId(),
updatedTeam.getName());
}