Search in sources :

Example 26 with VariableSpace

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

the class Spoon method fillVariables.

private void fillVariables(RowMetaAndData vars) {
    TransMeta[] transMetas = getLoadedTransformations();
    JobMeta[] jobMetas = getLoadedJobs();
    if ((transMetas == null || transMetas.length == 0) && (jobMetas == null || jobMetas.length == 0)) {
        return;
    }
    Properties sp = new Properties();
    sp.putAll(System.getProperties());
    VariableSpace space = Variables.getADefaultVariableSpace();
    String[] keys = space.listVariables();
    for (String key : keys) {
        sp.put(key, space.getVariable(key));
    }
    for (TransMeta transMeta : transMetas) {
        List<String> list = transMeta.getUsedVariables();
        for (String varName : list) {
            String varValue = sp.getProperty(varName, "");
            if (vars.getRowMeta().indexOfValue(varName) < 0 && !varName.startsWith(Const.INTERNAL_VARIABLE_PREFIX)) {
                vars.addValue(new ValueMetaString(varName), varValue);
            }
        }
    }
    for (JobMeta jobMeta : jobMetas) {
        List<String> list = jobMeta.getUsedVariables();
        for (String varName : list) {
            String varValue = sp.getProperty(varName, "");
            if (vars.getRowMeta().indexOfValue(varName) < 0 && !varName.startsWith(Const.INTERNAL_VARIABLE_PREFIX)) {
                vars.addValue(new ValueMetaString(varName), varValue);
            }
        }
    }
}
Also used : ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) JobMeta(org.pentaho.di.job.JobMeta) VariableSpace(org.pentaho.di.core.variables.VariableSpace) TransMeta(org.pentaho.di.trans.TransMeta) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) Properties(java.util.Properties)

Example 27 with VariableSpace

use of org.pentaho.di.core.variables.VariableSpace in project pentaho-metaverse by pentaho.

the class MongoDbResourceInfoTest method setUp.

@Before
public void setUp() throws Exception {
    meta = mock(MongoDbMeta.class);
    when(meta.getDbName()).thenReturn(null);
    when(meta.getPort()).thenReturn(null);
    when(meta.getHostnames()).thenReturn(null);
    when(meta.getAuthenticationUser()).thenReturn(null);
    when(meta.getAuthenticationPassword()).thenReturn(null);
    when(meta.getUseAllReplicaSetMembers()).thenReturn(false);
    when(meta.getUseKerberosAuthentication()).thenReturn(false);
    when(meta.getConnectTimeout()).thenReturn(null);
    when(meta.getSocketTimeout()).thenReturn(null);
    when(meta.getCollection()).thenReturn(null);
    StepMeta stepMeta = new StepMeta();
    TransMeta transMeta = new TransMeta();
    stepMeta.setParentTransMeta(transMeta);
    VariableSpace variables = new Variables();
    when(meta.getParentStepMeta()).thenReturn(stepMeta);
    info = new MongoDbResourceInfo(meta);
}
Also used : Variables(org.pentaho.di.core.variables.Variables) VariableSpace(org.pentaho.di.core.variables.VariableSpace) TransMeta(org.pentaho.di.trans.TransMeta) StepMeta(org.pentaho.di.trans.step.StepMeta) MongoDbMeta(org.pentaho.di.trans.steps.mongodb.MongoDbMeta) Before(org.junit.Before)

Example 28 with VariableSpace

use of org.pentaho.di.core.variables.VariableSpace in project pdi-dataservice-server-plugin by pentaho.

the class ParameterGeneration method setQueryParameter.

protected String setQueryParameter(String query, String parameterValue) {
    VariableSpace varSpace = new Variables();
    varSpace.setVariable(getParameterName(), parameterValue);
    return varSpace.environmentSubstitute(query);
}
Also used : Variables(org.pentaho.di.core.variables.Variables) VariableSpace(org.pentaho.di.core.variables.VariableSpace)

Example 29 with VariableSpace

use of org.pentaho.di.core.variables.VariableSpace in project pdi-dataservice-server-plugin by pentaho.

