Search in sources :

Example 1 with IConnParamName

use of org.talend.metadata.managment.ui.model.IConnParamName in project tdi-studio-se by Talend.

the class GenericContextUtil method setPropertiesForContextMode.

public static void setPropertiesForContextMode(String prefixName, Connection connection, Set<IConnParamName> paramSet) {
    if (connection == null) {
        return;
    }
    if (connection instanceof GenericConnection) {
        GenericConnection genericConn = (GenericConnection) connection;
        ComponentProperties componentProperties = getComponentProperties(genericConn);
        String originalVariableName = prefixName + ConnectionContextHelper.LINE;
        String genericVariableName = null;
        for (IConnParamName param : paramSet) {
            if (param instanceof GenericConnParamName) {
                GenericConnParamName genericParam = (GenericConnParamName) param;
                String paramVarName = genericParam.getContextVar();
                genericVariableName = originalVariableName + paramVarName;
                matchContextForAttribues(componentProperties, genericParam, genericVariableName);
            }
        }
        updateComponentProperties(genericConn, componentProperties);
    }
}
Also used : ComponentProperties(org.talend.components.api.properties.ComponentProperties) GenericConnParamName(org.talend.metadata.managment.ui.utils.GenericConnParamName) IConnParamName(org.talend.metadata.managment.ui.model.IConnParamName) GenericConnection(org.talend.repository.generic.model.genericMetadata.GenericConnection)

Example 2 with IConnParamName

use of org.talend.metadata.managment.ui.model.IConnParamName in project tdi-studio-se by Talend.

the class GenericContextHandler method exportContext.

@Override
public boolean exportContext(ConnectionItem connectionItem) {
    boolean isContextMode = connectionItem.getConnection().isContextMode();
    if (isContextMode) {
        ConnectionContextHelper.openInConetxtModeDialog();
    } else {
        String defaultContextName = ConnectionContextHelper.convertContextLabel(connectionItem.getProperty().getLabel());
        if (StringUtils.isEmpty(defaultContextName)) {
            //$NON-NLS-1$ //$NON-NLS-2$
            MessageDialog.openError(DisplayUtils.getDefaultShell(), Messages.getString("GenericContextHandler.wizardTitle"), Messages.getString("GenericContextHandler.defineConnectionName"));
        }
        Set<IConnParamName> contextParams = getContextParams();
        Map<ContextItem, List<ConectionAdaptContextVariableModel>> variableModels = ConnectionContextHelper.exportAsContext(defaultContextName, connectionItem, contextParams);
        if (variableModels != null) {
            Iterator<ContextItem> contextItor = variableModels.keySet().iterator();
            while (contextItor.hasNext()) {
                ContextItem contextItem = contextItor.next();
                List<ConectionAdaptContextVariableModel> apaptModels = variableModels.get(contextItem);
                if (contextItem != null && apaptModels.size() == 0) {
                    // create
                    if (ConnectionContextHelper.contextManager instanceof JobContextManager) {
                        Map<String, String> map = ((JobContextManager) ConnectionContextHelper.contextManager).getNameMap();
                        // set properties for context mode
                        ConnectionContextHelper.setPropertiesForContextMode(defaultContextName, connectionItem, contextItem, contextParams, map);
                    }
                } else {
                    // set properties for exist context
                    ConnectionContextHelper.setPropertiesForExistContextMode(connectionItem, contextParams, variableModels);
                }
            }
        }
        return true;
    }
    return false;
}
Also used : ContextItem(org.talend.core.model.properties.ContextItem) IConnParamName(org.talend.metadata.managment.ui.model.IConnParamName) List(java.util.List) JobContextManager(org.talend.core.model.context.JobContextManager) ConectionAdaptContextVariableModel(org.talend.core.ui.context.model.table.ConectionAdaptContextVariableModel)

Example 3 with IConnParamName

use of org.talend.metadata.managment.ui.model.IConnParamName in project tdi-studio-se by Talend.

the class GenericContextHandler method getContextParams.

