use of org.pentaho.di.repository.ObjectId in project pentaho-kettle by pentaho.
the class RepositoryExplorerDialog method exportTransformations.
public void exportTransformations(RepositoryDirectoryInterface root) {
try {
DirectoryDialog dialog = new DirectoryDialog(shell, SWT.OPEN);
if (dialog.open() != null) {
String directory = dialog.getFilterPath();
ObjectId[] dirids = ((root == null) ? directoryTree : root).getDirectoryIDs();
for (int d = 0; d < dirids.length; d++) {
RepositoryDirectoryInterface repdir = directoryTree.findDirectory(dirids[d]);
String[] trans = rep.getTransformationNames(dirids[d], false);
// See if the directory exists...
File dir = new File(directory + repdir.getPath());
if (!dir.exists()) {
dir.mkdir();
log.logBasic("Exporting transformation", "Created directory [" + dir.getName() + "]");
}
for (int i = 0; i < trans.length; i++) {
// reads last version
TransMeta ti = rep.loadTransformation(trans[i], repdir, null, true, null);
if (log.isBasic()) {
log.logBasic("Exporting transformation", "[" + trans[i] + "] in directory [" + repdir.getPath() + "]");
}
String xml = XMLHandler.getXMLHeader() + ti.getXML();
String filename = directory + repdir.getPath() + Const.FILE_SEPARATOR + fixFileName(trans[i]) + ".ktr";
File f = new File(filename);
try {
FileOutputStream fos = new FileOutputStream(f);
fos.write(xml.getBytes(Const.XML_ENCODING));
fos.close();
} catch (IOException e) {
throw new RuntimeException("Exporting transformation: Couldn't create file [" + filename + "]", e);
}
}
}
}
} catch (Exception e) {
new ErrorDialog(shell, BaseMessages.getString(PKG, "RepositoryExplorerDialog.ExportTrans.UnexpectedError.Title"), BaseMessages.getString(PKG, "RepositoryExplorerDialog.ExportTrans.UnexpectedError.Message"), e);
}
}
use of org.pentaho.di.repository.ObjectId in project pentaho-kettle by pentaho.
the class RepositoryExplorerDialog method newDatabase.
public void newDatabase() {
try {
DatabaseMeta databaseMeta = new DatabaseMeta();
databaseMeta.initializeVariablesFrom(null);
getDatabaseDialog().setDatabaseMeta(databaseMeta);
String name = getDatabaseDialog().open();
if (name != null) {
// See if this user already exists...
ObjectId idDatabase = rep.getDatabaseID(name);
if (idDatabase == null) {
rep.insertLogEntry("Creating new database '" + databaseMeta.getName() + "'");
rep.save(databaseMeta, Const.VERSION_COMMENT_INITIAL_VERSION, null);
} else {
MessageBox mb = new MessageBox(shell, SWT.ICON_ERROR | SWT.OK);
mb.setMessage(BaseMessages.getString(PKG, "RepositoryExplorerDialog.Connection.Create.AlreadyExists.Message"));
mb.setText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.Connection.Create.AlreadyExists.Title"));
mb.open();
}
// Refresh tree...
refreshTree();
}
} catch (KettleException e) {
new ErrorDialog(shell, BaseMessages.getString(PKG, "RepositoryExplorerDialog.Connection.Create.UnexpectedError.Title"), BaseMessages.getString(PKG, "RepositoryExplorerDialog.Connection.Create.UnexpectedError.Message"), e);
}
}
use of org.pentaho.di.repository.ObjectId in project pentaho-kettle by pentaho.
the class JsonInputMetaTest method verifyReadingRepoSetsAcceptFilenames.
@Test
public void verifyReadingRepoSetsAcceptFilenames() throws Exception {
ObjectId objectId = () -> "id";
when(repository.getStepAttributeBoolean(objectId, "IsInFields")).thenReturn(true);
jsonInputMeta.readRep(repository, null, objectId, null);
assertTrue(jsonInputMeta.isInFields());
assertTrue(jsonInputMeta.inputFiles.acceptingFilenames);
}
use of org.pentaho.di.repository.ObjectId in project pentaho-kettle by pentaho.
the class PurRepository method deleteDatabaseMeta.
@Override
public void deleteDatabaseMeta(final String databaseName) throws KettleException {
RepositoryFile fileToDelete = null;
ObjectId idDatabase = null;
try {
readWriteLock.writeLock().lock();
try {
fileToDelete = pur.getFile(getPath(databaseName, null, RepositoryObjectType.DATABASE));
idDatabase = new StringObjectId(fileToDelete.getId().toString());
permanentlyDeleteSharedObject(idDatabase);
removeFromSharedObjectCache(RepositoryObjectType.DATABASE, idDatabase);
} finally {
readWriteLock.writeLock().unlock();
}
} catch (Exception e) {
throw new KettleException("Unable to delete database with name [" + databaseName + "]", e);
}
}
use of org.pentaho.di.repository.ObjectId in project pentaho-kettle by pentaho.
the class PurRepository method getDatabaseID.
@Override
public ObjectId getDatabaseID(final String name) throws KettleException {
try {
ObjectId objectId = getObjectId(name, null, RepositoryObjectType.DATABASE, false);
if (objectId == null) {
List<RepositoryFile> allDatabases = getAllFilesOfType(null, RepositoryObjectType.DATABASE, false);
String[] existingNames = new String[allDatabases.size()];
for (int i = 0; i < allDatabases.size(); i++) {
RepositoryFile file = allDatabases.get(i);
existingNames[i] = file.getTitle();
}
int index = DatabaseMeta.indexOfName(existingNames, name);
if (index != -1) {
return new StringObjectId(allDatabases.get(index).getId().toString());
}
}
return objectId;
} catch (Exception e) {
throw new KettleException("Unable to get ID for database [" + name + "]", e);
}
}
Aggregations