Search in sources :

Example 26 with Condition

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;
}
Also used : Condition(org.pentaho.di.core.Condition) PerformanceLogTable(org.pentaho.di.core.logging.PerformanceLogTable) SlaveStepCopyPartitionDistribution(org.pentaho.di.trans.SlaveStepCopyPartitionDistribution) PartitionSchema(org.pentaho.di.partition.PartitionSchema) TransMeta(org.pentaho.di.trans.TransMeta) TransDependency(org.pentaho.di.trans.TransDependency) SlaveServer(org.pentaho.di.cluster.SlaveServer) StepMeta(org.pentaho.di.trans.step.StepMeta) BaseStepMeta(org.pentaho.di.trans.step.BaseStepMeta) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) ChannelLogTable(org.pentaho.di.core.logging.ChannelLogTable) StepLogTable(org.pentaho.di.core.logging.StepLogTable) TransLogTable(org.pentaho.di.core.logging.TransLogTable)

Example 27 with Condition

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;
    }
}
Also used : Condition(org.pentaho.di.core.Condition) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Node(org.w3c.dom.Node) ErrorDialog(org.pentaho.di.ui.core.dialog.ErrorDialog) MenuItem(org.eclipse.swt.widgets.MenuItem) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) Document(org.w3c.dom.Document) Point(org.eclipse.swt.graphics.Point) KettleXMLException(org.pentaho.di.core.exception.KettleXMLException) SelectionEvent(org.eclipse.swt.events.SelectionEvent) KettleXMLException(org.pentaho.di.core.exception.KettleXMLException) Menu(org.eclipse.swt.widgets.Menu)

Example 28 with Condition

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();
}
Also used : Condition(org.pentaho.di.core.Condition)

Example 29 with Condition

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;
    }
}
Also used : Condition(org.pentaho.di.core.Condition) DataNode(org.pentaho.platform.api.repository2.unified.data.node.DataNode)

Example 30 with Condition

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);
}
Also used : FilterRowsMeta(org.pentaho.di.trans.steps.filterrows.FilterRowsMeta) Condition(org.pentaho.di.core.Condition) ArrayList(java.util.ArrayList) StepMeta(org.pentaho.di.trans.step.StepMeta) DummyTransMeta(org.pentaho.di.trans.steps.dummytrans.DummyTransMeta) Test(org.junit.Test)

Aggregations

Condition (org.pentaho.di.core.Condition)42 Test (org.junit.Test)14 Matchers.anyString (org.mockito.Matchers.anyString)6 RowMeta (org.pentaho.di.core.row.RowMeta)6 SQLCondition (org.pentaho.di.core.sql.SQLCondition)6 StepMeta (org.pentaho.di.trans.step.StepMeta)6 KettleException (org.pentaho.di.core.exception.KettleException)5 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)5 SQL (org.pentaho.di.core.sql.SQL)5 ParameterGenerationTest.newCondition (org.pentaho.di.trans.dataservice.optimization.paramgen.ParameterGenerationTest.newCondition)5 KettleStepException (org.pentaho.di.core.exception.KettleStepException)4 KettleXMLException (org.pentaho.di.core.exception.KettleXMLException)4 ValueMetaAndData (org.pentaho.di.core.row.ValueMetaAndData)4 JUnitMatchers.containsString (org.junit.matchers.JUnitMatchers.containsString)3 RowMetaAndData (org.pentaho.di.core.RowMetaAndData)3 ArrayList (java.util.ArrayList)2 LinkedList (java.util.LinkedList)2 Map (java.util.Map)2 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)2 SelectionEvent (org.eclipse.swt.events.SelectionEvent)2