Ejemplo n.º 1
0
  private void exportEntitlements(File baseDir, Consumer consumer)
      throws IOException, ExportCreationException {
    File entCertDir = new File(baseDir.getCanonicalPath(), "entitlements");
    entCertDir.mkdir();

    for (Entitlement ent : entitlementCurator.listByConsumer(consumer)) {
      if (ent.getDirty()) {
        log.error("Entitlement " + ent.getId() + " is marked as dirty.");
        throw new ExportCreationException("Attempted to export dirty entitlements");
      }

      if (!this.exportRules.canExport(ent)) {
        if (log.isDebugEnabled()) {
          log.debug("Skipping export of entitlement with product:  " + ent.getProductId());
        }

        continue;
      }

      if (log.isDebugEnabled()) {
        log.debug("Exporting entitlement for product" + ent.getProductId());
      }
      FileWriter writer = null;
      try {
        File file = new File(entCertDir.getCanonicalPath(), ent.getId() + ".json");
        writer = new FileWriter(file);
        entExporter.export(mapper, writer, ent);
      } finally {
        if (writer != null) {
          writer.close();
        }
      }
    }
  }