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.isDirty()) { 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.getPool().getProductId()); } continue; } if (log.isDebugEnabled()) { log.debug("Exporting entitlement for product" + ent.getPool().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(); } } } }
private String createDN(Entitlement ent) { StringBuilder sb = new StringBuilder("CN="); sb.append(ent.getId()); return sb.toString(); }