コード例 #1
0
  public Product buildProduct(
      String productAccessUrl, String downloadDirectory, ProductPriority priority) {
    Product product = new Product();
    product.setProductAccessUrl(productAccessUrl);
    product.setUuid(UUID.randomUUID().toString());
    /*
     * add a small delay before setting the creation timestamp - this ensures that each product has a unique timestamp.
     * The timestamp is used to determine which product should be downloaded first if priorities are the same.
     */
    try {
      Thread.sleep(10);
    } catch (InterruptedException e) {
      e.printStackTrace();
    }

    product.setCreationTimestamp(new Timestamp(new Date().getTime()));
    product.setNotified(false);
    product.setDownloadDirectory(downloadDirectory);
    product.setPriority(priority);
    product.setVisible(true);

    ProductProgress productProgress = new ProductProgress();
    productProgress.setProgressPercentage(0);
    productProgress.setDownloadedSize(0);
    productProgress.setStatus(EDownloadStatus.NOT_STARTED);
    productProgress.setMessage(null);

    product.setProductProgress(productProgress);
    return product;
  }