use of com.google.api.ads.adwords.axis.v201809.cm.Dimensions in project googleads-java-lib by googleads.
the class GetAllImagesAndVideos method runExample.
/**
* Runs the example.
*
* @param adWordsServices 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(AdWordsServicesInterface adWordsServices, AdWordsSession session) throws RemoteException {
// Get the MediaService.
MediaServiceInterface mediaService = adWordsServices.get(session, MediaServiceInterface.class);
int offset = 0;
// Create selector.
SelectorBuilder builder = new SelectorBuilder();
Selector selector = builder.fields(MediaField.MediaId, MediaField.Width, MediaField.Height, MediaField.MimeType).orderAscBy(MediaField.MediaId).offset(offset).limit(PAGE_SIZE).in(MediaField.Type, "IMAGE", "VIDEO").build();
MediaPage page = null;
do {
// Get all images.
page = mediaService.get(selector);
// Display images.
if (page != null && page.getEntries() != null) {
for (Media media : page.getEntries()) {
Map<MediaSize, Dimensions> dimensions = Maps.toMap(media.getDimensions());
System.out.printf("Media with ID %d, dimensions %s, and MIME type '%s' was found.%n", media.getMediaId(), toString(dimensions.get(MediaSize.FULL)), media.getMediaType());
}
} else {
System.out.println("No images/videos were found.");
}
offset += PAGE_SIZE;
selector = builder.increaseOffsetBy(PAGE_SIZE).build();
} while (offset < page.getTotalNumEntries());
}
use of com.google.api.ads.adwords.axis.v201809.cm.Dimensions in project googleads-java-lib by googleads.
the class ProductPartitionTreeImpl method addMutateOperations.
/**
* Adds to the operations list all operations required to mutate {@code originalNode} to the state
* of {@code newNode}.
*
* <p>The returned set of child product dimensions will only <em>potentially</em> be non-empty if
* both {@code originalNode != null} and {@code newNode != null}.
*
* @param originalNode may be null
* @param newNode may be null
* @param ops the operations list to add to
*
* @return the set of child product dimensions that require further processing
*/
private Set<ProductDimension> addMutateOperations(@Nullable ProductPartitionNode originalNode, @Nullable ProductPartitionNode newNode, List<OperationPair> ops) {
Set<ProductDimension> childDimensionsToProcess = Sets.newTreeSet(dimensionComparator);
NodeDifference nodeDifference = ProductPartitionNodeDiffer.diff(originalNode, newNode, dimensionComparator);
boolean isProcessChildren;
switch(nodeDifference) {
case NEW_NODE:
ops.addAll(createAddOperations(newNode));
// No need to further process children. The ADD operations above will include operations
// for all children of newNode.
isProcessChildren = false;
break;
case REMOVED_NODE:
ops.add(createRemoveOperation(originalNode));
// No need to further process children. The REMOVE operation above will perform a
// cascading delete of all children of newNode.
isProcessChildren = false;
break;
case PARTITION_TYPE_CHANGE:
case EXCLUDED_UNIT_CHANGE:
ops.add(createRemoveOperation(originalNode));
ops.addAll(createAddOperations(newNode));
// No need to further process children. The ADD operations above will include operations
// for all children of newNode.
isProcessChildren = false;
break;
case BIDDABLE_UNIT_CHANGE:
// Ensure that the new node has the proper ID (this may have been lost if the node
// was removed and then re-added).
newNode = newNode.setProductPartitionId(originalNode.getProductPartitionId());
ops.add(createSetBidOperation(newNode));
// Process the children of newNode. The SET operation above will only handle changes
// made to newNode, not its children.
isProcessChildren = true;
break;
case NONE:
// Ensure that the new node has the proper ID (this may have been lost if the node
// was removed and then re-added).
newNode = newNode.setProductPartitionId(originalNode.getProductPartitionId());
// This node does not have changes, but its children may.
isProcessChildren = true;
break;
default:
throw new IllegalStateException("Unrecognized difference: " + nodeDifference);
}
if (isProcessChildren) {
for (ProductPartitionNode childNode : Iterables.concat(originalNode.getChildren(), newNode.getChildren())) {
childDimensionsToProcess.add(childNode.getDimension());
}
}
return childDimensionsToProcess;
}
use of com.google.api.ads.adwords.axis.v201809.cm.Dimensions in project googleads-java-lib by googleads.
the class ProductPartitionTreeImpl method addMutateOperationsByParent.
/**
* Adds to the operations list all operations required to mutate the children of
* {@code originalParentNode} to {@code newParentNode}.
*
* @param originalParentNode required - must not be null
* @param newParentNode required - must not be null
* @param childDimensionsToProcess the child dimensions to process
* @param ops the operations list to add to
*/
private void addMutateOperationsByParent(ProductPartitionNode originalParentNode, ProductPartitionNode newParentNode, Set<ProductDimension> childDimensionsToProcess, List<OperationPair> ops) {
for (ProductDimension dimensionToProcess : childDimensionsToProcess) {
ProductPartitionNode originalChild = originalParentNode.hasChild(dimensionToProcess) ? originalParentNode.getChild(dimensionToProcess) : null;
ProductPartitionNode newChild = newParentNode.hasChild(dimensionToProcess) ? newParentNode.getChild(dimensionToProcess) : null;
Set<ProductDimension> grandchildDimensionsToProcess = addMutateOperations(originalChild, newChild, ops);
if (!grandchildDimensionsToProcess.isEmpty()) {
// Logic check - the only condition where further processing of children is required
// is when the parent exists in both trees. If the parent is null in one tree but
// not the other, then the node for dimensionToProcess was either:
// 1) removed from the original OR
// 2) added to the new tree
// In both cases, the call to addMutateOperations above will have already added all of the
// necessary operations to handle the node and all of its children.
Preconditions.checkState(originalChild != null, "Original child should not be null if there are children to process");
Preconditions.checkState(newChild != null, "New child should not be null if there are children to process");
addMutateOperationsByParent(originalChild, newChild, grandchildDimensionsToProcess, ops);
}
}
}
use of com.google.api.ads.adwords.axis.v201809.cm.Dimensions in project googleads-java-lib by googleads.
the class BaseProductDimensionComparatorTest method testCompareToDifferentDimensionType.
@Test
public void testCompareToDifferentDimensionType() {
ProductDimension dimension = createOtherProductDimension();
ProductDimension otherTypeOfDimension = dimension instanceof ProductBrand ? ProductDimensions.createOfferId("abc") : ProductDimensions.createBrand("google");
assertThat("Comparing dimensions of different types should return a non-zero result", comparator.compare(dimension, otherTypeOfDimension), Matchers.not(0));
assertThat("Comparing dimensions of different types should return a non-zero result", comparator.compare(otherTypeOfDimension, dimension), Matchers.not(0));
}
use of com.google.api.ads.adwords.axis.v201809.cm.Dimensions in project googleads-java-lib by googleads.
the class UploadImage method runExample.
/**
* Runs the example.
*
* @param adWordsServices 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.
* @throws IOException if unable to get media data from the URL.
*/
public static void runExample(AdWordsServicesInterface adWordsServices, AdWordsSession session) throws IOException {
// Get the MediaService.
MediaServiceInterface mediaService = adWordsServices.get(session, MediaServiceInterface.class);
// Create image.
Image image = new Image();
image.setData(com.google.api.ads.common.lib.utils.Media.getMediaDataFromUrl("https://goo.gl/3b9Wfh"));
image.setType(MediaMediaType.IMAGE);
Media[] media = new Media[] { image };
// Upload image.
Media[] result = mediaService.upload(media);
// Display images.
image = (Image) result[0];
Map<MediaSize, Dimensions> dimensions = Maps.toMap(image.getDimensions());
System.out.printf("Image with ID %d, dimensions %dx%d, and MIME type '%s' was " + "uploaded.%n", image.getMediaId(), dimensions.get(MediaSize.FULL).getWidth(), dimensions.get(MediaSize.FULL).getHeight(), image.getMediaType());
}
Aggregations