use of org.pentaho.di.repository.RepositoryDirectory in project pentaho-kettle by pentaho.
the class KettleDatabaseRepositoryDirectoryDelegate method renameDirectory.
/**
* Move / rename a directory in the repository
*
* @param id_directory
* Id of the directory to be moved/renamed
* @param id_directory_parent
* Id of the new parent directory (null if the parent does not change)
* @param newName
* New name for this directory (null if the name does not change)
* @throws KettleException
*/
public synchronized void renameDirectory(ObjectId id_directory, ObjectId id_directory_parent, String newName) throws KettleException {
if (id_directory.equals(id_directory_parent)) {
// Make sure the directory cannot become its own parent
throw new KettleException("Failed to copy directory into itself");
} else {
// Make sure the directory does not become a descendant of itself
RepositoryDirectory rd = new RepositoryDirectory();
loadRepositoryDirectory(rd, id_directory);
if (rd.findDirectory(id_directory_parent) != null) {
// The parent directory is a child of this directory. Do not proceed
throw new KettleException("Directory cannot become a child to itself");
} else {
// Check for duplication
RepositoryDirectory newParent = new RepositoryDirectory();
loadRepositoryDirectory(newParent, id_directory_parent);
RepositoryDirectory child = newParent.findChild(newName == null ? rd.getName() : newName);
if (child != null) {
throw new KettleException("Destination directory already contains a diectory with requested name");
}
}
}
if (id_directory_parent != null || newName != null) {
RowMetaAndData r = new RowMetaAndData();
String sql = "UPDATE " + quoteTable(KettleDatabaseRepository.TABLE_R_DIRECTORY) + " SET ";
boolean additionalParameter = false;
if (newName != null) {
additionalParameter = true;
sql += quote(KettleDatabaseRepository.FIELD_DIRECTORY_DIRECTORY_NAME) + " = ?";
r.addValue(new ValueMetaString(KettleDatabaseRepository.FIELD_DIRECTORY_DIRECTORY_NAME), newName);
}
if (id_directory_parent != null) {
// Add a parameter separator if the first parm was added
if (additionalParameter) {
sql += ", ";
}
sql += quote(KettleDatabaseRepository.FIELD_DIRECTORY_ID_DIRECTORY_PARENT) + " = ?";
r.addValue(new ValueMetaInteger(KettleDatabaseRepository.FIELD_DIRECTORY_ID_DIRECTORY_PARENT), id_directory_parent);
}
sql += " WHERE " + quote(KettleDatabaseRepository.FIELD_DIRECTORY_ID_DIRECTORY) + " = ? ";
r.addValue(new ValueMetaInteger("id_directory"), Long.valueOf(id_directory.toString()));
repository.connectionDelegate.getDatabase().execStatement(sql, r.getRowMeta(), r.getData());
}
}
use of org.pentaho.di.repository.RepositoryDirectory in project pentaho-kettle by pentaho.
the class JobExecutorMeta method exportResources.
@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));
}
}
Aggregations