Search in sources :

Example 1 with IPdiContentProvider

use of org.pentaho.platform.api.util.IPdiContentProvider in project pdi-platform-plugin by pentaho.

the class UserParametersTest method testJobUserParameters.

@Test
public void testJobUserParameters() throws Exception {
    PdiAction action = new PdiAction();
    action.setRepositoryName(KettleFileRepositoryMeta.REPOSITORY_TYPE_ID);
    action.setArguments(new String[] { "dummyArg" });
    action.setDirectory(SOLUTION_REPOSITORY);
    action.setJob(SAMPLE_JOB);
    action.execute();
    Assert.isTrue(action.localJob != null && action.localJob.getJobMeta() != null);
    NamedParams np = action.localJob.getJobMeta();
    boolean protectedParameterNameExistsInKjb = false;
    for (String param : np.listParameters()) {
        protectedParameterNameExistsInKjb |= param != null && param.equals(SAMPLE_PROTECTED_PARAMETER_NAME);
    }
    // we make sure: this kjb does indeed have a system/hidden parameter
    Assert.isTrue(protectedParameterNameExistsInKjb);
    // reset attribute
    protectedParameterNameExistsInKjb = false;
    // we now call IPdiContentProvider.getUserParameters( kjb ), that should filter out protected parameters
    IPdiContentProvider pdiContentProvider = new PdiContentProvider(PentahoSystem.get(IUnifiedRepository.class));
    String[] userParams = pdiContentProvider.getUserParameters(SOLUTION_REPOSITORY + SAMPLE_JOB + ".kjb");
    for (String userParam : userParams) {
        protectedParameterNameExistsInKjb |= userParam != null && userParam.equals(SAMPLE_PROTECTED_PARAMETER_NAME);
    }
    // we make sure: IPdiContentProvider has filtered it out
    Assert.isTrue(!protectedParameterNameExistsInKjb);
}
Also used : NamedParams(org.pentaho.di.core.parameters.NamedParams) IPdiContentProvider(org.pentaho.platform.api.util.IPdiContentProvider) IPdiContentProvider(org.pentaho.platform.api.util.IPdiContentProvider) IUnifiedRepository(org.pentaho.platform.api.repository2.unified.IUnifiedRepository) Test(org.junit.Test)

Example 2 with IPdiContentProvider

use of org.pentaho.platform.api.util.IPdiContentProvider in project pdi-platform-plugin by pentaho.

the class ParameterContentGenerator method createContent.

@Override
public void createContent(OutputStream out) throws Exception {
    IParameterProvider pathParams = parameterProviders.get(PATH);
    IParameterProvider requestParams = parameterProviders.get(IParameterProvider.SCOPE_REQUEST);
    RepositoryFile file = null;
    if (pathParams != null) {
        file = (RepositoryFile) pathParams.getParameter(FILE);
    } else {
        IUnifiedRepository repo = PentahoSystem.get(IUnifiedRepository.class, null);
        String path = URLDecoder.decode(requestParams.getStringParameter(PATH, StringUtils.EMPTY), LocaleHelper.UTF_8);
        file = repo.getFile(idTopath(path));
    }
    IPdiContentProvider provider = (IPdiContentProvider) PentahoSystem.get(IPluginManager.class).getBean(IPdiContentProvider.class.getSimpleName());
    String[] userParams = provider.getUserParameters(file.getPath());
    ParametersBean paramBean = new ParametersBean(userParams, requestParameterToStringMap(requestParams));
    String response = paramBean.getParametersXmlString();
    out.write(response.getBytes(LocaleHelper.getSystemEncoding()));
    out.flush();
}
Also used : IParameterProvider(org.pentaho.platform.api.engine.IParameterProvider) IPdiContentProvider(org.pentaho.platform.api.util.IPdiContentProvider) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) IUnifiedRepository(org.pentaho.platform.api.repository2.unified.IUnifiedRepository)

Example 3 with IPdiContentProvider

use of org.pentaho.platform.api.util.IPdiContentProvider in project pdi-platform-plugin by pentaho.

the class UserParametersTest method testTransformationUserParameters.

@Test
public void testTransformationUserParameters() throws Exception {
    PdiAction action = new PdiAction();
    action.setRepositoryName(KettleFileRepositoryMeta.REPOSITORY_TYPE_ID);
    action.setArguments(new String[] { "dummyArg" });
    action.setDirectory(SOLUTION_REPOSITORY);
    action.setTransformation(SAMPLE_TRANS);
    action.execute();
    Assert.isTrue(action.localTrans != null && action.localTrans.getTransMeta() != null);
    NamedParams np = action.localTrans.getTransMeta();
    boolean protectedParameterNameExistsInKtr = false;
    for (String param : np.listParameters()) {
        protectedParameterNameExistsInKtr |= param != null && param.equals(SAMPLE_PROTECTED_PARAMETER_NAME);
    }
    // we make sure: this ktr does indeed have a system/hidden parameter
    Assert.isTrue(protectedParameterNameExistsInKtr);
    // reset attribute
    protectedParameterNameExistsInKtr = false;
    // we now call IPdiContentProvider.getUserParameters( kjb ), that should filter out protected parameters
    IPdiContentProvider pdiContentProvider = new PdiContentProvider(PentahoSystem.get(IUnifiedRepository.class));
    String[] userParams = pdiContentProvider.getUserParameters(SOLUTION_REPOSITORY + SAMPLE_TRANS + ".ktr");
    for (String userParam : userParams) {
        protectedParameterNameExistsInKtr |= userParam != null && userParam.equals(SAMPLE_PROTECTED_PARAMETER_NAME);
    }
    // we make sure: IPdiContentProvider has filtered it out
    Assert.isTrue(!protectedParameterNameExistsInKtr);
}
Also used : NamedParams(org.pentaho.di.core.parameters.NamedParams) IPdiContentProvider(org.pentaho.platform.api.util.IPdiContentProvider) IPdiContentProvider(org.pentaho.platform.api.util.IPdiContentProvider) IUnifiedRepository(org.pentaho.platform.api.repository2.unified.IUnifiedRepository) Test(org.junit.Test)

Aggregations

IUnifiedRepository (org.pentaho.platform.api.repository2.unified.IUnifiedRepository)3 IPdiContentProvider (org.pentaho.platform.api.util.IPdiContentProvider)3 Test (org.junit.Test)2 NamedParams (org.pentaho.di.core.parameters.NamedParams)2 IParameterProvider (org.pentaho.platform.api.engine.IParameterProvider)1 RepositoryFile (org.pentaho.platform.api.repository2.unified.RepositoryFile)1