/**
   * @param inArchive
   * @param inAssetID
   * @throws StoreException
   */
  protected void deleteAsset(MediaArchive inArchive, String inAssetID) {
    // String id = findAssetId(tabs[5],tabs[4],catName);

    Asset product = inArchive.getAsset(inAssetID);
    if (product == null) {
      inArchive.getAssetSearcher().deleteFromIndex(inAssetID); // Just in case index is out of date
    } else {
      String sourcePath = product.getSourcePath();
      Page thumb = inArchive.getCreatorManager().getThumbImageFile(sourcePath);
      Page medium = inArchive.getCreatorManager().getMediumImageFile(sourcePath);
      getPageManager().removePage(thumb);
      getPageManager().removePage(medium);

      inArchive.getAssetSearcher().deleteFromIndex(inAssetID);
      inArchive.getAssetArchive().deleteAsset(product);
      inArchive.getAssetArchive().clearAsset(product);
    }
  }
  protected void processDeleteLog(File inLog, MediaArchive inArchive, ConvertStatus inStatus)
      throws FileNotFoundException, IOException, Exception {
    BufferedReader reader = new BufferedReader(new FileReader(inLog));
    try {
      String line = reader.readLine();
      int count = 0;
      while (line != null) {
        String[] tabs = line.split("\t");
        if (tabs.length > 3) {
          if ("Record deleted".equals(tabs[3])) {
            String catName = inLog.getName();
            if (catName.indexOf('-') != -1) {
              catName = catName.substring(0, catName.indexOf('-'));
            } else if (catName.indexOf('.') != -1) {
              catName = catName.substring(0, catName.lastIndexOf('.'));
            }
            String recordId = tabs[4];
            String cumulusid = catName + "_" + recordId; // /createCumulusID(catName, recordId);

            // catName = extractId(catName);
            // Category root =
            // inArchive.getStore().getCatalogArchive().getRootCatalog().getChildByName(catName);
            SearchQuery query = inArchive.getAssetSearcher().createSearchQuery();
            query.addExact("cumulusid", cumulusid);
            HitTracker hits = inArchive.getAssetSearcher().search(query);
            if (hits.getTotal() > 0) {
              count++;
              String id = hits.get(0).get("id");
              deleteAsset(inArchive, id);
            } else {
              log.debug("No record found " + catName + "dash" + recordId);
            }
          }
        }
        line = reader.readLine();
      }
      if (count > 0) {
        inArchive.getAssetSearcher().flush();
        logMessage(inStatus, "Removed " + count + " records");
      }
    } finally {
      FileUtils.safeClose(reader);
    }
  }
Exemplo n.º 3
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;
  }