Search in sources :

Example 11 with Repository

use of org.pentaho.di.repository.Repository in project pentaho-kettle by pentaho.

the class WebServiceMetaTest method testGetFields.

@Test
public void testGetFields() throws Exception {
    WebServiceMeta webServiceMeta = new WebServiceMeta();
    webServiceMeta.setDefault();
    RowMetaInterface rmi = mock(RowMetaInterface.class);
    RowMetaInterface rmi2 = mock(RowMetaInterface.class);
    StepMeta nextStep = mock(StepMeta.class);
    IMetaStore metastore = mock(IMetaStore.class);
    Repository rep = mock(Repository.class);
    WebServiceField field1 = new WebServiceField();
    field1.setName("field1");
    field1.setWsName("field1WS");
    field1.setXsdType("string");
    WebServiceField field2 = new WebServiceField();
    field2.setName("field2");
    field2.setWsName("field2WS");
    field2.setXsdType("string");
    WebServiceField field3 = new WebServiceField();
    field3.setName("field3");
    field3.setWsName("field3WS");
    field3.setXsdType("string");
    webServiceMeta.setFieldsOut(Arrays.asList(field1, field2, field3));
    webServiceMeta.getFields(rmi, "idk", new RowMetaInterface[] { rmi2 }, nextStep, new Variables(), rep, metastore);
    verify(rmi).addValueMeta(argThat(matchValueMetaString("field1")));
    verify(rmi).addValueMeta(argThat(matchValueMetaString("field2")));
    verify(rmi).addValueMeta(argThat(matchValueMetaString("field3")));
}
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) Test(org.junit.Test)

Example 12 with Repository

use of org.pentaho.di.repository.Repository in project pentaho-kettle by pentaho.

the class WebServiceMetaTest method testReadRep.

@Test
public void testReadRep() throws Exception {
    Repository rep = mock(Repository.class);
    IMetaStore metastore = mock(IMetaStore.class);
    DatabaseMeta dbMeta = mock(DatabaseMeta.class);
    StringObjectId id_step = new StringObjectId("oid");
    when(rep.getStepAttributeString(id_step, "wsOperation")).thenReturn("GetCurrentExchangeRate");
    when(rep.getStepAttributeString(id_step, "wsOperationRequest")).thenReturn("opRequest");
    when(rep.getStepAttributeString(id_step, "wsOperationNamespace")).thenReturn("opNamespace");
    when(rep.getStepAttributeString(id_step, "wsInFieldContainer")).thenReturn("ifc");
    when(rep.getStepAttributeString(id_step, "wsInFieldArgument")).thenReturn("ifa");
    when(rep.getStepAttributeString(id_step, "wsOutFieldContainer")).thenReturn("ofc");
    when(rep.getStepAttributeString(id_step, "wsOutFieldArgument")).thenReturn("ofa");
    when(rep.getStepAttributeString(id_step, "proxyHost")).thenReturn("phost");
    when(rep.getStepAttributeString(id_step, "proxyPort")).thenReturn("1234");
    when(rep.getStepAttributeString(id_step, "httpLogin")).thenReturn("user");
    when(rep.getStepAttributeString(id_step, "httpPassword")).thenReturn("password");
    when(rep.getStepAttributeInteger(id_step, "callStep")).thenReturn(2L);
    when(rep.getStepAttributeBoolean(id_step, "passingInputData")).thenReturn(true);
    when(rep.getStepAttributeBoolean(id_step, 0, "compatible", true)).thenReturn(false);
    when(rep.getStepAttributeString(id_step, "repeating_element")).thenReturn("repeat");
    when(rep.getStepAttributeBoolean(id_step, 0, "reply_as_string")).thenReturn(true);
    when(rep.countNrStepAttributes(id_step, "fieldIn_ws_name")).thenReturn(2);
    when(rep.getStepAttributeString(id_step, 0, "fieldIn_name")).thenReturn("bank");
    when(rep.getStepAttributeString(id_step, 0, "fieldIn_ws_name")).thenReturn("inBank");
    when(rep.getStepAttributeString(id_step, 0, "fieldIn_xsd_type")).thenReturn("string");
    when(rep.getStepAttributeString(id_step, 1, "fieldIn_name")).thenReturn("branch");
    when(rep.getStepAttributeString(id_step, 1, "fieldIn_ws_name")).thenReturn("inBranch");
    when(rep.getStepAttributeString(id_step, 1, "fieldIn_xsd_type")).thenReturn("string");
    when(rep.countNrStepAttributes(id_step, "fieldOut_ws_name")).thenReturn(2);
    when(rep.getStepAttributeString(id_step, 0, "fieldOut_name")).thenReturn("balance");
    when(rep.getStepAttributeString(id_step, 0, "fieldOut_ws_name")).thenReturn("outBalance");
    when(rep.getStepAttributeString(id_step, 0, "fieldOut_xsd_type")).thenReturn("int");
    when(rep.getStepAttributeString(id_step, 1, "fieldOut_name")).thenReturn("transactions");
    when(rep.getStepAttributeString(id_step, 1, "fieldOut_ws_name")).thenReturn("outTransactions");
    when(rep.getStepAttributeString(id_step, 1, "fieldOut_xsd_type")).thenReturn("int");
    WebServiceMeta webServiceMeta = new WebServiceMeta(rep, metastore, id_step, Collections.singletonList(dbMeta));
    String expectedXml = "" + "    <wsURL/>\n" + "    <wsOperation>GetCurrentExchangeRate</wsOperation>\n" + "    <wsOperationRequest>opRequest</wsOperationRequest>\n" + "    <wsOperationNamespace>opNamespace</wsOperationNamespace>\n" + "    <wsInFieldContainer>ifc</wsInFieldContainer>\n" + "    <wsInFieldArgument>ifa</wsInFieldArgument>\n" + "    <wsOutFieldContainer>ofc</wsOutFieldContainer>\n" + "    <wsOutFieldArgument>ofa</wsOutFieldArgument>\n" + "    <proxyHost>phost</proxyHost>\n" + "    <proxyPort>1234</proxyPort>\n" + "    <httpLogin>user</httpLogin>\n" + "    <httpPassword>password</httpPassword>\n" + "    <callStep>2</callStep>\n" + "    <passingInputData>Y</passingInputData>\n" + "    <compatible>N</compatible>\n" + "    <repeating_element>repeat</repeating_element>\n" + "    <reply_as_string>Y</reply_as_string>\n" + "    <fieldsIn>\n" + "    <field>\n" + "        <name>bank</name>\n" + "        <wsName>inBank</wsName>\n" + "        <xsdType>string</xsdType>\n" + "    </field>\n" + "    <field>\n" + "        <name>branch</name>\n" + "        <wsName>inBranch</wsName>\n" + "        <xsdType>string</xsdType>\n" + "    </field>\n" + "      </fieldsIn>\n" + "    <fieldsOut>\n" + "    <field>\n" + "        <name>balance</name>\n" + "        <wsName>outBalance</wsName>\n" + "        <xsdType>int</xsdType>\n" + "    </field>\n" + "    <field>\n" + "        <name>transactions</name>\n" + "        <wsName>outTransactions</wsName>\n" + "        <xsdType>int</xsdType>\n" + "    </field>\n" + "      </fieldsOut>\n";
    String actualXml = TestUtils.toUnixLineSeparators(webServiceMeta.getXML());
    assertEquals(expectedXml, actualXml);
}
Also used : Repository(org.pentaho.di.repository.Repository) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) IMetaStore(org.pentaho.metastore.api.IMetaStore) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) StringObjectId(org.pentaho.di.repository.StringObjectId) Test(org.junit.Test)

