Пример #1
0
  /* (non-Javadoc)
   * @see ca.cmput301f13t03.adventure_datetime.model.IWebStorage#getStory(java.util.UUID)
   */
  @Override
  public Story getStory(UUID storyId) throws Exception {
    Get get = new Get.Builder(_index, storyId.toString()).type("story").build();
    JestResult result = execute(get);
    Story story = result.getSourceAsObject(Story.class);

    Image image = getImage(storyId);
    if (image != null) story.setThumbnail(image.getEncodedBitmap());

    return story;
  }
Пример #2
0
  private boolean putImages(List<Image> images) throws Exception {
    if (images == null) return true;

    Bulk.Builder bulkBuilder = new Bulk.Builder().defaultIndex(_index).defaultType("image");

    for (Image i : images) {
      bulkBuilder.addAction(new Index.Builder(i).id(i.getId().toString()).build());
    }

    JestResult result = execute(bulkBuilder.build());
    return result.isSucceeded();
  }
Пример #3
0
 /* (non-Javadoc)
  * @see ca.cmput301f13t03.adventure_datetime.model.IWebStorage#putImage(ca.cmput301f13t03.adventure_datetime.model.Image)
  */
 @Override
 public boolean putImage(Image image) throws Exception {
   Index index =
       new Index.Builder(image).index(_index).type("image").id(image.getId().toString()).build();
   JestResult result = execute(index);
   return result.isSucceeded();
 }
Пример #4
0
  private void mapImagesToComments(List<Comment> comments) throws Exception {
    if (comments == null || comments.size() == 0) return;

    // Get the thumbnails
    List<UUID> ids = new ArrayList<UUID>();
    for (Comment c : comments) {
      ids.add(c.getId());
    }

    List<Image> images = getImages(ids);

    for (Image i : images) {
      for (Comment c : comments) {
        if (c.getId().equals(i.getId())) {
          c.setImage(i.getEncodedBitmap());
          break;
        }
      }
    }
  }
Пример #5
0
  private void mapImagesToStories(List<Story> stories) throws Exception {
    if (stories == null || stories.size() == 0) return;

    // Get the thumbnails
    List<UUID> ids = new ArrayList<UUID>();
    for (Story s : stories) {
      ids.add(s.getId());
    }

    List<Image> images = getImages(ids);

    for (Image i : images) {
      for (Story s : stories) {
        if (s.getId().equals(i.getId())) {
          s.setThumbnail(i.getEncodedBitmap());
          break;
        }
      }
    }
  }