Search in sources :

Example 21 with ContextParameterType

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

the class ExportProcessorHelper method exportJob.

public String exportJob(Processor processor, int statisticsPort, int tracePort, String watchParam, String log4jLevel, final IProgressMonitor progressMonitor) throws ProcessorException {
    ProcessItem processItem = (ProcessItem) processor.getProperty().getItem();
    processName = processor.getProperty().getLabel();
    //$NON-NLS-1$
    File archiveFile = new File(getTmpExportFolder(), "remote_run_export-" + processName + FileExtensions.ZIP_FILE_SUFFIX);
    Properties prop = new Properties();
    if (watchParam != null) {
        prop.setProperty(TalendProcessArgumentConstant.ARG_ENABLE_WATCH, watchParam);
    }
    // FIXME, maybe should try another way. it's not good, I think.
    // update directly the .item (without save it) in case of prompt
    // then the generation will be correct automatically in the .properties
    IContext context = processor.getContext();
    if (context != null) {
        List<IContextParameter> contextParameterList = context.getContextParameterList();
        if (contextParameterList != null && contextParameterList.size() > 0) {
            for (IContextParameter contextParameter : contextParameterList) {
                if (!contextParameter.isPromptNeeded()) {
                    continue;
                }
                for (Object curCType : processItem.getProcess().getContext()) {
                    ContextType cType = (ContextType) curCType;
                    if (context.getName().equals(cType.getName())) {
                        for (Object curParam : cType.getContextParameter()) {
                            ContextParameterType cParamType = (ContextParameterType) curParam;
                            if (contextParameter.getName().equals(cParamType.getName())) {
                                cParamType.setRawValue(contextParameter.getValue());
                            }
                        }
                    }
                }
            }
        }
    }
    export(progressMonitor, processItem, ERepositoryObjectType.getItemType(processItem), processor.getContext().getName(), archiveFile.toString(), log4jLevel, false, statisticsPort, tracePort, prop);
    return archiveFile.toString();
}
Also used : ContextType(org.talend.designer.core.model.utils.emf.talendfile.ContextType) IContext(org.talend.core.model.process.IContext) ProcessItem(org.talend.core.model.properties.ProcessItem) Properties(java.util.Properties) File(java.io.File) IContextParameter(org.talend.core.model.process.IContextParameter) ContextParameterType(org.talend.designer.core.model.utils.emf.talendfile.ContextParameterType)

Example 22 with ContextParameterType

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

the class EncryptDbPasswordMigrationTask method encryptContextPassword.

/**
     * DOC chuang Comment method "encryptContextPassword".
     * 
     * @param item
     * @param contextTypeList
     * @return
     */
private ExecutionResult encryptContextPassword(Item item, List<ContextType> contextTypeList) {
    boolean modify = false;
    if (contextTypeList != null) {
        for (ContextType type : contextTypeList) {
            List<ContextParameterType> paramTypes = type.getContextParameter();
            if (paramTypes != null) {
                for (ContextParameterType param : paramTypes) {
                    try {
                        // before migration task, the value should be raw. so keep it.
                        if (param.getValue() != null && PasswordEncryptUtil.isPasswordType(param.getType())) {
                            encryptPassword(param);
                            modify = true;
                        }
                    } catch (Exception e) {
                        ExceptionHandler.process(e);
                        return ExecutionResult.FAILURE;
                    }
                }
            }
        }
    }
    if (modify) {
        try {
            factory.save(item, true);
        } catch (PersistenceException e) {
            ExceptionHandler.process(e);
            return ExecutionResult.FAILURE;
        }
    }
    return ExecutionResult.SUCCESS_NO_ALERT;
}
Also used : ContextType(org.talend.designer.core.model.utils.emf.talendfile.ContextType) PersistenceException(org.talend.commons.exception.PersistenceException) ContextParameterType(org.talend.designer.core.model.utils.emf.talendfile.ContextParameterType) PersistenceException(org.talend.commons.exception.PersistenceException)

Example 23 with ContextParameterType

use of org.talend.designer.core.model.utils.emf.talendfile.ContextParameterType 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 24 with ContextParameterType

use of org.talend.designer.core.model.utils.emf.talendfile.ContextParameterType 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 25 with ContextParameterType

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

Aggregations

ContextParameterType (org.talend.designer.core.model.utils.emf.talendfile.ContextParameterType)25 ContextType (org.talend.designer.core.model.utils.emf.talendfile.ContextType)19 ContextItem (org.talend.core.model.properties.ContextItem)8 PersistenceException (org.talend.commons.exception.PersistenceException)7 ArrayList (java.util.ArrayList)6 ProcessItem (org.talend.core.model.properties.ProcessItem)5 HashMap (java.util.HashMap)4 EList (org.eclipse.emf.common.util.EList)4 List (java.util.List)3 JobletProcessItem (org.talend.core.model.properties.JobletProcessItem)3 File (java.io.File)2 Test (org.junit.Test)2 IContext (org.talend.core.model.process.IContext)2 IContextParameter (org.talend.core.model.process.IContextParameter)2 IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Map (java.util.Map)1 Properties (java.util.Properties)1 Element (org.dom4j.Element)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1