Search in sources :

Example 76 with ContextType

use of org.talend.designer.core.model.utils.emf.talendfile.ContextType in project tdi-studio-se by Talend.

the class ExportJobUtil method getJobContextValues.

/**
     * DOC zli Comment method "getJobContextValues".
     * 
     * @param processItem
     * @param contextName
     * @return
     */
@SuppressWarnings("rawtypes")
public static List<ContextParameterType> getJobContextValues(ProcessItem processItem, String contextName) {
    if (contextName == null) {
        return null;
    }
    // else do next line
    List<ContextParameterType> list = new ArrayList<ContextParameterType>();
    EList contexts = ((ProcessTypeImpl) processItem.getProcess()).getContext();
    for (int i = 0; i < contexts.size(); i++) {
        Object object = contexts.get(i);
        if (object instanceof ContextType) {
            ContextType contextType = (ContextType) object;
            if (contextName.equals(contextType.getName())) {
                EList contextParameter = contextType.getContextParameter();
                for (int j = 0; j < contextParameter.size(); j++) {
                    Object object2 = contextParameter.get(j);
                    if (object2 instanceof ContextParameterType) {
                        ContextParameterType contextParameterType = (ContextParameterType) object2;
                        list.add(contextParameterType);
                    }
                }
                return list;
            }
        }
    }
    return null;
}
Also used : ContextType(org.talend.designer.core.model.utils.emf.talendfile.ContextType) EList(org.eclipse.emf.common.util.EList) ArrayList(java.util.ArrayList) ProcessTypeImpl(org.talend.designer.core.model.utils.emf.talendfile.impl.ProcessTypeImpl) ContextParameterType(org.talend.designer.core.model.utils.emf.talendfile.ContextParameterType)

Example 77 with ContextType

use of org.talend.designer.core.model.utils.emf.talendfile.ContextType 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)

Example 78 with ContextType

use of org.talend.designer.core.model.utils.emf.talendfile.ContextType in project tdi-studio-se by Talend.

the class ReplaceJavaKeywordsNameForContextMigrationTask method modifyJobContext.

/**
     * 
     * ggu Comment method "modifyJobContext".
     * 
     * this function will get the replaced variables map.
     */
@SuppressWarnings("unchecked")
private boolean modifyJobContext(Map<String, String> jobContextReplacedNamesMap, List<ContextType> contextTypeList) {
    if (contextTypeList == null || contextTypeList.isEmpty()) {
        return false;
    }
    boolean changed = false;
    boolean first = true;
    Set<String> varNames = null;
    for (ContextType contextType : (List<ContextType>) contextTypeList) {
        if (first) {
            varNames = ContextUtils.getContextVarNames(contextType);
        }
        for (ContextParameterType paramType : (List<ContextParameterType>) contextType.getContextParameter()) {
            final String oldName = paramType.getName();
            final String sourceId = paramType.getRepositoryContextId();
            if (first) {
                if (ContextUtils.isJavaKeyWords(oldName)) {
                    // is java keywords
                    String newName = getNewName(varNames, oldName);
                    String tmpName = getContextNewNameFromMap(contextReplacedNamesMap, sourceId, oldName);
                    if (tmpName != null) {
                        // from repository context
                        newName = tmpName;
                    }
                    jobContextReplacedNamesMap.put(newName, oldName);
                    paramType.setName(newName);
                    changed = true;
                }
            } else {
                String newName = getJobContextNewNameFromMap(jobContextReplacedNamesMap, oldName);
                if (newName != null) {
                    // is key words
                    paramType.setName(newName);
                    changed = true;
                }
            }
        }
    }
    return changed;
}
Also used : ContextType(org.talend.designer.core.model.utils.emf.talendfile.ContextType) ArrayList(java.util.ArrayList) List(java.util.List) ContextParameterType(org.talend.designer.core.model.utils.emf.talendfile.ContextParameterType)

Example 79 with ContextType

use of org.talend.designer.core.model.utils.emf.talendfile.ContextType in project tdi-studio-se by Talend.

the class ProcessController method updateContextList.

/**
     * 
     * ggu Comment method "updateContextList".
     * 
     * @param processParam
     */
