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;
}
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;
}
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;
}
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);
}
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);
}
Aggregations