private void validateLayerQuota(DiskQuotaConfig quotaConfig, LayerQuota lq)
      throws ConfigurationException {
    String layer = lq.getLayer();
    try {
      tileLayerDispatcher.getTileLayer(layer);
    } catch (GeoWebCacheException e) {
      log.error(
          "LayerQuota configuration error: layer "
              + layer
              + " does not exist. Removing quota from runtime configuration.",
          e);
      quotaConfig.remove(lq);
    }

    final ExpirationPolicy expirationPolicyName = lq.getExpirationPolicyName();
    if (expirationPolicyName == null) {
      // if expiration policy is not defined, then there should be no quota defined either,
      // as it means the layer is managed by the global expiration policy, if any
      if (lq.getQuota() != null) {
        throw new ConfigurationException(
            "Layer "
                + lq.getLayer()
                + " has no expiration policy, but does have a quota defined. "
                + "Either both or neither should be present");
      }
      return;
    }

    Quota quota = lq.getQuota();
    try {
      validateQuota(quota);
    } catch (ConfigurationException e) {
      log.error(
          "LayerQuota configuration error for layer "
              + layer
              + ". Error message is: "
              + e.getMessage()
              + ". Quota removed from runtime configuration.");
      quotaConfig.remove(lq);
    }
  }
  private void validateConfig(DiskQuotaConfig quotaConfig) throws ConfigurationException {
    int cacheCleanUpFrequency = quotaConfig.getCacheCleanUpFrequency();
    if (cacheCleanUpFrequency <= 0) {
      throw new ConfigurationException("cacheCleanUpFrequency shall be a positive integer");
    }
    TimeUnit cacheCleanUpUnits = quotaConfig.getCacheCleanUpUnits();
    if (cacheCleanUpUnits == null) {
      throw new ConfigurationException(
          "cacheCleanUpUnits shall be specified. Expected one of SECONDS, MINUTES, HOURS, DAYS. Got null");
    }
    int diskBlockSize = quotaConfig.getDiskBlockSize();
    if (diskBlockSize <= 0) {
      throw new ConfigurationException(
          "Disk block size shall be specified and be a positive integer");
    }

    int maxConcurrentCleanUps = quotaConfig.getMaxConcurrentCleanUps();
    if (maxConcurrentCleanUps <= 0) {
      throw new ConfigurationException(
          "maxConcurrentCleanUps shall be specified as a positive integer");
    }

    if (null != quotaConfig.getLayerQuotas()) {
      for (LayerQuota lq : new ArrayList<LayerQuota>(quotaConfig.getLayerQuotas())) {
        if (null == lq.getQuota()) {
          log.info(
              "Configured quota for layer "
                  + lq.getLayer()
                  + " is null. Discarding it to be attached to the global quota");
          quotaConfig.remove(lq);
          continue;
        }

        validateLayerQuota(quotaConfig, lq);
      }
    }
  }