Search in sources :

Example 86 with Variables

use of org.pentaho.di.core.variables.Variables in project pentaho-kettle by pentaho.

the class BaseStreamStepMetaTest method testCheckErrorsOnVariablesSubstituteError.

@Test
public void testCheckErrorsOnVariablesSubstituteError() {
    List<CheckResultInterface> remarks = new ArrayList<>();
    Variables space = new Variables();
    space.setVariable("something", "0");
    meta.setBatchSize("${something}");
    meta.setBatchDuration("${something}");
    meta.check(remarks, null, null, null, null, null, null, space, null, null);
    assertEquals(1, remarks.size());
    assertEquals("The \"Number of records\" and \"Duration\" fields can’t both be set to 0. Please set a value of 1 " + "or higher for one of the fields.", remarks.get(0).getText());
    testRoundTrip(meta);
}
Also used : Variables(org.pentaho.di.core.variables.Variables) ArrayList(java.util.ArrayList) CheckResultInterface(org.pentaho.di.core.CheckResultInterface) Test(org.junit.Test)

Example 87 with Variables

use of org.pentaho.di.core.variables.Variables in project pentaho-kettle by pentaho.

the class JobExecutorMetaTest method testLoadJobMeta.

@Test
public void testLoadJobMeta() throws KettleException {
    String param1 = "param1";
    String param2 = "param2";
    String param3 = "param3";
    String parentValue1 = "parentValue1";
    String parentValue2 = "parentValue2";
    String childValue3 = "childValue3";
    JobExecutorMeta jobExecutorMeta = spy(new JobExecutorMeta());
    Repository repository = Mockito.mock(Repository.class);
    JobMeta meta = new JobMeta();
    meta.setVariable(param2, "childValue2 should be override");
    meta.setVariable(param3, childValue3);
    Mockito.doReturn(meta).when(repository).loadJob(Mockito.eq("test.kjb"), Mockito.anyObject(), Mockito.anyObject(), Mockito.anyObject());
    VariableSpace parentSpace = new Variables();
    parentSpace.setVariable(param1, parentValue1);
    parentSpace.setVariable(param2, parentValue2);
    jobExecutorMeta.setSpecificationMethod(ObjectLocationSpecificationMethod.FILENAME);
    jobExecutorMeta.setFileName("/home/admin/test.kjb");
    JobMeta jobMeta;
    jobExecutorMeta.getParameters().setInheritingAllVariables(false);
    jobMeta = JobExecutorMeta.loadJobMeta(jobExecutorMeta, repository, parentSpace);
    Assert.assertEquals(null, jobMeta.getVariable(param1));
    Assert.assertEquals(parentValue2, jobMeta.getVariable(param2));
    Assert.assertEquals(childValue3, jobMeta.getVariable(param3));
    jobExecutorMeta.getParameters().setInheritingAllVariables(true);
    jobMeta = JobExecutorMeta.loadJobMeta(jobExecutorMeta, repository, parentSpace);
    Assert.assertEquals(parentValue1, jobMeta.getVariable(param1));
    Assert.assertEquals(parentValue2, jobMeta.getVariable(param2));
    Assert.assertEquals(childValue3, jobMeta.getVariable(param3));
}
Also used : Variables(org.pentaho.di.core.variables.Variables) Repository(org.pentaho.di.repository.Repository) JobMeta(org.pentaho.di.job.JobMeta) VariableSpace(org.pentaho.di.core.variables.VariableSpace) Test(org.junit.Test)

Example 88 with Variables

use of org.pentaho.di.core.variables.Variables in project pentaho-kettle by pentaho.

the class Translator2 method addLists.

