Пример #1
0
  /* (non-Javadoc)
   * @see impl.LTIExportService#export(java.io.OutputStream, org.sakaiproject.lti.api.LTIExportService.ExportType, java.lang.String)
   */
  public void export(OutputStream out, String siteId, ExportType exportType, String filterId) {
    String search = null;
    // check if we need to filter the tools by tool_id
    if (StringUtils.isNotEmpty(filterId)) {
      search = "tool_id:" + filterId;
    }
    List<Map<String, Object>> contents =
        ltiService.getContentsDao(search, null, 0, 0, siteId, isAdmin(siteId));
    LTIExporter exporter = null;
    switch (exportType) {
      case CSV:
        exporter = new ExporterCSV();
        break;
      case EXCEL:
        exporter = new ExporterExcel();
        break;
    }

    if (exporter != null) {
      DateFormat dateFormatter =
          DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM, rb.getLocale());

      String attribution_name =
          serverConfigurationService.getString(LTIService.LTI_SITE_ATTRIBUTION_PROPERTY_NAME);
      if (StringUtils.isNotEmpty(attribution_name)) {
        // check if given property is a translation key
        String aux = rb.getString(attribution_name);
        if (StringUtils.isNotEmpty(aux)) attribution_name = aux;
      }

      boolean isAdmin = isAdmin(siteId);

      // set header row
      exporter.newLine();
      exporter.addCell(rb.getString("export.title"));
      exporter.addCell(rb.getString("export.url"));
      if (isAdmin) {
        exporter.addCell(rb.getString("export.siteid"));
        exporter.addCell(rb.getString("export.sitetitle"));
      }
      exporter.addCell(rb.getString("export.createdat"));
      if (isAdmin) {
        exporter.addCell(rb.getString("export.sitecontactname"));
        exporter.addCell(rb.getString("export.sitecontactemail"));
        if (StringUtils.isNotEmpty(attribution_name)) {
          exporter.addCell(attribution_name);
        }
      }

      // values rows
      for (Map<String, Object> content : contents) {
        exporter.newLine();
        exporter.addCell((String) content.get("title"));

        String url = (String) content.get("launch");
        if (StringUtils.isEmpty(url)) {
          try {
            url =
                (String)
                    (ltiService
                        .getToolDao(
                            new Long(content.get(LTIService.LTI_TOOL_ID).toString()), siteId)
                        .get("launch"));
          } catch (Exception e) {
            url = "-";
          }
        }
        exporter.addCell(url);

        if (isAdmin) {
          exporter.addCell((String) content.get("SITE_ID"));

          exporter.addCell((String) content.get("SITE_TITLE"));
        }

        try {
          exporter.addCell(dateFormatter.format(content.get("created_at")));
        } catch (Exception e) {
          exporter.addCell("-");
        }

        if (isAdmin) {
          exporter.addCell((String) content.get("SITE_CONTACT_NAME"));

          exporter.addCell((String) content.get("SITE_CONTACT_EMAIL"));

          if (StringUtils.isNotEmpty(attribution_name)) {
            exporter.addCell((String) content.get("ATTRIBUTION"));
          }
        }
      }

      exporter.write(out);
    } else {
      M_log.error("Error exporting : no exporter found for " + exportType);
    }
  }