private static final String CREATIVE_ID = "INSERT_IN_STREAM_VIDEO_CREATIVE_ID_HERE";
public static void runExample(DfaServices dfaServices, DfaSession session, long creativeId)
throws Exception {
// Request the creative service from the service client factory.
CreativeRemote creativeService = dfaServices.get(session, CreativeRemote.class);
// Fetch the In-Stream video creative which contains the asset to modify.
CreativeBase rawCreative = creativeService.getCreative(creativeId);
if (!(rawCreative instanceof InStreamVideoCreative)) {
System.out.printf("Unable to update creative with ID \"%s\": not an In-Stream video "
+ "creative.", creativeId);
} else {
InStreamVideoCreative inStreamVideoCreative = (InStreamVideoCreative) rawCreative;
// Modify the media files, companion ads, and/or non-linear ads.
if (inStreamVideoCreative.getMediaFiles() != null) {
for (InStreamMediaFile mediaFile : inStreamVideoCreative.getMediaFiles()) {
mediaFile.setPickedToServe(!mediaFile.isPickedToServe());
}
}
if (inStreamVideoCreative.getCompanionAds() != null) {
for (InStreamCompanionAd companionAd : inStreamVideoCreative.getCompanionAds()) {
companionAd.setAltText(companionAd.getAltText() + " Updated.");
}
}
if (inStreamVideoCreative.getNonLinearAds() != null) {
for (InStreamNonLinearAd nonLinearAd : inStreamVideoCreative.getNonLinearAds()) {
nonLinearAd.setScalable(!nonLinearAd.isScalable());
}
}
CreativeSaveResult creativeSaveResult =
creativeService.saveCreative(inStreamVideoCreative, 0);
System.out.printf("Updated the In-Stream assets of In-Stream video creative with ID "
+ "\"%s\".%n", creativeSaveResult.getId());
}
}