org.pentaho.di.core.EngineMetaInterface Java Examples

The following examples show how to use org.pentaho.di.core.EngineMetaInterface. 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: ConnectionEndpoints.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
@PUT
@Path( "/connection" )
@Consumes( { APPLICATION_JSON } )
public Response createConnection( ConnectionDetails connectionDetails, @QueryParam( "name" ) String name ) {
  boolean saved = connectionManager.save( connectionDetails );
  if ( saved ) {
    if ( !connectionDetails.getName().equals( name ) ) {
      connectionManager.delete( name );
    }
    getSpoon().getShell().getDisplay().asyncExec( () -> getSpoon().refreshTree(
      ConnectionFolderProvider.STRING_VFS_CONNECTIONS ) );
    EngineMetaInterface engineMetaInterface = getSpoon().getActiveMeta();
    if ( engineMetaInterface instanceof AbstractMeta ) {
      ( (AbstractMeta) engineMetaInterface ).setChanged();
    }
    return Response.ok().build();
  } else {
    return Response.serverError().build();
  }
}
 
Example #2
Source File: SpoonTest.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
@Test
public void testVersioningEnabled() throws Exception {
  Repository repository = Mockito.mock( Repository.class );
  RepositorySecurityProvider securityProvider = Mockito.mock( RepositorySecurityProvider.class );
  Mockito.doReturn( securityProvider ).when( repository ).getSecurityProvider();
  EngineMetaInterface jobTransMeta = Mockito.spy( new TransMeta() );
  RepositoryDirectoryInterface repositoryDirectoryInterface = Mockito.mock( RepositoryDirectoryInterface.class );
  Mockito.doReturn( "/home" ).when( repositoryDirectoryInterface ).toString();
  Mockito.doReturn( "trans" ).when( jobTransMeta ).getName();
  Mockito.doReturn( RepositoryObjectType.TRANSFORMATION ).when( jobTransMeta ).getRepositoryElementType();
  Mockito.doReturn( true ).when( jobTransMeta ).getVersioningEnabled();

  boolean result = Spoon.isVersionEnabled( repository, jobTransMeta );

  Assert.assertTrue( result );
  Mockito.verify( securityProvider, Mockito.never() ).isVersioningEnabled( Mockito.anyString() );
}
 
Example #3
Source File: SpoonTest.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
@Test
public void testVersioningDisabled() throws Exception {
  Repository repository = Mockito.mock( Repository.class );
  RepositorySecurityProvider securityProvider = Mockito.mock( RepositorySecurityProvider.class );
  Mockito.doReturn( securityProvider ).when( repository ).getSecurityProvider();
  EngineMetaInterface jobTransMeta = Mockito.spy( new TransMeta() );
  RepositoryDirectoryInterface repositoryDirectoryInterface = Mockito.mock( RepositoryDirectoryInterface.class );
  Mockito.doReturn( "/home" ).when( repositoryDirectoryInterface ).toString();
  Mockito.doReturn( "trans" ).when( jobTransMeta ).getName();
  Mockito.doReturn( RepositoryObjectType.TRANSFORMATION ).when( jobTransMeta ).getRepositoryElementType();
  Mockito.doReturn( false ).when( jobTransMeta ).getVersioningEnabled();

  boolean result = Spoon.isVersionEnabled( repository, jobTransMeta );

  Assert.assertFalse( result );
  Mockito.verify( securityProvider, Mockito.never() ).isVersioningEnabled( Mockito.anyString() );
}
 
Example #4
Source File: SpoonTabsDelegate.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
public void tabSelected( TabItem item ) {
  // See which core objects to show
  //
  for ( TabMapEntry entry : tabMap ) {
    boolean isAbstractGraph = ( entry.getObject() instanceof AbstractGraph );
    if ( item.equals( entry.getTabItem() ) ) {
      if ( isAbstractGraph ) {
        EngineMetaInterface meta = entry.getObject().getMeta();
        if ( meta != null ) {
          meta.setInternalKettleVariables();
        }
        if ( spoon.getCoreObjectsState() != SpoonInterface.STATE_CORE_OBJECTS_SPOON ) {
          spoon.refreshCoreObjects();
        }
        ( (AbstractGraph) entry.getObject() ).setFocus();
      }
      break;
    }
  }

  // Also refresh the tree
  spoon.refreshTree();
  spoon.setShellText(); // calls also enableMenus() and markTabsChanged()
}
 
