コード例 #1
0
  public List removeExpiredAssets(MediaArchive archive, String sourcepath, User inUser) {
    AssetSearcher searcher = archive.getAssetSearcher();
    SearchQuery q = searcher.createSearchQuery();
    HitTracker assets = null;
    if (sourcepath == null) {
      assets = searcher.getAllHits();
    } else {
      q.addStartsWith("sourcepath", sourcepath);
      assets = searcher.search(q);
    }
    List<String> removed = new ArrayList<String>();
    List<String> sourcepaths = new ArrayList<String>();

    for (Object obj : assets) {
      Data hit = (Data) obj;
      sourcepaths.add(hit.get("sourcepath")); // TODO: Move to using page of hits
      if (sourcepaths.size() > 250000) {
        log.error("Should not load up so many paths");
        break;
      }
    }
    for (String path : sourcepaths) {
      Asset asset = archive.getAssetBySourcePath(path);
      if (asset == null) {
        continue;
      }
      String assetsource = asset.getSourcePath();
      String pathToOriginal =
          "/WEB-INF/data" + archive.getCatalogHome() + "/originals/" + assetsource;
      if (asset.isFolder() && asset.getPrimaryFile() != null) {
        pathToOriginal = pathToOriginal + "/" + asset.getPrimaryFile();
      }
      Page page = getPageManager().getPage(pathToOriginal);
      if (!page.exists()) {
        removed.add(asset.getSourcePath());
        archive.removeGeneratedImages(asset);
        archive.getAssetSearcher().delete(asset, inUser);
      }
    }
    return removed;
  }