Ejemplo n.º 1
0
  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 Boolean canViewAsset(WebPageRequest inReq) {
   //		String orderid = inReq.getRequestParameter("orderid");
   //		if (orderid == null)
   //		{
   //			return false;
   //		}
   Order order = loadOrder(inReq);
   if (order == null) {
     order = (Order) inReq.getSessionValue("vieworder");
   }
   if (order == null) {
     return false;
   }
   Asset asset = getAsset(inReq);
   if (asset == null) {
     log.info("Asset not found");
     return false;
   }
   String catalogid = inReq.findValue("catalogid");
   HitTracker assets = getOrderManager().findOrderItems(inReq, catalogid, order);
   int found = assets.findRow("assetid", asset.getId());
   if (found > -1 && !order.isExpired()) {
     return true;
   }
   return false;
 }
  /**
   * @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);
    }
  }
 public void filterOrderItems(WebPageRequest req) {
   ArrayList<String> list = new ArrayList<String>(); // add omitted orders to a list
   String publishtype = req.getRequestParameter("publishdestination.value");
   String catalogid = req.findValue("catalogid");
   HitTracker items = (HitTracker) req.getPageValue("orderitems");
   if (items == null) {
     Order order = loadOrder(req);
     if (order != null) {
       String orderid = order.getId();
       if (orderid == null) {
         orderid = req.getRequestParameter("orderid");
       }
       items = getOrderManager().findOrderItems(req, catalogid, order);
     }
   }
   if (items != null) {
     // get searchers
     Searcher publishdestsearcher =
         getMediaArchive(req).getSearcherManager().getSearcher(catalogid, "publishdestination");
     Data publisher = (Data) publishdestsearcher.searchById(publishtype);
     String publishername = publisher.getName();
     Searcher convertpresetsearcher =
         getMediaArchive(req).getSearcherManager().getSearcher(catalogid, "convertpreset");
     // see if convertpreset has the appropriate field
     String publishtofield = "publishto" + publishername.replace(" ", "").toLowerCase();
     if (convertpresetsearcher.getDetail(publishtofield) != null) // field is present
     {
       for (int i = 0; i < items.size(); i++) {
         Data data = items.get(i);
         Asset asset = getMediaArchive(req).getAsset(data.get("assetid"));
         String fileformat = asset.get("fileformat");
         String rendertype = getMediaArchive(req).getMediaRenderType(fileformat);
         // build query
         SearchQuery presetquery = convertpresetsearcher.createSearchQuery();
         presetquery.append(publishtofield, "true").append("inputtype", rendertype);
         // execute query
         HitTracker hits = convertpresetsearcher.search(presetquery);
         if (hits.size() > 0) continue;
         list.add(asset.getId());
       }
     }
   }
   req.putPageValue("invaliditems", list); // process this in step2
 }
  public boolean checkItemApproval(WebPageRequest inReq) throws Exception {

    if (inReq.getUser() == null) {
      return false;
    }
    MediaArchive archive = getMediaArchive(inReq);

    // Searcher ordersearcher =
    // archive.getSearcherManager().getSearcher(archive.getCatalogId(),
    // "order");
    // SearchQuery search = ordersearcinKeyher.createSearchQuery();
    // search.addExact("userid", inReq.getUser().getId());
    // search.addExact("orderstatus", "processed");
    // search.addSortBy("date");
    // HitTracker hits = ordersearcher.search(search);
    // look for the most recent order for an approved asset
    Asset asset = (Asset) inReq.getPageValue("asset");
    String sourcepath = null;
    if (asset != null) {
      sourcepath = asset.getSourcePath();
    } else {
      sourcepath = archive.getSourcePathForPage(inReq);
    }
    if (sourcepath == null) {
      return false;
    }
    Searcher itemsearcher =
        archive.getSearcherManager().getSearcher(archive.getCatalogId(), "orderitem");
    SearchQuery search = itemsearcher.createSearchQuery();
    search.addExact("userid", inReq.getUser().getId());
    search.addExact("assetsourcepath", sourcepath);
    search.addMatches("status", "approved");
    HitTracker results = itemsearcher.search(search);
    if (results.size() > 0) {
      return true;
    }
    return false;
  }
Ejemplo n.º 6
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;
  }