예제 #1
0
  public void outputSummaryToCsv(final OutputStream outputStream, final Locale locale)
      throws IOException {
    final List<ReportSummaryData.PresentationRow> outputList =
        summaryData.asPresentableCollection(pwmApplication.getConfig(), locale);
    final CSVPrinter csvPrinter = Helper.makeCsvPrinter(outputStream);

    for (final ReportSummaryData.PresentationRow presentationRow : outputList) {
      final List<String> headerRow = new ArrayList<>();
      headerRow.add(presentationRow.getLabel());
      headerRow.add(presentationRow.getCount());
      headerRow.add(presentationRow.getPct());
      csvPrinter.printRecord(headerRow);
    }

    csvPrinter.close();
  }
예제 #2
0
  public void outputToCsv(
      final OutputStream outputStream, final boolean includeHeader, final Locale locale)
      throws IOException, ChaiUnavailableException, ChaiOperationException,
          PwmUnrecoverableException, PwmOperationalException {
    final CSVPrinter csvPrinter = Helper.makeCsvPrinter(outputStream);
    final Configuration config = pwmApplication.getConfig();
    final Class localeClass = password.pwm.i18n.Admin.class;
    if (includeHeader) {
      final List<String> headerRow = new ArrayList<>();
      headerRow.add(
          LocaleHelper.getLocalizedMessage(locale, "Field_Report_UserDN", config, localeClass));
      headerRow.add(
          LocaleHelper.getLocalizedMessage(
              locale, "Field_Report_LDAP_Profile", config, localeClass));
      headerRow.add(
          LocaleHelper.getLocalizedMessage(locale, "Field_Report_Username", config, localeClass));
      headerRow.add(
          LocaleHelper.getLocalizedMessage(locale, "Field_Report_Email", config, localeClass));
      headerRow.add(
          LocaleHelper.getLocalizedMessage(locale, "Field_Report_UserGuid", config, localeClass));
      headerRow.add(
          LocaleHelper.getLocalizedMessage(locale, "Field_Report_LastLogin", config, localeClass));
      headerRow.add(
          LocaleHelper.getLocalizedMessage(
              locale, "Field_Report_PwdExpireTime", config, localeClass));
      headerRow.add(
          LocaleHelper.getLocalizedMessage(
              locale, "Field_Report_PwdChangeTime", config, localeClass));
      headerRow.add(
          LocaleHelper.getLocalizedMessage(
              locale, "Field_Report_ResponseSaveTime", config, localeClass));
      headerRow.add(
          LocaleHelper.getLocalizedMessage(
              locale, "Field_Report_HasResponses", config, localeClass));
      headerRow.add(
          LocaleHelper.getLocalizedMessage(
              locale, "Field_Report_HasHelpdeskResponses", config, localeClass));
      headerRow.add(
          LocaleHelper.getLocalizedMessage(
              locale, "Field_Report_ResponseStorageMethod", config, localeClass));
      headerRow.add(
          LocaleHelper.getLocalizedMessage(locale, "Field_Report_PwdExpired", config, localeClass));
      headerRow.add(
          LocaleHelper.getLocalizedMessage(
              locale, "Field_Report_PwdPreExpired", config, localeClass));
      headerRow.add(
          LocaleHelper.getLocalizedMessage(
              locale, "Field_Report_PwdViolatesPolicy", config, localeClass));
      headerRow.add(
          LocaleHelper.getLocalizedMessage(
              locale, "Field_Report_PwdWarnPeriod", config, localeClass));
      headerRow.add(
          LocaleHelper.getLocalizedMessage(
              locale, "Field_Report_RequiresPasswordUpdate", config, localeClass));
      headerRow.add(
          LocaleHelper.getLocalizedMessage(
              locale, "Field_Report_RequiresResponseUpdate", config, localeClass));
      headerRow.add(
          LocaleHelper.getLocalizedMessage(
              locale, "Field_Report_RequiresProfileUpdate", config, localeClass));
      headerRow.add(
          LocaleHelper.getLocalizedMessage(
              locale, "Field_Report_RecordCacheTime", config, localeClass));
      csvPrinter.printRecord(headerRow);
    }

    ClosableIterator<UserCacheRecord> cacheBeanIterator = null;
    try {
      cacheBeanIterator = this.iterator();
      while (cacheBeanIterator.hasNext()) {
        final UserCacheRecord userCacheRecord = cacheBeanIterator.next();
        outputRecordRow(config, locale, userCacheRecord, csvPrinter);
      }
    } finally {
      if (cacheBeanIterator != null) {
        cacheBeanIterator.close();
      }
    }

    csvPrinter.flush();
  }