Example #5
Source File: SpoonTabsDelegate.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
public EngineMetaInterface getActiveMeta() {
  TabSet tabfolder = spoon.tabfolder;
  if ( tabfolder == null ) {
    return null;
  }
  TabItem tabItem = tabfolder.getSelected();
  if ( tabItem == null ) {
    return null;
  }

  // What transformation is in the active tab?
  // TransLog, TransGraph & TransHist contain the same transformation
  //
  TabMapEntry mapEntry = getTab( tabfolder.getSelected() );
  EngineMetaInterface meta = null;
  if ( mapEntry != null ) {
    if ( mapEntry.getObject() instanceof TransGraph ) {
      meta = ( mapEntry.getObject() ).getMeta();
    }
    if ( mapEntry.getObject() instanceof JobGraph ) {
      meta = ( mapEntry.getObject() ).getMeta();
    }
  }

  return meta;
}
 
Example #6
Source File: SpoonSharedObjectDelegate.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
protected void saveSharedObjects() {
  try {
    // flush to file for newly opened
    EngineMetaInterface meta = spoon.getActiveMeta();
    if ( meta != null ) {
      meta.saveSharedObjects();
    }
  } catch ( KettleException e ) {
    spoon.getLog().logError( e.getLocalizedMessage(), e );
  }
}
 
Example #7
Source File: EngineMetaUtils.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
/**
 * Validates if {@code engineMetaInterface} is Job or Transformation.
 * 
 * @param engineMetaInterface
 * @return true if engineMetaInterface instance is Job or Transformation, otherwise false.
 */
public static boolean isJobOrTransformation( EngineMetaInterface engineMetaInterface ) {
  if ( engineMetaInterface == null || engineMetaInterface.getRepositoryElementType() == null ) {
    return false;
  }
  RepositoryObjectType objectType = engineMetaInterface.getRepositoryElementType();
  return RepositoryObjectType.TRANSFORMATION.equals( objectType ) || RepositoryObjectType.JOB.equals( objectType );
}
 
Example #8
Source File: RepositoryBrowserController.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
/**
 * Checks if there is a duplicate file in a given directory (i.e. hidden file)
 *
 * @param path     - Path to directory in which we are saving
 * @param name     - Name of file to save
 * @param fileName - Possible duplicate file name
 * @param override - True is user wants override file, false otherwise
 * @return - true if a duplicate file is found, false otherwise
 */
private boolean hasDupeFile( String path, String name, String fileName, boolean override ) {
  try {
    RepositoryDirectoryInterface repositoryDirectoryInterface = getRepository().findDirectory( path );
    EngineMetaInterface meta = getSpoon().getActiveMeta();
    RepositoryObjectType type = "Trans".equals( meta.getFileType() )
      ? RepositoryObjectType.TRANSFORMATION : RepositoryObjectType.JOB;
    if ( getRepository().exists( name, repositoryDirectoryInterface, type ) ) {
      return !override || !name.equals( fileName );
    }
  } catch ( Exception e ) {
    System.out.println( e );
  }
  return false;
}
 
Example #9
Source File: MainSpoonPerspective.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
@Override
public EngineMetaInterface getActiveMeta() {

  if ( tabfolder == null ) {
    return null;
  }

  TabItem tabItem = tabfolder.getSelected();
  if ( tabItem == null ) {
    return null;
  }

  // What transformation is in the active tab?
  // TransLog, TransGraph & TransHist contain the same transformation
  //
  TabMapEntry mapEntry = ( (Spoon) SpoonFactory.getInstance() ).delegates.tabs.getTab( tabfolder.getSelected() );
  EngineMetaInterface meta = null;
  if ( mapEntry != null ) {
    if ( mapEntry.getObject() instanceof TransGraph ) {
      meta = ( mapEntry.getObject() ).getMeta();
    }
    if ( mapEntry.getObject() instanceof JobGraph ) {
      meta = ( mapEntry.getObject() ).getMeta();
    }
  }

  return meta;

}
 
Example #10
Source File: ConnectionDelegate.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
public void delete( String label ) {
  ConnectionDeleteDialog connectionDeleteDialog = new ConnectionDeleteDialog( spoonSupplier.get().getShell() );
  if ( connectionDeleteDialog.open( label ) == SWT.YES ) {
    ConnectionManager connectionManager = ConnectionManager.getInstance();
    connectionManager.delete( label );
    spoonSupplier.get().getShell().getDisplay().asyncExec( () -> spoonSupplier.get().refreshTree(
      ConnectionFolderProvider.STRING_VFS_CONNECTIONS ) );
    EngineMetaInterface engineMetaInterface = spoonSupplier.get().getActiveMeta();
    if ( engineMetaInterface instanceof AbstractMeta ) {
      ( (AbstractMeta) engineMetaInterface ).setChanged();
    }
  }
}
 
