use of org.pentaho.di.repository.StringObjectId in project pentaho-kettle by pentaho.
the class PurRepository method loadTransformation.
@Override
public TransMeta loadTransformation(final String transName, final RepositoryDirectoryInterface parentDir, final ProgressMonitorListener monitor, final boolean setInternalVariables, final String versionId) throws KettleException {
String absPath = null;
try {
// by the user
if (StringUtils.isBlank(transName)) {
throw new KettleFileException(BaseMessages.getString(PKG, "PurRepository.ERROR_0007_TRANSFORMATION_NAME_MISSING"));
}
try {
absPath = getPath(transName, parentDir, RepositoryObjectType.TRANSFORMATION);
} catch (Exception e) {
// ignore and handle null value below
}
// variable that is not available at runtime
if (StringUtils.isBlank(absPath)) {
// Couldn't resolve path, throw an exception
throw new KettleFileException(BaseMessages.getString(PKG, "PurRepository.ERROR_0008_TRANSFORMATION_PATH_INVALID", transName));
}
RepositoryFile file = pur.getFile(absPath);
if (versionId != null) {
// need to go back to server to get versioned info
file = pur.getFileAtVersion(file.getId(), versionId);
}
// valid file
if (file == null) {
throw new KettleException(BaseMessages.getString(PKG, "PurRepository.ERROR_0008_TRANSFORMATION_PATH_INVALID", absPath));
}
NodeRepositoryFileData data = null;
ObjectRevision revision = null;
// Additional obfuscation through obscurity
data = pur.getDataAtVersionForRead(file.getId(), versionId, NodeRepositoryFileData.class);
revision = getObjectRevision(new StringObjectId(file.getId().toString()), versionId);
TransMeta transMeta = buildTransMeta(file, parentDir, data, revision);
ExtensionPointHandler.callExtensionPoint(log, KettleExtensionPoint.TransformationMetaLoaded.id, transMeta);
return transMeta;
} catch (final KettleException ke) {
// if we have a KettleException, simply re-throw it
throw ke;
} catch (Exception e) {
throw new KettleException("Unable to load transformation from path [" + absPath + "]", e);
}
}
use of org.pentaho.di.repository.StringObjectId in project pentaho-kettle by pentaho.
the class PurRepository method getObjectId.
/**
* Copying the behavior of the original JCRRepository, this implementation returns IDs of deleted objects too.
*/
private ObjectId getObjectId(final String name, final RepositoryDirectoryInterface dir, final RepositoryObjectType objectType, boolean includedDeleteFiles) {
final String absPath = getPath(name, dir, objectType);
RepositoryFile file = pur.getFile(absPath);
if (file != null) {
// file exists
return new StringObjectId(file.getId().toString());
} else if (includedDeleteFiles) {
switch(objectType) {
case DATABASE:
{
// file either never existed or has been deleted
List<RepositoryFile> deletedChildren = pur.getDeletedFiles(getDatabaseMetaParentFolderPath(), name + RepositoryObjectType.DATABASE.getExtension());
if (!deletedChildren.isEmpty()) {
return new StringObjectId(deletedChildren.get(0).getId().toString());
} else {
return null;
}
}
case TRANSFORMATION:
{
// file either never existed or has been deleted
List<RepositoryFile> deletedChildren = pur.getDeletedFiles(dir.getObjectId().getId(), name + RepositoryObjectType.TRANSFORMATION.getExtension());
if (!deletedChildren.isEmpty()) {
return new StringObjectId(deletedChildren.get(0).getId().toString());
} else {
return null;
}
}
case PARTITION_SCHEMA:
{
// file either never existed or has been deleted
List<RepositoryFile> deletedChildren = pur.getDeletedFiles(getPartitionSchemaParentFolderPath(), name + RepositoryObjectType.PARTITION_SCHEMA.getExtension());
if (!deletedChildren.isEmpty()) {
return new StringObjectId(deletedChildren.get(0).getId().toString());
} else {
return null;
}
}
case SLAVE_SERVER:
{
// file either never existed or has been deleted
List<RepositoryFile> deletedChildren = pur.getDeletedFiles(getSlaveServerParentFolderPath(), name + RepositoryObjectType.SLAVE_SERVER.getExtension());
if (!deletedChildren.isEmpty()) {
return new StringObjectId(deletedChildren.get(0).getId().toString());
} else {
return null;
}
}
case CLUSTER_SCHEMA:
{
// file either never existed or has been deleted
List<RepositoryFile> deletedChildren = pur.getDeletedFiles(getClusterSchemaParentFolderPath(), name + RepositoryObjectType.CLUSTER_SCHEMA.getExtension());
if (!deletedChildren.isEmpty()) {
return new StringObjectId(deletedChildren.get(0).getId().toString());
} else {
return null;
}
}
case JOB:
{
// file either never existed or has been deleted
List<RepositoryFile> deletedChildren = pur.getDeletedFiles(dir.getObjectId().getId(), name + RepositoryObjectType.JOB.getExtension());
if (!deletedChildren.isEmpty()) {
return new StringObjectId(deletedChildren.get(0).getId().toString());
} else {
return null;
}
}
default:
{
throw new UnsupportedOperationException("not implemented");
}
}
} else {
return null;
}
}
use of org.pentaho.di.repository.StringObjectId in project pentaho-kettle by pentaho.
the class PurRepository method deleteDatabaseMeta.
@Override
public void deleteDatabaseMeta(final String databaseName) throws KettleException {
RepositoryFile fileToDelete = null;
try {
fileToDelete = pur.getFile(getPath(databaseName, null, RepositoryObjectType.DATABASE));
} catch (Exception e) {
throw new KettleException("Unable to delete database with name [" + databaseName + "]", e);
}
ObjectId idDatabase = new StringObjectId(fileToDelete.getId().toString());
permanentlyDeleteSharedObject(idDatabase);
removeFromSharedObjectCache(RepositoryObjectType.DATABASE, idDatabase);
}
use of org.pentaho.di.repository.StringObjectId in project pentaho-kettle by pentaho.
the class PurRepository method getClusterIDs.
@Override
public ObjectId[] getClusterIDs(boolean includeDeleted) throws KettleException {
try {
List<RepositoryFile> children = getAllFilesOfType(null, RepositoryObjectType.CLUSTER_SCHEMA, includeDeleted);
List<ObjectId> ids = new ArrayList<ObjectId>();
for (RepositoryFile file : children) {
ids.add(new StringObjectId(file.getId().toString()));
}
return ids.toArray(new ObjectId[0]);
} catch (Exception e) {
throw new KettleException("Unable to get all cluster schema IDs", e);
}
}
use of org.pentaho.di.repository.StringObjectId in project pentaho-kettle by pentaho.
the class PurRepository method fillRepositoryDirectoryFromTree.
private void fillRepositoryDirectoryFromTree(final RepositoryDirectoryInterface parentDir, final RepositoryFileTree treeNode) throws KettleException {
try {
List<RepositoryElementMetaInterface> fileChildren = new ArrayList<RepositoryElementMetaInterface>();
List<RepositoryFileTree> children = treeNode.getChildren();
if (children != null) {
for (RepositoryFileTree child : children) {
if (child.getFile().isFolder()) {
RepositoryDirectory dir = new RepositoryDirectory(parentDir, child.getFile().getName());
dir.setObjectId(new StringObjectId(child.getFile().getId().toString()));
parentDir.addSubdirectory(dir);
fillRepositoryDirectoryFromTree(dir, child);
} else {
// a real file, like a Transformation or Job
RepositoryLock lock = unifiedRepositoryLockService.getLock(child.getFile());
RepositoryObjectType objectType = getObjectType(child.getFile().getName());
fileChildren.add(new EERepositoryObject(child, parentDir, null, objectType, null, lock, false));
}
}
parentDir.setRepositoryObjects(fileChildren);
}
} catch (Exception e) {
throw new KettleException("Unable to load directory structure from repository", e);
}
}
Aggregations