if (contentBrowseCustomTargetingKeyId == 0) {
throw new RuntimeException("Your network does not have content categories enabled.");
}
// Create a statement to select the categories matching the name comedy.
Statement categoryFilterStatement = new StatementBuilder()
.where("customTargetingKeyId = :contentBrowseCustomTargetingKeyId and name = :category")
.limit(1)
.withBindVariableValue(
"contentBrowseCustomTargetingKeyId", contentBrowseCustomTargetingKeyId)
.withBindVariableValue("category", "comedy").toStatement();
// Get categories matching the filter statement.
CustomTargetingValuePage customTargetingValuePage =
customTargetingService.getCustomTargetingValuesByStatement(categoryFilterStatement);
// Get the custom targeting value ID for the comedy category.
long categoryCustomTargetingValueId = customTargetingValuePage.getResults()[0].getId();
// Create a statement to select all content.
StatementBuilder statementBuilder = new StatementBuilder()
.orderBy("id ASC")
.limit(StatementBuilder.SUGGESTED_PAGE_LIMIT);
// Default for total result set size.
int totalResultSetSize = 0;
do {
// Get content by statement.
ContentPage page = contentService.getContentByStatementAndCustomTargetingValue(
statementBuilder.toStatement(), categoryCustomTargetingValueId);
if (page.getResults() != null) {
totalResultSetSize = page.getTotalResultSetSize();
int i = page.getStartIndex();
for (Content content : page.getResults()) {
System.out.printf(
"%d) Content with ID \"%d\" and name \"%s\" was found.\n", i++,
content.getId(), content.getName());
}
}
statementBuilder.increaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
} while (statementBuilder.getOffset() < totalResultSetSize);
System.out.printf("Number of results found: %d\n", totalResultSetSize);
}