Search in sources :

Example 36 with IContextParameter

use of org.talend.core.model.process.IContextParameter in project tbd-studio-se by Talend.

the class NoSQLRepositoryContextHandlerTest method testCreateContextParameters.

@Test
public void testCreateContextParameters() throws Exception {
    List<IContextParameter> varList = handler.createContextParameters("Mongo", noSqlConnection, paramSet);
    int i = 0;
    for (IContextParameter contextParameter : varList) {
        if (contextParameter.getValue().equals("localhost")) {
            assertEquals("Mongo_ReplicaHost_1", contextParameter.getName());
            assertEquals(contextParameter.getType(), JavaTypesManager.STRING.getId());
            i++;
        } else if (contextParameter.getValue().equals("12701")) {
            assertEquals("Mongo_ReplicaPort_1", contextParameter.getName());
            assertEquals(contextParameter.getType(), JavaTypesManager.INTEGER.getId());
            i++;
        }
    }
    assertTrue(i == 2);
}
Also used : IContextParameter(org.talend.core.model.process.IContextParameter) Test(org.junit.Test)

Example 37 with IContextParameter

use of org.talend.core.model.process.IContextParameter in project tbd-studio-se by Talend.

the class HCatalogContextHandler method createContextParameters.

@Override
public List<IContextParameter> createContextParameters(String prefixName, Connection connection, Set<IConnParamName> paramSet) {
    List<IContextParameter> varList = new ArrayList<IContextParameter>();
    if (connection instanceof HCatalogConnection) {
        HCatalogConnection conn = (HCatalogConnection) connection;
        String paramPrefix = prefixName + ConnectionContextHelper.LINE;
        String paramName = null;
        for (IConnParamName param : paramSet) {
            if (param instanceof EHadoopParamName) {
                EHadoopParamName hcatalogParam = (EHadoopParamName) param;
                paramName = paramPrefix + hcatalogParam;
                switch(hcatalogParam) {
                    case HCatalogHostName:
                        ConnectionContextHelper.createParameters(varList, paramName, conn.getHostName());
                        break;
                    case HCatalogPort:
                        ConnectionContextHelper.createParameters(varList, paramName, conn.getPort());
                        break;
                    case HCatalogUser:
                        ConnectionContextHelper.createParameters(varList, paramName, conn.getUserName());
                        break;
                    case HCatalogPassword:
                        ConnectionContextHelper.createParameters(varList, paramName, conn.getPassword(), JavaTypesManager.PASSWORD);
                        break;
                    case HCatalogKerPrin:
                        ConnectionContextHelper.createParameters(varList, paramName, conn.getKrbPrincipal());
                        break;
                    case HCatalogRealm:
                        ConnectionContextHelper.createParameters(varList, paramName, conn.getKrbRealm());
                        break;
                    case HCatalogDatabase:
                        ConnectionContextHelper.createParameters(varList, paramName, conn.getDatabase());
                        break;
                    case HcataLogRowSeparator:
                        ConnectionContextHelper.createParameters(varList, paramName, conn.getRowSeparator());
                        break;
                    case HcatalogFileSeparator:
                        ConnectionContextHelper.createParameters(varList, paramName, conn.getFieldSeparator());
                        break;
                    default:
                }
            }
        }
        createHadoopPropertiesContextVariable(prefixName, varList, conn.getHadoopProperties());
    }
    return varList;
}
Also used : HCatalogConnection(org.talend.repository.model.hcatalog.HCatalogConnection) ArrayList(java.util.ArrayList) EHadoopParamName(org.talend.metadata.managment.ui.utils.ExtendedNodeConnectionContextUtils.EHadoopParamName) IConnParamName(org.talend.metadata.managment.ui.model.IConnParamName) IContextParameter(org.talend.core.model.process.IContextParameter)

Example 38 with IContextParameter

use of org.talend.core.model.process.IContextParameter in project tbd-studio-se by Talend.

the class HdfsContextHandlerTest method testCreateContextParameters.

