Search in sources :

Example 1 with Transformation

use of org.pentaho.di.engine.api.model.Transformation in project pentaho-kettle by pentaho.

the class TransMetaConverter method convert.

public static Transformation convert(TransMeta transMeta) {
    final org.pentaho.di.engine.model.Transformation transformation = new org.pentaho.di.engine.model.Transformation(createTransformationId(transMeta));
    try {
        TransMeta copyTransMeta = (TransMeta) transMeta.realClone(false);
        cleanupDisabledHops(copyTransMeta);
        // Turn off lazy conversion for AEL for now
        disableLazyConversion(copyTransMeta);
        resolveStepMetaResources(copyTransMeta);
        copyTransMeta.getSteps().forEach(createOperation(transformation));
        findHops(copyTransMeta, hop -> true).forEach(createHop(transformation));
        transformation.setConfig(TRANS_META_CONF_KEY, copyTransMeta.getXML());
        transformation.setConfig(TRANS_META_NAME_CONF_KEY, Optional.ofNullable(transMeta.getName()).orElse(TRANS_DEFAULT_NAME));
        Map<String, Transformation> subTransformations = copyTransMeta.getResourceDependencies().stream().flatMap(resourceReference -> resourceReference.getEntries().stream()).filter(entry -> ResourceEntry.ResourceType.ACTIONFILE.equals(entry.getResourcetype())).collect(toMap(ResourceEntry::getResource, entry -> {
            try {
                Repository repository = copyTransMeta.getRepository();
                if (repository != null) {
                    Path path = Paths.get(entry.getResource());
                    RepositoryDirectoryInterface directory = repository.findDirectory(path.getParent().toString().replace(File.separator, "/"));
                    return convert(repository.loadTransformation(path.getFileName().toString(), directory, null, true, null));
                }
                return convert(new TransMeta(entry.getResource(), copyTransMeta.getParentVariableSpace()));
            } catch (KettleException e) {
                throw new RuntimeException(e);
            }
        }));
        transformation.setConfig(SUB_TRANSFORMATIONS_KEY, (Serializable) subTransformations);
    } catch (KettleException e) {
        Throwables.propagate(e);
    }
    return transformation;
}
Also used : IntStream(java.util.stream.IntStream) Transformation(org.pentaho.di.engine.api.model.Transformation) Hop(org.pentaho.di.engine.api.model.Hop) KettleException(org.pentaho.di.core.exception.KettleException) Operation(org.pentaho.di.engine.api.model.Operation) TransMeta(org.pentaho.di.trans.TransMeta) Collectors.toMap(java.util.stream.Collectors.toMap) Map(java.util.Map) CsvInputMeta(org.pentaho.di.trans.steps.csvinput.CsvInputMeta) Path(java.nio.file.Path) RepositoryDirectoryInterface(org.pentaho.di.repository.RepositoryDirectoryInterface) StepMeta(org.pentaho.di.trans.step.StepMeta) StepMetaInterface(org.pentaho.di.trans.step.StepMetaInterface) Predicate(java.util.function.Predicate) Repository(org.pentaho.di.repository.Repository) ResourceEntry(org.pentaho.di.resource.ResourceEntry) Throwables(com.google.common.base.Throwables) Utils(org.pentaho.di.core.util.Utils) Collectors(java.util.stream.Collectors) File(java.io.File) Serializable(java.io.Serializable) Consumer(java.util.function.Consumer) ResolvableResource(org.pentaho.di.workarounds.ResolvableResource) List(java.util.List) TransHopMeta(org.pentaho.di.trans.TransHopMeta) Paths(java.nio.file.Paths) Optional(java.util.Optional) TableInputMeta(org.pentaho.di.trans.steps.tableinput.TableInputMeta) Path(java.nio.file.Path) RepositoryDirectoryInterface(org.pentaho.di.repository.RepositoryDirectoryInterface) KettleException(org.pentaho.di.core.exception.KettleException) Transformation(org.pentaho.di.engine.api.model.Transformation) TransMeta(org.pentaho.di.trans.TransMeta) Repository(org.pentaho.di.repository.Repository)

Example 2 with Transformation

use of org.pentaho.di.engine.api.model.Transformation in project pentaho-kettle by pentaho.