private void addLists() {
    Composite composite = new Composite(sashform, SWT.NONE);
    props.setLook(composite);
    FormLayout formLayout = new FormLayout();
    formLayout.marginHeight = Const.FORM_MARGIN;
    formLayout.marginWidth = Const.FORM_MARGIN;
    composite.setLayout(formLayout);
    wLocale = new List(composite, SWT.SINGLE | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
    FormData fdLocale = new FormData();
    fdLocale.left = new FormAttachment(0, 0);
    fdLocale.right = new FormAttachment(100, 0);
    fdLocale.top = new FormAttachment(0, 0);
    fdLocale.bottom = new FormAttachment(10, 0);
    wLocale.setLayoutData(fdLocale);
    ColumnInfo[] colinfo = new ColumnInfo[] { new ColumnInfo(BaseMessages.getString(PKG, "i18nDialog.SourceFolder"), ColumnInfo.COLUMN_TYPE_TEXT, false, true), new ColumnInfo(BaseMessages.getString(PKG, "i18nDialog.Packagename"), ColumnInfo.COLUMN_TYPE_TEXT, false, true) };
    wPackages = new TableView(new Variables(), composite, SWT.FULL_SELECTION | SWT.SINGLE | SWT.BORDER, colinfo, 1, true, null, props);
    FormData fdPackages = new FormData();
    fdPackages.left = new FormAttachment(0, 0);
    fdPackages.right = new FormAttachment(100, 0);
    fdPackages.top = new FormAttachment(wLocale, Const.MARGIN);
    fdPackages.bottom = new FormAttachment(100, 0);
    wPackages.setLayoutData(fdPackages);
    wPackages.setSortable(false);
    FormData fdComposite = new FormData();
    fdComposite.left = new FormAttachment(0, 0);
    fdComposite.right = new FormAttachment(100, 0);
    fdComposite.top = new FormAttachment(0, 0);
    fdComposite.bottom = new FormAttachment(100, 0);
    composite.setLayoutData(fdComposite);
    // Add a selection listener.
    wLocale.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            refreshGrid();
        }
    });
    wPackages.table.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            refreshGrid();
        }
    });
    composite.layout();
}
Also used : FormLayout(org.eclipse.swt.layout.FormLayout) FormData(org.eclipse.swt.layout.FormData) Variables(org.pentaho.di.core.variables.Variables) Composite(org.eclipse.swt.widgets.Composite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ColumnInfo(org.pentaho.di.ui.core.widget.ColumnInfo) List(org.eclipse.swt.widgets.List) ArrayList(java.util.ArrayList) FormAttachment(org.eclipse.swt.layout.FormAttachment) TableView(org.pentaho.di.ui.core.widget.TableView)

Example 89 with Variables

use of org.pentaho.di.core.variables.Variables in project pentaho-kettle by pentaho.

the class SubjectDataBrowserDialog method addFields.

private boolean addFields() {
    // int middle = props.getMiddlePct();
    int margin = Const.MARGIN;
    if (wlSubjectMessage == null) {
        wlSubjectMessage = new Label(shell, SWT.LEFT);
        wlSubjectMessage.setText(subjectMessage);
        props.setLook(wlSubjectMessage);
        FormData fdlFields = new FormData();
        fdlFields.left = new FormAttachment(0, 0);
        fdlFields.top = new FormAttachment(0, margin);
        wlSubjectMessage.setLayoutData(fdlFields);
        wSubject = new CCombo(shell, SWT.LEFT | SWT.READ_ONLY | SWT.BORDER);
        wSubject.setItems(subjects);
        wSubject.setText(selectedSubject);
        props.setLook(wSubject);
        FormData fdlSubject = new FormData();
        fdlSubject.left = new FormAttachment(wlSubjectMessage, margin);
        // fdlSubject.right = new FormAttachment(100, 0);
        fdlSubject.top = new FormAttachment(wlSubjectMessage, 0, SWT.CENTER);
        wSubject.setLayoutData(fdlSubject);
        wSubject.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent arg0) {
                selectedSubject = wSubject.getText();
                // Refresh
                addFields();
            }
        });
    } else {
        wFields.dispose();
    }
    RowMetaInterface rowMeta = metaMap.get(selectedSubject);
    List<Object[]> buffer = dataMap.get(selectedSubject);
    // 
    if (buffer == null) {
        buffer = new ArrayList<Object[]>();
    }
    // ColumnInfo[] colinf = new ColumnInfo[rowMeta==null ? 0 : rowMeta.size()];
    ColumnInfo[] colinf = new ColumnInfo[rowMeta.size()];
    for (int i = 0; i < rowMeta.size(); i++) {
        ValueMetaInterface v = rowMeta.getValueMeta(i);
        colinf[i] = new ColumnInfo(v.getName(), ColumnInfo.COLUMN_TYPE_TEXT, v.isNumeric());
        colinf[i].setToolTip(v.toStringMeta());
        colinf[i].setValueMeta(v);
    }
    wFields = new TableView(new Variables(), shell, SWT.BORDER | SWT.FULL_SELECTION | SWT.MULTI, colinf, 0, null, props);
    wFields.setShowingBlueNullValues(true);
    FormData fdFields = new FormData();
    fdFields.left = new FormAttachment(0, 0);
    fdFields.top = new FormAttachment(wSubject, margin);
    fdFields.right = new FormAttachment(100, 0);
    fdFields.bottom = new FormAttachment(100, -50);
    wFields.setLayoutData(fdFields);
    // 
    for (int i = 0; i < buffer.size(); i++) {
        TableItem item;
        if (i == 0) {
            item = wFields.table.getItem(i);
        } else {
            item = new TableItem(wFields.table, SWT.NONE);
        }
        Object[] rowData = buffer.get(i);
        getDataForRow(item, rowMeta, rowData, i + 1);
    }
    if (!wFields.isDisposed()) {
        wFields.optWidth(true, 200);
    }
    shell.layout(true, true);
    return false;
}
Also used : FormData(org.eclipse.swt.layout.FormData) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) TableItem(org.eclipse.swt.widgets.TableItem) Label(org.eclipse.swt.widgets.Label) ColumnInfo(org.pentaho.di.ui.core.widget.ColumnInfo) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface) Variables(org.pentaho.di.core.variables.Variables) CCombo(org.eclipse.swt.custom.CCombo) SelectionEvent(org.eclipse.swt.events.SelectionEvent) FormAttachment(org.eclipse.swt.layout.FormAttachment) TableView(org.pentaho.di.ui.core.widget.TableView)

