Beispiel #1
0
 public static void addImages(Described content, String anImage) {
   if (!Strings.isNullOrEmpty(anImage)) {
     Matcher matcher = IMAGE_PATTERN.matcher(anImage);
     if (matcher.matches()) {
       content.setThumbnail(matcher.group(1) + THUMBNAIL_SIZE + matcher.group(2));
       content.setImage((matcher.group(1) + IMAGE_SIZE + matcher.group(2)));
     }
   }
 }
Beispiel #2
0
  private void setPublishStatusOfItem(
      Optional<String> id, Optional<String> uri, Optional<String> publisher, boolean status) {
    // if we cannot resolve the ID we want a notfound exception
    LookupEntry lookupEntry = getLookupEntry(id, uri);

    Optional<Identified> identified = resolveContent(lookupEntry);
    Described described = validatePublisher(publisher, identified);

    removeItemFromEquivSet(status, lookupEntry);
    described.setActivelyPublished(status);
    writeUpdate(described);
  }
Beispiel #3
0
 private Described validatePublisher(Optional<String> publisher, Optional<Identified> identified) {
   Described described = (Described) identified.get();
   publisher.ifPresent(
       key -> {
         if (!key.equals(described.getPublisher().key())) {
           throw new RuntimeException(
               (String.format(
                   "Described %d is not published by '%s'", described.getId(), publisher)));
         }
       });
   return described;
 }
 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());
 }
  /**
   * 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));
      }
    }
  }
Beispiel #6
0
  private void writeUpdate(Described described) {
    if (described instanceof Item) {
      contentWriter.createOrUpdate((Item) described);
      return;
    }

    if (described instanceof Container) {
      contentWriter.createOrUpdate((Container) described);
      return;
    }

    throw new IllegalStateException(
        (String.format("Described %d is not Item/Container", described.getId())));
  }