Search in sources :

Example 46 with VariableSpace

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

the class RunConfigurationRunExtensionPoint method callExtensionPoint.

@Override
public void callExtensionPoint(LogChannelInterface logChannelInterface, Object o) throws KettleException {
    ExecutionConfiguration executionConfiguration = (ExecutionConfiguration) ((Object[]) o)[0];
    AbstractMeta meta = (AbstractMeta) ((Object[]) o)[1];
    VariableSpace variableSpace = (VariableSpace) ((Object[]) o)[2];
    Repository repository = (Repository) ((Object[]) o)[3];
    EmbeddedMetaStore embeddedMetaStore = meta.getEmbeddedMetaStore();
    RunConfiguration runConfiguration = runConfigurationManager.load(executionConfiguration.getRunConfiguration());
    if (runConfiguration == null) {
        RunConfigurationManager embeddedRunConfigurationManager = EmbeddedRunConfigurationManager.build(embeddedMetaStore);
        runConfiguration = embeddedRunConfigurationManager.load(executionConfiguration.getRunConfiguration());
    }
    if (runConfiguration != null) {
        RunConfigurationExecutor runConfigurationExecutor = runConfigurationManager.getExecutor(runConfiguration.getType());
        if (runConfigurationExecutor != null) {
            runConfigurationExecutor.execute(runConfiguration, executionConfiguration, meta, variableSpace, repository);
        }
    } else {
        String name = "";
        if (variableSpace instanceof TransMeta) {
            name = ((TransMeta) variableSpace).getFilename();
        }
        throw new KettleException(BaseMessages.getString(PKG, "RunConfigurationRunExtensionPoint.ConfigNotFound.Error", name, executionConfiguration.getRunConfiguration(), "{0}"));
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) Repository(org.pentaho.di.repository.Repository) RunConfiguration(org.pentaho.di.engine.configuration.api.RunConfiguration) VariableSpace(org.pentaho.di.core.variables.VariableSpace) RunConfigurationManager(org.pentaho.di.engine.configuration.impl.RunConfigurationManager) EmbeddedRunConfigurationManager(org.pentaho.di.engine.configuration.impl.EmbeddedRunConfigurationManager) AbstractMeta(org.pentaho.di.base.AbstractMeta) TransMeta(org.pentaho.di.trans.TransMeta) ExecutionConfiguration(org.pentaho.di.ExecutionConfiguration) RunConfigurationExecutor(org.pentaho.di.engine.configuration.api.RunConfigurationExecutor) EmbeddedMetaStore(org.pentaho.di.core.attributes.metastore.EmbeddedMetaStore)

Example 47 with VariableSpace

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

the class SpoonDBDelegate method newConnection.

public void newConnection(HasDatabasesInterface hasDatabasesInterface) {
    DatabaseMeta databaseMeta = new DatabaseMeta();
    if (hasDatabasesInterface instanceof VariableSpace) {
        databaseMeta.shareVariablesWith((VariableSpace) hasDatabasesInterface);
    } else {
        databaseMeta.initializeVariablesFrom(null);
    }
    getDatabaseDialog().setDatabaseMeta(databaseMeta);
    String con_name = getDatabaseDialog().open();
    if (!Utils.isEmpty(con_name)) {
        con_name = con_name.trim();
        databaseMeta.setName(con_name);
        databaseMeta.setDisplayName(con_name);
        databaseMeta = getDatabaseDialog().getDatabaseMeta();
        if (databaseMeta.findDatabase(hasDatabasesInterface.getDatabases(), con_name) == null) {
            hasDatabasesInterface.addDatabase(databaseMeta);
            spoon.addUndoNew((UndoInterface) hasDatabasesInterface, new DatabaseMeta[] { (DatabaseMeta) databaseMeta.clone() }, new int[] { hasDatabasesInterface.indexOfDatabase(databaseMeta) });
            if (spoon.rep != null) {
                try {
                    if (!spoon.rep.getSecurityProvider().isReadOnly()) {
                        // spoon.rep.getDatabaseID(  )
                        spoon.rep.save(databaseMeta, Const.VERSION_COMMENT_INITIAL_VERSION, null);
                    } else {
                        throw new KettleException(BaseMessages.getString(PKG, "Spoon.Dialog.Exception.ReadOnlyRepositoryUser"));
                    }
                } catch (KettleException e) {
                    new ErrorDialog(spoon.getShell(), BaseMessages.getString(PKG, "Spoon.Dialog.ErrorSavingConnection.Title"), BaseMessages.getString(PKG, "Spoon.Dialog.ErrorSavingConnection.Message", databaseMeta.getName()), e);
                }
            }
            spoon.refreshTree();
        } else {
            DatabaseDialog.showDatabaseExistsDialog(spoon.getShell(), databaseMeta);
        }
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) VariableSpace(org.pentaho.di.core.variables.VariableSpace) ErrorDialog(org.pentaho.di.ui.core.dialog.ErrorDialog) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta)

Example 48 with VariableSpace

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

the class MetaInjectMetaTest method testLoadMappingMetaWhenConnectedToRep.

@Test
public void testLoadMappingMetaWhenConnectedToRep() throws Exception {
    String variablePath = "Internal.Entry.Current.Directory";
    String virtualDir = "/testFolder/test";
    String fileName = "testTrans.ktr";
    VariableSpace variables = new Variables();
    variables.setVariable(variablePath, virtualDir);
    MetaInjectMeta metaInjectMetaMock = mock(MetaInjectMeta.class);
    when(metaInjectMetaMock.getSpecificationMethod()).thenReturn(ObjectLocationSpecificationMethod.FILENAME);
    when(metaInjectMetaMock.getFileName()).thenReturn("${" + variablePath + "}/" + fileName);
    // mock repo and answers
    Repository rep = mock(Repository.class);
    doAnswer(invocation -> {
        String originalArgument = (String) (invocation.getArguments())[0];
        // be sure that the variable was replaced by real path
        assertEquals(originalArgument, virtualDir);
        return null;
    }).when(rep).findDirectory(anyString());
    doAnswer(invocation -> {
        String originalArgument = (String) (invocation.getArguments())[0];
        // be sure that transformation name was resolved correctly
        assertEquals(originalArgument, fileName);
        return mock(TransMeta.class);
    }).when(rep).loadTransformation(anyString(), any(RepositoryDirectoryInterface.class), any(ProgressMonitorListener.class), anyBoolean(), anyString());
    assertNotNull(MetaInjectMeta.loadTransformationMeta(metaInjectMetaMock, rep, null, variables));
}
Also used : Variables(org.pentaho.di.core.variables.Variables) RepositoryDirectoryInterface(org.pentaho.di.repository.RepositoryDirectoryInterface) Repository(org.pentaho.di.repository.Repository) VariableSpace(org.pentaho.di.core.variables.VariableSpace) Matchers.anyString(org.mockito.Matchers.anyString) ProgressMonitorListener(org.pentaho.di.core.ProgressMonitorListener) Test(org.junit.Test)

Example 49 with VariableSpace

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

the class StringOperationsMetaTest method testGetFields.

@Test
public void testGetFields() throws Exception {
    StringOperationsMeta meta = new StringOperationsMeta();
    meta.allocate(1);
    meta.setFieldInStream(new String[] { "field1" });
    RowMetaInterface rowMetaInterface = new RowMeta();
    ValueMetaInterface valueMeta = new ValueMetaString("field1");
    valueMeta.setStorageMetadata(new ValueMetaString("field1"));
    valueMeta.setStorageType(ValueMetaInterface.STORAGE_TYPE_BINARY_STRING);
    rowMetaInterface.addValueMeta(valueMeta);
    VariableSpace space = mock(VariableSpace.class);
    meta.getFields(rowMetaInterface, "STRING_OPERATIONS", null, null, space, null, null);
    RowMetaInterface expectedRowMeta = new RowMeta();
    expectedRowMeta.addValueMeta(new ValueMetaString("field1"));
    assertEquals(expectedRowMeta.toString(), rowMetaInterface.toString());
}
Also used : ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) RowMeta(org.pentaho.di.core.row.RowMeta) VariableSpace(org.pentaho.di.core.variables.VariableSpace) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface) 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