Example 13 with Repository

use of org.pentaho.di.repository.Repository in project pentaho-kettle by pentaho.

the class RunTransServletTest method testRunTransServletCheckParameter.

@Test
public void testRunTransServletCheckParameter() throws Exception {
    HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
    HttpServletResponse response = Mockito.mock(HttpServletResponse.class);
    Mockito.when(request.getParameter("trans")).thenReturn("home/test.rtr");
    StringWriter out = new StringWriter();
    PrintWriter printWriter = new PrintWriter(out);
    Mockito.when(request.getContextPath()).thenReturn(RunTransServlet.CONTEXT_PATH);
    Mockito.when(response.getWriter()).thenReturn(printWriter);
    TransformationMap mockTransformationMap = Mockito.mock(TransformationMap.class);
    SlaveServerConfig slaveServerConfig = Mockito.mock(SlaveServerConfig.class);
    Mockito.when(mockTransformationMap.getSlaveServerConfig()).thenReturn(slaveServerConfig);
    Repository repository = Mockito.mock(Repository.class);
    Mockito.when(slaveServerConfig.getRepository()).thenReturn(repository);
    RepositoryDirectoryInterface repositoryDirectoryInterface = Mockito.mock(RepositoryDirectoryInterface.class);
    Mockito.when(repository.loadRepositoryDirectoryTree()).thenReturn(repositoryDirectoryInterface);
    Mockito.when(repositoryDirectoryInterface.findDirectory(Mockito.anyString())).thenReturn(repositoryDirectoryInterface);
    TransMeta transMeta = Mockito.mock(TransMeta.class);
    Mockito.when(repository.loadTransformation(Mockito.any(), Mockito.any())).thenReturn(transMeta);
    String testParameter = "testParameter";
    Mockito.when(transMeta.listVariables()).thenReturn(new String[] { testParameter });
    Mockito.when(transMeta.getVariable(Mockito.anyString())).thenReturn("default value");
    Mockito.when(transMeta.listParameters()).thenReturn(new String[] { testParameter });
    Mockito.when(request.getParameterNames()).thenReturn(new StringTokenizer(testParameter));
    String testValue = "testValue";
    Mockito.when(request.getParameterValues(testParameter)).thenReturn(new String[] { testValue });
    RunTransServlet runTransServlet = Mockito.mock(RunTransServlet.class);
    Mockito.doCallRealMethod().when(runTransServlet).doGet(Mockito.anyObject(), Mockito.anyObject());
    Trans trans = new Trans(transMeta, new SimpleLoggingObject(RunTransServlet.CONTEXT_PATH, LoggingObjectType.CARTE, null));
    Mockito.when(runTransServlet.createTrans(Mockito.anyObject(), Mockito.anyObject())).thenReturn(trans);
    Mockito.when(transMeta.getParameterValue(Mockito.eq(testParameter))).thenReturn(testValue);
    runTransServlet.log = new LogChannel("RunTransServlet");
    runTransServlet.transformationMap = mockTransformationMap;
    runTransServlet.doGet(request, response);
    Assert.assertEquals(testValue, trans.getParameterValue(testParameter));
}
Also used : RepositoryDirectoryInterface(org.pentaho.di.repository.RepositoryDirectoryInterface) TransMeta(org.pentaho.di.trans.TransMeta) HttpServletResponse(javax.servlet.http.HttpServletResponse) LogChannel(org.pentaho.di.core.logging.LogChannel) SimpleLoggingObject(org.pentaho.di.core.logging.SimpleLoggingObject) HttpServletRequest(javax.servlet.http.HttpServletRequest) Repository(org.pentaho.di.repository.Repository) StringTokenizer(java.util.StringTokenizer) StringWriter(java.io.StringWriter) Trans(org.pentaho.di.trans.Trans) PrintWriter(java.io.PrintWriter) Test(org.junit.Test)