private void updateContextList(IElementParameter processParam) {
    if (processParam == null || (processParam.getFieldType() != EParameterFieldType.PROCESS_TYPE && processParam.getFieldType() != EParameterFieldType.ROUTE_INPUT_PROCESS_TYPE)) {
        return;
    }
    // for context type
    List<String> contextNameList = new ArrayList<String>();
    List<String> contextValueList = new ArrayList<String>();
    // for version type
    List<String> versionNameList = new ArrayList<String>();
    List<String> versionValueList = new ArrayList<String>();
    versionNameList.add(ItemCacheManager.LATEST_VERSION);
    versionValueList.add(ItemCacheManager.LATEST_VERSION);
    IElementParameter jobNameParam = processParam.getChildParameters().get(EParameterName.PROCESS_TYPE_PROCESS.getName());
    // feature 19312
    Item item = null;
    StringBuffer labels = new StringBuffer("");
    List<IRepositoryViewObject> allVersion = new ArrayList<IRepositoryViewObject>();
    final String strJobId = (String) jobNameParam.getValue();
    String[] strJobIds = strJobId.split(ProcessController.COMMA);
    for (int i = 0; i < strJobIds.length; i++) {
        String id = strJobIds[i];
        if (StringUtils.isNotEmpty(id)) {
            allVersion = ProcessorUtilities.getAllVersionObjectById(id);
            // IRepositoryObject lastVersionObject = null;
            String label = null;
            if (allVersion != null) {
                String oldVersion = null;
                for (IRepositoryViewObject obj : allVersion) {
                    String version = obj.getVersion();
                    if (oldVersion == null) {
                        oldVersion = version;
                    }
                    if (VersionUtils.compareTo(version, oldVersion) >= 0) {
                        item = obj.getProperty().getItem();
                    // lastVersionObject = obj;
                    }
                    oldVersion = version;
                    versionNameList.add(version);
                    versionValueList.add(version);
                }
                label = item.getProperty().getLabel();
                if (i > 0) {
                    labels.append(ProcessController.COMMA);
                }
                labels.append(label);
            // IPath path = RepositoryNodeUtilities.getPath(lastVersionObject);
            // if (path != null) {
            // label = path.toString() + IPath.SEPARATOR + label;
            // }
            } else {
            // FIXME TUP-5524, don't set empty, keep the id value instead.
            // final String parentName = processParam.getName() + ":"; //$NON-NLS-1$
            // if (elem != null) {
            // // can be called in multi-thread, dispose method may be already called before executing this
            // method
            //elem.setPropertyValue(parentName + jobNameParam.getName(), ""); //$NON-NLS-1$
            // }
            }
        }
    }
    jobNameParam.setLabelFromRepository(labels.toString());
    // set default context
    String defalutValue = null;
    if (item != null && item instanceof ProcessItem) {
        for (Object o : ((ProcessItem) item).getProcess().getContext()) {
            if (o instanceof ContextType) {
                ContextType context = (ContextType) o;
                contextNameList.add(context.getName());
                contextValueList.add(context.getName());
            }
        }
        defalutValue = ((ProcessItem) item).getProcess().getDefaultContext();
    }
    setProcessTypeRelatedValues(processParam, contextNameList, contextValueList, EParameterName.PROCESS_TYPE_CONTEXT.getName(), defalutValue);
    setProcessTypeRelatedValues(processParam, versionNameList, versionValueList, EParameterName.PROCESS_TYPE_VERSION.getName(), null);
}
Also used : ContextType(org.talend.designer.core.model.utils.emf.talendfile.ContextType) ArrayList(java.util.ArrayList) Point(org.eclipse.swt.graphics.Point) Item(org.talend.core.model.properties.Item) ProcessItem(org.talend.core.model.properties.ProcessItem) ProcessItem(org.talend.core.model.properties.ProcessItem) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) IElementParameter(org.talend.core.model.process.IElementParameter) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject)

Example 80 with ContextType

use of org.talend.designer.core.model.utils.emf.talendfile.ContextType in project tdq-studio-se by Talend.

the class ContextHelper method getUrlWithoutContext.

/**
 * translate the context variable in the string to the value according to the specific context group name.
 *
 * @param context
 * @param contextGroupName
 * @param contextString the stirng contains context variable, example:
 * jdbc:mysql://context.TdqContext_Host:context.TdqContext_Port/context.TdqContext_DbName?characterEncoding=UTF8
 * @return
 */
public static String getUrlWithoutContext(List<ContextType> context, String contextGroupName, String contextString) {
    // key is the context script code(start with context.), value is the context value
    Map<String, String> contextValues = new HashMap<String, String>();
    for (ContextType contextType : context) {
        if (contextType.getName().equals(contextGroupName)) {
            for (Object obj : contextType.getContextParameter()) {
                ContextParameterType cpt = (ContextParameterType) obj;
                contextValues.put(ContextParameterUtils.getNewScriptCode(cpt.getName(), LANGUAGE), cpt.getRawValue());
            }
            break;
        }
    }
    return getUrlWithoutContext(contextString, contextValues);
}
Also used : ContextType(org.talend.designer.core.model.utils.emf.talendfile.ContextType) HashMap(java.util.HashMap) ContextParameterType(org.talend.designer.core.model.utils.emf.talendfile.ContextParameterType)

Aggregations

ContextType (org.talend.designer.core.model.utils.emf.talendfile.ContextType)108 ContextParameterType (org.talend.designer.core.model.utils.emf.talendfile.ContextParameterType)27 ArrayList (java.util.ArrayList)26 ContextItem (org.talend.core.model.properties.ContextItem)21 PersistenceException (org.talend.commons.exception.PersistenceException)17 File (java.io.File)16 NoSQLServerException (org.talend.repository.nosql.exceptions.NoSQLServerException)15 HadoopClusterConnection (org.talend.repository.model.hadoopcluster.HadoopClusterConnection)13 NoSQLReflectionException (org.talend.repository.nosql.exceptions.NoSQLReflectionException)13 Test (org.junit.Test)12 HashMap (java.util.HashMap)10 List (java.util.List)10 ProcessItem (org.talend.core.model.properties.ProcessItem)9 IOException (java.io.IOException)8 Map (java.util.Map)8 EList (org.eclipse.emf.common.util.EList)7 FileNotFoundException (java.io.FileNotFoundException)6 FileOutputStream (java.io.FileOutputStream)6 Property (org.talend.core.model.properties.Property)6 HashSet (java.util.HashSet)5