Java Code Examples for org.pentaho.di.job.JobMeta#setFilename()

The following examples show how to use org.pentaho.di.job.JobMeta#setFilename() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: KettleFileRepository.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
@Override
public JobMeta loadJob( String jobname, RepositoryDirectoryInterface repdir, ProgressMonitorListener monitor,
  String versionName ) throws KettleException {

  // This is a standard load of a transformation serialized in XML...
  //
  String filename = calcDirectoryName( repdir ) + jobname + EXT_JOB;
  JobMeta jobMeta = new JobMeta( filename, this );
  jobMeta.setFilename( null );
  jobMeta.setName( jobname );
  jobMeta.setObjectId( new StringObjectId( calcObjectId( repdir, jobname, EXT_JOB ) ) );

  jobMeta.setRepository( this );
  jobMeta.setMetaStore( getMetaStore() );

  readDatabases( jobMeta, true );
  jobMeta.clearChanged();

  return jobMeta;

}
 
Example 2
Source File: JobEntryJobDialog.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
private boolean askToCreateNewJob( String prevName ) {
  MessageBox mb = new MessageBox( shell, SWT.YES | SWT.NO | SWT.ICON_QUESTION );
  mb.setMessage( BaseMessages.getString( PKG, "JobJob.Dialog.CreateJobQuestion.Message" ) );
  mb.setText( BaseMessages.getString( PKG, "JobJob.Dialog.CreateJobQuestion.Title" ) );
  int answer = mb.open();
  if ( answer == SWT.YES ) {
    Spoon spoon = Spoon.getInstance();
    spoon.newJobFile();
    JobMeta newJobMeta = spoon.getActiveJob();
    newJobMeta.initializeVariablesFrom( jobEntry );
    newJobMeta.setFilename( jobMeta.environmentSubstitute( prevName ) );
    wPath.setText( prevName );
    specificationMethod = ObjectLocationSpecificationMethod.FILENAME;
    spoon.saveFile();
    return true;
  }
  return false;
}
 
Example 3
Source File: PurRepository.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
private JobMeta buildJobMeta( final RepositoryFile file, final RepositoryDirectoryInterface parentDir,
                              final NodeRepositoryFileData data, final ObjectRevision revision )
  throws KettleException {
  JobMeta jobMeta = new JobMeta();
  jobMeta.setName( file.getTitle() );
  jobMeta.setFilename( file.getName() );
  jobMeta.setDescription( file.getDescription() );
  jobMeta.setObjectId( new StringObjectId( file.getId().toString() ) );
  jobMeta.setObjectRevision( revision );
  jobMeta.setRepository( this );
  jobMeta.setRepositoryDirectory( parentDir );
  jobMeta.setMetaStore( getMetaStore() );
  readJobMetaSharedObjects( jobMeta ); // This should read from the local cache
  jobDelegate.dataNodeToElement( data.getNode(), jobMeta );
  jobMeta.clearChanged();
  return jobMeta;
}
 
Example 4
Source File: SharedObjectSyncUtilTest.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
private JobMeta createJobMeta() throws Exception {
    JobMeta jobMeta = new JobMeta();
    jobMeta.setName( UUID.randomUUID().toString() );
    jobMeta.setFilename( UUID.randomUUID().toString() );
    jobMeta.setRepositoryDirectory( mock( RepositoryDirectory.class ) );
//    jobMeta.setSharedObjectsFile( SHARED_OBJECTS_FILE );
    initSharedObjects( jobMeta, SHARED_OBJECTS_FILE );
    when( spoon.getActiveMeta() ).thenReturn( jobMeta );
    return jobMeta;
  }
 