Example 90 with Variables

use of org.pentaho.di.core.variables.Variables in project pentaho-kettle by pentaho.

the class XMLOutputMetaTest method testGetFields.

@Test
public void testGetFields() throws Exception {
    XMLOutputMeta xmlOutputMeta = new XMLOutputMeta();
    xmlOutputMeta.setDefault();
    XMLField xmlField = new XMLField();
    xmlField.setFieldName("aField");
    xmlField.setLength(10);
    xmlField.setPrecision(3);
    xmlOutputMeta.setOutputFields(new XMLField[] { xmlField });
    RowMetaInterface row = mock(RowMetaInterface.class);
    RowMetaInterface rmi = mock(RowMetaInterface.class);
    StepMeta nextStep = mock(StepMeta.class);
    Repository repo = mock(Repository.class);
    IMetaStore metastore = mock(IMetaStore.class);
    ValueMetaInterface vmi = mock(ValueMetaInterface.class);
    when(row.searchValueMeta("aField")).thenReturn(vmi);
    xmlOutputMeta.getFields(row, "", new RowMetaInterface[] { rmi }, nextStep, new Variables(), repo, metastore);
    verify(vmi).setLength(10, 3);
}
Also used : Variables(org.pentaho.di.core.variables.Variables) Repository(org.pentaho.di.repository.Repository) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) StepMeta(org.pentaho.di.trans.step.StepMeta) IMetaStore(org.pentaho.metastore.api.IMetaStore) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface) Test(org.junit.Test)

Aggregations

Variables (org.pentaho.di.core.variables.Variables)119 Test (org.junit.Test)67 TransMeta (org.pentaho.di.trans.TransMeta)31 ArrayList (java.util.ArrayList)25 CheckResultInterface (org.pentaho.di.core.CheckResultInterface)20 RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)20 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)20 StepMeta (org.pentaho.di.trans.step.StepMeta)18 RowMeta (org.pentaho.di.core.row.RowMeta)17 RowMetaAndData (org.pentaho.di.core.RowMetaAndData)16 VariableSpace (org.pentaho.di.core.variables.VariableSpace)14 Repository (org.pentaho.di.repository.Repository)12 TableView (org.pentaho.di.ui.core.widget.TableView)10 FormAttachment (org.eclipse.swt.layout.FormAttachment)9 FormData (org.eclipse.swt.layout.FormData)9 ColumnInfo (org.pentaho.di.ui.core.widget.ColumnInfo)9 Label (org.eclipse.swt.widgets.Label)8 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)7 SelectionEvent (org.eclipse.swt.events.SelectionEvent)7 DummyTransMeta (org.pentaho.di.trans.steps.dummytrans.DummyTransMeta)7