Search in sources :

Example 26 with ModuleNeeded

use of org.talend.core.model.general.ModuleNeeded in project tdi-studio-se by Talend.

the class JobSettingsManager method getExtraOnDBParameters.

private static List<IElementParameter> getExtraOnDBParameters(IProcess process) {
    ElementParameter param;
    List<IElementParameter> paramList = new ArrayList<IElementParameter>();
    IPreferenceStore preferenceStore = DesignerPlugin.getDefault().getPreferenceStore();
    //$NON-NLS-1$
    String languagePrefix = LanguageManager.getCurrentLanguage().toString() + "_";
    final String onDBCondition = JobSettingsConstants.getExtraParameterName(EParameterName.FROM_DATABASE_FLAG.getName()) + //$NON-NLS-1$
    " == 'true'";
    final String dbCondition = JobSettingsConstants.addBrackets(CONTEXTLOAD_CONDITION) + " and " + //$NON-NLS-1$
    JobSettingsConstants.addBrackets(onDBCondition);
    // property type
    ElementParameter parentPropertyType = new ElementParameter(process);
    parentPropertyType.setName(JobSettingsConstants.getExtraParameterName(EParameterName.PROPERTY_TYPE.getName()));
    parentPropertyType.setDisplayName(EParameterName.PROPERTY_TYPE.getDisplayName());
    //$NON-NLS-1$
    parentPropertyType.setValue("");
    parentPropertyType.setCategory(EComponentCategory.EXTRA);
    parentPropertyType.setFieldType(EParameterFieldType.PROPERTY_TYPE);
    parentPropertyType.setRepositoryValue(ERepositoryCategoryType.DATABASE.getName());
    parentPropertyType.setNumRow(41);
    parentPropertyType.setShowIf(dbCondition);
    parentPropertyType.setGroup(IMPLICIT_GROUP);
    paramList.add(parentPropertyType);
    param = new ElementParameter(process);
    param.setName(EParameterName.PROPERTY_TYPE.getName());
    param.setDisplayName(EParameterName.PROPERTY_TYPE.getDisplayName());
    param.setListItemsDisplayName(new String[] { EmfComponent.TEXT_BUILTIN, EmfComponent.TEXT_REPOSITORY });
    param.setListItemsDisplayCodeName(new String[] { EmfComponent.BUILTIN, EmfComponent.REPOSITORY });
    param.setListItemsValue(new String[] { EmfComponent.BUILTIN, EmfComponent.REPOSITORY });
    param.setValue(EmfComponent.BUILTIN);
    param.setCategory(EComponentCategory.EXTRA);
    param.setFieldType(EParameterFieldType.TECHNICAL);
    param.setRepositoryValue(ERepositoryCategoryType.DATABASE.getName());
    param.setNumRow(41);
    param.setShowIf(dbCondition);
    param.setGroup(IMPLICIT_GROUP);
    param.setParentParameter(parentPropertyType);
    // paramList.add(param);
    // repository property type
    param = new ElementParameter(process);
    param.setName(EParameterName.REPOSITORY_PROPERTY_TYPE.getName());
    param.setDisplayName(EParameterName.REPOSITORY_PROPERTY_TYPE.getDisplayName());
    param.setListItemsDisplayName(new String[] {});
    param.setListItemsValue(new String[] {});
    // param.setValue(""); //$NON-NLS-1$
    param.setCategory(EComponentCategory.EXTRA);
    param.setFieldType(EParameterFieldType.TECHNICAL);
    param.setShow(false);
    param.setRequired(true);
    param.setNumRow(41);
    param.setGroup(IMPLICIT_GROUP);
    param.setParentParameter(parentPropertyType);
    // paramList.add(param);
    // dbType
    final String dbTypeName = JobSettingsConstants.getExtraParameterName(EParameterName.DB_TYPE.getName());
    param = new ElementParameter(process);
    param.setName(dbTypeName);
    param.setDisplayName(EParameterName.DB_TYPE.getDisplayName());
    param.setFieldType(EParameterFieldType.CLOSED_LIST);
    param.setCategory(EComponentCategory.EXTRA);
    param.setListItemsDisplayName(StatsAndLogsConstants.DISPLAY_DBNAMES[1]);
    param.setListItemsValue(JobSettingsConstants.DB_INPUT_COMPONENTS[1]);
    param.setListRepositoryItems(StatsAndLogsConstants.REPOSITORY_ITEMS[1]);
    param.setListItemsDisplayCodeName(StatsAndLogsConstants.CODE_LIST[1]);
    param.setValue("");
    param.setNumRow(42);
    //$NON-NLS-1$
    param.setRepositoryValue("TYPE");
    param.setRequired(true);
    param.setShowIf(dbCondition);
    param.setGroup(IMPLICIT_GROUP);
    paramList.add(param);
    // dbVersion
    final String dbVersionName = JobSettingsConstants.getExtraParameterName(EParameterName.DB_VERSION.getName());
    if (process.getElementParameter(dbVersionName) == null) {
        param = new ElementParameter(process);
        param.setName(dbVersionName);
        param.setValue(StatsAndLogsConstants.DB_VERSION_DRIVER[1]);
        param.setDisplayName(EParameterName.DB_VERSION.getDisplayName());
        param.setFieldType(EParameterFieldType.CLOSED_LIST);
        param.setCategory(EComponentCategory.EXTRA);
        param.setListItemsDisplayName(StatsAndLogsConstants.DB_VERSION_DISPLAY);
        param.setListItemsValue(StatsAndLogsConstants.DB_VERSION_DRIVER);
        param.setListItemsDisplayCodeName(StatsAndLogsConstants.DB_VERSION_CODE);
        param.setNumRow(42);
        //$NON-NLS-1$
        param.setRepositoryValue("DB_VERSION");
        param.setRequired(true);
        param.setShowIf(dbCondition + " and (" + dbTypeName + " == 'OCLE' or " + dbTypeName + " == 'OCLE_OCI' or " + dbTypeName + " =='ACCESS' or " + dbTypeName + " =='MSSQL' or " + dbTypeName + //$NON-NLS-1$ //$NON-NLS-2$//$NON-NLS-3$ //$NON-NLS-4$//$NON-NLS-5$
        " =='MYSQL') ");
        param.setGroup(IMPLICIT_GROUP);
        paramList.add(param);
    }
    // jdbc url
    param = new ElementParameter(process);
    param.setName(JobSettingsConstants.getExtraParameterName(EParameterName.URL.getName()));
    param.setValue(StatsAndLogsManager.addQuotes(preferenceStore.getString(languagePrefix + EParameterName.URL.getName())));
    param.setDisplayName(EParameterName.URL.getDisplayName());
    param.setFieldType(EParameterFieldType.TEXT);
    param.setCategory(EComponentCategory.EXTRA);
    param.setNumRow(43);
    //$NON-NLS-1$
    param.setRepositoryValue("URL");
    String dbCon = dbTypeName + " == 'JDBC'";
    //$NON-NLS-1$
    param.setShowIf(JobSettingsConstants.addBrackets(dbCon) + " and " + dbCondition);
    param.setGroup(IMPLICIT_GROUP);
    paramList.add(param);
    // jdbc child param
    if (moduleNameList == null) {
        List<ModuleNeeded> moduleNeededList = ModulesNeededProvider.getModulesNeeded();
        moduleNameList = new ArrayList<String>();
        moduleValueList = new ArrayList<String>();
        for (ModuleNeeded module : moduleNeededList) {
            String moduleName = module.getModuleName();
            if (moduleName != null) {
                if (!moduleNameList.contains(moduleName)) {
                    moduleNameList.add(moduleName);
                }
                String moduleValue = TalendTextUtils.addQuotes(moduleName);
                if (!moduleValueList.contains(moduleValue)) {
                    moduleValueList.add(moduleValue);
                }
            }
        }
        Comparator<String> comprarator = new IgnoreCaseComparator();
        Collections.sort(moduleNameList, comprarator);
        Collections.sort(moduleValueList, comprarator);
    }
    String[] moduleNameArray = moduleNameList.toArray(new String[0]);
    String[] moduleValueArray = moduleValueList.toArray(new String[0]);
    ElementParameter childParam = new ElementParameter(process);
    childParam.setName("JAR_NAME");
    childParam.setDisplayName("JAR_NAME");
    childParam.setFieldType(EParameterFieldType.MODULE_LIST);
    childParam.setListItemsDisplayName(moduleNameArray);
    childParam.setListItemsValue(moduleValueArray);
    // driver jar for jdbc
    param = new ElementParameter(process);
    param.setName(JobSettingsConstants.getExtraParameterName(EParameterName.DRIVER_JAR.getName()));
    param.setDisplayName(EParameterName.DRIVER_JAR.getDisplayName());
    param.setFieldType(EParameterFieldType.TABLE);
    param.setListItemsDisplayCodeName(new String[] { "JAR_NAME" });
    param.setListItemsDisplayName(new String[] { "Jar Name" });
    param.setListItemsValue(new ElementParameter[] { childParam });
    param.setValue(new ArrayList<Map<String, Object>>());
    param.setCategory(EComponentCategory.EXTRA);
    param.setNumRow(44);
    //$NON-NLS-1$
    param.setRepositoryValue("DRIVER_JAR");
    dbCon = dbTypeName + " == 'JDBC'";
    //$NON-NLS-1$
    param.setShowIf(JobSettingsConstants.addBrackets(dbCon) + " and " + dbCondition);
    param.setGroup(IMPLICIT_GROUP);
    paramList.add(param);
    // class name for jdbc
    param = new ElementParameter(process);
    param.setName(JobSettingsConstants.getExtraParameterName(EParameterName.DRIVER_CLASS.getName()));
    param.setValue(StatsAndLogsManager.addQuotes(preferenceStore.getString(languagePrefix + EParameterName.DRIVER_CLASS.getName())));
    param.setDisplayName(EParameterName.DRIVER_CLASS.getDisplayName());
    param.setFieldType(EParameterFieldType.TEXT);
    param.setCategory(EComponentCategory.EXTRA);
    param.setNumRow(45);
    //$NON-NLS-1$
    param.setRepositoryValue("DRIVER_CLASS");
    dbCon = dbTypeName + " == 'JDBC'";
    //$NON-NLS-1$
    param.setShowIf(JobSettingsConstants.addBrackets(dbCon) + " and " + dbCondition);
    param.setGroup(IMPLICIT_GROUP);
    paramList.add(param);
    // host
    param = new ElementParameter(process);
    param.setName(JobSettingsConstants.getExtraParameterName(EParameterName.HOST.getName()));
    //$NON-NLS-1$
    param.setValue(StatsAndLogsManager.addQuotes(""));
    param.setDisplayName(EParameterName.HOST.getDisplayName());
    param.setFieldType(EParameterFieldType.TEXT);
    param.setCategory(EComponentCategory.EXTRA);
    param.setNumRow(46);
    //$NON-NLS-1$
    param.setRepositoryValue("SERVER_NAME");
    dbCon = dbTypeName + " != 'SQLITE'" + " and " + dbTypeName + " != 'ACCESS'" + " and " + dbTypeName + "!='OCLE_OCI'" + " and " + dbTypeName + "!='JDBC'" + " and " + dbTypeName + //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$//$NON-NLS-4$//$NON-NLS-5$
    "!='ODBC'";
    //$NON-NLS-1$
    param.setShowIf(JobSettingsConstants.addBrackets(dbCon) + " and " + dbCondition);
    param.setGroup(IMPLICIT_GROUP);
    paramList.add(param);
    // port
    param = new ElementParameter(process);
    param.setName(JobSettingsConstants.getExtraParameterName(EParameterName.PORT.getName()));
    //$NON-NLS-1$
    param.setValue(StatsAndLogsManager.addQuotes(""));
    param.setDisplayName(EParameterName.PORT.getDisplayName());
    param.setFieldType(EParameterFieldType.TEXT);
    param.setCategory(EComponentCategory.EXTRA);
    param.setNumRow(46);
    //$NON-NLS-1$
    param.setRepositoryValue("PORT");
    dbCon = dbTypeName + " != 'SQLITE'" + " and " + dbTypeName + " != 'ACCESS'" + " and " + dbTypeName + " != 'FIREBIRD'" + " and " + dbTypeName + "!='OCLE_OCI'" + " and " + dbTypeName + "!='JDBC'" + " and " + dbTypeName + //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$//$NON-NLS-6$//$NON-NLS-7$
    "!='ODBC'";
    //$NON-NLS-1$
    param.setShowIf(JobSettingsConstants.addBrackets(dbCon) + " and " + dbCondition);
    param.setGroup(IMPLICIT_GROUP);
    paramList.add(param);
    // dbName
    param = new ElementParameter(process);
    param.setName(JobSettingsConstants.getExtraParameterName(EParameterName.DBNAME.getName()));
    //$NON-NLS-1$
    param.setValue(StatsAndLogsManager.addQuotes(""));
    param.setDisplayName(EParameterName.DBNAME.getDisplayName());
    param.setFieldType(EParameterFieldType.TEXT);
    param.setCategory(EComponentCategory.EXTRA);
    param.setNumRow(47);
    //$NON-NLS-1$
    param.setRepositoryValue("SID");
    dbCon = dbTypeName + " != 'SQLITE'" + " and " + dbTypeName + " != 'ACCESS'" + " and " + dbTypeName + " != 'FIREBIRD'" + " and " + dbTypeName + "!='OCLE_OCI'" + " and " + dbTypeName + //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$//$NON-NLS-6$//$NON-NLS-7$
    "!='JDBC'";
    //$NON-NLS-1$
    param.setShowIf(JobSettingsConstants.addBrackets(dbCon) + " and " + dbCondition);
    param.setGroup(IMPLICIT_GROUP);
    paramList.add(param);
    // local service name
    param = new ElementParameter(process);
    param.setName(JobSettingsConstants.getExtraParameterName(EParameterName.LOCAL_SERVICE_NAME.getName()));
    param.setValue(StatsAndLogsManager.addQuotes(""));
    param.setDisplayName(EParameterName.LOCAL_SERVICE_NAME.getDisplayName());
    param.setFieldType(EParameterFieldType.TEXT);
    param.setCategory(EComponentCategory.EXTRA);
    param.setNumRow(47);
    //$NON-NLS-1$
    param.setRepositoryValue("SID");
    dbCon = dbTypeName + " =='OCLE_OCI' ";
    //$NON-NLS-1$
    param.setShowIf(JobSettingsConstants.addBrackets(dbCon) + " and " + dbCondition);
    param.setGroup(IMPLICIT_GROUP);
    paramList.add(param);
    // additional parameters
    param = new ElementParameter(process);
    param.setName(JobSettingsConstants.getExtraParameterName(EParameterName.PROPERTIES.getName()));
    //$NON-NLS-1$
    param.setValue(StatsAndLogsManager.addQuotes(""));
    param.setDisplayName(EParameterName.PROPERTIES.getDisplayName());
    param.setFieldType(EParameterFieldType.TEXT);
    param.setCategory(EComponentCategory.EXTRA);
    param.setNumRow(47);
    //$NON-NLS-1$
    param.setRepositoryValue("PROPERTIES_STRING");
    dbCon = dbTypeName + " == 'MSSQL'" + " or " + dbTypeName + " == 'MYSQL'" + " or " + //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
    dbTypeName + " == 'INFORMIX'" + " or " + dbTypeName + " == 'OCLE'" + " or " + dbTypeName + " == 'OCLE_OCI'" + " or " + dbTypeName + //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$
    " == 'SYBASE'";
    //$NON-NLS-1$
    param.setShowIf(JobSettingsConstants.addBrackets(dbCon) + " and " + dbCondition);
    param.setGroup(IMPLICIT_GROUP);
    paramList.add(param);
    // schema
    param = new ElementParameter(process);
    param.setName(JobSettingsConstants.getExtraParameterName(EParameterName.SCHEMA_DB.getName()));
    //$NON-NLS-1$
    param.setValue(StatsAndLogsManager.addQuotes(""));
    param.setDisplayName(EParameterName.SCHEMA_DB.getDisplayName());
    param.setFieldType(EParameterFieldType.TEXT);
    param.setCategory(EComponentCategory.EXTRA);
    param.setNumRow(47);
    //$NON-NLS-1$
    param.setRepositoryValue("SCHEMA");
    final String schemaCondition = JobSettingsConstants.addBrackets(dbTypeName + " =='OCLE' or " + //$NON-NLS-1$
    dbTypeName + " =='POSTGRESQL' or " + dbTypeName + " =='POSTGRESPLUS' or " + dbTypeName + " =='OCLE_OCI' or " + dbTypeName + " =='MSSQL' or " + dbTypeName + " =='INFORMIX' or " + dbTypeName + " =='IBM_DB2' or " + dbTypeName + //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$//$NON-NLS-4$//$NON-NLS-5$//$NON-NLS-6$//$NON-NLS-7$
    " =='SYBASE'");
    //$NON-NLS-1$
    param.setShowIf(schemaCondition + " and " + dbCondition);
    param.setGroup(IMPLICIT_GROUP);
    paramList.add(param);
    // username
    param = new ElementParameter(process);
    param.setName(JobSettingsConstants.getExtraParameterName(EParameterName.USER.getName()));
    //$NON-NLS-1$
    param.setValue(StatsAndLogsManager.addQuotes(""));
    param.setDisplayName(EParameterName.USER.getDisplayName());
    param.setFieldType(EParameterFieldType.TEXT);
    param.setCategory(EComponentCategory.EXTRA);
    param.setNumRow(48);
    param.setRequired(true);
    //$NON-NLS-1$
    param.setRepositoryValue("USERNAME");
    //$NON-NLS-1$
    dbCon = dbTypeName + " != 'SQLITE'";
    //$NON-NLS-1$
    param.setShowIf(JobSettingsConstants.addBrackets(dbCon) + " and " + dbCondition);
    param.setGroup(IMPLICIT_GROUP);
    paramList.add(param);
    // password
    param = new ElementParameter(process);
    param.setName(JobSettingsConstants.getExtraParameterName(EParameterName.PASS.getName()));
    //$NON-NLS-1$
    param.setValue(StatsAndLogsManager.addQuotes(""));
    param.setDisplayName(EParameterName.PASS.getDisplayName());
    param.setFieldType(EParameterFieldType.PASSWORD);
    param.setCategory(EComponentCategory.EXTRA);
    param.setNumRow(48);
    param.setRequired(true);
    //$NON-NLS-1$
    param.setRepositoryValue("PASSWORD");
    //$NON-NLS-1$
    dbCon = dbTypeName + " != 'SQLITE'";
    //$NON-NLS-1$
    param.setShowIf(JobSettingsConstants.addBrackets(dbCon) + " and " + dbCondition);
    param.setGroup(IMPLICIT_GROUP);
    paramList.add(param);
    // databse file path
    param = new ElementParameter(process);
    param.setName(JobSettingsConstants.getExtraParameterName(EParameterName.DBFILE.getName()));
    //$NON-NLS-1$
    param.setValue(StatsAndLogsManager.addQuotes(""));
    param.setDisplayName(EParameterName.DBFILE.getDisplayName());
    param.setFieldType(EParameterFieldType.FILE);
    param.setCategory(EComponentCategory.EXTRA);
    param.setNumRow(49);
    //$NON-NLS-1$
    param.setRepositoryValue("FILE");
    //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
    dbCon = dbTypeName + " == 'SQLITE'" + " or " + dbTypeName + " == 'ACCESS'" + " or " + dbTypeName + " == 'FIREBIRD'";
    //$NON-NLS-1$
    param.setShowIf(JobSettingsConstants.addBrackets(dbCon) + " and " + dbCondition);
    param.setGroup(IMPLICIT_GROUP);
    paramList.add(param);
    // table
    param = new ElementParameter(process);
    param.setName(JobSettingsConstants.getExtraParameterName(EParameterName.DBTABLE.getName()));
    //$NON-NLS-1$
    param.setValue(StatsAndLogsManager.addQuotes(""));
    param.setDisplayName(EParameterName.DBTABLE.getDisplayName());
    param.setFieldType(EParameterFieldType.DBTABLE);
    param.setCategory(EComponentCategory.EXTRA);
    param.setNumRow(50);
    param.setShowIf(dbCondition);
    param.setGroup(IMPLICIT_GROUP);
    paramList.add(param);
    // query condition
    param = new ElementParameter(process);
    param.setName(JobSettingsConstants.getExtraParameterName(EParameterName.QUERY_CONDITION.getName()));
    param.setValue(QUOTE + QUOTE);
    param.setDisplayName(EParameterName.QUERY_CONDITION.getDisplayName());
    param.setFieldType(EParameterFieldType.TEXT);
    param.setCategory(EComponentCategory.EXTRA);
    param.setNumRow(51);
    param.setShowIf(dbCondition);
    param.setGroup(IMPLICIT_GROUP);
    paramList.add(param);
    for (IElementParameter currentParam : paramList) {
        if (currentParam.getRepositoryValue() != null) {
            // if any of the parameter of stat&logs is using repository, then force to link it to the name of the
            // property for implicit
            currentParam.setRepositoryProperty(parentPropertyType.getName());
        }
    }
    return paramList;
}
Also used : ArrayList(java.util.ArrayList) IElementParameter(org.talend.core.model.process.IElementParameter) ElementParameter(org.talend.designer.core.model.components.ElementParameter) IElementParameter(org.talend.core.model.process.IElementParameter) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) ModuleNeeded(org.talend.core.model.general.ModuleNeeded) Map(java.util.Map)