the class MongoDbBasicValidation method checkStep.

@Override
public void checkStep(CheckStepsExtension checkStepExtension, DataServiceMeta dataServiceMeta, LogChannelInterface log) {
    StepMeta stepMeta = checkStepExtension.getStepMetas()[0];
    List<CheckResultInterface> remarks = checkStepExtension.getRemarks();
    MongoDbInputMeta mongoDbMeta = (MongoDbInputMeta) checkStepExtension.getStepMetas()[0].getStepMetaInterface();
    VariableSpace space = checkStepExtension.getVariableSpace();
    checkOutputJson(stepMeta, remarks, mongoDbMeta);
    checkPushdownParameter(stepMeta, remarks, mongoDbMeta, space);
    checkParameterGenerationOptimizedMeta(checkStepExtension, dataServiceMeta, log);
}
Also used : VariableSpace(org.pentaho.di.core.variables.VariableSpace) MongoDbInputMeta(org.pentaho.di.trans.steps.mongodbinput.MongoDbInputMeta) CheckResultInterface(org.pentaho.di.core.CheckResultInterface) StepMeta(org.pentaho.di.trans.step.StepMeta)

Example 30 with VariableSpace

use of org.pentaho.di.core.variables.VariableSpace in project pentaho-metaverse by pentaho.

the class JdbcResourceInfoTest method testDbMetaVarPort.

@Test
public void testDbMetaVarPort() throws Exception {
    DatabaseMeta dbMeta = mock(DatabaseMeta.class);
    DatabaseInterface dbInterface = mock(DatabaseInterface.class);
    when(dbMeta.getDatabaseInterface()).thenReturn(dbInterface);
    when(dbMeta.getAccessTypeDesc()).thenReturn("Native");
    final VariableSpace vs = new Variables();
    when(dbMeta.getDatabasePortNumberString()).thenReturn("${port_var}");
    when(dbMeta.environmentSubstitute(any(String.class))).thenAnswer(new Answer<String>() {

        public String answer(InvocationOnMock invocation) throws Throwable {
            return vs.environmentSubstitute((String) invocation.getArguments()[0]);
        }
    });
    // check if var replaced
    vs.setVariable("port_var", "4321");
    JdbcResourceInfo jdbcResourceInfo = new JdbcResourceInfo(dbMeta);
    assertEquals(jdbcResourceInfo.getPort(), new Integer(4321));
    // check no exception when empty
    vs.setVariable("port_var", "");
    jdbcResourceInfo = new JdbcResourceInfo(dbMeta);
}
Also used : Variables(org.pentaho.di.core.variables.Variables) DatabaseInterface(org.pentaho.di.core.database.DatabaseInterface) VariableSpace(org.pentaho.di.core.variables.VariableSpace) InvocationOnMock(org.mockito.invocation.InvocationOnMock) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) Test(org.junit.Test)

Aggregations

VariableSpace (org.pentaho.di.core.variables.VariableSpace)49 Test (org.junit.Test)21 Variables (org.pentaho.di.core.variables.Variables)14 KettleException (org.pentaho.di.core.exception.KettleException)12 Repository (org.pentaho.di.repository.Repository)10 TransMeta (org.pentaho.di.trans.TransMeta)10 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)9 RepositoryDirectoryInterface (org.pentaho.di.repository.RepositoryDirectoryInterface)8 StepMeta (org.pentaho.di.trans.step.StepMeta)8 RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)7 KettleXMLException (org.pentaho.di.core.exception.KettleXMLException)6 IOException (java.io.IOException)5 FileObject (org.apache.commons.vfs2.FileObject)5 CurrentDirectoryResolver (org.pentaho.di.core.util.CurrentDirectoryResolver)5 HashMap (java.util.HashMap)4 Properties (java.util.Properties)4 Matchers.anyString (org.mockito.Matchers.anyString)4 DatabaseMeta (org.pentaho.di.core.database.DatabaseMeta)4 KettleDatabaseException (org.pentaho.di.core.exception.KettleDatabaseException)4 ValueMetaInterface (org.pentaho.di.core.row.ValueMetaInterface)4