Search in sources :

Example 1 with ConectionAdaptContextVariableModel

use of org.talend.core.ui.context.model.table.ConectionAdaptContextVariableModel in project tdi-studio-se by Talend.

the class AbstractJSONStepForm method exportAsContext.

/*
     * (non-Javadoc)
     * 
     * @see org.talend.repository.ui.swt.utils.AbstractForm#exportAsContext()
     */
@Override
protected void exportAsContext() {
    if (hasContextBtn() && connectionItem != null) {
        if (isContextMode()) {
            JSONConnectionContextHelper.openInConetxtModeDialog();
        } else {
            Map<ContextItem, List<ConectionAdaptContextVariableModel>> variableModels = JSONConnectionContextHelper.exportAsContext(connectionItem, getConetxtParams());
            contextManager = JSONConnectionContextHelper.contextManager;
            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 (contextManager instanceof JobContextManager) {
                            Map<String, String> map = ((JobContextManager) contextManager).getNameMap();
                            // set properties for context mode
                            JSONConnectionContextHelper.setPropertiesForContextMode(connectionItem, contextItem, getConetxtParams(), map);
                        }
                    } else {
                        // set properties for exist context
                        JSONConnectionContextHelper.setPropertiesForExistContextMode(connectionItem, getConetxtParams(), variableModels);
                    }
                    // refresh current UI.
                    initialize();
                    adaptFormToEditable();
                }
            }
        }
    }
}
Also used : ContextItem(org.talend.core.model.properties.ContextItem) List(java.util.List) JobContextManager(org.talend.core.model.context.JobContextManager) ConectionAdaptContextVariableModel(org.talend.core.ui.context.model.table.ConectionAdaptContextVariableModel)

Example 2 with ConectionAdaptContextVariableModel

use of org.talend.core.ui.context.model.table.ConectionAdaptContextVariableModel in project tdi-studio-se by Talend.

the class JSONConnectionContextHelper method setJSONFilePropertiesForExistContextMode.

static void setJSONFilePropertiesForExistContextMode(JSONFileConnection jsonConn, Set<IConnParamName> paramSet, Map<ContextItem, List<ConectionAdaptContextVariableModel>> map) {
    if (jsonConn == null) {
        return;
    }
    String jsonVariableName = null;
    for (IConnParamName param : paramSet) {
        if (param instanceof EParamName) {
            EParamName jsonParam = (EParamName) param;
            if (map != null && map.size() > 0) {
                for (Map.Entry<ContextItem, List<ConectionAdaptContextVariableModel>> entry : map.entrySet()) {
                    List<ConectionAdaptContextVariableModel> modelList = entry.getValue();
                    for (ConectionAdaptContextVariableModel model : modelList) {
                        if (model.getValue().equals(jsonParam.name())) {
                            jsonVariableName = model.getName();
                            break;
                        }
                    }
                }
            }
            if (jsonConn.isInputModel()) {
                switch(jsonParam) {
                    case FilePath:
                        jsonConn.setJSONFilePath(ContextParameterUtils.getNewScriptCode(jsonVariableName, LANGUAGE));
                        break;
                    case Encoding:
                        jsonConn.setEncoding(ContextParameterUtils.getNewScriptCode(jsonVariableName, LANGUAGE));
                        break;
                    case XPathQuery:
                        EList schema = jsonConn.getSchema();
                        if (schema != null) {
                            if (schema.get(0) instanceof JSONXPathLoopDescriptor) {
                                JSONXPathLoopDescriptor descriptor = (JSONXPathLoopDescriptor) schema.get(0);
                                descriptor.setAbsoluteXPathQuery(ContextParameterUtils.getNewScriptCode(jsonVariableName, LANGUAGE));
                            }
                        }
                    default:
                }
            } else {
                if (jsonParam.equals(EParamName.OutputFilePath)) {
                    jsonConn.setOutputFilePath(ContextParameterUtils.getNewScriptCode(jsonVariableName, LANGUAGE));
                }
            }
        }
    }
}
Also used : ContextItem(org.talend.core.model.properties.ContextItem) JSONXPathLoopDescriptor(org.talend.repository.model.json.JSONXPathLoopDescriptor) EParamName(org.talend.metadata.managment.ui.utils.OtherConnectionContextUtils.EParamName) EList(org.eclipse.emf.common.util.EList) IConnParamName(org.talend.metadata.managment.ui.model.IConnParamName) List(java.util.List) ArrayList(java.util.ArrayList) EList(org.eclipse.emf.common.util.EList) ConectionAdaptContextVariableModel(org.talend.core.ui.context.model.table.ConectionAdaptContextVariableModel) Map(java.util.Map) HashMap(java.util.HashMap)

Example 3 with ConectionAdaptContextVariableModel

use of org.talend.core.ui.context.model.table.ConectionAdaptContextVariableModel 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 4 with ConectionAdaptContextVariableModel

use of org.talend.core.ui.context.model.table.ConectionAdaptContextVariableModel 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 5 with ConectionAdaptContextVariableModel

use of org.talend.core.ui.context.model.table.ConectionAdaptContextVariableModel 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)

Aggregations

List (java.util.List)5 ContextItem (org.talend.core.model.properties.ContextItem)5 ConectionAdaptContextVariableModel (org.talend.core.ui.context.model.table.ConectionAdaptContextVariableModel)5 ArrayList (java.util.ArrayList)3 IConnParamName (org.talend.metadata.managment.ui.model.IConnParamName)3 HashMap (java.util.HashMap)2 Map (java.util.Map)2 EList (org.eclipse.emf.common.util.EList)2 JobContextManager (org.talend.core.model.context.JobContextManager)2 ISelection (org.eclipse.jface.viewers.ISelection)1 WizardDialog (org.eclipse.jface.wizard.WizardDialog)1 ComponentProperties (org.talend.components.api.properties.ComponentProperties)1 IContextParameter (org.talend.core.model.process.IContextParameter)1 GenericConnParamName (org.talend.metadata.managment.ui.utils.GenericConnParamName)1 EParamName (org.talend.metadata.managment.ui.utils.OtherConnectionContextUtils.EParamName)1 ContextModeWizard (org.talend.metadata.managment.ui.wizard.context.ContextModeWizard)1 GenericConnection (org.talend.repository.generic.model.genericMetadata.GenericConnection)1 JSONXPathLoopDescriptor (org.talend.repository.model.json.JSONXPathLoopDescriptor)1