Пример #1
0
  public View tempView(String id) {
    assertNotEmpty(id, "id");
    String viewPath = format("%s/%s/", TEMP_VIEWS_DIR, id);
    List<String> dirList = listResources(viewPath);
    assertNotEmpty(dirList, "Temp view directory");

    mapRedtempViewM = new MapReduce();
    for (String mapRed : dirList) {
      String def = readFile(format("/%s%s", viewPath, mapRed));
      if (MAP_JS.equals(mapRed)) mapRedtempViewM.setMap(def);
      else if (REDUCE_JS.equals(mapRed)) mapRedtempViewM.setReduce(def);
    }
    return this;
  }
Пример #2
0
  /**
   * Gets a design document from desk.
   *
   * @param id The document id to get.
   * @return {@link DesignDocument}
   */
  public DesignDocument getFromDesk(String id) {
    assertNotEmpty(id, "id");
    DesignDocument dd = new DesignDocument();
    String rootPath = format("%s/%s/", DESIGN_DOCS_DIR, id);
    List<String> elements = listResources(rootPath);
    if (elements == null) {
      throw new IllegalArgumentException("Design docs directory cannot be empty.");
    }

    if (elements.contains(VALIDATE_DOC)) { // validate_doc_update
      String validateDocPath = format("%s%s/", rootPath, VALIDATE_DOC);
      List<String> dirList = listResources(validateDocPath);
      for (String file : dirList) {
        String contents = readFile(format("/%s%s", validateDocPath, file));
        dd.setValidateDocUpdate(contents);
        break; // only one validate_doc_update file
      }
    } // /validate_doc_update
    Map<String, MapReduce> views = null;
    if (elements.contains(VIEWS)) { // views
      String viewsPath = format("%s%s/", rootPath, VIEWS);
      views = new HashMap<String, MapReduce>();
      for (String viewDirName : listResources(viewsPath)) { // views sub-dirs
        MapReduce mr = new MapReduce();
        String viewPath = format("%s%s/", viewsPath, viewDirName);
        List<String> dirList = listResources(viewPath);
        for (String fileName : dirList) { // view files
          String def = readFile(format("/%s%s", viewPath, fileName));
          if (MAP_JS.equals(fileName)) mr.setMap(def);
          else if (REDUCE_JS.equals(fileName)) mr.setReduce(def);
        } // /foreach view files
        views.put(viewDirName, mr);
      } // /foreach views sub-dirs
    } // /views
    dd.setId(DESIGN_PREFIX + id);
    dd.setLanguage(JAVASCRIPT);
    dd.setViews(views);
    dd.setFilters(populateMap(rootPath, elements, FILTERS));
    dd.setShows(populateMap(rootPath, elements, SHOWS));
    dd.setLists(populateMap(rootPath, elements, LISTS));
    dd.setUpdates(populateMap(rootPath, elements, UPDATES));
    return dd;
  }
Пример #3
0
 /**
  * Gets a design document from desk.
  *
  * @param id The document id to get.
  * @return {@link DesignDocument}
  */
 public DesignDocument getFromDesk(String id) {
   assertNotEmpty(id, "id");
   final DesignDocument dd = new DesignDocument();
   final String rootPath = format("%s/%s/", DESIGN_DOCS_DIR, id);
   final List<String> elements = listResources(rootPath);
   if (elements == null) {
     throw new IllegalArgumentException("Design docs directory cannot be empty.");
   }
   // Views
   Map<String, MapReduce> views = null;
   if (elements.contains(VIEWS)) {
     views = new HashMap<String, MapReduce>();
     final String viewsPath = format("%s%s/", rootPath, VIEWS);
     for (String viewDirName : listResources(viewsPath)) { // views sub-dirs
       final MapReduce mr = new MapReduce();
       final String viewPath = format("%s%s/", viewsPath, viewDirName);
       final List<String> dirList = listResources(viewPath);
       for (String fileName : dirList) { // view files
         final String def = readFile(format("/%s%s", viewPath, fileName));
         if (MAP_JS.equals(fileName)) mr.setMap(def);
         else if (REDUCE_JS.equals(fileName)) mr.setReduce(def);
       } // /foreach view files
       views.put(viewDirName, mr);
     } // /foreach views sub-dirs
   } // /views
   dd.setId(DESIGN_PREFIX + id);
   dd.setLanguage(JAVASCRIPT);
   dd.setViews(views);
   dd.setFilters(populateMap(rootPath, elements, FILTERS));
   dd.setShows(populateMap(rootPath, elements, SHOWS));
   dd.setLists(populateMap(rootPath, elements, LISTS));
   dd.setUpdates(populateMap(rootPath, elements, UPDATES));
   dd.setValidateDocUpdate(readContent(elements, rootPath, VALIDATE_DOC));
   dd.setRewrites(
       dbc.getGson().fromJson(readContent(elements, rootPath, REWRITES), JsonArray.class));
   dd.setFulltext(
       dbc.getGson().fromJson(readContent(elements, rootPath, FULLTEXT), JsonObject.class));
   dd.setIndexes(
       dbc.getGson().fromJson(readContent(elements, rootPath, INDEXES), JsonObject.class));
   return dd;
 }