@Override
public Set<IConnParamName> getContextParams() {
    Set<IConnParamName> contextParams = new HashSet<>();
    if (parameters != null) {
        for (IElementParameter param : parameters) {
            if (param instanceof GenericElementParameter) {
                GenericElementParameter genericElementParameter = (GenericElementParameter) param;
                if (genericElementParameter.isSupportContext()) {
                    GenericConnParamName connParamName = new GenericConnParamName();
                    String paramName = genericElementParameter.getName();
                    connParamName.setName(paramName);
                    connParamName.setContextVar(getValidContextVarName(paramName));
                    contextParams.add(connParamName);
                }
            }
        }
    }
    return contextParams;
}
Also used : GenericConnParamName(org.talend.metadata.managment.ui.utils.GenericConnParamName) GenericElementParameter(org.talend.designer.core.generic.model.GenericElementParameter) IElementParameter(org.talend.core.model.process.IElementParameter) IConnParamName(org.talend.metadata.managment.ui.model.IConnParamName) HashSet(java.util.HashSet)

Example 4 with IConnParamName

use of org.talend.metadata.managment.ui.model.IConnParamName in project tdi-studio-se by Talend.

the class GenericContextUtil method setPropertiesForExistContextMode.

public static void setPropertiesForExistContextMode(Connection connection, Set<IConnParamName> paramSet, Map<ContextItem, List<ConectionAdaptContextVariableModel>> adaptMap) {
    if (connection == null) {
        return;
    }
    if (connection instanceof GenericConnection) {
        GenericConnection genericConn = (GenericConnection) connection;
        ComponentProperties componentProperties = getComponentProperties(genericConn);
        ContextItem currentContext = null;
        for (IConnParamName param : paramSet) {
            if (param instanceof GenericConnParamName) {
                String genericVariableName = null;
                GenericConnParamName genericParam = (GenericConnParamName) param;
                if (adaptMap != null && adaptMap.size() > 0) {
                    for (Map.Entry<ContextItem, List<ConectionAdaptContextVariableModel>> entry : adaptMap.entrySet()) {
                        currentContext = entry.getKey();
                        List<ConectionAdaptContextVariableModel> modelList = entry.getValue();
                        for (ConectionAdaptContextVariableModel model : modelList) {
                            if (model.getValue().equals(genericParam.getName())) {
                                genericVariableName = model.getName();
                                break;
                            }
                        }
                    }
                }
                if (genericVariableName != null) {
                    genericVariableName = getCorrectVariableName(currentContext, genericVariableName, genericParam);
                    matchContextForAttribues(componentProperties, genericParam, genericVariableName);
                }
            }
        }
        updateComponentProperties(genericConn, componentProperties);
    }
}
Also used : ContextItem(org.talend.core.model.properties.ContextItem) ComponentProperties(org.talend.components.api.properties.ComponentProperties) GenericConnParamName(org.talend.metadata.managment.ui.utils.GenericConnParamName) IConnParamName(org.talend.metadata.managment.ui.model.IConnParamName) ArrayList(java.util.ArrayList) List(java.util.List) GenericConnection(org.talend.repository.generic.model.genericMetadata.GenericConnection) ConectionAdaptContextVariableModel(org.talend.core.ui.context.model.table.ConectionAdaptContextVariableModel) Map(java.util.Map)

Example 5 with IConnParamName

use of org.talend.metadata.managment.ui.model.IConnParamName 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

IConnParamName (org.talend.metadata.managment.ui.model.IConnParamName)8 GenericConnParamName (org.talend.metadata.managment.ui.utils.GenericConnParamName)4 GenericConnection (org.talend.repository.generic.model.genericMetadata.GenericConnection)4 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)3 List (java.util.List)3 ComponentProperties (org.talend.components.api.properties.ComponentProperties)3 ContextItem (org.talend.core.model.properties.ContextItem)3 ConectionAdaptContextVariableModel (org.talend.core.ui.context.model.table.ConectionAdaptContextVariableModel)3 Map (java.util.Map)2 EParamName (org.talend.metadata.managment.ui.utils.OtherConnectionContextUtils.EParamName)2 HashMap (java.util.HashMap)1 EList (org.eclipse.emf.common.util.EList)1 Test (org.junit.Test)1 JobContextManager (org.talend.core.model.context.JobContextManager)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 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)1 GenericElementParameter (org.talend.designer.core.generic.model.GenericElementParameter)1