<commit_before>package pt.webdetails.cda.dataaccess;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.dom4j.Element;
import org.pentaho.reporting.engine.classic.core.ClassicEngineBoot;
import org.pentaho.reporting.engine.classic.core.DataFactory;
import org.pentaho.reporting.engine.classic.core.ParameterDataRow;
import org.pentaho.reporting.engine.classic.core.states.CachingDataFactory;
import org.pentaho.reporting.engine.classic.core.util.LibLoaderResourceBundleFactory;
import org.pentaho.reporting.libraries.resourceloader.ResourceKey;
import org.pentaho.reporting.libraries.resourceloader.ResourceKeyCreationException;
import org.pentaho.reporting.libraries.resourceloader.ResourceManager;
import pt.webdetails.cda.connections.InvalidConnectionException;
import pt.webdetails.cda.settings.UnknownConnectionException;

import javax.swing.table.TableModel;
import java.io.File;
import java.util.Locale;
import java.util.TimeZone;

/**
 * This is the DataAccess implementation for PentahoReportingEngine based queries.
 * <p/>
 * User: pedro
 * Date: Feb 3, 2010
 * Time: 2:18:19 PM
 */
public abstract class PREDataAccess extends SimpleDataAccess {

  private static final Log logger = LogFactory.getLog(PREDataAccess.class);


  public PREDataAccess(final Element element) {
    super(element);


  }


  public abstract DataFactory getDataFactory() throws UnknownConnectionException, InvalidConnectionException;

  @Override
  public TableModel queryData() throws QueryException {

    try {

      DataFactory dataFactory = new CachingDataFactory(getDataFactory());

      ResourceManager resourceManager = new ResourceManager();
      resourceManager.registerDefaults();
      final ResourceKey contextKey = resourceManager.createKey(new File(getCdaSettings().getId()));


      /*
      dataFactory.initialize(ClassicEngineBoot.getInstance().getGlobalConfig(), resourceManager,
              contextKey,
              new LibLoaderResourceBundleFactory(resourceManager, contextKey, Locale.getDefault(), TimeZone.getDefault()));

      // you may give it some real parameters via the constructor of parameter-datarow ...
      final ParameterDataRow parameters = new ParameterDataRow();
      // fire the query. you always get a tablemodel or an exception.
      final TableModel tableModel = reportDataFactory.queryData("Query 1", parameters);

      // process your data as you like

      // and at the end, close your tablemodel if it holds on to resources like a resultset
      if (tableModel instanceof CloseableTableModel) {
        CloseableTableModel ctm = (CloseableTableModel) tableModel;
        ctm.close();
      }

      // and finally shut down the datafactory to free any connection that may be open.
      reportDataFactory.close();
      */


    } catch (UnknownConnectionException e) {
      throw new QueryException("Unknown connection", e);
    } catch (InvalidConnectionException e) {
      throw new QueryException("Unknown connection", e);
    } catch (ResourceKeyCreationException e) {
      throw new QueryException("ResourceKeyCreateException", e);
    }


    logger.fatal("Not Implemented Yet!!");
    return null;  //To change body of implemented methods use File | Settings | File Templates.


  }

  private static ResourceKey createContextKey(final ResourceManager resourceManager,
                                              final String dashboardDefinitionPath) throws ResourceKeyCreationException {

    /*
    HashMap helperObjects = new HashMap();
    // add the runtime context so that PentahoResourceData class can get access
    // to the solution repo
    helperObjects.put(new FactoryParameterKey(RepositoryResourceData.PENTAHO_REPOSITORY_KEY), PentahoSystem.get(ISolutionRepository.class, pentahoSession));

    ResourceKey key = resourceManager.createKey(RepositoryResourceLoader.SOLUTION_SCHEMA_NAME + RepositoryResourceLoader.SCHEMA_SEPARATOR
        + dashboardDefinitionPath, helperObjects);
    */

    ResourceKey key = resourceManager.createKey(dashboardDefinitionPath);
    return key;
  }


}<commit_msg>Making the data-factory initialize itself properly.<commit_after>package pt.webdetails.cda.dataaccess;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.dom4j.Element;
import org.pentaho.reporting.engine.classic.core.ClassicEngineBoot;
import org.pentaho.reporting.engine.classic.core.DataFactory;
import org.pentaho.reporting.engine.classic.core.ParameterDataRow;
import org.pentaho.reporting.engine.classic.core.ReportDataFactoryException;
import org.pentaho.reporting.engine.classic.core.states.CachingDataFactory;
import org.pentaho.reporting.engine.classic.core.util.CloseableTableModel;
import org.pentaho.reporting.engine.classic.core.util.LibLoaderResourceBundleFactory;
import org.pentaho.reporting.libraries.resourceloader.ResourceKey;
import org.pentaho.reporting.libraries.resourceloader.ResourceKeyCreationException;
import org.pentaho.reporting.libraries.resourceloader.ResourceManager;
import pt.webdetails.cda.connections.InvalidConnectionException;
import pt.webdetails.cda.settings.UnknownConnectionException;

import javax.swing.table.TableModel;
import java.io.File;
import java.util.Locale;
import java.util.TimeZone;

/**
 * This is the DataAccess implementation for PentahoReportingEngine based queries.
 * <p/>
 * User: pedro
 * Date: Feb 3, 2010
 * Time: 2:18:19 PM
 */
public abstract class PREDataAccess extends SimpleDataAccess {

  private static final Log logger = LogFactory.getLog(PREDataAccess.class);


  public PREDataAccess(final Element element) {
    super(element);


  }


  public abstract DataFactory getDataFactory() throws UnknownConnectionException, InvalidConnectionException;

  @Override
  public TableModel queryData() throws QueryException {

    try {

      CachingDataFactory dataFactory = new CachingDataFactory(getDataFactory());

      ResourceManager resourceManager = new ResourceManager();
      resourceManager.registerDefaults();
      final ResourceKey contextKey = resourceManager.createKey(new File(getCdaSettings().getId()));



      dataFactory.initialize(ClassicEngineBoot.getInstance().getGlobalConfig(), resourceManager,
              contextKey,
              new LibLoaderResourceBundleFactory(resourceManager, contextKey, Locale.getDefault(), TimeZone.getDefault()));

      // you may give it some real parameters via the constructor of parameter-datarow ...
      final ParameterDataRow parameters = new ParameterDataRow();
      // fire the query. you always get a tablemodel or an exception.
      final TableModel tableModel = dataFactory.queryData("Query 1", parameters);

      // process your data as you like

      // and at the end, close your tablemodel if it holds on to resources like a resultset
      if (tableModel instanceof CloseableTableModel) {
        CloseableTableModel ctm = (CloseableTableModel) tableModel;
        ctm.close();
      }

      // and finally shut down the datafactory to free any connection that may be open.
      dataFactory.close();



    } catch (UnknownConnectionException e) {
      throw new QueryException("Unknown connection", e);
    } catch (InvalidConnectionException e) {
      throw new QueryException("Unknown connection", e);
    } catch (ResourceKeyCreationException e) {
      throw new QueryException("ResourceKeyCreateException", e);
    }
    catch (ReportDataFactoryException e)
    {
      throw new QueryException("ResourceKeyCreateException", e);
    }


    logger.fatal("Not Implemented Yet!!");
    return null;  //To change body of implemented methods use File | Settings | File Templates.


  }

}
{'fraction_non_alphanumeric': 0.08363589211618257, 'fraction_numerical': 0.0031120331950207467, 'mean_word_length': 4.2792607802874745, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2554354', 'n_tokens_mistral': 2043, 'n_tokens_neox': 1953, 'n_words': 515}