Package org.pentaho.platform.plugin.action.jfreereport.helper

Examples of org.pentaho.platform.plugin.action.jfreereport.helper.PentahoTableDataFactory


  }

  @Override
  protected PentahoTableDataFactory getDataFactory() throws ClassNotFoundException, InstantiationException,
    IllegalAccessException, Exception {
    PentahoTableDataFactory factory = null;
    if ( reportSpec != null ) {
      if ( !isDefinedInput( AbstractJFreeReportComponent.REPORTGENERATEDEFN_REPORTTEMP_PERFQRY )
          || "true".equals( getInputParameter( AbstractJFreeReportComponent.REPORTGENERATEDEFN_REPORTTEMP_PERFQRY ) ) ) { //$NON-NLS-1$
        IPentahoResultSet pentahoResultSet = getResultSet( getReportSpec() );
        factory = new PentahoTableDataFactory();
        pentahoResultSet.beforeFirst();
        factory.addTable( AbstractJFreeReportComponent.DATACOMPONENT_DEFAULTINPUT, new PentahoTableModel(
              pentahoResultSet ) );

      } else {
        factory = super.getDataFactory();
      }
View Full Code Here


    return result;
  }

  protected PentahoTableDataFactory getDataFactory() throws ClassNotFoundException, InstantiationException,
    IllegalAccessException, Exception {
    PentahoTableDataFactory factory = null;
    factory = getQueryComponentDataFactory();
    if ( factory == null ) {
      factory = getInputParamDataFactory();
    }
    if ( factory == null ) {
View Full Code Here

  }

  private PentahoTableDataFactory getQueryComponentDataFactory() throws ClassNotFoundException, InstantiationException,
    IllegalAccessException, Exception {
    JFreeReportAction jFreeReportAction = (JFreeReportAction) getActionDefinition();
    PentahoTableDataFactory factory = null;
    String dataComponentName = jFreeReportAction.getDataComponent().getStringValue();
    String origComponentName = jFreeReportAction.getComponentName();
    if ( dataComponentName != null ) {
      if ( JFreeReportAction.SQL_DATA_SOURCE.equalsIgnoreCase( dataComponentName ) ) {
        dataComponentName = AbstractJFreeReportComponent.DATACOMPONENT_SQLCLASS;
      } else if ( JFreeReportAction.MDX_DATA_SOURCE.equalsIgnoreCase( dataComponentName ) ) {
        dataComponentName = AbstractJFreeReportComponent.DATACOMPONENT_MDXCLASS;
      }
      try {
        // This is a giant hack and a big no, no. Basically we're going to transform the JFreeReportAction into a
        // SQL or MDX lookup action, by changing its component name. Then we create the appropriate component to run the
        // transformed action.
        // All this to support the DB and Query info being embedded in the JFreeReport action. This is definitely
        // deprecated functionality
        // that should not be relied upon. The correct way to do this is to create an SQL or MDX action prior to the
        // JFreeReport
        // action in the action sequence. That action performs the desired query, then pass the results of that query to
        // the JFreeReport
        // action.
        jFreeReportAction.setComponentName( dataComponentName );
        ActionDefinition tmpActionDefinition =
            ActionFactory.getActionDefinition( jFreeReportAction.getElement(), jFreeReportAction
                .getActionParameterMgr() );
        final Class componentClass = Class.forName( dataComponentName );
        IDataComponent dataComponent = (IDataComponent) componentClass.newInstance();
        dataComponent.setInstanceId( getInstanceId() );
        dataComponent.setActionName( getActionName() );
        dataComponent.setProcessId( getProcessId() );
        dataComponent.setActionDefinition( tmpActionDefinition );
        dataComponent.setComponentDefinition( getComponentDefinition() );
        dataComponent.setRuntimeContext( getRuntimeContext() );
        dataComponent.setSession( getSession() );
        dataComponent.setLoggingLevel( getLoggingLevel() );
        dataComponent.setMessages( getMessages() );
        // if that fails, then we know we messed up again.
        // Abort, we cant continue anyway.
        if ( ( dataComponent.validate() == IRuntimeContext.RUNTIME_CONTEXT_VALIDATE_OK ) && dataComponent.init()
            && ( dataComponent.execute() == IRuntimeContext.RUNTIME_STATUS_SUCCESS ) ) {
          final IPentahoResultSet resultset = dataComponent.getResultSet();
          factory =
              new PentahoTableDataFactory( AbstractJFreeReportComponent.DATACOMPONENT_DEFAULTINPUT,
                  new PentahoTableModel( resultset ) );
        } else {
          throw new IllegalArgumentException( Messages.getInstance().getErrorString(
              "JFreeReport.ERROR_0021_DATA_COMPONENT_FAILED" ) ); //$NON-NLS-1$
        }
View Full Code Here

    }
    return factory;
  }

  private PentahoTableDataFactory getJarDataFactory() throws Exception {
    PentahoTableDataFactory factory = null;
    JFreeReportAction jFreeReportAction = (JFreeReportAction) getActionDefinition();
    try {
      org.pentaho.actionsequence.dom.IActionResource actionResource = jFreeReportAction.getDataJar().getJar();
      if ( actionResource != null ) {
        DataSource dataSource = new ActivationHelper.PentahoStreamSourceWrapper( actionResource.getDataSource() );
        InputStream in = dataSource.getInputStream();
        try {
          // not being able to read a single char is definitly a big boo ..
          if ( in.read() == -1 ) {
            throw new Exception( Messages.getInstance().getErrorString( "JFreeReport.ERROR_0009_REPORT_JAR_UNREADABLE" ) ); //$NON-NLS-1$
          } else {
            final ClassLoader loader =
                ReportUtils.createJarLoader( getSession(), getResource( actionResource.getName() ) );
            if ( loader == null ) {
              throw new Exception( Messages.getInstance().getString(
                "JFreeReportDataComponent.ERROR_0035_COULD_NOT_CREATE_CLASSLOADER" ) ); //$NON-NLS-1$
            } else if ( !isDefinedInput( AbstractJFreeReportComponent.DATACOMPONENT_CLASSLOCINPUT ) ) {
              throw new Exception( Messages.getInstance().getErrorString(
                "JFreeReport.ERROR_0012_CLASS_LOCATION_MISSING" ) ); //$NON-NLS-1$
            } else {
              // Get input parameters, and set them as properties in the report
              // object.
              final ReportParameterValues reportProperties = new ReportParameterValues();
              IActionInput[] actionInputs = jFreeReportAction.getInputs();
              for ( IActionInput element : actionInputs ) {
                final Object paramValue = element.getValue();
                if ( paramValue instanceof Object[] ) {
                  final Object[] values = (Object[]) paramValue;
                  final StringBuffer valuesBuffer = new StringBuffer();
                  // TODO support non-string items
                  for ( int z = 0; z < values.length; z++ ) {
                    if ( z == 0 ) {
                      valuesBuffer.append( values[z].toString() );
                    } else {
                      valuesBuffer.append( ',' ).append( values[z].toString() );
                    }
                  }
                  reportProperties.put( element.getName(), valuesBuffer.toString() );
                } else {
                  reportProperties.put( element.getName(), paramValue );
                }
              }

              final DataFactory dataFactory = new PentahoDataFactory( loader );
              final TableModel model =
                  dataFactory.queryData( jFreeReportAction.getDataJar().getDataClass(), new ParameterDataRow(
                      reportProperties ) );

              factory = new PentahoTableDataFactory( AbstractJFreeReportComponent.DATACOMPONENT_DEFAULTINPUT, model );
            }
          }
        } catch ( Exception e ) {
          throw new Exception( Messages.getInstance().getErrorString( "JFreeReport.ERROR_0009_REPORT_JAR_UNREADABLE" ) ); //$NON-NLS-1$
        }
View Full Code Here

    }
    return factory;
  }

  private PentahoTableDataFactory getInputParamDataFactory() {
    PentahoTableDataFactory factory = null;
    JFreeReportAction jFreeReportAction = (JFreeReportAction) getActionDefinition();

    ActionInput reportDataParam = (ActionInput) jFreeReportAction.getData();
    Object dataObject = reportDataParam != null ? reportDataParam.getValue() : null;
    if ( ( dataObject instanceof IPentahoResultSet ) || ( dataObject instanceof TableModel ) ) {
      factory = new PentahoTableDataFactory();
      if ( dataObject instanceof IPentahoResultSet ) {
        IPentahoResultSet resultset = (IPentahoResultSet) dataObject;
        if ( resultset.isScrollable() ) {
          resultset.beforeFirst();
        } else {
          debug( "ResultSet is not scrollable. Copying into memory" ); //$NON-NLS-1$
          IPentahoResultSet memSet = resultset.memoryCopy();
          resultset.close();
          resultset = memSet;
        }
        factory.addTable( AbstractJFreeReportComponent.DATACOMPONENT_DEFAULTINPUT, new PentahoTableModel( resultset ) );
      } else if ( dataObject instanceof TableModel ) {
        factory.addTable( AbstractJFreeReportComponent.DATACOMPONENT_DEFAULTINPUT, (TableModel) dataObject );
      }

      IActionInput[] subreportQueries = jFreeReportAction.getSubreportQueryParams();
      for ( IActionInput element : subreportQueries ) {
        dataObject = element.getValue();
        if ( dataObject instanceof IPreparedComponent ) {
          factory.addPreparedComponent( element.getName(), (IPreparedComponent) dataObject );
        } else if ( dataObject instanceof IPentahoResultSet ) {
          final IPentahoResultSet resultset = (IPentahoResultSet) dataObject;
          resultset.beforeFirst();
          factory.addTable( element.getName(), new PentahoTableModel( resultset ) );
        } else if ( dataObject instanceof TableModel ) {
          factory.addTable( element.getName(), (TableModel) dataObject );
        }
      }
    }
    return factory;
  }
View Full Code Here

  }

  @SuppressWarnings( "unused" )
  private PentahoTableDataFactory getQueryComponentDataFactory() throws ClassNotFoundException, InstantiationException,
    IllegalAccessException, Exception {
    PentahoTableDataFactory factory = null;
    dataComponent = null;
    final Node sourceNode =
        getComponentDefinition().selectSingleNode( AbstractJFreeReportComponent.DATACOMPONENT_SOURCE );
    if ( sourceNode != null ) {
      String dataComponentClass = sourceNode.getText();
      if ( AbstractJFreeReportComponent.DATACOMPONENT_SQLSOURCE.equalsIgnoreCase( dataComponentClass ) ) {
        dataComponentClass = AbstractJFreeReportComponent.DATACOMPONENT_SQLCLASS;
      } else if ( AbstractJFreeReportComponent.DATACOMPONENT_MDXSOURCE.equalsIgnoreCase( dataComponentClass ) ) {
        dataComponentClass = AbstractJFreeReportComponent.DATACOMPONENT_MDXCLASS;
      }
      if ( dataComponentClass != null ) {
        try {
          final Class componentClass = Class.forName( dataComponentClass );
          dataComponent = (IDataComponent) componentClass.newInstance();
          dataComponent.setInstanceId( getInstanceId() );
          dataComponent.setActionName( getActionName() );
          dataComponent.setProcessId( getProcessId() );
          dataComponent.setComponentDefinition( getComponentDefinition() );
          dataComponent.setRuntimeContext( getRuntimeContext() );
          dataComponent.setSession( getSession() );
          dataComponent.setLoggingLevel( getLoggingLevel() );
          dataComponent.setMessages( getMessages() );
          // if that fails, then we know we messed up again.
          // Abort, we cant continue anyway.
          if ( ( dataComponent.validate() == IRuntimeContext.RUNTIME_CONTEXT_VALIDATE_OK ) && dataComponent.init()
              && ( dataComponent.execute() == IRuntimeContext.RUNTIME_STATUS_SUCCESS ) ) {
            final IPentahoResultSet resultset = dataComponent.getResultSet();
            factory =
                new PentahoTableDataFactory( AbstractJFreeReportComponent.DATACOMPONENT_DEFAULTINPUT,
                    new PentahoTableModel( resultset ) );
          } else {
            throw new IllegalArgumentException( Messages.getInstance().getErrorString(
                "JFreeReport.ERROR_0021_DATA_COMPONENT_FAILED" ) ); //$NON-NLS-1$
          }
View Full Code Here

    return factory;
  }

  @SuppressWarnings( "unused" )
  private PentahoTableDataFactory getJarDataFactory() throws Exception {
    PentahoTableDataFactory factory = null;
    if ( isDefinedResource( AbstractJFreeReportComponent.DATACOMPONENT_JARINPUT ) ) {
      final IActionSequenceResource resource = getResource( AbstractJFreeReportComponent.DATACOMPONENT_JARINPUT );
      final InputStream in;
      try {
        in = resource.getInputStream( RepositoryFilePermission.READ, LocaleHelper.getLocale() );
        try {
          // not being able to read a single char is definitly a big boo ..
          if ( in.read() == -1 ) {
            throw new Exception( Messages.getInstance().getErrorString( "JFreeReport.ERROR_0009_REPORT_JAR_UNREADABLE" ) ); //$NON-NLS-1$
          } else {
            final ClassLoader loader = ReportUtils.createJarLoader( getSession(), resource );
            if ( loader == null ) {
              throw new Exception( Messages.getInstance().getString(
                "JFreeReportDataComponent.ERROR_0035_COULD_NOT_CREATE_CLASSLOADER" ) ); //$NON-NLS-1$
            } else if ( !isDefinedInput( AbstractJFreeReportComponent.DATACOMPONENT_CLASSLOCINPUT ) ) {
              throw new Exception( Messages.getInstance().getErrorString(
                "JFreeReport.ERROR_0012_CLASS_LOCATION_MISSING" ) ); //$NON-NLS-1$
            } else {
              final String classLocation =
                  getInputStringValue( AbstractJFreeReportComponent.DATACOMPONENT_CLASSLOCINPUT );
              // Get input parameters, and set them as properties in the report
              // object.
              final ReportParameterValues reportProperties = new ReportParameterValues();
              final Set paramNames = getInputNames();
              final Iterator it = paramNames.iterator();
              while ( it.hasNext() ) {
                final String paramName = (String) it.next();
                final Object paramValue = getInputValue( paramName );
                if ( paramValue instanceof Object[] ) {
                  final Object[] values = (Object[]) paramValue;
                  final StringBuffer valuesBuffer = new StringBuffer();
                  // TODO support non-string items
                  for ( int i = 0; i < values.length; i++ ) {
                    if ( i == 0 ) {
                      valuesBuffer.append( values[i].toString() );
                    } else {
                      valuesBuffer.append( ',' ).append( values[i].toString() );
                    }
                  }
                  reportProperties.put( paramName, valuesBuffer.toString() );
                } else {
                  reportProperties.put( paramName, paramValue );
                }
              }

              final DataFactory dataFactory = new PentahoDataFactory( loader );
              final TableModel model = dataFactory.queryData( classLocation, new ParameterDataRow( reportProperties ) );

              factory = new PentahoTableDataFactory( AbstractJFreeReportComponent.DATACOMPONENT_DEFAULTINPUT, model );
            }
          }
        } catch ( Exception e ) {
          throw new Exception( Messages.getInstance().getErrorString( "JFreeReport.ERROR_0009_REPORT_JAR_UNREADABLE" ) ); //$NON-NLS-1$
        }
View Full Code Here

  }

  @SuppressWarnings( "unused" )
  private PentahoTableDataFactory getInputParamDataFactory() {

    PentahoTableDataFactory factory = null;
    if ( isDefinedInput( AbstractJFreeReportComponent.DATACOMPONENT_DATAINPUT )
        || isDefinedInput( AbstractJFreeReportComponent.DATACOMPONENT_DEFAULTINPUT ) ) {

      factory = new PentahoTableDataFactory();
      final Iterator iter = getInputNames().iterator();
      while ( iter.hasNext() ) {
        String name = (String) iter.next();
        final Object dataObject = getInputValue( name );
        // if input name is "data", rename to "default" which is the name that jfreereport is expecting.
        if ( name.equals( AbstractJFreeReportComponent.DATACOMPONENT_DATAINPUT ) ) {
          name = AbstractJFreeReportComponent.DATACOMPONENT_DEFAULTINPUT;
        }
        if ( dataObject instanceof IPreparedComponent ) {
          final IPreparedComponent comp = (IPreparedComponent) dataObject;
          factory.addPreparedComponent( name, comp );
        } else if ( dataObject instanceof IPentahoResultSet ) {
          final IPentahoResultSet resultset = (IPentahoResultSet) dataObject;
          resultset.beforeFirst();
          factory.addTable( name, new PentahoTableModel( resultset ) );
        } else if ( dataObject instanceof TableModel ) {
          final TableModel model = (TableModel) dataObject;
          factory.addTable( name, model );
        }
      }
    }
    return factory;
  }
View Full Code Here

TOP

Related Classes of org.pentaho.platform.plugin.action.jfreereport.helper.PentahoTableDataFactory

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.