private void setPrimaryImage(Described described, Image image, PictureUsage picture) {
   image.setType(ImageType.PRIMARY);
   // The image URL is set to the "legacy" URL of http://images.../pa/image.jpg since there
   // are external dependencies on it. The new image block moves to the new URL scheme of
   // http://images.../pressassociation.com/image.jpg
   described.setImage(IMAGE_URL_BASE + picture.getvalue());
 }
  private Image createImage(PictureUsage pictureUsage) {
    String imageUri = IMAGE_URL_BASE + pictureUsage.getvalue();
    Image image = new Image(imageUri);

    image.setHeight(576);
    image.setWidth(1024);
    image.setType(ImageType.ADDITIONAL);
    image.setAspectRatio(ImageAspectRatio.SIXTEEN_BY_NINE);
    image.setMimeType(MimeType.IMAGE_JPG);
    image.setAvailabilityStart(fromPaDate(pictureUsage.getStartDate()));
    DateTime expiry = fromPaDate(pictureUsage.getExpiryDate());
    if (expiry != null) {
      image.setAvailabilityEnd(expiry.plusDays(1));
    } else {
      image.setAvailabilityEnd(null);
    }
    return image;
  }
  /**
   * If pictures is not null, add a list of images of the given primary type to the described
   * object. If no images of the primary type are found, fall back to the first, or optional second
   * type. Only one (the first) fallback image will be used. Ordering is preserved for images. If
   * pictures is null, this method does nothing.
   *
   * @param pictures The picture collection to use
   * @param described The object that will have images added
   * @param primaryImageType The primary image type to add
   * @param firstFallbackType The preferred fallback image type to add
   * @param secondFallbackType The optional fallback image type to add
   */
  void selectImages(
      Pictures pictures,
      Described described,
      String primaryImageType,
      String firstFallbackType,
      Maybe<String> secondFallbackType) {
    if (pictures != null) {
      Set<Image> images = Sets.newLinkedHashSet();
      Image fallbackImage = null;
      boolean hasFirstFallbackType = false;

      for (PictureUsage picture : pictures.getPictureUsage()) {
        Image image = createImage(picture);

        if (secondFallbackType.hasValue()
            && picture.getType().equals(secondFallbackType.requireValue())
            && images.isEmpty()
            && fallbackImage == null) {
          setPrimaryImage(described, image, picture);
          fallbackImage = image;
        }
        if (picture.getType().equals(firstFallbackType)
            && images.isEmpty()
            && !hasFirstFallbackType) {
          setPrimaryImage(described, image, picture);
          fallbackImage = image;
          hasFirstFallbackType = true;
        }
        if (picture.getType().equals(primaryImageType)) {
          if (images.size() == 0) {
            setPrimaryImage(described, image, picture);
          }
          images.add(image);
        }
      }

      if (!images.isEmpty()) {
        described.setImages(images);
      } else if (fallbackImage != null) {
        described.setImages(ImmutableSet.of(fallbackImage));
      }
    }
  }