Java Code Examples for org.pentaho.di.repository.RepositoryDirectoryInterface#findChild()

The following examples show how to use org.pentaho.di.repository.RepositoryDirectoryInterface#findChild() . 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: KettleDatabaseRepositoryDirectoryDelegate.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
/**
 * Create a new directory, possibly by creating several sub-directies of / at the same time.
 *
 * @param parentDirectory
 *          the parent directory
 * @param directoryPath
 *          The path to the new Repository Directory, to be created.
 * @return The created sub-directory
 * @throws KettleException
 *           In case something goes wrong
 */
public RepositoryDirectoryInterface createRepositoryDirectory( RepositoryDirectoryInterface parentDirectory,
  String directoryPath ) throws KettleException {

  // RepositoryDirectoryInterface refreshedParentDir =
  // repository.loadRepositoryDirectoryTree().findDirectory(parentDirectory.getPath());

  RepositoryDirectoryInterface refreshedParentDir = parentDirectory;
  String[] path = Const.splitPath( directoryPath, RepositoryDirectory.DIRECTORY_SEPARATOR );

  RepositoryDirectoryInterface parent = refreshedParentDir;
  for ( int level = 0; level < path.length; level++ ) {

    RepositoryDirectoryInterface rd = parent.findChild( path[level] );
    if ( rd == null ) {
      // This child directory doesn't exists, let's add it!
      //
      rd = new RepositoryDirectory( parent, path[level] );
      saveRepositoryDirectory( rd );

      // Don't forget to add this directory to the tree!
      //
      parent.addSubdirectory( rd );

      parent = rd;
    } else {
      parent = rd;
    }
  }
  return parent;
}
 
Example 2
Source File: PurRepository.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
@Override
public RepositoryDirectoryInterface createRepositoryDirectory( final RepositoryDirectoryInterface parentDirectory,
                                                               final String directoryPath ) throws KettleException {
  // allow new folders only inside Home and Public directory, else - provide UI message
  try {
    // if parentDirectory is root then we have to check if the defined directory is valid ( only Public and Home folders are allowed )
    if ( parentDirectory.isRoot()
      &&
        ( directoryPath.equals( Import.ROOT_DIRECTORY )
          ||
        ( !directoryPath.startsWith( Import.HOME_DIRECTORY ) && !directoryPath.startsWith( Import.PUBLIC_DIRECTORY ) )
        ) ) {
      throw new KettleException( BaseMessages.getString( PKG, "PurRepository.invalidRepositoryDirectory", directoryPath ) );
    }

    RepositoryDirectoryInterface refreshedParentDir = findDirectory( parentDirectory.getPath() );

    // update the passed in repository directory with the children recently loaded from the repo
    parentDirectory.setChildren( refreshedParentDir.getChildren() );
    String[] path = Const.splitPath( directoryPath, RepositoryDirectory.DIRECTORY_SEPARATOR );

    RepositoryDirectoryInterface follow = parentDirectory;

    for ( int level = 0; level < path.length; level++ ) {
      RepositoryDirectoryInterface child = follow.findChild( path[level] );
      if ( child == null ) {
        // create this one
        child = new RepositoryDirectory( follow, path[level] );
        saveRepositoryDirectory( child );
        // link this with the parent directory
        follow.addSubdirectory( child );
      }

      follow = child;
    }
    return follow;
  } catch ( Exception e ) {
    throw new KettleException( "Unable to create directory with path [" + directoryPath + "]", e );
  }
}
 
Example 3
Source File: RepositoryBrowserController.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
public ObjectId rename( String id, String path, String newName, String type, String oldName ) throws KettleException {
  RepositoryDirectoryInterface repositoryDirectoryInterface = findDirectory( path );
  ObjectId objectId = null;
  switch ( type ) {
    case JOB:
      if ( getRepository().exists( newName, repositoryDirectoryInterface, RepositoryObjectType.JOB ) ) {
        throw new KettleObjectExistsException();
      }
      if ( isJobOpened( id, path, oldName ) ) {
        throw new KettleJobException();
      }
      renameRecent( id, type, newName );
      objectId = getRepository().renameJob( () -> id, repositoryDirectoryInterface, newName );
      break;
    case TRANSFORMATION:
      if ( getRepository().exists( newName, repositoryDirectoryInterface, RepositoryObjectType.TRANSFORMATION ) ) {
        throw new KettleObjectExistsException();
      }
      if ( isTransOpened( id, path, oldName ) ) {
        throw new KettleTransException();
      }
      renameRecent( id, type, newName );
      objectId = getRepository().renameTransformation( () -> id, repositoryDirectoryInterface, newName );
      break;
    case FOLDER:
      isFileOpenedInFolder( path );
      RepositoryDirectoryInterface parent = findDirectory( path ).getParent();
      if ( parent == null ) {
        parent = findDirectory( path );
      }
      RepositoryDirectoryInterface child = parent.findChild( newName );
      if ( child != null ) {
        throw new KettleObjectExistsException();
      }
      if ( getRepository() instanceof RepositoryExtended ) {
        objectId =
          ( (RepositoryExtended) getRepository() ).renameRepositoryDirectory( () -> id, null, newName, true );
      } else {
        objectId = getRepository().renameRepositoryDirectory( () -> id, null, newName );
      }
      break;
  }
  return objectId;
}
 
Example 4
Source File: RepositoryFileProvider.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
public RepositoryFile doRename( RepositoryFile file, String newName ) throws KettleException {
  RepositoryDirectoryInterface repositoryDirectoryInterface = findDirectory( file.getParent() );
  ObjectId objectId = null;
  switch ( file.getType() ) {
    case JOB:
      if ( getRepository().exists( newName, repositoryDirectoryInterface, RepositoryObjectType.JOB ) ) {
        throw new KettleObjectExistsException();
      }
      if ( isJobOpened( file.getObjectId(), file.getParent(), file.getName() ) ) {
        throw new KettleJobException();
      }
      objectId = getRepository().renameJob( file::getObjectId, repositoryDirectoryInterface, newName );
      break;
    case TRANSFORMATION:
      if ( getRepository().exists( newName, repositoryDirectoryInterface, RepositoryObjectType.TRANSFORMATION ) ) {
        throw new KettleObjectExistsException();
      }
      if ( isTransOpened( file.getObjectId(), file.getParent(), file.getName() ) ) {
        throw new KettleJobException();
      }
      objectId = getRepository().renameTransformation( file::getObjectId, repositoryDirectoryInterface, newName );
      break;
    case FOLDER:
      isFileOpenedInFolder( file.getPath() );
      RepositoryDirectoryInterface parent = findDirectory( file.getPath() ).getParent();
      if ( parent == null ) {
        parent = findDirectory( file.getPath() );
      }
      RepositoryDirectoryInterface child = parent.findChild( newName );
      if ( child != null ) {
        throw new KettleObjectExistsException();
      }
      if ( getRepository() instanceof RepositoryExtended ) {
        objectId =
          ( (RepositoryExtended) getRepository() )
            .renameRepositoryDirectory( file::getObjectId, null, newName, true );
      } else {
        objectId = getRepository().renameRepositoryDirectory( file::getObjectId, null, newName );
      }
      break;
  }
  RepositoryFile repositoryFile = new RepositoryFile();
  return repositoryFile;
}