Example #11
Source File: SpoonMenuLockController.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
public void updateMenu( Document doc ) {
  try {
    Spoon spoon = Spoon.getInstance();

    // If we are working with an Enterprise Repository
    if ( ( spoon != null ) && ( spoon.getRepository() != null ) && ( spoon.getRepository() instanceof PurRepository ) ) {
      ILockService service = getService( spoon.getRepository() );

      EngineMetaInterface meta = spoon.getActiveMeta();

      // If (meta is not null) and (meta is either a Transformation or Job)
      if ( ( meta != null ) && ( meta instanceof ILockable ) ) {

        RepositoryLock repoLock = null;
        if ( service != null && meta.getObjectId() != null ) {
          if ( meta instanceof EEJobMeta ) {
            repoLock = service.getJobLock( meta.getObjectId() );
          } else {
            repoLock = service.getTransformationLock( meta.getObjectId() );
          }
        }
        // If (there is a lock on this item) and (the UserInfo does not have permission to unlock this file)
        if ( repoLock != null ) {
          if ( !service.canUnlockFileById( meta.getObjectId() ) ) {
            // User does not have modify permissions on this file
            ( (XulToolbarbutton) doc.getElementById( "toolbar-file-save" ) ).setDisabled( true ); //$NON-NLS-1$
            ( (XulMenuitem) doc.getElementById( "file-save" ) ).setDisabled( true ); //$NON-NLS-1$  
          }
        }
      }
    }
  } catch ( Exception e ) {
    throw new RuntimeException( e );
  }
}
 
Example #12
Source File: SpoonLockController.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
protected RepositoryLock fetchRepositoryLock( EngineMetaInterface meta ) throws KettleException {
  RepositoryLock result = null;
  if ( meta != null ) {
    if ( meta.getObjectId() != null ) {
      if ( meta instanceof TransMeta ) {
        result = getService( Spoon.getInstance().getRepository() ).getTransformationLock( meta.getObjectId() );
      } else if ( meta instanceof JobMeta ) {
        result = getService( Spoon.getInstance().getRepository() ).getJobLock( meta.getObjectId() );
      }
    }
  }
  return result;
}
 
Example #13
Source File: SharedObjectSyncUtil.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
private synchronized void synchronizeAll( boolean includeActive, Consumer<AbstractMeta> synchronizeAction  ) {
  EngineMetaInterface current = spoon.getActiveMeta();
  for ( TransMeta trans : spoonDelegates.trans.getLoadedTransformations() ) {
    if ( includeActive || trans != current ) {
      synchronizeAction.accept( trans );
    }
  }
  for ( JobMeta job : spoonDelegates.jobs.getLoadedJobs() ) {
    if ( includeActive || job != current ) {
      synchronizeAction.accept( job );
    }
  }
}
 
Example #14
Source File: SpoonTest.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
@Test
public void testVersioningCheckingOnServer() throws Exception {
  Repository repository = Mockito.mock( Repository.class );
  RepositorySecurityProvider securityProvider = Mockito.mock( RepositorySecurityProvider.class );
  Mockito.doReturn( securityProvider ).when( repository ).getSecurityProvider();
  EngineMetaInterface jobTransMeta = Mockito.spy( new TransMeta() );
  RepositoryDirectoryInterface repositoryDirectoryInterface = Mockito.mock( RepositoryDirectoryInterface.class );
  Mockito.doReturn( "/home" ).when( repositoryDirectoryInterface ).toString();
  Mockito.doReturn( "trans" ).when( jobTransMeta ).getName();
  Mockito.doReturn( RepositoryObjectType.TRANSFORMATION ).when( jobTransMeta ).getRepositoryElementType();
  Mockito.doReturn( true ).when( securityProvider ).isVersioningEnabled( Mockito.anyString() );

  boolean result = Spoon.isVersionEnabled( repository, jobTransMeta );
  Assert.assertTrue( result );
}
 
