コード例 #1
0
  public List<CrawlableDataset> listDatasets(CrawlableDatasetFilter filter) throws IOException {
    if (filter == null) return this.listDatasets();

    if (!this.isCollection) throw new IllegalStateException("Dataset not a collection.");
    if (this.childrenList == null || this.childrenList.isEmpty()) return Collections.emptyList();

    List<CrawlableDataset> matchingChildren = new ArrayList<CrawlableDataset>();
    for (CrawlableDataset curCrDs : this.childrenList) {
      if (filter.accept(curCrDs)) matchingChildren.add(curCrDs);
    }
    return matchingChildren;
  }
コード例 #2
0
  /** Test ... */
  public void testOne() {
    createFiles();

    // ******** DO TEST STUFF **********
    /*
     <filter logicalComp="OR">
       <!-- Only grib1 files that are older than 60 seconds -->
       <filter logicalComp="AND">
         <filter>
           <include wildcard="*.grib1"/>
         </filter>
         <filter lastModifiedLimit="60000"  />
       </filter>
       <!-- Only nc files that are less then 60 seconds old -->
       <filter logicalComp="AND">
         <filter>
           <include wildcard="*.nc"/>
         </filter>
         <filter logicalComp="NOT">
           <filter lastModifiedLimit="60000"/>
         </filter>
       </filter>
     </filter>
    */
    CrawlableDatasetFilter includeGribFilter =
        new MultiSelectorFilter(
            new MultiSelectorFilter.Selector(
                new WildcardMatchOnNameFilter("*.grib1"), true, true, false));
    CrawlableDatasetFilter lastModAtLeast4MinPastFilter = new LastModifiedLimitFilter(240000);
    CrawlableDatasetFilter oldGribFilter =
        LogicalFilterComposer.getAndFilter(includeGribFilter, lastModAtLeast4MinPastFilter);

    CrawlableDatasetFilter includeNcFilter =
        new MultiSelectorFilter(
            new MultiSelectorFilter.Selector(
                new WildcardMatchOnNameFilter("*.nc"), true, true, false));
    CrawlableDatasetFilter newNcFilter =
        LogicalFilterComposer.getAndFilter(
            includeNcFilter, LogicalFilterComposer.getNotFilter(lastModAtLeast4MinPastFilter));

    CrawlableDatasetFilter oldGribOrNewNcFilter =
        LogicalFilterComposer.getOrFilter(oldGribFilter, newNcFilter);

    CrawlableDataset tmpDirCrDs = new CrawlableDatasetFile(tmpDir);
    List crDsList = null;
    try {
      crDsList = tmpDirCrDs.listDatasets();
    } catch (IOException e) {
      assertTrue("I/O problem getting contained dataset list.", false);
      deleteFiles();
      return;
    }
    for (Iterator it = crDsList.iterator(); it.hasNext(); ) {
      CrawlableDataset curCrDs = (CrawlableDataset) it.next();
      if (oldGribOrNewNcFilter.accept(curCrDs)) {
        if (!curCrDs.getName().equals("old.grib1") && !curCrDs.getName().equals("new.nc")) {
          assertTrue("Matched wrong file <" + curCrDs.getPath() + ">.", false);
          deleteFiles();
          return;
        }
      }
    }

    // ******** DO TEST STUFF - END **********
    deleteFiles();
  }