Search in sources :

Example 16 with ContextItem

use of org.talend.core.model.properties.ContextItem 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 17 with ContextItem

use of org.talend.core.model.properties.ContextItem 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 18 with ContextItem

use of org.talend.core.model.properties.ContextItem in project tdi-studio-se by Talend.

the class JSONConnectionContextHelper method getRepositoryContext.

private static ISelection getRepositoryContext(final String contextNameOrId, boolean isId) {
    if (contextNameOrId == null || "".equals(contextNameOrId.trim())) {
        //$NON-NLS-1$
        return null;
    }
    if (isId && RepositoryNode.NO_ID.equals(contextNameOrId.trim())) {
        return null;
    }
    IRepositoryViewObject contextObject = null;
    try {
        ProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
        List<IRepositoryViewObject> contextObjectList = factory.getAll(ERepositoryObjectType.CONTEXT, true);
        if (contextObjectList != null) {
            for (IRepositoryViewObject object : contextObjectList) {
                Item item = object.getProperty().getItem();
                if (item != null && item instanceof ContextItem) {
                    String itemNameOrId = null;
                    if (isId) {
                        itemNameOrId = item.getProperty().getId();
                    } else {
                        itemNameOrId = item.getProperty().getLabel();
                    }
                    if (contextNameOrId.equals(itemNameOrId)) {
                        contextObject = object;
                        break;
                    }
                }
            }
        }
    } catch (PersistenceException e) {
    //
    }
    StructuredSelection selection = new StructuredSelection();
    if (contextObject != null) {
        RepositoryNode repositoryNode = RepositoryNodeUtilities.getRepositoryNode(contextObject);
        if (repositoryNode != null) {
            selection = new StructuredSelection(repositoryNode);
        }
    }
    return selection;
}
Also used : ContextItem(org.talend.core.model.properties.ContextItem) Item(org.talend.core.model.properties.Item) ConnectionItem(org.talend.core.model.properties.ConnectionItem) ContextItem(org.talend.core.model.properties.ContextItem) ProxyRepositoryFactory(org.talend.core.repository.model.ProxyRepositoryFactory) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) PersistenceException(org.talend.commons.exception.PersistenceException) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) RepositoryNode(org.talend.repository.model.RepositoryNode)

Example 19 with ContextItem

use of org.talend.core.model.properties.ContextItem in project tdi-studio-se by Talend.

the class JSONConnectionContextHelper method setPropertiesForExistContextMode.

public static void setPropertiesForExistContextMode(ConnectionItem connectionItem, Set<IConnParamName> paramSet, Map<ContextItem, List<ConectionAdaptContextVariableModel>> map) {
    if (connectionItem == null) {
        return;
    }
    ContextItem selItem = null;
    if (map.keySet().size() == 1) {
        selItem = map.keySet().iterator().next();
    }
    Connection conn = connectionItem.getConnection();
    if (conn instanceof JSONFileConnection) {
        setJSONFilePropertiesForExistContextMode((JSONFileConnection) conn, paramSet, map);
    }
    // set connection for context mode
    connectionItem.getConnection().setContextMode(true);
    connectionItem.getConnection().setContextId(selItem.getProperty().getId());
    connectionItem.getConnection().setContextName(selItem.getDefaultContext());
}
Also used : ContextItem(org.talend.core.model.properties.ContextItem) JSONFileConnection(org.talend.repository.model.json.JSONFileConnection) Connection(org.talend.core.model.metadata.builder.connection.Connection) JSONFileConnection(org.talend.repository.model.json.JSONFileConnection)

Example 20 with ContextItem

use of org.talend.core.model.properties.ContextItem in project tdi-studio-se by Talend.

the class ReplaceJavaKeywordsNameForContextMigrationTask method getReplacedNamesAndReplaceContextVars.

/**
     * 
     * ggu Comment method "getReplacedNamesAndReplaceContextVars".
     * 
     * get the replaced names, and replace the context variables at the same time.
     */
@SuppressWarnings("unchecked")
private Map<String, Map<String, String>> getReplacedNamesAndReplaceContextVars() {
    // id to map(oldName to newName)
    Map<String, Map<String, String>> contextIdNamesMap = new HashMap<String, Map<String, String>>();
    List<ContextItem> allContextItem = ContextUtils.getAllContextItem();
    if (allContextItem != null) {
        for (ContextItem contextItem : allContextItem) {
            boolean changed = false;
            boolean first = true;
            Set<String> varNames = null;
            for (ContextType contextType : (List<ContextType>) contextItem.getContext()) {
                if (first) {
                    varNames = ContextUtils.getContextVarNames(contextType);
                }
                // oldName to newName
                Map<String, String> nameMap = new HashMap<String, String>();
                final String contextId = contextItem.getProperty().getId();
                for (ContextParameterType paramType : (List<ContextParameterType>) contextType.getContextParameter()) {
                    String oldName = paramType.getName();
                    if (first) {
                        if (ContextUtils.isJavaKeyWords(oldName)) {
                            // is java keywords
                            String newName = getNewName(varNames, oldName);
                            nameMap.put(newName, oldName);
                            paramType.setName(newName);
                            changed = true;
                        }
                    } else {
                        String newName = getContextNewNameFromMap(contextIdNamesMap, contextId, oldName);
                        if (newName != null) {
                            // is java keywords
                            paramType.setName(newName);
                            changed = true;
                        }
                    }
                }
                if (first && !nameMap.isEmpty()) {
                    contextIdNamesMap.put(contextId, nameMap);
                }
                first = false;
            }
            if (changed) {
                // save
                try {
                    factory.save(contextItem, true);
                } catch (PersistenceException e) {
                // 
                }
            }
        }
    }
    return contextIdNamesMap;
}
Also used : ContextItem(org.talend.core.model.properties.ContextItem) ContextType(org.talend.designer.core.model.utils.emf.talendfile.ContextType) HashMap(java.util.HashMap) PersistenceException(org.talend.commons.exception.PersistenceException) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) ContextParameterType(org.talend.designer.core.model.utils.emf.talendfile.ContextParameterType)

Aggregations

ContextItem (org.talend.core.model.properties.ContextItem)28 ArrayList (java.util.ArrayList)9 PersistenceException (org.talend.commons.exception.PersistenceException)9 ProcessItem (org.talend.core.model.properties.ProcessItem)9 HashMap (java.util.HashMap)8 List (java.util.List)8 ConnectionItem (org.talend.core.model.properties.ConnectionItem)7 Item (org.talend.core.model.properties.Item)7 JobletProcessItem (org.talend.core.model.properties.JobletProcessItem)7 ContextType (org.talend.designer.core.model.utils.emf.talendfile.ContextType)7 EList (org.eclipse.emf.common.util.EList)6 ContextParameterType (org.talend.designer.core.model.utils.emf.talendfile.ContextParameterType)6 RepositoryNode (org.talend.repository.model.RepositoryNode)6 ConectionAdaptContextVariableModel (org.talend.core.ui.context.model.table.ConectionAdaptContextVariableModel)5 IProxyRepositoryFactory (org.talend.repository.model.IProxyRepositoryFactory)5 Iterator (java.util.Iterator)4 Map (java.util.Map)4 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)4 Connection (org.talend.core.model.metadata.builder.connection.Connection)4 IContext (org.talend.core.model.process.IContext)4