Example #15
Source File: StarModelerPerspective.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
public boolean exportFile(EngineMetaInterface meta, String filename) {

    try {
      String xml = meta.getXML();
      OutputStream outputStream = KettleVFS.getOutputStream(filename, false);
      outputStream.write(xml.getBytes(Const.XML_ENCODING));
      outputStream.close();

      meta.setFilename(filename);
      return true;
    } catch(Exception e) {
      new ErrorDialog(Spoon.getInstance().getShell(), "Error", "Error export star domain to XML", e);
      return false;
    }
  }
 
Example #16
Source File: StarModelerPerspective.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
@Override
public boolean save(EngineMetaInterface meta, String fname, boolean isExport) {
  try {

    // We only expect a start domain here. How else would we end up here?
    //
    if (meta instanceof StarDomain) {
      StarDomain starDomain = (StarDomain) meta;

      // Make sure we pick the active MetaStore to save to, otherwise it's hard to verify
      //
      IMetaStore metaStore = Spoon.getInstance().metaStore.getActiveMetaStore();

      LogChannel.GENERAL.logBasic("Saving star domain to meta store: "+metaStore.getName());

      // Save the name and description of the shared dimension in the metastore
      //
      StarDomainMetaStoreUtil.saveStarDomain(metaStore, starDomain);

      // Save the shared dimensions in the Spoon IMetaStore (update or create)
      //
      for (LogicalTable sharedDimension : starDomain.getSharedDimensions()) {
        SharedDimensionMetaStoreUtil.saveSharedDimension(metaStore, sharedDimension, defaultLocale);
      }

      meta.clearChanged();
      Spoon.getInstance().enableMenus();

      return true;
    }
  } catch(Exception e) {
    new ErrorDialog(Spoon.getInstance().getShell(), "Error saving model", "There was an error while saving the model:", e);
  }

  return false;
}
 
Example #17
Source File: SpoonTransformationDelegate.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
public void tabSelected( TabItem item ) {
  List<TabMapEntry> collection = spoon.delegates.tabs.getTabs();

  // See which core objects to show
  //
  for ( TabMapEntry entry : collection ) {
    if ( item.equals( entry.getTabItem() ) ) {
      // TabItemInterface itemInterface = entry.getObject();

      //
      // Another way to implement this may be to keep track of the
      // state of the core object tree in method
      // addCoreObjectsToTree()
      //
      if ( entry.getObject() instanceof TransGraph || entry.getObject() instanceof JobGraph ) {
        EngineMetaInterface meta = entry.getObject().getMeta();
        if ( meta != null ) {
          meta.setInternalKettleVariables();
        }
        if ( spoon.getCoreObjectsState() != SpoonInterface.STATE_CORE_OBJECTS_SPOON ) {
          spoon.refreshCoreObjects();
        }
      }
    }
  }

  // Also refresh the tree
  spoon.refreshTree();
  spoon.enableMenus();
}
 
Example #18
Source File: SaveProgressDialog.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new dialog that will handle the wait while saving a transformation...
 */
public SaveProgressDialog( Shell shell, Repository rep, EngineMetaInterface meta, String versionComment ) {
  this.shell = shell;
  this.rep = rep;
  this.meta = meta;
  this.versionComment = versionComment;
}
 
Example #19
Source File: SpoonTabsDelegate.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
public String makeTabName( EngineMetaInterface transMeta, boolean showLocation ) {
  if ( Utils.isEmpty( transMeta.getName() ) && Utils.isEmpty( transMeta.getFilename() ) ) {
    return Spoon.STRING_TRANS_NO_NAME;
  }

  if ( Utils.isEmpty( transMeta.getName() )
    || spoon.delegates.trans.isDefaultTransformationName( transMeta.getName() ) ) {
    transMeta.nameFromFilename();
  }

  String name = "";

  if ( showLocation ) {
    if ( !Utils.isEmpty( transMeta.getFilename() ) ) {
      // Regular file...
      //
      name += transMeta.getFilename() + " : ";
    } else {
      // Repository object...
      //
      name += transMeta.getRepositoryDirectory().getPath() + " : ";
    }
  }

  name += transMeta.getName();
  if ( showLocation ) {
    ObjectRevision version = transMeta.getObjectRevision();
    if ( version != null ) {
      name += " : r" + version.getName();
    }
  }
  return name;
}
 