Example 27 with ModuleNeeded

use of org.talend.core.model.general.ModuleNeeded in project tdi-studio-se by Talend.

the class GuessSchemaProcess method buildProcess.

private void buildProcess() {
    process = new Process(property);
    process.getContextManager().getListContext().addAll(node.getProcess().getContextManager().getListContext());
    process.getContextManager().setDefaultContext(this.selectContext);
    outputComponent = ComponentsFactoryProvider.getInstance().get(EDatabaseComponentName.FILEDELIMITED.getOutPutComponentName(), ComponentCategory.CATEGORY_4_DI.getName());
    if (node.getModulesNeeded().size() > 0 && !node.getComponent().getName().equals("tRedshiftInput")) {
        //$NON-NLS-1$
        for (ModuleNeeded module : node.getModulesNeeded()) {
            if (module.isRequired(node.getElementParameters())) {
                Node libNode1 = new Node(ComponentsFactoryProvider.getInstance().get(LIB_NODE, ComponentCategory.CATEGORY_4_DI.getName()), process);
                //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
                libNode1.setPropertyValue("LIBRARY", "\"" + module.getModuleName() + "\"");
                NodeContainer nc = process.loadNodeContainer(libNode1, false);
                process.addNodeContainer(nc);
            }
        }
    } else {
        // hywang add for 9594
        if (node.getComponent().getName().equals("tJDBCInput") || node.getComponent().getName().equals("tRedshiftInput")) {
            List<String> drivers = EDatabaseVersion4Drivers.getDrivers(info.getTrueDBTypeForJDBC(), info.getDbVersion());
            String moduleNeedName = "";
            Node libNode1 = new Node(ComponentsFactoryProvider.getInstance().get(LIB_NODE, ComponentCategory.CATEGORY_4_DI.getName()), process);
            if (drivers.size() > 0) {
                // use the first driver as defalult.
                // added for bug 13592
                moduleNeedName = drivers.get(0).toString();
                //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
                libNode1.setPropertyValue("LIBRARY", "\"" + moduleNeedName + "\"");
            }
            process.addNodeContainer(new NodeContainer(libNode1));
        }
    }
    INode connectionNode = null;
    IElementParameter existConnection = node.getElementParameter("USE_EXISTING_CONNECTION");
    boolean useExistConnection = (existConnection == null ? false : (Boolean) existConnection.getValue());
    if (useExistConnection) {
        IElementParameter connector = node.getElementParameter("CONNECTION");
        if (connector != null) {
            String connectorValue = connector.getValue().toString();
            List<? extends INode> generatingNodes = originalProcess.getGeneratingNodes();
            for (INode node : generatingNodes) {
                if (node.getUniqueName().equals(connectorValue)) {
                    connectionNode = node;
                    break;
                }
            }
        }
    }
    List<ModuleNeeded> neededLibraries = new ArrayList<ModuleNeeded>();
    JavaProcessUtil.addNodeRelatedModules(process, neededLibraries, node);
    for (ModuleNeeded module : neededLibraries) {
        Node libNode1 = new Node(ComponentsFactoryProvider.getInstance().get(LIB_NODE), process);
        //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        libNode1.setPropertyValue("LIBRARY", "\"" + module.getModuleName() + "\"");
        process.addNodeContainer(new NodeContainer(libNode1));
    }
    if (connectionNode != null) {
        neededLibraries = new ArrayList<ModuleNeeded>();
        JavaProcessUtil.addNodeRelatedModules(process, neededLibraries, connectionNode);
        for (ModuleNeeded module : neededLibraries) {
            Node libNode1 = new Node(ComponentsFactoryProvider.getInstance().get(LIB_NODE), process);
            //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
            libNode1.setPropertyValue("LIBRARY", "\"" + module.getModuleName() + "\"");
            process.addNodeContainer(new NodeContainer(libNode1));
        }
    }
    // create the tLibraryLoad for the output component which is "tFileOutputDelimited"
    for (ModuleNeeded module : outputComponent.getModulesNeeded()) {
        Node libNode2 = new Node(ComponentsFactoryProvider.getInstance().get(LIB_NODE), process);
        //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        libNode2.setPropertyValue("LIBRARY", "\"" + module.getModuleName() + "\"");
        process.addNodeContainer(new NodeContainer(libNode2));
    }
    // for sql statement, feature 6622.
    int fetchSize = maximumRowsToPreview;
    if (maximumRowsToPreview > 1000) {
        fetchSize = 1000;
    }
    String codeStart, codeMain, codeEnd;
    temppath = buildTempCSVFilename();
    // Should also replace "/r". NMa.
    // ISO-8859-15
    memoSQL = memoSQL.replace("\r", " ");
    // fix for TDI-26285
    //$NON-NLS-1$
    String createStatament = "conn.createStatement(java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE,java.sql.ResultSet.CONCUR_READ_ONLY)";
    //$NON-NLS-1$ 
    String systemProperty = "";
    if (info.isHive()) {
        //$NON-NLS-1$ 
        createStatament = "conn.createStatement()";
        systemProperty = //$NON-NLS-1$ //$NON-NLS-2$ 
        "System.setProperty(\"mapred.job.tracker\",\"" + info.getJobTracker() + "\");\r\n" + "System.setProperty(\"fs.default.name\", \"" + info.getNameNode() + //$NON-NLS-1$ //$NON-NLS-2$ 
        "\");\r\n";
        // only embeded hive need the following params
        if (info.getThrifturi() != null) {
            systemProperty = //$NON-NLS-1$ 
            systemProperty + " System.setProperty(\"hive.metastore.local\", \"false\");\r\n" + " System.setProperty(\"hive.metastore.uris\", \"" + info.getThrifturi() + //$NON-NLS-1$ //$NON-NLS-2$ 
            "\");\r\n" + //$NON-NLS-1$ 
            "System.setProperty(\"hive.metastore.execute.setugi\", \"true\");\r\n";
        }
    }
    // add for bug TDI-27137 by fwang on 27 August, 2013.
    EDatabaseTypeName dbType = EDatabaseTypeName.JAVADB_EMBEDED.getTypeFromDbType(info.getDbType());
    if (EDatabaseTypeName.JAVADB_EMBEDED.equals(dbType)) {
        IElementParameter dbPathElement = node.getElementParameter("DBPATH");
        if (dbPathElement != null) {
            String derbyPath = dbPathElement.getValue().toString().replace("\"", "").trim();
            systemProperty = systemProperty + "System.setProperty(\"derby.system.home\",\"" + derbyPath + "\");\r\n";
        }
    }
    // the Sqlite
    if (EDatabaseTypeName.SQLITE.getXmlName().equals(info.getDbType())) {
        createStatament = "conn.createStatement()";
    }
    // the VERTICA
    if (ConnectionUtils.isVertica(info.getUrl())) {
        createStatament = "conn.createStatement()";
    }
    if (EDatabaseTypeName.GENERAL_JDBC.getXmlName().equals(info.getDbType()) && "com.sap.db.jdbc.Driver".equals(info.getDriverClassName()) || EDatabaseTypeName.SAPHana.getXmlName().equals(info.getDbType())) {
        createStatament = "conn.createStatement()";
    }
    codeStart = systemProperty + getCodeStart(connectionNode, createStatament, fetchSize);
    codeMain = //$NON-NLS-1$ //$NON-NLS-2$
    "String[] dataOneRow = new String[numbOfColumn];\r\n" + "for (int i = 1; i <= numbOfColumn; i++) {\r\n" + "    \r\n" + " try{\r\n" + "    String tempStr = rs.getString(i);\r\n" + "    dataOneRow[i-1] = tempStr;\r\n" + "      } catch (java.sql.SQLException e) {\r\n" + "}\r\n" + //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
    "}\r\n" + //$NON-NLS-1$
    "csvWriter.writeNext(dataOneRow);";
    if (EDatabaseTypeName.REDSHIFT.getXmlName().equals(info.getDbType())) {
        codeEnd = //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
        "nbRows++;\r\n" + "    if (nbRows > " + maximumRowsToPreview + ") break;\r\n" + "}\r\n" + "conn.close();\r\n" + //$NON-NLS-1$ //$NON-NLS-2$
        "csvWriter.close();\r\n";
    } else {
        codeEnd = //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
        "nbRows++;\r\n" + "    if (nbRows > " + maximumRowsToPreview + ") break;\r\n" + "}\r\n" + "conn.close();\r\n" + //$NON-NLS-1$ //$NON-NLS-2$
        "csvWriter.close();\r\n";
    }
    IComponent component = null;
    switch(LanguageManager.getCurrentLanguage()) {
        case JAVA:
            //$NON-NLS-1$
            component = ComponentsFactoryProvider.getInstance().get("tJavaFlex");
            break;
        case PERL:
        default:
            //$NON-NLS-1$
            component = ComponentsFactoryProvider.getInstance().get("tPerlFlex");
            break;
    }
    Node flexNode = new Node(component, process);
    //$NON-NLS-1$
    flexNode.setPropertyValue("CODE_START", codeStart);
    //$NON-NLS-1$
    flexNode.setPropertyValue("CODE_MAIN", codeMain);
    //$NON-NLS-1$
    flexNode.setPropertyValue("CODE_END", codeEnd);
    process.addNodeContainer(new NodeContainer(flexNode));
}
Also used : INode(org.talend.core.model.process.INode) IComponent(org.talend.core.model.components.IComponent) Node(org.talend.designer.core.ui.editor.nodes.Node) INode(org.talend.core.model.process.INode) ArrayList(java.util.ArrayList) IProcess(org.talend.core.model.process.IProcess) Process(org.talend.designer.core.ui.editor.process.Process) NodeContainer(org.talend.designer.core.ui.editor.nodecontainer.NodeContainer) IElementParameter(org.talend.core.model.process.IElementParameter) EDatabaseTypeName(org.talend.core.database.EDatabaseTypeName) ModuleNeeded(org.talend.core.model.general.ModuleNeeded)

