use of org.pentaho.di.repository.RepositoryElementMetaInterface in project pentaho-kettle by pentaho.
the class TrashBrowseController method undelete.
public void undelete() {
// make a copy because the selected trash items changes as soon as trashService.undelete is called
List<UIDeletedObject> selectedTrashFileItemsSnapshot = new ArrayList<UIDeletedObject>(selectedTrashFileItems);
if (selectedTrashFileItemsSnapshot != null && selectedTrashFileItemsSnapshot.size() > 0) {
List<ObjectId> ids = new ArrayList<ObjectId>();
for (UIDeletedObject uiObj : selectedTrashFileItemsSnapshot) {
ids.add(uiObj.getId());
}
try {
trashService.undelete(ids);
setTrash(trashService.getTrash());
for (UIDeletedObject uiObj : selectedTrashFileItemsSnapshot) {
// find the closest UIRepositoryDirectory that is in the dirMap
RepositoryDirectoryInterface dir = repository.findDirectory(uiObj.getOriginalParentPath());
while (dir != null && dirMap.get(dir.getObjectId()) == null) {
dir = dir.getParent();
}
// now refresh that UIRepositoryDirectory so that the file/folders deck instantly refreshes on undelete
if (dir != null) {
dirMap.get(dir.getObjectId()).refresh();
}
// if transformation or directory with transformations call extension to restore data services references.
if (RepositoryObjectType.TRANSFORMATION.name().equals(uiObj.getType())) {
TransMeta transMeta = repository.loadTransformation(uiObj.getId(), null);
ExtensionPointHandler.callExtensionPoint(LogChannel.GENERAL, KettleExtensionPoint.TransAfterOpen.id, transMeta);
transMeta.clearChanged();
} else if (!RepositoryObjectType.JOB.name().equals(uiObj.getType())) {
// if not a transformation and not a job then is a Directory
RepositoryDirectoryInterface actualDir = repository.findDirectory(uiObj.getOriginalParentPath() + RepositoryDirectory.DIRECTORY_SEPARATOR + uiObj.getName());
if (actualDir != null) {
List<RepositoryElementMetaInterface> transformations = new ArrayList<>();
getAllTransformations(actualDir, transformations);
for (RepositoryElementMetaInterface repositoryElementMetaInterface : transformations) {
TransMeta transMeta = repository.loadTransformation(repositoryElementMetaInterface.getObjectId(), null);
ExtensionPointHandler.callExtensionPoint(LogChannel.GENERAL, KettleExtensionPoint.TransAfterOpen.id, transMeta);
transMeta.clearChanged();
}
} else {
displayExceptionMessage(BaseMessages.getString(PKG, "TrashBrowseController.UnableToRestoreDirectory", uiObj.getOriginalParentPath() + RepositoryDirectory.DIRECTORY_SEPARATOR + uiObj.getName()));
}
}
}
deck.setSelectedIndex(1);
} catch (Throwable th) {
if (mainController == null || !mainController.handleLostRepository(th)) {
displayExceptionMessage(BaseMessages.getString(PKG, "TrashBrowseController.UnableToRestoreFile", // $NON-NLS-1$
th.getLocalizedMessage()));
}
}
} else {
// ui probably allowed the button to be enabled when it shouldn't have been enabled
throw new RuntimeException();
}
}
use of org.pentaho.di.repository.RepositoryElementMetaInterface in project pentaho-kettle by pentaho.
the class UIRepositoryDirectory method getRepositoryObjects.
// TODO: Abstract working model; should throw RepositoryException
// TODO: We will need a way to reset this cache when a directory or element changes
public UIRepositoryObjects getRepositoryObjects() throws KettleException {
if (kidElementCache != null) {
return kidElementCache;
}
if (kidElementCache == null) {
kidElementCache = new UIRepositoryObjects() {
private static final long serialVersionUID = 6901479331535375165L;
public void onRemove(UIRepositoryObject child) {
List<? extends RepositoryElementMetaInterface> dirRepoObjects = getDirectory().getRepositoryObjects();
if (dirRepoObjects != null) {
Iterator<? extends RepositoryElementMetaInterface> iter = dirRepoObjects.iterator();
while (iter.hasNext()) {
RepositoryElementMetaInterface e = iter.next();
if (child.getObjectId().equals(e.getObjectId())) {
iter.remove();
return;
}
}
}
}
};
}
for (UIRepositoryObject child : getChildren()) {
kidElementCache.add(child);
}
List<RepositoryElementMetaInterface> jobsAndTransformations = getDirectory().getRepositoryObjects();
if (jobsAndTransformations == null) {
RepositoryDirectoryInterface dir = getDirectory();
jobsAndTransformations = rep.getJobAndTransformationObjects(dir.getObjectId(), false);
dir.setRepositoryObjects(jobsAndTransformations);
}
for (RepositoryElementMetaInterface child : jobsAndTransformations) {
if (child.getObjectType().equals(RepositoryObjectType.TRANSFORMATION)) {
try {
kidElementCache.add(UIObjectRegistry.getInstance().constructUITransformation(child, this, rep));
} catch (UIObjectCreationException e) {
kidElementCache.add(new UITransformation(child, this, rep));
}
} else if (child.getObjectType().equals(RepositoryObjectType.JOB)) {
try {
kidElementCache.add(UIObjectRegistry.getInstance().constructUIJob(child, this, rep));
} catch (UIObjectCreationException e) {
kidElementCache.add(new UIJob(child, this, rep));
}
}
}
return kidElementCache;
}
use of org.pentaho.di.repository.RepositoryElementMetaInterface in project pentaho-kettle by pentaho.
the class RepositoryDirectoryUI method loadRepositoryObjects.
protected static List<RepositoryElementMetaInterface> loadRepositoryObjects(RepositoryDirectoryInterface dir, boolean getTransformations, boolean getJobs, Repository rep) throws KettleDatabaseException {
// Then show the transformations & jobs in that directory...
List<RepositoryElementMetaInterface> repositoryObjects = new ArrayList<RepositoryElementMetaInterface>();
if (dir.getRepositoryObjects() == null) {
try {
dir.setRepositoryObjects(rep.getJobAndTransformationObjects(dir.getObjectId(), false));
} catch (KettleException e) {
throw new KettleDatabaseException(e);
}
}
List<RepositoryObjectType> allowedTypes = new ArrayList<>(2);
if (getTransformations) {
allowedTypes.add(RepositoryObjectType.TRANSFORMATION);
}
if (getJobs) {
allowedTypes.add(RepositoryObjectType.JOB);
}
for (RepositoryElementMetaInterface repoObject : dir.getRepositoryObjects()) {
if (allowedTypes.contains(repoObject.getObjectType())) {
repositoryObjects.add(repoObject);
}
}
return repositoryObjects;
}
use of org.pentaho.di.repository.RepositoryElementMetaInterface in project pentaho-kettle by pentaho.
the class RepositoryDirectoryUI method getTreeWithNames.
/**
* Set the name of this directory on a TreeItem. Also, create children on this TreeItem to reflect the subdirectories.
* In these sub-directories, fill in the available transformations from the repository.
*
* @param ti
* The TreeItem to set the name on and to create the subdirectories
* @param rep
* The repository
* @param objectMap
* The tree path to repository object mapping to populate.
* @param dircolor
* The color in which the directories will be drawn.
* @param sortPosition
* The sort position
* @param ascending
* The ascending flag
* @param getTransformations
* Include transformations in the tree or not
* @param getJobs
* Include jobs in the tree or not
* @throws KettleDatabaseException
*/
public static void getTreeWithNames(TreeItem ti, Repository rep, Color dircolor, int sortPosition, boolean includeDeleted, boolean ascending, boolean getTransformations, boolean getJobs, RepositoryDirectoryInterface dir, String filterString, Pattern pattern) throws KettleDatabaseException {
ti.setText(dir.getName());
ti.setData(dir);
ti.setData("isFolder", true);
// First, we draw the directories
List<RepositoryDirectoryInterface> children = dir.getChildren();
Collections.sort(children, new Comparator<RepositoryDirectoryInterface>() {
@Override
public int compare(RepositoryDirectoryInterface o1, RepositoryDirectoryInterface o2) {
return o1.getName().compareToIgnoreCase(o2.getName());
}
});
for (int i = 0; i < children.size(); i++) {
RepositoryDirectory subdir = (RepositoryDirectory) children.get(i);
TreeItem subti = new TreeItem(ti, SWT.NONE);
subti.setImage(GUIResource.getInstance().getImageFolder());
subti.setData("isFolder", true);
getTreeWithNames(subti, rep, dircolor, sortPosition, includeDeleted, ascending, getTransformations, getJobs, subdir, filterString, pattern);
}
List<RepositoryElementMetaInterface> repositoryObjects = loadRepositoryObjects(dir, getTransformations, getJobs, rep);
// Sort the directory list appropriately...
RepositoryObject.sortRepositoryObjects(repositoryObjects, sortPosition, ascending);
addToTree(ti, filterString, pattern, repositoryObjects);
ti.setExpanded(dir.isRoot());
}
use of org.pentaho.di.repository.RepositoryElementMetaInterface in project pentaho-kettle by pentaho.
the class RepositoryExplorerDialog method delSelectedObjects.
public boolean delSelectedObjects() {
TreeItem[] items = wTree.getSelection();
boolean error = false;
MessageBox mb = new MessageBox(shell, SWT.ICON_WARNING | SWT.YES | SWT.NO);
mb.setMessage(BaseMessages.getString(PKG, "RepositoryExplorerDialog.Trans.Delete.Confirm.Message1") + (items.length > 1 ? BaseMessages.getString(PKG, "RepositoryExplorerDialog.Trans.Delete.Confirm.Message2") + items.length + BaseMessages.getString(PKG, "RepositoryExplorerDialog.Trans.Delete.Confirm.Message3") : BaseMessages.getString(PKG, "RepositoryExplorerDialog.Trans.Delete.Confirm.Message4")));
mb.setText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.Trans.Delete.Confirm.Title"));
int answer = mb.open();
if (answer != SWT.YES) {
return false;
}
for (int i = 0; i < items.length; i++) {
final RepositoryElementMetaInterface repositoryObject = objectMap.get(ConstUI.getTreePath(items[i], 0));
if (repositoryObject != null) {
try {
switch(repositoryObject.getObjectType()) {
case TRANSFORMATION:
rep.deleteTransformation(repositoryObject.getObjectId());
break;
case JOB:
rep.deleteJob(repositoryObject.getObjectId());
break;
default:
break;
}
} catch (Exception e) {
new ErrorDialog(shell, BaseMessages.getString(PKG, "RepositoryExplorerDialog.Trans.Delete.ErrorRemoving.Title"), BaseMessages.getString(PKG, "RepositoryExplorerDialog.Trans.Delete.ErrorRemoving.Message") + repositoryObject.getName() + "]", e);
error = true;
}
}
}
refreshTree();
return !error;
}
Aggregations