Example 5
Source File: KettleFileRepositoryIT.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
private void verifyJobSamples( RepositoryDirectoryInterface samplesDirectory ) throws Exception {
  FileObject jobSamplesFolder = KettleVFS.getFileObject( "samples/jobs/" );
  FileObject[] files = jobSamplesFolder.findFiles( new FileSelector() {

    @Override
    public boolean traverseDescendents( FileSelectInfo arg0 ) throws Exception {
      return true;
    }

    @Override
    public boolean includeFile( FileSelectInfo info ) throws Exception {
      return info.getFile().getName().getExtension().equalsIgnoreCase( "kjb" );
    }
  } );

  List<FileObject> filesList = Arrays.asList( files );
  Collections.sort( filesList, new Comparator<FileObject>() {
    @Override
    public int compare( FileObject o1, FileObject o2 ) {
      return o1.getName().getPath().compareTo( o2.getName().getPath() );
    }
  } );

  for ( FileObject file : filesList ) {
    String jobFilename = file.getName().getPath();
    System.out.println( "Storing/Loading/validating job '" + jobFilename + "'" );

    // Load the JobMeta object...
    //
    JobMeta jobMeta = new JobMeta( jobFilename, repository );
    jobMeta.setFilename( null );

    // The name is sometimes empty in the file, duplicates are present too...
    // Replaces slashes and the like as well...
    //
    jobMeta.setName( Const.createName( file.getName().getBaseName() ) );
    jobMeta.setName( jobMeta.getName().replace( '/', '-' ) );

    if ( Utils.isEmpty( jobMeta.getName() ) ) {
      jobMeta.setName( Const.createName( file.getName().getBaseName() ) );
    }
    if ( jobMeta.getName().contains( "/" ) ) {
      jobMeta.setName( jobMeta.getName().replace( '/', '-' ) );
    }

    // Save it in the repository in the samples folder
    //
    jobMeta.setRepositoryDirectory( samplesDirectory );
    repository.save( jobMeta, "unit testing" );
    assertNotNull( jobMeta.getObjectId() );

    // Load it back up again...
    //
    JobMeta repJobMeta = repository.loadJob( jobMeta.getObjectId(), null );
    String oneXml = repJobMeta.getXML();

    // Save & load it again
    //
    repository.save( jobMeta, "unit testing" );
    repJobMeta = repository.loadJob( jobMeta.getObjectId(), null );
    String twoXml = repJobMeta.getXML();

    // The XML needs to be identical after loading
    //
    // storeFile(oneXml, "/tmp/one.ktr");
    // storeFile(twoXml, "/tmp/two.ktr");
    //
    assertEquals( oneXml, twoXml );
  }

  // Verify the number of stored files, see if we can find them all again.
  //
  System.out.println( "Stored " + files.length + " job samples in folder " + samplesDirectory.getPath() );
  String[] jobNames = repository.getJobNames( samplesDirectory.getObjectId(), false );
  assertEquals( files.length, jobNames.length );
}
 
Example 6
Source File: JobEntryJob.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
/**
 * Exports the object to a flat-file system, adding content with filename keys to a set of definitions. The supplied
 * resource naming interface allows the object to name appropriately without worrying about those parts of the
 * implementation specific details.
 *
 * @param space
 *          The variable space to resolve (environment) variables with.
 * @param definitions
 *          The map containing the filenames and content
 * @param namingInterface
 *          The resource naming interface allows the object to be named appropriately
 * @param repository
 *          The repository to load resources from
 * @param metaStore
 *          the metaStore to load external metadata from
 *
 * @return The filename for this object. (also contained in the definitions map)
 * @throws KettleException
 *           in case something goes wrong during the export
 */
@Override
public String exportResources( VariableSpace space, Map<String, ResourceDefinition> definitions,
  ResourceNamingInterface namingInterface, Repository repository, IMetaStore metaStore ) throws KettleException {
  // Try to load the transformation from repository or file.
  // Modify this recursively too...
  //
  // AGAIN: there is no need to clone this job entry because the caller is
  // responsible for this.
  //
  // First load the job meta data...
  //
  copyVariablesFrom( space ); // To make sure variables are available.
  JobMeta jobMeta = getJobMeta( repository, metaStore, space );

  // Also go down into the job and export the files there. (going down
  // recursively)
  //
  String proposedNewFilename =
    jobMeta.exportResources( jobMeta, definitions, namingInterface, repository, metaStore );

  // To get a relative path to it, we inject
  // ${Internal.Entry.Current.Directory}
  //
  String newFilename = "${" + Const.INTERNAL_VARIABLE_ENTRY_CURRENT_DIRECTORY + "}/" + proposedNewFilename;

  // Set the filename in the job
  //
  jobMeta.setFilename( newFilename );

  // exports always reside in the root directory, in case we want to turn this
  // into a file repository...
  //
  jobMeta.setRepositoryDirectory( new RepositoryDirectory() );

  // export to filename ALWAYS (this allows the exported XML to be executed remotely)
  //
  setSpecificationMethod( ObjectLocationSpecificationMethod.FILENAME );

  // change it in the job entry
  //
  filename = newFilename;

  return proposedNewFilename;
}
 