the class TransMetaConverterTest method transConfigItems.

@Test
public void transConfigItems() throws Exception {
    TransMeta meta = new TransMeta();
    meta.setName("foo");
    Transformation trans = TransMetaConverter.convert(meta);
    assertThat(trans.getConfig().get(TransMetaConverter.TRANS_META_NAME_CONF_KEY), is("foo"));
    assertThat((String) trans.getConfig().get(TransMetaConverter.TRANS_META_CONF_KEY), startsWith("<transformation>"));
}
Also used : Transformation(org.pentaho.di.engine.api.model.Transformation) TransMeta(org.pentaho.di.trans.TransMeta) DummyTransMeta(org.pentaho.di.trans.steps.dummytrans.DummyTransMeta) Test(org.junit.Test)

Example 3 with Transformation

use of org.pentaho.di.engine.api.model.Transformation in project pentaho-kettle by pentaho.

the class TransMetaConverterTest method errorHops.

@Test
public void errorHops() throws Exception {
    TransMeta meta = new TransMeta();
    meta.setFilename("fileName");
    StepMeta from = new StepMeta("step1", stepMetaInterface);
    meta.addStep(from);
    StepMeta to = new StepMeta("step2", stepMetaInterface);
    meta.addStep(to);
    meta.addTransHop(new TransHopMeta(from, to));
    StepMeta error = new StepMeta("errorHandler", stepMetaInterface);
    meta.addStep(error);
    TransHopMeta errorHop = new TransHopMeta(from, error);
    errorHop.setErrorHop(true);
    meta.addTransHop(errorHop);
    Transformation trans = TransMetaConverter.convert(meta);
    Map<String, List<Hop>> hops = trans.getHops().stream().collect(Collectors.groupingBy(Hop::getType));
    List<Hop> normalHops = hops.get(Hop.TYPE_NORMAL);
    assertThat(normalHops.size(), is(1));
    assertThat(normalHops.get(0).getTo().getId(), is("step2"));
    List<Hop> errorHops = hops.get(Hop.TYPE_ERROR);
    assertThat(errorHops.size(), is(1));
    assertThat(errorHops.get(0).getTo().getId(), is("errorHandler"));
    assertThat(hops.values().stream().flatMap(List::stream).map(Hop::getFrom).map(Operation::getId).collect(Collectors.toList()), everyItem(equalTo("step1")));
}
Also used : Transformation(org.pentaho.di.engine.api.model.Transformation) TransMeta(org.pentaho.di.trans.TransMeta) DummyTransMeta(org.pentaho.di.trans.steps.dummytrans.DummyTransMeta) Hop(org.pentaho.di.engine.api.model.Hop) List(java.util.List) TransHopMeta(org.pentaho.di.trans.TransHopMeta) Operation(org.pentaho.di.engine.api.model.Operation) StepMeta(org.pentaho.di.trans.step.StepMeta) BaseStepMeta(org.pentaho.di.trans.step.BaseStepMeta) Test(org.junit.Test)

Example 4 with Transformation

use of org.pentaho.di.engine.api.model.Transformation in project pentaho-kettle by pentaho.

the class TransMetaConverterTest method testIncludesSubTransformations.

@Test
public void testIncludesSubTransformations() throws Exception {
    TransMeta parentTransMeta = new TransMeta(getClass().getResource("trans-meta-converter-parent.ktr").getPath());
    Transformation transformation = TransMetaConverter.convert(parentTransMeta);
    @SuppressWarnings({ "unchecked", "ConstantConditions" }) HashMap<String, Transformation> config = (HashMap<String, Transformation>) transformation.getConfig(TransMetaConverter.SUB_TRANSFORMATIONS_KEY).get();
    assertEquals(1, config.size());
    assertNotNull(config.get("file://" + getClass().getResource("trans-meta-converter-sub.ktr").getPath()));
}
Also used : Transformation(org.pentaho.di.engine.api.model.Transformation) HashMap(java.util.HashMap) TransMeta(org.pentaho.di.trans.TransMeta) DummyTransMeta(org.pentaho.di.trans.steps.dummytrans.DummyTransMeta) Test(org.junit.Test)

Example 5 with Transformation

