protected Asset createAssetFromPage(MediaArchive inArchive, User inUser, Page inAssetPage) { Asset asset = getAssetUtilities().createAssetIfNeeded(inAssetPage.getContentItem(), inArchive, inUser); boolean existing = true; if (asset == null) { // Should never call this String originals = "/WEB-INF/data" + inArchive.getCatalogHome() + "/originals/"; String sourcepath = inAssetPage.getPath().substring(originals.length()); asset = inArchive.getAssetBySourcePath(sourcepath); return asset; } if (asset.get("recordmodificationdate") == null) { existing = false; } inArchive.saveAsset(asset, inUser); if (existing) { inArchive.fireMediaEvent("asset/originalmodified", inUser, asset); } else { inArchive.fireMediaEvent("asset/assetcreated", inUser, asset); } inArchive.fireMediaEvent("importing/assetsimported", inUser, asset); return asset; }
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; }