Exemplo n.º 1
0
  /**
   * @param locale
   * @param olatResource
   * @param shortTitle
   * @param olatResourceDetail
   * @param repositoryRef
   * @param type
   * @param exportDirectory
   * @param anonymizerCallback callback that should be used to anonymize the user names or NULL if
   *     row counter should be used (only for type 2 and 3)
   * @return
   */
  public boolean selectAndExportResults(
      final QTIExportFormatter qef,
      final Long olatResource,
      final String shortTitle,
      final String olatResourceDetail,
      final Long repositoryRef,
      final File exportDirectory,
      final String charset,
      final String fileNameSuffix) {
    boolean resultsFoundAndExported = false;
    final List results =
        qtiResultService.selectResults(
            olatResource, olatResourceDetail, repositoryRef, qef.getType());
    if (results.size() > 0) {
      final QTIResult res0 = (QTIResult) results.get(0);

      final QTIObjectTreeBuilder qotb =
          new QTIObjectTreeBuilder(new Long(res0.getResultSet().getRepositoryRef()));

      final List qtiItemObjectList = qotb.getQTIItemObjectList();
      qef.setQTIItemObjectList(qtiItemObjectList);
      if (results.size() > 0) {
        createContentOfExportFile(results, qtiItemObjectList, qef);
        writeContentToFile(shortTitle, exportDirectory, charset, qef, fileNameSuffix);
        resultsFoundAndExported = true;
      }
    }
    return resultsFoundAndExported;
  }
Exemplo n.º 2
0
  /** writes content of all results to a file */
  private String writeContentToFile(
      final String shortTitle,
      final File exportDirectory,
      final String charset,
      final QTIExportFormatter qef,
      final String fileNameSuffix) {
    // defining target filename
    final StringBuilder tf = new StringBuilder();
    tf.append(qef.getFileNamePrefix());
    tf.append(Formatter.makeStringFilesystemSave(shortTitle));
    tf.append("_");
    final DateFormat myformat = new SimpleDateFormat("yyyy-MM-dd__hh-mm-ss__SSS");
    final String timestamp = myformat.format(new Date());
    tf.append(timestamp);
    tf.append(fileNameSuffix);
    final String targetFileName = tf.toString();

    ExportUtil.writeContentToFile(targetFileName, qef.getReport(), exportDirectory, charset);

    return targetFileName;
  }
Exemplo n.º 3
0
  /**
   * @param locale Locale used for export file headers / default values
   * @param results
   * @param type
   * @param anonymizerCallback
   * @return String
   */
  private void createContentOfExportFile(
      final List qtiResults, final List qtiItemObjectList, final QTIExportFormatter qef) {

    qef.openReport();

    // formatter has information about how to format the different qti objects
    final Map mapWithConfigs = qef.getMapWithExportItemConfigs();
    final QTIExportItemFactory qeif = new QTIExportItemFactory(mapWithConfigs);

    while (qtiResults.size() > 0) {
      final List assessIDresults = stripNextAssessID(qtiResults);

      qef.openResultSet(new QTIExportSet((QTIResult) assessIDresults.get(0)));

      for (final Iterator iter = qtiItemObjectList.iterator(); iter.hasNext(); ) {
        final QTIItemObject element = (QTIItemObject) iter.next();

        QTIResult qtir;
        qtir = element.extractQTIResult(assessIDresults);
        qef.visit(qeif.getExportItem(qtir, element));
      }
      qef.closeResultSet();
    }
    qef.closeReport();
  }
Exemplo n.º 4
0
  /**
   * @param qef
   * @param results
   * @param qtiItemObjectList
   * @param shortTitle
   * @param exportDirectory
   * @param charset
   * @param fileNameSuffix
   * @return
   */
  public String exportResults(
      final QTIExportFormatter qef,
      final List results,
      final List qtiItemObjectList,
      final String shortTitle,
      final File exportDirectory,
      final String charset,
      final String fileNameSuffix) {
    String targetFileName = null;

    qef.setQTIItemObjectList(qtiItemObjectList);
    if (results.size() > 0) {
      createContentOfExportFile(results, qtiItemObjectList, qef);
      targetFileName =
          writeContentToFile(shortTitle, exportDirectory, charset, qef, fileNameSuffix);
    }
    return targetFileName;
  }