Package org.pentaho.di.repository

Examples of org.pentaho.di.repository.Repository


    // Sadly Kettle always insists on creating a log-file. There is no way around it (yet).
    final LogWriter logWriter = LogWriter.getInstance("Kettle-reporting-datasource", false);
    try
    {
      final Repository repository = connectToRepository(logWriter);
      try
      {
        final TransMeta transMeta = loadTransformation(repository, resourceManager, resourceKey);
        transMeta.setArguments(params);
        final Trans trans = new Trans(transMeta);
        for (int i = 0; i < definedVariableNames.length; i++)
        {
          final ParameterMapping mapping = definedVariableNames[i];
          final String sourceName = mapping.getName();
          final String variableName = mapping.getAlias();
          final Object value = parameters.get(sourceName);
          if (value != null)
          {
            trans.setParameterValue(variableName, String.valueOf(value));
          }
        }

        transMeta.setInternalKettleVariables();
        trans.prepareExecution(transMeta.getArguments());

        TableProducer tableProducer = null;
        final List stepList = trans.getSteps();
        for (int i = 0; i < stepList.size(); i++)
        {
          final StepMetaDataCombi metaDataCombi = (StepMetaDataCombi) stepList.get(i);
          if (stepName.equals(metaDataCombi.stepname) == false)
          {
            continue;
          }
          final RowMetaInterface row = transMeta.getStepFields(stepName);
          tableProducer = new TableProducer(row, queryLimit, stopOnError);
          metaDataCombi.step.addRowListener(tableProducer);
          break;
        }

        if (tableProducer == null)
        {
          throw new ReportDataFactoryException("Cannot find the specified transformation step " + stepName);
        }

        currentlyRunningTransformation = trans;
        trans.startThreads();
        trans.waitUntilFinished();
        trans.cleanup();
        return tableProducer.getTableModel();
      }
      finally
      {
        currentlyRunningTransformation = null;
        if (repository != null)
        {
          repository.disconnect();
        }
      }
    }
    finally
    {
View Full Code Here


      // repository object is not necessary for filesystem transformations
      return null;
      // throw new ReportDataFactoryException("The specified repository " + repositoryName + " is not defined.");
    }

    final Repository repository = PluginRegistry.getInstance().loadClass(RepositoryPluginType.class, repositoryMeta.getId(), Repository.class);
    repository.init(repositoryMeta);
    repository.connect(username, password);
    return repository;
  }
View Full Code Here

  }

  public TransMeta loadTransformation(final DataFactoryContext context)
      throws KettleException, ReportDataFactoryException
  {
    final Repository repository = connectToRepository();
    try
    {
      return loadTransformation(repository, context.getResourceManager(), context.getContextKey());
    }
    finally
    {
      currentlyRunningTransformation = null;
      if (repository != null)
      {
        repository.disconnect();
      }
    }
  }
View Full Code Here

    if (stepName == null)
    {
      throw new ReportDataFactoryException("No step name defined.");
    }

    final Repository repository = connectToRepository();
    try
    {
      ResourceManager resourceManager = context.getResourceManager();
      final TransMeta transMeta = loadTransformation(repository, resourceManager, context.getContextKey());
      if (isDynamicTransformation(transMeta))
      {
        // we cannot safely guess columns from transformations that use Metadata-Injection.
        // So lets solve them the traditional way.
        return performQueryOnTransformation(parameter, 1, context, transMeta);
      }

      StepMeta step = transMeta.findStep(stepName);
      if (step == null)
      {
        throw new ReportDataFactoryException("Cannot find the specified transformation step " + stepName);
      }

      final RowMetaInterface row = transMeta.getStepFields(getStepName());
      final TableProducer tableProducer = new TableProducer(row, 1, true);
      return tableProducer.getTableModel();
    }
    catch (final EvaluationException e)
    {
      throw new ReportDataFactoryException("Failed to evaluate parameter", e);
    }
    catch (final ParseException e)
    {
      throw new ReportDataFactoryException("Failed to evaluate parameter", e);
    }
    finally
    {
      if (repository != null)
      {
        repository.disconnect();
      }
    }
  }
View Full Code Here

    if (targetStepName == null)
    {
      throw new ReportDataFactoryException("No step name defined.");
    }

    final Repository repository = connectToRepository();
    try
    {
      final TransMeta transMeta = loadTransformation(repository, context.getResourceManager(), context.getContextKey());
      return performQueryOnTransformation(parameters, queryLimit, context, transMeta);
    }
    catch (final EvaluationException e)
    {
      throw new ReportDataFactoryException("Failed to evaluate parameter", e);
    }
    catch (final ParseException e)
    {
      throw new ReportDataFactoryException("Failed to evaluate parameter", e);
    }
    finally
    {
      if (repository != null)
      {
        repository.disconnect();
      }
    }
  }