Example 28 with ModuleNeeded

use of org.talend.core.model.general.ModuleNeeded in project tesb-studio-se by Talend.

the class EditCamelBean method doRun.

/*
     * (non-Javadoc)
     * 
     * @see org.eclipse.jface.action.Action#run()
     */
@Override
protected void doRun() {
    if (repositoryNode == null) {
        repositoryNode = (RepositoryNode) ((IStructuredSelection) getSelection()).getFirstElement();
    }
    BeanItem beanItem = (BeanItem) repositoryNode.getObject().getProperty().getItem();
    try {
        openBeanEditor(beanItem, false);
        refresh(repositoryNode);
        CorePlugin.getDefault().getLibrariesService().resetModulesNeeded();
        CorePlugin.getDefault().getRunProcessService().updateLibraries(new HashSet<ModuleNeeded>(), null);
    } catch (PartInitException e) {
        MessageBoxExceptionHandler.process(e);
    } catch (SystemException e) {
        MessageBoxExceptionHandler.process(e);
    }
}
Also used : SystemException(org.talend.commons.exception.SystemException) BeanItem(org.talend.camel.core.model.camelProperties.BeanItem) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) PartInitException(org.eclipse.ui.PartInitException) ModuleNeeded(org.talend.core.model.general.ModuleNeeded)