use of org.pentaho.di.engine.api.model.Transformation in project pentaho-kettle by pentaho.

the class TransMetaConverterTest method testDisabledHops.

@Test
public void testDisabledHops() {
    TransMeta trans = new TransMeta();
    StepMeta start = new StepMeta("Start", stepMetaInterface);
    trans.addStep(start);
    StepMeta withEnabledHop = new StepMeta("WithEnabledHop", stepMetaInterface);
    trans.addStep(withEnabledHop);
    StepMeta withDisabledHop = new StepMeta("WithDisabledHop", stepMetaInterface);
    trans.addStep(withDisabledHop);
    StepMeta shouldStay = new StepMeta("ShouldStay", stepMetaInterface);
    trans.addStep(shouldStay);
    StepMeta shouldNotStay = new StepMeta("ShouldNotStay", stepMetaInterface);
    trans.addStep(shouldNotStay);
    StepMeta withEnabledAndDisabledHops = new StepMeta("WithEnabledAndDisabledHops", stepMetaInterface);
    trans.addStep(withEnabledAndDisabledHops);
    StepMeta afterEnabledDisabled = new StepMeta("AfterEnabledDisabled", stepMetaInterface);
    trans.addStep(afterEnabledDisabled);
    trans.addTransHop(new TransHopMeta(start, withEnabledHop));
    trans.addTransHop(new TransHopMeta(start, withDisabledHop, false));
    trans.addTransHop(new TransHopMeta(withEnabledHop, shouldStay));
    trans.addTransHop(new TransHopMeta(withDisabledHop, shouldStay));
    trans.addTransHop(new TransHopMeta(withDisabledHop, shouldNotStay));
    trans.addTransHop(new TransHopMeta(start, withEnabledAndDisabledHops));
    trans.addTransHop(new TransHopMeta(withEnabledHop, withEnabledAndDisabledHops, false));
    trans.addTransHop(new TransHopMeta(withEnabledAndDisabledHops, afterEnabledDisabled));
    Transformation transformation = TransMetaConverter.convert(trans);
    List<String> steps = transformation.getOperations().stream().map(op -> op.getId()).collect(Collectors.toList());
    assertThat("Only 5 ops should exist", steps.size(), is(5));
    assertThat(steps, hasItems("Start", "WithEnabledHop", "ShouldStay", "WithEnabledAndDisabledHops", "AfterEnabledDisabled"));
    List<String> hops = transformation.getHops().stream().map(hop -> hop.getId()).collect(Collectors.toList());
    assertThat("Only 4 hops should exist", hops.size(), is(4));
    assertThat(hops, hasItems("Start -> WithEnabledHop", "WithEnabledHop -> ShouldStay", "Start -> WithEnabledAndDisabledHops", "WithEnabledAndDisabledHops -> AfterEnabledDisabled"));
}
Also used : Transformation(org.pentaho.di.engine.api.model.Transformation) CoreMatchers.is(org.hamcrest.CoreMatchers.is) Trans(org.pentaho.di.trans.Trans) StepDataInterface(org.pentaho.di.trans.step.StepDataInterface) StepPluginType(org.pentaho.di.core.plugins.StepPluginType) Hop(org.pentaho.di.engine.api.model.Hop) CoreMatchers.startsWith(org.hamcrest.CoreMatchers.startsWith) KettleClientEnvironment(org.pentaho.di.core.KettleClientEnvironment) Operation(org.pentaho.di.engine.api.model.Operation) TransMeta(org.pentaho.di.trans.TransMeta) KettleXMLException(org.pentaho.di.core.exception.KettleXMLException) Document(org.w3c.dom.Document) Matchers.eq(org.mockito.Matchers.eq) Spy(org.mockito.Spy) KettleMissingPluginsException(org.pentaho.di.core.exception.KettleMissingPluginsException) Map(java.util.Map) Mockito.doAnswer(org.mockito.Mockito.doAnswer) CsvInputMeta(org.pentaho.di.trans.steps.csvinput.CsvInputMeta) ClassRule(org.junit.ClassRule) Mockito.doReturn(org.mockito.Mockito.doReturn) StepInterface(org.pentaho.di.trans.step.StepInterface) StepMeta(org.pentaho.di.trans.step.StepMeta) AfterClass(org.junit.AfterClass) StepMetaInterface(org.pentaho.di.trans.step.StepMetaInterface) Variables(org.pentaho.di.core.variables.Variables) MetaStoreException(org.pentaho.metastore.api.exceptions.MetaStoreException) Collectors(java.util.stream.Collectors) ResolvableResource(org.pentaho.di.workarounds.ResolvableResource) List(java.util.List) BaseStepMeta(org.pentaho.di.trans.step.BaseStepMeta) Mockito.mock(org.mockito.Mockito.mock) RestorePDIEngineEnvironment(org.pentaho.di.junit.rules.RestorePDIEngineEnvironment) BeforeClass(org.junit.BeforeClass) CoreMatchers.equalTo(org.hamcrest.CoreMatchers.equalTo) KettleException(org.pentaho.di.core.exception.KettleException) RunWith(org.junit.runner.RunWith) HashMap(java.util.HashMap) Mockito.spy(org.mockito.Mockito.spy) Answer(org.mockito.stubbing.Answer) CoreMatchers.everyItem(org.hamcrest.CoreMatchers.everyItem) InvocationOnMock(org.mockito.invocation.InvocationOnMock) XMLHandler(org.pentaho.di.core.xml.XMLHandler) PluginRegistry(org.pentaho.di.core.plugins.PluginRegistry) DummyTransMeta(org.pentaho.di.trans.steps.dummytrans.DummyTransMeta) Node(org.w3c.dom.Node) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Before(org.junit.Before) RepositoryDirectoryInterface(org.pentaho.di.repository.RepositoryDirectoryInterface) Props(org.pentaho.di.core.Props) Repository(org.pentaho.di.repository.Repository) CoreMatchers.hasItems(org.hamcrest.CoreMatchers.hasItems) Assert.assertNotNull(org.junit.Assert.assertNotNull) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) KettleEnvironment(org.pentaho.di.core.KettleEnvironment) File(java.io.File) Mockito.verify(org.mockito.Mockito.verify) Mockito.never(org.mockito.Mockito.never) MockitoJUnitRunner(org.mockito.runners.MockitoJUnitRunner) TransHopMeta(org.pentaho.di.trans.TransHopMeta) RepositoryDirectory(org.pentaho.di.repository.RepositoryDirectory) TableInputMeta(org.pentaho.di.trans.steps.tableinput.TableInputMeta) Assert.assertEquals(org.junit.Assert.assertEquals) Transformation(org.pentaho.di.engine.api.model.Transformation) TransMeta(org.pentaho.di.trans.TransMeta) DummyTransMeta(org.pentaho.di.trans.steps.dummytrans.DummyTransMeta) TransHopMeta(org.pentaho.di.trans.TransHopMeta) StepMeta(org.pentaho.di.trans.step.StepMeta) BaseStepMeta(org.pentaho.di.trans.step.BaseStepMeta) Test(org.junit.Test)

Aggregations

Transformation (org.pentaho.di.engine.api.model.Transformation)15 TransMeta (org.pentaho.di.trans.TransMeta)15 Test (org.junit.Test)12 DummyTransMeta (org.pentaho.di.trans.steps.dummytrans.DummyTransMeta)12 StepMeta (org.pentaho.di.trans.step.StepMeta)10 BaseStepMeta (org.pentaho.di.trans.step.BaseStepMeta)7 HashMap (java.util.HashMap)6 List (java.util.List)6 Operation (org.pentaho.di.engine.api.model.Operation)6 TransHopMeta (org.pentaho.di.trans.TransHopMeta)6 Map (java.util.Map)5 Collectors (java.util.stream.Collectors)5 KettleException (org.pentaho.di.core.exception.KettleException)5 Hop (org.pentaho.di.engine.api.model.Hop)5 StepMetaInterface (org.pentaho.di.trans.step.StepMetaInterface)5 Optional (java.util.Optional)3 Collectors.toMap (java.util.stream.Collectors.toMap)3 Repository (org.pentaho.di.repository.Repository)3 RepositoryDirectoryInterface (org.pentaho.di.repository.RepositoryDirectoryInterface)3 Trans (org.pentaho.di.trans.Trans)3