DYFILegacyStorage.java

  1. package gov.usgs.earthquake.dyfi;

  2. import gov.usgs.earthquake.distribution.FileProductStorage;
  3. import gov.usgs.earthquake.product.ProductId;

  4. import java.io.File;

  5. /**
  6.  * Storage class used by DYFIIndexerWedge.
  7.  */
  8. @Deprecated
  9. public class DYFILegacyStorage extends FileProductStorage {

  10.     @Override
  11.     public String getProductPath(ProductId id) {
  12.         StringBuffer path = new StringBuffer();
  13.         String fs = System.getProperty("file.separator");

  14.         path.append(id.getCode().substring(0, 2)).append(fs); // Legacy network
  15.         path.append(id.getCode().substring(2)).append(fs);    // Legacy code
  16.         path.append(id.getSource());
  17.        
  18.         return path.toString();
  19.     }
  20.    
  21.     @Override
  22.     public boolean hasProduct(ProductId id) throws Exception {
  23.        
  24.         File productDir = new File(getBaseDirectory(), getProductPath(id));
  25.         boolean hasProduct = false;
  26.        
  27.         if (productDir.exists()) {
  28.        
  29.             // Legacy storage only keeps most recent product. So can't just check
  30.             // for directory existence since this may be from an earlier version.
  31.             // Check version to make sure incoming product is newer than current.
  32.             ProductId storedProduct = getProduct(id).getId();
  33.            
  34.             int status = id.compareTo(storedProduct);
  35.            
  36.             if (status == 0) {
  37.                 // Equal product id we already have product
  38.                 hasProduct = true;
  39.             } else if (status > 0) {
  40.                 // This product is newer than stored product. We don't have this yet
  41.                 hasProduct = false;
  42.             } else if (status < 0) {
  43.                 // This product is older than stored product. Skip it.
  44.                 hasProduct = true;
  45.             }
  46.         }
  47.        
  48.         return hasProduct;
  49.     }
  50. }