Example 29 with ModuleNeeded

use of org.talend.core.model.general.ModuleNeeded in project tdi-studio-se by Talend.

the class JobJavaScriptsManager method getLib.

protected List<URL> getLib(List<ModuleNeeded> libs, Boolean needLib) {
    List<URL> list = new ArrayList<URL>();
    if (!needLib) {
        return list;
    }
    try {
        org.talend.core.model.general.Project projecdddt = ProjectManager.getInstance().getCurrentProject();
        IProject fsProject = null;
        try {
            fsProject = ResourceUtils.getProject(projecdddt);
        } catch (PersistenceException e2) {
            ExceptionHandler.process(e2);
        }
        //$NON-NLS-1$
        IPath temPath = fsProject.getLocation().append(File.separator + "temp");
        ILibraryManagerService repositoryBundleService = CorePlugin.getDefault().getRepositoryBundleService();
        if (repositoryBundleService != null) {
            repositoryBundleService.retrieve(new HashSet<ModuleNeeded>(libs), temPath.toString(), true);
        }
        File file = temPath.toFile();
        File[] files = file.listFiles(new FilenameFilter() {

            @Override
            public boolean accept(File dir, String name) {
                return name.toLowerCase().endsWith(FileConstants.JAR_FILE_SUFFIX) || name.toLowerCase().endsWith(FileConstants.PROPERTIES_FILE_SUFFIX) || name.toLowerCase().endsWith(FileConstants.ZIP_FILE_SUFFIX) ? true : false;
            }
        });
        Set<String> moduleNames = new HashSet<String>();
        for (ModuleNeeded m : libs) {
            moduleNames.add(m.getModuleName());
        }
        for (File tempFile : files) {
            try {
                if (moduleNames.contains(tempFile.getName())) {
                    list.add(tempFile.toURL());
                }
            } catch (MalformedURLException e) {
                ExceptionHandler.process(e);
            }
        }
    } catch (Exception e) {
        ExceptionHandler.process(e);
    }
    return list;
}
Also used : MalformedURLException(java.net.MalformedURLException) IPath(org.eclipse.core.runtime.IPath) ArrayList(java.util.ArrayList) URL(java.net.URL) IProject(org.eclipse.core.resources.IProject) CoreException(org.eclipse.core.runtime.CoreException) IOException(java.io.IOException) DocumentException(org.dom4j.DocumentException) ProcessorException(org.talend.designer.runprocess.ProcessorException) MalformedURLException(java.net.MalformedURLException) PersistenceException(org.talend.commons.exception.PersistenceException) FilenameFilter(java.io.FilenameFilter) ILibraryManagerService(org.talend.core.ILibraryManagerService) PersistenceException(org.talend.commons.exception.PersistenceException) ModuleNeeded(org.talend.core.model.general.ModuleNeeded) IFile(org.eclipse.core.resources.IFile) File(java.io.File) LinkedHashSet(java.util.LinkedHashSet) HashSet(java.util.HashSet)

