Пример #1
0
  /**
   * Do process all products in database that their ingestion is not finished. If provided parameter
   * is null, default processing consists in removing the data from database. Otherwise, the
   * provided processing is launched.
   *
   * @param proc the processing to execute. if null, remove processing will be performed.
   * @return the list of products reprocessed.
   */
  @Transactional(readOnly = false, propagation = Propagation.REQUIRED)
  @CacheEvict(
      value = {"product_count", "product", "products"},
      allEntries = true)
  public void processUnprocessed(boolean recover) {
    long start = new Date().getTime();

    if (!recover) {
      Iterator<Product> products = getUnprocessedProducts();
      while (products.hasNext()) {
        products.next();
        products.remove();
      }

      logger.debug(
          "Cleanup incomplete processed products in " + (new Date().getTime() - start) + "ms");
    } else {
      Iterator<Product> products = getUnprocessedProducts();
      while (products.hasNext()) {
        Product product = products.next();
        // Do reporcess only already transfered products
        if (product.getPath().toString().equals(product.getOrigin())) {
          products.remove();
        } else {
          try {
            String path = product.getPath().getPath();
            logger.info("Recovering product from " + path);
            // Check if product is still present in repository
            if (!new File(path).exists()) {
              throw new DataStoreException("Product " + path + " not present locally.");
            }
            // Retrieve owner if any
            User owner = productDao.getOwnerOfProduct(product);

            // Retrieve collections
            List<Collection> collections = collectionDao.getCollectionsOfProduct(product.getId());

            processProduct(product, owner, collections, null, null);
          } catch (Exception e) {
            logger.error("Error while processing: " + e.getMessage() + "- abort reprocessing.");
            products.remove();
          }
        }
      }
    }
  }
Пример #2
0
  /**
   * Adds a product in the database, the given product will not be queued for processing nor it will
   * be submitted to the search engine.
   *
   * @param product a product to store in the database.
   * @return the created product.
   * @throws IllegalArgumentException incomplete products are not allowed.
   */
  @Transactional(readOnly = false, propagation = Propagation.REQUIRED)
  @Caching(
      evict = {
        @CacheEvict(value = "product", allEntries = true),
        @CacheEvict(value = "products", allEntries = true)
      })
  @IncrementCache(name = "product_count", key = "all", value = 1)
  public Product addProduct(Product product) throws IllegalArgumentException {
    URL path = product.getPath();
    String origin = product.getOrigin();
    if (path == null || origin == null || origin.isEmpty()) {
      throw new IllegalArgumentException("product must have a path and an origin");
    }
    // FIXME do I have to check every field? isn't it done by hibernate based on column constraints?

    Product final_product = this.productDao.create(product);
    return final_product;
  }