@Test
public void testCreateContextParameters() {
    // $NON-NLS-1$
    String prefixName = "testHDFS";
    HDFSConnection connection = (HDFSConnection) HDFSConnectionTestUtils.createDefaultHDFSItem().getConnection();
    Set<IConnParamName> paramSet = new HashSet<>();
    paramSet.add(EHadoopParamName.HdfsUser);
    paramSet.add(EHadoopParamName.HdfsFileSeparator);
    paramSet.add(EHadoopParamName.HdfsRowSeparator);
    paramSet.add(EHadoopParamName.HdfsRowHeader);
    List<String> contextParameterNames = new ArrayList<>();
    for (IConnParamName paramName : paramSet) {
        contextParameterNames.add(prefixName + ConnectionContextHelper.LINE + paramName);
    }
    List<IContextParameter> contextParameters = contextHandler.createContextParameters(prefixName, connection, paramSet);
    for (IContextParameter contextParameter : contextParameters) {
        String contextParameterName = contextParameter.getName();
        assertTrue(contextParameterNames.contains(contextParameterName));
        checkContextParameter(contextParameter, connection);
    }
}
Also used : ArrayList(java.util.ArrayList) HDFSConnection(org.talend.repository.model.hdfs.HDFSConnection) IConnParamName(org.talend.metadata.managment.ui.model.IConnParamName) IContextParameter(org.talend.core.model.process.IContextParameter) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 39 with IContextParameter

use of org.talend.core.model.process.IContextParameter in project tesb-studio-se by Talend.

the class ContextPartGenerator method generatePart.

public CharSequence generatePart(IContext designerContext) throws CodeGeneratorException {
    List<IContextParameter> listParameters = designerContext.getContextParameterList();
    if (listParameters == null) {
        return "";
    }
    CodeGeneratorArgument codeGenArgument = argumentBuilder.build();
    codeGenArgument.setContextName(designerContext.getName());
    List<IContextParameter> listParametersCopy = tranformEncryptedParams(listParameters);
    codeGenArgument.setNode(listParametersCopy);
    JetBean jetBean = JetUtil.createJetBean(codeGenArgument);
    CodeGeneratorInternalTemplatesFactory codegenTemplatesFactory = CodeGeneratorInternalTemplatesFactoryProvider.getInstance();
    if (codegenTemplatesFactory.getTemplates() == null) {
        codegenTemplatesFactory.init();
    }
    for (TemplateUtil template : codegenTemplatesFactory.getTemplatesFromType(EInternalTemplate.CONTEXT)) {
        jetBean.setJetPluginRepository(template.getJetPluginRepository());
        jetBean.setTemplateRelativeUri(template.getTemplateRelativeUri());
    }
    return JetUtil.jetGenerate(jetBean);
}
Also used : JetBean(org.talend.designer.codegen.config.JetBean) TemplateUtil(org.talend.designer.codegen.config.TemplateUtil) CodeGeneratorArgument(org.talend.designer.codegen.config.CodeGeneratorArgument) CodeGeneratorInternalTemplatesFactory(org.talend.designer.codegen.model.CodeGeneratorInternalTemplatesFactory) IContextParameter(org.talend.core.model.process.IContextParameter)

Aggregations

IContextParameter (org.talend.core.model.process.IContextParameter)39 ArrayList (java.util.ArrayList)20 IContext (org.talend.core.model.process.IContext)14 HashMap (java.util.HashMap)6 List (java.util.List)6 IConnParamName (org.talend.metadata.managment.ui.model.IConnParamName)6 Map (java.util.Map)5 IElementParameter (org.talend.core.model.process.IElementParameter)4 IDesignerCoreService (org.talend.designer.core.IDesignerCoreService)4 EHadoopParamName (org.talend.metadata.managment.ui.utils.ExtendedNodeConnectionContextUtils.EHadoopParamName)4 Point (org.eclipse.swt.graphics.Point)3 Test (org.junit.Test)3 JobContextParameter (org.talend.core.model.context.JobContextParameter)3 ModuleNeeded (org.talend.core.model.general.ModuleNeeded)3 IContextManager (org.talend.core.model.process.IContextManager)3 IProcess (org.talend.core.model.process.IProcess)3 ContextItem (org.talend.core.model.properties.ContextItem)3 ProcessItem (org.talend.core.model.properties.ProcessItem)3 ContextType (org.talend.designer.core.model.utils.emf.talendfile.ContextType)3 File (java.io.File)2