Search in sources :

Example 26 with IContextParameter

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

the class GenericContextUtil method createContextParameters.

public static List<IContextParameter> createContextParameters(String prefixName, Connection connection, Set<IConnParamName> paramSet) {
    List<IContextParameter> varList = new ArrayList<>();
    if (connection instanceof GenericConnection) {
        GenericConnection conn = (GenericConnection) connection;
        if (conn == null || prefixName == null || paramSet == null || paramSet.isEmpty()) {
            return Collections.emptyList();
        }
        String paramPrefix = prefixName + ConnectionContextHelper.LINE;
        String paramName = null;
        for (IConnParamName param : paramSet) {
            if (param instanceof GenericConnParamName) {
                GenericConnParamName connParamName = (GenericConnParamName) param;
                String name = connParamName.getName();
                ComponentProperties componentProperties = getComponentProperties((GenericConnection) connection);
                Property<?> property = componentProperties.getValuedProperty(name);
                paramName = paramPrefix + connParamName.getContextVar();
                JavaType type = JavaTypesManager.STRING;
                if (property.isFlag(Property.Flags.ENCRYPT)) {
                    type = JavaTypesManager.PASSWORD;
                }
                if (GenericTypeUtils.isIntegerType(property)) {
                    type = JavaTypesManager.INTEGER;
                }
                String value = property == null || property.getValue() == null ? null : StringEscapeUtils.escapeJava(String.valueOf(property.getValue()));
                ConnectionContextHelper.createParameters(varList, paramName, value, type);
            }
        }
    }
    return varList;
}
Also used : JavaType(org.talend.core.model.metadata.types.JavaType) ComponentProperties(org.talend.components.api.properties.ComponentProperties) GenericConnParamName(org.talend.metadata.managment.ui.utils.GenericConnParamName) ArrayList(java.util.ArrayList) IConnParamName(org.talend.metadata.managment.ui.model.IConnParamName) GenericConnection(org.talend.repository.generic.model.genericMetadata.GenericConnection) IContextParameter(org.talend.core.model.process.IContextParameter)

Example 27 with IContextParameter

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

the class JSONConnectionContextHelper method createContextParameters.

private static List<IContextParameter> createContextParameters(ConnectionItem connectionItem, Set<IConnParamName> paramSet) {
    if (connectionItem == null) {
        return null;
    }
    final String label = convertContextLabel(connectionItem.getProperty().getLabel());
    Connection conn = connectionItem.getConnection();
    List<IContextParameter> varList = null;
    if (conn instanceof JSONFileConnection) {
        varList = getJSONFileVariables(label, (JSONFileConnection) conn);
    }
    return varList;
}
Also used : JSONFileConnection(org.talend.repository.model.json.JSONFileConnection) Connection(org.talend.core.model.metadata.builder.connection.Connection) JSONFileConnection(org.talend.repository.model.json.JSONFileConnection) IContextParameter(org.talend.core.model.process.IContextParameter)

Example 28 with IContextParameter

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

the class JSONConnectionContextHelper method getJSONFileVariables.

static List<IContextParameter> getJSONFileVariables(String prefixName, JSONFileConnection conn) {
    if (conn == null || prefixName == null) {
        return Collections.emptyList();
    }
    List<IContextParameter> varList = new ArrayList<IContextParameter>();
    prefixName = prefixName + LINE;
    String paramName = null;
    if (!conn.isInputModel()) {
        String outputFilePath = conn.getOutputFilePath();
        paramName = prefixName + EParamName.OutputFilePath;
        createParameters(varList, paramName, outputFilePath, JavaTypesManager.FILE);
    } else {
        String jsonFilePath = conn.getJSONFilePath();
        String encoding = conn.getEncoding();
        if (LANGUAGE.equals(ECodeLanguage.PERL)) {
            jsonFilePath = TalendQuoteUtils.addQuotes(jsonFilePath);
            encoding = TalendQuoteUtils.addQuotes(encoding);
        }
        paramName = prefixName + EParamName.FilePath;
        createParameters(varList, paramName, jsonFilePath, JavaTypesManager.FILE);
        paramName = prefixName + EParamName.Encoding;
        createParameters(varList, paramName, encoding);
        EList schema = conn.getSchema();
        if (schema != null) {
            Object object = schema.get(0);
            if (object instanceof JSONXPathLoopDescriptor) {
                JSONXPathLoopDescriptor loopDesc = (JSONXPathLoopDescriptor) object;
                paramName = prefixName + EParamName.XPathQuery;
                String absoluteXPathQuery = loopDesc.getAbsoluteXPathQuery();
                if (LANGUAGE.equals(ECodeLanguage.PERL)) {
                    absoluteXPathQuery = TalendQuoteUtils.addQuotes(absoluteXPathQuery);
                }
                createParameters(varList, paramName, absoluteXPathQuery);
            }
        }
    }
    return varList;
}
Also used : JSONXPathLoopDescriptor(org.talend.repository.model.json.JSONXPathLoopDescriptor) EList(org.eclipse.emf.common.util.EList) ArrayList(java.util.ArrayList) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) IContextParameter(org.talend.core.model.process.IContextParameter)

Example 29 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 30 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)

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