use of com.google.api.ads.admanager.axis.v202108.Team in project googleads-java-lib by googleads.
the class GetAllUserTeamAssociations method runExample.
/**
* Runs the example.
*
* @param adManagerServices the services factory.
* @param session the session.
* @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) throws RemoteException {
// Get the UserTeamAssociationService.
UserTeamAssociationServiceInterface userTeamAssociationService = adManagerServices.get(session, UserTeamAssociationServiceInterface.class);
// Create a statement to select all user team associations.
StatementBuilder statementBuilder = new StatementBuilder().orderBy("teamId ASC, userId ASC").limit(StatementBuilder.SUGGESTED_PAGE_LIMIT);
// 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 associations with team ID %d and user ID %d was found.%n", i++, userTeamAssociation.getTeamId(), userTeamAssociation.getUserId());
}
}
statementBuilder.increaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
} while (statementBuilder.getOffset() < totalResultSetSize);
System.out.printf("Number of results found: %d%n", totalResultSetSize);
}
use of com.google.api.ads.admanager.axis.v202108.Team in project googleads-java-lib by googleads.
the class UpdateUserTeamAssociations method runExample.
/**
* Runs the example.
*
* @param adManagerServices the services factory.
* @param session the session.
* @param userId the user ID of the user team association to update.
* @param teamId the team ID of the user team association 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 userId, long teamId) throws RemoteException {
// Get the UserTeamAssociationService.
UserTeamAssociationServiceInterface userTeamAssociationService = adManagerServices.get(session, UserTeamAssociationServiceInterface.class);
// Create a statement to only select a single user team association by ID.
StatementBuilder statementBuilder = new StatementBuilder().where("userId = :userId AND teamId = :teamId").orderBy("userId, teamId ASC").limit(1).withBindVariableValue("userId", userId).withBindVariableValue("teamId", teamId);
// Get the user team association.
UserTeamAssociationPage page = userTeamAssociationService.getUserTeamAssociationsByStatement(statementBuilder.toStatement());
UserTeamAssociation userTeamAssociation = Iterables.getOnlyElement(Arrays.asList(page.getResults()));
// Update the user's access type on the team.
userTeamAssociation.setOverriddenTeamAccessType(TeamAccessType.READ_ONLY);
// Update the user team associations on the server.
UserTeamAssociation[] userTeamAssociations = userTeamAssociationService.updateUserTeamAssociations(new UserTeamAssociation[] { userTeamAssociation });
for (UserTeamAssociation updatedUserTeamAssociation : userTeamAssociations) {
System.out.printf("User team association with user ID %d and team ID %d was updated.%n", updatedUserTeamAssociation.getUserId(), updatedUserTeamAssociation.getTeamId());
}
}
use of com.google.api.ads.admanager.axis.v202108.Team in project googleads-java-lib by googleads.
the class CreateTeams method runExample.
/**
* Runs the example.
*
* @param adManagerServices the services factory.
* @param session the session.
* @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) throws RemoteException {
// Get the TeamService.
TeamServiceInterface teamService = adManagerServices.get(session, TeamServiceInterface.class);
// Create a read/write team.
Team readWriteTeam = new Team();
readWriteTeam.setName("Read/write team #" + new Random().nextInt(Integer.MAX_VALUE));
readWriteTeam.setTeamAccessType(TeamAccessType.READ_WRITE);
readWriteTeam.setHasAllCompanies(false);
readWriteTeam.setHasAllInventory(false);
// Create a read-only team.
Team readOnlyTeam = new Team();
readOnlyTeam.setName("Read-only team #" + new Random().nextInt(Integer.MAX_VALUE));
readOnlyTeam.setTeamAccessType(TeamAccessType.READ_ONLY);
readOnlyTeam.setHasAllCompanies(false);
readOnlyTeam.setHasAllInventory(false);
// Create the teams on the server.
Team[] teams = teamService.createTeams(new Team[] { readWriteTeam, readOnlyTeam });
for (Team createdTeam : teams) {
System.out.printf("A team with ID %d and name '%s' was created.%n", createdTeam.getId(), createdTeam.getName());
}
}
use of com.google.api.ads.admanager.axis.v202108.Team in project googleads-java-lib by googleads.
the class GetAllTeams method runExample.
/**
* Runs the example.
*
* @param adManagerServices the services factory.
* @param session the session.
* @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) throws RemoteException {
// Get the TeamService.
TeamServiceInterface teamService = adManagerServices.get(session, TeamServiceInterface.class);
// Create a statement to select all teams.
StatementBuilder statementBuilder = new StatementBuilder().orderBy("id ASC").limit(StatementBuilder.SUGGESTED_PAGE_LIMIT);
// Default for total result set size.
int totalResultSetSize = 0;
do {
// Get teams by statement.
TeamPage page = teamService.getTeamsByStatement(statementBuilder.toStatement());
if (page.getResults() != null) {
totalResultSetSize = page.getTotalResultSetSize();
int i = page.getStartIndex();
for (Team team : page.getResults()) {
System.out.printf("%d) Team with ID %d and name '%s' was found.%n", i++, team.getId(), team.getName());
}
}
statementBuilder.increaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
} while (statementBuilder.getOffset() < totalResultSetSize);
System.out.printf("Number of results found: %d%n", totalResultSetSize);
}
Aggregations