Search in sources :

Example 16 with IContextParameter

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

the class ContextModifyCommand method propagateType.

private void propagateType(IContextManager contextManager, IContextParameter param) {
    for (IContext context : contextManager.getListContext()) {
        IContextParameter paramToModify = context.getContextParameter(param.getName());
        paramToModify.setType(param.getType());
    }
}
Also used : IContext(org.talend.core.model.process.IContext) IContextParameter(org.talend.core.model.process.IContextParameter)

Example 17 with IContextParameter

use of org.talend.core.model.process.IContextParameter 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)

Example 18 with IContextParameter

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

the class JavaProcessUtil method getModulesInTable.

private static void getModulesInTable(final IProcess process, IElementParameter curParam, List<ModuleNeeded> modulesNeeded) {
    if (!(curParam.getValue() instanceof List)) {
        return;
    }
    List<Map<String, Object>> values = (List<Map<String, Object>>) curParam.getValue();
    if (values != null && !values.isEmpty()) {
        Object[] listItemsValue = curParam.getListItemsValue();
        if (listItemsValue != null && listItemsValue.length > 0 && listItemsValue[0] instanceof IElementParameter) {
            for (Object o : listItemsValue) {
                IElementParameter param = (IElementParameter) o;
                if (param.getFieldType() == EParameterFieldType.MODULE_LIST) {
                    for (Map<String, Object> line : values) {
                        String moduleName = (String) line.get(param.getName());
                        if (moduleName != null && !"".equals(moduleName)) {
                            //$NON-NLS-1$
                            boolean isContextMode = ContextParameterUtils.containContextVariables(moduleName);
                            if (isContextMode) {
                                List<IContext> listContext = process.getContextManager().getListContext();
                                for (IContext context : listContext) {
                                    List<IContextParameter> contextParameterList = context.getContextParameterList();
                                    for (IContextParameter contextPara : contextParameterList) {
                                        String var = ContextParameterUtils.getVariableFromCode(moduleName);
                                        if (var.equals(contextPara.getName())) {
                                            String value = context.getContextParameter(contextPara.getName()).getValue();
                                            if (curParam.getName().equals(EParameterName.DRIVER_JAR.getName()) && value.contains(";")) {
                                                //$NON-NLS-1$
                                                //$NON-NLS-1$
                                                String[] jars = value.split(";");
                                                for (String jar2 : jars) {
                                                    String jar = jar2;
                                                    //$NON-NLS-1$
                                                    jar = jar.substring(jar.lastIndexOf("\\") + 1);
                                                    ModuleNeeded module = new ModuleNeeded(null, jar, null, true);
                                                    modulesNeeded.add(module);
                                                }
                                            } else {
                                                //$NON-NLS-1$
                                                value = value.substring(value.lastIndexOf("\\") + 1);
                                                ModuleNeeded module = new ModuleNeeded(null, value, null, true);
                                                modulesNeeded.add(module);
                                            }
                                        }
                                    }
                                }
                            } else {
                                ModuleNeeded mn = getModuleValue(process, moduleName);
                                if (line.get("JAR_NEXUS_VERSION") != null) {
                                    String a = moduleName.replaceFirst("[.][^.]+$", "");
                                    mn.setMavenUri("mvn:org.talend.libraries/" + a + "/" + line.get("JAR_NEXUS_VERSION") + "/jar");
                                }
                                modulesNeeded.add(mn);
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : IContext(org.talend.core.model.process.IContext) IContextParameter(org.talend.core.model.process.IContextParameter) IElementParameter(org.talend.core.model.process.IElementParameter) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) ModuleNeeded(org.talend.core.model.general.ModuleNeeded)

Example 19 with IContextParameter

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

the class ContextParameterPage method setParameter.

public void setParameter(IContextParameter contextParameter, List<? extends IContext> contexts) {
    this.parameter = contextParameter;
    existingParameterNames = new HashSet<String>();
    for (IContext context : contexts) {
        for (IContextParameter ctxPrm : context.getContextParameterList()) {
            existingParameterNames.add(ctxPrm.getName());
        }
    }
}
Also used : IContext(org.talend.core.model.process.IContext) IContextParameter(org.talend.core.model.process.IContextParameter)

Example 20 with IContextParameter

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

the class TableController method updateContextList.

private void updateContextList(IElementParameter param) {
    List<String> contextParameterNamesList = new ArrayList<String>();
    IElementParameter processTypeParam = elem.getElementParameterFromField(EParameterFieldType.PROCESS_TYPE);
    if (processTypeParam == null) {
        processTypeParam = elem.getElementParameterFromField(EParameterFieldType.ROUTE_INPUT_PROCESS_TYPE);
        if (processTypeParam == null) {
            return;
        }
    }
    boolean haveContextParamList = false;
    for (Object valueParam : param.getListItemsValue()) {
        if (valueParam instanceof IElementParameter) {
            IElementParameter vParam = (IElementParameter) valueParam;
            if (vParam.getFieldType() == EParameterFieldType.CONTEXT_PARAM_NAME_LIST) {
                haveContextParamList = true;
                break;
            }
        }
    }
    if (!haveContextParamList) {
        return;
    }
    IElementParameter jobElemParam = processTypeParam.getChildParameters().get(EParameterName.PROCESS_TYPE_PROCESS.getName());
    IElementParameter jobVersionParam = processTypeParam.getChildParameters().get(EParameterName.PROCESS_TYPE_VERSION.getName());
    IElementParameter contextElemParam = processTypeParam.getChildParameters().get(EParameterName.PROCESS_TYPE_CONTEXT.getName());
    // get context list
    String processId = (String) jobElemParam.getValue();
    String contextName = (String) contextElemParam.getValue();
    if (contextName == null) {
        contextName = new String();
    }
    if (processId == null || contextName == null) {
        revertToolBarButtonState(false);
        return;
    }
    IElementParameter useDynamic = elem.getElementParameter("USE_DYNAMIC_JOB");
    if (useDynamic != null && Boolean.valueOf(String.valueOf(useDynamic.getValue()))) {
        String[] split = processId.split(";");
        processId = split[0];
    }
    ProcessItem processItem = ItemCacheManager.getProcessItem(processId, (String) jobVersionParam.getValue());
    String[] contextParameterNames = null;
    if (processItem != null) {
        // achen modify to fix bug 0006107
        IDesignerCoreService service = CorePlugin.getDefault().getDesignerCoreService();
        // process = new Process(processItem.getProperty());
        // process.loadXmlFile();
        IContextManager contextManager = service.getProcessContextFromItem(processItem);
        if (contextManager != null) {
            IContext context = contextManager.getContext(contextName);
            for (IContextParameter contextParam : context.getContextParameterList()) {
                contextParameterNamesList.add(contextParam.getName());
            }
        }
        contextParameterNames = contextParameterNamesList.toArray(new String[0]);
    }
    if (contextParameterNames == null || contextParameterNames.length == 0) {
        contextParameterNamesList.clear();
        // we rerebuild the list here from what was saved in the job before
        for (HashMap<String, Object> values : (List<HashMap<String, Object>>) param.getValue()) {
            //$NON-NLS-1$
            String name = (String) values.get("PARAM_NAME_COLUMN");
            contextParameterNamesList.add(name);
        }
        contextParameterNames = contextParameterNamesList.toArray(new String[0]);
    }
    // update table values
    TableViewerCreator tableViewerCreator = (TableViewerCreator) hashCurControls.get(param.getName());
    Object[] itemsValue = param.getListItemsValue();
    if (tableViewerCreator != null) {
        List colList = tableViewerCreator.getColumns();
        for (int j = 0; j < itemsValue.length; j++) {
            if ((j + 1) >= colList.size()) {
                break;
            }
            if (itemsValue[j] instanceof IElementParameter) {
                IElementParameter tmpParam = (IElementParameter) itemsValue[j];
                if (tmpParam.getFieldType() == EParameterFieldType.CONTEXT_PARAM_NAME_LIST) {
                    tmpParam.setListItemsDisplayCodeName(contextParameterNames);
                    tmpParam.setListItemsDisplayName(contextParameterNames);
                    tmpParam.setListItemsValue(contextParameterNames);
                    // TDI-35251 won't set default, if not fount, keep error
                    // if (contextParameterNames.length > 0) {
                    // tmpParam.setDefaultClosedListValue(contextParameterNames[0]);
                    // } else {
                    //$NON-NLS-1$
                    tmpParam.setDefaultClosedListValue("");
                    // }
                    // j + 1 because first column is masked
                    TableViewerCreatorColumnNotModifiable column = (TableViewerCreatorColumnNotModifiable) colList.get(j + 1);
                    CCombo combo = (CCombo) column.getCellEditor().getControl();
                    String[] oldItems = combo.getItems();
                    combo.setItems(contextParameterNames);
                    List<Map<String, Object>> paramValues = (List<Map<String, Object>>) param.getValue();
                    String[] items = param.getListItemsDisplayCodeName();
                    for (int currentIndex = 0; currentIndex < paramValues.size(); currentIndex++) {
                        Map<String, Object> currentLine = paramValues.get(currentIndex);
                        Object o = currentLine.get(items[j]);
                        if (o instanceof Integer) {
                            Integer nb = (Integer) o;
                            if ((nb >= oldItems.length) || (nb == -1)) {
                                currentLine.put(items[j], tmpParam.getDefaultClosedListValue());
                            } else {
                                currentLine.put(items[j], oldItems[nb]);
                            }
                        } else {
                            if (o instanceof String) {
                                Integer nb = new Integer(tmpParam.getIndexOfItemFromList((String) o));
                                if (nb == -1 && !"".equals(tmpParam.getDefaultClosedListValue())) {
                                    currentLine.put(items[j], tmpParam.getDefaultClosedListValue());
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    // (bug 3740)
    boolean checked = contextParameterNames != null && contextParameterNames.length > 0;
    revertToolBarButtonState(checked);
}
Also used : IContext(org.talend.core.model.process.IContext) TableViewerCreator(org.talend.commons.ui.swt.tableviewer.TableViewerCreator) TableViewerCreatorColumnNotModifiable(org.talend.commons.ui.runtime.swt.tableviewer.TableViewerCreatorColumnNotModifiable) ArrayList(java.util.ArrayList) IContextParameter(org.talend.core.model.process.IContextParameter) Point(org.eclipse.swt.graphics.Point) CCombo(org.eclipse.swt.custom.CCombo) ProcessItem(org.talend.core.model.properties.ProcessItem) IElementParameter(org.talend.core.model.process.IElementParameter) ArrayList(java.util.ArrayList) List(java.util.List) IDesignerCoreService(org.talend.designer.core.IDesignerCoreService) IContextManager(org.talend.core.model.process.IContextManager) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

IContextParameter (org.talend.core.model.process.IContextParameter)32 ArrayList (java.util.ArrayList)14 IContext (org.talend.core.model.process.IContext)14 HashMap (java.util.HashMap)6 List (java.util.List)6 Map (java.util.Map)4 IElementParameter (org.talend.core.model.process.IElementParameter)4 IDesignerCoreService (org.talend.designer.core.IDesignerCoreService)4 Point (org.eclipse.swt.graphics.Point)3 JobContextParameter (org.talend.core.model.context.JobContextParameter)3 ModuleNeeded (org.talend.core.model.general.ModuleNeeded)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 File (java.io.File)2 Properties (java.util.Properties)2 EList (org.eclipse.emf.common.util.EList)2 CCombo (org.eclipse.swt.custom.CCombo)2 TableViewerCreatorColumnNotModifiable (org.talend.commons.ui.runtime.swt.tableviewer.TableViewerCreatorColumnNotModifiable)2 TableViewerCreator (org.talend.commons.ui.swt.tableviewer.TableViewerCreator)2