Example 7
Source File: JobExecutorMeta.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
@Override
public String exportResources( VariableSpace space, Map<String, ResourceDefinition> definitions,
  ResourceNamingInterface resourceNamingInterface, Repository repository, IMetaStore metaStore ) throws KettleException {
  try {
    // Try to load the transformation from repository or file.
    // Modify this recursively too...
    //
    // NOTE: there is no need to clone this step because the caller is
    // responsible for this.
    //
    // First load the executor job metadata...
    //
    JobMeta executorJobMeta = loadJobMetaProxy( this, repository, space );

    // Also go down into the mapping transformation and export the files
    // there. (mapping recursively down)
    //
    String proposedNewFilename =
      executorJobMeta.exportResources(
        executorJobMeta, definitions, resourceNamingInterface, repository, metaStore );

    // To get a relative path to it, we inject
    // ${Internal.Entry.Current.Directory}
    //
    String newFilename =
      "${" + Const.INTERNAL_VARIABLE_ENTRY_CURRENT_DIRECTORY + "}/" + proposedNewFilename;

    // Set the correct filename inside the XML.
    //
    executorJobMeta.setFilename( newFilename );

    // exports always reside in the root directory, in case we want to turn
    // this into a file repository...
    //
    executorJobMeta.setRepositoryDirectory( new RepositoryDirectory() );

    // change it in the job entry
    //
    fileName = newFilename;

    setSpecificationMethod( ObjectLocationSpecificationMethod.FILENAME );

    return proposedNewFilename;
  } catch ( Exception e ) {
    throw new KettleException( BaseMessages.getString(
      PKG, "JobExecutorMeta.Exception.UnableToLoadJob", fileName ) );
  }
}
 
Example 8
Source File: JobFileListener.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
public boolean open( Node jobNode, String fname, String connection, boolean importfile ) {
  Spoon spoon = Spoon.getInstance();
  try {
    // Call extension point(s) before the file has been opened
    ExtensionPointHandler.callExtensionPoint( spoon.getLog(), KettleExtensionPoint.JobBeforeOpen.id, fname );

    JobMeta jobMeta = new JobMeta();
    jobMeta.loadXML( jobNode, fname, spoon.getRepository(), spoon.getMetaStore(), false, spoon );
    if ( jobMeta.hasMissingPlugins() ) {
      MissingEntryDialog missingDialog = new MissingEntryDialog( spoon.getShell(), jobMeta.getMissingEntries() );
      if ( missingDialog.open() == null ) {
        return true;
      }
    }
    if ( jobMeta.getRepositoryDirectory() == null || !importfile ) {
      jobMeta.setRepositoryDirectory( spoon.getDefaultSaveLocation( jobMeta ) );
    }
    jobMeta.setRepository( spoon.getRepository() );
    jobMeta.setMetaStore( spoon.getMetaStore() );
    if ( connection != null ) {
      jobMeta.setVariable( Spoon.CONNECTION, connection );
    }
    spoon.setJobMetaVariables( jobMeta );
    spoon.getProperties()
      .addLastFile( LastUsedFile.FILE_TYPE_JOB, fname, null, false, null, null, new Date(), connection );
    spoon.addMenuLast();

    // If we are importing into a repository we need to fix 
    // up the references to other jobs and transformations
    // if any exist.
    if ( importfile ) {
      if ( spoon.getRepository() != null ) {
        jobMeta = fixLinks( jobMeta );
      }
    } else {
      jobMeta.clearChanged();
    }

    jobMeta.setFilename( fname );
    spoon.delegates.jobs.addJobGraph( jobMeta );

    // Call extension point(s) now that the file has been opened
    ExtensionPointHandler.callExtensionPoint( spoon.getLog(), KettleExtensionPoint.JobAfterOpen.id, jobMeta );

    spoon.refreshTree();
    SpoonPerspectiveManager.getInstance().activatePerspective( MainSpoonPerspective.class );
    return true;
  } catch ( KettleException e ) {
    new ErrorDialog(
      spoon.getShell(), BaseMessages.getString( PKG, "Spoon.Dialog.ErrorOpening.Title" ), BaseMessages
      .getString( PKG, "Spoon.Dialog.ErrorOpening.Message" )
      + fname, e );
  }
  return false;
}