예제 #1
0
  /* (non-Javadoc)
   * @see ca.cmput301f13t03.adventure_datetime.model.IWebStorage#publishStory(ca.cmput301f13t03.adventure_datetime.model.Story, java.util.List)
   */
  @Override
  public boolean publishStory(Story story, List<StoryFragment> fragments) throws Exception {
    boolean succeeded;

    // I am not cleaning up old fragments because I am assuming we do not support
    // deleting fragments. If we do support that, then I will have to clean them up.
    Index index =
        new Index.Builder(story).index(_index).type("story").id(story.getId().toString()).build();
    JestResult result = execute(index);
    succeeded = result.isSucceeded();

    if (story.getThumbnail() != null) {
      succeeded &= putImage(story.getThumbnail());
    }

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

    if (fragments != null) {
      for (StoryFragment f : fragments) {
        f.updateMediaIds();
        bulkBuilder.addAction(new Index.Builder(f).id(f.getFragmentID().toString()).build());
      }

      result = execute(bulkBuilder.build());
      succeeded &= result.isSucceeded();

      for (StoryFragment f : fragments) {
        succeeded &= putImages(f.getStoryMedia());
      }
    }

    return succeeded;
  }
예제 #2
0
  private void mapImagesToFragment(StoryFragment fragment) throws Exception {
    if (fragment.getMediaIds() == null) return;

    List<Image> images = getImages(fragment.getMediaIds());
    fragment.setStoryMedia(new ArrayList<Image>(images));
  }