use of org.pentaho.di.trans.step.StepMeta in project pentaho-kettle by pentaho.
the class SpoonJobDelegate method ripDB.
public JobMeta ripDB(final List<DatabaseMeta> databases, final String jobname, final RepositoryDirectoryInterface repdir, final String directory, final DatabaseMeta sourceDbInfo, final DatabaseMeta targetDbInfo, final String[] tables) {
//
// Create a new job...
//
final JobMeta jobMeta = new JobMeta();
jobMeta.setDatabases(databases);
jobMeta.setFilename(null);
jobMeta.setName(jobname);
if (spoon.getRepository() != null) {
jobMeta.setRepositoryDirectory(repdir);
} else {
jobMeta.setFilename(Const.createFilename(directory, jobname, "." + Const.STRING_JOB_DEFAULT_EXT));
}
spoon.refreshTree();
spoon.refreshGraph();
final Point location = new Point(50, 50);
// The start entry...
final JobEntryCopy start = JobMeta.createStartEntry();
start.setLocation(new Point(location.x, location.y));
start.setDrawn();
jobMeta.addJobEntry(start);
// final Thread parentThread = Thread.currentThread();
// Create a dialog with a progress indicator!
IRunnableWithProgress op = monitor -> {
try {
// This is running in a new process: copy some KettleVariables
// info
// LocalVariables.getInstance().createKettleVariables(Thread.currentThread().getName(),
// parentThread.getName(), true);
monitor.beginTask(BaseMessages.getString(PKG, "Spoon.RipDB.Monitor.BuildingNewJob"), tables.length);
monitor.worked(0);
JobEntryCopy previous = start;
// Loop over the table-names...
for (int i = 0; i < tables.length && !monitor.isCanceled(); i++) {
monitor.setTaskName(BaseMessages.getString(PKG, "Spoon.RipDB.Monitor.ProcessingTable") + tables[i] + "]...");
//
// Create the new transformation...
//
String transname = BaseMessages.getString(PKG, "Spoon.RipDB.Monitor.Transname1") + sourceDbInfo + "].[" + tables[i] + BaseMessages.getString(PKG, "Spoon.RipDB.Monitor.Transname2") + targetDbInfo + "]";
TransMeta transMeta = new TransMeta();
if (repdir != null) {
transMeta.setRepositoryDirectory(repdir);
} else {
transMeta.setFilename(Const.createFilename(directory, transname, "." + Const.STRING_TRANS_DEFAULT_EXT));
}
// Add the source & target db
transMeta.addDatabase(sourceDbInfo);
transMeta.addDatabase(targetDbInfo);
//
// Add a note
//
String note = BaseMessages.getString(PKG, "Spoon.RipDB.Monitor.Note1") + tables[i] + BaseMessages.getString(PKG, "Spoon.RipDB.Monitor.Note2") + sourceDbInfo + "]" + Const.CR;
note += BaseMessages.getString(PKG, "Spoon.RipDB.Monitor.Note3") + tables[i] + BaseMessages.getString(PKG, "Spoon.RipDB.Monitor.Note4") + targetDbInfo + "]";
NotePadMeta ni = new NotePadMeta(note, 150, 10, -1, -1);
transMeta.addNote(ni);
//
// Add the TableInputMeta step...
//
String fromstepname = BaseMessages.getString(PKG, "Spoon.RipDB.Monitor.FromStep.Name") + tables[i] + "]";
TableInputMeta tii = new TableInputMeta();
tii.setDefault();
tii.setDatabaseMeta(sourceDbInfo);
// It's already quoted!
tii.setSQL("SELECT * FROM " + tables[i]);
String fromstepid = PluginRegistry.getInstance().getPluginId(StepPluginType.class, tii);
StepMeta fromstep = new StepMeta(fromstepid, fromstepname, tii);
fromstep.setLocation(150, 100);
fromstep.setDraw(true);
fromstep.setDescription(BaseMessages.getString(PKG, "Spoon.RipDB.Monitor.FromStep.Description") + tables[i] + BaseMessages.getString(PKG, "Spoon.RipDB.Monitor.FromStep.Description2") + sourceDbInfo + "]");
transMeta.addStep(fromstep);
//
// Add the TableOutputMeta step...
//
String tostepname = BaseMessages.getString(PKG, "Spoon.RipDB.Monitor.ToStep.Name") + tables[i] + "]";
TableOutputMeta toi = new TableOutputMeta();
toi.setDatabaseMeta(targetDbInfo);
toi.setTableName(tables[i]);
toi.setCommitSize(100);
toi.setTruncateTable(true);
String tostepid = PluginRegistry.getInstance().getPluginId(StepPluginType.class, toi);
StepMeta tostep = new StepMeta(tostepid, tostepname, toi);
tostep.setLocation(500, 100);
tostep.setDraw(true);
tostep.setDescription(BaseMessages.getString(PKG, "Spoon.RipDB.Monitor.ToStep.Description1") + tables[i] + BaseMessages.getString(PKG, "Spoon.RipDB.Monitor.ToStep.Description2") + targetDbInfo + "]");
transMeta.addStep(tostep);
//
// Add a hop between the two steps...
//
TransHopMeta hi = new TransHopMeta(fromstep, tostep);
transMeta.addTransHop(hi);
//
// Now we generate the SQL needed to run for this
// transformation.
//
// First set the limit to 1 to speed things up!
String tmpSql = tii.getSQL();
tii.setSQL(tii.getSQL() + sourceDbInfo.getLimitClause(1));
String sql;
try {
sql = transMeta.getSQLStatementsString();
} catch (KettleStepException kse) {
throw new InvocationTargetException(kse, BaseMessages.getString(PKG, "Spoon.RipDB.Exception.ErrorGettingSQLFromTransformation") + transMeta + "] : " + kse.getMessage());
}
// remove the limit
tii.setSQL(tmpSql);
//
// Now, save the transformation...
//
boolean ok;
if (spoon.getRepository() != null) {
ok = spoon.saveToRepository(transMeta, false);
} else {
ok = spoon.saveToFile(transMeta);
}
if (!ok) {
throw new InvocationTargetException(new Exception(BaseMessages.getString(PKG, "Spoon.RipDB.Exception.UnableToSaveTransformationToRepository")), BaseMessages.getString(PKG, "Spoon.RipDB.Exception.UnableToSaveTransformationToRepository"));
}
// We can now continue with the population of the job...
// //////////////////////////////////////////////////////////////////////
location.x = 250;
if (i > 0) {
location.y += 100;
}
//
if (!Utils.isEmpty(sql)) {
String jesqlname = BaseMessages.getString(PKG, "Spoon.RipDB.JobEntrySQL.Name") + tables[i] + "]";
JobEntrySQL jesql = new JobEntrySQL(jesqlname);
jesql.setDatabase(targetDbInfo);
jesql.setSQL(sql);
jesql.setDescription(BaseMessages.getString(PKG, "Spoon.RipDB.JobEntrySQL.Description") + targetDbInfo + "].[" + tables[i] + "]");
JobEntryCopy jecsql = new JobEntryCopy();
jecsql.setEntry(jesql);
jecsql.setLocation(new Point(location.x, location.y));
jecsql.setDrawn();
jobMeta.addJobEntry(jecsql);
// Add the hop too...
JobHopMeta jhi = new JobHopMeta(previous, jecsql);
jobMeta.addJobHop(jhi);
previous = jecsql;
}
//
// Add the jobentry for the transformation too...
//
String jetransname = BaseMessages.getString(PKG, "Spoon.RipDB.JobEntryTrans.Name") + tables[i] + "]";
JobEntryTrans jetrans = new JobEntryTrans(jetransname);
jetrans.setTransname(transMeta.getName());
if (spoon.getRepository() != null) {
jetrans.setSpecificationMethod(ObjectLocationSpecificationMethod.REPOSITORY_BY_NAME);
jetrans.setDirectory(transMeta.getRepositoryDirectory().getPath());
} else {
jetrans.setSpecificationMethod(ObjectLocationSpecificationMethod.FILENAME);
jetrans.setFileName(Const.createFilename("${" + Const.INTERNAL_VARIABLE_JOB_FILENAME_DIRECTORY + "}", transMeta.getName(), "." + Const.STRING_TRANS_DEFAULT_EXT));
}
JobEntryCopy jectrans = new JobEntryCopy(jetrans);
jectrans.setDescription(BaseMessages.getString(PKG, "Spoon.RipDB.JobEntryTrans.Description1") + Const.CR + BaseMessages.getString(PKG, "Spoon.RipDB.JobEntryTrans.Description2") + sourceDbInfo + "].[" + tables[i] + "]" + Const.CR + BaseMessages.getString(PKG, "Spoon.RipDB.JobEntryTrans.Description3") + targetDbInfo + "].[" + tables[i] + "]");
jectrans.setDrawn();
location.x += 400;
jectrans.setLocation(new Point(location.x, location.y));
jobMeta.addJobEntry(jectrans);
// Add a hop between the last 2 job entries.
JobHopMeta jhi2 = new JobHopMeta(previous, jectrans);
jobMeta.addJobHop(jhi2);
previous = jectrans;
monitor.worked(1);
}
monitor.worked(100);
monitor.done();
} catch (Exception e) {
new ErrorDialog(spoon.getShell(), "Error", "An unexpected error occurred!", e);
}
};
try {
ProgressMonitorDialog pmd = new ProgressMonitorDialog(spoon.getShell());
pmd.run(false, true, op);
} catch (InvocationTargetException | InterruptedException e) {
new ErrorDialog(spoon.getShell(), BaseMessages.getString(PKG, "Spoon.ErrorDialog.RipDB.ErrorRippingTheDatabase.Title"), BaseMessages.getString(PKG, "Spoon.ErrorDialog.RipDB.ErrorRippingTheDatabase.Message"), e);
return null;
} finally {
spoon.refreshGraph();
spoon.refreshTree();
}
return jobMeta;
}
use of org.pentaho.di.trans.step.StepMeta in project pentaho-kettle by pentaho.
the class SpoonStepsDelegate method dupeStep.
public void dupeStep(TransMeta transMeta, StepMeta stepMeta) {
spoon.getLog().logDebug(toString(), // Duplicate
BaseMessages.getString(PKG, "Spoon.Log.DuplicateStep") + stepMeta.getName());
// step:
StepMeta stMeta = (StepMeta) stepMeta.clone();
if (stMeta != null) {
String newname = transMeta.getAlternativeStepname(stepMeta.getName());
int nr = 2;
while (transMeta.findStep(newname) != null) {
newname = stepMeta.getName() + " (copy " + nr + ")";
nr++;
}
stMeta.setName(newname);
// Don't select this new step!
stMeta.setSelected(false);
Point loc = stMeta.getLocation();
stMeta.setLocation(loc.x + 20, loc.y + 20);
transMeta.addStep(stMeta);
spoon.addUndoNew(transMeta, new StepMeta[] { (StepMeta) stMeta.clone() }, new int[] { transMeta.indexOfStep(stMeta) });
spoon.refreshTree();
spoon.refreshGraph();
}
}
use of org.pentaho.di.trans.step.StepMeta in project pentaho-kettle by pentaho.
the class SpoonTransformationDelegate method redoTransformationAction.
public void redoTransformationAction(TransMeta transMeta, TransAction transAction) {
switch(transAction.getType()) {
case TransAction.TYPE_ACTION_NEW_STEP:
// re-delete the step at correct location:
for (int i = 0; i < transAction.getCurrent().length; i++) {
StepMeta stepMeta = (StepMeta) transAction.getCurrent()[i];
int idx = transAction.getCurrentIndex()[i];
transMeta.addStep(idx, stepMeta);
spoon.refreshTree();
spoon.refreshGraph();
}
break;
case TransAction.TYPE_ACTION_NEW_CONNECTION:
// re-insert the connection at correct location:
for (int i = 0; i < transAction.getCurrent().length; i++) {
DatabaseMeta ci = (DatabaseMeta) transAction.getCurrent()[i];
int idx = transAction.getCurrentIndex()[i];
transMeta.addDatabase(idx, ci);
spoon.refreshTree();
spoon.refreshGraph();
}
break;
case TransAction.TYPE_ACTION_NEW_NOTE:
// re-insert the note at correct location:
for (int i = 0; i < transAction.getCurrent().length; i++) {
NotePadMeta ni = (NotePadMeta) transAction.getCurrent()[i];
int idx = transAction.getCurrentIndex()[i];
transMeta.addNote(idx, ni);
spoon.refreshTree();
spoon.refreshGraph();
}
break;
case TransAction.TYPE_ACTION_NEW_HOP:
// re-insert the hop at correct location:
for (int i = 0; i < transAction.getCurrent().length; i++) {
TransHopMeta hi = (TransHopMeta) transAction.getCurrent()[i];
int idx = transAction.getCurrentIndex()[i];
transMeta.addTransHop(idx, hi);
spoon.refreshTree();
spoon.refreshGraph();
}
break;
//
case TransAction.TYPE_ACTION_DELETE_STEP:
// re-remove the step at correct location:
for (int i = transAction.getCurrent().length - 1; i >= 0; i--) {
int idx = transAction.getCurrentIndex()[i];
transMeta.removeStep(idx);
}
spoon.refreshTree();
spoon.refreshGraph();
break;
case TransAction.TYPE_ACTION_DELETE_CONNECTION:
// re-remove the connection at correct location:
for (int i = transAction.getCurrent().length - 1; i >= 0; i--) {
int idx = transAction.getCurrentIndex()[i];
transMeta.removeDatabase(idx);
}
spoon.refreshTree();
spoon.refreshGraph();
break;
case TransAction.TYPE_ACTION_DELETE_NOTE:
// re-remove the note at correct location:
for (int i = transAction.getCurrent().length - 1; i >= 0; i--) {
int idx = transAction.getCurrentIndex()[i];
transMeta.removeNote(idx);
}
spoon.refreshTree();
spoon.refreshGraph();
break;
case TransAction.TYPE_ACTION_DELETE_HOP:
// re-remove the hop at correct location:
for (int i = transAction.getCurrent().length - 1; i >= 0; i--) {
int idx = transAction.getCurrentIndex()[i];
transMeta.removeTransHop(idx);
}
spoon.refreshTree();
spoon.refreshGraph();
break;
// We changed a step : undo this...
case TransAction.TYPE_ACTION_CHANGE_STEP:
// Delete the current step, insert previous version.
for (int i = 0; i < transAction.getCurrent().length; i++) {
StepMeta stepMeta = (StepMeta) ((StepMeta) transAction.getCurrent()[i]).clone();
transMeta.getStep(transAction.getCurrentIndex()[i]).replaceMeta(stepMeta);
}
spoon.refreshTree();
spoon.refreshGraph();
break;
// We changed a connection : undo this...
case TransAction.TYPE_ACTION_CHANGE_CONNECTION:
// Delete & re-insert
for (int i = 0; i < transAction.getCurrent().length; i++) {
DatabaseMeta databaseMeta = (DatabaseMeta) transAction.getCurrent()[i];
int idx = transAction.getCurrentIndex()[i];
transMeta.getDatabase(idx).replaceMeta((DatabaseMeta) databaseMeta.clone());
}
spoon.refreshTree();
spoon.refreshGraph();
break;
// We changed a note : undo this...
case TransAction.TYPE_ACTION_CHANGE_NOTE:
// Delete & re-insert
for (int i = 0; i < transAction.getCurrent().length; i++) {
NotePadMeta ni = (NotePadMeta) transAction.getCurrent()[i];
int idx = transAction.getCurrentIndex()[i];
transMeta.removeNote(idx);
transMeta.addNote(idx, (NotePadMeta) ni.clone());
}
spoon.refreshTree();
spoon.refreshGraph();
break;
// We changed a hop : undo this...
case TransAction.TYPE_ACTION_CHANGE_HOP:
// Delete & re-insert
for (int i = 0; i < transAction.getCurrent().length; i++) {
TransHopMeta hi = (TransHopMeta) transAction.getCurrent()[i];
int idx = transAction.getCurrentIndex()[i];
transMeta.removeTransHop(idx);
transMeta.addTransHop(idx, (TransHopMeta) hi.clone());
}
spoon.refreshTree();
spoon.refreshGraph();
break;
//
case TransAction.TYPE_ACTION_POSITION_STEP:
for (int i = 0; i < transAction.getCurrentIndex().length; i++) {
// Find & change the location of the step:
StepMeta stepMeta = transMeta.getStep(transAction.getCurrentIndex()[i]);
stepMeta.setLocation(transAction.getCurrentLocation()[i]);
}
spoon.refreshGraph();
break;
case TransAction.TYPE_ACTION_POSITION_NOTE:
for (int i = 0; i < transAction.getCurrentIndex().length; i++) {
int idx = transAction.getCurrentIndex()[i];
NotePadMeta npi = transMeta.getNote(idx);
Point curr = transAction.getCurrentLocation()[i];
npi.setLocation(curr);
}
spoon.refreshGraph();
break;
default:
break;
}
// OK, now check if we need to do this again...
if (transMeta.viewNextUndo() != null) {
if (transMeta.viewNextUndo().getNextAlso()) {
spoon.redoAction(transMeta);
}
}
}
use of org.pentaho.di.trans.step.StepMeta in project pentaho-kettle by pentaho.
the class SpoonTreeDelegate method addDragSourceToTree.
public void addDragSourceToTree(final Tree tree, final Tree selectionTree, final Tree coreObjectsTree) {
// Drag & Drop for steps
Transfer[] ttypes = new Transfer[] { XMLTransfer.getInstance() };
DragSource ddSource = new DragSource(tree, DND.DROP_MOVE);
ddSource.setTransfer(ttypes);
ddSource.addDragListener(new DragSourceListener() {
public void dragStart(DragSourceEvent event) {
TreeSelection[] treeObjects = getTreeObjects(tree, selectionTree, coreObjectsTree);
if (treeObjects.length == 0) {
event.doit = false;
return;
}
spoon.hideToolTips();
TreeSelection treeObject = treeObjects[0];
Object object = treeObject.getSelection();
TransMeta transMeta = spoon.getActiveTransformation();
if (object instanceof StepMeta || object instanceof PluginInterface || (object instanceof DatabaseMeta && transMeta != null) || object instanceof TransHopMeta || object instanceof JobEntryCopy) {
event.doit = true;
} else {
event.doit = false;
}
}
public void dragSetData(DragSourceEvent event) {
TreeSelection[] treeObjects = getTreeObjects(tree, selectionTree, coreObjectsTree);
if (treeObjects.length == 0) {
event.doit = false;
return;
}
int type = 0;
String id = null;
String data = null;
TreeSelection treeObject = treeObjects[0];
Object object = treeObject.getSelection();
if (object instanceof StepMeta) {
StepMeta stepMeta = (StepMeta) object;
type = DragAndDropContainer.TYPE_STEP;
// name of the step.
data = stepMeta.getName();
} else if (object instanceof PluginInterface) {
PluginInterface plugin = (PluginInterface) object;
Class<? extends PluginTypeInterface> pluginType = plugin.getPluginType();
if (Const.classIsOrExtends(pluginType, StepPluginType.class)) {
type = DragAndDropContainer.TYPE_BASE_STEP_TYPE;
id = plugin.getIds()[0];
// Step type name
data = plugin.getName();
} else {
type = DragAndDropContainer.TYPE_BASE_JOB_ENTRY;
// job entry type name
data = plugin.getName();
if (treeObject.getItemText().equals(JobMeta.createStartEntry().getName())) {
data = treeObject.getItemText();
} else if (treeObject.getItemText().equals(JobMeta.createDummyEntry().getName())) {
data = treeObject.getItemText();
}
}
} else if (object instanceof DatabaseMeta) {
DatabaseMeta databaseMeta = (DatabaseMeta) object;
type = DragAndDropContainer.TYPE_DATABASE_CONNECTION;
data = databaseMeta.getName();
} else if (object instanceof TransHopMeta) {
TransHopMeta hop = (TransHopMeta) object;
type = DragAndDropContainer.TYPE_TRANS_HOP;
// nothing for really ;-)
data = hop.toString();
} else if (object instanceof JobEntryCopy) {
JobEntryCopy jobEntryCopy = (JobEntryCopy) object;
type = DragAndDropContainer.TYPE_JOB_ENTRY;
// name of the job entry.
data = jobEntryCopy.getName();
} else {
event.doit = false;
// ignore anything else you drag.
return;
}
event.data = new DragAndDropContainer(type, data, id);
}
public void dragFinished(DragSourceEvent event) {
}
});
}
use of org.pentaho.di.trans.step.StepMeta in project pentaho-kettle by pentaho.
the class PreviewSelectDialog method open.
public void open() {
Shell parent = getParent();
Display display = parent.getDisplay();
shell = new Shell(parent, SWT.DIALOG_TRIM | SWT.RESIZE | SWT.MAX | SWT.MIN);
props.setLook(shell);
shell.setImage(GUIResource.getInstance().getImageSpoon());
FormLayout formLayout = new FormLayout();
formLayout.marginWidth = Const.FORM_MARGIN;
formLayout.marginHeight = Const.FORM_MARGIN;
shell.setLayout(formLayout);
// Preview
shell.setText(BaseMessages.getString(PKG, "PreviewSelectDialog.Dialog.PreviewSelection.Title"));
// selection
// screen
shell.setImage(GUIResource.getInstance().getImageLogoSmall());
int margin = Const.MARGIN;
wlFields = new Label(shell, SWT.NONE);
// Steps:
wlFields.setText(BaseMessages.getString(PKG, "PreviewSelectDialog.Label.Steps"));
props.setLook(wlFields);
fdlFields = new FormData();
fdlFields.left = new FormAttachment(0, 0);
fdlFields.top = new FormAttachment(0, margin);
wlFields.setLayoutData(fdlFields);
List<StepMeta> usedSteps = transMeta.getUsedSteps();
final int FieldsRows = usedSteps.size();
ColumnInfo[] colinf = { new ColumnInfo(BaseMessages.getString(PKG, "PreviewSelectDialog.Column.Stepname"), ColumnInfo.COLUMN_TYPE_TEXT, false, // Stepname
true), new ColumnInfo(BaseMessages.getString(PKG, "PreviewSelectDialog.Column.PreviewSize"), ColumnInfo.COLUMN_TYPE_TEXT, false, // Preview size
false) };
wFields = new TableView(transMeta, shell, SWT.BORDER | SWT.FULL_SELECTION | SWT.MULTI, colinf, FieldsRows, // read-only
true, null, props);
fdFields = new FormData();
fdFields.left = new FormAttachment(0, 0);
fdFields.top = new FormAttachment(wlFields, margin);
fdFields.right = new FormAttachment(100, 0);
fdFields.bottom = new FormAttachment(100, -50);
wFields.setLayoutData(fdFields);
wPreview = new Button(shell, SWT.PUSH);
wPreview.setText(BaseMessages.getString(PKG, "System.Button.Show"));
wCancel = new Button(shell, SWT.PUSH);
wCancel.setText(BaseMessages.getString(PKG, "System.Button.Close"));
BaseStepDialog.positionBottomButtons(shell, new Button[] { wPreview, wCancel }, margin, null);
// Add listeners
lsCancel = new Listener() {
public void handleEvent(Event e) {
cancel();
}
};
lsPreview = new Listener() {
public void handleEvent(Event e) {
preview();
}
};
wCancel.addListener(SWT.Selection, lsCancel);
wPreview.addListener(SWT.Selection, lsPreview);
// Detect X or ALT-F4 or something that kills this window...
shell.addShellListener(new ShellAdapter() {
public void shellClosed(ShellEvent e) {
cancel();
}
});
BaseStepDialog.setSize(shell);
getData();
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
}
Aggregations