View Full Code Here

      // repository object is not necessary for filesystem transformations
      return null;
      // throw new ReportDataFactoryException("The specified repository " + repositoryName + " is not defined.");
    }

    final Repository repository = PluginRegistry.getInstance().loadClass(RepositoryPluginType.class, repositoryMeta.getId(), Repository.class);
    repository.init(repositoryMeta);
    repository.connect(username, password);
    return repository;
  }
View Full Code Here

      error( ke.getMessage(), ke );
    }

    String solutionPath = "solution:";

    Repository repository = connectToRepository();
    boolean result = false;

    try {
      if ( isDefinedInput( KettleComponent.DIRECTORY ) ) {
        String directoryName = getInputStringValue( KettleComponent.DIRECTORY );

        if ( repository == null ) {
          return false;
        }

        if ( isDefinedInput( KettleComponent.TRANSFORMATION ) ) {
          String transformationName = getInputStringValue( KettleComponent.TRANSFORMATION );
          transMeta = loadTransformFromRepository( directoryName, transformationName, repository );
          if ( transMeta != null ) {
            try {
              for ( String key : parameterMap.keySet() ) {
                transMeta.setParameterValue( key, parameterMap.get( key ) );
              }
              for ( String key : variableMap.keySet() ) {
                transMeta.setVariable( key, variableMap.get( key ) );
              }

            } catch ( UnknownParamException e ) {
              error( e.getMessage() );
            }
            transMeta.setArguments( arguments );
          } else {
            return false;
          }
        } else if ( isDefinedInput( KettleComponent.JOB ) ) {
          String jobName = getInputStringValue( KettleComponent.JOB );
          jobMeta = loadJobFromRepository( directoryName, jobName, repository );
          if ( jobMeta != null ) {
            try {
              for ( String key : parameterMap.keySet() ) {
                jobMeta.setParameterValue( key, parameterMap.get( key ) );
              }
              for ( String key : variableMap.keySet() ) {
                jobMeta.setVariable( key, variableMap.get( key ) );
              }

            } catch ( UnknownParamException e ) {
              error( e.getMessage() );
            }
            jobMeta.setArguments( arguments );
          } else {
            return false;
          }
        }
      } else if ( isDefinedResource( KettleComponent.TRANSFORMFILE ) ) {
        IActionSequenceResource transformResource = getResource( KettleComponent.TRANSFORMFILE );
        String fileAddress = getActualFileName( transformResource );

        try {
          if ( fileAddress != null ) { // We have an actual loadable
            // filesystem and file
            transMeta = new TransMeta( fileAddress, repository, true );
            transMeta.setFilename( fileAddress );
          } else if ( repository != null && repository.isConnected() ) {

            fileAddress = transformResource.getAddress();
            // load transformation resource from kettle/settings.xml configured repository
            transMeta = loadTransformFromRepository( FilenameUtils.getPathNoEndSeparator( fileAddress ), FilenameUtils.getBaseName( fileAddress ), repository );
          } else {
            String jobXmlStr = getResourceAsString( getResource( KettleComponent.TRANSFORMFILE ) );
            jobXmlStr = jobXmlStr.replaceAll( "\\$\\{pentaho.solutionpath\\}", solutionPath ); //$NON-NLS-1$
            jobXmlStr = jobXmlStr.replaceAll( "\\%\\%pentaho.solutionpath\\%\\%", solutionPath ); //$NON-NLS-1$
            org.w3c.dom.Document doc = XmlW3CHelper.getDomFromString( jobXmlStr );
            // create a tranformation from the document
            transMeta = new TransMeta( doc.getFirstChild(), repository );
          }
        } catch ( Exception e ) {
          error( Messages.getInstance().getErrorString(
              "Kettle.ERROR_0015_BAD_RESOURCE", KettleComponent.TRANSFORMFILE, fileAddress ), e ); //$NON-NLS-1$
          return false;
        }

        /*
         * Unreachable code below... if (transMeta == null) {
         * error(Messages.getInstance().getErrorString("Kettle.ERROR_0015_BAD_RESOURCE", KettleComponent.TRANSFORMFILE,
         * fileAddress)); //$NON-NLS-1$ debug(getKettleLog(true)); return false; }
         */

        // Don't forget to set the parameters here as well...
        try {
          for ( String key : parameterMap.keySet() ) {
            transMeta.setParameterValue( key, parameterMap.get( key ) );
          }
          for ( String key : variableMap.keySet() ) {
            transMeta.setVariable( key, variableMap.get( key ) );
          }

        } catch ( UnknownParamException e ) {
          error( e.getMessage() );
        }
        transMeta.setArguments( arguments );
        /*
         * We do not need to concatenate the solutionPath info as the fileAddress has the complete location of the file
         * from start to end. This is to resolve BISERVER-502.
         */
        transMeta.setFilename( fileAddress );

      } else if ( isDefinedResource( KettleComponent.JOBFILE ) ) {
        String fileAddress = ""; //$NON-NLS-1$
        try {
          fileAddress = getResource( KettleComponent.JOBFILE ).getAddress();

          if ( repository != null && repository.isConnected() ) {

            solutionPath = StringUtils.EMPTY;

            // load job resource from kettle/settings.xml configured repository
            jobMeta = loadJobFromRepository( FilenameUtils.getPathNoEndSeparator( fileAddress ), FilenameUtils.getBaseName( fileAddress ), repository );

          } else {

            String jobXmlStr = getResourceAsString( getResource( KettleComponent.JOBFILE ) );
            // String jobXmlStr =
            // XmlW3CHelper.getContentFromSolutionResource(fileAddress);
            jobXmlStr = jobXmlStr.replaceAll( "\\$\\{pentaho.solutionpath\\}", solutionPath ); //$NON-NLS-1$
            jobXmlStr = jobXmlStr.replaceAll( "\\%\\%pentaho.solutionpath\\%\\%", solutionPath ); //$NON-NLS-1$
            org.w3c.dom.Document doc = XmlW3CHelper.getDomFromString( jobXmlStr );
            if ( doc == null ) {
              error( Messages.getInstance().getErrorString(
                  "Kettle.ERROR_0015_BAD_RESOURCE", KettleComponent.JOBFILE, fileAddress ) ); //$NON-NLS-1$
              debug( getKettleLog( true ) );
              return false;
            }
            // create a job from the document
            try {
              repository = connectToRepository();
              // if we get a valid repository its great, if not try it
              // without

              jobMeta = new JobMeta( solutionPath + fileAddress, repository );
            } catch ( Exception e ) {
              error( Messages.getInstance().getString( "Kettle.ERROR_0023_NO_META" ), e ); //$NON-NLS-1$
            } finally {
              if ( repository != null ) {
                if ( ComponentBase.debug ) {
                  debug( Messages.getInstance().getString( "Kettle.DEBUG_DISCONNECTING" ) ); //$NON-NLS-1$
                }
                repository.disconnect();
              }
            }
          }
        } catch ( Exception e ) {
          error( Messages.getInstance().getErrorString(
              "Kettle.ERROR_0015_BAD_RESOURCE", KettleComponent.JOBFILE, fileAddress ), e ); //$NON-NLS-1$
          return false;
        }
        if ( jobMeta == null ) {
          error( Messages.getInstance().getErrorString(
              "Kettle.ERROR_0015_BAD_RESOURCE", KettleComponent.JOBFILE, fileAddress ) ); //$NON-NLS-1$
          debug( getKettleLog( true ) );
          return false;
        } else {
          try {
            for ( String key : parameterMap.keySet() ) {
              jobMeta.setParameterValue( key, parameterMap.get( key ) );
            }
            for ( String key : variableMap.keySet() ) {
              jobMeta.setVariable( key, variableMap.get( key ) );
            }

          } catch ( UnknownParamException e ) {
            error( e.getMessage() );
          }
          jobMeta.setArguments( arguments );
          jobMeta.setFilename( solutionPath + fileAddress );
        }

      }

      // OK, we have the information, let's load and execute the
      // transformation or job

      if ( transMeta != null ) {
        result = executeTransformation( transMeta );
      }
      if ( jobMeta != null ) {
        result = executeJob( jobMeta, repository );
      }

    } finally {

      if ( repository != null ) {
        if ( ComponentBase.debug ) {
          debug( Messages.getInstance().getString( "Kettle.DEBUG_DISCONNECTING" ) ); //$NON-NLS-1$
        }
        try {
          repository.disconnect();
        } catch ( Exception ignored ) {
          //ignore
        }
      }

View Full Code Here

      }

      if ( ComponentBase.debug ) {
        debug( Messages.getInstance().getString( "Kettle.DEBUG_GETTING_REPOSITORY" ) ); //$NON-NLS-1$
      }
      Repository repository = null;
      try {

        repository =
            PluginRegistry.getInstance().loadClass( RepositoryPluginType.class, repositoryMeta.getId(),
                Repository.class );
        repository.init( repositoryMeta );

      } catch ( Exception e ) {
        error( Messages.getInstance().getErrorString( "Kettle.ERROR_0016_COULD_NOT_GET_REPOSITORY_INSTANCE" ), e ); //$NON-NLS-1$
        return null;
      }

      // OK, now try the username and password
      if ( ComponentBase.debug ) {
        debug( Messages.getInstance().getString( "Kettle.DEBUG_CONNECTING" ) ); //$NON-NLS-1$
      }
      repository.connect( username, password );

      // OK, the repository is open and ready to use.
      if ( ComponentBase.debug ) {
        debug( Messages.getInstance().getString( "Kettle.DEBUG_FINDING_DIRECTORY" ) ); //$NON-NLS-1$
      }
View Full Code Here

TOP

Related Classes of org.pentaho.di.repository.Repository

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.