Example 30 with ModuleNeeded

use of org.talend.core.model.general.ModuleNeeded in project tdi-studio-se by Talend.

the class JavaProcessUtil method findMoreLibraries.

/**
     * DOC YeXiaowei Comment method "findMoreLibraries".
     *
     * @param neededLibraries
     * @param curParam
     */
public static void findMoreLibraries(final IProcess process, List<ModuleNeeded> modulesNeeded, IElementParameter curParam) {
    Object value = curParam.getValue();
    String name = curParam.getName();
    if (name.equals("DRIVER_JAR")) {
        // added for bug 13592. new parameter DRIVER_JAR was used for jdbc connection
        if (value != null && value instanceof List) {
            List list = (List) value;
            for (int i = 0; i < list.size(); i++) {
                if (list.get(i) instanceof HashMap) {
                    // JAR_NAME
                    HashMap map = (HashMap) list.get(i);
                    //$NON-NLS-1$
                    Object object = map.get("JAR_NAME");
                    if (object != null && object instanceof String) {
                        String driverName = (String) object;
                        if (driverName != null && !"".equals(driverName)) {
                            //$NON-NLS-1$
                            boolean isContextMode = ContextParameterUtils.containContextVariables(driverName);
                            if (isContextMode) {
                                getModulesInTable(process, curParam, modulesNeeded);
                            } else {
                                ModuleNeeded module = new ModuleNeeded(null, driverName, null, true);
                                modulesNeeded.add(module);
                            }
                        }
                    }
                }
            }
        }
    } else if (name.equals("DB_VERSION")) {
        //$NON-NLS-1$
        String jdbcName = (String) value;
        if (jdbcName != null) {
            String jars = //$NON-NLS-1$
            (jdbcName).replaceAll(TalendTextUtils.QUOTATION_MARK, "").replaceAll(TalendTextUtils.SINGLE_QUOTE, //$NON-NLS-1$
            "");
            //$NON-NLS-1$
            String separator = ";";
            if (jars.contains(separator)) {
                for (String jar : jars.split(separator)) {
                    if (!jar.contains(".")) {
                        //$NON-NLS-1$
                        continue;
                    }
                    ModuleNeeded module = new ModuleNeeded(null, jar, null, true);
                    modulesNeeded.add(module);
                }
            } else if (jars.contains(".")) {
                //$NON-NLS-1$
                ModuleNeeded module = new ModuleNeeded(null, jars, null, true);
                modulesNeeded.add(module);
            }
        }
    } else if (name.equals("HOTLIBS")) {
        //$NON-NLS-1$
        List<Map<String, Object>> tableValues = (List<Map<String, Object>>) value;
        Object[] listItemsValue = curParam.getListItemsValue();
        for (Map<String, Object> line : tableValues) {
            //$NON-NLS-1$
            Object libPath = line.get("LIBPATH");
            if (libPath == null) {
                continue;
            }
            String text = null;
            if (libPath instanceof String && !StringUtils.isEmpty((String) libPath)) {
                text = (String) libPath;
            } else if (libPath instanceof Integer && listItemsValue != null) {
                int index = ((Integer) libPath).intValue();
                if (index > -1 && index < listItemsValue.length && listItemsValue[index] != null) {
                    if (listItemsValue[index] instanceof IElementParameter) {
                        text = (String) ((IElementParameter) listItemsValue[index]).getValue();
                    } else {
                        text = listItemsValue[index].toString();
                    }
                }
            }
            if (text != null && text.contains(".")) {
                //$NON-NLS-1$
                boolean isContextMode = ContextParameterUtils.containContextVariables(text);
                if (isContextMode) {
                    List<IContext> listContext = process.getContextManager().getListContext();
                    String var = ContextParameterUtils.getVariableFromCode(text);
                    for (IContext context : listContext) {
                        List<IContextParameter> contextParameterList = context.getContextParameterList();
                        for (IContextParameter contextPara : contextParameterList) {
                            String paramName = contextPara.getName();
                            if (var.equals(paramName)) {
                                ModuleNeeded module = getModuleNeededForContextParam(contextPara);
                                if (module != null && !modulesNeeded.contains(module)) {
                                    module.setDynamic(true);
                                    modulesNeeded.add(module);
                                }
                            }
                        }
                    }
                } else {
                    ModuleNeeded module = new ModuleNeeded(null, TalendTextUtils.removeQuotes(text), null, true);
                    module.setDynamic(true);
                    modulesNeeded.add(module);
                }
            }
        }
    } else if (name.equals(EParameterName.HADOOP_CUSTOM_JARS.getDisplayName())) {
        String jarsName = (String) value;
        if (StringUtils.isNotEmpty(jarsName)) {
            String jars = //$NON-NLS-1$
            jarsName.replaceAll(TalendTextUtils.QUOTATION_MARK, "").replaceAll(TalendTextUtils.SINGLE_QUOTE, //$NON-NLS-1$
            "");
            //$NON-NLS-1$
            String separator = ";";
            for (String jar : jars.split(separator)) {
                ModuleNeeded module = new ModuleNeeded(null, jar, null, true);
                modulesNeeded.add(module);
            }
        }
    }
}
Also used : IContext(org.talend.core.model.process.IContext) HashMap(java.util.HashMap) IContextParameter(org.talend.core.model.process.IContextParameter) IElementParameter(org.talend.core.model.process.IElementParameter) ArrayList(java.util.ArrayList) List(java.util.List) ModuleNeeded(org.talend.core.model.general.ModuleNeeded) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

ModuleNeeded (org.talend.core.model.general.ModuleNeeded)38 ArrayList (java.util.ArrayList)17 IElementParameter (org.talend.core.model.process.IElementParameter)11 HashSet (java.util.HashSet)9 File (java.io.File)8 Map (java.util.Map)8 List (java.util.List)5 Test (org.junit.Test)5 IComponent (org.talend.core.model.components.IComponent)5 ProcessItem (org.talend.core.model.properties.ProcessItem)5 ElementParameter (org.talend.designer.core.model.components.ElementParameter)5 Node (org.talend.designer.core.ui.editor.nodes.Node)5 IOException (java.io.IOException)4 URL (java.net.URL)4 INode (org.talend.core.model.process.INode)4 HashMap (java.util.HashMap)3 TreeSet (java.util.TreeSet)3 IPath (org.eclipse.core.runtime.IPath)3 Path (org.eclipse.core.runtime.Path)3 IPreferenceStore (org.eclipse.jface.preference.IPreferenceStore)3