use of org.pentaho.di.core.Condition in project pentaho-kettle by pentaho.
the class RepositoryTestBase method createTransMeta.
protected TransMeta createTransMeta(final String dbName) throws Exception {
RepositoryDirectoryInterface rootDir = loadStartDirectory();
TransMeta transMeta = new TransMeta();
transMeta.setName(EXP_TRANS_NAME.concat(dbName));
transMeta.setDescription(EXP_TRANS_DESC);
transMeta.setExtendedDescription(EXP_TRANS_EXTENDED_DESC);
transMeta.setRepositoryDirectory(rootDir.findDirectory(DIR_TRANSFORMATIONS));
transMeta.setTransversion(EXP_TRANS_VERSION);
transMeta.setTransstatus(EXP_TRANS_STATUS);
transMeta.setCreatedUser(EXP_TRANS_CREATED_USER);
transMeta.setCreatedDate(EXP_TRANS_CREATED_DATE);
transMeta.setModifiedUser(EXP_TRANS_MOD_USER);
transMeta.setModifiedDate(EXP_TRANS_MOD_DATE);
transMeta.addParameterDefinition(EXP_TRANS_PARAM_1_NAME, EXP_TRANS_PARAM_1_DEF, EXP_TRANS_PARAM_1_DESC);
// TODO mlowery other transLogTable fields could be set for testing here
TransLogTable transLogTable = TransLogTable.getDefault(transMeta, transMeta, new ArrayList<StepMeta>(0));
transLogTable.setConnectionName(EXP_TRANS_LOG_TABLE_CONN_NAME);
transLogTable.setLogInterval(EXP_TRANS_LOG_TABLE_INTERVAL);
transLogTable.setSchemaName(EXP_TRANS_LOG_TABLE_SCHEMA_NAME);
transLogTable.setLogSizeLimit(EXP_TRANS_LOG_TABLE_SIZE_LIMIT);
transLogTable.setTableName(EXP_TRANS_LOG_TABLE_TABLE_NAME);
transLogTable.setTimeoutInDays(EXP_TRANS_LOG_TABLE_TIMEOUT_IN_DAYS);
transMeta.setTransLogTable(transLogTable);
// TODO mlowery other perfLogTable fields could be set for testing here
PerformanceLogTable perfLogTable = PerformanceLogTable.getDefault(transMeta, transMeta);
perfLogTable.setConnectionName(EXP_TRANS_LOG_TABLE_CONN_NAME);
perfLogTable.setLogInterval(EXP_TRANS_LOG_TABLE_INTERVAL);
perfLogTable.setSchemaName(EXP_TRANS_LOG_TABLE_SCHEMA_NAME);
perfLogTable.setTableName(EXP_TRANS_LOG_TABLE_TABLE_NAME);
perfLogTable.setTimeoutInDays(EXP_TRANS_LOG_TABLE_TIMEOUT_IN_DAYS);
transMeta.setPerformanceLogTable(perfLogTable);
// TODO mlowery other channelLogTable fields could be set for testing here
ChannelLogTable channelLogTable = ChannelLogTable.getDefault(transMeta, transMeta);
channelLogTable.setConnectionName(EXP_TRANS_LOG_TABLE_CONN_NAME);
channelLogTable.setSchemaName(EXP_TRANS_LOG_TABLE_SCHEMA_NAME);
channelLogTable.setTableName(EXP_TRANS_LOG_TABLE_TABLE_NAME);
channelLogTable.setTimeoutInDays(EXP_TRANS_LOG_TABLE_TIMEOUT_IN_DAYS);
transMeta.setChannelLogTable(channelLogTable);
// TODO mlowery other stepLogTable fields could be set for testing here
StepLogTable stepLogTable = StepLogTable.getDefault(transMeta, transMeta);
stepLogTable.setConnectionName(EXP_TRANS_LOG_TABLE_CONN_NAME);
stepLogTable.setSchemaName(EXP_TRANS_LOG_TABLE_SCHEMA_NAME);
stepLogTable.setTableName(EXP_TRANS_LOG_TABLE_TABLE_NAME);
stepLogTable.setTimeoutInDays(EXP_TRANS_LOG_TABLE_TIMEOUT_IN_DAYS);
transMeta.setStepLogTable(stepLogTable);
DatabaseMeta dbMeta = createDatabaseMeta(dbName);
// dbMeta must be saved so that it gets an ID
repository.save(dbMeta, VERSION_COMMENT_V1, null);
deleteStack.push(dbMeta);
transMeta.setMaxDateConnection(dbMeta);
transMeta.setMaxDateTable(EXP_TRANS_MAX_DATE_TABLE);
transMeta.setMaxDateField(EXP_TRANS_MAX_DATE_FIELD);
transMeta.setMaxDateOffset(EXP_TRANS_MAX_DATE_OFFSET);
transMeta.setMaxDateDifference(EXP_TRANS_MAX_DATE_DIFF);
transMeta.setSizeRowset(EXP_TRANS_SIZE_ROWSET);
transMeta.setSleepTimeEmpty(EXP_TRANS_SLEEP_TIME_EMPTY);
transMeta.setSleepTimeFull(EXP_TRANS_SLEEP_TIME_FULL);
transMeta.setUsingUniqueConnections(EXP_TRANS_USING_UNIQUE_CONN);
transMeta.setFeedbackShown(EXP_TRANS_FEEDBACK_SHOWN);
transMeta.setFeedbackSize(EXP_TRANS_FEEDBACK_SIZE);
transMeta.setUsingThreadPriorityManagment(EXP_TRANS_USING_THREAD_PRIORITY_MGMT);
transMeta.setSharedObjectsFile(EXP_TRANS_SHARED_OBJECTS_FILE);
transMeta.setCapturingStepPerformanceSnapShots(EXP_TRANS_CAPTURE_STEP_PERF_SNAPSHOTS);
transMeta.setStepPerformanceCapturingDelay(EXP_TRANS_STEP_PERF_CAP_DELAY);
transMeta.addDependency(new TransDependency(dbMeta, EXP_TRANS_DEP_TABLE_NAME, EXP_TRANS_DEP_FIELD_NAME));
DatabaseMeta stepDbMeta = createDatabaseMeta(EXP_DBMETA_NAME_STEP.concat(dbName));
repository.save(stepDbMeta, VERSION_COMMENT_V1, null);
deleteStack.push(stepDbMeta);
Condition cond = new Condition();
StepMeta step1 = createStepMeta1(transMeta, stepDbMeta, cond);
transMeta.addStep(step1);
StepMeta step2 = createStepMeta2(stepDbMeta, cond);
transMeta.addStep(step2);
transMeta.addTransHop(createTransHopMeta(step1, step2));
SlaveServer slaveServer = createSlaveServer(dbName);
PartitionSchema partSchema = createPartitionSchema(dbName);
// slaveServer, partSchema must be saved so that they get IDs
repository.save(slaveServer, VERSION_COMMENT_V1, null);
deleteStack.push(slaveServer);
repository.save(partSchema, VERSION_COMMENT_V1, null);
deleteStack.push(partSchema);
SlaveStepCopyPartitionDistribution slaveStepCopyPartitionDistribution = new SlaveStepCopyPartitionDistribution();
slaveStepCopyPartitionDistribution.addPartition(EXP_SLAVE_NAME, EXP_PART_SCHEMA_NAME, 0);
slaveStepCopyPartitionDistribution.setOriginalPartitionSchemas(Arrays.asList(new PartitionSchema[] { partSchema }));
transMeta.setSlaveStepCopyPartitionDistribution(slaveStepCopyPartitionDistribution);
transMeta.setSlaveTransformation(EXP_TRANS_SLAVE_TRANSFORMATION);
return transMeta;
}
use of org.pentaho.di.core.Condition in project pentaho-kettle by pentaho.
the class ConditionEditor method setMenu.
private void setMenu(int area, Point screen) {
final int cond_nr = getNrSubcondition(screen);
if (mPop != null && !mPop.isDisposed()) {
mPop.dispose();
}
switch(area) {
case AREA_NOT:
mPop = new Menu(widget);
MenuItem miNegate = new MenuItem(mPop, SWT.CASCADE);
miNegate.setText(BaseMessages.getString(PKG, "ConditionEditor.NegateCondition"));
miNegate.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
active_condition.negate();
widget.redraw();
setModified();
}
});
setMenu(mPop);
break;
case AREA_BACKGROUND:
case AREA_ICON_ADD:
mPop = new Menu(widget);
MenuItem miAdd = new MenuItem(mPop, SWT.CASCADE);
miAdd.setText(BaseMessages.getString(PKG, "ConditionEditor.AddCondition.Label"));
miAdd.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
addCondition();
}
});
setMenu(mPop);
break;
case AREA_SUBCONDITION:
mPop = new Menu(widget);
MenuItem miEdit = new MenuItem(mPop, SWT.CASCADE);
miEdit.setText("Edit condition");
miEdit.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
editCondition(cond_nr);
setModified();
widget.redraw();
}
});
MenuItem miDel = new MenuItem(mPop, SWT.CASCADE);
miDel.setText(BaseMessages.getString(PKG, "ConditionEditor.DeleteCondition.Label"));
miDel.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
removeCondition(cond_nr);
setModified();
widget.redraw();
}
});
// Add a sub-condition in the subcondition... (move down)
final Condition sub = active_condition.getCondition(cond_nr);
if (sub.getLeftValuename() != null) {
miAdd = new MenuItem(mPop, SWT.CASCADE);
miAdd.setText(BaseMessages.getString(PKG, "ConditionEditor.AddSubCondition.Label"));
miAdd.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
Condition c = new Condition();
c.setOperator(Condition.OPERATOR_AND);
sub.addCondition(c);
setModified();
widget.redraw();
}
});
}
// --------------------------------------------------
new MenuItem(mPop, SWT.SEPARATOR);
MenuItem miCopy = new MenuItem(mPop, SWT.CASCADE);
miCopy.setText(BaseMessages.getString(PKG, "ConditionEditor.CopyToClipboard"));
miCopy.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
Condition c = active_condition.getCondition(cond_nr);
try {
String xml = c.getXML();
GUIResource.getInstance().toClipboard(xml);
widget.redraw();
} catch (Exception ex) {
new ErrorDialog(shell, "Error", "Error encoding to XML", ex);
}
}
});
MenuItem miPasteBef = new MenuItem(mPop, SWT.CASCADE);
miPasteBef.setText(BaseMessages.getString(PKG, "ConditionEditor.PasteFromClipboardBeforeCondition"));
miPasteBef.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
String xml = GUIResource.getInstance().fromClipboard();
try {
Document d = XMLHandler.loadXMLString(xml);
Node condNode = XMLHandler.getSubNode(d, "condition");
if (condNode != null) {
Condition c = new Condition(condNode);
active_condition.addCondition(cond_nr, c);
widget.redraw();
} else {
new ErrorDialog(shell, BaseMessages.getString(PKG, "ConditionEditor.Error"), BaseMessages.getString(PKG, "ConditionEditor.NoConditionFoundXML"), new KettleXMLException(BaseMessages.getString(PKG, "ConditionEditor.NoConditionFoundXML.Exception", Const.CR + Const.CR + xml)));
}
} catch (KettleXMLException ex) {
new ErrorDialog(shell, BaseMessages.getString(PKG, "ConditionEditor.Error"), BaseMessages.getString(PKG, "ConditionEditor.ErrorParsingCondition"), ex);
}
}
});
// --------------------------------------------------
new MenuItem(mPop, SWT.SEPARATOR);
MenuItem miPasteAft = new MenuItem(mPop, SWT.CASCADE);
miPasteAft.setText(BaseMessages.getString(PKG, "ConditionEditor.PasteFromClipboardAfterCondition"));
miPasteAft.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
String xml = GUIResource.getInstance().fromClipboard();
try {
Document d = XMLHandler.loadXMLString(xml);
Node condNode = XMLHandler.getSubNode(d, "condition");
if (condNode != null) {
Condition c = new Condition(condNode);
active_condition.addCondition(cond_nr + 1, c);
widget.redraw();
} else {
new ErrorDialog(shell, BaseMessages.getString(PKG, "ConditionEditor.Error"), BaseMessages.getString(PKG, "ConditionEditor.NoConditionFoundXML"), new KettleXMLException(BaseMessages.getString(PKG, "ConditionEditor.NoConditionFoundXML.Exception", Const.CR + Const.CR + xml)));
}
} catch (KettleXMLException ex) {
new ErrorDialog(shell, BaseMessages.getString(PKG, "ConditionEditor.Error"), BaseMessages.getString(PKG, "ConditionEditor.ErrorParsingCondition"), ex);
}
}
});
// --------------------------------------------------
new MenuItem(mPop, SWT.SEPARATOR);
MenuItem miMoveSub = new MenuItem(mPop, SWT.CASCADE);
miMoveSub.setText(BaseMessages.getString(PKG, "ConditionEditor.MoveConditionToSubCondition"));
miMoveSub.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
// Move the condition lower: this means create a subcondition and put the condition there in the list.
//
Condition down = active_condition.getCondition(cond_nr);
Condition c = new Condition();
c.setOperator(down.getOperator());
down.setOperator(Condition.OPERATOR_NONE);
active_condition.setCondition(cond_nr, c);
c.addCondition(down);
widget.redraw();
}
});
MenuItem miMoveParent = new MenuItem(mPop, SWT.CASCADE);
miMoveParent.setText(BaseMessages.getString(PKG, "ConditionEditor.MoveConditionToParentCondition"));
if (getLevel() == 0) {
miMoveParent.setEnabled(false);
}
miMoveParent.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
// Move the condition lower: this means delete the condition from the active_condition.
// After that, move it to the parent.
Condition up = active_condition.getCondition(cond_nr);
active_condition.removeCondition(cond_nr);
Condition parent = parents.get(getLevel() - 1);
parent.addCondition(up);
// Take a look upward...
goUp();
widget.redraw();
}
});
// --------------------------------------------------
new MenuItem(mPop, SWT.SEPARATOR);
MenuItem miMoveDown = new MenuItem(mPop, SWT.CASCADE);
miMoveDown.setText(BaseMessages.getString(PKG, "ConditionEditor.MoveConditionDown"));
if (cond_nr >= active_condition.nrConditions() - 1) {
miMoveDown.setEnabled(false);
}
miMoveDown.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
Condition down = active_condition.getCondition(cond_nr);
active_condition.removeCondition(cond_nr);
active_condition.addCondition(cond_nr + 1, down);
widget.redraw();
}
});
MenuItem miMoveUp = new MenuItem(mPop, SWT.CASCADE);
miMoveUp.setText(BaseMessages.getString(PKG, "ConditionEditor.MoveConditionUp"));
if (cond_nr == 0) {
miMoveUp.setEnabled(false);
}
miMoveUp.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
Condition up = active_condition.getCondition(cond_nr);
active_condition.removeCondition(cond_nr);
active_condition.addCondition(cond_nr - 1, up);
widget.redraw();
}
});
setMenu(mPop);
break;
case AREA_OPERATOR:
Menu mPop = new Menu(widget);
MenuItem miDown = new MenuItem(mPop, SWT.CASCADE);
miDown.setText(BaseMessages.getString(PKG, "ConditionEditor.MoveDown"));
miDown.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
// Move a condition down!
// oper_nr = 1 : means move down
setModified();
widget.redraw();
}
});
setMenu(mPop);
break;
default:
setMenu(null);
break;
}
}
use of org.pentaho.di.core.Condition in project pentaho-kettle by pentaho.
the class ConditionEditor method addCondition.
private void addCondition() {
Condition c = new Condition();
c.setOperator(Condition.OPERATOR_AND);
addCondition(c);
setModified();
widget.redraw();
}
use of org.pentaho.di.core.Condition in project pentaho-kettle by pentaho.
the class RepositoryProxy method loadConditionFromStepAttribute.
public Condition loadConditionFromStepAttribute(ObjectId idStep, String code) throws KettleException {
DataNode conditionNode = node.getNode(code);
if (conditionNode.hasProperty(PROPERTY_XML)) {
String xml = conditionNode.getProperty(PROPERTY_XML).getString();
Condition condition = new Condition(XMLHandler.getSubNode(XMLHandler.loadXMLString(xml), Condition.XML_TAG));
return condition;
} else {
return null;
}
}
use of org.pentaho.di.core.Condition in project pentaho-kettle by pentaho.
the class StringSearcherTest method testSearchConditionCase.
@Test
public void testSearchConditionCase() {
String dummyStepname = "Output";
DummyTransMeta dummyMeta = new DummyTransMeta();
String dummyStepPid = PluginRegistry.getInstance().getPluginId(StepPluginType.class, dummyMeta);
StepMeta dummyStep = new StepMeta(dummyStepPid, dummyStepname, dummyMeta);
List<StringSearchResult> stringList = new ArrayList<StringSearchResult>();
StringSearcher.findMetaData(dummyStep, 0, stringList, dummyMeta, 0);
int checkCount = 0;
String aResult = null;
// Check that it found a couple of fields and emits the values properly
for (int i = 0; i < stringList.size(); i++) {
aResult = stringList.get(i).toString();
if (aResult.endsWith("Dummy (stepid)")) {
checkCount++;
} else if (aResult.endsWith("Output (name)")) {
checkCount++;
}
if (checkCount == 2) {
break;
}
}
assertEquals(2, checkCount);
FilterRowsMeta filterRowsMeta = new FilterRowsMeta();
Condition condition = new Condition();
condition.setNegated(false);
condition.setLeftValuename("wibble_t");
condition.setRightValuename("wobble_s");
condition.setFunction(org.pentaho.di.core.Condition.FUNC_EQUAL);
filterRowsMeta.setDefault();
filterRowsMeta.setCondition(condition);
String filterRowsPluginPid = PluginRegistry.getInstance().getPluginId(StepPluginType.class, filterRowsMeta);
StepMeta filterRowsStep = new StepMeta(filterRowsPluginPid, "Filter Rows", filterRowsMeta);
stringList.clear();
StringSearcher.findMetaData(filterRowsStep, 0, stringList, filterRowsMeta, 0);
checkCount = 0;
for (int i = 0; i < stringList.size(); i++) {
aResult = stringList.get(i).toString();
if (aResult.endsWith("FilterRows (stepid)")) {
checkCount++;
} else if (aResult.endsWith("Filter Rows (name)")) {
checkCount++;
}
if (checkCount == 2) {
break;
}
}
assertEquals(2, checkCount);
}
Aggregations