Example #20
Source File: SpoonTabsDelegate.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
/**
 * Finds the tab for the transformation that matches the metadata provided (either the file must be the same or the
 * repository id).
 *
 * @param trans
 *          Transformation metadata to look for
 * @return Tab with transformation open whose metadata matches {@code trans} or {@code null} if no tab exists.
 * @throws KettleFileException
 *           If there is a problem loading the file object for an open transformation with an invalid a filename.
 */
public TabMapEntry findTabForTransformation( TransMeta trans ) throws KettleFileException {
  // File for the transformation we're looking for. It will be loaded upon first request.
  FileObject transFile = null;
  for ( TabMapEntry entry : tabMap ) {
    if ( entry != null && !entry.getTabItem().isDisposed() ) {
      if ( trans.getFilename() != null && entry.getFilename() != null ) {
        // If the entry has a file name it is the same as trans iff. they originated from the same files
        FileObject entryFile = KettleVFS.getFileObject( entry.getFilename() );
        if ( transFile == null ) {
          transFile = KettleVFS.getFileObject( trans.getFilename() );
        }
        if ( entryFile.equals( transFile ) ) {
          return entry;
        }
      } else if ( trans.getObjectId() != null && entry.getObject() != null ) {
        EngineMetaInterface meta = entry.getObject().getMeta();
        if ( meta != null && trans.getObjectId().equals( meta.getObjectId() ) ) {
          // If the transformation has an object id and the entry shares the same id they are the same
          return entry;
        }
      }
    }
  }
  // No tabs for the transformation exist and are not disposed
  return null;
}
 
Example #21
Source File: RepositoryBrowserController.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
/**
 * Checks if there is a duplicate file in a given directory (i.e. hidden file)
 *
 * @param path     - Path to directory in which we are saving
 * @param name     - Name of file to save
 * @param fileName - Possible duplicate file name
 * @param override - True is user wants override file, false otherwise
 * @return - true if a duplicate file is found, false otherwise
 */
private boolean hasDupeFile( String path, String name, String fileName, boolean override ) {
  try {
    RepositoryDirectoryInterface repositoryDirectoryInterface = getRepository().findDirectory( path );
    EngineMetaInterface meta = getSpoon().getActiveMeta();
    RepositoryObjectType type = "Trans".equals( meta.getFileType() )
      ? RepositoryObjectType.TRANSFORMATION : RepositoryObjectType.JOB;
    if ( getRepository().exists( name, repositoryDirectoryInterface, type ) ) {
      return !override || !name.equals( fileName );
    }
  } catch ( Exception e ) {
    System.out.println( e );
  }
  return false;
}
 
Example #22
Source File: StarModelerPerspective.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
public EngineMetaInterface getActiveMeta() {
  int idx = tabbox.getSelectedIndex();
  if( idx == -1 || idx >= tabbox.getTabs().getChildNodes().size()) {
    return null;
  }
  return metas.get(tabbox.getTabs().getChildNodes().get( idx ));
}
 
Example #23
Source File: RepositoryBrowserController.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
private boolean checkSecurity() {
  EngineMetaInterface meta = getSpoon().getActiveMeta();
  return getSpoon().saveToRepositoryCheckSecurity( meta );
}
 
Example #24
Source File: StarModelerPerspective.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
public void setMetaForTab(XulTab tab, EngineMetaInterface meta){
  metas.put(tab, meta);
}
 
Example #25
Source File: RepositoryBrowserController.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
private boolean checkSecurity() {
  EngineMetaInterface meta = getSpoon().getActiveMeta();
  return getSpoon().saveToRepositoryCheckSecurity( meta );
}
 
Example #26
Source File: StarModelerPerspective.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
@Override
public boolean save(EngineMetaInterface meta) {
  return save(meta, null, false);
}
 
Example #27
Source File: StarModelerPerspective.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
@Override
public void syncMetaName(EngineMetaInterface meta, String name) {
}
 
Example #28
Source File: StarModelerPerspective.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
public void setSelectedMeta(EngineMetaInterface meta){
  EngineMetaInterface prevVal = this.selectedMeta;
  this.selectedMeta = meta;
  Spoon.getInstance().enableMenus();
  firePropertyChange("selectedMeta", prevVal, meta);
}
 
Example #29
Source File: StarModelerPerspective.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
public EngineMetaInterface getSelectedMeta(){
  return selectedMeta;
}
 
Example #30
Source File: BeamPerspective.java    From kettle-beam with Apache License 2.0 4 votes vote down vote up
@Override public EngineMetaInterface getActiveMeta() {
  return null;
}