Search in sources :

Example 6 with GenericConnParamName

use of org.talend.metadata.managment.ui.utils.GenericConnParamName 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)

Aggregations

GenericConnParamName (org.talend.metadata.managment.ui.utils.GenericConnParamName)6 IConnParamName (org.talend.metadata.managment.ui.model.IConnParamName)4 ComponentProperties (org.talend.components.api.properties.ComponentProperties)3 GenericConnection (org.talend.repository.generic.model.genericMetadata.GenericConnection)3 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 JavaType (org.talend.core.model.metadata.types.JavaType)1 IContextParameter (org.talend.core.model.process.IContextParameter)1 IElementParameter (org.talend.core.model.process.IElementParameter)1 ContextItem (org.talend.core.model.properties.ContextItem)1 ConectionAdaptContextVariableModel (org.talend.core.ui.context.model.table.ConectionAdaptContextVariableModel)1 GenericElementParameter (org.talend.designer.core.generic.model.GenericElementParameter)1