Example 14 with Repository

use of org.pentaho.di.repository.Repository in project pentaho-kettle by pentaho.

the class TransExecutionConfiguration method connectRepository.

public Repository connectRepository(RepositoriesMeta repositoriesMeta, String repositoryName, String username, String password) throws KettleException {
    RepositoryMeta repositoryMeta = repositoriesMeta.findRepository(repositoryName);
    if (repositoryMeta == null) {
        log.logBasic("I couldn't find the repository with name '" + repositoryName + "'");
        return null;
    }
    Repository rep = PluginRegistry.getInstance().loadClass(RepositoryPluginType.class, repositoryMeta, Repository.class);
    if (rep == null) {
        log.logBasic("Unable to load repository plugin for '" + repositoryName + "'");
        return null;
    }
    rep.init(repositoryMeta);
    try {
        rep.connect(username, password);
        setRepository(rep);
        return rep;
    } catch (Exception e) {
        log.logBasic("Unable to connect to the repository with name '" + repositoryName + "'");
        return null;
    }
}
Also used : RepositoryMeta(org.pentaho.di.repository.RepositoryMeta) Repository(org.pentaho.di.repository.Repository) KettleException(org.pentaho.di.core.exception.KettleException) IOException(java.io.IOException)

Example 15 with Repository

use of org.pentaho.di.repository.Repository 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);
        // This is needed to resolve resources if a parameter is used within steps like text file out or Hadoop out.
        // It is unclear why this is needed, as the resource location can be resolved on the AEL/Driver/Executor side.
        // This should be removed a long with org.pentaho.di.workarounds.ResolvableResource which is apparently deprecated
        // since 8.1
        copyTransMeta.activateParameters();
        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)

Aggregations

Repository (org.pentaho.di.repository.Repository)194 Test (org.junit.Test)110 KettleException (org.pentaho.di.core.exception.KettleException)66 TransMeta (org.pentaho.di.trans.TransMeta)48 ObjectId (org.pentaho.di.repository.ObjectId)36 RepositoryDirectoryInterface (org.pentaho.di.repository.RepositoryDirectoryInterface)31 IMetaStore (org.pentaho.metastore.api.IMetaStore)29 JobMeta (org.pentaho.di.job.JobMeta)27 StringObjectId (org.pentaho.di.repository.StringObjectId)26 RepositoryMeta (org.pentaho.di.repository.RepositoryMeta)24 ArrayList (java.util.ArrayList)20 StepMeta (org.pentaho.di.trans.step.StepMeta)20 VariableSpace (org.pentaho.di.core.variables.VariableSpace)18 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)18 IUnifiedRepository (org.pentaho.platform.api.repository2.unified.IUnifiedRepository)17 PrintWriter (java.io.PrintWriter)15 Variables (org.pentaho.di.core.variables.Variables)15 IOException (java.io.IOException)14 DatabaseMeta (org.pentaho.di.core.database.DatabaseMeta)14 RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)13