Search in sources :

Example 21 with IContextParameter

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

the class JSONConnectionContextHelper method exportAsContext.

/**
     * 
     * ggu Comment method "exportAsContext".
     * 
     */
public static Map<ContextItem, List<ConectionAdaptContextVariableModel>> exportAsContext(ConnectionItem connItem, Set<IConnParamName> paramSet) {
    if (connItem == null) {
        return null;
    }
    List<IContextParameter> varList = createContextParameters(connItem, paramSet);
    if (varList == null || varList.isEmpty()) {
        return null;
    }
    String contextName = convertContextLabel(connItem.getProperty().getLabel());
    ISelection selection = getRepositoryContext(contextName, false);
    if (selection == null) {
        return null;
    }
    Map<ContextItem, List<ConectionAdaptContextVariableModel>> variableContextMap = new HashMap();
    List<ConectionAdaptContextVariableModel> models = new ArrayList<ConectionAdaptContextVariableModel>();
    Set<String> connectionVaribles = getConnVariables(connItem, paramSet);
    ContextModeWizard contextWizard = new ContextModeWizard(contextName, selection.isEmpty(), selection, varList, connectionVaribles);
    WizardDialog dlg = new WizardDialog(Display.getCurrent().getActiveShell(), contextWizard);
    if (dlg.open() == Window.OK) {
        ContextItem contextItem = contextWizard.getContextItem();
        models = contextWizard.getAdaptModels();
        if (contextItem != null) {
            variableContextMap.put(contextItem, models);
        }
        contextManager = contextWizard.getContextManager();
        if (contextItem != null) {
            contextItem.getProperty().setLabel(contextName);
        }
        return variableContextMap;
    }
    return null;
}
Also used : ContextItem(org.talend.core.model.properties.ContextItem) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ContextModeWizard(org.talend.metadata.managment.ui.wizard.context.ContextModeWizard) ConectionAdaptContextVariableModel(org.talend.core.ui.context.model.table.ConectionAdaptContextVariableModel) IContextParameter(org.talend.core.model.process.IContextParameter) ISelection(org.eclipse.jface.viewers.ISelection) List(java.util.List) ArrayList(java.util.ArrayList) EList(org.eclipse.emf.common.util.EList) WizardDialog(org.eclipse.jface.wizard.WizardDialog)

Example 22 with IContextParameter

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

the class SpagicJavaDeployManager method getProperties.

public List<URL> getProperties(ProcessItem processItem, String contextName) {
    List<URL> list = new ArrayList<URL>();
    Properties p = new Properties();
    FileOutputStream out = null;
    String projectName = getCorrespondingProjectName(processItem);
    String jobName = processItem.getProperty().getLabel();
    String jobFolderName = JavaResourcesHelper.getJobFolderName(escapeFileNameSpace(processItem), processItem.getProperty().getVersion());
    try {
        // List<SpagoBiServer> listServerSapgo = null;
        // listServerSapgo = SpagicServerHelper.parse(new SpagicPreferencePage().getPreferenceStore().getString(
        // SpagoBiServer.SPAGOBI_SERVER));
        // if (listServerSapgo != null && !listServerSapgo.isEmpty()) {
        // Iterator<SpagoBiServer> iterator = listServerSapgo.iterator();
        // while (iterator.hasNext()) {
        // SpagoBiServer spagoBiServer = iterator.next();
        // }
        // }
        IPath path = getSrcRootLocation();
        //$NON-NLS-1$
        File file = new File(getTmpFolder() + PATH_SEPARATOR + "spagic.properties");
        //$NON-NLS-1$
        path = path.append(projectName).append(jobFolderName).append(jobName + ".java");
        BufferedReader buff = new BufferedReader(new FileReader(path.toPortableString()));
        int nbLine = 0;
        while (buff.readLine() != null) {
            nbLine++;
        }
        out = new FileOutputStream(file);
        PrintStream ps = new PrintStream(out);
        IDesignerCoreService service = CorePlugin.getDefault().getDesignerCoreService();
        IProcess process = service.getProcessFromProcessItem(processItem);
        List<IContextParameter> ctxParams = process.getContextManager().getContext(contextName).getContextParameterList();
        for (IContextParameter ctxParam : ctxParams) {
            p.put(ctxParam.getName(), ctxParam.getValue());
        }
        p.put("JobClassName", //$NON-NLS-1$
        getCorrespondingProjectName(null) + //$NON-NLS-1$
        "." + JavaResourcesHelper.getJobFolderName(processItem.getProperty().getLabel(), processItem.getProperty().getVersion()) + "." + //$NON-NLS-1$
        processItem.getProperty().getLabel());
        //$NON-NLS-1$
        p.put("talendJobClassDescription", HTMLDocUtils.checkString(processItem.getProperty().getDescription()));
        //$NON-NLS-1$
        p.put("rowNumber", Integer.toString(nbLine));
        //$NON-NLS-1$ //$NON-NLS-2$
        p.put("host", "localhost");
        p.list(ps);
        ps.flush();
        list.add(file.toURI().toURL());
    } catch (Exception e) {
        ExceptionHandler.process(e);
    } finally {
        if (out != null) {
            try {
                out.close();
            } catch (Exception e) {
            }
        }
    }
    return list;
}
Also used : PrintStream(java.io.PrintStream) IPath(org.eclipse.core.runtime.IPath) ArrayList(java.util.ArrayList) Properties(java.util.Properties) IContextParameter(org.talend.core.model.process.IContextParameter) URL(java.net.URL) ProcessorException(org.talend.designer.runprocess.ProcessorException) FileOutputStream(java.io.FileOutputStream) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) IDesignerCoreService(org.talend.designer.core.IDesignerCoreService) File(java.io.File) IProcess(org.talend.core.model.process.IProcess)

Example 23 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);
    jetBean.setTemplateRelativeUri(ECamelTemplate.CONTEXT.getTemplateURL());
    return JetUtil.jetGenerate(jetBean);
}
Also used : JetBean(org.talend.designer.codegen.config.JetBean) CodeGeneratorArgument(org.talend.designer.codegen.config.CodeGeneratorArgument) IContextParameter(org.talend.core.model.process.IContextParameter)

Example 24 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 25 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)

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